AnaUtils.cxx
Go to the documentation of this file.
1 //
2 // AnaUtils.h
3 //
4 // Created by C. Hilgenberg
5 
6 //#ifndef GAR_ANAUTILS_cxx
7 //#define GAR_ANAUTILS_cxx
8 
9 #include "AnaUtils.h"
10 #include <iostream>
11 
12 using std::vector;
13 using std::pair;
14 
15 namespace gar{
16 
17  garana::GTruth MakeAnaGTruth(const simb::GTruth& gt, const int& vtxregion) {
18 
19  garana::GTruth outtruth;
20  FillGTruth(gt, outtruth);
21 
22  outtruth.fVertexRegion = vtxregion;
23 
24  return outtruth;
25 
26  }
27 
28 
30  return garana::FSParticle(mcp.TrackId(), mcp.PdgCode(),mcp.Position(),mcp.Momentum());
31  }
32 
33  garana::G4Particle MakeG4Particle(const simb::MCParticle& mcp, int parentPdg, int progenitorPdg, int progenitorTrackId,
34  const vector<pair<TLorentzVector,TLorentzVector>>& positions,
35  const vector<pair<TLorentzVector,TLorentzVector>>& momenta, const vector<int>& regions,
36  const vector<size_t>& nptsPerRegion) {
37  return garana::G4Particle(
38  mcp.NumberTrajectoryPoints(), mcp.PdgCode(), parentPdg, progenitorPdg,
39  mcp.TrackId(), mcp.Mother(), progenitorTrackId,
42  positions, momenta, regions, nptsPerRegion
43  );
44  }
45 
46 
47  //////////////////////////////////////////////
48  garana::CaloCluster MakeAnaCalCluster(const rec::Cluster& clust, const int& region, const std::vector<std::pair<int,float>>& edeps) {
49 
50  TLorentzVector pos( clust.Position()[0], clust.Position()[1], clust.Position()[2], clust.Time() );
51 
52  //trade in our arrays for vectors/TVector3s
53  const float* eigs = clust.EigenVectors();
54  std::vector<TVector3> vecs;
55  for(int i=0; i<3; i++){
56  TVector3 eig( eigs[i], eigs[i+1], eigs[i+2] );
57  vecs.push_back(eig);
58  }
59 
60  garana::CaloCluster outclust(pos, region, clust.Energy(), clust.EnergyError(), clust.TimeDiffFirstLast(),
61  clust.Shape(), clust.ITheta(), clust.IPhi(), vecs, edeps );
62 
63  return outclust;
64  }//
65 
66  ///////////////////////////////////////////////
68 
69  TLorentzVector vtx( vee.Position()[0], vee.Position()[1], vee.Position()[2], vee.Time() );
70  std::vector<TLorentzVector> vecs;
71  for(int i=0; i<3; i++) {
72  vecs.push_back(vee.FourMomentum(i));
73  }
74 
75  garana::Vee outvee( vtx, vecs, vee.Chisq(), vee.VertexCov() );
76 
77  return outvee;
78  }//
79  ///////////////////////////////////////////////
81 
82  TLorentzVector pos( vtx.Position()[0], vtx.Position()[1], vtx.Position()[2], vtx.Time() );
83  garana::Vertex outvtx(pos, vtx.CovMat());
84 
85  return outvtx;
86  }//
87 
88  ////////////////////////////////////////////////
89  std::unordered_map<std::string,int> processMap{
90  {"unknown" , 0 },
91  {"primary" , 1 },
92  {"compt" , 2 },
93  {"phot" , 3 },
94  {"annihil" , 4 },
95  {"eIoni" , 5 },
96  {"eBrem" , 6 },
97  {"conv" , 7 },
98  {"muIoni" , 8 },
99  {"muMinusCaptureAtRest" , 9 },
100  {"neutronInelastic" , 10},
101  {"nCapture" , 11},
102  {"hadElastic" , 12},
103  {"Decay" , 13},
104  {"CoulombScat" , 14},
105  {"muPairProd" , 15},
106  {"muBrems" , 16},
107  {"muPairProd" , 17},
108  {"PhotonInelastic" , 18},
109  {"hIoni" , 19},
110  {"protonInelastic" , 20},
111  {"pi+Inelastic" , 21},
112  {"CHIPSNuclearCaptureAtRest" , 22},
113  {"pi-Inelastic" , 23},
114  {"hBertiniCaptureAtRest" , 24},
115  {"photonNuclear" , 25},
116  {"muonNuclear" , 26},
117  {"kaon-Inelastic" , 27},
118  {"kaon+Inelastic" , 28},
119  {"Transportation" , 29},
120  {"nKiller" , 30},
121  {"ionIoni" , 31},
122  {"msc" , 32},
123  {"dInelastic" , 33},
124  {"kaon0LInelastic" , 34},
125  {"electronNuclear" , 35},
126  {"tInelastic" , 36},
127  {"kaon0SInelastic" , 37},
128  {"sigma+Inelastic" , 38},
129  {"lambdaInelastic" , 39},
130  {"anti_protonInelastic" , 40},
131  {"alphaInelastic" , 41}
132  };
133 
134 
135  //convert process name from G4 to numeric value for
136  // easy storage in TTrees
138  {
139  if(processMap.find(p)==processMap.end()){
140  std::cout << "WARNING(AnaUtils::ProcessNameToCode): "
141  << "unknown process name, '" << p << "'" << std::endl;
142  return -9999;
143  }
144 
145  else
146  return processMap[p];
147 
148  }
149 
150  // make a copy of the ghep record and write to empty garana product
151  void FillGTruth(const simb::GTruth& gt, garana::GTruth& outtruth) {
152 
153  outtruth.fVertex = gt.fVertex;
154  outtruth.fVertex.SetVect(100.*gt.fVertex.Vect()); // GENIE uses meters - convert to cm (same as MCParticle)
155  outtruth.fVertex.SetT(1.e9*gt.fVertex.T()); // GENIE uses seconds - convert to ns (same as MCParticle)
156  outtruth.fweight = gt.fweight;
157  outtruth.fprobability = gt.fprobability;
158  outtruth.fXsec = gt.fXsec;
159  outtruth.fDiffXsec = gt.fDiffXsec;
160  outtruth.fGPhaseSpace = gt.fGPhaseSpace;
161 
162  outtruth.fProbePDG = gt.fProbePDG;
163  outtruth.fProbeP4 = gt.fProbeP4;
164  outtruth.fTgtP4 = gt.fTgtP4;
165 
166  outtruth.ftgtZ = gt.ftgtZ;
167  outtruth.ftgtA = gt.ftgtA;
168  outtruth.ftgtPDG = gt.ftgtPDG;
169  outtruth.fHitNucPDG = gt.fHitNucPDG;
170  outtruth.fHitQrkPDG = gt.fHitQrkPDG;
171  outtruth.fIsSeaQuark = gt.fIsSeaQuark;
172  outtruth.fHitNucP4 = gt.fHitNucP4;
173  outtruth.fHitNucPos = gt.fHitNucPos;
174 
175  outtruth.fGscatter = gt.fGscatter;
176  outtruth.fGint = gt.fGint;
177 
178  outtruth.fgQ2 = gt.fgQ2;
179  outtruth.fgq2 = gt.fgq2;
180  outtruth.fgW = gt.fgW ;
181  outtruth.fgT = gt.fgT;
182  outtruth.fgX = gt.fgX;
183  outtruth.fgY = gt.fgY;
184  outtruth.fFSleptonP4 = gt.fFSleptonP4;
185  outtruth.fFShadSystP4 = gt.fFShadSystP4;
186 
187  outtruth.fIsCharm = gt.fIsCharm;
188  outtruth.fCharmHadronPdg = gt.fCharmHadronPdg;
189  outtruth.fIsStrange = gt.fIsStrange;
190  outtruth.fStrangeHadronPdg = gt.fStrangeHadronPdg;
191  outtruth.fNumProton = gt.fNumProton;
192  outtruth.fNumNeutron = gt.fNumNeutron;
193  outtruth.fNumPi0 = gt.fNumPi0;
194  outtruth.fNumPiPlus = gt.fNumPiPlus;
195  outtruth.fNumPiMinus = gt.fNumPiMinus;
196  outtruth.fResNum = gt.fResNum;
197  outtruth.fDecayMode = gt.fDecayMode;
198  }
199 
200 
201  //////////////////////////////////////////////////////////////////////////////////////////////////
202  const garana::Track MakeAnaTrack(const rec::Track& trk, const vector<pair<int,float>>& pidf,
203  const vector<pair<int,float>>& pidb, float ionf, float ionb,
204  const vector<pair<UInt_t,TLorentzVector>>& posBeg,
205  const vector<pair<UInt_t,TLorentzVector>>& posEnd,
206  const vector<pair<UInt_t,TLorentzVector>>& momBeg,
207  const vector<pair<UInt_t,TLorentzVector>>& momEnd,
208  const vector<pair<int,float>>& edeps)
209  {
210 
211  const float* tmp = trk.Vertex();
212  TLorentzVector vtx(tmp[0], tmp[1], tmp[2], trk.Time());
213 
214  tmp = trk.End();
215  TLorentzVector end(tmp[0], tmp[1], tmp[2], trk.Time()); // eventually track end times should be different
216 
217  tmp = trk.VtxDir();
218  TVector3 vtxDir(tmp[0], tmp[1], tmp[2]);
219 
220  tmp = trk.EndDir();
221  TVector3 endDir(tmp[0], tmp[1], tmp[2]);
222 
223  garana::Track anatrk( trk.LengthForward(), trk.LengthBackward(), trk.Momentum_beg(), trk.Momentum_end(),
224  vtx, end, vtxDir, endDir, trk.ChisqForward(), trk.ChisqBackward(), trk.NHits(),
225  trk.TrackParBeg(), trk.TrackParEnd(), trk.CovMatBegPacked(), trk.CovMatEndPacked(),
226  trk.ChargeBeg(), trk.ChargeEnd(), pidf, pidb, ionf, ionb, posBeg, posEnd, momBeg,
227  momEnd, edeps);
228 
229  return anatrk;
230 
231  }
232 
233  /*void ChangeToTpcCoords(garana::GTruth& gt, const TLorentzVector& origin) {
234  gt
235  }
236 
237  void ChangeToTpcCoords(garana::Track& track, const TLorentzVector& origin) {
238 
239  }
240 
241  void ChangeToTpcCoords(garana::CaloCluster& clust, const TLorentzVector& origin) {
242 
243  }
244 
245  void ChangeToTpcCoords(garana::Vertex& vtx, const TLorentzVector& origin) {
246 
247  }
248 
249  void ChangeToTpcCoords(garana::Vee& vee, const TLorentzVector& origin) {
250 
251  }
252 
253  void ChangeToTpcCoords(garana::G4Particle& g4p, const TLorentzVector& origin) {
254 
255  }
256 
257  void ChangeToTpcCoords(garana::FSParticle& g4p, const TLorentzVector& origin) {
258 
259  }*/
260 
261 
262 }//namespace
263 
264 //#endif
265 
double fgW
Definition: GTruth.h:64
int fGint
interaction code
Definition: GTruth.h:56
bool fIsCharm
did the interaction produce a charmed hadron?
Definition: GTruth.h:69
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
float const & Momentum_beg() const
Definition: Track.h:146
unsigned int NumberTrajectoryPoints() const
Definition: MCParticle.h:218
double fgq2
Definition: GTruth.h:60
const TLorentzVector & Position(const int i=0) const
Definition: MCParticle.h:219
int PdgCode() const
Definition: MCParticle.h:212
double fgq2
Definition: GTruth.h:63
double fgX
Definition: GTruth.h:66
int ftgtA
Definition: GTruth.h:46
TLorentzVector fTgtP4
Definition: GTruth.h:41
int fCharmHadronPdg
Definition: GTruth.h:70
int fVertexRegion
region code where vertex is located
Definition: GTruth.h:26
float Chisq() const
Definition: Vee.h:68
const float * TrackParBeg() const
Definition: Track.h:151
int fStrangeHadronPdg
Definition: GTruth.h:72
std::string string
Definition: nybbler.cc:12
int fNumPiMinus
number of pi minuses after reaction, before FSI
Definition: GTruth.h:77
int ProcessNameToCode(std::string const &p)
Definition: AnaUtils.cxx:137
int Mother() const
Definition: MCParticle.h:213
int fGPhaseSpace
phase space system of DiffXSec
Definition: GTruth.h:32
const float * VertexCov() const
Definition: Vee.h:66
double fweight
event interaction weight (genie internal)
Definition: GTruth.h:32
garana::FSParticle MakeFSParticle(const simb::MCParticle &mcp)
Definition: AnaUtils.cxx:29
int fNumNeutron
number of neutrons after reaction, before FSI
Definition: GTruth.h:81
struct vector vector
int fNumProton
number of protons after reaction, before FSI
Definition: GTruth.h:73
int ftgtZ
Definition: GTruth.h:45
double fXsec
cross section of interaction
Definition: GTruth.h:30
int fNumPiPlus
number of pi pluses after reaction, before FSI
Definition: GTruth.h:83
int fNumPiMinus
number of pi minuses after reaction, before FSI
Definition: GTruth.h:84
int fGscatter
neutrino scattering code
Definition: GTruth.h:54
float const & LengthBackward() const
Definition: Track.h:145
std::unordered_map< std::string, int > processMap
Definition: AnaUtils.cxx:89
const float * Position() const
Definition: Vee.h:65
double fgY
Definition: GTruth.h:64
std::string Process() const
Definition: MCParticle.h:215
TLorentzVector fFSleptonP4
generated final state primary lepton (LAB frame) // added version 13
Definition: GTruth.h:65
double fgT
Definition: GTruth.h:62
float TimeDiffFirstLast() const
Definition: Cluster.h:95
garana::Vee MakeAnaVee(const rec::Vee &vee)
Definition: AnaUtils.cxx:67
double Time() const
Definition: Vee.h:67
bool fIsStrange
strange production // added version 13
Definition: GTruth.h:78
int fNumNeutron
number of neutrons after reaction, before FSI
Definition: GTruth.h:74
float const & ChisqBackward() const
Definition: Track.h:149
int TrackId() const
Definition: MCParticle.h:210
const float * VtxDir() const
Definition: Track.h:141
TLorentzVector fProbeP4
Definition: GTruth.h:41
int fResNum
resonance number
Definition: GTruth.h:78
garana::CaloCluster MakeAnaCalCluster(const rec::Cluster &clust, const int &region, const std::vector< std::pair< int, float >> &edeps)
Definition: AnaUtils.cxx:48
TLorentzVector fVertex
Definition: GTruth.h:31
float ITheta() const
Definition: Cluster.h:97
float IPhi() const
Definition: Cluster.h:98
double const & Time() const
Definition: Track.h:155
int fResNum
resonance number
Definition: GTruth.h:89
int fNumProton
number of protons after reaction, before FSI
Definition: GTruth.h:80
int fDecayMode
Definition: GTruth.h:90
double fprobability
interaction probability
Definition: GTruth.h:29
double fprobability
interaction probability
Definition: GTruth.h:33
float const & LengthForward() const
Definition: Track.h:144
const float * Vertex() const
Definition: Track.h:139
int fProbePDG
Definition: GTruth.h:39
int ChargeEnd() const
Definition: Track.cxx:236
double fgX
Definition: GTruth.h:63
std::string EndProcess() const
Definition: MCParticle.h:216
TLorentzVector fFSleptonP4
generated final state primary lepton (LAB frame) // added version 13
Definition: GTruth.h:72
int ftgtPDG
PDG of Target Nucleus, nucleon only if free.
Definition: GTruth.h:46
int fGscatter
neutrino scattering code
Definition: GTruth.h:55
double fXsec
cross section of interaction
Definition: GTruth.h:34
void FillGTruth(const simb::GTruth &gt, garana::GTruth &outtruth)
Definition: AnaUtils.cxx:151
garana::Vertex MakeAnaVtx(const rec::Vertex &vtx)
Definition: AnaUtils.cxx:80
TLorentzVector fProbeP4
Definition: GTruth.h:40
garana::G4Particle MakeG4Particle(const simb::MCParticle &mcp, int parentPdg, int progenitorPdg, int progenitorTrackId, const vector< pair< TLorentzVector, TLorentzVector >> &positions, const vector< pair< TLorentzVector, TLorentzVector >> &momenta, const vector< int > &regions, const vector< size_t > &nptsPerRegion)
Definition: AnaUtils.cxx:33
int fNumPi0
number of pi0 after reaction, before FSI
Definition: GTruth.h:82
int fCharmHadronPdg
Definition: GTruth.h:77
const TLorentzVector & FourMomentum(const size_t i) const
Definition: Vee.h:69
TLorentzVector fHitNucP4
Definition: GTruth.h:50
int ChargeBeg() const
Definition: Track.cxx:229
int fHitQrkPDG
hit quark PDG code // added version 13
Definition: GTruth.h:49
int fNumPi0
number of pi0 after reaction, before FSI
Definition: GTruth.h:75
bool fIsCharm
did the interaction produce a charmed hadron?
Definition: GTruth.h:76
p
Definition: test.py:223
const float * TrackParEnd() const
Definition: Track.h:152
int fDecayMode
Definition: GTruth.h:79
double fweight
event interaction weight (genie internal)
Definition: GTruth.h:28
string tmp
Definition: languages.py:63
const float * EigenVectors() const
Definition: Cluster.h:99
float const & ChisqForward() const
Definition: Track.h:148
double fHitNucPos
Definition: GTruth.h:51
int fGPhaseSpace
phase space system of DiffXSec
Definition: GTruth.h:36
int fProbePDG
Definition: GTruth.h:39
const float * End() const
Definition: Track.h:140
TLorentzVector fHitNucP4
Definition: GTruth.h:51
double fgW
Definition: GTruth.h:61
double fDiffXsec
differential cross section of interaction
Definition: GTruth.h:35
const float * Position() const
Definition: Vertex.h:56
const float * Position() const
Definition: Cluster.h:96
const float * CovMat() const
Definition: Vertex.h:57
General GArSoft Utilities.
int fNumPiPlus
number of pi pluses after reaction, before FSI
Definition: GTruth.h:76
garana::GTruth MakeAnaGTruth(const simb::GTruth &gt, const int &vtxregion)
Definition: AnaUtils.cxx:17
int fHitNucPDG
hit nucleon PDG code
Definition: GTruth.h:47
double fHitNucPos
Definition: GTruth.h:52
int ftgtPDG
PDG of Target Nucleus, nucleon only if free.
Definition: GTruth.h:47
double fgQ2
Definition: GTruth.h:62
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:220
TLorentzVector fFShadSystP4
generated final state hadronic system (LAB frame)
Definition: GTruth.h:73
int fGint
interaction code
Definition: GTruth.h:55
TLorentzVector fTgtP4
Definition: GTruth.h:42
int fHitNucPDG
hit nucleon PDG code // added version 13
Definition: GTruth.h:48
float const & Momentum_end() const
Definition: Track.h:147
float Time() const
Definition: Cluster.h:94
size_t const & NHits() const
Definition: Track.h:150
double fgT
Definition: GTruth.h:65
bool fIsSeaQuark
Definition: GTruth.h:49
int fHitQrkPDG
hit quark PDG code
Definition: GTruth.h:48
bool fIsStrange
strange production // added version 13
Definition: GTruth.h:71
const float * CovMatEndPacked() const
Definition: Track.h:154
double Time() const
Definition: Vertex.h:58
const float * CovMatBegPacked() const
Definition: Track.h:153
TLorentzVector fFShadSystP4
generated final state hadronic system (LAB frame)
Definition: GTruth.h:66
const float * Shape() const
Definition: Cluster.h:100
float Energy() const
Definition: Cluster.h:92
bool fIsSeaQuark
Definition: GTruth.h:50
TLorentzVector fVertex
Definition: GTruth.h:26
double fgY
a common running variable to be recorded
Definition: GTruth.h:67
double fgQ2
< these are for the internal (on shell) genie kinematics
Definition: GTruth.h:59
double fDiffXsec
differential cross section of interaction
Definition: GTruth.h:31
const garana::Track MakeAnaTrack(const rec::Track &trk, const vector< pair< int, float >> &pidf, const vector< pair< int, float >> &pidb, float ionf, float ionb, const vector< pair< UInt_t, TLorentzVector >> &posBeg, const vector< pair< UInt_t, TLorentzVector >> &posEnd, const vector< pair< UInt_t, TLorentzVector >> &momBeg, const vector< pair< UInt_t, TLorentzVector >> &momEnd, const vector< pair< int, float >> &edeps)
Definition: AnaUtils.cxx:202
QTextStream & endl(QTextStream &s)
float EnergyError() const
Definition: Cluster.h:93
const float * EndDir() const
Definition: Track.h:142
int fStrangeHadronPdg
Definition: GTruth.h:79