ProtoDUNEBeamlineFilter_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // ProtoDUNEBeamlineFilter selects events based on reconstructed
4 // beamline info
5 //
6 // 2018 Justin Hugon, jhugon@fnal.gov
7 //
8 ////////////////////////////////////////////////////////////////////////
9 
10 // Framework includes
15 #include "art_root_io/TFileService.h"
18 #include "fhiclcpp/ParameterSet.h"
19 
20 // dunetpc includes
22 
23 // ROOT includes
24 #include "TH1F.h"
25 #include "TH2F.h"
26 
27 #include <cmath>
28 
29 namespace protoana{
30  class ProtoDUNEBeamlineFilter;
31 }
32 
34 public:
35 
36  explicit ProtoDUNEBeamlineFilter(fhicl::ParameterSet const& pset);
37  virtual ~ProtoDUNEBeamlineFilter();
38 
39  void beginJob();
40  bool filter(art::Event& evt);
41  void reconfigure(fhicl::ParameterSet const& pset);
42  void endJob();
43 
44 private:
45 
47  float fNominalBeamMomentum; // GeV/c
49  bool fIsMuon;
50  bool fIsPion;
51  bool fIsKaon;
52  bool fIsProton;
53  bool fAndParticles; // otherwise do or of the allowed particles
54 
55  // Histograms
65  TH1F* fMomentumAll;
67  TH1F* fTOFAll;
68  TH1F* fTOFPass;
71  TH1F* fCKov0All;
72  TH1F* fCKov0Pass;
73  TH1F* fCKov1All;
74  TH1F* fCKov1Pass;
79  TH1F* fCKovAll;
80  TH1F* fCKovPass;
81  TH1F* fMassAll;
82  TH1F* fMassPass;
83 };
84 
85 //-----------------------------------------------------------------------
87  EDFilter(pset), fBeamlineUtils(pset.get<fhicl::ParameterSet>("BeamlineUtils"))
88 {
89 
90  this->reconfigure(pset);
91 
92 }
93 
94 //-----------------------------------------------------------------------
96 
97 //-----------------------------------------------------------------------
99 
101  fIsBeamTrigger = tfs->make<TH1F>("IsBeamTrigger", "Is the CTB trigger from the beamline?", 2,0,1);
102  fBITriggerAll = tfs->make<TH1F>("BITriggerAll", "Beam Instrumentation Trigger for All Events", 3,-1,1);
103  fBITriggerPass = tfs->make<TH1F>("BITriggerPass", "Beam Instrumentation Trigger for Passing Events", 3,-1,1);
104  fBIAndTimingMatchAll = tfs->make<TH1F>("BIAndTimingMatchAll", "Beam Instrumentation & Timing Triggers Match for All Events", 2,0,1);
105  fBIAndTimingMatchPass = tfs->make<TH1F>("BIAndTimingMatchPass", "Beam Instrumentation & Timing Triggers Match for Passing Events", 2,0,1);
106  fPossiblePartsTOF = tfs->make<TH1F>("PossiblePartsTOF", "Possible TOF Particles for All Events", 5,0,5);
107  fPossiblePartsCherenkov = tfs->make<TH1F>("PossiblePartsCherenkov", "Possible Cherenkov Particles for All Events", 5,0,5);
108  fPossiblePartsAll = tfs->make<TH1F>("PossiblePartsAll", "Possible Particles for All Events", 5,0,5);
109  fPossiblePartsPass = tfs->make<TH1F>("PossiblePartsPass", "Possible Particles for Passing Events", 5,0,5);
110  fMomentumAll = tfs->make<TH1F>("MomentumAll", "Momentum for All Events", 100,0,10);
111  fMomentumPass = tfs->make<TH1F>("MomentumPass", "Momentum for Passing Events", 100,0,10);
112  fTOFAll = tfs->make<TH1F>("TOFAll", "TOF for All Events", 350,-100,250);
113  fTOFPass = tfs->make<TH1F>("TOFPass", "TOF for Passing Events", 350,-100,250);
114  fTOFChannelAll = tfs->make<TH1F>("TOFChannelAll", "TOF Channel for All Events", 6,-1,5);
115  fTOFChannelPass = tfs->make<TH1F>("TOFChannelPass", "TOF Channel for Passing Events", 6,-1,5);
116  fCKov0All = tfs->make<TH1F>("CKov0All", "Cherenkov 0 for All Events", 3,-1,2);
117  fCKov0Pass = tfs->make<TH1F>("CKov0Pass", "Cherenkov 0 for Passing Events", 3,-1,2);
118  fCKov1All = tfs->make<TH1F>("CKov1All", "Cherenkov 1 for All Events", 3,-1,2);
119  fCKov1Pass = tfs->make<TH1F>("CKov1Pass", "Cherenkov 1 for Passing Events", 3,-1,2);
120  fCKov0PressureAll = tfs->make<TH1F>("CKov0PressureAll", "Cherenkov 0 Pressure for All Events", 100,0,10);
121  fCKov0PressurePass = tfs->make<TH1F>("CKov0PressurePass", "Cherenkov 0 Pressure for Passing Events", 100,0,10);
122  fCKov1PressureAll = tfs->make<TH1F>("CKov1PressureAll", "Cherenkov 1 Pressure for All Events", 100,0,10);
123  fCKov1PressurePass = tfs->make<TH1F>("CKov1PressurePass", "Cherenkov 1 Pressure for Passing Events", 100,0,10);
124  fCKovAll = tfs->make<TH1F>("CKovAll", "Both Cherenkovs for All Events", 5,-1,4);
125  fCKovPass = tfs->make<TH1F>("CKovPass", "Both Cherenkovs for Passing Events", 5,-1,4);
126  fMassAll = tfs->make<TH1F>("MassAll", "Beamline Particle Mass for All Events", 200,0,5);
127  fMassPass = tfs->make<TH1F>("MassPass", "Beamline Particle Mass for Passing Events", 200,0,5);
128 
129 }
130 
131 //-----------------------------------------------------------------------
133  fNominalBeamMomentum = pset.get<float>("NominalBeamMomentum"); // GeV/c
134  fIsElectron = pset.get<bool>("IsElectron");
135  fIsMuon = pset.get<bool>("IsMuon");
136  fIsPion = pset.get<bool>("IsPion");
137  fIsKaon = pset.get<bool>("IsKaon");
138  fIsProton = pset.get<bool>("IsProton");
139  fAndParticles = pset.get<bool>("AndParticles");
140 }
141 
142 //-----------------------------------------------------------------------
144 
146  {
147  fIsBeamTrigger->Fill(1);
148  }
149  else
150  {
151  fIsBeamTrigger->Fill(0);
152  return false;
153  }
154  const auto possibleParts = fBeamlineUtils.GetPIDCandidates(evt,fNominalBeamMomentum);
155  mf::LogInfo("protoana::ProtoDUNEBeamlineFilter::filter") << (std::string) possibleParts;
156  bool result = false;
157  if(fAndParticles)
158  {
159  if(fIsElectron && !possibleParts.electron) result = false;
160  else if(fIsMuon && !possibleParts.muon) result = false;
161  else if(fIsPion && !possibleParts.pion) result = false;
162  else if(fIsKaon && !possibleParts.kaon) result = false;
163  else if(fIsProton && !possibleParts.proton) result = false;
164  else result = true;
165  }
166  else // or
167  {
168  if(fIsElectron && possibleParts.electron) result = true;
169  else if(fIsMuon && possibleParts.muon) result = true;
170  else if(fIsPion && possibleParts.pion) result = true;
171  else if(fIsKaon && possibleParts.kaon) result = true;
172  else if(fIsProton && possibleParts.proton) result = true;
173  else result = false;
174  }
175 
176  if (possibleParts.electron) fPossiblePartsAll->Fill(0);
177  if (possibleParts.muon) fPossiblePartsAll->Fill(1);
178  if (possibleParts.pion) fPossiblePartsAll->Fill(2);
179  if (possibleParts.kaon) fPossiblePartsAll->Fill(3);
180  if (possibleParts.proton) fPossiblePartsAll->Fill(4);
181  if(result)
182  {
183  if (possibleParts.electron) fPossiblePartsPass->Fill(0);
184  if (possibleParts.muon) fPossiblePartsPass->Fill(1);
185  if (possibleParts.pion) fPossiblePartsPass->Fill(2);
186  if (possibleParts.kaon) fPossiblePartsPass->Fill(3);
187  if (possibleParts.proton) fPossiblePartsPass->Fill(4);
188  }
189 
190  const auto [momentum,tof,tofChannel,ckov0,ckov1,ckov0Pressure,ckov1Pressure,timingTrigger,BITrigger,areBIAndTimingMatched] = fBeamlineUtils.GetBeamlineVarsAndStatus(evt);
191  fMomentumAll->Fill(momentum);
192  if(result) fMomentumPass->Fill(momentum);
193  fTOFAll->Fill(momentum);
194  if(result) fTOFPass->Fill(tof);
195  fTOFChannelAll->Fill(tofChannel);
196  if(result) fTOFChannelPass->Fill(tofChannel);
197 
198  fCKov0All->Fill(ckov0);
199  if(result) fCKov0Pass->Fill(ckov0);
200  fCKov1All->Fill(ckov1);
201  if(result) fCKov1Pass->Fill(ckov1);
202  fCKov0PressureAll->Fill(ckov0Pressure);
203  if(result) fCKov0PressurePass->Fill(ckov0Pressure);
204  fCKov1PressureAll->Fill(ckov1);
205  if(result) fCKov1PressurePass->Fill(ckov1Pressure);
206 
207  int ckov = -1;
208  if (ckov0 >=0 && ckov1 >=0)
209  {
210  ckov = ckov0;
211  ckov += (ckov1 << 1);
212  }
213  fCKovAll->Fill(ckov);
214  if(result) fCKovPass->Fill(ckov);
215 
216  mf::LogInfo("protoana::ProtoDUNEBeamlineFilter::filter") << "pass: " << result << "momentum: " << momentum << " GeV/c, TOF: "<<tof
217  << " ns, tofChannel: " << tofChannel << " cherenkov 0: " << ckov0 << " cherenkov 1: " << ckov1
218  << " ckov0Pressure: " << ckov0Pressure
219  << " ckov1Pressure: " << ckov1Pressure
220  << " timingTrigger: "<<timingTrigger<<" BITrigger: "<<BITrigger
221  << " BIAndTimingMatched: "<<areBIAndTimingMatched;
222  std::vector<double> massSquareds = fBeamlineUtils.GetBeamlineMassSquared(evt);
223  for (const auto& massSquared: massSquareds)
224  {
225  const auto& mass = std::sqrt(massSquared);
226  mf::LogInfo("protoana::ProtoDUNEBeamlineFilter::filter") << "mass^2: " << massSquared << " (GeV/c^2)^2 " << "mass: " << mass << " GeV/c^2";
227  fMassAll->Fill(mass);
228  if(result) fMassPass->Fill(mass);
229  }
230  fBITriggerAll->Fill(BITrigger);
231  if(result) fBITriggerPass->Fill(BITrigger);
232  fBIAndTimingMatchAll->Fill(areBIAndTimingMatched);
233  if(result) fBIAndTimingMatchPass->Fill(areBIAndTimingMatched);
234 
235  return result;
236 }
237 
239 
PossibleParticleCands GetPIDCandidates(beam::ProtoDUNEBeamEvent const &beamevt, double nominal_momentum)
static QCString result
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
const std::tuple< double, double, int, int, int, double, double, int, int, bool > GetBeamlineVarsAndStatus(art::Event const &evt) const
std::vector< double > GetBeamlineMassSquared(art::Event const &evt) const
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
T get(std::string const &key) const
Definition: ParameterSet.h:271
bool IsGoodBeamlineTrigger(art::Event const &evt) const
EDFilter(fhicl::ParameterSet const &pset)
Definition: EDFilter.h:21
TCEvent evt
Definition: DataStructs.cxx:7
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
def momentum(x1, x2, x3, scale=1.)
protoana::ProtoDUNEBeamlineUtils fBeamlineUtils
void reconfigure(fhicl::ParameterSet const &pset)
ProtoDUNEBeamlineFilter(fhicl::ParameterSet const &pset)