FairShip
Loading...
Searching...
No Matches
MuDISFilter.cxx
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP
3// Collaboration
4
5#include "MuDISFilter.h"
6
7#include <Pythia8/Pythia.h>
8#include <TFile.h>
9#include <TTree.h>
10#include <TTreeReader.h>
11#include <TTreeReaderValue.h>
12
13#include <algorithm>
14#include <cmath>
15#include <iostream>
16#include <memory>
17#include <sstream>
18#include <stdexcept>
19
20#include "FairLogger.h"
22#include "TMath.h"
23#include "TROOT.h"
24#include "TRandom.h"
25#include "TSystem.h"
26#include "TVectorD.h"
27
28using namespace ShipMuDIS;
29
30namespace {
31// Keep the nominal bin width and reserve one visible bin at each end.
32template <typename Histogram>
33Histogram* WithFlowBins(TDirectory* dir, const char* name, const char* title,
34 int bins, double low, double high) {
35 const double width = (high - low) / bins;
36 auto* histogram =
37 new Histogram(name, title, bins + 2, low - width, high + width);
38 histogram->SetDirectory(dir);
39 return histogram;
40}
41
42template <typename Histogram>
43Histogram* WithFlowBins(TDirectory* dir, const char* name, const char* title,
44 int nx, double xmin, double xmax, int ny, double ymin,
45 double ymax) {
46 const double dx = (xmax - xmin) / nx, dy = (ymax - ymin) / ny;
47 auto* histogram = new Histogram(name, title, nx + 2, xmin - dx, xmax + dx,
48 ny + 2, ymin - dy, ymax + dy);
49 histogram->SetDirectory(dir);
50 return histogram;
51}
52
53double VisibleFlowValue(const TAxis* axis, double value) {
54 if (value < axis->GetBinLowEdge(2)) return axis->GetBinCenter(1);
55 if (value >= axis->GetBinLowEdge(axis->GetNbins()))
56 return axis->GetBinCenter(axis->GetNbins());
57 return value;
58}
59
60void FillWithFlow(TH1* histogram, double value) {
61 if (!histogram) return;
62 histogram->Fill(VisibleFlowValue(histogram->GetXaxis(), value));
63}
64
65void FillWithFlow(TH2* histogram, double x, double y) {
66 if (!histogram) return;
67 histogram->Fill(VisibleFlowValue(histogram->GetXaxis(), x),
68 VisibleFlowValue(histogram->GetYaxis(), y));
69}
70
71bool IsNeutrino(const DISparticle& particle) {
72 const int pid = std::abs(particle.pid);
73 return pid == 12 || pid == 14 || pid == 16;
74}
75
76bool InsideXY(const TVector3& hit, const std::array<double, 4>& bounds) {
77 return hit.X() >= bounds[0] && hit.X() <= bounds[1] && hit.Y() >= bounds[2] &&
78 hit.Y() <= bounds[3];
79}
80
81bool PassesChargedMomentumCut(const DISparticle& particle) {
82 return std::sqrt(particle.px * particle.px + particle.py * particle.py +
83 particle.pz * particle.pz) > 1.;
84}
85
86constexpr std::array<double, 5> kMomentumEdges = {2., 20., 50., 100., 400.};
87constexpr std::array<double, 6> kPtEdges = {0., 1., 2., 3., 5., 10.};
88
89int KinematicBin(double value, const double* edges, unsigned bins) {
90 if (!std::isfinite(value) || value < edges[0] || value > edges[bins])
91 return -1;
92 for (unsigned bin = 0; bin < bins; ++bin)
93 if (value < edges[bin + 1] || bin + 1 == bins) return bin;
94 return -1;
95}
96} // namespace
97
98// ----- Default constructor -------------------------------------------
100 ftree = nullptr;
101 fouttree = nullptr;
102
103 fLogger = FairLogger::GetLogger();
104 fnEvts = -1;
105 fstartEvt = 0;
106 fPDG = TDatabasePDG::Instance();
107}
108
109void MuDISFilter::SetFilterEfficiencyBinning(double xmin, double xmax,
110 unsigned xbins, double ymin,
111 double ymax, unsigned ybins,
112 double zmin, double zmax,
113 unsigned zbins) {
114 const auto symmetricAboutZero = [](double low, double high) {
115 return std::abs(low + high) <=
116 1.e-12 * std::max({1., std::abs(low), std::abs(high)});
117 };
118 if (!std::isfinite(xmin) || !std::isfinite(xmax) || !std::isfinite(ymin) ||
119 !std::isfinite(ymax) || !std::isfinite(zmin) || !std::isfinite(zmax) ||
120 xmin >= xmax || ymin >= ymax || zmin >= zmax || xbins == 0 ||
121 ybins == 0 || zbins == 0 || xbins % 2 == 0 || ybins % 2 == 0 ||
122 !symmetricAboutZero(xmin, xmax) || !symmetricAboutZero(ymin, ymax))
123 throw std::invalid_argument(
124 "Filter-efficiency x/y axes must be symmetric about zero with an odd "
125 "positive number of bins; all axis bounds must increase");
126 fEfficiencyXYBounds = {xmin, xmax, ymin, ymax};
127 fEfficiencyXBins = xbins;
128 fEfficiencyYBins = ybins;
129 fEfficiencyZBounds = {zmin, zmax};
130 fEfficiencyZBins = zbins;
131}
132
133Histograms MuDISFilter::BookHistograms(TDirectory* dir, const TString& mat,
134 const TString& label) {
135 dir->cd();
136
137 Histograms h;
138
139 h.dis_vxz = WithFlowBins<TH2D>(
140 dir, Form("vertex_x_vs_z_%s", label.Data()),
141 Form("DIS vertex x vs z - %s;z [cm];x [cm]", mat.Data()), 3300, 2700.,
142 9000., 600, -300., 300.);
143 h.dis_vyz = WithFlowBins<TH2D>(
144 dir, Form("vertex_y_vs_z_%s", label.Data()),
145 Form("DIS vertex y vs z - %s;z [cm];y [cm]", mat.Data()), 3300, 2700.,
146 9000., 600, -300., 300.);
147 h.dis_vxy = WithFlowBins<TH2D>(
148 dir, Form("vertex_y_vs_x_%s", label.Data()),
149 Form("DIS vertex y vs x - %s;x [cm];y [cm]", mat.Data()), 600, -300.,
150 300., 600, -300., 300.);
152 h.dis_vr = WithFlowBins<TH1D>(
153 dir, Form("vertex_r_%s", label.Data()),
154 Form("DIS vertex radius - %s;r [cm];Events", mat.Data()), 600, 0.,
155 600.);
156 h.dis_vz = WithFlowBins<TH1D>(
157 dir, Form("vertex_z_%s", label.Data()),
158 Form("DIS vertex z - %s;z [cm];Events", mat.Data()), 3300, 2700., 9000.);
160 h.dis_pdg = WithFlowBins<TH1I>(
161 dir, Form("daughter_pdg_%s", label.Data()),
162 Form("PDG code of DIS daughters - %s;PDG code;Particles", mat.Data()),
163 12001, -6000.5, 6000.5);
164 h.dis_pdgGrouped = WithFlowBins<TH1I>(
165 dir, Form("daughter_pdg_grouped_%s", label.Data()),
166 Form("DIS daughter species - %s;Species;Particles", mat.Data()), 11, 0.5,
167 11.5);
168 const char* labels[] = {"e^{+}", "e^{-}", "#mu^{+}", "#mu^{-}",
169 "#gamma", "#nu/#bar{#nu}", "#pi^{#pm}", "h^{#pm}",
170 "#pi^{0}", "h^{0}", "other"};
171 for (int bin = 1; bin <= 11; ++bin)
172 h.dis_pdgGrouped->GetXaxis()->SetBinLabel(bin + 1, labels[bin - 1]);
174 h.dis_n = WithFlowBins<TH1I>(
175 dir, Form("n_daughters_%s", label.Data()),
176 Form("Number of DIS daughters - %s;multiplicity;Event", mat.Data()), 50,
177 0, 50);
179 h.dis_nCharged = WithFlowBins<TH1I>(
180 dir, Form("n_daughters_charged_%s", label.Data()),
181 Form("Number of charged DIS daughters - %s;charged multiplicity;Event",
182 mat.Data()),
183 50, 0, 50);
184 h.dis_nChargedCandidates = WithFlowBins<TH1I>(
185 dir, Form("n_charged_candidates_%s", label.Data()),
186 Form(
187 "Number of charged filter candidates - %s;charged multiplicity;Event",
188 mat.Data()),
189 50, 0, 50);
190 h.dis_eNeutralTD = WithFlowBins<TH1D>(
191 dir, Form("neutral_candidate_energy_TD_%s", label.Data()),
192 Form("Visible neutral candidate energy reaching timing detector - "
193 "%s;energy [GeV];Event",
194 mat.Data()),
195 400, 0., 400.);
197 h.dis_pChargedFrac = WithFlowBins<TH1D>(
198 dir, Form("pfrac_charged_%s", label.Data()),
199 Form("Charged fraction - %s;p(charged)/p(all);Event", mat.Data()), 101,
200 0, 1.01);
202 h.dis_pMuFrac = WithFlowBins<TH1D>(
203 dir, Form("pfrac_mu_%s", label.Data()),
204 Form("p fraction of outgoing mu - %s;p(mu)/p(all);Event", mat.Data()),
205 101, 0, 1.01);
207 h.mu_p = WithFlowBins<TH1D>(
208 dir, Form("muon_p_%s", label.Data()),
209 Form("muon momentum - %s;p_{#mu,in} [GeV]; Input mu events",
210 mat.Data()),
211 400, 0., 400.);
213 h.mu_pt = WithFlowBins<TH1D>(
214 dir, Form("muon_pt_%s", label.Data()),
215 Form("muon p_{T} - %s;p_{T,#mu,in} [GeV];Input mu events", mat.Data()),
216 100, 0., 10.);
217 h.mu_ppt = WithFlowBins<TH2D>(dir, Form("muon_pt_vs_p_%s", label.Data()),
218 Form("muon p_{T} vs p - %s;p_{#mu,in} [GeV]; "
219 "p_{T,#mu,in} [GeV];Input mu events",
220 mat.Data()),
221 400, 0, 400, 100, 0., 10.);
223 h.mu_ndis = WithFlowBins<TH1I>(
224 dir, Form("muon_n_dis_%s", label.Data()),
225 Form("Number of DIS events - %s;DIS multiplicity;Input mu events",
226 mat.Data()),
227 1001, 0, 1001);
229 h.mu_wdis = WithFlowBins<TH1D>(
230 dir, Form("muon_vtx_weight_%s", label.Data()),
231 Form("DIS vertex weight - %s;wDIS;Input mu events", mat.Data()), 100,
232 0., 1000.);
233 return h;
234}
235
237 dir->cd();
239 const double xmin = fEfficiencyXYBounds[0], xmax = fEfficiencyXYBounds[1];
240 const double ymin = fEfficiencyXYBounds[2], ymax = fEfficiencyXYBounds[3];
241 for (unsigned ip = 0; ip < kMomentumBins; ++ip)
242 for (unsigned ipt = 0; ipt < kPtBins; ++ipt)
243 for (unsigned imat = 0; imat < kEfficiencyMaterials; ++imat) {
244 const TString tag =
245 Form("p%u_pt%u_%s", ip, ipt, MatTypeStr[imat].Data());
246 const TString title = Form(
247 "DIS filter efficiency, %.0f #leq p < %.0f GeV, "
248 "%.0f #leq p_{T} < %.0f GeV - %s",
249 kMomentumEdges[ip], kMomentumEdges[ip + 1], kPtEdges[ipt],
250 kPtEdges[ipt + 1], MatTypeStr[imat].Data());
251 const TString axTitles = ";x_{#mu,start} [cm];y_{#mu,start} [cm]";
252 auto*& all = fFilterEfficiency.allXY[ip][ipt][imat];
253 auto*& passed = fFilterEfficiency.passedXY[ip][ipt][imat];
254 all = new TH2D(Form("filter_efficiency_all_%s", tag.Data()),
255 title + axTitles, fEfficiencyXBins, xmin, xmax,
256 fEfficiencyYBins, ymin, ymax);
257 passed = new TH2D(Form("filter_efficiency_passed_%s", tag.Data()),
258 title + axTitles, fEfficiencyXBins, xmin, xmax,
259 fEfficiencyYBins, ymin, ymax);
260 all->SetDirectory(dir);
261 all->Sumw2();
262 passed->SetDirectory(dir);
263 passed->Sumw2();
264 if (!fDetailedHistograms) continue;
265 auto& allZByX = fFilterEfficiency.allZ[ip][ipt];
266 auto& passedZByX = fFilterEfficiency.passedZ[ip][ipt];
267 allZByX.resize(fEfficiencyXBins);
268 passedZByX.resize(fEfficiencyXBins);
269 for (unsigned ix = 0; ix < fEfficiencyXBins; ++ix) {
270 allZByX[ix].resize(fEfficiencyYBins);
271 passedZByX[ix].resize(fEfficiencyYBins);
272 for (unsigned iy = 0; iy < fEfficiencyYBins; ++iy) {
273 auto*& allZ = fFilterEfficiency.allZ[ip][ipt][ix][iy][imat];
274 auto*& passedZ = fFilterEfficiency.passedZ[ip][ipt][ix][iy][imat];
275 allZ = new TH1D(
276 Form("filter_efficiency_z_all_%s_x%u_y%u", tag.Data(), ix, iy),
277 title + Form(";z_{DIS} [cm];Weighted DIS events"),
279 passedZ = new TH1D(Form("filter_efficiency_z_passed_%s_x%u_y%u",
280 tag.Data(), ix, iy),
281 allZ->GetTitle(), fEfficiencyZBins,
283 allZ->SetDirectory(dir);
284 allZ->Sumw2();
285 passedZ->SetDirectory(dir);
286 passedZ->Sumw2();
287 }
288 }
289 }
290}
291
293 double momentum, double pt,
294 double x, double y, double z,
295 double weight, bool passed) {
296 if (material >= kEfficiencyMaterials || !std::isfinite(weight)) return;
297 const int ip = KinematicBin(momentum, kMomentumEdges.data(), kMomentumBins);
298 const int ipt = KinematicBin(pt, kPtEdges.data(), kPtBins);
299 if (ip < 0 || ipt < 0) return;
300 auto* all = fFilterEfficiency.allXY[ip][ipt][material];
301 auto* accepted = fFilterEfficiency.passedXY[ip][ipt][material];
302 all->Fill(x, y, weight);
303 if (passed) accepted->Fill(x, y, weight);
304 if (!fDetailedHistograms) return;
305 const int ix = all->GetXaxis()->FindFixBin(x) - 1;
306 const int iy = all->GetYaxis()->FindFixBin(y) - 1;
307 if (ix < 0 || ix >= static_cast<int>(fEfficiencyXBins) || iy < 0 ||
308 iy >= static_cast<int>(fEfficiencyYBins))
309 return;
310 fFilterEfficiency.allZ[ip][ipt][ix][iy][material]->Fill(z, weight);
311 if (passed)
312 fFilterEfficiency.passedZ[ip][ipt][ix][iy][material]->Fill(z, weight);
313}
314
315void MuDISFilter::init(const int& aEvts, const int& aStart) {
316 if (aEvts < -1 || aStart < 0)
317 throw std::invalid_argument("Invalid event range");
318 fnEvts = aEvts;
319 fstartEvt = aStart;
320}
321
322Bool_t MuDISFilter::InitFile(const char* fileName) {
323 return InitFile(fileName, 0);
324}
325
326Bool_t MuDISFilter::InitFiles(const std::vector<std::string>& fileNames) {
327 return InitFiles(fileNames, 0);
328}
329
330// ----- Default constructor -------------------------------------------
331Bool_t MuDISFilter::InitFile(const char* fileName, const int startEvent) {
332 std::vector<std::string> fileNames = {fileName};
333 return InitFiles(fileNames, startEvent);
334}
335
336Bool_t MuDISFilter::InitFiles(const std::vector<std::string>& fileNames,
337 const int startEvent) {
338 if (startEvent < 0) return kFALSE;
339 fstartEvt = startEvent;
340 if (fileNames.empty()) {
341 LOG(error) << "MuDISFilter: no input files provided. "
342 << "Check the -f/--inputFile argument or input file glob.";
343 return kFALSE;
344 }
345 for (const auto& fileName : fileNames) {
346 if (fileName.empty()) {
347 LOG(error) << "MuDISFilter: received an empty input file name. "
348 << "Check the -f/--inputFile argument.";
349 return kFALSE;
350 }
351 }
352
353 for (const auto& name : fileNames) {
354 std::unique_ptr<TFile> file(TFile::Open(name.c_str(), "READ"));
355 TTree* tree = nullptr;
356 if (file && !file->IsZombie()) file->GetObject("MuonDIS", tree);
357 if (!tree) {
358 LOG(error) << "MuDISFilter: missing MuonDIS tree in " << name;
359 return kFALSE;
360 }
361 MuonInBranches check;
362 if (!check.Setup(tree)) return kFALSE;
363 tree->ResetBranchAddresses();
364 }
365
366 {
367 delete ftree;
368 ftree = new TChain("MuonDIS");
369 for (const auto& name : fileNames) {
370 if (!ftree->Add(name.c_str())) return kFALSE;
371 }
372 Long64_t treeEvts = ftree->GetEntries();
373 LOG(info) << "Reading " << treeEvts << " entries.";
374 bool ok = finEv.Setup(ftree);
375
376 if (!ok) {
377 LOG(error) << "MuDISFilter: failed to bind one or more required branches";
378 return kFALSE;
379 }
380 LOG(info) << "MuDISFilter: Initialization successful.";
381 return kTRUE;
382 }
383 return kFALSE;
384}
385
386void MuDISFilter::process_file(const std::string& input,
387 const std::string& output) {
388 std::vector<std::string> fileNames = {input};
389 return process_file(fileNames, output);
390}
391
392void MuDISFilter::process_file(const std::vector<std::string>& input,
393 const std::string& output) {
395 throw std::runtime_error(
396 "Filter options 1 and 2 require detector acceptance");
398 throw std::runtime_error(
399 "Configure detector acceptance with geometry and field map first");
400
401 Bool_t treeOK = InitFiles(input, fstartEvt);
402
403 if (!treeOK) {
404 throw std::runtime_error("MuDISFilter: failed to initialize input files");
405 }
406
407 if (!fFilter && fUseDetectorAcceptance && fPropagator->HasMuonShieldField()) {
408 // A separate, vertex-only reader preserves the filtering chain's branch
409 // addresses and cache learning. Restrict the scan to the requested entries.
410 TChain vertices("MuonDIS");
411 for (const auto& name : input) vertices.Add(name.c_str());
412 TTreeReader reader(&vertices);
413 std::vector<std::unique_ptr<TTreeReaderValue<std::vector<double>>>> vz;
414 for (unsigned imat = 0; imat < nMats; ++imat)
415 vz.emplace_back(new TTreeReaderValue<std::vector<double>>(
416 reader, "mudis_DISvz_" + MatTypeStr[imat]));
417 const Long64_t end = fnEvts >= 0 ? std::min(Long64_t(fstartEvt) + fnEvts,
418 ftree->GetEntries())
419 : ftree->GetEntries();
420 double minimum = std::numeric_limits<double>::infinity(),
421 msMinimum = minimum;
422 bool valid = true;
423 if (fstartEvt < end) {
424 reader.SetEntriesRange(fstartEvt, end);
425 Long64_t scanned = 0;
426 while (reader.Next()) {
427 ++scanned;
428 for (unsigned imat = 0; imat < nMats; ++imat) {
429 const auto* values = vz[imat]->Get();
430 if (!values || vz[imat]->GetSetupStatus() < 0 ||
431 vz[imat]->GetReadStatus() !=
432 TTreeReaderValue<std::vector<double>>::kReadSuccess) {
433 valid = false;
434 continue;
435 }
436 for (double z : *values) {
437 if (!std::isfinite(z)) {
438 valid = false;
439 continue;
440 }
441 minimum = std::min(minimum, z);
442 if (MatTypeStr[imat] == "MS") msMinimum = std::min(msMinimum, z);
443 }
444 }
445 }
446 valid = valid && scanned == end - fstartEvt;
447 }
448 if (valid && std::isfinite(minimum)) {
449 const double detectorMinimum =
451 : fFilterOption == 1
452 ? *std::min_element(fStationZ.begin(), fStationZ.end())
453 : fDetectorZ;
454 minimum = std::min(minimum, detectorMinimum);
455 LOG(info) << "Muon shield field bounds: input MS minimum z = "
456 << msMinimum << " cm; conservative scan minimum z = " << minimum
457 << " cm";
458 fPropagator->SetMuonShieldMinZ(minimum);
459 } else {
460 // No usable vertices or failed reads: retain the complete field map.
461 fPropagator->SetMuonShieldMinZ(-std::numeric_limits<double>::infinity());
462 if (!valid)
463 LOG(warn)
464 << "Vertex range scan failed; using full muon shield field bounds";
465 }
466 }
467
468 // Histograms belong to this file, even if ROOT's automatic attachment is
469 // disabled. Clear borrowed pointers on success and on exception alike.
470 const auto closeOutput = [this](TFile* file) {
471 delete file;
472 fouttree = nullptr;
473 for (auto& hist : hist_all) hist = {};
474 for (auto& hist : hist_filt) hist = {};
476 };
477 std::unique_ptr<TFile, decltype(closeOutput)> outfile(
478 TFile::Open(output.c_str(), "CREATE"), closeOutput);
479 if (!outfile || outfile->IsZombie()) {
480 throw std::runtime_error("MuDISFilter: cannot create output file " +
481 output);
482 }
483 outfile->cd();
484
485 for (unsigned imat = 0; imat < nMats; ++imat) {
486 TDirectory* dir = outfile->mkdir(MatTypeStr[imat].Data());
487
488 hist_all[imat] = BookHistograms(dir, MatTypeStr[imat]);
489 hist_filt[imat] = BookHistograms(dir, MatTypeStr[imat], "filtered");
490 }
491 BookFilterEfficiencyHistograms(outfile->mkdir("filter_efficiency"));
492
493 outfile->cd();
494 fouttree = new TTree(
495 "MuonDIS", "Muon information, DIS products and soft interaction tracks");
496 foutEv.InitTree(fouttree);
497
498 Long64_t n = ftree->GetEntries();
499 LOG(info) << " * input tree with " << n << " entries" << std::endl;
500
502
503 outfile->cd();
504 if (outfile->Write() <= 0 || outfile->TestBit(TFile::kWriteError))
505 throw std::runtime_error("MuDISFilter: failed to write output file");
506 outfile->Close();
507}
508
510
512 foutEv.initEvent();
513 for (unsigned i = 0; i < nMats; ++i) foutEv.br[i].initEvent(0);
514}
515
516bool MuDISFilter::IsCharged(const DISparticle& particle) const {
517 return Charge(particle) != 0.;
518}
519
520double MuDISFilter::Charge(const DISparticle& particle) const {
521 const auto* pdg = fPDG->GetParticle(particle.pid);
522 // Nuclear PDG codes encode Z in digits 5--7 (10LZZZAAAI).
523 if (!pdg && std::abs(particle.pid) >= 1000000000)
524 return ((std::abs(particle.pid) / 10000) % 1000) *
525 (particle.pid > 0 ? 1. : -1.);
526 return pdg ? pdg->Charge() / 3. : 0.;
527}
528
529int MuDISFilter::DaughterCategory(const DISparticle& particle) const {
530 switch (particle.pid) {
531 case -11:
532 return 1;
533 case 11:
534 return 2;
535 case -13:
536 return 3;
537 case 13:
538 return 4;
539 case 22:
540 return 5;
541 case 12:
542 case -12:
543 case 14:
544 case -14:
545 case 16:
546 case -16:
547 return 6;
548 case 211:
549 case -211:
550 return 7;
551 case 111:
552 return 9;
553 }
554 const auto* pdg = fPDG->GetParticle(particle.pid);
555 if (pdg) {
556 const TString particleClass = pdg->ParticleClass();
557 if (particleClass == "Meson" || particleClass == "Baryon")
558 return pdg->Charge() != 0. ? 8 : 10;
559 }
560 return 11;
561}
562
564 unsigned option, const MagneticTrackPropagator& propagator) {
565 if (option == 1) {
566 const std::array<const char*, 5> names = {"Tr1", "Tr2", "Tr3", "Tr4",
567 "TimingDetector"};
568 std::array<double, 5> planes;
569 std::array<std::array<double, 4>, 5> bounds;
570 for (unsigned i = 0; i < names.size(); ++i) {
571 planes[i] = propagator.GetPlaneZ(names[i]);
572 bounds[i] = propagator.GetVolumeExitFaceXY(names[i]);
573 }
574 fStationZ = planes;
575 fStationXY = bounds;
576 } else if (option == 2) {
577 const double front = propagator.GetVolumeZRange("Tr1").first;
578 const double end = propagator.GetVolumeZRange("TimingDetector").second;
579 if (front >= end)
580 throw std::runtime_error(
581 "Timing detector end must be downstream of the Tr1 front");
582 fDetectorVolumeZ = {front, end};
583 }
584}
585
586void MuDISFilter::SetFilterOption(unsigned option) {
587 if (option > 2)
588 throw std::invalid_argument("Filter option must be 0, 1 or 2");
590 fFilterOption = option;
591}
592
594 fPythiaDecayer = std::make_unique<Pythia8::Pythia>();
595 fPythiaDecayer->readString("ProcessLevel:all = off");
596 fPythiaDecayer->readString("Random:setSeed = on");
597 unsigned seed = fPythiaDecaySeed;
598 if (seed == 0) {
599 // Pythia's time-based seed can exceed the Random:seed input range.
600 // Wrap before init so replaying the logged seed follows the same setup.
601 fPythiaDecayer->rndm.init(0);
602 seed =
603 1 + (static_cast<unsigned>(fPythiaDecayer->rndm.getState().seed) - 1) %
604 900000000;
605 }
606 if (!fPythiaDecayer->readString("Random:seed = " + std::to_string(seed)))
607 throw std::invalid_argument("MuDISFilter: invalid Pythia8 decay seed");
608 constexpr std::array<int, 10> decayIds = {211, 321, 130, 310, 3112,
609 3122, 3222, 3312, 3322, 3334};
610 for (int id : decayIds) {
611 if (!fPythiaDecayer->readString(std::to_string(id) + ":mayDecay = on"))
612 throw std::runtime_error(
613 "MuDISFilter: cannot enable Pythia8 decay for PDG " +
614 std::to_string(id));
615 }
616 if (!fPythiaDecayer->init())
617 throw std::runtime_error(
618 "MuDISFilter: failed to initialize the Pythia8 decayer");
619 LOG(info) << "MuDISFilter: Pythia8 decay seed = "
620 << fPythiaDecayer->rndm.getState().seed;
621}
622
624 fUsePythiaDecays = enabled;
625 if (enabled)
627 else
628 fPythiaDecayer.reset();
629}
630
635
636std::vector<MuDISFilter::FilterCandidate> MuDISFilter::DecayDaughters(
637 const std::vector<DISparticle>& daughters, const TVector3& vertex) const {
638 if (!fUsePythiaDecays) {
639 std::vector<FilterCandidate> candidates;
640 candidates.reserve(daughters.size());
641 for (const auto& particle : daughters)
642 candidates.push_back({particle, vertex});
643 return candidates;
644 }
645 if (!fPythiaDecayer || !std::isfinite(fTr1Z))
646 throw std::runtime_error("MuDISFilter: Pythia decays require Tr1 geometry");
647
648 std::vector<FilterCandidate> candidates;
649 const double tr1Zmm = 10. * fTr1Z;
650 const auto addParticle = [&candidates](const Pythia8::Particle& particle) {
651 DISparticle daughter;
652 daughter.pid = particle.id();
653 daughter.px = particle.px();
654 daughter.py = particle.py();
655 daughter.pz = particle.pz();
656 daughter.E = particle.e();
657 candidates.push_back(
658 {daughter, TVector3(particle.xProd() / 10., particle.yProd() / 10.,
659 particle.zProd() / 10.)});
660 };
661 for (const auto& daughter : daughters) {
662 fPythiaDecayer->event.reset();
663 const double momentum2 = daughter.px * daughter.px +
664 daughter.py * daughter.py +
665 daughter.pz * daughter.pz;
666 const double mass2 = daughter.E * daughter.E - momentum2;
667 if (mass2 < -1.e-8) {
668 candidates.push_back({daughter, vertex});
669 continue;
670 }
671 const int root = fPythiaDecayer->event.append(
672 daughter.pid, 1, 0, 0, daughter.px, daughter.py, daughter.pz,
673 daughter.E, std::sqrt(std::max(0., mass2)));
674 fPythiaDecayer->event[root].vProd(10. * vertex.X(), 10. * vertex.Y(),
675 10. * vertex.Z(), 0.);
676 // Manually appended particles have tau = 0. Pythia samples lifetimes
677 // for its own decay products, but the original particle needs one here.
678 fPythiaDecayer->event[root].tau(fPythiaDecayer->event[root].tau0() *
679 fPythiaDecayer->rndm.exp());
680
681 std::function<void(int)> decay = [&](int index) {
682 const auto& particle = fPythiaDecayer->event[index];
683 if ((tr1Zmm - particle.zProd()) * particle.pz() <= 0.) {
684 addParticle(particle);
685 return;
686 }
687 if (!fPythiaDecayer->moreDecays(index) ||
688 fPythiaDecayer->event[index].isFinal() ||
689 ((tr1Zmm - fPythiaDecayer->event[index].zDec()) *
690 fPythiaDecayer->event[index].pz() <=
691 0)) {
692 addParticle(fPythiaDecayer->event[index]);
693 return;
694 }
695 for (int child : fPythiaDecayer->event[index].daughterList())
696 decay(child);
697 };
698 decay(root);
699 }
700 return candidates;
701}
702
703bool MuDISFilter::IncludesParticle(const DISparticle& particle) const {
704 return fIncludeMuons || std::abs(particle.pid) != 13;
705}
706
708 double z) const {
709 return (z - candidate.vertex.Z()) * candidate.particle.pz >= 0.;
710}
711
713 const FilterCandidate& candidate) const {
714 const auto& particle = candidate.particle;
715 if (!IncludesParticle(particle) || !PassesChargedMomentumCut(particle) ||
717 return 0.;
718 return Charge(particle);
719}
720
722 double charge, double z,
723 const std::array<double, 4>& bounds) const {
724 if (!IsForwardToPlane(candidate, z)) return false;
725 const auto& particle = candidate.particle;
726 TVector3 hit, momentum;
727 return fPropagator->Extrapolate(
728 charge, candidate.vertex,
729 TVector3(particle.px, particle.py, particle.pz), z, hit,
730 momentum) &&
731 InsideXY(hit, bounds);
732}
733
735 double charge) const {
736 const auto& particle = candidate.particle;
737 const auto& vertex = candidate.vertex;
738 TVector3 position = vertex, momentum(particle.px, particle.py, particle.pz);
739 std::array<unsigned, 5> order = {0, 1, 2, 3, 4};
740 std::sort(order.begin(), order.end(),
741 [this, &particle](unsigned a, unsigned b) {
742 return particle.pz >= 0. ? fStationZ[a] < fStationZ[b]
743 : fStationZ[a] > fStationZ[b];
744 });
745 bool firstPair = false, secondPair = false, TD = false;
746 for (unsigned station : order) {
747 if (!IsForwardToPlane(candidate, fStationZ[station])) continue;
748 TVector3 hit, nextMomentum;
749 if (!fPropagator->Extrapolate(charge, position, momentum,
750 fStationZ[station], hit, nextMomentum))
751 return false;
752 position = hit;
753 momentum = nextMomentum;
754 if (!InsideXY(hit, fStationXY[station])) continue;
755 if (station < 2)
756 firstPair = true;
757 else if (station < 4)
758 secondPair = true;
759 else
760 TD = true;
761 if (firstPair && secondPair && TD) return true;
762 }
763 return false;
764}
765
767 const auto& particle = candidate.particle;
768 if (IsNeutrino(particle) || !IncludesParticle(particle)) return false;
769 const TVector3 minimum(-200., -300., fDetectorVolumeZ.first);
770 const TVector3 maximum(200., 300., fDetectorVolumeZ.second);
771 return fPropagator->IntersectsBox(
772 Charge(particle), candidate.vertex,
773 TVector3(particle.px, particle.py, particle.pz), minimum, maximum);
774}
775
777 const std::vector<FilterCandidate>& candidates, unsigned minimum) const {
778 if (minimum == 0) return true;
779 if (candidates.size() < minimum) return false;
780 // Both charged filters count eligible candidates before expensive transport.
781 unsigned remaining = 0, accepted = 0;
782 std::vector<double> charges;
783 charges.reserve(candidates.size());
784 for (const auto& candidate : candidates) {
785 const double charge = ChargedCandidateCharge(candidate);
786 charges.push_back(charge);
787 if (charge != 0.) ++remaining;
788 }
789 for (std::size_t i = 0; i < candidates.size(); ++i) {
790 if (accepted + remaining < minimum) return false;
791 if (charges[i] == 0.) continue;
792 --remaining;
794 const bool hits =
795 fFilterOption == 1
796 ? HitsTrackingAndTD(candidates[i], charges[i])
797 : HitsDetectorPlane(candidates[i], charges[i], fDetectorZ,
798 {-200., 200., -300., 300.});
799 if (!hits) continue;
800 }
801 if (++accepted >= minimum) return true;
802 }
803 return false;
804}
805
807 TGeoManager* geometry, double z,
808 ShipBFieldMap* muonShieldField) {
809 if (!field)
810 throw std::invalid_argument("Detector acceptance requires a field map");
811 auto propagator = std::make_unique<MagneticTrackPropagator>(field, geometry,
812 muonShieldField);
813 if (muonShieldField) {
814 const auto range = propagator->GetMuonShieldZRange();
815 LOG(info)
816 << "MuDISFilter: muon shield geometry z range [" << range.first << ", "
817 << range.second
818 << "] cm; propagating with shield map including nonzero fringe fields";
819 }
820 const double planeZ = std::isnan(z) ? propagator->GetPlaneZ() : z;
821 if (!std::isfinite(planeZ))
822 throw std::invalid_argument("Detector z must be finite");
823 fTr1Z = propagator->GetPlaneZ("Tr1");
824 try {
825 fTimingDetectorZ = propagator->GetPlaneZ("TimingDetector");
826 fTimingDetectorXY = propagator->GetVolumeExitFaceXY("TimingDetector");
827 } catch (const std::runtime_error&) {
828 fTimingDetectorZ = std::numeric_limits<double>::quiet_NaN();
829 }
831 fPropagator = std::move(propagator);
832 fDetectorZ = planeZ;
834}
835
836bool MuDISFilter::PassFilter(const std::vector<DISparticle>& daughters) const {
838 throw std::runtime_error(
839 "Detector acceptance requires the DIS vertex; use "
840 "PassFilter(daughters, vertex)");
841 return PassFilter(daughters, TVector3());
842}
843
844bool MuDISFilter::PassFilter(const std::vector<DISparticle>& daughters,
845 const TVector3& vertex) const {
846 if (fFilter) return fFilter(daughters);
847 return PassCandidates(DecayDaughters(daughters, vertex));
848}
849
851 const std::vector<FilterCandidate>& candidates) const {
853 throw std::runtime_error(
854 "Filter options 1 and 2 require detector acceptance");
856 throw std::runtime_error(
857 "Configure detector acceptance with geometry and field map first");
858 if (fFilterOption == 2)
859 return std::any_of(candidates.begin(), candidates.end(),
860 [this](const FilterCandidate& candidate) {
861 return HitsDetectorVolume(candidate);
862 });
863 // Option 1 always requires two tracks, independently of the option-0 minimum.
864 return PassChargedCandidates(candidates,
866}
867
870 !std::isfinite(fTimingDetectorZ))
871 return false;
872 return HitsDetectorPlane(candidate, Charge(candidate.particle),
874}
875
877 const std::vector<DISparticle>& daughters,
878 const std::vector<FilterCandidate>& candidates,
879 Histograms* filtered) {
880 unsigned charged = 0;
881 double totalP = 0., chargedP = 0., muonP = 0.;
882 for (const auto& p : daughters) {
883 const int category = DaughterCategory(p);
884 for (auto* target : {&h, filtered}) {
885 if (!target) continue;
886 FillWithFlow(target->dis_pdg, p.pid);
887 FillWithFlow(target->dis_pdgGrouped, category);
888 }
889 const double momentum = std::sqrt(p.px * p.px + p.py * p.py + p.pz * p.pz);
890 totalP += momentum;
891 if (IsCharged(p)) {
892 ++charged;
893 chargedP += momentum;
894 }
895 if (std::abs(p.pid) == 13) muonP += momentum;
896 }
897 unsigned chargedCandidates = 0;
898 double neutralTDEnergy = 0.;
899 for (const auto& candidate : candidates) {
900 if (IsCharged(candidate.particle)) {
901 ++chargedCandidates;
902 } else if (!IsNeutrino(candidate.particle) &&
903 HitsTimingDetector(candidate)) {
904 neutralTDEnergy += candidate.particle.E;
905 }
906 }
907 for (auto* target : {&h, filtered}) {
908 if (!target) continue;
909 FillWithFlow(target->dis_vxz, br.DISvz->at(idis), br.DISvx->at(idis));
910 FillWithFlow(target->dis_vyz, br.DISvz->at(idis), br.DISvy->at(idis));
911 FillWithFlow(target->dis_vxy, br.DISvx->at(idis), br.DISvy->at(idis));
912 FillWithFlow(target->dis_vr,
913 std::hypot(br.DISvx->at(idis), br.DISvy->at(idis)));
914 FillWithFlow(target->dis_vz, br.DISvz->at(idis));
915 FillWithFlow(target->dis_n, daughters.size());
916 FillWithFlow(target->dis_nCharged, charged);
917 FillWithFlow(target->dis_nChargedCandidates, chargedCandidates);
918 FillWithFlow(target->dis_eNeutralTD, neutralTDEnergy);
919 if (totalP > 0.) {
920 FillWithFlow(target->dis_pChargedFrac, chargedP / totalP);
921 FillWithFlow(target->dis_pMuFrac, muonP / totalP);
922 }
923 }
924}
925
927 if (!ftree || !fouttree)
928 throw std::runtime_error("Initialize input and output first");
929 if (fstartEvt < 0) throw std::invalid_argument("Negative start event");
930 const Long64_t end =
931 fnEvts >= 0 ? std::min(Long64_t(fstartEvt) + fnEvts, ftree->GetEntries())
932 : ftree->GetEntries();
933 Long64_t selected = 0, skipped = 0;
934 Long64_t selectedDIS[nMats] = {};
935 double weightedDIS[nMats] = {};
936 Long64_t processedDIS[nMats] = {};
937 double weightedProcessedDIS[nMats] = {};
938 double weightedMuons[nMats] = {}, weightedSelectedMuons[nMats] = {};
939 for (Long64_t event = fstartEvt; event < end; ++event) {
940 if ((event - fstartEvt) % 100 == 0)
941 LOG(info) << "MuDISFilter: processing entry " << event;
942 if (!finEv.PrepareEntry(ftree, event) || ftree->GetEntry(event) <= 0 ||
943 !finEv.mcTrks || finEv.mcTrks->empty() || !finEv.sbtPt ||
944 !finEv.ubtPt || !finEv.sstPt) {
945 ++skipped;
946 continue;
947 }
948 // Check all vector lengths before filling histograms or copying any data.
949 bool valid = true;
950 for (const auto& br : finEv.br) {
951 if (!br.IsValid()) {
952 valid = false;
953 break;
954 }
955 }
956 if (!valid) {
957 LOG(error) << "MuDISFilter: malformed entry " << event << "; skipping";
958 ++skipped;
959 continue;
960 }
961 initEvent();
962 const auto& muon = finEv.mcTrks->at(0);
963 const double muonP = muon.GetP(), muonPt = muon.GetPt();
964 bool keep = false;
965 for (unsigned imat = 0; imat < nMats; ++imat) {
966 const auto& in = finEv.br[imat];
967 auto& out = foutEv.br[imat];
968 out.wDIS = in.wDIS;
969 out.nDISevtsGenerated = in.nDISevtsGenerated;
970 out.pPythia = in.pPythia;
971 std::size_t offset = 0;
972 for (int idis = 0; idis < in.nDISevts; ++idis) {
973 const auto endOffset = offset + in.nDISdau->at(idis);
974 std::vector<DISparticle> daughters(
975 in.DISparticles->begin() + offset,
976 in.DISparticles->begin() + endOffset);
977 offset = endOffset;
978 const TVector3 vertex(in.DISvx->at(idis), in.DISvy->at(idis),
979 in.DISvz->at(idis));
980 std::vector<FilterCandidate> candidates;
981 if (fFilter) {
982 candidates.reserve(daughters.size());
983 for (const auto& daughter : daughters)
984 candidates.push_back({daughter, vertex});
985 } else {
986 candidates = DecayDaughters(daughters, vertex);
987 }
988 bool identical = candidates.size() == daughters.size();
989 for (std::size_t i = 0; identical && i < daughters.size(); ++i) {
990 const auto& original = daughters[i];
991 const auto& candidate = candidates[i];
992 identical = candidate.particle.pid == original.pid &&
993 candidate.particle.px == original.px &&
994 candidate.particle.py == original.py &&
995 candidate.particle.pz == original.pz &&
996 candidate.particle.E == original.E &&
997 candidate.vertex.Z() == vertex.Z();
998 }
999 if (!identical) {
1000 std::ostringstream original;
1001 for (const auto& daughter : daughters) original << ' ' << daughter;
1002 LOG(debug) << "MuDISFilter: " << MatTypeStr[imat].Data() << " DIS "
1003 << idis << " at z=" << vertex.Z()
1004 << " cm original daughters:" << original.str();
1005 std::ostringstream final;
1006 for (const auto& candidate : candidates) {
1007 const auto& daughter = candidate.particle;
1008 final << " [" << daughter.pid << ',' << daughter.px << ','
1009 << daughter.py << ',' << daughter.pz << ',' << daughter.E
1010 << "; vz=" << candidate.vertex.Z() << ']';
1011 }
1012 LOG(debug) << "MuDISFilter: " << MatTypeStr[imat].Data() << " DIS "
1013 << idis << " final stable daughters:" << final.str();
1014 }
1015 const bool accepted =
1016 fFilter ? fFilter(daughters) : PassCandidates(candidates);
1017 FillDIS(hist_all[imat], in, idis, daughters, candidates,
1018 accepted ? &hist_filt[imat] : nullptr);
1019 FillFilterEfficiencyHistograms(imat, muonP, muonPt, muon.GetStartX(),
1020 muon.GetStartY(), vertex.Z(), in.wDIS,
1021 accepted);
1022 if (!accepted) continue;
1023 ++out.nDISevts;
1024 out.DISxsec.push_back(in.DISxsec->at(idis));
1025 out.DIStarget.push_back(in.DIStarget->at(idis));
1026 out.DISvx.push_back(in.DISvx->at(idis));
1027 out.DISvy.push_back(in.DISvy->at(idis));
1028 out.DISvz.push_back(in.DISvz->at(idis));
1029 out.DISvt.push_back(in.DISvt->at(idis));
1030 out.nDISdau.push_back(daughters.size());
1031 out.DISparticles.insert(out.DISparticles.end(), daughters.begin(),
1032 daughters.end());
1033 keep = true;
1034 }
1035 auto fillMuon = [muonP, muonPt, &in](Histograms& h, int count) {
1036 FillWithFlow(h.mu_p, muonP);
1037 FillWithFlow(h.mu_pt, muonPt);
1038 FillWithFlow(h.mu_ppt, muonP, muonPt);
1039 FillWithFlow(h.mu_ndis, count);
1040 FillWithFlow(h.mu_wdis, in.wDIS);
1041 };
1042 fillMuon(hist_all[imat], in.nDISevts);
1043 if (out.nDISevts > 0) fillMuon(hist_filt[imat], out.nDISevts);
1044 selectedDIS[imat] += out.nDISevts;
1045 if (out.nDISevts > 0) weightedDIS[imat] += out.nDISevts * in.wDIS;
1046 processedDIS[imat] += in.nDISevts;
1047 if (in.nDISevts > 0) weightedProcessedDIS[imat] += in.nDISevts * in.wDIS;
1048 weightedMuons[imat] += in.wDIS;
1049 if (out.nDISevts > 0) weightedSelectedMuons[imat] += in.wDIS;
1050 }
1051 if (keep) {
1052 foutEv.mcTrks = *finEv.mcTrks;
1053 foutEv.sbtPt = *finEv.sbtPt;
1054 foutEv.ubtPt = *finEv.ubtPt;
1055 foutEv.sstPt = *finEv.sstPt;
1056 foutEv.tdPt = *finEv.tdPt;
1057 foutEv.pathLength = finEv.pathLength;
1058 foutEv.pathLengthByMat = finEv.pathLengthByMat;
1059 if (fouttree->Fill() < 0)
1060 throw std::runtime_error("Failed writing MuonDIS entry");
1061 ++selected;
1062 }
1063 }
1064 LOG(info) << "MuDISFilter: saved " << selected << " muon entries; skipped "
1065 << skipped << " unreadable or malformed entries.";
1066 for (unsigned imat = 0; imat < nMats; ++imat) {
1067 LOG(info) << "MuDISFilter: selected DIS events in "
1068 << MatTypeStr[imat].Data() << ": raw = " << selectedDIS[imat]
1069 << ", weighted = " << weightedDIS[imat];
1070 auto* counts =
1071 new TH1D("filter_counts", "Filter counts;Sample;Count", 8, 0., 8.);
1072 counts->SetDirectory(
1073 fouttree->GetDirectory()->GetDirectory(MatTypeStr[imat].Data()));
1074 const char* labels[] = {"muons_processed_raw", "muons_processed_weighted",
1075 "muons_selected_raw", "muons_selected_weighted",
1076 "dis_processed_raw", "dis_processed_weighted",
1077 "dis_selected_raw", "dis_selected_weighted"};
1078 const double values[] = {
1079 hist_all[imat].mu_ppt->GetEntries(), weightedMuons[imat],
1080 hist_filt[imat].mu_ppt->GetEntries(), weightedSelectedMuons[imat],
1081 static_cast<double>(processedDIS[imat]), weightedProcessedDIS[imat],
1082 static_cast<double>(selectedDIS[imat]), weightedDIS[imat]};
1083 for (int bin = 1; bin <= 8; ++bin) {
1084 counts->GetXaxis()->SetBinLabel(bin, labels[bin - 1]);
1085 counts->SetBinContent(bin, values[bin - 1]);
1086 }
1087 }
1088}
const Int_t debug
double GetPlaneZ(const char *volumeName="Tr1") const
std::pair< double, double > GetVolumeZRange(const char *volumeName) const
std::array< double, 4 > GetVolumeExitFaceXY(const char *volumeName) const
void SetFilterEfficiencyBinning(double xmin, double xmax, unsigned xbins, double ymin, double ymax, unsigned ybins, double zmin, double zmax, unsigned zbins)
int DaughterCategory(const DISparticle &particle) const
double ChargedCandidateCharge(const FilterCandidate &candidate) const
ShipMuDIS::MuonInBranches finEv
std::unique_ptr< MagneticTrackPropagator > fPropagator
Runtime decayer.
ShipMuDIS::MuonBranches foutEv
std::vector< FilterCandidate > DecayDaughters(const std::vector< DISparticle > &daughters, const TVector3 &vertex) const
std::unique_ptr< Pythia8::Pythia > fPythiaDecayer
TChain * ftree
User-supplied runtime predicate.
bool HitsDetectorVolume(const FilterCandidate &candidate) const
void SetUsePythiaDecays(bool enabled)
Bool_t InitFile(const char *, int)
TDatabasePDG * fPDG
std::array< double, 4 > fTimingDetectorXY
int fnEvts
don't make it persistent, magic ROOT command
double fTimingDetectorZ
Filter fFilter
Runtime transport.
unsigned fFilterOption
Histograms BookHistograms(TDirectory *dir, const TString &mat, const TString &label="")
bool IsCharged(const DISparticle &particle) const
std::array< double, 4 > fEfficiencyXYBounds
bool HitsTrackingAndTD(const FilterCandidate &candidate, double charge) const
Histograms hist_filt[ShipMuDIS::nMats]
bool fUsePythiaDecays
void FillDIS(Histograms &h, const ShipMuDIS::MuonDISInBranches &br, int idis, const std::vector< DISparticle > &daughters, const std::vector< FilterCandidate > &candidates, Histograms *filtered)
std::array< double, 5 > fStationZ
std::pair< double, double > fDetectorVolumeZ
Tr1, Tr2, Tr3, Tr4, TD plane.
static constexpr unsigned kMomentumBins
void SetDetectorAcceptance(ShipBFieldMap *field, TGeoManager *geometry, double z=std::numeric_limits< double >::quiet_NaN(), ShipBFieldMap *muonShieldField=nullptr)
TTree * fouttree
static constexpr unsigned kPtBins
void SetPythiaDecaySeed(unsigned seed)
bool IsForwardToPlane(const FilterCandidate &candidate, double z) const
void ProcessEvents()
bool PassCandidates(const std::vector< FilterCandidate > &candidates) const
bool PassChargedCandidates(const std::vector< FilterCandidate > &candidates, unsigned minimum) const
Bool_t InitFiles(const std::vector< std::string > &, int)
void FillFilterEfficiencyHistograms(unsigned material, double momentum, double pt, double x, double y, double z, double weight, bool passed)
double Charge(const DISparticle &particle) const
std::array< double, 2 > fEfficiencyZBounds
unsigned fEfficiencyZBins
void init(const int &aEvts, const int &aStart)
Histograms hist_all[ShipMuDIS::nMats]
unsigned fMinChargedDaughters
void process_file(const std::string &input, const std::string &output)
void ConfigureFilterGeometry(unsigned option, const MagneticTrackPropagator &propagator)
unsigned fEfficiencyYBins
void SetFilterOption(unsigned option)
bool fIncludeMuons
double fDetectorZ
static constexpr unsigned kEfficiencyMaterials
bool fUseDetectorAcceptance
unsigned fEfficiencyXBins
bool HitsDetectorPlane(const FilterCandidate &candidate, double charge, double z, const std::array< double, 4 > &bounds) const
bool IncludesParticle(const DISparticle &particle) const
bool HitsTimingDetector(const FilterCandidate &candidate) const
bool fDetailedHistograms
void BookFilterEfficiencyHistograms(TDirectory *dir)
unsigned fPythiaDecaySeed
FilterEfficiencyHistograms fFilterEfficiency
bool PassFilter(const std::vector< DISparticle > &daughters) const
void InitialisePythiaDecayer()
std::array< std::array< double, 4 >, 5 > fStationXY
FairLogger * fLogger
Class that defines a (3d) magnetic field map (distances in cm, fields in tesla).
const std::array< TString, nMats > MatTypeStr
Definition MuDISDefs.h:45
width(particle)
Definition rpvsusy.py:91
bool Setup(TTree *tree)
Definition MuDISDefs.h:325