ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/PhotonTreeWriter.cc
Revision: 1.8
Committed: Sat Dec 17 22:29:30 2011 UTC (13 years, 4 months ago) by bendavid
Content type: text/plain
Branch: MAIN
Changes since 1.7: +37 -6 lines
Log Message:
further small gamma gamma updates

File Contents

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