FairShip
Loading...
Searching...
No Matches
MuDISFilter Class Reference

#include <MuDISFilter.h>

Collaboration diagram for MuDISFilter:
[legend]

Classes

struct  FilterCandidate
struct  FilterEfficiencyHistograms

Public Types

using Filter = std::function<bool(const std::vector<DISparticle>&)>

Public Member Functions

 MuDISFilter ()
 ~MuDISFilter ()
 MuDISFilter (const MuDISFilter &)=delete
MuDISFilter & operator= (const MuDISFilter &)=delete
void SetFilter (Filter filter)
void SetFilterOption (unsigned option)
unsigned GetFilterOption () const
void SetMinChargedDaughters (unsigned minimum)
void SetIncludeMuons (bool include)
void SetDetectorAcceptance (ShipBFieldMap *field, TGeoManager *geometry, double z=std::numeric_limits< double >::quiet_NaN(), ShipBFieldMap *muonShieldField=nullptr)
void SetUseDetectorAcceptance (bool enabled)
void SetUsePythiaDecays (bool enabled)
void SetPythiaDecaySeed (unsigned seed)
void SetFilterEfficiencyBinning (double xmin, double xmax, unsigned xbins, double ymin, double ymax, unsigned ybins, double zmin, double zmax, unsigned zbins)
void SetDetailedHistograms (bool enabled)
double GetDetectorZ () const
bool PassFilter (const std::vector< DISparticle > &daughters) const
bool PassFilter (const std::vector< DISparticle > &daughters, const TVector3 &vertex) const
Histograms BookHistograms (TDirectory *dir, const TString &mat, const TString &label="")
void init (const int &aEvts, const int &aStart)
Bool_t InitFile (const char *, int)
Bool_t InitFile (const char *)
Bool_t InitFiles (const std::vector< std::string > &, int)
Bool_t InitFiles (const std::vector< std::string > &)
void process_file (const std::string &input, const std::string &output)
void process_file (const std::vector< std::string > &input, const std::string &output)
void initEvent ()
void ProcessEvents ()

Private Types

using EfficiencyMaps
using EfficiencyZHistograms

Private Member Functions

void ConfigureFilterGeometry (unsigned option, const MagneticTrackPropagator &propagator)
void InitialisePythiaDecayer ()
std::vector< FilterCandidate > DecayDaughters (const std::vector< DISparticle > &daughters, const TVector3 &vertex) const
bool PassCandidates (const std::vector< FilterCandidate > &candidates) const
bool IncludesParticle (const DISparticle &particle) const
bool IsForwardToPlane (const FilterCandidate &candidate, double z) const
double ChargedCandidateCharge (const FilterCandidate &candidate) const
bool PassChargedCandidates (const std::vector< FilterCandidate > &candidates, unsigned minimum) const
bool HitsDetectorVolume (const FilterCandidate &candidate) const
bool HitsDetectorPlane (const FilterCandidate &candidate, double charge, double z, const std::array< double, 4 > &bounds) const
bool HitsTimingDetector (const FilterCandidate &candidate) const
bool HitsTrackingAndTD (const FilterCandidate &candidate, double charge) const
bool IsCharged (const DISparticle &particle) const
double Charge (const DISparticle &particle) const
int DaughterCategory (const DISparticle &particle) const
void FillDIS (Histograms &h, const ShipMuDIS::MuonDISInBranches &br, int idis, const std::vector< DISparticle > &daughters, const std::vector< FilterCandidate > &candidates, Histograms *filtered)
void BookFilterEfficiencyHistograms (TDirectory *dir)
void FillFilterEfficiencyHistograms (unsigned material, double momentum, double pt, double x, double y, double z, double weight, bool passed)

Private Attributes

unsigned fMinChargedDaughters = 2
unsigned fFilterOption = 0
std::array< std::array< double, 4 >, 5 > fStationXY = {}
std::array< double, 4 > fTimingDetectorXY = {}
std::array< double, 5 > fStationZ = {}
std::pair< double, double > fDetectorVolumeZ = {0., 0.}
 Tr1, Tr2, Tr3, Tr4, TD plane.
