CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PizeroMCTruthFinder.cc
Go to the documentation of this file.
4 
5 #include <algorithm>
6 
10 }
11 
15  std::cout << "~PizeroMCTruthFinder" << std::endl;
16 }
17 
18 std::vector<PizeroMCTruth> PizeroMCTruthFinder::find(const std::vector<SimTrack>& theSimTracks,
19  const std::vector<SimVertex>& theSimVertices) {
20  std::cout << " PizeroMCTruthFinder::find " << std::endl;
21 
22  std::vector<PhotonMCTruth> mcPhotons = thePhotonMCTruthFinder_->find(theSimTracks, theSimVertices);
23 
24  std::vector<PizeroMCTruth> result;
25  std::vector<PhotonMCTruth> photonsFromPizero;
26  std::vector<ElectronMCTruth> electronsFromPizero;
27 
28  // Local variables
29  //const int SINGLE=1;
30  //const int DOUBLE=2;
31  //const int PYTHIA=3;
32  //const int ELECTRON_FLAV=1;
33  //const int PIZERO_FLAV=2;
34  //const int PHOTON_FLAV=3;
35 
36  //int ievtype=0;
37  //int ievflav=0;
38 
39  std::vector<SimTrack> pizeroTracks;
40  SimVertex primVtx;
41 
42  fill(theSimTracks, theSimVertices);
43 
44  int iPV = -1;
45  //int partType1=0;
46  //int partType2=0;
47  std::vector<SimTrack>::const_iterator iFirstSimTk = theSimTracks.begin();
48  if (!(*iFirstSimTk).noVertex()) {
49  iPV = (*iFirstSimTk).vertIndex();
50 
51  int vtxId = (*iFirstSimTk).vertIndex();
52  primVtx = theSimVertices[vtxId];
53 
54  //partType1 = (*iFirstSimTk).type();
55  std::cout << " Primary vertex id " << iPV << " first track type " << (*iFirstSimTk).type() << std::endl;
56  } else {
57  std::cout << " First track has no vertex " << std::endl;
58  }
59 
60  // CLHEP::HepLorentzVector primVtxPos= primVtx.position();
61  math::XYZTLorentzVectorD primVtxPos(
62  primVtx.position().x(), primVtx.position().y(), primVtx.position().z(), primVtx.position().e());
63 
64  // Look at a second track
65  iFirstSimTk++;
66  if (iFirstSimTk != theSimTracks.end()) {
67  if ((*iFirstSimTk).vertIndex() == iPV) {
68  //partType2 = (*iFirstSimTk).type();
69  std::cout << " second track type " << (*iFirstSimTk).type() << " vertex " << (*iFirstSimTk).vertIndex()
70  << std::endl;
71 
72  } else {
73  std::cout << " Only one kine track from Primary Vertex " << std::endl;
74  }
75  }
76 
77  int npv = 0;
78 
79  for (std::vector<SimTrack>::const_iterator iSimTk = theSimTracks.begin(); iSimTk != theSimTracks.end(); ++iSimTk) {
80  if ((*iSimTk).noVertex())
81  continue;
82 
83  int vertexId = (*iSimTk).vertIndex();
84  SimVertex vertex = theSimVertices[vertexId];
85 
86  std::cout << " Particle type " << (*iSimTk).type() << " Sim Track ID " << (*iSimTk).trackId() << " momentum "
87  << (*iSimTk).momentum() << " vertex position " << vertex.position() << std::endl;
88 
89  if ((*iSimTk).vertIndex() == iPV) {
90  npv++;
91  if (std::abs((*iSimTk).type()) == 111) {
92  std::cout << " Found a primary pizero with ID " << (*iSimTk).trackId() << " momentum " << (*iSimTk).momentum()
93  << std::endl;
94 
95  pizeroTracks.push_back(*iSimTk);
96 
97  // CLHEP::HepLorentzVector momentum = (*iSimTk).momentum();
98  math::XYZTLorentzVectorD momentum(
99  (*iSimTk).momentum().x(), (*iSimTk).momentum().y(), (*iSimTk).momentum().z(), (*iSimTk).momentum().e());
100  }
101  }
102  }
103 
104  std::cout << " There are " << npv << " particles originating in the PV " << std::endl;
105 
106  //if(npv > 4) {
107  // ievtype = PYTHIA;
108  //} else if(npv == 1) {
109  // if( std::abs(partType1) == 11 ) {
110  // ievtype = SINGLE; ievflav = ELECTRON_FLAV;
111  // } else if(partType1 == 111) {
112  // ievtype = SINGLE; ievflav = PIZERO_FLAV;
113  // } else if(partType1 == 22) {
114  // ievtype = SINGLE; ievflav = PHOTON_FLAV;
115  // }
116  //} else if(npv == 2) {
117  // if ( std::abs(partType1) == 11 && std::abs(partType2) == 11 ) {
118  // ievtype = DOUBLE; ievflav = ELECTRON_FLAV;
119  // } else if(partType1 == 111 && partType2 == 111) {
120  // ievtype = DOUBLE; ievflav = PIZERO_FLAV;
121  // } else if(partType1 == 22 && partType2 == 22) {
122  // ievtype = DOUBLE; ievflav = PHOTON_FLAV;
123  // }
124  //}
125 
126  for (std::vector<SimTrack>::iterator iPizTk = pizeroTracks.begin(); iPizTk != pizeroTracks.end(); ++iPizTk) {
127  std::cout << " Looping on the primary pizero pt " << sqrt((*iPizTk).momentum().perp2()) << " pizero track ID "
128  << (*iPizTk).trackId() << std::endl;
129 
130  photonsFromPizero.clear();
131  std::cout << " mcPhotons.size " << mcPhotons.size() << std::endl;
132  for (std::vector<PhotonMCTruth>::iterator iPho = mcPhotons.begin(); iPho != mcPhotons.end(); ++iPho) {
133  int phoVtxIndex = (*iPho).vertexInd();
134  SimVertex phoVtx = theSimVertices[phoVtxIndex];
135  unsigned int phoParentInd = phoVtx.parentIndex();
136  std::cout << " photon parent vertex index " << phoParentInd << std::endl;
137 
138  if (phoParentInd == (*iPizTk).trackId()) {
139  std::cout << "Matched Photon ID " << (*iPho).trackId() << " vtx " << phoParentInd << " with pizero "
140  << (*iPizTk).trackId() << std::endl;
141  photonsFromPizero.push_back(*iPho);
142  }
143  }
144  std::cout << " Photon matching the pizero vertex " << photonsFromPizero.size() << std::endl;
145 
146  // build pizero MC thruth
147  CLHEP::HepLorentzVector tmpMom(
148  (*iPizTk).momentum().px(), (*iPizTk).momentum().py(), (*iPizTk).momentum().pz(), (*iPizTk).momentum().e());
149  CLHEP::HepLorentzVector tmpPos(
150  primVtx.position().x(), primVtx.position().y(), primVtx.position().z(), primVtx.position().t());
151  result.push_back(PizeroMCTruth(tmpMom, photonsFromPizero, tmpPos));
152 
153  } // end loop over primary pizeros
154 
155  std::cout << " Pizero size " << result.size() << std::endl;
156 
157  return result;
158 }
159 
160 void PizeroMCTruthFinder::fill(const std::vector<SimTrack>& simTracks, const std::vector<SimVertex>& simVertices) {
161  unsigned nVtx = simVertices.size();
162  unsigned nTks = simTracks.size();
163 
164  // Empty event, do nothin'
165  if (nVtx == 0)
166  return;
167 
168  // create a map associating geant particle id and position in the
169  // event SimTrack vector
170  for (unsigned it = 0; it < nTks; ++it) {
171  geantToIndex_[simTracks[it].trackId()] = it;
172  std::cout << " PizeroMCTruthFinder::fill it " << it << " simTracks[it].trackId() " << simTracks[it].trackId()
173  << std::endl;
174  }
175 }
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
PhotonMCTruthFinder * thePhotonMCTruthFinder_
ElectronMCTruthFinder * theElectronMCTruthFinder_
tuple result
Definition: mps_fire.py:311
int parentIndex() const
Definition: SimVertex.h:29
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::map< unsigned, unsigned > geantToIndex_
const math::XYZTLorentzVectorD & position() const
Definition: CoreSimVertex.h:21
std::vector< PizeroMCTruth > find(const std::vector< SimTrack > &simTracks, const std::vector< SimVertex > &simVertices)
std::vector< PhotonMCTruth > find(const std::vector< SimTrack > &simTracks, const std::vector< SimVertex > &simVertices)
tuple cout
Definition: gather_cfg.py:144
void fill(const std::vector< SimTrack > &theSimTracks, const std::vector< SimVertex > &theSimVertices)