ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/PhotonTreeWriter.cc
Revision: 1.6
Committed: Tue Dec 13 21:13:23 2011 UTC (13 years, 5 months ago) by bendavid
Content type: text/plain
Branch: MAIN
Changes since 1.5: +12 -6 lines
Log Message:
gamma gamma Electron veto inversion, systematics mod, and macro

File Contents

# Content
1 #include "MitPhysics/Mods/interface/PhotonTreeWriter.h"
2 #include "MitAna/DataTree/interface/PhotonCol.h"
3 #include "MitAna/DataTree/interface/PFCandidateCol.h"
4 #include "MitAna/DataTree/interface/StableData.h"
5 #include "MitAna/DataTree/interface/StableParticle.h"
6 #include "MitAna/DataTree/interface/PFMet.h"
7 #include "MitPhysics/Init/interface/ModNames.h"
8 #include "MitPhysics/Utils/interface/IsolationTools.h"
9 #include "MitPhysics/Utils/interface/PhotonTools.h"
10 #include "MitPhysics/Utils/interface/VertexTools.h"
11 #include "TDataMember.h"
12 #include <TNtuple.h>
13 #include <TRandom3.h>
14 #include <TSystem.h>
15
16 using namespace mithep;
17
18 ClassImp(mithep::PhotonTreeWriter)
19 ClassImp(mithep::PhotonTreeWriterPhoton)
20 ClassImp(mithep::PhotonTreeWriterDiphotonEvent)
21
22
23 //--------------------------------------------------------------------------------------------------
24 PhotonTreeWriter::PhotonTreeWriter(const char *name, const char *title) :
25 // Base Module...
26 BaseMod (name,title),
27
28 // define all the Branches to load
29 fPhotonBranchName (Names::gkPhotonBrn),
30 fElectronName (Names::gkElectronBrn),
31 fGoodElectronName (Names::gkElectronBrn),
32 fConversionName (Names::gkMvfConversionBrn),
33 fTrackBranchName (Names::gkTrackBrn),
34 fPileUpDenName (Names::gkPileupEnergyDensityBrn),
35 fPVName (Names::gkPVBeamSpotBrn),
36 fBeamspotName (Names::gkBeamSpotBrn),
37 fPFCandName (Names::gkPFCandidatesBrn),
38 fMCParticleName (Names::gkMCPartBrn),
39 fPileUpName (Names::gkPileupInfoBrn),
40 fSuperClusterName ("PFSuperClusters"),
41 fPFMetName ("PFMet"),
42 fPFJetName (Names::gkPFJetBrn),
43
44
45 fIsData (false),
46 fPhotonsFromBranch (true),
47 fPVFromBranch (true),
48 fGoodElectronsFromBranch (kTRUE),
49 fPFJetsFromBranch (kTRUE),
50
51 // ----------------------------------------
52 // collections....
53 fPhotons (0),
54 fElectrons (0),
55 fConversions (0),
56 fTracks (0),
57 fPileUpDen (0),
58 fPV (0),
59 fBeamspot (0),
60 fPFCands (0),
61 fMCParticles (0),
62 fPileUp (0),
63 fSuperClusters (0),
64 fPFJets (0),
65
66 fLoopOnGoodElectrons(kFALSE),
67 fApplyElectronVeto(kTRUE),
68
69 fWriteDiphotonTree(kTRUE),
70 fWriteSingleTree(kTRUE),
71 fExcludeSinglePrompt(kFALSE),
72 fExcludeDoublePrompt(kFALSE),
73 fEnableJets(kFALSE),
74 fPhFixDataFile(gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/PhotonFixSTART42V13.dat")),
75 fTupleName ("hPhotonTree")
76
77
78 {
79 // Constructor.
80 }
81
82 PhotonTreeWriter::~PhotonTreeWriter(){
83 ;
84 }
85
86 //--------------------------------------------------------------------------------------------------
87 void PhotonTreeWriter::Process()
88 {
89 // ------------------------------------------------------------
90 // Process entries of the tree.
91
92 LoadEventObject(fPhotonBranchName, fPhotons);
93 LoadEventObject(fGoodElectronName, fGoodElectrons);
94
95 const BaseCollection *egcol = 0;
96 if (fLoopOnGoodElectrons) {
97 egcol = fGoodElectrons;
98 }
99 else {
100 egcol = fPhotons;
101 }
102
103 if (egcol->GetEntries()<1) return;
104
105 LoadEventObject(fElectronName, fElectrons);
106 LoadEventObject(fConversionName, fConversions);
107 LoadEventObject(fTrackBranchName, fTracks);
108 LoadEventObject(fPileUpDenName, fPileUpDen);
109 LoadEventObject(fPVName, fPV);
110 LoadEventObject(fBeamspotName, fBeamspot);
111 LoadEventObject(fPFCandName, fPFCands);
112 LoadEventObject(fSuperClusterName, fSuperClusters);
113 LoadEventObject(fPFMetName, fPFMet);
114 if (fEnableJets) LoadEventObject(fPFJetName, fPFJets);
115
116 // ------------------------------------------------------------
117 // load event based information
118 Int_t _numPU = -1.; // some sensible default values....
119 Int_t _numPUminus = -1.; // some sensible default values....
120 Int_t _numPUplus = -1.; // some sensible default values....
121
122 Float_t _tRho = -99.;
123 if( fPileUpDen->GetEntries() > 0 )
124 _tRho = (Double_t) fPileUpDen->At(0)->RhoRandomLowEta();
125
126 const BaseVertex *bsp = dynamic_cast<const BaseVertex*>(fBeamspot->At(0));
127
128 if( !fIsData ) {
129 LoadBranch(fMCParticleName);
130 LoadBranch(fPileUpName);
131 }
132
133 if( !fIsData ) {
134 for (UInt_t i=0; i<fPileUp->GetEntries(); ++i) {
135 const PileupInfo *puinfo = fPileUp->At(i);
136 if (puinfo->GetBunchCrossing()==0) _numPU = puinfo->GetPU_NumInteractions();
137 else if (puinfo->GetBunchCrossing() == -1) _numPUminus = puinfo->GetPU_NumInteractions();
138 else if (puinfo->GetBunchCrossing() == 1) _numPUplus = puinfo->GetPU_NumInteractions();
139 }
140 }
141
142 // in case of a MC event, try to find Higgs and Higgs decay Z poisition
143 Float_t _pth = -100.;
144 Float_t _decayZ = -100.;
145 Float_t _genmass = -100.;
146 if( !fIsData ) FindHiggsPtAndZ(_pth, _decayZ, _genmass);
147
148 fDiphotonEvent->rho = _tRho;
149 fDiphotonEvent->genHiggspt = _pth;
150 fDiphotonEvent->genHiggsZ = _decayZ;
151 fDiphotonEvent->genmass = _genmass;
152 fDiphotonEvent->gencostheta = -99.;
153 fDiphotonEvent->nVtx = fPV->GetEntries();
154 fDiphotonEvent->bsX = fBeamspot->At(0)->X();
155 fDiphotonEvent->bsY = fBeamspot->At(0)->Y();
156 fDiphotonEvent->bsZ = fBeamspot->At(0)->Z();
157 fDiphotonEvent->vtxX = (fDiphotonEvent->nVtx>0) ? fPV->At(0)->X() : -99.;
158 fDiphotonEvent->vtxY = (fDiphotonEvent->nVtx>0) ? fPV->At(0)->Y() : -99.;
159 fDiphotonEvent->vtxZ = (fDiphotonEvent->nVtx>0) ? fPV->At(0)->Z() : -99.;
160 fDiphotonEvent->numPU = _numPU;
161 fDiphotonEvent->numPUminus = _numPUminus;
162 fDiphotonEvent->numPUplus = _numPUplus;
163 fDiphotonEvent->mass = -99.;
164 fDiphotonEvent->ptgg = -99.;
165 fDiphotonEvent->costheta = -99.;
166 fDiphotonEvent->mt = -99.;
167 fDiphotonEvent->cosphimet = -99.;
168 fDiphotonEvent->mtele = -99.;
169 fDiphotonEvent->cosphimetele = -99.;
170 fDiphotonEvent->evt = GetEventHeader()->EvtNum();
171 fDiphotonEvent->run = GetEventHeader()->RunNum();
172 fDiphotonEvent->lumi = GetEventHeader()->LumiSec();
173 fDiphotonEvent->evtcat = -99;
174 fDiphotonEvent->nobj = fPhotons->GetEntries();
175 fDiphotonEvent->pfmet = fPFMet->At(0)->Pt();
176 fDiphotonEvent->pfmetphi = fPFMet->At(0)->Phi();
177 fDiphotonEvent->pfmetx = fPFMet->At(0)->Px();
178 fDiphotonEvent->pfmety = fPFMet->At(0)->Py();
179 fDiphotonEvent->masscor = -99.;
180 fDiphotonEvent->masscorerr = -99.;
181 fDiphotonEvent->masscorele = -99.;
182 fDiphotonEvent->masscoreleerr = -99.;
183 fDiphotonEvent->ismc = GetEventHeader()->IsMC();
184
185 //jets
186 const Jet *jet1 = 0;
187 const Jet *jet2 = 0;
188 const Jet *jetcentral = 0;
189
190 fDiphotonEvent->jet1pt = -99.;
191 fDiphotonEvent->jet1eta = -99.;
192 fDiphotonEvent->jet1phi = -99.;
193 fDiphotonEvent->jet1mass = -99.;
194 fDiphotonEvent->jet2pt = -99.;
195 fDiphotonEvent->jet2eta = -99.;
196 fDiphotonEvent->jet2phi = -99.;
197 fDiphotonEvent->jet2mass = -99.;
198 fDiphotonEvent->jetcentralpt = -99.;
199 fDiphotonEvent->jetcentraleta = -99.;
200 fDiphotonEvent->jetcentralphi = -99.;
201 fDiphotonEvent->jetcentralmass = -99.;
202 fDiphotonEvent->dijetpt = -99.;
203 fDiphotonEvent->dijeteta = -99.;
204 fDiphotonEvent->dijetphi = -99.;
205 fDiphotonEvent->dijetmass = -99.;
206 fDiphotonEvent->jetetaplus = -99.;
207 fDiphotonEvent->jetetaminus = -99.;
208 fDiphotonEvent->zeppenfeld = -99.;
209 fDiphotonEvent->dphidijetgg = -99.;
210
211 Int_t nhitsbeforevtxmax = 1;
212 if (!fApplyElectronVeto) nhitsbeforevtxmax = 999;
213
214 if (egcol->GetEntries()>=2) {
215
216 const Particle *p1 = 0;
217 const Particle *p2 = 0;
218 const Photon *phHard = 0;
219 const Photon *phSoft = 0;
220 const Electron *ele1 = 0;
221 const Electron *ele2 = 0;
222 const SuperCluster *sc1 = 0;
223 const SuperCluster *sc2 = 0;
224
225 if (fLoopOnGoodElectrons) {
226 ele1 = fGoodElectrons->At(0);
227 ele2 = fGoodElectrons->At(1);
228 p1 = ele1;
229 p2 = ele2;
230 sc1 = ele1->SCluster();
231 sc2 = ele2->SCluster();
232 phHard = PhotonTools::MatchedPhoton(ele1,fPhotons);
233 phSoft = PhotonTools::MatchedPhoton(ele2,fPhotons);
234 }
235 else {
236 phHard = fPhotons->At(0);
237 phSoft = fPhotons->At(1);
238 p1 = phHard;
239 p2 = phSoft;
240 sc1 = phHard->SCluster();
241 sc2 = phSoft->SCluster();
242 ele1 = PhotonTools::MatchedElectron(phHard,fGoodElectrons);
243 ele2 = PhotonTools::MatchedElectron(phSoft,fGoodElectrons);
244 }
245
246 const DecayParticle *conv1 = PhotonTools::MatchedConversion(sc1,fConversions,bsp,nhitsbeforevtxmax);
247 const DecayParticle *conv2 = PhotonTools::MatchedConversion(sc2,fConversions,bsp,nhitsbeforevtxmax);
248
249 const SuperCluster *pfsc1 = PhotonTools::MatchedSC(sc1,fSuperClusters);
250 const SuperCluster *pfsc2 = PhotonTools::MatchedSC(sc2,fSuperClusters);
251
252 const MCParticle *phgen1 = 0;
253 const MCParticle *phgen2 = 0;
254 if( !fIsData ) {
255 phgen1 = PhotonTools::MatchMC(p1,fMCParticles,!fApplyElectronVeto);
256 phgen2 = PhotonTools::MatchMC(p2,fMCParticles,!fApplyElectronVeto);
257 }
258
259 /* if (phgen1 && phgen2) {
260 printf("p1 pt = %5f, eta = %5f, phi = %5f\n",p1->Pt(),p1->Eta(),p1->Phi());
261 printf("p2 pt = %5f, eta = %5f, phi = %5f\n",p2->Pt(),p2->Eta(),p2->Phi());
262 printf("phgen1 pt = %5f, eta = %5f, phi = %5f, pdg = %i, motherpdg = %i, distinctmotherpdg = %i, distinctmotherstatus = %i\n",phgen1->Pt(),phgen1->Eta(),phgen1->Phi(),phgen1->PdgId(),phgen1->Mother()->PdgId(),phgen1->DistinctMother()->PdgId(),phgen1->DistinctMother()->Status());
263 printf("phgen2 pt = %5f, eta = %5f, phi = %5f, pdg = %i, motherpdg = %i, distinctmotherpdg = %i, distinctmotherstatus = %i\n",phgen2->Pt(),phgen2->Eta(),phgen2->Phi(),phgen2->PdgId(),phgen2->Mother()->PdgId(),phgen2->DistinctMother()->PdgId(),phgen2->DistinctMother()->Status());
264 } */
265
266
267 if (fExcludeSinglePrompt && (phgen1 || phgen2) ) return;
268 if (fExcludeDoublePrompt && (phgen1 && phgen2) ) return;
269
270 if (!fLoopOnGoodElectrons && phHard->HasPV()) {
271 fDiphotonEvent->vtxX = phHard->PV()->X();
272 fDiphotonEvent->vtxY = phHard->PV()->Y();
273 fDiphotonEvent->vtxZ = phHard->PV()->Z();
274 fDiphotonEvent->vtxprob = phHard->VtxProb();
275 }
276
277 //fill jet variables
278 if (fEnableJets) {
279 for (UInt_t ijet=0; ijet<fPFJets->GetEntries();++ijet) {
280 const Jet *jet = fPFJets->At(ijet);
281 if (jet->AbsEta()<4.7 && MathUtils::DeltaR(jet,p1)>0.3 && MathUtils::DeltaR(jet,p2)>0.3) {
282 if (!jet1) jet1 = jet;
283 else if (!jet2) jet2 = jet;
284 else if (!jetcentral && 0) jetcentral = jet;
285 }
286 if (jet1&&jet2&&jetcentral) break;
287 }
288 }
289
290 if (jet1) {
291 fDiphotonEvent->jet1pt = jet1->Pt();
292 fDiphotonEvent->jet1eta = jet1->Eta();
293 fDiphotonEvent->jet1phi = jet1->Phi();
294 fDiphotonEvent->jet1mass = jet1->Mass();
295 }
296
297 if (jet2) {
298 fDiphotonEvent->jet2pt = jet2->Pt();
299 fDiphotonEvent->jet2eta = jet2->Eta();
300 fDiphotonEvent->jet2phi = jet2->Phi();
301 fDiphotonEvent->jet2mass = jet2->Mass();
302 }
303
304 if (jetcentral) {
305 fDiphotonEvent->jetcentralpt = jetcentral->Pt();
306 fDiphotonEvent->jetcentraleta = jetcentral->Eta();
307 fDiphotonEvent->jetcentralphi = jetcentral->Phi();
308 fDiphotonEvent->jetcentralmass = jetcentral->Mass();
309 }
310
311 if (jet1&&jet2){
312 FourVectorM momjj = (jet1->Mom() + jet2->Mom());
313
314 fDiphotonEvent->dijetpt = momjj.Pt();
315 fDiphotonEvent->dijeteta = momjj.Eta();
316 fDiphotonEvent->dijetphi = momjj.Phi();
317 fDiphotonEvent->dijetmass = momjj.M();
318
319 if (jet1->Eta()>jet2->Eta()) {
320 fDiphotonEvent->jetetaplus = jet1->Eta();
321 fDiphotonEvent->jetetaminus = jet2->Eta();
322 }
323 else {
324 fDiphotonEvent->jetetaplus = jet2->Eta();
325 fDiphotonEvent->jetetaminus = jet1->Eta();
326 }
327
328 }
329
330
331
332 Double_t _mass = -99.;
333 Double_t _masserr = -99.;
334 Double_t _masserrsmeared = -99.;
335 Double_t _masserrwrongvtx = -99.;
336 Double_t _masserrsmearedwrongvtx = -99.;
337 Double_t _ptgg = -99.;
338 Double_t _etagg = -99.;
339 Double_t _phigg = -99.;
340 Double_t _costheta = -99.;
341 PhotonTools::DiphotonR9EtaPtCats _evtcat = PhotonTools::kOctCat0;
342 if (phHard && phSoft) {
343 _mass = (phHard->Mom()+phSoft->Mom()).M();
344 _masserr = 0.5*_mass*TMath::Sqrt(phHard->EnergyErr()*phHard->EnergyErr()/phHard->E()/phHard->E() + phSoft->EnergyErr()*phSoft->EnergyErr()/phSoft->E()/phSoft->E());
345 _masserrsmeared = 0.5*_mass*TMath::Sqrt(phHard->EnergyErrSmeared()*phHard->EnergyErrSmeared()/phHard->E()/phHard->E() + phSoft->EnergyErrSmeared()*phSoft->EnergyErrSmeared()/phSoft->E()/phSoft->E());
346 _ptgg = (phHard->Mom()+phSoft->Mom()).Pt();
347 _etagg = (phHard->Mom()+phSoft->Mom()).Eta();
348 _phigg = (phHard->Mom()+phSoft->Mom()).Phi();
349 _costheta = ThreeVector(phHard->Mom()).Unit().Dot(ThreeVector(phSoft->Mom()).Unit());
350 _evtcat = PhotonTools::DiphotonR9EtaPtCat(phHard,phSoft);
351
352 const Double_t dz = sqrt(2.0)*5.8;
353 Double_t deltamvtx = _mass*VertexTools::DeltaMassVtx(phHard->CaloPos().X(), phHard->CaloPos().Y(), phHard->CaloPos().Z(),
354 phSoft->CaloPos().X(), phSoft->CaloPos().Y(), phSoft->CaloPos().Z(),
355 dz);
356
357 fDiphotonEvent->deltamvtx = deltamvtx;
358
359 _masserrwrongvtx = TMath::Sqrt(_masserr*_masserr + deltamvtx*deltamvtx);
360 _masserrsmearedwrongvtx = TMath::Sqrt(_masserrsmeared*_masserrsmeared + deltamvtx*deltamvtx);
361
362 if (jet1 && jet2) {
363 fDiphotonEvent->zeppenfeld = TMath::Abs(_etagg - 0.5*(jet1->Eta()+jet2->Eta()));
364 fDiphotonEvent->dphidijetgg = MathUtils::DeltaPhi( (jet1->Mom()+jet2->Mom()).Phi(), _phigg );
365 }
366
367 }
368
369
370 Float_t _massele = -99.;
371 Float_t _ptee = -99.;
372 Float_t _costhetaele = -99.;
373 if (ele1 && ele2) {
374 _massele = (ele1->Mom()+ele2->Mom()).M();
375 _ptee = (ele1->Mom()+ele2->Mom()).Pt();
376 _costhetaele = ThreeVector(ele1->Mom()).Unit().Dot(ThreeVector(ele2->Mom()).Unit());
377 }
378
379 Float_t _gencostheta = -99.;
380 if (phgen1 && phgen2) {
381 _gencostheta = ThreeVector(phgen1->Mom()).Unit().Dot(ThreeVector(phgen2->Mom()).Unit());
382 }
383
384 fDiphotonEvent->gencostheta = _gencostheta;
385 fDiphotonEvent->mass = _mass;
386 fDiphotonEvent->masserr = _masserr;
387 fDiphotonEvent->masserrsmeared = _masserrsmeared;
388 fDiphotonEvent->masserrwrongvtx = _masserrwrongvtx;
389 fDiphotonEvent->masserrsmearedwrongvtx = _masserrsmearedwrongvtx;
390 fDiphotonEvent->ptgg = _ptgg;
391 fDiphotonEvent->etagg = _etagg;
392 fDiphotonEvent->phigg = _phigg;
393 fDiphotonEvent->costheta = _costheta;;
394 fDiphotonEvent->massele = _massele;
395 fDiphotonEvent->ptee = _ptee;
396 fDiphotonEvent->costhetaele = _costhetaele;
397 fDiphotonEvent->evtcat = _evtcat;
398
399 fDiphotonEvent->photons[0].SetVars(phHard,conv1,ele1,pfsc1,phgen1,fPhfixph,fPhfixele);
400 fDiphotonEvent->photons[1].SetVars(phSoft,conv2,ele2,pfsc2,phgen2,fPhfixph,fPhfixele);
401
402 Float_t ph1ecor = fDiphotonEvent->photons[0].Ecor();
403 Float_t ph1ecorerr = fDiphotonEvent->photons[0].Ecorerr();
404 Float_t ph2ecor = fDiphotonEvent->photons[1].Ecor();
405 Float_t ph2ecorerr = fDiphotonEvent->photons[1].Ecorerr();
406
407 Float_t ph1ecorele = fDiphotonEvent->photons[0].Ecorele();
408 Float_t ph1ecoreleerr = fDiphotonEvent->photons[0].Ecoreleerr();
409 Float_t ph2ecorele = fDiphotonEvent->photons[1].Ecorele();
410 Float_t ph2ecoreleerr = fDiphotonEvent->photons[1].Ecoreleerr();
411
412
413 fDiphotonEvent->masscor = TMath::Sqrt(2.0*ph1ecor*ph2ecor*(1.0-fDiphotonEvent->costheta));
414 fDiphotonEvent->masscorerr = 0.5*fDiphotonEvent->masscor*TMath::Sqrt(ph1ecorerr*ph1ecorerr/ph1ecor/ph1ecor + ph2ecorerr*ph2ecorerr/ph2ecor/ph2ecor);
415
416 fDiphotonEvent->masscorele = TMath::Sqrt(2.0*ph1ecorele*ph2ecorele*(1.0-fDiphotonEvent->costheta));
417 fDiphotonEvent->masscoreleerr = 0.5*fDiphotonEvent->masscorele*TMath::Sqrt(ph1ecoreleerr*ph1ecoreleerr/ph1ecorele/ph1ecorele + ph2ecoreleerr*ph2ecoreleerr/ph2ecorele/ph2ecorele);
418
419 //printf("r9 = %5f, photon sigieie = %5f, seed sigieie = %5f\n",phHard->R9(),phHard->CoviEtaiEta(),sqrt(phHard->SCluster()->Seed()->CoviEtaiEta()));
420
421 if (fWriteDiphotonTree) hCiCTuple->Fill();
422
423 }
424
425 if (!fWriteSingleTree) return;
426
427
428 for (UInt_t iph = 0; iph<egcol->GetEntries(); ++iph) {
429
430 const Particle *p = 0;
431 const Photon *ph = 0;
432 const Electron *ele = 0;
433 const SuperCluster *sc = 0;
434 if (fLoopOnGoodElectrons) {
435 ele = fGoodElectrons->At(iph);
436 p = ele;
437 sc = ele->SCluster();
438 ph = PhotonTools::MatchedPhoton(ele,fPhotons);
439 }
440 else {
441 ph = fPhotons->At(iph);
442 p = ph;
443 sc = ph->SCluster();
444 ele = PhotonTools::MatchedElectron(ph,fGoodElectrons);
445 }
446
447 const DecayParticle *conv = PhotonTools::MatchedConversion(sc,fConversions,bsp,nhitsbeforevtxmax);
448 const SuperCluster *pfsc = PhotonTools::MatchedSC(sc,fSuperClusters);
449
450
451
452 if (!fLoopOnGoodElectrons && ph->HasPV()) {
453 fDiphotonEvent->vtxZ = ph->PV()->Z();
454 }
455
456 const MCParticle *phgen = 0;
457 if( !fIsData ) {
458 phgen = PhotonTools::MatchMC(p,fMCParticles,!fApplyElectronVeto);
459 }
460
461 if (fExcludeSinglePrompt && phgen) return;
462
463 fDiphotonEvent->mt = -99.;
464 fDiphotonEvent->cosphimet = -99.;
465 fDiphotonEvent->mtele = -99.;
466 fDiphotonEvent->cosphimetele = -99.;
467
468 if (ph) {
469 fDiphotonEvent->cosphimet = TMath::Cos(ph->Phi()-fPFMet->At(0)->Phi());
470 fDiphotonEvent->mt = TMath::Sqrt(2.0*fPFMet->At(0)->Pt()*ph->Pt()*(1.0-fDiphotonEvent->cosphimet));
471 }
472
473 if (ele) {
474 fDiphotonEvent->cosphimetele = TMath::Cos(ele->Phi()-fPFMet->At(0)->Phi());
475 fDiphotonEvent->mtele = TMath::Sqrt(2.0*fPFMet->At(0)->Pt()*ele->Pt()*(1.0-fDiphotonEvent->cosphimetele));
476 }
477
478 fSinglePhoton->SetVars(ph,conv,ele,pfsc,phgen,fPhfixph,fPhfixele);
479 hCiCTupleSingle->Fill();
480
481 }
482
483
484 return;
485
486 }
487
488 //--------------------------------------------------------------------------------------------------
489 void PhotonTreeWriter::SlaveBegin()
490 {
491 // Run startup code on the computer (slave) doing the actual analysis. Here,
492 // we just request the photon collection branch.
493
494 ReqEventObject(fPhotonBranchName, fPhotons, fPhotonsFromBranch);
495 ReqEventObject(fTrackBranchName, fTracks, true);
496 ReqEventObject(fElectronName, fElectrons, true);
497 ReqEventObject(fGoodElectronName, fGoodElectrons, fGoodElectronsFromBranch);
498 ReqEventObject(fPileUpDenName, fPileUpDen, true);
499 ReqEventObject(fPVName, fPV, fPVFromBranch);
500 ReqEventObject(fConversionName, fConversions,true);
501 ReqEventObject(fBeamspotName, fBeamspot, true);
502 ReqEventObject(fPFCandName, fPFCands, true);
503 ReqEventObject(fSuperClusterName, fSuperClusters, true);
504 ReqEventObject(fPFMetName, fPFMet, true);
505 if (fEnableJets) ReqEventObject(fPFJetName, fPFJets, fPFJetsFromBranch);
506
507 if (!fIsData) {
508 ReqBranch(fPileUpName, fPileUp);
509 ReqBranch(fMCParticleName, fMCParticles);
510 }
511
512
513 if (fIsData) {
514 fPhFixDataFile = gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/PhotonFixGRPV22.dat");
515 }
516 else {
517 fPhFixDataFile = gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/PhotonFixSTART42V13.dat");
518 }
519
520 //initialize photon energy corrections
521 //PhotonFix::initialise("4_2",std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/PhotonFix.dat")).Data()));
522
523 fPhfixph.initialise("4_2",std::string(fPhFixDataFile));
524 fPhfixele.initialise("4_2e",std::string(fPhFixDataFile));
525
526 fDiphotonEvent = new PhotonTreeWriterDiphotonEvent;
527 fSinglePhoton = new PhotonTreeWriterPhoton;
528
529
530 if (fWriteDiphotonTree) hCiCTuple = new TTree(fTupleName.Data(),fTupleName.Data());
531 TString singlename = fTupleName + TString("Single");
532 if (fWriteSingleTree) hCiCTupleSingle = new TTree(singlename,singlename);
533
534 //make flattish tree from classes so we don't have to rely on dictionaries for reading later
535 TClass *eclass = TClass::GetClass("mithep::PhotonTreeWriterDiphotonEvent");
536 TClass *pclass = TClass::GetClass("mithep::PhotonTreeWriterPhoton");
537 TList *elist = eclass->GetListOfDataMembers();
538 TList *plist = pclass->GetListOfDataMembers();
539
540 for (int i=0; i<elist->GetEntries(); ++i) {
541 const TDataMember *tdm = static_cast<const TDataMember*>(elist->At(i));
542 if (!(tdm->IsBasic() && tdm->IsPersistent())) continue;
543 TString typestring;
544 if (TString(tdm->GetTypeName())=="Char_t") typestring = "B";
545 else if (TString(tdm->GetTypeName())=="UChar_t") typestring = "b";
546 else if (TString(tdm->GetTypeName())=="Short_t") typestring = "S";
547 else if (TString(tdm->GetTypeName())=="UShort_t") typestring = "s";
548 else if (TString(tdm->GetTypeName())=="Int_t") typestring = "I";
549 else if (TString(tdm->GetTypeName())=="UInt_t") typestring = "i";
550 else if (TString(tdm->GetTypeName())=="Float_t") typestring = "F";
551 else if (TString(tdm->GetTypeName())=="Double_t") typestring = "D";
552 else if (TString(tdm->GetTypeName())=="Long64_t") typestring = "L";
553 else if (TString(tdm->GetTypeName())=="ULong64_t") typestring = "l";
554 else if (TString(tdm->GetTypeName())=="Bool_t") typestring = "O";
555 else continue;
556 //printf("%s %s: %i\n",tdm->GetTypeName(),tdm->GetName(),int(tdm->GetOffset()));
557 Char_t *addr = (Char_t*)fDiphotonEvent;
558 assert(sizeof(Char_t)==1);
559 if (fWriteDiphotonTree) hCiCTuple->Branch(tdm->GetName(),addr + tdm->GetOffset(),TString::Format("%s/%s",tdm->GetName(),typestring.Data()));
560 if (fWriteSingleTree) hCiCTupleSingle->Branch(tdm->GetName(),addr + tdm->GetOffset(),TString::Format("%s/%s",tdm->GetName(),typestring.Data()));
561 }
562
563 for (int iph=0; iph<2; ++iph) {
564 for (int i=0; i<plist->GetEntries(); ++i) {
565 const TDataMember *tdm = static_cast<const TDataMember*>(plist->At(i));
566 if (!(tdm->IsBasic() && tdm->IsPersistent())) continue;
567 TString typestring;
568 if (TString(tdm->GetTypeName())=="Char_t") typestring = "B";
569 else if (TString(tdm->GetTypeName())=="UChar_t") typestring = "b";
570 else if (TString(tdm->GetTypeName())=="Short_t") typestring = "S";
571 else if (TString(tdm->GetTypeName())=="UShort_t") typestring = "s";
572 else if (TString(tdm->GetTypeName())=="Int_t") typestring = "I";
573 else if (TString(tdm->GetTypeName())=="UInt_t") typestring = "i";
574 else if (TString(tdm->GetTypeName())=="Float_t") typestring = "F";
575 else if (TString(tdm->GetTypeName())=="Double_t") typestring = "D";
576 else if (TString(tdm->GetTypeName())=="Long64_t") typestring = "L";
577 else if (TString(tdm->GetTypeName())=="ULong64_t") typestring = "l";
578 else if (TString(tdm->GetTypeName())=="Bool_t") typestring = "O";
579 else continue;
580 //printf("%s\n",tdm->GetTypeName());
581 TString varname = TString::Format("ph%d.%s",iph+1,tdm->GetName());
582
583 Char_t *addr = (Char_t*)&fDiphotonEvent->photons[iph];
584 assert(sizeof(Char_t)==1);
585 if (fWriteDiphotonTree) hCiCTuple->Branch(varname,addr+tdm->GetOffset(),TString::Format("%s/%s",varname.Data(),typestring.Data()));
586
587 if (iph==0) {
588 TString singlename = TString::Format("ph.%s",tdm->GetName());
589 Char_t *addrsingle = (Char_t*)fSinglePhoton;
590 if (fWriteSingleTree) hCiCTupleSingle->Branch(singlename,addrsingle+tdm->GetOffset(),TString::Format("%s/%s",singlename.Data(),typestring.Data()));
591 }
592 }
593 }
594
595
596 if (fWriteDiphotonTree) AddOutput(hCiCTuple);
597 if (fWriteSingleTree) AddOutput(hCiCTupleSingle);
598
599
600 }
601
602 // ----------------------------------------------------------------------------------------
603 // some helpfer functions....
604 void PhotonTreeWriter::FindHiggsPtAndZ(Float_t& pt, Float_t& decayZ, Float_t& mass) {
605
606 pt = -999.;
607 decayZ = -999.;
608 mass = -999.;
609
610 // loop over all GEN particles and look for status 1 photons
611 for(UInt_t i=0; i<fMCParticles->GetEntries(); ++i) {
612 const MCParticle* p = fMCParticles->At(i);
613 if( p->Is(MCParticle::kH) || (!fApplyElectronVeto && (p->AbsPdgId()==23||p->AbsPdgId()==24) ) ) {
614 pt=p->Pt();
615 decayZ = p->DecayVertex().Z();
616 mass = p->Mass();
617 break;
618 }
619 }
620
621 return;
622 }
623
624
625 Float_t PhotonTreeWriter::GetEventCat(PhotonTools::CiCBaseLineCats cat1, PhotonTools::CiCBaseLineCats cat2) {
626
627 bool ph1IsEB = (cat1 == PhotonTools::kCiCCat1 || cat1 == PhotonTools::kCiCCat2);
628 bool ph2IsEB = (cat2 == PhotonTools::kCiCCat1 || cat2 == PhotonTools::kCiCCat2);
629
630 bool ph1IsHR9 = (cat1 == PhotonTools::kCiCCat1 || cat1 == PhotonTools::kCiCCat3);
631 bool ph2IsHR9 = (cat2 == PhotonTools::kCiCCat1 || cat2 == PhotonTools::kCiCCat3);
632
633 if( ph1IsEB && ph2IsEB )
634 return ( ph1IsHR9 && ph2IsHR9 ? 0. : 1.);
635
636 return ( ph1IsHR9 && ph2IsHR9 ? 2. : 3.);
637 }
638
639 void PhotonTreeWriterPhoton::SetVars(const Photon *p, const DecayParticle *c, const Electron *ele, const SuperCluster *pfsc, const MCParticle *m, PhotonFix &phfixph, PhotonFix &phfixele) {
640
641 const SuperCluster *s = 0;
642 if (p) {
643 s = p->SCluster();
644 }
645 else {
646 s = ele->SCluster();
647 }
648 const BasicCluster *b = s->Seed();
649 const BasicCluster *b2 = 0;
650 Double_t ebcmax = -99.;
651 for (UInt_t i=0; i<s->ClusterSize(); ++i) {
652 const BasicCluster *bc = s->Cluster(i);
653 if (bc->Energy() > ebcmax && bc !=b) {
654 b2 = bc;
655 ebcmax = bc->Energy();
656 }
657 }
658
659 const BasicCluster *bclast = 0;
660 Double_t ebcmin = 1e6;
661 for (UInt_t i=0; i<s->ClusterSize(); ++i) {
662 const BasicCluster *bc = s->Cluster(i);
663 if (bc->Energy() < ebcmin && bc !=b) {
664 bclast = bc;
665 ebcmin = bc->Energy();
666 }
667 }
668
669 const BasicCluster *bclast2 = 0;
670 ebcmin = 1e6;
671 for (UInt_t i=0; i<s->ClusterSize(); ++i) {
672 const BasicCluster *bc = s->Cluster(i);
673 if (bc->Energy() < ebcmin && bc !=b && bc!=bclast) {
674 bclast2 = bc;
675 ebcmin = bc->Energy();
676 }
677 }
678
679
680 if (p) {
681 hasphoton = kTRUE;
682 e = p->E();
683 pt = p->Pt();
684 eta = p->Eta();
685 phi = p->Phi();
686 r9 = p->R9();
687 e3x3 = p->E33();
688 e5x5 = p->E55();
689 hovere = p->HadOverEm();
690 sigietaieta = p->CoviEtaiEta();
691 phcat = PhotonTools::CiCBaseLineCat(p);
692 eerr = p->EnergyErr();
693 eerrsmeared = p->EnergyErrSmeared();
694 esmearing = p->EnergySmearing();
695 idmva = p->IdMva();
696 hcalisodr03 = p->HcalTowerSumEtDr03();
697 ecalisodr03 = p->EcalRecHitIsoDr03();
698 trkisohollowdr03 = p->HollowConeTrkIsoDr03();
699 }
700 else {
701 hasphoton = kFALSE;
702 e = -99.;
703 pt = -99.;
704 eta = -99.;
705 phi = -99.;
706 r9 = b->E3x3()/s->RawEnergy();
707 e3x3 = b->E3x3();
708 e5x5 = b->E5x5();
709 hovere = ele->HadronicOverEm();
710 sigietaieta = ele->CoviEtaiEta();
711 phcat = -99;
712 eerr = -99.;
713 eerrsmeared = -99.;
714 esmearing = 0.;
715 idmva = -99.;
716 }
717
718
719 sce = s->Energy();
720 scrawe = s->RawEnergy();
721 scpse = s->PreshowerEnergy();
722 sceta = s->Eta();
723 scphi = s->Phi();
724 scnclusters = s->ClusterSize();
725 scnhits = s->NHits();
726 scetawidth = s->EtaWidth();
727 scphiwidth = s->PhiWidth();
728 isbarrel = (s->AbsEta()<1.5);
729 isr9reco = (isbarrel && r9>0.94) || (!isbarrel && r9>0.95);
730 isr9cat = (r9>0.94);
731
732 eseed = b->Energy();
733 etaseed = b->Eta();
734 phiseed = b->Phi();
735 ietaseed = b->IEta();
736 iphiseed = b->IPhi();
737 ixseed = b->IX();
738 iyseed = b->IY();
739 etacryseed = b->EtaCry();
740 phicryseed = b->PhiCry();
741 xcryseed = b->XCry();
742 ycryseed = b->YCry();
743 thetaaxisseed = b->ThetaAxis();
744 phiaxisseed = b->PhiAxis();
745 sigietaietaseed = TMath::Sqrt(b->CoviEtaiEta());
746 sigiphiphiseed = TMath::Sqrt(b->CoviPhiiPhi());
747 if (isnan(sigiphiphiseed)) sigiphiphiseed = -99.;
748 covietaiphiseed = b->CoviEtaiPhi();
749 if (isnan(covietaiphiseed)) covietaiphiseed = -99.;
750 e3x3seed = b->E3x3();
751 e5x5seed = b->E5x5();
752 emaxseed = b->EMax();
753 e2ndseed = b->E2nd();
754 etopseed = b->ETop();
755 ebottomseed = b->EBottom();
756 eleftseed = b->ELeft();
757 erightseed = b->ERight();
758 e1x3seed = b->E1x3();
759 e3x1seed = b->E3x1();
760 e1x5seed = b->E1x5();
761 e2x2seed = b->E2x2();
762 e4x4seed = b->E4x4();
763 e2x5maxseed = b->E2x5Max();
764 e2x5topseed = b->E2x5Top();
765 e2x5bottomseed = b->E2x5Bottom();
766 e2x5leftseed = b->E2x5Left();
767 e2x5rightseed = b->E2x5Right();
768 xseedseed = b->Pos().X();
769 yseedseed = b->Pos().Y();
770 zseedseed = b->Pos().Z();
771 nhitsseed = b->NHits();
772
773
774 if (b2) {
775 ebc2 = b2->Energy();
776 etabc2 = b2->Eta();
777 phibc2 = b2->Phi();
778 ietabc2 = b2->IEta();
779 iphibc2 = b2->IPhi();
780 ixbc2 = b2->IX();
781 iybc2 = b2->IY();
782 etacrybc2 = b2->EtaCry();
783 phicrybc2 = b2->PhiCry();
784 xcrybc2 = b2->XCry();
785 ycrybc2 = b2->YCry();
786 thetaaxisbc2 = b2->ThetaAxis();
787 phiaxisbc2 = b2->PhiAxis();
788 sigietaietabc2 = TMath::Sqrt(b2->CoviEtaiEta());
789 sigiphiphibc2 = TMath::Sqrt(b2->CoviPhiiPhi());
790 if (isnan(sigiphiphibc2)) sigiphiphibc2 = -99.;
791 covietaiphibc2 = b2->CoviEtaiPhi();
792 if (isnan(covietaiphibc2)) covietaiphibc2 = -99.;
793 e3x3bc2 = b2->E3x3();
794 e5x5bc2 = b2->E5x5();
795 emaxbc2 = b2->EMax();
796 e2ndbc2 = b2->E2nd();
797 etopbc2 = b2->ETop();
798 ebottombc2 = b2->EBottom();
799 eleftbc2 = b2->ELeft();
800 erightbc2 = b2->ERight();
801 e1x3bc2 = b2->E1x3();
802 e3x1bc2 = b2->E3x1();
803 e1x5bc2 = b2->E1x5();
804 e2x2bc2 = b2->E2x2();
805 e4x4bc2 = b2->E4x4();
806 e2x5maxbc2 = b2->E2x5Max();
807 e2x5topbc2 = b2->E2x5Top();
808 e2x5bottombc2 = b2->E2x5Bottom();
809 e2x5leftbc2 = b2->E2x5Left();
810 e2x5rightbc2 = b2->E2x5Right();
811 xbc2bc2 = b2->Pos().X();
812 ybc2bc2 = b2->Pos().Y();
813 zbc2bc2 = b2->Pos().Z();
814 nhitsbc2= b2->NHits();
815 }
816 else {
817 ebc2 = 0;
818 etabc2 = 0;
819 phibc2 = 0;
820 ietabc2 = 0;
821 iphibc2 = 0;
822 ixbc2 = 0;
823 iybc2 = 0;
824 etacrybc2 = 0;
825 phicrybc2 = 0;
826 xcrybc2 = 0;
827 ycrybc2 = 0;
828 thetaaxisbc2 = 0;
829 phiaxisbc2 = 0;
830 sigietaietabc2 = 0;
831 sigiphiphibc2 = 0;
832 covietaiphibc2 = 0;
833 e3x3bc2 = 0;
834 e5x5bc2 = 0;
835 emaxbc2 = 0;
836 e2ndbc2 = 0;
837 etopbc2 = 0;
838 ebottombc2 = 0;
839 eleftbc2 = 0;
840 erightbc2 = 0;
841 e1x3bc2 = 0;
842 e3x1bc2 = 0;
843 e1x5bc2 = 0;
844 e2x2bc2 = 0;
845 e4x4bc2 = 0;
846 e2x5maxbc2 = 0;
847 e2x5topbc2 = 0;
848 e2x5bottombc2 = 0;
849 e2x5leftbc2 = 0;
850 e2x5rightbc2 = 0;
851 xbc2bc2 = 0;
852 ybc2bc2 = 0;
853 zbc2bc2 = 0;
854 nhitsbc2 = 0;
855 }
856
857 if (bclast) {
858 ebclast = bclast->Energy();
859 etabclast = bclast->Eta();
860 phibclast = bclast->Phi();
861 ietabclast = bclast->IEta();
862 iphibclast = bclast->IPhi();
863 ixbclast = bclast->IX();
864 iybclast = bclast->IY();
865 etacrybclast = bclast->EtaCry();
866 phicrybclast = bclast->PhiCry();
867 xcrybclast = bclast->XCry();
868 ycrybclast = bclast->YCry();
869 thetaaxisbclast = bclast->ThetaAxis();
870 phiaxisbclast = bclast->PhiAxis();
871 sigietaietabclast = TMath::Sqrt(bclast->CoviEtaiEta());
872 sigiphiphibclast = TMath::Sqrt(bclast->CoviPhiiPhi());
873 if (isnan(sigiphiphibclast)) sigiphiphibclast = -99.;
874 covietaiphibclast = bclast->CoviEtaiPhi();
875 if (isnan(covietaiphibclast)) covietaiphibclast = -99.;
876 e3x3bclast = bclast->E3x3();
877 nhitsbclast = bclast->NHits();
878 }
879 else {
880 ebclast = 0;
881 etabclast = 0;
882 phibclast = 0;
883 ietabclast = 0;
884 iphibclast = 0;
885 ixbclast = 0;
886 iybclast = 0;
887 etacrybclast = 0;
888 phicrybclast = 0;
889 xcrybclast = 0;
890 ycrybclast = 0;
891 thetaaxisbclast = 0;
892 phiaxisbclast = 0;
893 sigietaietabclast = 0;
894 sigiphiphibclast = 0;
895 covietaiphibclast = 0;
896 e3x3bclast = 0;
897 nhitsbclast = 0;
898 }
899
900 if (bclast2) {
901 ebclast2 = bclast2->Energy();
902 etabclast2 = bclast2->Eta();
903 phibclast2 = bclast2->Phi();
904 ietabclast2 = bclast2->IEta();
905 iphibclast2 = bclast2->IPhi();
906 ixbclast2 = bclast2->IX();
907 iybclast2 = bclast2->IY();
908 etacrybclast2 = bclast2->EtaCry();
909 phicrybclast2 = bclast2->PhiCry();
910 xcrybclast2 = bclast2->XCry();
911 ycrybclast2 = bclast2->YCry();
912 thetaaxisbclast2 = bclast2->ThetaAxis();
913 phiaxisbclast2 = bclast2->PhiAxis();
914 sigietaietabclast2 = TMath::Sqrt(bclast2->CoviEtaiEta());
915 sigiphiphibclast2 = TMath::Sqrt(bclast2->CoviPhiiPhi());
916 if (isnan(sigiphiphibclast2)) sigiphiphibclast2 = -99.;
917 covietaiphibclast2 = bclast2->CoviEtaiPhi();
918 if (isnan(covietaiphibclast2)) covietaiphibclast2 = -99.;
919 e3x3bclast2 = bclast2->E3x3();
920 nhitsbclast2 = bclast2->NHits();
921 }
922 else {
923 ebclast2 = 0;
924 etabclast2 = 0;
925 phibclast2 = 0;
926 ietabclast2 = 0;
927 iphibclast2 = 0;
928 ixbclast2 = 0;
929 iybclast2 = 0;
930 etacrybclast2 = 0;
931 phicrybclast2 = 0;
932 xcrybclast2 = 0;
933 ycrybclast2 = 0;
934 thetaaxisbclast2 = 0;
935 phiaxisbclast2 = 0;
936 sigietaietabclast2 = 0;
937 sigiphiphibclast2 = 0;
938 covietaiphibclast2 = 0;
939 e3x3bclast2 = 0;
940 nhitsbclast2 = 0;
941 }
942
943
944 //initialize photon energy corrections if needed
945 /*if (!PhotonFix::initialised()) {
946 PhotonFix::initialise("4_2",std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/PhotonFix.dat")).Data()));
947 }*/
948
949
950 phfixph.setup(e,sceta,scphi,r9);
951 phfixele.setup(e,sceta,scphi,r9);
952
953 const Float_t dval = -99.;
954 ecor = phfixph.fixedEnergy();
955 ecorerr = phfixph.sigmaEnergy();
956 ecorele = phfixele.fixedEnergy();
957 ecoreleerr = phfixele.sigmaEnergy();
958 if (phfixph.isbarrel()) {
959 etac = phfixph.etaC();
960 etas = phfixph.etaS();
961 etam = phfixph.etaM();
962 phic = phfixph.phiC();
963 phis = phfixph.phiS();
964 phim = phfixph.phiM();
965 xz = dval;
966 xc = dval;
967 xs = dval;
968 xm = dval;
969 yz = dval;
970 yc = dval;
971 ys = dval;
972 ym = dval;
973 }
974 else {
975 etac = dval;
976 etas = dval;
977 etam = dval;
978 phic = dval;
979 phis = dval;
980 phim = dval;
981 xz = phfixph.xZ();
982 xc = phfixph.xC();
983 xs = phfixph.xS();
984 xm = phfixph.xM();
985 yz = phfixph.yZ();
986 yc = phfixph.yC();
987 ys = phfixph.yS();
988 ym = phfixph.yM();
989 }
990
991 if (c) {
992 hasconversion = kTRUE;
993 convp = c->P();
994 convpt = c->Pt();
995 conveta = c->Eta();
996 convphi = c->Phi();
997 ThreeVector dirconvsc = ThreeVector(s->Point()) - c->Position();
998 convdeta = c->Eta() - dirconvsc.Eta();
999 convdphi = MathUtils::DeltaPhi(c->Phi(),dirconvsc.Phi());
1000 convvtxrho = c->Position().Rho();
1001 convvtxz = c->Position().Z();
1002 convvtxphi = c->Position().Phi();
1003
1004 const StableData *leadsd = dynamic_cast<const StableData*>(c->DaughterDat(0));
1005 const StableData *trailsd = dynamic_cast<const StableData*>(c->DaughterDat(1));
1006 if (leadsd->Pt()<trailsd->Pt()) {
1007 const StableData *sdtmp = leadsd;
1008 leadsd = trailsd;
1009 trailsd = sdtmp;
1010 }
1011
1012 const Track *leadtrack = dynamic_cast<const StableParticle*>(leadsd->Original())->Trk();
1013 const Track *trailtrack = dynamic_cast<const StableParticle*>(trailsd->Original())->Trk();
1014
1015 convleadpt = leadsd->Pt();
1016 convtrailpt = trailsd->Pt();
1017 convleadtrackpt = leadtrack->Pt();
1018 convleadtrackalgo = leadtrack->Algo();
1019 if (convleadtrackalgo==29) convleadtrackalgos=2; //gsf track
1020 else if (convleadtrackalgo==15 ||convleadtrackalgo==16) convleadtrackalgos=1; //ecal-seeded track
1021 else convleadtrackalgos = 0; //std iterative track
1022 convleadtrackcharge = leadtrack->Charge();
1023 convtrailtrackpt = trailtrack->Pt();
1024 convtrailtrackalgo = trailtrack->Algo();
1025 if (convtrailtrackalgo==29) convtrailtrackalgos=2; //gsf track
1026 else if (convtrailtrackalgo==15 ||convtrailtrackalgo==16) convtrailtrackalgos=1; //ecal-seeded track
1027 else convtrailtrackalgos = 0; //std iterative track
1028 trailtrackcharge = trailtrack->Charge();
1029 }
1030 else {
1031 hasconversion = kFALSE;
1032 convp = -99.;
1033 convpt = -99.;
1034 conveta = -99.;
1035 convphi = -99.;
1036 convdeta = -99.;
1037 convdphi = -99.;
1038 convvtxrho = -99.;
1039 convvtxz = -999.;
1040 convvtxphi = -99.;
1041 convleadpt = -99.;
1042 convtrailpt = -99.;
1043 convleadtrackpt = -99.;
1044 convleadtrackalgo = -99;
1045 convleadtrackalgos = -99;
1046 convleadtrackcharge = 0;
1047 convtrailtrackpt = -99.;
1048 convtrailtrackalgo = -99;
1049 convtrailtrackalgos = -99;
1050 trailtrackcharge = 0;
1051 }
1052
1053 //electron quantities
1054 if (ele) {
1055 haselectron = kTRUE;
1056 eleisecaldriven = ele->IsEcalDriven();
1057 eleistrackerdriven = ele->IsTrackerDriven();
1058 elee = ele->E();
1059 elept = ele->Pt();
1060 eleeta = ele->Eta();
1061 elephi = ele->Phi();
1062 elecharge = ele->Charge();
1063 elefbrem = ele->FBrem();
1064 eledeta = ele->DeltaEtaSuperClusterTrackAtVtx();
1065 eledphi = ele->DeltaPhiSuperClusterTrackAtVtx();
1066 elep = s->Energy()/ele->ESuperClusterOverP();
1067 elepin = ele->PIn();
1068 elepout = ele->POut();
1069 }
1070 else {
1071 haselectron = kFALSE;
1072 eleisecaldriven = kFALSE;
1073 eleistrackerdriven = kFALSE;
1074 elee = -99.;
1075 elept = -99.;
1076 eleeta = -99.;
1077 elephi = -99.;
1078 elecharge = -99;
1079 elefbrem = -99.;
1080 eledeta = -99.;
1081 eledphi = -99.;
1082 elep = -99.;
1083 elepin = -99.;
1084 elepout = -99.;
1085 }
1086
1087 //pf supercluster quantities
1088 if (pfsc) {
1089 haspfsc = kTRUE;
1090 pfsce = pfsc->Energy();
1091 pfscrawe = pfsc->RawEnergy();
1092 pfsceta = pfsc->Eta();
1093 pfscphi = pfsc->Phi();
1094 }
1095 else {
1096 haspfsc = kFALSE;
1097 pfsce = -99.;
1098 pfscrawe = -99.;
1099 pfsceta = -99.;
1100 pfscphi = -99.;
1101 }
1102
1103 genz = -99.;
1104 if (m) {
1105 ispromptgen = kTRUE;
1106 gene = m->E();
1107 genpt = m->Pt();
1108 geneta = m->Eta();
1109 genphi = m->Phi();
1110 const MCParticle *mm = m->DistinctMother();
1111 if (mm) genz = mm->DecayVertex().Z();
1112 pdgid = m->PdgId();
1113 if (mm) motherpdgid = mm->PdgId();
1114 else motherpdgid = -99;
1115 }
1116 else {
1117 ispromptgen = kFALSE;
1118 gene = -99.;
1119 genpt = -99.;
1120 geneta = -99.;
1121 genphi = -99.;
1122 pdgid = -99;
1123 motherpdgid = -99;
1124 }
1125
1126 }
1127