CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
ElectronMCTruthFinder Class Reference

#include <ElectronMCTruthFinder.h>

Public Member Functions

 ElectronMCTruthFinder ()
 
std::vector< ElectronMCTruthfind (const std::vector< SimTrack > &simTracks, const std::vector< SimVertex > &simVertices)
 
virtual ~ElectronMCTruthFinder ()
 

Private Member Functions

void fill (const std::vector< SimTrack > &theSimTracks, const std::vector< SimVertex > &theSimVertices)
 

Private Attributes

std::map< unsigned, unsigned > geantToIndex_
 
PhotonMCTruthFinderthePhotonMCTruthFinder_
 

Detailed Description

Definition at line 13 of file ElectronMCTruthFinder.h.

Constructor & Destructor Documentation

ElectronMCTruthFinder::ElectronMCTruthFinder ( )

Definition at line 6 of file ElectronMCTruthFinder.cc.

6  {
7 
8 
9 }
ElectronMCTruthFinder::~ElectronMCTruthFinder ( )
virtual

Definition at line 11 of file ElectronMCTruthFinder.cc.

12 {
13 
14 }

Member Function Documentation

void ElectronMCTruthFinder::fill ( const std::vector< SimTrack > &  theSimTracks,
const std::vector< SimVertex > &  theSimVertices 
)
private

Definition at line 232 of file ElectronMCTruthFinder.cc.

References geantToIndex_.

Referenced by find().

233  {
234  //std::cout << " ElectronMCTruthFinder::fill " << std::endl;
235 
236  unsigned nVtx = simVertices.size();
237  unsigned nTks = simTracks.size();
238 
239  // Empty event, do nothin'
240  if ( nVtx == 0 ) return;
241 
242  // create a map associating geant particle id and position in the
243  // event SimTrack vector
244  for( unsigned it=0; it<nTks; ++it ) {
245  geantToIndex_[ simTracks[it].trackId() ] = it;
246  //std::cout << " ElectronMCTruthFinder::fill it " << it << " simTracks[it].trackId() " << simTracks[it].trackId() << std::endl;
247 
248  }
249 
250 
251 }
std::map< unsigned, unsigned > geantToIndex_
std::vector< ElectronMCTruth > ElectronMCTruthFinder::find ( const std::vector< SimTrack > &  simTracks,
const std::vector< SimVertex > &  simVertices 
)

Now store the electron truth

here fill the electron

Definition at line 17 of file ElectronMCTruthFinder.cc.

References funct::abs(), alignCSCRings::e, fill(), geantToIndex_, reco::if(), CoreSimTrack::momentum(), SimVertex::parentIndex(), CoreSimVertex::position(), query::result, CoreSimTrack::trackId(), CoreSimTrack::type(), and SimTrack::vertIndex().

Referenced by MCElectronAnalyzer::analyze().

