HighLAND
Interaction.cxx
1 #include <Interaction.hxx>
2 #include <BasicUtils.hxx>
3 #include "stdlib.h"
4 
5 Interaction::Interaction(){
6 
7  parentPDG = 0;
8  parent=NULL;
9 
10 }
11 
12 
13 Interaction::Interaction(AnaTrueParticleB* traj, AnaTrueParticleB* parent2){
14 
15  parentPDG = traj->ParentPDG;
16  parentID = traj->ParentID;
17  parent = parent2;
18  for(int i = 0; i < 4; ++i){
19  position[i] = traj->Position[i];
20  }
21 
22  AddTrajectory(traj, parent2);
23 }
24 
25 void Interaction::AddTrajectory(AnaTrueParticleB* traj, AnaTrueParticleB* parent2){
26 
27  trajectories.push_back(traj);
28  if (parent != parent2) std::cout << "Interaction::AddTrajectory().WARNING: add trajectory with a different parent !!!" << std::endl;
29 }
30 
31 Bool_t Interaction::IncludesTrajectory(AnaTrueParticleB* traj){
32 
33  return traj->Position[3] == position[3];
34 
35 }
36 
37 Int_t Interaction::NumberOfParticleType(Int_t pdg){
38 
39  Int_t NParticle = 0;
40 
41  for (unsigned int i = 0; i < trajectories.size(); i++){
42 
43  if (trajectories[i]->PDG == pdg){
44 
45  NParticle++;
46 
47  }
48  }
49 
50  return NParticle;
51 
52 }
53 
54 std::vector<UInt_t> Interaction::IndicesOfParticleType(Int_t pdg){
55 
56  std::vector<UInt_t> result;
57 
58  for (UInt_t i = 0; i < trajectories.size(); i++){
59 
60  if (trajectories[i]->PDG == pdg){
61  result.push_back(i);
62  }
63  }
64 
65  return result;
66 }
67 
68 
69 Int_t Interaction::NPiZeroFromDecayProducts(){
70 
71  Int_t NPi0Decays = 0;
72 
73  //Get the indices of gammas, e+ and e-.
74  std::vector<UInt_t> gammaIndices = IndicesOfParticleType(22);
75  std::vector<UInt_t> ePlusIndices = IndicesOfParticleType(-11);
76  std::vector<UInt_t> eMinusIndices = IndicesOfParticleType(11);
77 
78 
79  //First, add up the 4-momentum of e+e- pairs.
80  std::vector<TLorentzVector> momEPlusEMinusPairs;
81  for (UInt_t em = 0; em < eMinusIndices.size(); em++){
82  for(UInt_t ep = 0; ep < ePlusIndices.size(); ep++){
83 
84  TVector3 eMinusDir(trajectories[eMinusIndices[em]]->Direction[0],trajectories[eMinusIndices[em]]->Direction[1], trajectories[eMinusIndices[em]]->Direction[2]);
85  TVector3 ePlusDir(trajectories[ePlusIndices[ep]]->Direction[0], trajectories[ePlusIndices[ep]]->Direction[1], trajectories[ePlusIndices[ep]]->Direction[2]);
86 
87  double eMinusMom = trajectories[eMinusIndices[em]]->Momentum;
88  double ePlusMom = trajectories[ePlusIndices[em]]->Momentum;
89 
90  TLorentzVector eMinusFourMom = GetFourMomentum(eMinusDir,eMinusMom,0.5109989);
91  TLorentzVector ePlusFourMom = GetFourMomentum(ePlusDir,ePlusMom,0.5109989);
92 
93  momEPlusEMinusPairs.push_back(eMinusFourMom + ePlusFourMom);
94  }
95  }
96 
97  //Now check for a gamma and a e+e- pair, the other decay mode (~1% of the time.)
98  for(UInt_t gi = 0; gi < gammaIndices.size(); gi++){
99  for(UInt_t pi = 0; pi < momEPlusEMinusPairs.size(); pi++){
100 
101  TVector3 gammaDir(trajectories[gammaIndices[gi]]->Direction[0], trajectories[gammaIndices[gi]]->Direction[1], trajectories[gammaIndices[gi]]->Direction[2]);
102  double gammaMom = trajectories[gammaIndices[gi]]->Momentum;
103 
104  TLorentzVector gammaFourMom = GetFourMomentum(gammaDir,gammaMom,0.0);
105 
106  TLorentzVector sumOfMoms = gammaFourMom + momEPlusEMinusPairs[pi];
107 
108  Double_t invariantMassofPair = sumOfMoms.M();
109  if (invariantMassofPair > 134.96 && invariantMassofPair < 135.00){
110  NPi0Decays++;
111  }
112  }
113 
114  }
115 
116  //Finally, check the gamma gamma decay mode.
117  if(gammaIndices.size() > 1){
118  for (UInt_t gi = 0; gi < gammaIndices.size() - 1; gi++){
119 
120  TVector3 gamma1Dir(trajectories[gammaIndices[gi]]->Direction[0], trajectories[gammaIndices[gi]]->Direction[1], trajectories[gammaIndices[gi]]->Direction[2]);
121  double gamma1Mom = trajectories[gammaIndices[gi]]->Momentum;
122  TLorentzVector gamma1FourMom = GetFourMomentum(gamma1Dir,gamma1Mom,0.0);
123 
124  for (UInt_t gj = gi + 1; gj < gammaIndices.size(); gj++){
125 
126  TVector3 gamma2Dir(trajectories[gammaIndices[gj]]->Direction[0], trajectories[gammaIndices[gj]]->Direction[1], trajectories[gammaIndices[gj]]->Direction[2]);
127  double gamma2Mom = trajectories[gammaIndices[gj]]->Momentum;
128  TLorentzVector gamma2FourMom = GetFourMomentum(gamma2Dir,gamma2Mom,0.0);
129 
130 
131  TLorentzVector sumOfPhotonMoms = gamma1FourMom + gamma2FourMom;
132 
133  //If the invariant mass indicates a pi0, increment the NGammaGammaPi0 counter.
134  Double_t invariantMassofPair = sumOfPhotonMoms.M();
135  if (invariantMassofPair > 134.96 && invariantMassofPair < 135.00){
136  NPi0Decays++;
137  }
138 
139  }
140 
141  }
142  }
143 
144  //With all decay modes checked, return the number of Pi0 decays found.
145  return NPi0Decays;
146 
147 }
148 
149 
150 //For use in comparing two Interaction objects so can sort a vector of them according to the time
151 //they occurred at (from first to last.)
152 Bool_t CompareInteractions(Interaction a, Interaction b){
153 
154  return a.position[3] < b.position[3];
155 
156 }
157 
158 //Takes in the direction and momentum from highland, and a use supplied mass, and returns the
159 //4 momentum.
160 TLorentzVector GetFourMomentum(TVector3 direction, double momentum, Double_t mass){
161 
162  TVector3 momVec = momentum*direction;
163 
164  Double_t E = sqrt(momVec.Mag2() + pow(mass,2));
165 
166  TLorentzVector fourMom(momVec.Px(),momVec.Py(),momVec.Pz(),E);
167 
168  return fourMom;
169 
170 
171 }
172 
173 //Counts all exotic particles, for shunting those events to "Other".
174 Int_t Interaction::CountExoticParticles(){
175 
176  Int_t NExotics = 0;
177 
178  for (unsigned int i = 0; i < trajectories.size(); i++){
179 
180  //Exotics are anything that we wouldn't expect
181  //in the oaAnalysis saved trajectories.
182  //i.e. not electrons, muons, pions, photons or nucleons.
183  //Remember: neutrino trajectories are not saved.
184  if (trajectories[i]->PDG != 11
185  && trajectories[i]->PDG != -11
186  && trajectories[i]->PDG != 13
187  && trajectories[i]->PDG != -13
188  && trajectories[i]->PDG != 111
189  && trajectories[i]->PDG != 211
190  && trajectories[i]->PDG != -211
191  && trajectories[i]->PDG != 22
192  && trajectories[i]->PDG != 2212
193  && trajectories[i]->PDG != 2112){
194 
195  NExotics++;
196 
197  }
198  }
199 
200  return NExotics;
201 
202 }
Representation of a true Monte Carlo trajectory/particle.
Int_t ParentPDG
The PDG code of this particle&#39;s immediate parent, or 0 if there is no parent.
Int_t ParentID
The ID of this particle&#39;s immediate parent, or 0 if there is no parent.
Float_t Position[4]
The initial position of the true particle.