ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/src/GeneratorTools.cc
Revision: 1.4
Committed: Wed Aug 17 18:11:07 2011 UTC (13 years, 8 months ago) by sixie
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_029c, Mit_029b, Mit_029a, Mit_028a, Mit_028, Mit_027, Mit_027a, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, HEAD
Changes since 1.3: +1 -0 lines
Log Message:
add mass to the gen table print out

File Contents

# User Rev Content
1 sixie 1.1 // $Id $
2    
3     #include "MitPhysics/Utils/interface/GeneratorTools.h"
4     #include "MitCommon/MathTools/interface/MathUtils.h"
5     #include "MitAna/DataCont/interface/ObjArray.h"
6     #include "MitAna/DataUtil/interface/Debug.h"
7    
8     using namespace mithep;
9     using namespace std;
10    
11     //--------------------------------------------------------------------------------------------------
12     void GeneratorTools::PrintHepMCTable(const mithep::Collection<mithep::MCParticle> *particles,
13     Bool_t showDaughters = true, int suppressEntriesAfterThisIndex = -1) {
14    
15     //Print entire HepMC Decay Table
16    
17     for (UInt_t d=0; d<particles->GetEntries(); d++) {
18     if (suppressEntriesAfterThisIndex == -1 || int(d) <= suppressEntriesAfterThisIndex) {
19     cout << "Particle " << d << " : " << particles->At(d)->PdgId() << " "
20     << particles->At(d)->Status() << " "
21 sixie 1.4 << particles->At(d)->Mass() << " "
22 sixie 1.1 << particles->At(d)->Pt() << " "
23     << particles->At(d)->Eta() << " " << particles->At(d)->Phi()
24     << " IsParton:" << particles->At(d)->IsParton()
25     << " Decays at " << particles->At(d)->DecayVertex().Rho() << " ";
26     if (particles->At(d)->HasMother()) {
27     cout << " Mother: " << particles->At(d)->Mother()->PdgId() << " "
28     << particles->At(d)->Mother()->Status() << " "
29     << particles->At(d)->Mother()->Pt() << " "
30     << particles->At(d)->Mother()->Eta() << " "
31     << particles->At(d)->Mother()->Phi() << " ";
32     }
33     cout << " " << particles->At(d)->NDaughters() << " Daughters : ";
34     if (showDaughters) {
35     for (UInt_t e=0;e<particles->At(d)->NDaughters();e++) {
36     if (e <= 4 || particles->At(d)->Daughter(e)->Pt() > 5.0 ) {
37     cout << " | "
38     << particles->At(d)->Daughter(e)->PdgId() << " "
39     << particles->At(d)->Daughter(e)->Status() << " "
40     << particles->At(d)->Daughter(e)->Pt() << " "
41     << particles->At(d)->Daughter(e)->Eta() << " "
42     << particles->At(d)->Daughter(e)->Phi() << " "
43     << " ";
44     } else {
45     cout << " ... ";
46     }
47     }
48     }
49     cout << endl;
50     }
51     }
52     return;
53     }
54    
55     //--------------------------------------------------------------------------------------------------
56     void GeneratorTools::PrintNearbyParticles(const mithep::Collection<mithep::MCParticle> *particles,
57     Double_t eta, Double_t phi, Double_t deltaR = 0.3) {
58    
59     //Print Particles in the HepMC table which are within the given DeltaR distance
60    
61     mithep::ObjArray<mithep::MCParticle> *descendants = new mithep::ObjArray<mithep::MCParticle>;
62    
63     //Print all particles and their descendants that are within the dR Cone.
64     for (UInt_t d=0; d<particles->GetEntries(); d++) {
65     Double_t dR = MathUtils::DeltaR(phi,eta,particles->At(d)->Phi(),particles->At(d)->Eta());
66    
67     //print out the particle if it is inside the dR cone, or if it is a descendant
68     if (dR < deltaR || descendants->HasObject(particles->At(d))) {
69     cout << "Particle " << d << " : " << particles->At(d)->PdgId() << " "
70     << particles->At(d)->Status() << " "
71     << particles->At(d)->Pt() << " "
72     << particles->At(d)->Eta() << " " << particles->At(d)->Phi()
73     << " IsParton:" << particles->At(d)->IsParton()
74     << " Decays at " << particles->At(d)->DecayVertex().Rho()
75     << " " << particles->At(d)->NDaughters() << " Daughters : ";
76    
77     for (UInt_t e=0;e<particles->At(d)->NDaughters();e++) {
78     descendants->Add(particles->At(d)->Daughter(e));
79     if (e <= 4 || particles->At(d)->Daughter(e)->Pt() > 5.0) {
80     cout << " | "
81     << particles->At(d)->Daughter(e)->PdgId() << " "
82     << particles->At(d)->Daughter(e)->Status() << " "
83     << particles->At(d)->Daughter(e)->Pt() << " "
84     << particles->At(d)->Daughter(e)->Eta() << " "
85     << particles->At(d)->Daughter(e)->Phi() << " "
86     << " ";
87     }
88     }
89     cout << " ... ";
90     cout << endl;
91     }
92     }
93     return;
94     }
95    
96     //***********************************************************************************************
97     //Match Electron to a SimTrack
98     //***********************************************************************************************
99     const MCParticle* GeneratorTools::MatchElectronToSimParticle(const mithep::Collection<mithep::MCParticle> *particles,
100     const mithep::Track *eleTrack, Bool_t isGsfTrack, Int_t printDebugLevel,
101     Bool_t printHepMCTable) {
102    
103     //Match Clean Electron to a SimTrack and then trace back up the mother chain.
104     const MCParticle *match = NULL;
105    
106     Double_t matchDeltaPtOverPt = 0.0;
107     Double_t secondaryMatchDeltaPtOverPt = 0.0;
108     Double_t minProductionVertexRho = 10000.0;
109     Double_t secondaryMatchMinDR = 5000.0;
110     Double_t minDR = 5000.0;
111     const MCParticle *matchedSimChargedParticle = NULL;
112     const MCParticle *secondaryMatchedSimChargedParticle = NULL;
113    
114     if (printDebugLevel >= 5) cout << "\nSimulated particles near Electron\n";
115     for(UInt_t j=0;j<particles->GetEntries();j++) {
116     Bool_t isStable = false;
117     Bool_t isTrackable = false;
118     if(particles->At(j)->NDaughters() == 0 || particles->At(j)->DecayVertex().Rho() > 10.0)
119     isStable = true;
120    
121     if (particles->At(j)->Mother() && particles->At(j)->Mother()->DecayVertex().Rho() <= 40)
122     isTrackable = true;
123    
124     if (particles->At(j)->IsSimulated()) {
125     Double_t DR = MathUtils::DeltaR(eleTrack->Phi(), eleTrack->Eta(), particles->At(j)->Phi(),
126     particles->At(j)->Eta());
127    
128     Double_t dPtOverPt = (eleTrack->Pt() - particles->At(j)->Pt())/eleTrack->Pt();
129    
130     //remove Neutrals
131     if (particles->At(j)->Charge() != 0) {
132     if( DR < 0.3) {
133     if (printDebugLevel >= 5) {
134     cout << "ChargedSimulatedParticle: " << j << " : " << fabs(dPtOverPt) << " : " << DR
135     << " " << particles->At(j)->PdgId()
136     << " " << particles->At(j)->Status() << " " << particles->At(j)->Pt()
137     << " " << particles->At(j)->Eta() << " " << particles->At(j)->Phi()
138     << " produced at ";
139    
140     if (particles->At(j)->Mother())
141     cout << particles->At(j)->Mother()->DecayVertex().Rho();
142     else
143     cout << "0.0";
144     cout << " decays at ";
145     if (particles->At(j)->NDaughters() > 0)
146     cout << particles->At(j)->DecayVertex().Rho();
147     else
148     cout << " Stable ";
149     cout << endl;
150     }
151     }
152    
153     //regular match
154     if (DR < minDR && fabs(dPtOverPt) < 0.5 && DR < 0.3 && isStable && isTrackable ) {
155     minDR = DR;
156     matchedSimChargedParticle = particles->At(j);
157     }
158    
159     Double_t productionVertexRho = 20000.0;
160     if (particles->At(j)->Mother())
161     productionVertexRho = particles->At(j)->Mother()->DecayVertex().Rho();
162    
163     //perform secondary match for GSF track only electrons
164     if ( DR < 0.3 && particles->At(j)->AbsPdgId() == 11 && particles->At(j)->Pt() > 3.0
165     && productionVertexRho < minProductionVertexRho ) {
166     minProductionVertexRho = productionVertexRho;
167     secondaryMatchedSimChargedParticle = particles->At(j);
168     }
169     } //is charged particle
170     } //is simulated
171     }// for all particles
172    
173     if (printDebugLevel >= 5) {
174     if (matchedSimChargedParticle && minDR < 0.3) {
175     cout << "Match : " << matchDeltaPtOverPt << " : " << minDR
176     << " " << matchedSimChargedParticle->PdgId()
177     << " " << matchedSimChargedParticle->Status() << " " << matchedSimChargedParticle->Pt()
178     << " " << matchedSimChargedParticle->Eta() << " " << matchedSimChargedParticle->Phi()
179     << " produced at ";
180     if (matchedSimChargedParticle->Mother())
181     cout << matchedSimChargedParticle->Mother()->DecayVertex().Rho();
182     else
183     cout << "0.0";
184     cout << " decays at ";
185     if (matchedSimChargedParticle->NDaughters() > 0)
186     cout << matchedSimChargedParticle->DecayVertex().Rho();
187     else
188     cout << " Stable ";
189     cout << endl;
190     }
191     }
192    
193     if (!(matchedSimChargedParticle && minDR < 0.3)) {
194     if (secondaryMatchedSimChargedParticle && isGsfTrack) {
195     matchedSimChargedParticle = secondaryMatchedSimChargedParticle;
196     matchDeltaPtOverPt = secondaryMatchDeltaPtOverPt;
197     minDR = secondaryMatchMinDR;
198     }
199    
200     if (printDebugLevel >= 5) {
201     if (matchedSimChargedParticle && minDR < 0.3) {
202     cout << "secondaryMatch : " << matchDeltaPtOverPt << " : " << minDR
203     << " " << matchedSimChargedParticle->PdgId()
204     << " " << matchedSimChargedParticle->Status() << " " << matchedSimChargedParticle->Pt()
205     << " " << matchedSimChargedParticle->Eta() << " " << matchedSimChargedParticle->Phi()
206     << " produced at ";
207     if (matchedSimChargedParticle->Mother())
208     cout << matchedSimChargedParticle->Mother()->DecayVertex().Rho();
209     else
210     cout << "0.0";
211     cout << " decays at ";
212     if (matchedSimChargedParticle->NDaughters() > 0)
213     cout << matchedSimChargedParticle->DecayVertex().Rho();
214     else
215     cout << " Stable ";
216     cout << endl;
217     }
218     }
219     }
220    
221     if (matchedSimChargedParticle && minDR < 0.3)
222     match = matchedSimChargedParticle;
223    
224     //MDB(kAnalysis, 6) PrintNearbyParticles(particles, ele->Eta(), ele->Phi(), 0.3);
225     MDB(kAnalysis, 7) if (printHepMCTable) PrintHepMCTable(particles);
226    
227     return match;
228     }
229    
230     //***********************************************************************************************
231     //Return the meson ancestor given the input matched simulated particle. Intended to be the
232     //particle corresponding to the large x fragmentation resulting in an electron fake.
233     //***********************************************************************************************
234     const MCParticle* GeneratorTools::FindElectronFakeAncestor(const mithep::MCParticle *matchedSimChargedParticle) {
235    
236     if (!matchedSimChargedParticle)
237     return 0;
238    
239     //If it's an electron, try
240     //1) to match to a conversion, then find ancestor pi0
241     //2) find B / D meson if it's semi-leptonic decay
242     //3) if it's a prompt photon, return null.
243     if (matchedSimChargedParticle->AbsPdgId() == 11) {
244    
245     //if no mother then return null
246     if (!matchedSimChargedParticle->Mother()) {
247     MDB(kAnalysis, 5) cout << "no mother\n";
248     return 0;
249     }
250    
251    
252     //while look to look for photon mother
253     Bool_t FoundPhotonMother = false;
254     const MCParticle *tmpParticle = matchedSimChargedParticle;
255     while (tmpParticle->Mother() && tmpParticle->Mother()->PdgId() != 22 ) {
256     tmpParticle = tmpParticle->Mother();
257     }
258     if (tmpParticle->Mother() && tmpParticle->Mother()->PdgId() == 22) {
259     FoundPhotonMother = true;
260     }
261    
262     //conversions
263     if (FoundPhotonMother) {
264     //find the meson ancestor.
265     const MCParticle *tmpParticle = matchedSimChargedParticle;
266     while (tmpParticle->Mother()
267     &&
268     tmpParticle->Mother()->PdgId() != 111
269     &&
270     tmpParticle->Mother()->PdgId() != 221
271     &&
272     tmpParticle->Mother()->PdgId() != 223
273     &&
274     !(tmpParticle->Mother()->PdgId() == 22 && tmpParticle->Mother()->Mother() &&
275     tmpParticle->Mother()->Mother()->IsParton())
276     &&
277     tmpParticle->Mother()->AbsPdgId() != 24
278     &&
279     tmpParticle->Mother()->AbsPdgId() != 23
280     &&
281     tmpParticle->Mother()->AbsPdgId() != 92
282     &&
283     !tmpParticle->Mother()->IsParton()
284     ) {
285     MDB(kAnalysis, 5) {
286     cout << "find : " << tmpParticle->Mother()->PdgId() << " " << tmpParticle->Mother()->Status()
287     << " " << tmpParticle->Mother()->Pt() << " " << tmpParticle->Mother()->Eta() << " "
288     << tmpParticle->Mother()->Phi() << endl;
289     }
290     tmpParticle = tmpParticle->Mother();
291     }
292     if (tmpParticle->Mother()->PdgId() == 111
293     ||tmpParticle->Mother()->PdgId() == 221
294     ||tmpParticle->Mother()->PdgId() == 223
295     ) {
296     return tmpParticle->Mother();
297     } else if (tmpParticle->Mother()->PdgId() == 22
298     || tmpParticle->Mother()->PdgId() == 23
299     || tmpParticle->Mother()->PdgId() == 24
300     ) {
301     //prompt photon or FSR photon or Brem photon
302     return 0;
303     } else {
304     return 0;
305     }
306     //end if sim electron mother was a photon
307     } else {
308     //now look for semi-leptonic decays
309     const MCParticle *tmpParticle = matchedSimChargedParticle;
310     while (tmpParticle->Mother()
311     &&
312     !((tmpParticle->Mother()->AbsPdgId() >= 400 &&
313     tmpParticle->Mother()->AbsPdgId() < 600) ||
314     (tmpParticle->Mother()->AbsPdgId() >= 4000 &&
315     tmpParticle->Mother()->AbsPdgId() < 6000)
316     )
317     ) {
318     MDB(kAnalysis, 5) {
319     cout << "find : " << tmpParticle->Mother()->PdgId() << " " << tmpParticle->Mother()->Status()
320     << " " << tmpParticle->Mother()->Pt() << " " << tmpParticle->Mother()->Eta() << " "
321     << tmpParticle->Mother()->Phi() << endl;
322     }
323     tmpParticle = tmpParticle->Mother();
324     }
325     if (tmpParticle->Mother() && tmpParticle->Mother()->HasDaughter(11)) {
326     return tmpParticle->Mother();
327     }
328     }
329     //end if sim particle was an electron
330     } else if (matchedSimChargedParticle->AbsPdgId() == 211 ) {
331     return matchedSimChargedParticle;
332     } else if (matchedSimChargedParticle->AbsPdgId() == 321) {
333     return matchedSimChargedParticle;
334     } else {
335     return 0;
336     }
337     return 0;
338     }
339    
340    
341     //***********************************************************************************************
342     //Categorizes Electron Fakes based on the input matched simulated particle
343     //***********************************************************************************************
344     Int_t GeneratorTools::CategorizeFakeElectron(const mithep::MCParticle *matchedSimChargedParticle) {
345    
346     //Categorizes Electron Fakes based on the input matched simulated particle
347     Int_t FakeCategory = 0;
348    
349     if (!matchedSimChargedParticle)
350     return FakeCategory;
351    
352     //Try to match to conversion
353     if (matchedSimChargedParticle->AbsPdgId() == 11) {
354     const MCParticle *mother = matchedSimChargedParticle->Mother();
355    
356     if (!mother) {
357     MDB(kAnalysis, 5) cout << "no mother\n";
358     FakeCategory = 7;
359     } else {
360     //try to find an ancestor that was a pi0 or a heavy meson
361     MDB(kAnalysis, 5) cout << "find pi0 or heavy meson ancestor\n";
362     const MCParticle *tmpParticle = matchedSimChargedParticle;
363     while (tmpParticle->Mother()
364     &&
365     tmpParticle->Mother()->PdgId() != 111
366     &&
367     tmpParticle->Mother()->PdgId() != 221
368     &&
369     tmpParticle->Mother()->PdgId() != 223
370     &&
371     !(tmpParticle->Mother()->PdgId() == 22 && tmpParticle->Mother()->Mother() &&
372     tmpParticle->Mother()->Mother()->IsParton())
373     &&
374     !((tmpParticle->Mother()->AbsPdgId() >= 400 &&
375     tmpParticle->Mother()->AbsPdgId() < 600) ||
376     (tmpParticle->Mother()->AbsPdgId() >= 4000 &&
377     tmpParticle->Mother()->AbsPdgId() < 6000)
378     )
379     &&
380     tmpParticle->Mother()->AbsPdgId() != 24
381     &&
382     tmpParticle->Mother()->AbsPdgId() != 23
383     &&
384     tmpParticle->Mother()->AbsPdgId() != 92
385     &&
386     !tmpParticle->Mother()->IsParton()
387     ) {
388     MDB(kAnalysis, 5) {
389     cout << "find : " << tmpParticle->Mother()->PdgId() << " " << tmpParticle->Mother()->Status()
390     << " " << tmpParticle->Mother()->Pt() << " " << tmpParticle->Mother()->Eta() << " "
391     << tmpParticle->Mother()->Phi() << endl;
392     }
393     tmpParticle = tmpParticle->Mother();
394     }
395     const MCParticle *Ancestor = tmpParticle->Mother();
396     if (Ancestor) {
397    
398     MDB(kAnalysis, 5) {
399     cout << "Found ancestor: " << Ancestor->PdgId() << " "
400     << Ancestor->Status() << " " << Ancestor->Pt()
401     << " " << Ancestor->Eta() << " "
402     << Ancestor->Phi() << " HasElectronDaughter: " << Ancestor->HasDaughter(11)
403     << endl;
404     }
405    
406     if (Ancestor->PdgId() == 111 || Ancestor->PdgId() == 221 || Ancestor->PdgId() == 223) {
407     FakeCategory = 1; //pi0->photon->conversion
408     } else if (Ancestor->PdgId() == 22) {
409     FakeCategory = 6; //prompt photon -> conversion
410     } else if ((Ancestor->AbsPdgId() >= 400 &&
411     Ancestor->AbsPdgId() < 600) ||
412 ceballos 1.2 ((Ancestor->AbsPdgId() >= 4000 &&
413 sixie 1.1 Ancestor->AbsPdgId() < 6000) &&
414 ceballos 1.2 Ancestor->HasDaughter(11))) {
415 sixie 1.1 FakeCategory = 4; //heavy flavor
416     } else if (Ancestor->AbsPdgId() == 24 || Ancestor->AbsPdgId() == 23) {
417     FakeCategory = 5;
418     } else {
419     FakeCategory = 7;
420     }
421     } else {
422     FakeCategory = 7;
423     }
424     }
425     } else if (matchedSimChargedParticle->AbsPdgId() == 211 ) {
426     FakeCategory = 2;
427     } else if (matchedSimChargedParticle->AbsPdgId() == 321) {
428     FakeCategory = 3;
429     } else {
430     FakeCategory = 7;
431     }
432     return FakeCategory;
433     }
434    
435    
436     //***********************************************************************************************
437     //Match Muon to a SimTrack
438     //***********************************************************************************************
439     const MCParticle* GeneratorTools::MatchMuonToSimParticle(
440     const mithep::Collection<mithep::MCParticle> *particles,const mithep::Track *muonTrack,
441     Bool_t isTrackerTrack, Int_t printDebugLevel, Bool_t printHepMCTable) {
442    
443     //Match Muon to a SimTrack
444     const MCParticle *match = NULL;
445    
446     Double_t minDR = 5000.0;
447     Double_t matchDeltaPtOverPt = 0.0;
448     Double_t secondaryMatchMinDR = 5000.0;
449     Double_t secondaryMatchDeltaPtOverPt = 0.0;
450    
451     const MCParticle *matchedSimChargedParticle = NULL;
452     const MCParticle *secondaryMatchedSimChargedParticle = NULL;
453    
454     if (printDebugLevel >= 5) cout << "\nSimulated particles near Electron\n";
455     for(UInt_t j=0;j<particles->GetEntries();j++) {
456 fabstoec 1.3 // removed byb Fabian... they are NOT used
457     // Bool_t isStable = false;
458     // Bool_t isTrackable = false;
459 sixie 1.1
460     if (particles->At(j)->IsSimulated()) {
461     Double_t DR = MathUtils::DeltaR(muonTrack->Phi(), muonTrack->Eta(), particles->At(j)->Phi(),
462     particles->At(j)->Eta());
463    
464     Double_t dPtOverPt = (muonTrack->Pt() - particles->At(j)->Pt())/muonTrack->Pt();
465    
466     //remove Neutrals
467     if (particles->At(j)->Charge() != 0) {
468     if( DR < 0.3) {
469     if (printDebugLevel >= 5) {
470     cout << "ChargedSimulatedParticle: " << j << " : " << fabs(dPtOverPt) << " : " << DR
471     << " " << particles->At(j)->PdgId()
472     << " " << particles->At(j)->Status() << " " << particles->At(j)->Pt()
473     << " " << particles->At(j)->Eta() << " " << particles->At(j)->Phi()
474     << " produced at ";
475    
476     if (particles->At(j)->Mother())
477     cout << particles->At(j)->Mother()->DecayVertex().Rho();
478     else
479     cout << "0.0";
480     cout << " decays at ";
481     if (particles->At(j)->NDaughters() > 0)
482     cout << particles->At(j)->DecayVertex().Rho();
483     else
484     cout << " Stable ";
485     cout << endl;
486     }
487     }
488    
489     //regular match. match to a muon
490     if (DR < minDR && DR < 0.3 && particles->At(j)->AbsPdgId() == 13
491     && particles->At(j)->Pt() > 5.0
492     && (particles->At(j)->Mother() &&
493     particles->At(j)->Mother()->DecayVertex().Rho() <= 150
494     )
495     ) {
496     minDR = DR;
497     matchedSimChargedParticle = particles->At(j);
498     matchDeltaPtOverPt = dPtOverPt;
499     }
500    
501     //perform secondary match for non muons
502     if (DR < secondaryMatchMinDR && DR < 0.3 && fabs(dPtOverPt) < 0.5 ) {
503     secondaryMatchMinDR = DR;
504     secondaryMatchedSimChargedParticle = particles->At(j);
505     secondaryMatchDeltaPtOverPt = dPtOverPt;
506     }
507    
508     } //is charged particle
509     } //is simulated
510     }// for all particles
511    
512     if (printDebugLevel >= 5) {
513     if (matchedSimChargedParticle && minDR < 0.3) {
514     cout << "Match : " << matchDeltaPtOverPt << " : " << minDR
515     << " " << matchedSimChargedParticle->PdgId()
516     << " " << matchedSimChargedParticle->Status() << " " << matchedSimChargedParticle->Pt()
517     << " " << matchedSimChargedParticle->Eta() << " " << matchedSimChargedParticle->Phi()
518     << " produced at ";
519     if (matchedSimChargedParticle->Mother())
520     cout << matchedSimChargedParticle->Mother()->DecayVertex().Rho();
521     else
522     cout << "0.0";
523     cout << " decays at ";
524     if (matchedSimChargedParticle->NDaughters() > 0)
525     cout << matchedSimChargedParticle->DecayVertex().Rho();
526     else
527     cout << " Stable ";
528     cout << endl;
529     }
530     }
531    
532     if (!matchedSimChargedParticle) {
533     if (secondaryMatchedSimChargedParticle) {
534     matchedSimChargedParticle = secondaryMatchedSimChargedParticle;
535     minDR = secondaryMatchMinDR;
536     matchDeltaPtOverPt = secondaryMatchDeltaPtOverPt;
537     }
538    
539     if (printDebugLevel >= 5) {
540     if (matchedSimChargedParticle && minDR < 0.3) {
541     cout << "secondaryMatch : " << matchDeltaPtOverPt << " : " << minDR
542     << " " << matchedSimChargedParticle->PdgId()
543     << " " << matchedSimChargedParticle->Status() << " " << matchedSimChargedParticle->Pt()
544     << " " << matchedSimChargedParticle->Eta() << " " << matchedSimChargedParticle->Phi()
545     << " produced at ";
546     if (matchedSimChargedParticle->Mother())
547     cout << matchedSimChargedParticle->Mother()->DecayVertex().Rho();
548     else
549     cout << "0.0";
550     cout << " decays at ";
551     if (matchedSimChargedParticle->NDaughters() > 0)
552     cout << matchedSimChargedParticle->DecayVertex().Rho();
553     else
554     cout << " Stable ";
555     cout << endl;
556     }
557     }
558     }
559    
560     if (matchedSimChargedParticle && minDR < 0.3)
561     match = matchedSimChargedParticle;
562    
563     return match;
564     }
565    
566    
567     //***********************************************************************************************
568     //Categorizes Electron Fakes based on the input matched simulated particle
569     //***********************************************************************************************
570     Int_t GeneratorTools::CategorizeFakeMuon(const mithep::MCParticle *matchedSimChargedParticle) {
571    
572     //Categorizes Electron Fakes based on the input matched simulated particle
573     Int_t FakeCategory = 0;
574    
575     if (!matchedSimChargedParticle)
576     return FakeCategory;
577    
578     //look for a muon first
579     if (matchedSimChargedParticle->AbsPdgId() == 13) {
580     const MCParticle *mother = matchedSimChargedParticle->Mother();
581    
582     if (!mother) {
583     MDB(kAnalysis, 5) cout << "no mother\n";
584     FakeCategory = 7;
585     } else {
586     //try to find an ancestor that was a pi+,K+ or a heavy meson
587     const MCParticle *tmpParticle = matchedSimChargedParticle;
588     while (tmpParticle->Mother()
589     &&
590     tmpParticle->Mother()->AbsPdgId() != 24
591     &&
592     tmpParticle->Mother()->AbsPdgId() != 23
593     &&
594     tmpParticle->Mother()->AbsPdgId() != 211
595     &&
596     tmpParticle->Mother()->AbsPdgId() != 321
597     &&
598     tmpParticle->Mother()->AbsPdgId() != 113
599     &&
600     !((tmpParticle->Mother()->AbsPdgId() >= 400 &&
601     tmpParticle->Mother()->AbsPdgId() < 600) ||
602     (tmpParticle->Mother()->AbsPdgId() >= 4000 &&
603     tmpParticle->Mother()->AbsPdgId() < 6000)
604     )
605     ) {
606     MDB(kAnalysis, 5) {
607     cout << "find : " << tmpParticle->Mother()->PdgId() << " " << tmpParticle->Mother()->Status()
608     << " " << tmpParticle->Mother()->Pt() << " " << tmpParticle->Mother()->Eta() << " "
609     << tmpParticle->Mother()->Phi() << endl;
610     }
611     tmpParticle = tmpParticle->Mother();
612     }
613     const MCParticle *Ancestor = tmpParticle->Mother();
614    
615     if (Ancestor) {
616     MDB(kAnalysis, 5) {
617     cout << "Found ancestor: " << Ancestor->PdgId() << " "
618     << Ancestor->Status() << " " << Ancestor->Pt()
619     << " " << Ancestor->Eta() << " "
620     << Ancestor->Phi() << " HasElectronDaughter: " << Ancestor->HasDaughter(13)
621     << endl;
622     }
623    
624     if (Ancestor->AbsPdgId() == 211) {
625     FakeCategory = 1; //pi+ decay in flight
626     } else if (Ancestor->AbsPdgId() == 321) {
627     FakeCategory = 2; //K+ decay in flight
628     } else if ((Ancestor->AbsPdgId() >= 400 &&
629     Ancestor->AbsPdgId() < 600) ||
630 ceballos 1.2 ((Ancestor->AbsPdgId() >= 4000 &&
631 sixie 1.1 Ancestor->AbsPdgId() < 6000) &&
632 ceballos 1.2 Ancestor->HasDaughter(13))) {
633 sixie 1.1 FakeCategory = 4; //heavy flavor semileptonic decay
634     } else if ( Ancestor->AbsPdgId() == 24 || Ancestor->AbsPdgId() == 23 ) {
635     FakeCategory = 7; //comes from real muon. bad global fit direction
636     } else {
637     FakeCategory = 3; //muon from something else
638     }
639     } else {
640     FakeCategory = -1; //no ancestor found
641     }
642     }
643     } else if (matchedSimChargedParticle->AbsPdgId() == 211
644     || matchedSimChargedParticle->AbsPdgId() == 321
645     || matchedSimChargedParticle->AbsPdgId() == 2212 ) {
646     FakeCategory = 5; //pion punchthrough
647     } else {
648     FakeCategory = 6; //other punchthrough?
649     }
650     return FakeCategory;
651     }
652    
653    
654    
655     //--------------------------------------------------------------------------------------------------
656     TString GeneratorTools::ConvertPdgIdToName(Int_t pdgId) {
657    
658     //Convert the pdgID code into a particle name
659    
660     TString answer = "";
661    
662     switch ( pdgId )
663     {
664     case 11:
665     answer = "e-";
666     break;
667     case -11:
668     answer = "e+";
669     break;
670     case 12:
671     answer = "nu_e";
672     break;
673     case -12:
674     answer = "nu_e bar";
675     break;
676     case 13:
677     answer = "mu-";
678     break;
679     case -13:
680     answer = "mu+";
681     break;
682     case 15:
683     answer = "tau-";
684     break;
685     case -15:
686     answer = "tau+";
687     break;
688     case 21:
689     answer = "gluon";
690     break;
691     case 22:
692     answer = "photon";
693     break;
694     case 23:
695     answer = "Z";
696     break;
697     case 24:
698     answer = "W+";
699     break;
700     case -24:
701     answer = "W-";
702     break;
703     case 25:
704     answer = "Higgs";
705     break;
706     case 111:
707     answer = "Pi0";
708     break;
709     case 113:
710     answer = "Rho0(770)";
711     break;
712     case 115:
713     answer = "a_2^0(1320)";
714     break;
715     case 117:
716     answer = "rho_3^0(1690)";
717     break;
718     case 119:
719     answer = "a_4^0(2040)";
720     break;
721     case 130:
722     answer = "K_L^0";
723     break;
724    
725    
726    
727     case 211:
728     answer = "Pi+";
729     break;
730     case -211:
731     answer = "Pi-";
732     break;
733     case 213:
734     answer = "Rho+";
735     break;
736     case -213:
737     answer = "Rho-";
738     break;
739     case 221:
740     answer = "Eta";
741     break;
742     case 223:
743     answer = "omega(782)";
744     break;
745     case 310:
746     answer = "K_S^0";
747     break;
748     case 311:
749     answer = "K0";
750     break;
751     case 321:
752     answer = "K+";
753     break;
754     case -321:
755     answer = "K-";
756     break;
757     case 313:
758     answer = "K0*(892)";
759     break;
760     case 323:
761     answer = "K+*(892)";
762     break;
763     case -323:
764     answer = "K-*(892)";
765     break;
766     case 315:
767     answer = "K_2^0*(1430)";
768     break;
769     case 325:
770     answer = "K_2^+*(1430)";
771     break;
772     case -325:
773     answer = "K_2^-*(1430)";
774     break;
775     case 317:
776     answer = "K_3^0*(1780)";
777     break;
778     case 327:
779     answer = "K_3^+*(1780)";
780     break;
781     case -327:
782     answer = "K_3^-*(1780)";
783     break;
784     case 319:
785     answer = "K_4^0*(2045)";
786     break;
787     case 329:
788     answer = "K_4^+*(2045)";
789     break;
790     case -329:
791     answer = "K_4^-*(2045)";
792     break;
793     case 331:
794     answer = "Eta'(958)";
795     break;
796     case 333:
797     answer = "phi'(1020)";
798     break;
799    
800    
801     case 411:
802     answer = "D+";
803     break;
804     case -411:
805     answer = "D-";
806     break;
807     case 421:
808     answer = "D0";
809     break;
810     case -421:
811     answer = "D0 bar";
812     break;
813     case 413:
814     answer = "D^+*(2010)";
815     break;
816     case -413:
817     answer = "D^-*(2010)";
818     break;
819     case 423:
820     answer = "D^0*(2010)";
821     break;
822     case -423:
823     answer = "D^0*(2010) bar";
824     break;
825     case 415:
826     answer = "D_2^+*(2460)";
827     break;
828     case -415:
829     answer = "D_2^-*(2460)";
830     break;
831     case 425:
832     answer = "D_2^0*(2460)";
833     break;
834     case -425:
835     answer = "D_2^0*(2460) bar";
836     break;
837     case 431:
838     answer = "D_s^+";
839     break;
840     case -431:
841     answer = "D_s^-";
842     break;
843     case 433:
844     answer = "D_s^+*";
845     break;
846     case -433:
847     answer = "D_s^-*";
848     break;
849     case 435:
850     answer = "D_s2^+*";
851     break;
852     case -435:
853     answer = "D_s2^-*";
854     break;
855    
856     case 511:
857     answer = "B0";
858     break;
859     case -511:
860     answer = "B0 bar";
861     break;
862     case -521:
863     answer = "B-";
864     break;
865     case 521:
866     answer = "B+";
867     break;
868     case 513:
869     answer = "B0*";
870     break;
871     case -513:
872     answer = "B0* bar";
873     break;
874     case -523:
875     answer = "B-*";
876     break;
877     case 523:
878     answer = "B+*";
879     break;
880     case 515:
881     answer = "B_2^0*";
882     break;
883     case -515:
884     answer = "B_2^0* bar";
885     break;
886     case -525:
887     answer = "B_2^-*";
888     break;
889     case 525:
890     answer = "B_2^+*";
891     break;
892     case 531:
893     answer = "B_s^0";
894     break;
895     case -531:
896     answer = "B_s^0 bar";
897     break;
898     case 533:
899     answer = "B_s^0*";
900     break;
901     case -533:
902     answer = "B_s^0* bar";
903     break;
904     case 535:
905     answer = "B_s2^0*";
906     break;
907     case -535:
908     answer = "B_s2^0* bar";
909     break;
910     case 541:
911     answer = "B_c^+";
912     break;
913     case -541:
914     answer = "B_c^-";
915     break;
916     case 543:
917     answer = "B_c^+*";
918     break;
919     case -543:
920     answer = "B_c^-*";
921     break;
922     case 545:
923     answer = "B_c2^+*";
924     break;
925     case -545:
926     answer = "B_c2^-*";
927     break;
928    
929     case 441:
930     answer = "eta_c(1S)";
931     break;
932     case 443:
933     answer = "JPsi(1S)";
934     break;
935     case 445:
936     answer = "chi_c2(1P)";
937     break;
938     case 551:
939     answer = "eta_b(1S)";
940     break;
941     case 553:
942     answer = "Upsilon(1S)";
943     break;
944     case 555:
945     answer = "chi_b2(1P)";
946     break;
947     case 557:
948     answer = "Upsilon(1D)";
949     break;
950    
951     case 2212:
952     answer = "proton";
953     break;
954     case 2112:
955     answer = "neutron";
956     break;
957     case 2224:
958     answer = "Delta++";
959     break;
960     case 2214:
961     answer = "Delta+";
962     break;
963     case 2114:
964     answer = "Delta0";
965     break;
966     case 1114:
967     answer = "Delta-";
968     break;
969     case 3122:
970     answer = "Lambda";
971     break;
972     case 3222:
973     answer = "Sigma+";
974     break;
975     case 3212:
976     answer = "Sigma0";
977     break;
978     case 3112:
979     answer = "Sigma-";
980     break;
981     case 3224:
982     answer = "Sigma+*";
983     break;
984     case 3214:
985     answer = "Sigma0*";
986     break;
987     case 3114:
988     answer = "Sigma-*";
989     break;
990     case 3322:
991     answer = "Xi0";
992     break;
993     case 3312:
994     answer = "Xi-";
995     break;
996     case 3324:
997     answer = "Xi0*";
998     break;
999     case 3314:
1000     answer = "Xi-*";
1001     break;
1002     case 3334:
1003     answer = "Omega-";
1004     break;
1005    
1006     default:
1007     answer = "";
1008     }
1009     return answer;
1010     }