17  {
18  //std::cout << " ElectronMCTruthFinder::find " << std::endl;
19 
20 
21 
22 
23  std::vector<ElectronMCTruth> result;
24 
25  // Local variables
26  //const int SINGLE=1;
27  //const int DOUBLE=2;
28  //const int PYTHIA=3;
29  //const int ELECTRON_FLAV=1;
30  //const int PIZERO_FLAV=2;
31  //const int PHOTON_FLAV=3;
32 
33  //int ievtype=0;
34  //int ievflav=0;
35 
36 
37  std::vector<SimTrack> electronTracks;
38  SimVertex primVtx;
39 
40  fill(theSimTracks, theSimVertices);
41 
42  int iPV=-1;
43  //int partType1=0;
44  //int partType2=0;
45  std::vector<SimTrack>::const_iterator iFirstSimTk = theSimTracks.begin();
46  if ( !(*iFirstSimTk).noVertex() ) {
47  iPV = (*iFirstSimTk).vertIndex();
48 
49  int vtxId = (*iFirstSimTk).vertIndex();
50  primVtx = theSimVertices[vtxId];
51 
52  //partType1 = (*iFirstSimTk).type();
53 
54 
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(primVtx.position().x(),
62  primVtx.position().y(),
63  primVtx.position().z(),
64  primVtx.position().e());
65 
66  // Look at a second track
67  iFirstSimTk++;
68  //if ( iFirstSimTk!= theSimTracks.end() ) {
69  //
70  // if ( (*iFirstSimTk).vertIndex() == iPV) {
71  // partType2 = (*iFirstSimTk).type();
72  //
73  // //std::cout << " second track type " << (*iFirstSimTk).type() << " vertex " << (*iFirstSimTk).vertIndex() << std::endl;
74  //
75  // } else {
76  // //std::cout << " Only one kine track from Primary Vertex " << std::endl;
77  // }
78  //}
79 
80  //std::cout << " Loop over all particles " << std::endl;
81 
82  int npv=0;
83  for (std::vector<SimTrack>::const_iterator iSimTk = theSimTracks.begin(); iSimTk != theSimTracks.end(); ++iSimTk){
84  if ( (*iSimTk).noVertex() ) continue;
85 
86  //int vertexId = (*iSimTk).vertIndex();
87  //SimVertex vertex = theSimVertices[vertexId];
88 
89  //std::cout << " Particle type " << (*iSimTk).type() << " Sim Track ID " << (*iSimTk).trackId() << " momentum " << (*iSimTk).momentum() << " vertex position " << vertex.position() << " vertex ID " << vertexId << std::endl;
90  if ( (*iSimTk).vertIndex() == iPV ) {
91  npv++;
92  if ( std::abs((*iSimTk).type() ) == 11) {
93  //std::cout << " Found a primary electron with ID " << (*iSimTk).trackId() << " momentum " << (*iSimTk).momentum() << std::endl;
94  electronTracks.push_back( *iSimTk );
95  }
96  }
97  }
98  //std::cout << " There are " << npv << " particles originating in the PV " << std::endl;
99 
100 
101  //if(npv > 4) {
102  // ievtype = PYTHIA;
103  //} else if(npv == 1) {
104  // if( std::abs(partType1) == 11 ) {
105  // ievtype = SINGLE; ievflav = ELECTRON_FLAV;
106  // } else if(partType1 == 111) {
107  // ievtype = SINGLE; ievflav = PIZERO_FLAV;
108  // } else if(partType1 == 22) {
109  // ievtype = SINGLE; ievflav = PHOTON_FLAV;
110  // }
111  //} else if(npv == 2) {
112  // if ( std::abs(partType1) == 11 && std::abs(partType2) == 11 ) {
113  // ievtype = DOUBLE; ievflav = ELECTRON_FLAV;
114  // } else if(partType1 == 111 && partType2 == 111) {
115  // ievtype = DOUBLE; ievflav = PIZERO_FLAV;
116  // } else if(partType1 == 22 && partType2 == 22) {
117  // ievtype = DOUBLE; ievflav = PHOTON_FLAV;
118  // }
119  //}
120 
121 
122 
124  std::vector<CLHEP::Hep3Vector> bremPos;
125  std::vector<CLHEP::HepLorentzVector> pBrem;
126  std::vector<float> xBrem;
127 
128 
129  for (std::vector<SimTrack>::iterator iEleTk = electronTracks.begin(); iEleTk != electronTracks.end(); ++iEleTk){
130  //std::cout << " Looping on the primary electron pt " << std::sqrt((*iEleTk).momentum().perp2()) << " electron track ID " << (*iEleTk).trackId() << std::endl;
131 
132 
133 
134  SimTrack trLast =(*iEleTk);
135  unsigned int eleId = (*iEleTk).trackId();
136  float remainingEnergy =trLast.momentum().e();
137 // CLHEP::HepLorentzVector motherMomentum = (*iEleTk).momentum();
138 // CLHEP::HepLorentzVector primEleMom = (*iEleTk).momentum();
139  math::XYZTLorentzVectorD motherMomentum((*iEleTk).momentum().x(),
140  (*iEleTk).momentum().y(),
141  (*iEleTk).momentum().z(),
142  (*iEleTk).momentum().e());
143  math::XYZTLorentzVectorD primEleMom(motherMomentum);
144  int eleVtxIndex= (*iEleTk).vertIndex();
145 
146  bremPos.clear();
147  pBrem.clear();
148  xBrem.clear();
149 
150 
151  for (std::vector<SimTrack>::const_iterator iSimTk = theSimTracks.begin(); iSimTk != theSimTracks.end(); ++iSimTk){
152 
153  if ( (*iSimTk).noVertex() ) continue;
154  if ( (*iSimTk).vertIndex() == iPV ) continue;
155 
156  //std::cout << " (*iEleTk)->trackId() " << (*iEleTk).trackId() << " (*iEleTk)->vertIndex() "<< (*iEleTk).vertIndex() << " (*iSimTk).vertIndex() " << (*iSimTk).vertIndex() << " (*iSimTk).type() " << (*iSimTk).type() << " (*iSimTk).trackId() " << (*iSimTk).trackId() << std::endl;
157 
158  int vertexId1 = (*iSimTk).vertIndex();
159  SimVertex vertex1 = theSimVertices[vertexId1];
160  int vertexId2 = trLast.vertIndex();
161  //SimVertex vertex2 = theSimVertices[vertexId2];
162 
163 
164  int motherId=-1;
165 
166  if( ( vertexId1 == vertexId2 ) && ( (*iSimTk).type() == (*iEleTk).type() ) && trLast.type() == 22 ) {
167  //std::cout << " Here a e/gamma brem vertex " << std::endl;
168 
169  //std::cout << " Secondary from electron: particle1 type " << (*iSimTk).type() << " trackId " << (*iSimTk).trackId() << " vertex ID " << vertexId1 << " vertex position " << std::sqrt(vertex1.position().perp2()) << " parent index "<< vertex1.parentIndex() << std::endl;
170 
171  //std::cout << " Secondary from electron: particle2 type " << trLast.type() << " trackId " << trLast.trackId()<< " vertex ID " << vertexId2 << " vertex position " << std::sqrt(vertex2.position().perp2()) << " parent index " << vertex2.parentIndex() << std::endl;
172 
173  //std::cout << " Electron pt " << std::sqrt((*iSimTk).momentum().perp2()) << " photon pt " << std::sqrt(trLast.momentum().perp2()) << "Mother electron pt " << sqrt(motherMomentum.perp2()) << std::endl;
174  //std::cout << " eleId " << eleId << std::endl;
175  float eLoss = remainingEnergy - ( (*iSimTk).momentum() + trLast.momentum()).e();
176  //std::cout << " eLoss " << eLoss << std::endl;
177 
178 
179  if ( vertex1.parentIndex() ) {
180 
181  unsigned motherGeantId = vertex1.parentIndex();
182  std::map<unsigned, unsigned >::iterator association = geantToIndex_.find( motherGeantId );
183  if(association != geantToIndex_.end() )
184  motherId = association->second;
185 
186  //int motherType = motherId == -1 ? 0 : theSimTracks[motherId].type();
187  //std::cout << " Parent to this vertex motherId " << motherId << " mother type " << motherType << " Sim track ID " << theSimTracks[motherId].trackId() << std::endl;
188  if ( theSimTracks[motherId].trackId() == eleId ) {
189 
190  //std::cout << " ***** Found the Initial Mother Electron **** theSimTracks[motherId].trackId() " << theSimTracks[motherId].trackId() << " eleId " << eleId << std::endl;
191  eleId= (*iSimTk).trackId();
192  remainingEnergy = (*iSimTk).momentum().e();
193  motherMomentum = (*iSimTk).momentum();
194 
195 
196  pBrem.push_back( CLHEP::HepLorentzVector(trLast.momentum().px(),trLast.momentum().py(),
197  trLast.momentum().pz(),trLast.momentum().e()) );
198  bremPos.push_back( CLHEP::HepLorentzVector(vertex1.position().x(),vertex1.position().y(),
199  vertex1.position().z(),vertex1.position().t()) );
200  xBrem.push_back(eLoss);
201 
202  }
203 
204 
205 
206 
207  } else {
208  //std::cout << " This vertex has no parent tracks " << std::endl;
209  }
210 
211  }
212  trLast=(*iSimTk);
213 
214  } // End loop over all SimTracks
215  //std::cout << " Going to build the ElectronMCTruth: pBrem size " << pBrem.size() << std::endl;
217  CLHEP::HepLorentzVector tmpEleMom(primEleMom.px(),primEleMom.py(),
218  primEleMom.pz(),primEleMom.e() ) ;
219  CLHEP::HepLorentzVector tmpVtxPos(primVtxPos.x(),primVtxPos.y(),primVtxPos.z(),primVtxPos.t());
220  result.push_back ( ElectronMCTruth( tmpEleMom, eleVtxIndex, bremPos, pBrem, xBrem, tmpVtxPos,(*iEleTk) ) ) ;
221 
222 
223  } // End loop over primary electrons
224 
225 
226 
227  return result;
228 }
std::map< unsigned, unsigned > geantToIndex_
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
void fill(const std::vector< SimTrack > &theSimTracks, const std::vector< SimVertex > &theSimVertices)
int parentIndex() const
Definition: SimVertex.h:33
tuple result
Definition: query.py:137
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const math::XYZTLorentzVectorD & position() const
Definition: CoreSimVertex.h:26
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
Definition: SimTrack.h:29
unsigned int trackId() const
Definition: CoreSimTrack.h:49
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:40
if(dp >Float(M_PI)) dp-
const math::XYZTLorentzVectorD & momentum() const
particle info...
Definition: CoreSimTrack.h:36

Member Data Documentation

std::map<unsigned, unsigned> ElectronMCTruthFinder::geantToIndex_
private

Definition at line 28 of file ElectronMCTruthFinder.h.

Referenced by fill(), and find().

PhotonMCTruthFinder* ElectronMCTruthFinder::thePhotonMCTruthFinder_
private

Definition at line 29 of file ElectronMCTruthFinder.h.