ProtoDUNEBeamlineUtils.h
Go to the documentation of this file.
1 #ifndef PROTODUNE_BEAMLINE_UTILS_H
2 #define PROTODUNE_BEAMLINE_UTILS_H
3 
4 ///////////////////////////////////////////////////////////////
5 // ProtoDUNEBeamlineUtils
6 // - Class to create tracks and momentum from beamline
7 // information. Will be used when updated monitor positions
8 // are available.
9 //
10 // - Jake Calcutt (calcuttj@msu.edu)
11 ///////////////////////////////////////////////////////////////
12 
14 #include "fhiclcpp/ParameterSet.h"
16 
17 #include "dune/DuneObj/ProtoDUNEBeamEvent.h"
19 
20 #include <set>
21 #include <map>
22 #include <string>
23 #include <ostream>
24 
25 #include "TVector3.h"
26 
27 namespace protoana {
28 
29  enum beamPDG{
30  kElectron = 11,
31  kMuon = 13,
32  kPion = 211,
33  kKaon = 321,
34  kProton = 2212,
35  kDeuteron = 1000010020
36  };
37 
39  public:
40  bool electron = false;
41  bool muon = false;
42  bool pion = false;
43  bool kaon = false;
44  bool proton = false;
45  bool deuteron = false;
46 
48  return {electron && b.electron, muon && b.muon, pion && b.pion, kaon && b.kaon, proton && b.proton, deuteron && b.deuteron};
49  }
51  return {electron || b.electron, muon || b.muon, pion || b.pion, kaon || b.kaon, proton || b.proton, deuteron || b.deuteron};
52  }
53  inline operator std::string () const { // overload cast to string
54  std::string result = "PossibleParticleCands: [ ";
55  if (electron) result += "e ";
56  if (muon) result += "mu ";
57  if (pion) result += "pi ";
58  if (kaon) result += "k ";
59  if (proton) result += "p ";
60  if (deuteron) result += "e ";
61  result += "]";
62  return result;
63  }
64  inline std::vector<int> getPDGCodes() const {
65  std::vector<int> result;
66  if (electron) result.push_back(kElectron);
67  if (muon) result.push_back(kMuon);
68  if (pion) result.push_back(kPion);
69  if (kaon) result.push_back(kKaon);
70  if (proton) result.push_back(kProton);
71  if (deuteron) result.push_back(kDeuteron);
72  return result;
73  }
74  };
75 
77 
78  public:
79 
82 
83  void reconfigure(fhicl::ParameterSet const &pset);
84 
85 
86  //GetBeamEvent(art::Event const & evt, std::string beamEventTag)
87  const beam::ProtoDUNEBeamEvent GetBeamEvent(art::Event const & evt) const;
88 
89  //GetFibers(art::Event const & evt, std::string beamEventTag, std::string monitorName)
90  //Replace with return double
91  void GetFibers( art::Event const & evt);
92  //GetCurrent(art::Event const & evt, std::string beamEventTag)
93  //Replace with return double
94  void GetCurrent( art::Event const & evt);
95 
96  //GetTracks()
97  //GetMomenta()
98 
99  //Remove
100  std::vector< recob::Track> MakeTracks( art::Event const & evt);
101 
102  //Remove
103  double GetPosition( short );
104  //Remove
105  TVector3 ConvertMonitorCoordinates( double, double, double, double );
106  //Remove
107  void BeamMonitorBasisVectors();
108  //Remove
109  void RotateMonitorVector(TVector3&);
110  //Remove
111  TVector3 ProjectToTPC(TVector3, TVector3);
112 
113  //Remove
114  std::vector< double > MomentumSpec( art::Event const & evt);
115  //Remove
116  double MomentumCosTheta( double, double, double );
117 
118  /**
119  * Get the particle ID from beamline instrumentation info (returns PDG IDs)
120  *
121  * Make sure to set fcl param UseCERNCalibSelection=true if the beam reco is done after ~v08_07_00
122  * otherwise if using an old reco'd BeamEvent (e.g. you are using the first central reco) set it to false
123  */
124  std::vector< int > GetPID( beam::ProtoDUNEBeamEvent const & beamevt, double nominal_momentum );
125  std::vector< int > GetPID( art::Event const & evt, double nominal_momentum );
126 
127  /**
128  * Get the particle ID from beamline instrumentation info
129  *
130  * Make sure to set fcl param UseCERNCalibSelection=true if the beam reco is done after ~v08_07_00
131  * otherwise if using an old reco'd BeamEvent (e.g. you are using the first central reco) set it to false
132  */
133  PossibleParticleCands GetPIDCandidates( beam::ProtoDUNEBeamEvent const & beamevt, double nominal_momentum );
134  PossibleParticleCands GetPIDCandidates( art::Event const & beamevt, double nominal_momentum );
135 
136  /**
137  * Compute what the beamline momentum SHOULD BE given a
138  * certain pdg and beamline TOF
139  */
140  double ComputeMomentum( int pdg, double tof );
141  /**
142  * Compute what the TOF SHOULD BE given a certain pdg
143  * and beamline momentum
144  */
145  double ComputeTOF ( int pdg, double momentum );
146 
147  /**
148  * Returns true if the beamline instrumentation has a good trigger
149  * that matches the ProtoDUNE trigger.
150  */
151  bool IsGoodBeamlineTrigger(art::Event const & evt) const;
152  bool IsGoodBeamlineTrigger(beam::ProtoDUNEBeamEvent const & beamEvent) const;
153 
154  /**
155  * Returns true if only 1 fiber is activated in each of the
156  * momentum spectrometer monitors
157  */
158  bool HasPerfectBeamMomentum(art::Event const & evt) const;
159  bool HasPerfectBeamMomentum(beam::ProtoDUNEBeamEvent const & beamEvent) const;
160 
161  /**
162  * Uses the beamline momentum and time of flight measurements
163  * to estimate the beamline particle mass in GeV/c^2
164  *
165  * Returns a list of all possible cominations (there can be
166  * multiple momenta).
167  */
168  std::vector<double> GetBeamlineMass(art::Event const & evt) const;
169 
170  /**
171  * Uses the beamline momentum and time of flight measurements
172  * to estimate the beamline particle mass^2 in (GeV/c^2)^2
173  *
174  * This can be more useful than the mass since measurement
175  * fluctuations can make it negative.
176  *
177  * Returns a list of all possible cominations (there can be
178  * multiple momenta).
179  */
180  std::vector<double> GetBeamlineMassSquared(art::Event const & evt) const;
181 
182  /**
183  * Get reconstructed beamline momentum (in GeV/c), tof (in ns), and
184  * flags for if the ckov's fired. Will be < 0 if invalid.
185  *
186  * C++ structured binding, so call like:
187  * const auto [momentum, tof, ckov0, ckov1] = dataUtils.GetBeamlineInformation(e);
188  *
189  * then you have the normal float momentum, int ckov0 variables, etc. in the current scope.
190  */
191  const std::tuple<double,double,int,int> GetBeamlineVars(art::Event const & evt) const;
192 
193  /**
194  * Get reconstructed beamline momentum (in GeV/c), tof (in ns),
195  * flags for the tofChannel and ckov's. Also the timing trigger (12 means beam),
196  * the beam instrumentation trigger (1 means beam trigger), and whether
197  * the timing and beam instrumentation triggers are matched.
198  *
199  * All values will be < 0 if invalid.
200  *
201  * C++ structured binding, so call like:
202  * const auto [momentum, tof, tofChannel,ckov0,ckov1,ckov0Pressure,ckov1Pressure,timingTrigger,BITrigger,areBIAndTimingMatched] = dataUtils.GetBeamlineInformation(e);
203  *
204  * then you have the normal float momentum, int ckov0 variables, etc. in the current scope. You can use (void) variable; lines
205  * to get rid of unused var warnings.
206  */
207  const std::tuple<double,double,int,int,int,double,double,int,int,bool> GetBeamlineVarsAndStatus(art::Event const & evt) const;
208 
209  private:
210 
211  /**
212  * Get the particle ID from beamline instrumentation info (this uses the official CERN cuts and assumes
213  * CERN calibrations)
214  */
215  std::vector< int > GetPID_CERNCalib( beam::ProtoDUNEBeamEvent const & beamevt, double nominal_momentum );
216  /**
217  * Get the particle ID from beamline instrumentation info (this uses the official CERN cuts and assumes
218  * CERN calibrations) if fUseCERNCalibSelection is set, otherwise uses old values.
219  */
220  PossibleParticleCands GetPIDCandidates_CERNCalib( beam::ProtoDUNEBeamEvent const & beamevt, double nominal_momentum );
221 
223 
225 
226  //Remove
227  std::map< std::string, std::vector< short > > ActiveFibers;
228 
229  //Remove
230  double Current;
231 
232  //std::vector< recob::Track > Tracks;
233 
234  //Just to make it easier to go through all devices
235  std::vector< std::string > AllDevices = {
236  "XBPF022707",
237  "XBPF022708",
238  "XBPF022716",
239  "XBPF022717",
240  "XBPF022697",
241  "XBPF022701",
242  "XBPF022702"
243  };
244 
245  //These will be static
246  //
247  //Tracking monitors
248  std::string HorizUpstream = "XBPF022707";
249  std::string VertUpstream = "XBPF022708";
250  std::string HorizDownstream = "XBPF022716";
251  std::string VertDownstream = "XBPF022717";
252 
253  //Momentum monitors
254  std::string BProf1 = "XBPF022697";
255  std::string BProf2 = "XBPF022701";
256  std::string BProf3 = "XBPF022702";
257 
258 
259  //Basis Vectors for transforming coords
260  TVector3 MonitorBasisX;
261  TVector3 MonitorBasisY;
262  TVector3 MonitorBasisZ;
263 
264  bool rotated = false;
265 
269 
272  double fNP04FrontZ;
273  double fBeamX, fBeamY, fBeamZ;
274 
275 
276  double fBeamBend;
277  double L1, L2, L3;
278  double fBProf1Shift, fBProf2Shift, fBProf3Shift;
279 
280  //Hardware Parameters for magnetic field stuff
281  double mag_P1 = 5.82044830e-3;
282 // double mag_P2 = 0.;
283  double mag_P3 = -4.68880000e-6;
284  double mag_P4 = 324.573967;
285 
286  std::map< int, double > particle_mass = {
287  {kElectron, .0005109989},
288  {kMuon, .1056583745},
289  {kPion, .13957018 },
290  {kKaon, .493677 },
291  {kProton, .9382720813},
292  {kDeuteron, 2.013553213}
293  };
294 
295  double c = 299792458.; // m/s
296  const double fTOFDist = 28.575; // m
297 
298  //////////////////////////////////////////////////////////////////
299  // for Justin Hugon's old beamline selection from BeamlineUtils //
300  //////////////////////////////////////////////////////////////////
302  float fMomentumOffset; // GeV/c
304  float fTOFOffset; // ns
305  //////////////////////////////////////////////////////////////////
306  //////////////////////////////////////////////////////////////////
307  //////////////////////////////////////////////////////////////////
308  };
309 
310 }
311 
312 #endif
313 
static QCString result
std::string string
Definition: nybbler.cc:12
virtual void reconfigure(fhicl::ParameterSet const &pset)
PossibleParticleCands operator||(const PossibleParticleCands &b) const
std::vector< int > getPDGCodes() const
Provides recob::Track data product.
static bool * b
Definition: config.cpp:1043
PossibleParticleCands operator&&(const PossibleParticleCands &b) const
std::map< std::string, std::vector< short > > ActiveFibers
TCEvent evt
Definition: DataStructs.cxx:7
def momentum(x1, x2, x3, scale=1.)