bool fIncludeMuons = true
bool fUseDetectorAcceptance = true
double fDetectorZ = std::numeric_limits<double>::quiet_NaN()
double fTr1Z = std::numeric_limits<double>::quiet_NaN()
double fTimingDetectorZ = std::numeric_limits<double>::quiet_NaN()
bool fUsePythiaDecays = false
unsigned fPythiaDecaySeed = 0
std::unique_ptr< Pythia8::Pythia > fPythiaDecayer
std::unique_ptr< MagneticTrackPropagator > fPropagator
 Runtime decayer.
Filter fFilter
 Runtime transport.
TChain * ftree
 User-supplied runtime predicate.
ShipMuDIS::MuonInBranches finEv
TTree * fouttree
ShipMuDIS::MuonBranches foutEv
FairLogger * fLogger
int fnEvts
 don't make it persistent, magic ROOT command
int fstartEvt
TDatabasePDG * fPDG
Histograms hist_all [ShipMuDIS::nMats]
Histograms hist_filt [ShipMuDIS::nMats]
FilterEfficiencyHistograms fFilterEfficiency
bool fDetailedHistograms = false
std::array< double, 4 > fEfficiencyXYBounds = {-200., 200., -300., 300.}
unsigned fEfficiencyXBins = 5
unsigned fEfficiencyYBins = 5
std::array< double, 2 > fEfficiencyZBounds = {2500., 9500.}
unsigned fEfficiencyZBins = 70

Static Private Attributes

static constexpr unsigned kMomentumBins = 4
static constexpr unsigned kPtBins = 5
static constexpr unsigned kEfficiencyMaterials

Detailed Description

Definition at line 54 of file MuDISFilter.h.

Member Typedef Documentation

◆ EfficiencyMaps

Initial value:
std::array<std::array<std::array<TH2D*, kEfficiencyMaterials>, kPtBins>,
static constexpr unsigned kMomentumBins
static constexpr unsigned kPtBins

Definition at line 140 of file MuDISFilter.h.

◆ EfficiencyZHistograms

Initial value:
std::array<
std::array<
std::vector<std::vector<std::array<TH1D*, kEfficiencyMaterials>>>,

Definition at line 143 of file MuDISFilter.h.

◆ Filter

using MuDISFilter::Filter = std::function<bool(const std::vector<DISparticle>&)>

Definition at line 65 of file MuDISFilter.h.

Constructor & Destructor Documentation

◆ MuDISFilter() [1/2]

MuDISFilter::MuDISFilter ( )

default constructor

Definition at line 99 of file MuDISFilter.cxx.

99 {
100 ftree = nullptr;
101 fouttree = nullptr;
102
103 fLogger = FairLogger::GetLogger();
104 fnEvts = -1;
105 fstartEvt = 0;
106 fPDG = TDatabasePDG::Instance();
107}
TChain * ftree
User-supplied runtime predicate.
TDatabasePDG * fPDG
int fnEvts
don't make it persistent, magic ROOT command
TTree * fouttree
FairLogger * fLogger

◆ ~MuDISFilter()

MuDISFilter::~MuDISFilter ( )

destructor

Definition at line 509 of file MuDISFilter.cxx.

509{ delete ftree; }

◆ MuDISFilter() [2/2]

MuDISFilter::MuDISFilter ( const MuDISFilter & )
delete

Member Function Documentation

◆ BookFilterEfficiencyHistograms()

void MuDISFilter::BookFilterEfficiencyHistograms ( TDirectory * dir)
private

Definition at line 236 of file MuDISFilter.cxx.

236 {
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}
std::array< double, 4 > fEfficiencyXYBounds
std::array< double, 2 > fEfficiencyZBounds
unsigned fEfficiencyZBins
unsigned fEfficiencyYBins
static constexpr unsigned kEfficiencyMaterials
unsigned fEfficiencyXBins
bool fDetailedHistograms
FilterEfficiencyHistograms fFilterEfficiency
const std::array< TString, nMats > MatTypeStr
Definition MuDISDefs.h:45

◆ BookHistograms()

Histograms MuDISFilter::BookHistograms ( TDirectory * dir,
const TString & mat,
const TString & label = "" )

Definition at line 133 of file MuDISFilter.cxx.

134 {
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}

◆ Charge()

double MuDISFilter::Charge ( const DISparticle & particle) const
private

Definition at line 520 of file MuDISFilter.cxx.

520 {
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}

◆ ChargedCandidateCharge()

double MuDISFilter::ChargedCandidateCharge ( const FilterCandidate & candidate) const
private

Definition at line 712 of file MuDISFilter.cxx.

713 {
714 const auto& particle = candidate.particle;
715 if (!IncludesParticle(particle) || !PassesChargedMomentumCut(particle) ||
717 return 0.;
718 return Charge(particle);
719}
bool IsForwardToPlane(const FilterCandidate &candidate, double z) const
double Charge(const DISparticle &particle) const
double fDetectorZ
bool fUseDetectorAcceptance
bool IncludesParticle(const DISparticle &particle) const

◆ ConfigureFilterGeometry()

void MuDISFilter::ConfigureFilterGeometry ( unsigned option,
const MagneticTrackPropagator & propagator )
private

Definition at line 563 of file MuDISFilter.cxx.

564 {
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}
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
std::array< double, 5 > fStationZ
std::pair< double, double > fDetectorVolumeZ
Tr1, Tr2, Tr3, Tr4, TD plane.
std::array< std::array< double, 4 >, 5 > fStationXY
int i
Definition ShipAna.py:108

◆ DaughterCategory()

int MuDISFilter::DaughterCategory ( const DISparticle & particle) const
private

Definition at line 529 of file MuDISFilter.cxx.

529 {
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}

◆ DecayDaughters()

std::vector< MuDISFilter::FilterCandidate > MuDISFilter::DecayDaughters ( const std::vector< DISparticle > & daughters,
const TVector3 & vertex ) const
private

Definition at line 636 of file MuDISFilter.cxx.

637 {
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}
std::unique_ptr< Pythia8::Pythia > fPythiaDecayer
bool fUsePythiaDecays

◆ FillDIS()

void MuDISFilter::FillDIS ( Histograms & h,
const ShipMuDIS::MuonDISInBranches & br,
int idis,
const std::vector< DISparticle > & daughters,
const std::vector< FilterCandidate > & candidates,
Histograms * filtered )
private

Definition at line 876 of file MuDISFilter.cxx.

879 {
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}
int DaughterCategory(const DISparticle &particle) const
bool IsCharged(const DISparticle &particle) const
bool HitsTimingDetector(const FilterCandidate &candidate) const

◆ FillFilterEfficiencyHistograms()

void MuDISFilter::FillFilterEfficiencyHistograms ( unsigned material,
double momentum,
double pt,
double x,
double y,
double z,
double weight,
bool passed )
private

Definition at line 292 of file MuDISFilter.cxx.

295 {
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}

◆ GetDetectorZ()

double MuDISFilter::GetDetectorZ ( ) const
inline

Definition at line 87 of file MuDISFilter.h.

87{ return fDetectorZ; }

◆ GetFilterOption()

unsigned MuDISFilter::GetFilterOption ( ) const
inline

Definition at line 68 of file MuDISFilter.h.

68{ return fFilterOption; }
unsigned fFilterOption

◆ HitsDetectorPlane()

bool MuDISFilter::HitsDetectorPlane ( const FilterCandidate & candidate,
double charge,
double z,
const std::array< double, 4 > & bounds ) const
private

Definition at line 721 of file MuDISFilter.cxx.

723 {
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}
std::unique_ptr< MagneticTrackPropagator > fPropagator
Runtime decayer.

◆ HitsDetectorVolume()

bool MuDISFilter::HitsDetectorVolume ( const FilterCandidate & candidate) const
private

Definition at line 766 of file MuDISFilter.cxx.

766 {
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}

◆ HitsTimingDetector()

bool MuDISFilter::HitsTimingDetector ( const FilterCandidate & candidate) const
private

Definition at line 868 of file MuDISFilter.cxx.

868 {
870 !std::isfinite(fTimingDetectorZ))
871 return false;
872 return HitsDetectorPlane(candidate, Charge(candidate.particle),
874}
std::array< double, 4 > fTimingDetectorXY
double fTimingDetectorZ
bool HitsDetectorPlane(const FilterCandidate &candidate, double charge, double z, const std::array< double, 4 > &bounds) const

◆ HitsTrackingAndTD()

bool MuDISFilter::HitsTrackingAndTD ( const FilterCandidate & candidate,
double charge ) const
private

Definition at line 734 of file MuDISFilter.cxx.

735 {
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}

◆ IncludesParticle()

bool MuDISFilter::IncludesParticle ( const DISparticle & particle) const
private

Definition at line 703 of file MuDISFilter.cxx.

703 {
704 return fIncludeMuons || std::abs(particle.pid) != 13;
705}
bool fIncludeMuons

◆ init()

void MuDISFilter::init ( const int & aEvts,
const int & aStart )

Definition at line 315 of file MuDISFilter.cxx.

315 {
316 if (aEvts < -1 || aStart < 0)
317 throw std::invalid_argument("Invalid event range");
318 fnEvts = aEvts;
319 fstartEvt = aStart;
320}

◆ initEvent()

void MuDISFilter::initEvent ( )

Definition at line 511 of file MuDISFilter.cxx.

511 {
512 foutEv.initEvent();
513 for (unsigned i = 0; i < nMats; ++i) foutEv.br[i].initEvent(0);
514}
ShipMuDIS::MuonBranches foutEv

◆ InitFile() [1/2]

Bool_t MuDISFilter::InitFile ( const char * fileName)

Definition at line 322 of file MuDISFilter.cxx.

322 {
323 return InitFile(fileName, 0);
324}
Bool_t InitFile(const char *, int)

◆ InitFile() [2/2]

Bool_t MuDISFilter::InitFile ( const char * fileName,
int startEvent )

Definition at line 331 of file MuDISFilter.cxx.

331 {
332 std::vector<std::string> fileNames = {fileName};
333 return InitFiles(fileNames, startEvent);
334}
Bool_t InitFiles(const std::vector< std::string > &, int)

◆ InitFiles() [1/2]

Bool_t MuDISFilter::InitFiles ( const std::vector< std::string > & fileNames)

Definition at line 326 of file MuDISFilter.cxx.

326 {
327 return InitFiles(fileNames, 0);
328}

◆ InitFiles() [2/2]

Bool_t MuDISFilter::InitFiles ( const std::vector< std::string > & fileNames,
int startEvent )

Definition at line 336 of file MuDISFilter.cxx.

337 {
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}
ShipMuDIS::MuonInBranches finEv
bool Setup(TTree *tree)
Definition MuDISDefs.h:325

◆ InitialisePythiaDecayer()

void MuDISFilter::InitialisePythiaDecayer ( )
private

Definition at line 593 of file MuDISFilter.cxx.

593 {
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}
unsigned fPythiaDecaySeed

◆ IsCharged()

bool MuDISFilter::IsCharged ( const DISparticle & particle) const
private

Definition at line 516 of file MuDISFilter.cxx.

516 {
517 return Charge(particle) != 0.;
518}

◆ IsForwardToPlane()

bool MuDISFilter::IsForwardToPlane ( const FilterCandidate & candidate,
double z ) const
private

Definition at line 707 of file MuDISFilter.cxx.

708 {
709 return (z - candidate.vertex.Z()) * candidate.particle.pz >= 0.;
710}

◆ operator=()

MuDISFilter & MuDISFilter::operator= ( const MuDISFilter & )
delete

◆ PassCandidates()

bool MuDISFilter::PassCandidates ( const std::vector< FilterCandidate > & candidates) const
private

Definition at line 850 of file MuDISFilter.cxx.

851 {
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}
bool PassChargedCandidates(const std::vector< FilterCandidate > &candidates, unsigned minimum) const
unsigned fMinChargedDaughters

◆ PassChargedCandidates()

bool MuDISFilter::PassChargedCandidates ( const std::vector< FilterCandidate > & candidates,
unsigned minimum ) const
private

Definition at line 776 of file MuDISFilter.cxx.

777 {
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}
double ChargedCandidateCharge(const FilterCandidate &candidate) const
bool HitsTrackingAndTD(const FilterCandidate &candidate, double charge) const

◆ PassFilter() [1/2]

bool MuDISFilter::PassFilter ( const std::vector< DISparticle > & daughters) const

Definition at line 836 of file MuDISFilter.cxx.

836 {
838 throw std::runtime_error(
839 "Detector acceptance requires the DIS vertex; use "
840 "PassFilter(daughters, vertex)");
841 return PassFilter(daughters, TVector3());
842}
Filter fFilter
Runtime transport.
bool PassFilter(const std::vector< DISparticle > &daughters) const

◆ PassFilter() [2/2]

bool MuDISFilter::PassFilter ( const std::vector< DISparticle > & daughters,
const TVector3 & vertex ) const

Definition at line 844 of file MuDISFilter.cxx.

845 {
846 if (fFilter) return fFilter(daughters);
847 return PassCandidates(DecayDaughters(daughters, vertex));
848}
std::vector< FilterCandidate > DecayDaughters(const std::vector< DISparticle > &daughters, const TVector3 &vertex) const
bool PassCandidates(const std::vector< FilterCandidate > &candidates) const

◆ process_file() [1/2]

void MuDISFilter::process_file ( const std::string & input,
const std::string & output )

Definition at line 386 of file MuDISFilter.cxx.

387 {
388 std::vector<std::string> fileNames = {input};
389 return process_file(fileNames, output);
390}
void process_file(const std::string &input, const std::string &output)

◆ process_file() [2/2]

void MuDISFilter::process_file ( const std::vector< std::string > & input,
const std::string & output )

Definition at line 392 of file MuDISFilter.cxx.

393 {
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}
Histograms BookHistograms(TDirectory *dir, const TString &mat, const TString &label="")
Histograms hist_filt[ShipMuDIS::nMats]
void ProcessEvents()
Histograms hist_all[ShipMuDIS::nMats]
void BookFilterEfficiencyHistograms(TDirectory *dir)

◆ ProcessEvents()

void MuDISFilter::ProcessEvents ( )

Definition at line 926 of file MuDISFilter.cxx.

926 {
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
void FillDIS(Histograms &h, const ShipMuDIS::MuonDISInBranches &br, int idis, const std::vector< DISparticle > &daughters, const std::vector< FilterCandidate > &candidates, Histograms *filtered)
void FillFilterEfficiencyHistograms(unsigned material, double momentum, double pt, double x, double y, double z, double weight, bool passed)

◆ SetDetailedHistograms()

void MuDISFilter::SetDetailedHistograms ( bool enabled)
inline

Definition at line 86 of file MuDISFilter.h.

86{ fDetailedHistograms = enabled; }

◆ SetDetectorAcceptance()

void MuDISFilter::SetDetectorAcceptance ( ShipBFieldMap * field,
TGeoManager * geometry,
double z = std::numeric_limits<double>::quiet_NaN(),
ShipBFieldMap * muonShieldField = nullptr )

Definition at line 806 of file MuDISFilter.cxx.

808 {
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}
void ConfigureFilterGeometry(unsigned option, const MagneticTrackPropagator &propagator)

◆ SetFilter()

void MuDISFilter::SetFilter ( Filter filter)
inline

Definition at line 66 of file MuDISFilter.h.

66{ fFilter = std::move(filter); }

◆ SetFilterEfficiencyBinning()

void MuDISFilter::SetFilterEfficiencyBinning ( double xmin,
double xmax,
unsigned xbins,
double ymin,
double ymax,
unsigned ybins,
double zmin,
double zmax,
unsigned zbins )

Definition at line 109 of file MuDISFilter.cxx.

113 {
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;
130 fEfficiencyZBins = zbins;
131}

◆ SetFilterOption()

void MuDISFilter::SetFilterOption ( unsigned option)

Definition at line 586 of file MuDISFilter.cxx.

586 {
587 if (option > 2)
588 throw std::invalid_argument("Filter option must be 0, 1 or 2");
590 fFilterOption = option;
591}

◆ SetIncludeMuons()

void MuDISFilter::SetIncludeMuons ( bool include)
inline

Definition at line 73 of file MuDISFilter.h.

include(${CMAKE_SOURCE_DIR}/cmake/modules/FairShipGitVersion.cmake) if(NOT GIT_DESCRIBE_RESULT EQUAL 0) message(WARNING "Git not found or no tags — using fallback version $

◆ SetMinChargedDaughters()

void MuDISFilter::SetMinChargedDaughters ( unsigned minimum)
inline

Definition at line 70 of file MuDISFilter.h.

70 {
71 fMinChargedDaughters = minimum;
72 }

◆ SetPythiaDecaySeed()

void MuDISFilter::SetPythiaDecaySeed ( unsigned seed)

Definition at line 631 of file MuDISFilter.cxx.

631 {
634}
void InitialisePythiaDecayer()

◆ SetUseDetectorAcceptance()

void MuDISFilter::SetUseDetectorAcceptance ( bool enabled)
inline

Definition at line 78 of file MuDISFilter.h.

78 {
79 fUseDetectorAcceptance = enabled;
80 }

◆ SetUsePythiaDecays()

void MuDISFilter::SetUsePythiaDecays ( bool enabled)

Definition at line 623 of file MuDISFilter.cxx.

623 {
624 fUsePythiaDecays = enabled;
625 if (enabled)
627 else
628 fPythiaDecayer.reset();
629}

Member Data Documentation

◆ fDetailedHistograms

bool MuDISFilter::fDetailedHistograms = false
private

Definition at line 188 of file MuDISFilter.h.

◆ fDetectorVolumeZ

std::pair<double, double> MuDISFilter::fDetectorVolumeZ = {0., 0.}
private

Tr1, Tr2, Tr3, Tr4, TD plane.

Definition at line 163 of file MuDISFilter.h.

163{0., 0.};

◆ fDetectorZ

double MuDISFilter::fDetectorZ = std::numeric_limits<double>::quiet_NaN()
private

Definition at line 166 of file MuDISFilter.h.

◆ fEfficiencyXBins

unsigned MuDISFilter::fEfficiencyXBins = 5
private

Definition at line 190 of file MuDISFilter.h.

◆ fEfficiencyXYBounds

std::array<double, 4> MuDISFilter::fEfficiencyXYBounds = {-200., 200., -300., 300.}
private

Definition at line 189 of file MuDISFilter.h.

189{-200., 200., -300., 300.};

◆ fEfficiencyYBins

unsigned MuDISFilter::fEfficiencyYBins = 5
private

Definition at line 191 of file MuDISFilter.h.

◆ fEfficiencyZBins

unsigned MuDISFilter::fEfficiencyZBins = 70
private

Definition at line 193 of file MuDISFilter.h.

◆ fEfficiencyZBounds

std::array<double, 2> MuDISFilter::fEfficiencyZBounds = {2500., 9500.}
private

Definition at line 192 of file MuDISFilter.h.

192{2500., 9500.};

◆ fFilter

Filter MuDISFilter::fFilter
private

Runtime transport.

Definition at line 173 of file MuDISFilter.h.

◆ fFilterEfficiency

FilterEfficiencyHistograms MuDISFilter::fFilterEfficiency
private

Definition at line 187 of file MuDISFilter.h.

◆ fFilterOption

unsigned MuDISFilter::fFilterOption = 0
private

Definition at line 159 of file MuDISFilter.h.

◆ fIncludeMuons

bool MuDISFilter::fIncludeMuons = true
private

Definition at line 164 of file MuDISFilter.h.

◆ finEv

ShipMuDIS::MuonInBranches MuDISFilter::finEv
private

Definition at line 175 of file MuDISFilter.h.

◆ fLogger

FairLogger* MuDISFilter::fLogger
private

Definition at line 180 of file MuDISFilter.h.

◆ fMinChargedDaughters

unsigned MuDISFilter::fMinChargedDaughters = 2
private

Definition at line 158 of file MuDISFilter.h.

◆ fnEvts

int MuDISFilter::fnEvts
private

don't make it persistent, magic ROOT command

Definition at line 181 of file MuDISFilter.h.

◆ foutEv

ShipMuDIS::MuonBranches MuDISFilter::foutEv
private

Definition at line 178 of file MuDISFilter.h.

◆ fouttree

TTree* MuDISFilter::fouttree
private

Definition at line 177 of file MuDISFilter.h.

◆ fPDG

TDatabasePDG* MuDISFilter::fPDG
private

Definition at line 184 of file MuDISFilter.h.

◆ fPropagator

std::unique_ptr<MagneticTrackPropagator> MuDISFilter::fPropagator
private

Runtime decayer.

Definition at line 172 of file MuDISFilter.h.

◆ fPythiaDecayer

std::unique_ptr<Pythia8::Pythia> MuDISFilter::fPythiaDecayer
mutableprivate

Definition at line 171 of file MuDISFilter.h.

◆ fPythiaDecaySeed

unsigned MuDISFilter::fPythiaDecaySeed = 0
private

Definition at line 170 of file MuDISFilter.h.

◆ fstartEvt

int MuDISFilter::fstartEvt
private

Definition at line 182 of file MuDISFilter.h.

◆ fStationXY

std::array<std::array<double, 4>, 5> MuDISFilter::fStationXY = {}
private

Definition at line 160 of file MuDISFilter.h.

160{};

◆ fStationZ

std::array<double, 5> MuDISFilter::fStationZ = {}
private

Definition at line 162 of file MuDISFilter.h.

162{};

◆ fTimingDetectorXY

std::array<double, 4> MuDISFilter::fTimingDetectorXY = {}
private

Definition at line 161 of file MuDISFilter.h.

161{};

◆ fTimingDetectorZ

double MuDISFilter::fTimingDetectorZ = std::numeric_limits<double>::quiet_NaN()
private

Definition at line 168 of file MuDISFilter.h.

◆ fTr1Z

double MuDISFilter::fTr1Z = std::numeric_limits<double>::quiet_NaN()
private

Definition at line 167 of file MuDISFilter.h.

◆ ftree

TChain* MuDISFilter::ftree
private

User-supplied runtime predicate.

Definition at line 174 of file MuDISFilter.h.

◆ fUseDetectorAcceptance

bool MuDISFilter::fUseDetectorAcceptance = true
private

Definition at line 165 of file MuDISFilter.h.

◆ fUsePythiaDecays

bool MuDISFilter::fUsePythiaDecays = false
private

Definition at line 169 of file MuDISFilter.h.

◆ hist_all

Histograms MuDISFilter::hist_all[ShipMuDIS::nMats]
private

Definition at line 185 of file MuDISFilter.h.

◆ hist_filt

Histograms MuDISFilter::hist_filt[ShipMuDIS::nMats]
private

Definition at line 186 of file MuDISFilter.h.

◆ kEfficiencyMaterials

unsigned MuDISFilter::kEfficiencyMaterials
staticconstexprprivate
Initial value:
=
ShipMuDIS::nMats - 1

Definition at line 138 of file MuDISFilter.h.

◆ kMomentumBins

unsigned MuDISFilter::kMomentumBins = 4
staticconstexprprivate

Definition at line 136 of file MuDISFilter.h.

◆ kPtBins

unsigned MuDISFilter::kPtBins = 5
staticconstexprprivate

Definition at line 137 of file MuDISFilter.h.


The documentation for this class was generated from the following files: