ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/PhotonTreeWriter.cc
Revision: 1.36
Committed: Fri Oct 26 19:23:05 2012 UTC (12 years, 6 months ago) by fabstoec
Content type: text/plain
Branch: MAIN
Changes since 1.35: +252 -86 lines
Log Message:
*** empty log message ***

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 fabstoec 1.16 #include "MitPhysics/Utils/interface/PFMetCorrectionTools.h"
12     #include "MitAna/DataTree/interface/PFJetCol.h"
13     #include "MitAna/DataTree/interface/GenJetCol.h"
14 bendavid 1.1 #include "TDataMember.h"
15 bendavid 1.20 #include "TFile.h"
16 bendavid 1.1 #include <TNtuple.h>
17     #include <TRandom3.h>
18     #include <TSystem.h>
19    
20     using namespace mithep;
21    
22     ClassImp(mithep::PhotonTreeWriter)
23 mingyang 1.26 templateClassImp(mithep::PhotonTreeWriterPhoton)//ming: what's this?
24 bendavid 1.1 ClassImp(mithep::PhotonTreeWriterDiphotonEvent)
25    
26     //--------------------------------------------------------------------------------------------------
27     PhotonTreeWriter::PhotonTreeWriter(const char *name, const char *title) :
28     // Base Module...
29 paus 1.12 BaseMod (name,title),
30 bendavid 1.1 // define all the Branches to load
31 paus 1.12 fPhotonBranchName (Names::gkPhotonBrn),
32 bendavid 1.20 fPFPhotonName ("PFPhotons"),
33 paus 1.12 fElectronName (Names::gkElectronBrn),
34     fGoodElectronName (Names::gkElectronBrn),
35     fConversionName (Names::gkMvfConversionBrn),
36 fabstoec 1.36 fPFConversionName ("PFPhotonConversions"),
37 paus 1.12 fTrackBranchName (Names::gkTrackBrn),
38     fPileUpDenName (Names::gkPileupEnergyDensityBrn),
39     fPVName (Names::gkPVBeamSpotBrn),
40     fBeamspotName (Names::gkBeamSpotBrn),
41     fPFCandName (Names::gkPFCandidatesBrn),
42 fabstoec 1.28 fPFNoPileUpName ("PFNoPileUp"),
43     fPFPileUpName ("PFPileUp"),
44 paus 1.12 fMCParticleName (Names::gkMCPartBrn),
45 bendavid 1.32 fMCEventInfoName (Names::gkMCEvtInfoBrn),
46 paus 1.12 fPileUpName (Names::gkPileupInfoBrn),
47     fSuperClusterName ("PFSuperClusters"),
48     fPFMetName ("PFMet"),
49     fPFJetName (Names::gkPFJetBrn),
50 fabstoec 1.19 funcorrPFJetName ("AKt5PFJets"),
51 fabstoec 1.17 fGenJetName ("AKT5GenJets"),
52 fabstoec 1.13 fLeptonTagElectronsName ("HggLeptonTagElectrons"),
53     fLeptonTagMuonsName ("HggLeptonTagMuons"),
54    
55 paus 1.12 fIsData (false),
56     fPhotonsFromBranch (kTRUE),
57     fPVFromBranch (kTRUE),
58     fGoodElectronsFromBranch(kTRUE),
59     fPFJetsFromBranch (kTRUE),
60 bendavid 1.1 // ----------------------------------------
61 fabstoec 1.36 // flag for synchronization, adds vertex variables
62     // should be on for synching trees
63     fDoSynching (kTRUE),
64    
65     // ----------------------------------------
66 bendavid 1.1 // collections....
67 paus 1.12 fPhotons (0),
68 bendavid 1.20 fPFPhotons (0),
69 paus 1.12 fElectrons (0),
70     fConversions (0),
71 fabstoec 1.36 fPFConversions (0),
72 paus 1.12 fTracks (0),
73     fPileUpDen (0),
74     fPV (0),
75     fBeamspot (0),
76     fPFCands (0),
77     fMCParticles (0),
78 bendavid 1.32 fMCEventInfo (0),
79 paus 1.12 fPileUp (0),
80     fSuperClusters (0),
81     fPFJets (0),
82 fabstoec 1.16 fGenJets (0),
83     funcorrPFJets (0),
84 fabstoec 1.13
85     fLeptonTagElectrons (0),
86     fLeptonTagMuons (0),
87 fabstoec 1.28 fPFNoPileUpCands (0),
88     fPFPileUpCands (0),
89 fabstoec 1.13
90 paus 1.12 fLoopOnGoodElectrons (kFALSE),
91     fApplyElectronVeto (kTRUE),
92     fWriteDiphotonTree (kTRUE),
93     fWriteSingleTree (kTRUE),
94 bendavid 1.20 fEnablePFPhotons (kTRUE),
95 paus 1.12 fExcludeSinglePrompt (kFALSE),
96     fExcludeDoublePrompt (kFALSE),
97     fEnableJets (kFALSE),
98 bendavid 1.22 fApplyJetId (kFALSE),
99 fabstoec 1.13 fApplyLeptonTag (kFALSE),
100 mingyang 1.31 fApplyVBFTag (kFALSE),
101 fabstoec 1.15 fApplyBTag (kFALSE),
102 fabstoec 1.17 fApplyPFMetCorrections (kFALSE),
103 bendavid 1.20 fFillClusterArrays (kFALSE),
104 bendavid 1.22 fFillVertexTree (kFALSE),
105 fabstoec 1.28 fDo2012LepTag (kFALSE),
106 paus 1.12 fPhFixDataFile (gSystem->Getenv("CMSSW_BASE") +
107     TString("/src/MitPhysics/data/PhotonFixSTART42V13.dat")),
108 bendavid 1.30 fBeamspotWidth (5.8),
109 fabstoec 1.36
110     fElectronIDMVA(0),
111     fElectronMVAWeights_Subdet0Pt10To20(""),
112     fElectronMVAWeights_Subdet1Pt10To20(""),
113     fElectronMVAWeights_Subdet2Pt10To20(""),
114     fElectronMVAWeights_Subdet0Pt20ToInf(""),
115     fElectronMVAWeights_Subdet1Pt20ToInf(""),
116     fElectronMVAWeights_Subdet2Pt20ToInf(""),
117     fTheRhoType(RhoUtilities::DEFAULT),
118    
119 paus 1.12 fTupleName ("hPhotonTree")
120 bendavid 1.1 {
121 paus 1.12 // Constructor
122 bendavid 1.1 }
123    
124 paus 1.12 PhotonTreeWriter::~PhotonTreeWriter()
125     {
126     // Destructor
127 bendavid 1.1 }
128    
129     //--------------------------------------------------------------------------------------------------
130     void PhotonTreeWriter::Process()
131     {
132     // ------------------------------------------------------------
133     // Process entries of the tree.
134     LoadEventObject(fPhotonBranchName, fPhotons);
135 paus 1.12 LoadEventObject(fGoodElectronName, fGoodElectrons);
136 fabstoec 1.13
137     // lepton tag collections
138     if( fApplyLeptonTag ) {
139     LoadEventObject(fLeptonTagElectronsName, fLeptonTagElectrons);
140     LoadEventObject(fLeptonTagMuonsName, fLeptonTagMuons);
141     }
142    
143 bendavid 1.2 const BaseCollection *egcol = 0;
144 paus 1.12 if (fLoopOnGoodElectrons)
145 bendavid 1.2 egcol = fGoodElectrons;
146 paus 1.12 else
147 bendavid 1.2 egcol = fPhotons;
148 paus 1.12 if (egcol->GetEntries()<1)
149     return;
150 bendavid 1.20
151     if (fEnablePFPhotons) LoadEventObject(fPFPhotonName, fPFPhotons);
152 bendavid 1.1 LoadEventObject(fElectronName, fElectrons);
153     LoadEventObject(fConversionName, fConversions);
154 fabstoec 1.36 if ( fDoSynching ) LoadEventObject(fPFConversionName, fPFConversions);
155 bendavid 1.1 LoadEventObject(fTrackBranchName, fTracks);
156     LoadEventObject(fPileUpDenName, fPileUpDen);
157     LoadEventObject(fPVName, fPV);
158     LoadEventObject(fBeamspotName, fBeamspot);
159     LoadEventObject(fPFCandName, fPFCands);
160 bendavid 1.2 LoadEventObject(fSuperClusterName, fSuperClusters);
161 paus 1.12 LoadEventObject(fPFMetName, fPFMet);
162 bendavid 1.30 // LoadEventObject(fPFNoPileUpName, fPFNoPileUpCands);
163     // LoadEventObject(fPFPileUpName, fPFPileUpCands);
164 fabstoec 1.28
165 fabstoec 1.16 if (fEnableJets){
166 paus 1.12 LoadEventObject(fPFJetName, fPFJets);
167 fabstoec 1.19 //LoadEventObject(funcorrPFJetName, funcorrPFJets);
168 fabstoec 1.16 LoadBranch(funcorrPFJetName);
169 fabstoec 1.19 // if(!fIsData) LoadEventObject(fGenJetName, fGenJets);
170 fabstoec 1.16 }
171 fabstoec 1.28
172 bendavid 1.1 // ------------------------------------------------------------
173     // load event based information
174 paus 1.12 Int_t _numPU = -1.; // some sensible default values....
175 bendavid 1.1 Int_t _numPUminus = -1.; // some sensible default values....
176 paus 1.12 Int_t _numPUplus = -1.; // some sensible default values....
177 bendavid 1.1
178 paus 1.12 Float_t rho = -99.;
179 bendavid 1.1 if( fPileUpDen->GetEntries() > 0 )
180 paus 1.12 rho = (Double_t) fPileUpDen->At(0)->RhoRandomLowEta();
181 bendavid 1.1
182 mingyang 1.26 const BaseVertex *bsp = dynamic_cast<const BaseVertex*>(fBeamspot->At(0));//ming:what's this?
183 bendavid 1.20
184 bendavid 1.1 if( !fIsData ) {
185     LoadBranch(fMCParticleName);
186 bendavid 1.32 LoadBranch(fMCEventInfoName);
187 bendavid 1.1 LoadBranch(fPileUpName);
188 fabstoec 1.19 if (fEnableJets) LoadEventObject(fGenJetName, fGenJets);
189     } else fGenJets = NULL;
190 bendavid 1.1
191     if( !fIsData ) {
192     for (UInt_t i=0; i<fPileUp->GetEntries(); ++i) {
193     const PileupInfo *puinfo = fPileUp->At(i);
194     if (puinfo->GetBunchCrossing()==0) _numPU = puinfo->GetPU_NumInteractions();
195     else if (puinfo->GetBunchCrossing() == -1) _numPUminus = puinfo->GetPU_NumInteractions();
196     else if (puinfo->GetBunchCrossing() == 1) _numPUplus = puinfo->GetPU_NumInteractions();
197     }
198     }
199    
200     // in case of a MC event, try to find Higgs and Higgs decay Z poisition
201 paus 1.12 Float_t _pth = -100.;
202     Float_t _decayZ = -100.;
203 bendavid 1.1 Float_t _genmass = -100.;
204 paus 1.12 if (!fIsData)
205     FindHiggsPtAndZ(_pth, _decayZ, _genmass);
206 bendavid 1.1
207 bendavid 1.30
208     fDiphotonEvent->genz = -999.;
209     if (!fIsData) {
210     fDiphotonEvent->genz = fMCParticles->At(0)->DecayVertex().Z();
211     }
212 bendavid 1.32
213     fDiphotonEvent->mcprocid = -999;
214     if (!fIsData) {
215     fDiphotonEvent->mcprocid = fMCEventInfo->ProcessId();
216     }
217 fabstoec 1.19
218 mtouch 1.25 Double_t _evt = GetEventHeader()->EvtNum();
219 fabstoec 1.28
220 fabstoec 1.19 Double_t _spfMet = fPFMet->At(0)->SumEt();
221 mtouch 1.25
222 fabstoec 1.13 fDiphotonEvent->leptonTag = -1; // disabled
223    
224 fabstoec 1.36 // ====================================================
225     // Vtx synching stuff...
226     fDiphotonEvent->vtxInd1 = -1;
227     fDiphotonEvent->vtxInd2 = -1;
228     fDiphotonEvent->vtxInd3 = -1;
229    
230     fDiphotonEvent->vtxBestPtbal = -1.;
231     fDiphotonEvent->vtxBestPtasym = -1.;
232     fDiphotonEvent->vtxBestSumpt2 = -1.;
233     fDiphotonEvent->vtxBestP2Conv = -1.;
234    
235     fDiphotonEvent->vtxMva1 = -1.;
236     fDiphotonEvent->vtxMva2 = -1.;
237     fDiphotonEvent->vtxMva3 = -1.;
238    
239     fDiphotonEvent->vtxNleg1 = -1;
240     fDiphotonEvent->vtxNleg2 = -1;
241     fDiphotonEvent->vtxNconv = -1;
242     // ====================================================
243    
244    
245 bendavid 1.20 fDiphotonEvent->rho = fPileUpDen->At(0)->RhoKt6PFJets();
246     fDiphotonEvent->rho25 = fPileUpDen->At(0)->RhoRandomLowEta();
247     fDiphotonEvent->rhoold = fPileUpDen->At(0)->Rho();
248 bendavid 1.1 fDiphotonEvent->genHiggspt = _pth;
249     fDiphotonEvent->genHiggsZ = _decayZ;
250     fDiphotonEvent->genmass = _genmass;
251     fDiphotonEvent->gencostheta = -99.;
252     fDiphotonEvent->nVtx = fPV->GetEntries();
253 bendavid 1.2 fDiphotonEvent->bsX = fBeamspot->At(0)->X();
254     fDiphotonEvent->bsY = fBeamspot->At(0)->Y();
255     fDiphotonEvent->bsZ = fBeamspot->At(0)->Z();
256 bendavid 1.7 fDiphotonEvent->bsSigmaZ = fBeamspot->At(0)->SigmaZ();
257 bendavid 1.2 fDiphotonEvent->vtxX = (fDiphotonEvent->nVtx>0) ? fPV->At(0)->X() : -99.;
258     fDiphotonEvent->vtxY = (fDiphotonEvent->nVtx>0) ? fPV->At(0)->Y() : -99.;
259 bendavid 1.1 fDiphotonEvent->vtxZ = (fDiphotonEvent->nVtx>0) ? fPV->At(0)->Z() : -99.;
260     fDiphotonEvent->numPU = _numPU;
261     fDiphotonEvent->numPUminus = _numPUminus;
262     fDiphotonEvent->numPUplus = _numPUplus;
263     fDiphotonEvent->mass = -99.;
264     fDiphotonEvent->ptgg = -99.;
265     fDiphotonEvent->costheta = -99.;
266 bendavid 1.2 fDiphotonEvent->mt = -99.;
267     fDiphotonEvent->cosphimet = -99.;
268     fDiphotonEvent->mtele = -99.;
269     fDiphotonEvent->cosphimetele = -99.;
270 bendavid 1.1 fDiphotonEvent->evt = GetEventHeader()->EvtNum();
271     fDiphotonEvent->run = GetEventHeader()->RunNum();
272     fDiphotonEvent->lumi = GetEventHeader()->LumiSec();
273     fDiphotonEvent->evtcat = -99;
274 bendavid 1.2 fDiphotonEvent->nobj = fPhotons->GetEntries();
275     fDiphotonEvent->pfmet = fPFMet->At(0)->Pt();
276     fDiphotonEvent->pfmetphi = fPFMet->At(0)->Phi();
277     fDiphotonEvent->pfmetx = fPFMet->At(0)->Px();
278     fDiphotonEvent->pfmety = fPFMet->At(0)->Py();
279 fabstoec 1.19 fDiphotonEvent->spfMet = _spfMet;
280 bendavid 1.1 fDiphotonEvent->masscor = -99.;
281     fDiphotonEvent->masscorerr = -99.;
282 bendavid 1.2 fDiphotonEvent->masscorele = -99.;
283     fDiphotonEvent->masscoreleerr = -99.;
284     fDiphotonEvent->ismc = GetEventHeader()->IsMC();
285    
286 bendavid 1.5 //jets
287     const Jet *jet1 = 0;
288     const Jet *jet2 = 0;
289     const Jet *jetcentral = 0;
290    
291     fDiphotonEvent->jet1pt = -99.;
292     fDiphotonEvent->jet1eta = -99.;
293     fDiphotonEvent->jet1phi = -99.;
294     fDiphotonEvent->jet1mass = -99.;
295     fDiphotonEvent->jet2pt = -99.;
296     fDiphotonEvent->jet2eta = -99.;
297     fDiphotonEvent->jet2phi = -99.;
298     fDiphotonEvent->jet2mass = -99.;
299     fDiphotonEvent->jetcentralpt = -99.;
300     fDiphotonEvent->jetcentraleta = -99.;
301     fDiphotonEvent->jetcentralphi = -99.;
302     fDiphotonEvent->jetcentralmass = -99.;
303     fDiphotonEvent->dijetpt = -99.;
304     fDiphotonEvent->dijeteta = -99.;
305     fDiphotonEvent->dijetphi = -99.;
306     fDiphotonEvent->dijetmass = -99.;
307     fDiphotonEvent->jetetaplus = -99.;
308     fDiphotonEvent->jetetaminus = -99.;
309     fDiphotonEvent->zeppenfeld = -99.;
310     fDiphotonEvent->dphidijetgg = -99.;
311    
312 fabstoec 1.19 //uncorrected jets
313     // const Jet *uncorrjet1 = 0;
314     // const Jet *uncorrjet2 = 0;
315     // const Jet *uncorrjetcentral = 0;
316    
317     // fDiphotonEvent->uncorrjet1pt = -99.;
318     // fDiphotonEvent->uncorrjet1eta = -99.;
319     // fDiphotonEvent->uncorrjet1phi = -99.;
320     // fDiphotonEvent->uncorrjet1mass = -99.;
321     // fDiphotonEvent->uncorrjet2pt = -99.;
322     // fDiphotonEvent->uncorrjet2eta = -99.;
323     // fDiphotonEvent->uncorrjet2phi = -99.;
324     // fDiphotonEvent->uncorrjet2mass = -99.;
325     // fDiphotonEvent->uncorrjetcentralpt = -99.;
326     // fDiphotonEvent->uncorrjetcentraleta = -99.;
327     // fDiphotonEvent->uncorrjetcentralphi = -99.;
328     // fDiphotonEvent->uncorrjetcentralmass = -99.;
329     // fDiphotonEvent->diuncorrjetpt = -99.;
330     // fDiphotonEvent->diuncorrjeteta = -99.;
331     // fDiphotonEvent->diuncorrjetphi = -99.;
332     // fDiphotonEvent->diuncorrjetmass = -99.;
333    
334    
335    
336 bendavid 1.1 Int_t nhitsbeforevtxmax = 1;
337 paus 1.12 if (!fApplyElectronVeto)
338     nhitsbeforevtxmax = 999;
339 bendavid 1.1
340 bendavid 1.2 if (egcol->GetEntries()>=2) {
341     const Particle *p1 = 0;
342     const Particle *p2 = 0;
343     const Photon *phHard = 0;
344     const Photon *phSoft = 0;
345     const Electron *ele1 = 0;
346     const Electron *ele2 = 0;
347     const SuperCluster *sc1 = 0;
348     const SuperCluster *sc2 = 0;
349    
350     if (fLoopOnGoodElectrons) {
351     ele1 = fGoodElectrons->At(0);
352     ele2 = fGoodElectrons->At(1);
353     p1 = ele1;
354     p2 = ele2;
355     sc1 = ele1->SCluster();
356     sc2 = ele2->SCluster();
357     phHard = PhotonTools::MatchedPhoton(ele1,fPhotons);
358     phSoft = PhotonTools::MatchedPhoton(ele2,fPhotons);
359     }
360     else {
361     phHard = fPhotons->At(0);
362     phSoft = fPhotons->At(1);
363     p1 = phHard;
364     p2 = phSoft;
365     sc1 = phHard->SCluster();
366     sc2 = phSoft->SCluster();
367     ele1 = PhotonTools::MatchedElectron(phHard,fGoodElectrons);
368     ele2 = PhotonTools::MatchedElectron(phSoft,fGoodElectrons);
369 bendavid 1.1 }
370    
371 paus 1.12 const DecayParticle *conv1 = PhotonTools::MatchedConversion(sc1,fConversions,bsp,
372     nhitsbeforevtxmax);
373     const DecayParticle *conv2 = PhotonTools::MatchedConversion(sc2,fConversions,bsp,
374     nhitsbeforevtxmax);
375 bendavid 1.2
376 bendavid 1.20 const SuperCluster *pfsc1 = PhotonTools::MatchedPFSC(sc1,fPFPhotons, fElectrons);
377     const SuperCluster *pfsc2 = PhotonTools::MatchedPFSC(sc2,fPFPhotons, fElectrons);
378 bendavid 1.1
379     const MCParticle *phgen1 = 0;
380     const MCParticle *phgen2 = 0;
381 paus 1.12 if (!fIsData) {
382 bendavid 1.6 phgen1 = PhotonTools::MatchMC(p1,fMCParticles,!fApplyElectronVeto);
383     phgen2 = PhotonTools::MatchMC(p2,fMCParticles,!fApplyElectronVeto);
384 bendavid 1.2 }
385    
386 paus 1.12 if (fExcludeSinglePrompt && (phgen1 || phgen2))
387     return;
388     if (fExcludeDoublePrompt && (phgen1 && phgen2))
389     return;
390 bendavid 1.2
391     if (!fLoopOnGoodElectrons && phHard->HasPV()) {
392     fDiphotonEvent->vtxX = phHard->PV()->X();
393     fDiphotonEvent->vtxY = phHard->PV()->Y();
394     fDiphotonEvent->vtxZ = phHard->PV()->Z();
395 bendavid 1.4 fDiphotonEvent->vtxprob = phHard->VtxProb();
396 bendavid 1.2 }
397    
398 fabstoec 1.15 // fill Btag information... set to true if One jet fullfills
399 fabstoec 1.19 fDiphotonEvent -> btagJet1 = -1.;
400     fDiphotonEvent -> btagJet1Pt = -99.;
401     fDiphotonEvent -> btagJet1Eta = -99.;
402    
403     fDiphotonEvent -> btagJet2 = -1.;
404     fDiphotonEvent -> btagJet2Pt = -99.;
405     fDiphotonEvent -> btagJet2Eta = -99.;
406 fabstoec 1.18
407 fabstoec 1.15 if( fApplyBTag && fEnableJets ) {
408     float highTag = 0.;
409     float highJetPt = 0.;
410     float highJetEta = 0.;
411 fabstoec 1.19
412     float trailTag = 0.;
413 fabstoec 1.18 float trailJetPt = 0.;
414     float trailJetEta = 0.;
415 fabstoec 1.19
416 fabstoec 1.15 for (UInt_t ijet=0; ijet<fPFJets->GetEntries();++ijet) {
417     const Jet *jet = fPFJets->At(ijet);
418 fabstoec 1.24 if ( jet->Pt() < 20. || jet->AbsEta() > 2.4 ) continue;
419 fabstoec 1.15 if ( jet->CombinedSecondaryVertexBJetTagsDisc() > highTag ) {
420 fabstoec 1.19
421 fabstoec 1.24 trailTag = highTag;
422     trailJetPt = highJetPt;
423 fabstoec 1.18 trailJetEta = highJetEta;
424 fabstoec 1.19
425 fabstoec 1.15 highTag = jet->CombinedSecondaryVertexBJetTagsDisc();
426     highJetPt = jet->Pt();
427     highJetEta = jet->Eta();
428 fabstoec 1.19
429 fabstoec 1.18 } else if ( jet->CombinedSecondaryVertexBJetTagsDisc() > trailTag ) {
430 fabstoec 1.19
431 fabstoec 1.18 trailTag = jet->CombinedSecondaryVertexBJetTagsDisc();
432     trailJetPt = jet->Pt();
433     trailJetEta = jet->Eta();
434 fabstoec 1.15 }
435     }
436 fabstoec 1.18 fDiphotonEvent -> btagJet1 = highTag;
437     fDiphotonEvent -> btagJet1Pt = highJetPt;
438 fabstoec 1.19 fDiphotonEvent -> btagJet1Eta = highJetEta;
439    
440 fabstoec 1.24 fDiphotonEvent -> btagJet2 = trailTag;
441     fDiphotonEvent -> btagJet2Pt = trailJetPt;
442     fDiphotonEvent -> btagJet2Eta = trailJetEta;
443 fabstoec 1.19
444 fabstoec 1.15 }
445    
446 bendavid 1.5 //fill jet variables
447 bendavid 1.22 const Vertex *selvtx = fPV->At(0);
448     if (!fLoopOnGoodElectrons && phHard->HasPV()) selvtx = phHard->PV();
449 bendavid 1.5 if (fEnableJets) {
450     for (UInt_t ijet=0; ijet<fPFJets->GetEntries();++ijet) {
451     const Jet *jet = fPFJets->At(ijet);
452 bendavid 1.8 if (jet->AbsEta()<4.7 && MathUtils::DeltaR(jet,p1)>0.5 && MathUtils::DeltaR(jet,p2)>0.5) {
453 bendavid 1.22 const PFJet *pfjet = dynamic_cast<const PFJet*>(jet);
454     if (!pfjet) continue;
455     if (fApplyJetId && !fJetId.passCut(pfjet,selvtx,fPV)) continue;
456 bendavid 1.5 if (!jet1) jet1 = jet;
457     else if (!jet2) jet2 = jet;
458     else if (!jetcentral && 0) jetcentral = jet;
459     }
460     if (jet1&&jet2&&jetcentral) break;
461 mtouch 1.25 }
462 bendavid 1.5 }
463    
464     if (jet1) {
465     fDiphotonEvent->jet1pt = jet1->Pt();
466     fDiphotonEvent->jet1eta = jet1->Eta();
467     fDiphotonEvent->jet1phi = jet1->Phi();
468     fDiphotonEvent->jet1mass = jet1->Mass();
469     }
470    
471     if (jet2) {
472     fDiphotonEvent->jet2pt = jet2->Pt();
473     fDiphotonEvent->jet2eta = jet2->Eta();
474     fDiphotonEvent->jet2phi = jet2->Phi();
475     fDiphotonEvent->jet2mass = jet2->Mass();
476     }
477    
478     if (jetcentral) {
479     fDiphotonEvent->jetcentralpt = jetcentral->Pt();
480     fDiphotonEvent->jetcentraleta = jetcentral->Eta();
481     fDiphotonEvent->jetcentralphi = jetcentral->Phi();
482     fDiphotonEvent->jetcentralmass = jetcentral->Mass();
483     }
484    
485     if (jet1&&jet2){
486     FourVectorM momjj = (jet1->Mom() + jet2->Mom());
487    
488     fDiphotonEvent->dijetpt = momjj.Pt();
489     fDiphotonEvent->dijeteta = momjj.Eta();
490     fDiphotonEvent->dijetphi = momjj.Phi();
491     fDiphotonEvent->dijetmass = momjj.M();
492    
493     if (jet1->Eta()>jet2->Eta()) {
494     fDiphotonEvent->jetetaplus = jet1->Eta();
495     fDiphotonEvent->jetetaminus = jet2->Eta();
496     }
497     else {
498     fDiphotonEvent->jetetaplus = jet2->Eta();
499     fDiphotonEvent->jetetaminus = jet1->Eta();
500     }
501     }
502    
503 fabstoec 1.16 //added gen. info of whether a lep. or nutrino is from W or Z --Heng 02/14/2012 12:30 EST
504     Double_t _fromZ = -99;
505     Double_t _fromW = -99;
506     Float_t _zpt = -99;
507     Float_t _zEta = -99;
508     Float_t _allZpt = -99;
509     Float_t _allZEta = -99;
510    
511     if( !fIsData ){
512    
513     // loop over all GEN particles and look for nutrinos whoes mother is Z
514     for(UInt_t j=0; j<fMCParticles->GetEntries(); ++j) {
515     const MCParticle* p = fMCParticles->At(j);
516     if( p->AbsPdgId()==23 ||p->AbsPdgId()==32 || p->AbsPdgId()==33 ) {
517     _allZpt=p->Pt();
518     _allZEta=p->Eta();
519     if (p->HasDaughter(12,kFALSE) || p->HasDaughter(14,kFALSE) || p->HasDaughter(16,kFALSE) ||p->HasDaughter(18,kFALSE) ) {
520     _fromZ=1;
521     _zpt=p->Pt();
522     _zEta=p->Eta();
523     }
524     }
525     else _fromW=1;
526     }
527     }
528 mtouch 1.25
529 fabstoec 1.16 fDiphotonEvent->fromZ = _fromZ;
530     fDiphotonEvent->fromW = _fromW;
531     fDiphotonEvent->zpt = _zpt;
532     fDiphotonEvent->zEta = _zEta;
533     fDiphotonEvent->allZpt = _allZpt;
534     fDiphotonEvent->allZEta = _allZEta;
535    
536     Double_t _dphiMetgg = -99;
537     Double_t _cosdphiMetgg = -99;
538     Double_t _dphiPhPh = -99;
539 mtouch 1.25
540 bendavid 1.4 Double_t _mass = -99.;
541     Double_t _masserr = -99.;
542     Double_t _masserrsmeared = -99.;
543     Double_t _masserrwrongvtx = -99.;
544     Double_t _masserrsmearedwrongvtx = -99.;
545     Double_t _ptgg = -99.;
546 bendavid 1.5 Double_t _etagg = -99.;
547     Double_t _phigg = -99.;
548 bendavid 1.4 Double_t _costheta = -99.;
549 bendavid 1.2 PhotonTools::DiphotonR9EtaPtCats _evtcat = PhotonTools::kOctCat0;
550 fabstoec 1.36
551     const Vertex* realVtx = NULL;
552    
553 bendavid 1.2 if (phHard && phSoft) {
554 fabstoec 1.16 _dphiMetgg = MathUtils::DeltaPhi((phHard->Mom()+phSoft->Mom()).Phi(),fPFMet->At(0)->Phi());
555     _cosdphiMetgg = TMath::Cos(_dphiMetgg);
556     _dphiPhPh = MathUtils::DeltaPhi((phHard->Mom()).Phi(),(phSoft->Mom()).Phi());
557 bendavid 1.2 _mass = (phHard->Mom()+phSoft->Mom()).M();
558     _masserr = 0.5*_mass*TMath::Sqrt(phHard->EnergyErr()*phHard->EnergyErr()/phHard->E()/phHard->E() + phSoft->EnergyErr()*phSoft->EnergyErr()/phSoft->E()/phSoft->E());
559     _masserrsmeared = 0.5*_mass*TMath::Sqrt(phHard->EnergyErrSmeared()*phHard->EnergyErrSmeared()/phHard->E()/phHard->E() + phSoft->EnergyErrSmeared()*phSoft->EnergyErrSmeared()/phSoft->E()/phSoft->E());
560     _ptgg = (phHard->Mom()+phSoft->Mom()).Pt();
561 bendavid 1.5 _etagg = (phHard->Mom()+phSoft->Mom()).Eta();
562     _phigg = (phHard->Mom()+phSoft->Mom()).Phi();
563 bendavid 1.2 _costheta = ThreeVector(phHard->Mom()).Unit().Dot(ThreeVector(phSoft->Mom()).Unit());
564     _evtcat = PhotonTools::DiphotonR9EtaPtCat(phHard,phSoft);
565 bendavid 1.4
566 bendavid 1.30 const Double_t dz = sqrt(2.0)*fBeamspotWidth;
567 paus 1.12 Double_t deltamvtx = _mass*VertexTools::DeltaMassVtx(phHard->CaloPos().X(),
568     phHard->CaloPos().Y(),
569     phHard->CaloPos().Z(),
570     phSoft->CaloPos().X(),
571     phSoft->CaloPos().Y(),
572     phSoft->CaloPos().Z(),
573     fDiphotonEvent->vtxX,
574     fDiphotonEvent->vtxY,
575     fDiphotonEvent->vtxZ,
576     dz);
577 bendavid 1.5 fDiphotonEvent->deltamvtx = deltamvtx;
578 fabstoec 1.36
579 paus 1.12 _masserrwrongvtx = TMath::Sqrt(_masserr*_masserr + deltamvtx*deltamvtx);
580 bendavid 1.4 _masserrsmearedwrongvtx = TMath::Sqrt(_masserrsmeared*_masserrsmeared + deltamvtx*deltamvtx);
581 fabstoec 1.36
582    
583    
584     // =================================================================================
585     // this is for synching the Vtx stuff
586     if ( fDoSynching ) {
587     //fill conversion collection for vertex selection, adding single leg conversions if needed
588     //note that momentum of single leg conversions needs to be recomputed from the track
589     //as it is not filled properly
590     DecayParticleOArr vtxconversions;
591     if ( true ) {
592     vtxconversions.SetOwner(kTRUE);
593     for (UInt_t iconv=0; iconv<fConversions->GetEntries(); ++iconv) {
594     DecayParticle *conv = new DecayParticle(*fConversions->At(iconv));
595     vtxconversions.AddOwned(conv);
596     }
597    
598     for (UInt_t iconv=0; iconv<fPFConversions->GetEntries(); ++iconv) {
599     const DecayParticle *c = fPFConversions->At(iconv);
600     if (c->NDaughters()!=1) continue;
601    
602     DecayParticle *conv = new DecayParticle(*c);
603     const Track *trk = static_cast<const StableParticle*>(conv->Daughter(0))->Trk();
604     conv->SetMom(trk->Px(), trk->Py(), trk->Pz(), trk->P());
605     vtxconversions.AddOwned(conv);
606     }
607     }
608     else {
609     for (UInt_t iconv=0; iconv<fConversions->GetEntries(); ++iconv) {
610     const DecayParticle *c = fConversions->At(iconv);
611     vtxconversions.Add(c);
612     }
613     }
614    
615    
616     const BaseVertex *bsp = dynamic_cast<const BaseVertex*>(fBeamspot->At(0));
617     double tmpVtxProb = 0.;
618    
619     std::vector<int> debugInds; // this hold the Vtx indices for the first three guys
620     std::vector<double> debugVals; // this holds hte mva input/output for the best ranked
621     std::vector<int> debugConv; // this holds number of legs for frist and second photon (0 if no conversion) and total number of conversions
622    
623    
624     realVtx = fVtxTools.findVtxBasicRanking(phHard, phSoft, bsp, fPV,
625     &vtxconversions,kTRUE,tmpVtxProb,
626     &debugInds, &debugVals, &debugConv
627     );
628    
629     fDiphotonEvent->vtxInd1 = debugInds[0];
630     fDiphotonEvent->vtxInd2 = debugInds[1];
631     fDiphotonEvent->vtxInd3 = debugInds[2];
632    
633     fDiphotonEvent->vtxConv1Z = debugVals[0];
634     fDiphotonEvent->vtxConv1DZ = debugVals[1];
635     fDiphotonEvent->vtxConv1Prob = debugVals[2];
636    
637     fDiphotonEvent->vtxConv2Z = debugVals[3];
638     fDiphotonEvent->vtxConv2DZ = debugVals[4];
639     fDiphotonEvent->vtxConv2Prob = debugVals[5];
640    
641    
642     fDiphotonEvent->vtxBestPtbal = debugVals[6];
643     fDiphotonEvent->vtxBestPtasym = debugVals[7];
644     fDiphotonEvent->vtxBestSumpt2 = debugVals[8];
645     fDiphotonEvent->vtxBestP2Conv = debugVals[9];
646    
647     fDiphotonEvent->vtxMva1Z = debugVals[10];
648     fDiphotonEvent->vtxMva2Z = debugVals[11];
649     fDiphotonEvent->vtxMva3Z = debugVals[12];
650    
651     fDiphotonEvent->vtxMva1 = debugVals[13];
652     fDiphotonEvent->vtxMva2 = debugVals[14];
653     fDiphotonEvent->vtxMva3 = debugVals[15];
654    
655     fDiphotonEvent->vtxNleg1 = debugConv[0];
656     fDiphotonEvent->vtxNleg2 = debugConv[1];
657     fDiphotonEvent->vtxConvIdx1 = debugConv[2];
658     fDiphotonEvent->vtxConvIdx2 = debugConv[3];
659    
660     fDiphotonEvent->vtxNconv = debugConv[4];
661    
662     if( false ) {
663     printf("---------------------------------------------------------------------\n");
664     printf("FINAL\nvtx %i: ptbal = %5f, ptasym = %5f, logsumpt2 = %5f, limpulltoconv = %5f, nconv = %i, mva = %5f\n",fDiphotonEvent->vtxInd1,fDiphotonEvent->vtxBestPtbal,fDiphotonEvent->vtxBestPtasym,fDiphotonEvent->vtxBestSumpt2,fDiphotonEvent->vtxBestP2Conv,fDiphotonEvent->vtxNconv,fDiphotonEvent->vtxMva1);
665     printf("---------------------------------------------------------------------\n");
666     }
667     }
668    
669    
670     // end of Vtx synching stuff ...
671     // =================================================================================
672    
673    
674    
675 bendavid 1.5 if (jet1 && jet2) {
676     fDiphotonEvent->zeppenfeld = TMath::Abs(_etagg - 0.5*(jet1->Eta()+jet2->Eta()));
677     fDiphotonEvent->dphidijetgg = MathUtils::DeltaPhi( (jet1->Mom()+jet2->Mom()).Phi(), _phigg );
678     }
679 bendavid 1.4
680 bendavid 1.20 PFJetOArr pfjets;
681     for (UInt_t ijet=0; ijet<fPFJets->GetEntries(); ++ijet) {
682     const PFJet *pfjet = dynamic_cast<const PFJet*>(fPFJets->At(ijet));
683     if (pfjet && MathUtils::DeltaR(*pfjet,*phHard)>0.3 && MathUtils::DeltaR(*pfjet,*phSoft)>0.3) pfjets.Add(pfjet);
684     }
685    
686     PFCandidateOArr pfcands;
687     for (UInt_t icand=0; icand<fPFCands->GetEntries(); ++icand) {
688     const PFCandidate *pfcand = fPFCands->At(icand);
689     if (MathUtils::DeltaR(*pfcand,*phHard)>0.1 && MathUtils::DeltaR(*pfcand,*phSoft)>0.1) pfcands.Add(pfcand);
690     }
691    
692     const Vertex *firstvtx = fPV->At(0);
693     const Vertex *selvtx = fPV->At(0);
694    
695     if (!fLoopOnGoodElectrons && phHard->HasPV()) {
696     selvtx = phHard->PV();
697     }
698 fabstoec 1.36
699 bendavid 1.21 if (0) //disable for now for performance reasons
700 fabstoec 1.36 {
701     Met mmet = fMVAMet.GetMet( false,
702     0.,0.,0.,
703     0.,0.,0.,
704     fPFMet->At(0),
705     &pfcands,selvtx,fPV, fPileUpDen->At(0)->Rho(),
706     &pfjets,
707     int(fPV->GetEntries()),
708     kFALSE);
709 bendavid 1.20
710 fabstoec 1.36 TMatrixD *metcov = fMVAMet.GetMetCovariance();
711    
712     ThreeVector fullmet(mmet.Px() - phHard->Px() - phSoft->Px(),
713     mmet.Py() - phHard->Py() - phSoft->Py(),
714     0.);
715    
716     ROOT::Math::SMatrix<double,2,2,ROOT::Math::MatRepSym<double,2> > mcov;
717     mcov(0,0) = (*metcov)(0,0);
718     mcov(0,1) = (*metcov)(0,1);
719     mcov(1,0) = (*metcov)(1,0);
720     mcov(1,1) = (*metcov)(1,1);
721     ROOT::Math::SVector<double,2> vmet;
722     vmet(0) = fullmet.X();
723     vmet(1) = fullmet.Y();
724     mcov.Invert();
725     Double_t metsig = sqrt(ROOT::Math::Similarity(mcov,vmet));
726 bendavid 1.20
727 fabstoec 1.36 fDiphotonEvent->mvametsel = fullmet.Rho();
728     fDiphotonEvent->mvametselphi = fullmet.Phi();
729     fDiphotonEvent->mvametselx = fullmet.X();
730     fDiphotonEvent->mvametsely = fullmet.Y();
731     fDiphotonEvent->mvametselsig = metsig;
732     }
733 bendavid 1.20
734 bendavid 1.21 if (0) //disable for now for performance reasons
735 fabstoec 1.36 {
736     Met mmet = fMVAMet.GetMet( false,
737     0.,0.,0.,
738     0.,0.,0.,
739     fPFMet->At(0),
740     &pfcands,firstvtx,fPV, fPileUpDen->At(0)->Rho(),
741     &pfjets,
742     int(fPV->GetEntries()),
743     kFALSE);
744    
745     TMatrixD *metcov = fMVAMet.GetMetCovariance();
746    
747     ThreeVector fullmet(mmet.Px() - phHard->Px() - phSoft->Px(),
748     mmet.Py() - phHard->Py() - phSoft->Py(),
749     0.);
750    
751     ROOT::Math::SMatrix<double,2,2,ROOT::Math::MatRepSym<double,2> > mcov;
752     mcov(0,0) = (*metcov)(0,0);
753     mcov(0,1) = (*metcov)(0,1);
754     mcov(1,0) = (*metcov)(1,0);
755     mcov(1,1) = (*metcov)(1,1);
756     ROOT::Math::SVector<double,2> vmet;
757     vmet(0) = fullmet.X();
758     vmet(1) = fullmet.Y();
759     mcov.Invert();
760     Double_t metsig = sqrt(ROOT::Math::Similarity(mcov,vmet));
761    
762     fDiphotonEvent->mvametfirst = fullmet.Rho();
763     fDiphotonEvent->mvametfirstphi = fullmet.Phi();
764     fDiphotonEvent->mvametfirstx = fullmet.X();
765     fDiphotonEvent->mvametfirsty = fullmet.Y();
766     fDiphotonEvent->mvametfirstsig = metsig;
767     }
768 bendavid 1.20
769 bendavid 1.2 }
770 fabstoec 1.36
771 mtouch 1.25
772 fabstoec 1.19 fDiphotonEvent->corrpfmet = -99.;
773     fDiphotonEvent->corrpfmetphi = -99.;
774     fDiphotonEvent->corrpfmetx = -99.;
775     fDiphotonEvent->corrpfmety = -99.;
776    
777     Met *corrMet =NULL;
778 bendavid 1.2
779 fabstoec 1.19 if (fApplyPFMetCorrections){
780     corrMet = new Met(fPFMet->At(0)->Px(),fPFMet->At(0)->Py());
781 fabstoec 1.17
782 fabstoec 1.19 if (!fIsData){
783 mtouch 1.25 PFMetCorrectionTools::correctMet(corrMet,phHard,phSoft,1,0,funcorrPFJets,fGenJets,fPFJets,_evt);
784 fabstoec 1.19 PFMetCorrectionTools::shiftMet(corrMet,fIsData,_spfMet);
785     }
786     else {
787     PFMetCorrectionTools::shiftMet(corrMet,fIsData,_spfMet);
788 mtouch 1.25 PFMetCorrectionTools::correctMet(corrMet,phHard,phSoft,0,1,funcorrPFJets,fGenJets,fPFJets,_evt);
789 fabstoec 1.19 }
790    
791     fDiphotonEvent->corrpfmet = corrMet->Pt();
792     fDiphotonEvent->corrpfmetphi = corrMet->Phi();
793     fDiphotonEvent->corrpfmetx = corrMet->Px();
794     fDiphotonEvent->corrpfmety = corrMet->Py();
795 fabstoec 1.17
796 fabstoec 1.19 delete corrMet;
797 fabstoec 1.17 }
798 fabstoec 1.16
799 mtouch 1.25
800 bendavid 1.2 Float_t _massele = -99.;
801     Float_t _ptee = -99.;
802     Float_t _costhetaele = -99.;
803     if (ele1 && ele2) {
804     _massele = (ele1->Mom()+ele2->Mom()).M();
805     _ptee = (ele1->Mom()+ele2->Mom()).Pt();
806     _costhetaele = ThreeVector(ele1->Mom()).Unit().Dot(ThreeVector(ele2->Mom()).Unit());
807 bendavid 1.1 }
808    
809     Float_t _gencostheta = -99.;
810     if (phgen1 && phgen2) {
811     _gencostheta = ThreeVector(phgen1->Mom()).Unit().Dot(ThreeVector(phgen2->Mom()).Unit());
812     }
813    
814     fDiphotonEvent->gencostheta = _gencostheta;
815 fabstoec 1.16 fDiphotonEvent->dphiMetgg = _dphiMetgg;
816     fDiphotonEvent->cosdphiMetgg = _cosdphiMetgg;
817     fDiphotonEvent->dphiPhPh = _dphiPhPh;
818 bendavid 1.1 fDiphotonEvent->mass = _mass;
819 bendavid 1.2 fDiphotonEvent->masserr = _masserr;
820     fDiphotonEvent->masserrsmeared = _masserrsmeared;
821 bendavid 1.4 fDiphotonEvent->masserrwrongvtx = _masserrwrongvtx;
822     fDiphotonEvent->masserrsmearedwrongvtx = _masserrsmearedwrongvtx;
823 bendavid 1.1 fDiphotonEvent->ptgg = _ptgg;
824 bendavid 1.5 fDiphotonEvent->etagg = _etagg;
825     fDiphotonEvent->phigg = _phigg;
826 bendavid 1.2 fDiphotonEvent->costheta = _costheta;;
827     fDiphotonEvent->massele = _massele;
828     fDiphotonEvent->ptee = _ptee;
829     fDiphotonEvent->costhetaele = _costhetaele;
830     fDiphotonEvent->evtcat = _evtcat;
831 bendavid 1.1
832 fabstoec 1.36 fDiphotonEvent->photons[0].SetVars(phHard,conv1,ele1,pfsc1,phgen1,fPhfixph,fPhfixele,fTracks,fPV,fPFCands,rho,fFillClusterArrays,fElectrons,fConversions,bsp,fApplyElectronVeto,realVtx);
833     fDiphotonEvent->photons[1].SetVars(phSoft,conv2,ele2,pfsc2,phgen2,fPhfixph,fPhfixele,fTracks,fPV,fPFCands,rho,fFillClusterArrays,fElectrons,fConversions,bsp,fApplyElectronVeto,realVtx);
834 bendavid 1.1
835     Float_t ph1ecor = fDiphotonEvent->photons[0].Ecor();
836     Float_t ph1ecorerr = fDiphotonEvent->photons[0].Ecorerr();
837     Float_t ph2ecor = fDiphotonEvent->photons[1].Ecor();
838     Float_t ph2ecorerr = fDiphotonEvent->photons[1].Ecorerr();
839 bendavid 1.2
840     Float_t ph1ecorele = fDiphotonEvent->photons[0].Ecorele();
841     Float_t ph1ecoreleerr = fDiphotonEvent->photons[0].Ecoreleerr();
842     Float_t ph2ecorele = fDiphotonEvent->photons[1].Ecorele();
843     Float_t ph2ecoreleerr = fDiphotonEvent->photons[1].Ecoreleerr();
844    
845 bendavid 1.1
846 paus 1.12 fDiphotonEvent->masscor = TMath::Sqrt(2.0*ph1ecor*ph2ecor*(1.0-fDiphotonEvent->costheta));
847     fDiphotonEvent->masscorerr = 0.5*fDiphotonEvent->masscor*
848     TMath::Sqrt(ph1ecorerr*ph1ecorerr/ph1ecor/ph1ecor + ph2ecorerr*ph2ecorerr/ph2ecor/ph2ecor);
849    
850     fDiphotonEvent->masscorele = TMath::Sqrt(2.0*ph1ecorele*ph2ecorele*
851     (1.0-fDiphotonEvent->costheta));
852     fDiphotonEvent->masscoreleerr = 0.5*fDiphotonEvent->masscorele*
853     TMath::Sqrt(ph1ecoreleerr*ph1ecoreleerr/ph1ecorele/ph1ecorele +
854     ph2ecoreleerr*ph2ecoreleerr/ph2ecorele/ph2ecorele);
855 bendavid 1.2
856 paus 1.12 //printf("r9 = %5f, photon sigieie = %5f, seed sigieie = %5f\n",phHard->R9(),
857     // phHard->CoviEtaiEta(),sqrt(phHard->SCluster()->Seed()->CoviEtaiEta()));
858 fabstoec 1.36
859 fabstoec 1.14 // MuonStuff
860     fDiphotonEvent-> muonPt = -99.;
861     fDiphotonEvent-> muonEta = -99.;
862     fDiphotonEvent-> muDR1 = -99.;
863     fDiphotonEvent-> muDR2 = -99.;
864     fDiphotonEvent-> muIso1 = -99.;
865     fDiphotonEvent-> muIso2 = -99.;
866     fDiphotonEvent-> muIso3 = -99.;
867     fDiphotonEvent-> muIso4 = -99.;
868     fDiphotonEvent-> muD0 = -99.;
869     fDiphotonEvent-> muDZ = -99.;
870     fDiphotonEvent-> muChi2 = -99.;
871     fDiphotonEvent-> muNhits = -99;
872     fDiphotonEvent-> muNpixhits = -99;
873     fDiphotonEvent-> muNegs = -99;
874     fDiphotonEvent-> muNMatch = -99;
875    
876     // Electron Stuff
877     fDiphotonEvent-> elePt = -99.;
878     fDiphotonEvent-> eleEta = -99.;
879     fDiphotonEvent-> eleSCEta = -99.;
880     fDiphotonEvent-> eleIso1 = -99.;
881     fDiphotonEvent-> eleIso2 = -99.;
882     fDiphotonEvent-> eleIso3 = -99.;
883     fDiphotonEvent-> eleIso4 = -99.;
884     fDiphotonEvent-> eleDist = -99.;
885     fDiphotonEvent-> eleDcot = -99.;
886     fDiphotonEvent-> eleCoviee = -99.;
887     fDiphotonEvent-> eleDphiin = -99.;
888     fDiphotonEvent-> eleDetain = -99.;
889     fDiphotonEvent-> eleDR1 = -99.;
890     fDiphotonEvent-> eleDR2 = -99.;
891     fDiphotonEvent-> eleMass1 = -99.;
892     fDiphotonEvent-> eleMass2 = -99.;
893     fDiphotonEvent-> eleNinnerHits = -99;
894 mingyang 1.31
895 fabstoec 1.36 fDiphotonEvent-> eleIdMva = -99.;
896    
897 fabstoec 1.13 if( fApplyLeptonTag ) {
898     // perform lepton tagging
899     // the diphoton event record will have one more entry; i.e. leptonTag
900     // leptonTag = -1 -> lepton-taggng was swicthed off
901     // = 0 -> event tagged as 'non-lepton-event'
902     // = +1 -> event tagged as muon-event
903     // = +2 -> event tagged as electron-event
904     fDiphotonEvent->leptonTag = 0;
905 mingyang 1.31
906 fabstoec 1.13 if ( fLeptonTagMuons->GetEntries() > 0 ) {
907 fabstoec 1.28 // need to have dR > 1 for with respect to both photons ***changed to 0.7 for 2012
908 mingyang 1.31 if( (MathUtils::DeltaR(fLeptonTagMuons->At(0),phHard) >= 1.0) &&
909     (MathUtils::DeltaR(fLeptonTagMuons->At(0),phSoft) >= 1.0) &&
910 mingyang 1.35 ((phHard->Pt()/(phHard->Mom() + phSoft->Mom()).M())>(45./120.)) &&
911     ((phSoft->Pt()/(phHard->Mom() + phSoft->Mom()).M())>(30./120.)) ){
912 mingyang 1.31
913 fabstoec 1.13 fDiphotonEvent->leptonTag = 1;
914 fabstoec 1.14
915 mingyang 1.31 fDiphotonEvent-> muonPt = fLeptonTagMuons->At(0)->Pt();
916     fDiphotonEvent-> muonEta = fLeptonTagMuons->At(0)->Eta();
917     fDiphotonEvent-> muDR1 = MathUtils::DeltaR(fLeptonTagMuons->At(0),phHard);
918     fDiphotonEvent-> muDR2 = MathUtils::DeltaR(fLeptonTagMuons->At(0),phSoft);
919    
920     fDiphotonEvent-> muIso1 = (fLeptonTagMuons->At(0)->IsoR03SumPt() + fLeptonTagMuons->At(0)->IsoR03EmEt() + fLeptonTagMuons->At(0)->IsoR03HadEt() - fPileUpDen->At(0)->RhoRandomLowEta() * TMath::Pi() * 0.3 * 0.3)/ fLeptonTagMuons->At(0)->Pt();
921     fDiphotonEvent-> muIso2 = (fLeptonTagMuons->At(0)->IsoR03SumPt() + fLeptonTagMuons->At(0)->IsoR03EmEt() + fLeptonTagMuons->At(0)->IsoR03HadEt() - fPileUpDen->At(0)->RhoRandom() * TMath::Pi() * 0.3 * 0.3)/ fLeptonTagMuons->At(0)->Pt();
922     fDiphotonEvent-> muIso3 = (fLeptonTagMuons->At(0)->IsoR03SumPt() + fLeptonTagMuons->At(0)->IsoR03EmEt() + fLeptonTagMuons->At(0)->IsoR03HadEt() - fPileUpDen->At(0)->RhoLowEta() * TMath::Pi() * 0.3 * 0.3)/ fLeptonTagMuons->At(0)->Pt();
923     fDiphotonEvent-> muIso4 = (fLeptonTagMuons->At(0)->IsoR03SumPt() + fLeptonTagMuons->At(0)->IsoR03EmEt() + fLeptonTagMuons->At(0)->IsoR03HadEt() - fPileUpDen->At(0)->Rho() * TMath::Pi() * 0.3 * 0.3)/ fLeptonTagMuons->At(0)->Pt();
924     fDiphotonEvent-> muD0 = TMath::Abs(fLeptonTagMuons->At(0)->BestTrk()->D0Corrected(*fPV->At(0)));
925     fDiphotonEvent-> muDZ = TMath::Abs(fLeptonTagMuons->At(0)->BestTrk()->DzCorrected(*fPV->At(0)));
926     fDiphotonEvent-> muChi2 = fLeptonTagMuons->At(0)->GlobalTrk()->Chi2()/fLeptonTagMuons->At(0)->GlobalTrk()->Ndof();
927 fabstoec 1.14
928 mingyang 1.31 fDiphotonEvent-> muNhits = fLeptonTagMuons->At(0)->BestTrk()->NHits();
929     fDiphotonEvent-> muNpixhits = fLeptonTagMuons->At(0)->BestTrk()->NPixelHits();
930     fDiphotonEvent-> muNegs = fLeptonTagMuons->At(0)->NSegments();
931     fDiphotonEvent-> muNMatch = fLeptonTagMuons->At(0)->NMatches();
932 fabstoec 1.13 }
933     }
934     if ( fDiphotonEvent->leptonTag < 1 && fLeptonTagElectrons->GetEntries() > 0 ) {
935 mingyang 1.31 if( (MathUtils::DeltaR(fLeptonTagElectrons->At(0),phHard) >= 1) &&
936     (MathUtils::DeltaR(fLeptonTagElectrons->At(0),phSoft) >= 1) &&
937     (PhotonTools::ElectronVetoCiC(phHard,fLeptonTagElectrons) >= 1) &&
938     (PhotonTools::ElectronVetoCiC(phSoft,fLeptonTagElectrons) >= 1) &&
939     (TMath::Abs( (phHard->Mom()+fLeptonTagElectrons->At(0)->Mom()).M()-91.19 ) >= 10) &&
940     (TMath::Abs( (phSoft->Mom()+fLeptonTagElectrons->At(0)->Mom()).M()-91.19 ) >= 10) &&
941 mingyang 1.35 ((phHard->Pt()/(phHard->Mom() + phSoft->Mom()).M())>(45./120.)) &&
942     ((phSoft->Pt()/(phHard->Mom() + phSoft->Mom()).M())>(30./120.)) ){
943 fabstoec 1.13
944     fDiphotonEvent->leptonTag = 2;
945 fabstoec 1.14
946 mingyang 1.31 fDiphotonEvent-> elePt = fLeptonTagElectrons->At(0)->Pt();
947     fDiphotonEvent-> eleEta = fLeptonTagElectrons->At(0)->Eta();
948     fDiphotonEvent-> eleSCEta = fLeptonTagElectrons->At(0)->SCluster()->Eta();
949     fDiphotonEvent-> eleIso1 = (fLeptonTagElectrons->At(0)->TrackIsolationDr03() + fLeptonTagElectrons->At(0)->EcalRecHitIsoDr03() + fLeptonTagElectrons->At(0)->HcalTowerSumEtDr03() - fPileUpDen->At(0)->RhoRandomLowEta() * TMath::Pi() * 0.3 * 0.3)/fDiphotonEvent-> elePt;
950 fabstoec 1.28
951     fDiphotonEvent-> eleIso2 = -99.;
952 fabstoec 1.36
953     if ( fDoSynching ) {
954     Double_t distVtx = 999.0;
955     Int_t closestVtx = 0;
956     for(UInt_t nv=0; nv<fPV->GetEntries(); nv++){
957     double dz = TMath::Abs(fLeptonTagElectrons->At(0)->GsfTrk()->DzCorrected(*fPV->At(nv)));
958     if(dz < distVtx) {
959     distVtx = dz;
960     closestVtx = nv;
961     }
962     }
963     fDiphotonEvent-> eleIdMva = fElectronIDMVA->MVAValue(fLeptonTagElectrons->At(0), fPV->At(closestVtx));
964     }
965    
966 mingyang 1.31 // fDiphotonEvent-> eleIso2 = ElectronTools::ElectronEffectiveArea(ElectronTools::kEleGammaIso03,fLeptonTagElectrons->At(0)->SCluster()->Eta(), ElectronTools::kEleEAData2012) + ElectronTools::ElectronEffectiveArea(ElectronTools::kEleNeutralHadronIso03, fLeptonTagElectrons->At(0)->SCluster()->Eta(), ElectronTools::kEleEAData2012) ;
967 fabstoec 1.28
968 mingyang 1.31 fDiphotonEvent-> eleIso3 = (fLeptonTagElectrons->At(0)->TrackIsolationDr03() + fLeptonTagElectrons->At(0)->EcalRecHitIsoDr03() + fLeptonTagElectrons->At(0)->HcalTowerSumEtDr03() - fPileUpDen->At(0)->RhoLowEta() * TMath::Pi() * 0.3 * 0.3)/fDiphotonEvent-> elePt;
969     fDiphotonEvent-> eleIso4 = (fLeptonTagElectrons->At(0)->TrackIsolationDr03() + fLeptonTagElectrons->At(0)->EcalRecHitIsoDr03() + fLeptonTagElectrons->At(0)->HcalTowerSumEtDr03() - fPileUpDen->At(0)->Rho() * TMath::Pi() * 0.3 * 0.3)/fDiphotonEvent-> elePt;
970     fDiphotonEvent-> eleDist = fLeptonTagElectrons->At(0)->ConvPartnerDist();
971     fDiphotonEvent-> eleDcot = fLeptonTagElectrons->At(0)->ConvPartnerDCotTheta();
972     fDiphotonEvent-> eleCoviee = fLeptonTagElectrons->At(0)->CoviEtaiEta();
973     fDiphotonEvent-> eleDphiin = TMath::Abs(fLeptonTagElectrons->At(0)->DeltaPhiSuperClusterTrackAtVtx());
974     fDiphotonEvent-> eleDetain = TMath::Abs(fLeptonTagElectrons->At(0)->DeltaEtaSuperClusterTrackAtVtx());
975     fDiphotonEvent-> eleDR1 = MathUtils::DeltaR(fLeptonTagElectrons->At(0),phHard);
976     fDiphotonEvent-> eleDR2 = MathUtils::DeltaR(fLeptonTagElectrons->At(0),phSoft);
977     fDiphotonEvent-> eleMass1 = (phHard->Mom()+fLeptonTagElectrons->At(0)->Mom()).M();
978     fDiphotonEvent-> eleMass2 = (phSoft->Mom()+fLeptonTagElectrons->At(0)->Mom()).M();
979     fDiphotonEvent-> eleNinnerHits = fLeptonTagElectrons->At(0)->Trk()->NExpectedHitsInner();
980     }
981     }
982     }
983    
984     //vbf tag
985     fDiphotonEvent->vbfTag = -1;
986     fDiphotonEvent->vbfbdt = -99;
987     if(fApplyVBFTag){
988     fDiphotonEvent->vbfTag = 0;
989     jet1pt_vbf = fDiphotonEvent->jet1pt;
990     jet2pt_vbf = fDiphotonEvent->jet2pt;
991 mingyang 1.34 deltajeteta_vbf = TMath::Abs(fDiphotonEvent->jet1eta - fDiphotonEvent->jet2eta);
992 mingyang 1.31 dijetmass_vbf = fDiphotonEvent->dijetmass;
993 mingyang 1.34 zeppenfeld_vbf = TMath::Abs(fDiphotonEvent->zeppenfeld);
994     dphidijetgg_vbf = TMath::Abs(fDiphotonEvent->dphidijetgg);
995 mingyang 1.31 diphoptOverdiphomass_vbf = fDiphotonEvent->ptgg/fDiphotonEvent->mass;
996     pho1ptOverdiphomass_vbf = phHard->Pt()/fDiphotonEvent->mass;
997     pho2ptOverdiphomass_vbf = phSoft->Pt()/fDiphotonEvent->mass;
998    
999 mingyang 1.35 if(jet1 && jet2 && (pho1ptOverdiphomass_vbf > 40./120.) && (pho2ptOverdiphomass_vbf > 30./120.) && (jet1pt_vbf > 30) && (jet2pt_vbf > 20) && (dijetmass_vbf > 250)){
1000 mingyang 1.31 fDiphotonEvent->vbfbdt = fMVAVBF.GetMVAbdtValue(jet1pt_vbf,jet2pt_vbf,deltajeteta_vbf,dijetmass_vbf,zeppenfeld_vbf,dphidijetgg_vbf,diphoptOverdiphomass_vbf,pho1ptOverdiphomass_vbf,pho2ptOverdiphomass_vbf);
1001    
1002     if((fDiphotonEvent->vbfbdt>=0.985) && (fDiphotonEvent->vbfbdt<=1)){
1003     fDiphotonEvent->vbfTag = 2;
1004     }
1005     if((fDiphotonEvent->vbfbdt>=0.93) && (fDiphotonEvent->vbfbdt<0.985)){
1006     fDiphotonEvent->vbfTag = 1;
1007 fabstoec 1.13 }
1008     }
1009     }
1010 mingyang 1.34 //printf("vbfbdt:%f\n",fDiphotonEvent->vbfbdt);
1011 paus 1.12 if (fWriteDiphotonTree)
1012     hCiCTuple->Fill();
1013 bendavid 1.22
1014     if (fFillVertexTree && phHard && phSoft) {
1015     for (UInt_t ivtx = 0; ivtx<fPV->GetEntries(); ++ivtx) {
1016     const Vertex *v = fPV->At(ivtx);
1017     fDiphotonVtx->SetVars(v,phHard,phSoft,fPFCands,ivtx,fPV->GetEntries(),_decayZ);
1018     hVtxTree->Fill();
1019     }
1020     }
1021    
1022 bendavid 1.1 }
1023    
1024 paus 1.12 if (!fWriteSingleTree)
1025     return;
1026 bendavid 1.1
1027 bendavid 1.2 for (UInt_t iph = 0; iph<egcol->GetEntries(); ++iph) {
1028     const Particle *p = 0;
1029     const Photon *ph = 0;
1030     const Electron *ele = 0;
1031     const SuperCluster *sc = 0;
1032     if (fLoopOnGoodElectrons) {
1033     ele = fGoodElectrons->At(iph);
1034     p = ele;
1035     sc = ele->SCluster();
1036     ph = PhotonTools::MatchedPhoton(ele,fPhotons);
1037     }
1038     else {
1039     ph = fPhotons->At(iph);
1040     p = ph;
1041     sc = ph->SCluster();
1042     ele = PhotonTools::MatchedElectron(ph,fGoodElectrons);
1043     }
1044    
1045 paus 1.12 const DecayParticle *conv = PhotonTools::MatchedConversion(sc,fConversions,bsp,
1046     nhitsbeforevtxmax);
1047 bendavid 1.20 const SuperCluster *pfsc = PhotonTools::MatchedPFSC(sc,fPFPhotons, fElectrons);
1048    
1049 bendavid 1.2 if (!fLoopOnGoodElectrons && ph->HasPV()) {
1050 bendavid 1.1 fDiphotonEvent->vtxZ = ph->PV()->Z();
1051     }
1052    
1053     const MCParticle *phgen = 0;
1054     if( !fIsData ) {
1055 bendavid 1.6 phgen = PhotonTools::MatchMC(p,fMCParticles,!fApplyElectronVeto);
1056 bendavid 1.1 }
1057    
1058 bendavid 1.2 if (fExcludeSinglePrompt && phgen) return;
1059    
1060     fDiphotonEvent->mt = -99.;
1061     fDiphotonEvent->cosphimet = -99.;
1062     fDiphotonEvent->mtele = -99.;
1063     fDiphotonEvent->cosphimetele = -99.;
1064    
1065     if (ph) {
1066     fDiphotonEvent->cosphimet = TMath::Cos(ph->Phi()-fPFMet->At(0)->Phi());
1067 paus 1.12 fDiphotonEvent->mt = TMath::Sqrt(2.0*fPFMet->At(0)->Pt()*ph->Pt()*
1068     (1.0-fDiphotonEvent->cosphimet));
1069 bendavid 1.2 }
1070 bendavid 1.1
1071 bendavid 1.2 if (ele) {
1072     fDiphotonEvent->cosphimetele = TMath::Cos(ele->Phi()-fPFMet->At(0)->Phi());
1073 paus 1.12 fDiphotonEvent->mtele = TMath::Sqrt(2.0*fPFMet->At(0)->Pt()*ele->Pt()*
1074     (1.0-fDiphotonEvent->cosphimetele));
1075 bendavid 1.2 }
1076    
1077 fabstoec 1.24 fSinglePhoton->SetVars(ph,conv,ele,pfsc,phgen,fPhfixph,fPhfixele,fTracks,fPV,fPFCands,rho,fFillClusterArrays,
1078 bendavid 1.30 fElectrons,fConversions,bsp,fApplyElectronVeto);
1079 bendavid 1.1 hCiCTupleSingle->Fill();
1080     }
1081 fabstoec 1.16
1082    
1083    
1084 bendavid 1.1 return;
1085     }
1086    
1087     //--------------------------------------------------------------------------------------------------
1088     void PhotonTreeWriter::SlaveBegin()
1089     {
1090     // Run startup code on the computer (slave) doing the actual analysis. Here,
1091     // we just request the photon collection branch.
1092    
1093 fabstoec 1.13 if( fApplyLeptonTag ) {
1094     ReqEventObject(fLeptonTagElectronsName, fLeptonTagElectrons, false);
1095     ReqEventObject(fLeptonTagMuonsName, fLeptonTagMuons, false);
1096     }
1097    
1098 bendavid 1.30 // ReqEventObject(fPFNoPileUpName, fPFNoPileUpCands, false);
1099     // ReqEventObject(fPFPileUpName, fPFPileUpCands, false);
1100 fabstoec 1.28
1101 paus 1.12 ReqEventObject(fPhotonBranchName,fPhotons, fPhotonsFromBranch);
1102 bendavid 1.20 if (fEnablePFPhotons) ReqEventObject(fPFPhotonName,fPFPhotons, true);
1103 paus 1.12 ReqEventObject(fTrackBranchName, fTracks, true);
1104     ReqEventObject(fElectronName, fElectrons, true);
1105     ReqEventObject(fGoodElectronName,fGoodElectrons,fGoodElectronsFromBranch);
1106     ReqEventObject(fPileUpDenName, fPileUpDen, true);
1107     ReqEventObject(fPVName, fPV, fPVFromBranch);
1108     ReqEventObject(fConversionName, fConversions, true);
1109 fabstoec 1.36 if ( fDoSynching ) ReqEventObject(fPFConversionName, fPFConversions, true);
1110 paus 1.12 ReqEventObject(fBeamspotName, fBeamspot, true);
1111     ReqEventObject(fPFCandName, fPFCands, true);
1112     ReqEventObject(fSuperClusterName,fSuperClusters,true);
1113     ReqEventObject(fPFMetName, fPFMet, true);
1114 fabstoec 1.16 if (fEnableJets){
1115     ReqEventObject(fPFJetName, fPFJets, fPFJetsFromBranch);
1116     ReqBranch(funcorrPFJetName, funcorrPFJets);
1117 fabstoec 1.19 // if (!fIsData) ReqEventObject(fGenJetName, fGenJets, true);
1118 fabstoec 1.16 }
1119 bendavid 1.1 if (!fIsData) {
1120 paus 1.12 ReqBranch(fPileUpName, fPileUp);
1121     ReqBranch(fMCParticleName, fMCParticles);
1122 mingyang 1.33 ReqBranch(fMCEventInfoName, fMCEventInfo);
1123 fabstoec 1.19 if (fEnableJets) ReqEventObject(fGenJetName, fGenJets, true);
1124 bendavid 1.1 }
1125 bendavid 1.6 if (fIsData) {
1126 paus 1.12 fPhFixDataFile = gSystem->Getenv("CMSSW_BASE") +
1127     TString("/src/MitPhysics/data/PhotonFixGRPV22.dat");
1128 bendavid 1.6 }
1129     else {
1130 paus 1.12 fPhFixDataFile = gSystem->Getenv("CMSSW_BASE") +
1131     TString("/src/MitPhysics/data/PhotonFixSTART42V13.dat");
1132 bendavid 1.6 }
1133 bendavid 1.1
1134 bendavid 1.2 fPhfixph.initialise("4_2",std::string(fPhFixDataFile));
1135     fPhfixele.initialise("4_2e",std::string(fPhFixDataFile));
1136    
1137 bendavid 1.20 // fMVAMet.Initialize(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/mva_JetID_lowpt.weights.xml"))),
1138     // TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/mva_JetID_highpt.weights.xml"))),
1139     // TString(getenv("CMSSW_BASE")+string("/src/MitPhysics/Utils/python/JetIdParams_cfi.py")),
1140     // TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/gbrmet_42.root"))),
1141     // TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/gbrmetphi_42.root"))),
1142     // TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/gbrmetu1_42.root"))),
1143     // TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/gbrmetu2_42.root")))
1144     // );
1145    
1146     fMVAMet.Initialize(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/mva_JetID_lowpt.weights.xml"))),
1147     TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/mva_JetID_highpt.weights.xml"))),
1148     TString(getenv("CMSSW_BASE")+string("/src/MitPhysics/Utils/python/JetIdParams_cfi.py")),
1149     TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/gbrmet_52.root"))),
1150     TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/gbrmetphi_52.root"))),
1151     TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/gbrmetu1cov_52.root"))),
1152     TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/gbrmetu2cov_52.root")))
1153     );
1154 bendavid 1.22
1155     fJetId.Initialize(JetIDMVA::kMedium,
1156 bendavid 1.23 TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/mva_JetID_lowpt.weights.xml"))),
1157     TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/mva_JetID_highpt.weights.xml"))),
1158 bendavid 1.22 JetIDMVA::kCut,
1159 bendavid 1.23 TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/Utils/python/JetIdParams_cfi.py")))
1160 mingyang 1.31
1161 bendavid 1.23 );
1162 mingyang 1.31
1163     fMVAVBF.InitializeMVA();
1164 bendavid 1.20
1165 fabstoec 1.36
1166     if( fDoSynching ) {
1167     fVtxTools.InitP(2);
1168     fElectronIDMVA = new ElectronIDMVA();
1169     fElectronIDMVA->Initialize("BDTG method",
1170     fElectronMVAWeights_Subdet0Pt10To20,
1171     fElectronMVAWeights_Subdet1Pt10To20,
1172     fElectronMVAWeights_Subdet2Pt10To20,
1173     fElectronMVAWeights_Subdet0Pt20ToInf,
1174     fElectronMVAWeights_Subdet1Pt20ToInf,
1175     fElectronMVAWeights_Subdet2Pt20ToInf,
1176     ElectronIDMVA::kIDEGamma2012NonTrigV1,
1177     fTheRhoType);
1178     }
1179    
1180    
1181 bendavid 1.1 fDiphotonEvent = new PhotonTreeWriterDiphotonEvent;
1182 bendavid 1.20 fSinglePhoton = new PhotonTreeWriterPhoton<16>;
1183 bendavid 1.1
1184 bendavid 1.20 TFile *ftmp = TFile::Open(TString::Format("%s_tmp.root",GetName()),"RECREATE");
1185    
1186     if (fWriteDiphotonTree) {
1187 paus 1.12 hCiCTuple = new TTree(fTupleName.Data(),fTupleName.Data());
1188 bendavid 1.20 hCiCTuple->SetAutoSave(300e9);
1189     }
1190 bendavid 1.1 TString singlename = fTupleName + TString("Single");
1191 bendavid 1.20 if (fWriteSingleTree) {
1192 paus 1.12 hCiCTupleSingle = new TTree(singlename,singlename);
1193 bendavid 1.20 hCiCTupleSingle->SetAutoSave(300e9);
1194     }
1195    
1196 bendavid 1.1 //make flattish tree from classes so we don't have to rely on dictionaries for reading later
1197     TClass *eclass = TClass::GetClass("mithep::PhotonTreeWriterDiphotonEvent");
1198 bendavid 1.20 TClass *pclass = TClass::GetClass("mithep::PhotonTreeWriterPhoton<16>");
1199 paus 1.12 TList *elist = eclass->GetListOfDataMembers();
1200     TList *plist = pclass->GetListOfDataMembers();
1201 bendavid 1.1
1202     for (int i=0; i<elist->GetEntries(); ++i) {
1203 mingyang 1.26 const TDataMember *tdm = static_cast<const TDataMember*>(elist->At(i));//ming
1204 bendavid 1.20 if (!(tdm->IsBasic() && tdm->IsPersistent())) continue;
1205 bendavid 1.1 TString typestring;
1206 bendavid 1.20 if (TString(tdm->GetTypeName()).BeginsWith("Char_t")) typestring = "B";
1207     else if (TString(tdm->GetTypeName()).BeginsWith("UChar_t")) typestring = "b";
1208     else if (TString(tdm->GetTypeName()).BeginsWith("Short_t")) typestring = "S";
1209     else if (TString(tdm->GetTypeName()).BeginsWith("UShort_t")) typestring = "s";
1210     else if (TString(tdm->GetTypeName()).BeginsWith("Int_t")) typestring = "I";
1211     else if (TString(tdm->GetTypeName()).BeginsWith("UInt_t")) typestring = "i";
1212     else if (TString(tdm->GetTypeName()).BeginsWith("Float_t")) typestring = "F";
1213     else if (TString(tdm->GetTypeName()).BeginsWith("Double_t")) typestring = "D";
1214     else if (TString(tdm->GetTypeName()).BeginsWith("Long64_t")) typestring = "L";
1215     else if (TString(tdm->GetTypeName()).BeginsWith("ULong64_t")) typestring = "l";
1216     else if (TString(tdm->GetTypeName()).BeginsWith("Bool_t")) typestring = "O";
1217     else continue;
1218 bendavid 1.1 //printf("%s %s: %i\n",tdm->GetTypeName(),tdm->GetName(),int(tdm->GetOffset()));
1219 mingyang 1.26 Char_t *addr = (Char_t*)fDiphotonEvent;//ming:?
1220 bendavid 1.1 assert(sizeof(Char_t)==1);
1221 bendavid 1.20 if (fWriteDiphotonTree) hCiCTuple->Branch(tdm->GetName(),addr + tdm->GetOffset(),TString::Format("%s/%s",tdm->GetName(),typestring.Data()));
1222     if (fWriteSingleTree) hCiCTupleSingle->Branch(tdm->GetName(),addr + tdm->GetOffset(),TString::Format("%s/%s",tdm->GetName(),typestring.Data()));
1223 bendavid 1.1 }
1224    
1225     for (int iph=0; iph<2; ++iph) {
1226     for (int i=0; i<plist->GetEntries(); ++i) {
1227     const TDataMember *tdm = static_cast<const TDataMember*>(plist->At(i));
1228 bendavid 1.20 if (!(tdm->IsBasic() && tdm->IsPersistent())) continue;
1229 bendavid 1.1 TString typestring;
1230 bendavid 1.20 if (TString(tdm->GetTypeName()).BeginsWith("Char_t")) typestring = "B";
1231     else if (TString(tdm->GetTypeName()).BeginsWith("UChar_t")) typestring = "b";
1232     else if (TString(tdm->GetTypeName()).BeginsWith("Short_t")) typestring = "S";
1233     else if (TString(tdm->GetTypeName()).BeginsWith("UShort_t")) typestring = "s";
1234     else if (TString(tdm->GetTypeName()).BeginsWith("Int_t")) typestring = "I";
1235     else if (TString(tdm->GetTypeName()).BeginsWith("UInt_t")) typestring = "i";
1236     else if (TString(tdm->GetTypeName()).BeginsWith("Float_t")) typestring = "F";
1237     else if (TString(tdm->GetTypeName()).BeginsWith("Double_t")) typestring = "D";
1238     else if (TString(tdm->GetTypeName()).BeginsWith("Long64_t")) typestring = "L";
1239     else if (TString(tdm->GetTypeName()).BeginsWith("ULong64_t")) typestring = "l";
1240     else if (TString(tdm->GetTypeName()).BeginsWith("Bool_t")) typestring = "O";
1241     else continue;
1242 bendavid 1.1 //printf("%s\n",tdm->GetTypeName());
1243     TString varname = TString::Format("ph%d.%s",iph+1,tdm->GetName());
1244 bendavid 1.20 if (tdm->GetArrayDim()==1) {
1245     varname = TString::Format("%s[%i]",varname.Data(),tdm->GetMaxIndex(0));
1246     }
1247    
1248     //printf("typename = %s, arraydim = %i, arraysize = %i,varname = %s\n", tdm->GetTypeName(), tdm->GetArrayDim(), tdm->GetMaxIndex(0), varname.Data());
1249 bendavid 1.1
1250     Char_t *addr = (Char_t*)&fDiphotonEvent->photons[iph];
1251     assert(sizeof(Char_t)==1);
1252 bendavid 1.20 if (fWriteDiphotonTree) hCiCTuple->Branch(varname,addr+tdm->GetOffset(),TString::Format("%s/%s",varname.Data(),typestring.Data()));
1253 bendavid 1.1
1254     if (iph==0) {
1255     TString singlename = TString::Format("ph.%s",tdm->GetName());
1256 bendavid 1.20 if (tdm->GetArrayDim()==1) {
1257     singlename = TString::Format("%s[%i]",singlename.Data(),tdm->GetMaxIndex(0));
1258     }
1259 bendavid 1.1 Char_t *addrsingle = (Char_t*)fSinglePhoton;
1260 bendavid 1.20 if (fWriteSingleTree) hCiCTupleSingle->Branch(singlename,addrsingle+tdm->GetOffset(),TString::Format("%s/%s",singlename.Data(),typestring.Data()));
1261 bendavid 1.1 }
1262     }
1263     }
1264 paus 1.12
1265     if (fWriteDiphotonTree)
1266     AddOutput(hCiCTuple);
1267     if (fWriteSingleTree)
1268     AddOutput(hCiCTupleSingle);
1269 bendavid 1.22
1270     if (fFillVertexTree) {
1271     fDiphotonVtx = new PhotonTreeWriterVtx;
1272     hVtxTree = new TTree("hVtxTree","hVtxTree");
1273     hVtxTree->SetAutoSave(300e9);
1274     AddOutput(hVtxTree);
1275    
1276     TClass *vclass = TClass::GetClass("mithep::PhotonTreeWriterVtx");
1277     TList *vlist = vclass->GetListOfDataMembers();
1278    
1279     for (int i=0; i<vlist->GetEntries(); ++i) {
1280     const TDataMember *tdm = static_cast<const TDataMember*>(vlist->At(i));
1281     if (!(tdm->IsBasic() && tdm->IsPersistent())) continue;
1282     TString typestring;
1283     if (TString(tdm->GetTypeName()).BeginsWith("Char_t")) typestring = "B";
1284     else if (TString(tdm->GetTypeName()).BeginsWith("UChar_t")) typestring = "b";
1285     else if (TString(tdm->GetTypeName()).BeginsWith("Short_t")) typestring = "S";
1286     else if (TString(tdm->GetTypeName()).BeginsWith("UShort_t")) typestring = "s";
1287     else if (TString(tdm->GetTypeName()).BeginsWith("Int_t")) typestring = "I";
1288     else if (TString(tdm->GetTypeName()).BeginsWith("UInt_t")) typestring = "i";
1289     else if (TString(tdm->GetTypeName()).BeginsWith("Float_t")) typestring = "F";
1290     else if (TString(tdm->GetTypeName()).BeginsWith("Double_t")) typestring = "D";
1291     else if (TString(tdm->GetTypeName()).BeginsWith("Long64_t")) typestring = "L";
1292     else if (TString(tdm->GetTypeName()).BeginsWith("ULong64_t")) typestring = "l";
1293     else if (TString(tdm->GetTypeName()).BeginsWith("Bool_t")) typestring = "O";
1294     else continue;
1295     //printf("%s %s: %i\n",tdm->GetTypeName(),tdm->GetName(),int(tdm->GetOffset()));
1296     Char_t *addr = (Char_t*)fDiphotonVtx;
1297     assert(sizeof(Char_t)==1);
1298     hVtxTree->Branch(tdm->GetName(),addr + tdm->GetOffset(),TString::Format("%s/%s",tdm->GetName(),typestring.Data()));
1299     }
1300     }
1301    
1302 bendavid 1.1 }
1303    
1304     // ----------------------------------------------------------------------------------------
1305     // some helpfer functions....
1306 paus 1.12 void PhotonTreeWriter::FindHiggsPtAndZ(Float_t& pt, Float_t& decayZ, Float_t& mass)
1307     {
1308     pt = -999.;
1309 bendavid 1.1 decayZ = -999.;
1310 paus 1.12 mass = -999.;
1311 bendavid 1.1
1312     // loop over all GEN particles and look for status 1 photons
1313     for(UInt_t i=0; i<fMCParticles->GetEntries(); ++i) {
1314     const MCParticle* p = fMCParticles->At(i);
1315 paus 1.12 if (p->Is(MCParticle::kH) || (!fApplyElectronVeto &&
1316     (p->AbsPdgId()==23 || p->AbsPdgId()==24))) {
1317     pt = p->Pt();
1318 bendavid 1.1 decayZ = p->DecayVertex().Z();
1319 paus 1.12 mass = p->Mass();
1320 bendavid 1.1 break;
1321     }
1322     }
1323    
1324     return;
1325     }
1326    
1327    
1328 paus 1.12 Float_t PhotonTreeWriter::GetEventCat(PhotonTools::CiCBaseLineCats cat1,
1329     PhotonTools::CiCBaseLineCats cat2) {
1330 bendavid 1.1
1331 paus 1.12 bool ph1IsEB = (cat1 == PhotonTools::kCiCCat1 || cat1 == PhotonTools::kCiCCat2);
1332     bool ph2IsEB = (cat2 == PhotonTools::kCiCCat1 || cat2 == PhotonTools::kCiCCat2);
1333 bendavid 1.1
1334     bool ph1IsHR9 = (cat1 == PhotonTools::kCiCCat1 || cat1 == PhotonTools::kCiCCat3);
1335     bool ph2IsHR9 = (cat2 == PhotonTools::kCiCCat1 || cat2 == PhotonTools::kCiCCat3);
1336    
1337     if( ph1IsEB && ph2IsEB )
1338     return ( ph1IsHR9 && ph2IsHR9 ? 0. : 1.);
1339    
1340     return ( ph1IsHR9 && ph2IsHR9 ? 2. : 3.);
1341     }
1342    
1343 bendavid 1.20 template <int NClus>
1344     void PhotonTreeWriterPhoton<NClus>::SetVars(const Photon *p, const DecayParticle *c, const Electron *ele,
1345 fabstoec 1.24 const SuperCluster *pfsc, const MCParticle *m,
1346     PhotonFix &phfixph, PhotonFix &phfixele,
1347     const TrackCol* trackCol,const VertexCol* vtxCol,
1348     const PFCandidateCol* fPFCands,
1349     Double_t rho,
1350     Bool_t fillclusterarrays,
1351 fabstoec 1.36 const ElectronCol* els, const DecayParticleCol *convs, const BaseVertex *bs, Bool_t applyElectronVeto, const Vertex* realVtx) {
1352 paus 1.12
1353     const SuperCluster *s = 0;
1354     if (p)
1355     s = p->SCluster();
1356     else
1357     s = ele->SCluster();
1358     const BasicCluster *b = s->Seed();
1359     const BasicCluster *b2 = 0;
1360     Double_t ebcmax = -99.;
1361     for (UInt_t i=0; i<s->ClusterSize(); ++i) {
1362     const BasicCluster *bc = s->Cluster(i);
1363     if (bc->Energy() > ebcmax && bc !=b) {
1364     b2 = bc;
1365     ebcmax = bc->Energy();
1366     }
1367     }
1368 bendavid 1.2
1369 paus 1.12 const BasicCluster *bclast = 0;
1370     Double_t ebcmin = 1e6;
1371     for (UInt_t i=0; i<s->ClusterSize(); ++i) {
1372     const BasicCluster *bc = s->Cluster(i);
1373     if (bc->Energy() < ebcmin && bc !=b) {
1374     bclast = bc;
1375     ebcmin = bc->Energy();
1376     }
1377     }
1378 bendavid 1.5
1379 paus 1.12 const BasicCluster *bclast2 = 0;
1380     ebcmin = 1e6;
1381     for (UInt_t i=0; i<s->ClusterSize(); ++i) {
1382     const BasicCluster *bc = s->Cluster(i);
1383     if (bc->Energy() < ebcmin && bc !=b && bc!=bclast) {
1384     bclast2 = bc;
1385     ebcmin = bc->Energy();
1386     }
1387     }
1388 bendavid 1.5
1389 paus 1.12 if (p) {
1390     hasphoton = kTRUE;
1391     e = p->E();
1392     pt = p->Pt();
1393     eta = p->Eta();
1394     phi = p->Phi();
1395     r9 = p->R9();
1396     e3x3 = p->E33();
1397     e5x5 = p->E55();
1398     hovere = p->HadOverEm();
1399 bendavid 1.20 hoveretower = p->HadOverEmTow();
1400 paus 1.12 sigietaieta = p->CoviEtaiEta();
1401     phcat = PhotonTools::CiCBaseLineCat(p);
1402     eerr = p->EnergyErr();
1403     eerrsmeared = p->EnergyErrSmeared();
1404     esmearing = p->EnergySmearing();
1405     idmva = p->IdMva();
1406     hcalisodr03 = p->HcalTowerSumEtDr03();
1407     ecalisodr03 = p->EcalRecHitIsoDr03();
1408     trkisohollowdr03 = p->HollowConeTrkIsoDr03();
1409     hcalisodr04 = p->HcalTowerSumEtDr04();
1410     ecalisodr04 = p->EcalRecHitIsoDr04();
1411     trkisohollowdr04 = p->HollowConeTrkIsoDr04();
1412    
1413 bendavid 1.30 passeleveto = PhotonTools::PassElectronVetoConvRecovery(p, els, convs, bs);
1414 paus 1.12
1415     const Vertex *vtx = vtxCol->At(0);
1416 fabstoec 1.36 if (p->HasPV()) vtx = p->PV();
1417     if ( realVtx ) vtx = realVtx;
1418    
1419 paus 1.12 UInt_t wVtxInd = 0;
1420    
1421     trackiso1 = IsolationTools::CiCTrackIsolation(p,vtx, 0.3, 0.02, 0.0, 0.0, 0.1, 1.0,
1422 fabstoec 1.36 trackCol, NULL, NULL,
1423     (!applyElectronVeto ? els : NULL) );
1424     //Question Ming:whyfPV->At(0) instead of selected vertex using ranking method?
1425    
1426 paus 1.12 // track iso worst vtx
1427     trackiso2 = IsolationTools::CiCTrackIsolation(p,vtx, 0.4, 0.02, 0.0, 0.0, 0.1, 1.0,
1428 fabstoec 1.36 trackCol, &wVtxInd,vtxCol,
1429     (!applyElectronVeto ? els : NULL) );
1430 paus 1.12 combiso1 = ecalisodr03+hcalisodr04+trackiso1 - 0.17*rho;
1431 fabstoec 1.24 combiso2 = ecalisodr04+hcalisodr04+trackiso2 - 0.52*rho;
1432 fabstoec 1.36
1433    
1434 fabstoec 1.24 // -----------------------------------------------------
1435     // PF-CiC4 Debug Stuff
1436     std::vector<double> debugVals;
1437     bool tmpPass = PhotonTools::PassCiCPFIsoSelection(p, vtx, fPFCands, vtxCol, rho, 20., &debugVals);
1438     if( debugVals.size() == 13 ) {
1439     pfcic4_tIso1 = debugVals[0];
1440     pfcic4_tIso2 = debugVals[1];
1441     pfcic4_tIso3 = debugVals[2];
1442     pfcic4_covIEtaIEta = debugVals[3];
1443     pfcic4_HoE = debugVals[4];
1444     pfcic4_R9 = debugVals[5];
1445     pfcic4_wVtxInd = debugVals[6];
1446     pfcic4_ecalIso3 = debugVals[7];
1447     pfcic4_ecalIso4 = debugVals[8];
1448     pfcic4_trackIsoSel03 = debugVals[9];
1449     pfcic4_trackIsoWorst04 = debugVals[10];
1450     pfcic4_combIso1 = debugVals[11];
1451     pfcic4_combIso2 = debugVals[12];
1452     }
1453     // -----------------------------------------------------
1454 mingyang 1.26 //id mva
1455     //2011
1456     idmva_tIso1abs=combiso1;
1457     idmva_tIso2abs=combiso2;
1458     idmva_tIso3abs=trackiso1;
1459     idmva_absIsoEcal=ecalisodr03;
1460     idmva_absIsoHcal=hcalisodr04;
1461     //2012
1462     idmva_CoviEtaiPhi=p->SCluster()->Seed()->CoviEtaiPhi();
1463 bendavid 1.27 idmva_s4ratio=p->S4Ratio();
1464 mingyang 1.26 idmva_GammaIso=IsolationTools::PFGammaIsolation(p,0.3,0,fPFCands);
1465     idmva_ChargedIso_selvtx=IsolationTools::PFChargedIsolation(p,vtx,0.3,0.,fPFCands);
1466 fabstoec 1.36 idmva_ChargedIso_0p2_selvtx=IsolationTools::PFChargedIsolation(p,vtx,0.2,0.,fPFCands);
1467 mingyang 1.26 idmva_ChargedIso_worstvtx=IsolationTools::PFChargedIsolation(p,vtx,0.3,0.,fPFCands,&wVtxInd,vtxCol);
1468 bendavid 1.27 idmva_PsEffWidthSigmaRR=p->EffSigmaRR();
1469 paus 1.12 }
1470     else {
1471     hasphoton = kFALSE;
1472     e = -99.;
1473     pt = -99.;
1474     eta = -99.;
1475     phi = -99.;
1476     r9 = b->E3x3()/s->RawEnergy();
1477     e3x3 = b->E3x3();
1478     e5x5 = b->E5x5();
1479     hovere = ele->HadronicOverEm();
1480     sigietaieta = ele->CoviEtaiEta();
1481     phcat = -99;
1482     eerr = -99.;
1483     eerrsmeared = -99.;
1484     esmearing = 0.;
1485     idmva = -99.;
1486     hcalisodr03 = -99;
1487     ecalisodr03 = -99;
1488     trkisohollowdr03 = -99;
1489     hcalisodr04 = -99;
1490     ecalisodr04 = -99;
1491     trkisohollowdr04 = -99;
1492     trackiso1 = -99.;
1493     trackiso2 = -99.;
1494     combiso1 = -99.;
1495     combiso2 = -99.;
1496     }
1497    
1498     sce = s->Energy();
1499     scrawe = s->RawEnergy();
1500     scpse = s->PreshowerEnergy();
1501 bendavid 1.20 scpssigmaxx = s->PsEffWidthSigmaXX();
1502     scpssigmayy = s->PsEffWidthSigmaYY();
1503 paus 1.12 sceta = s->Eta();
1504     scphi = s->Phi();
1505     scnclusters = s->ClusterSize();
1506     scnhits = s->NHits();
1507     scetawidth = -99.;
1508     scphiwidth = -99.;
1509     if (p) {
1510     scetawidth = p->EtaWidth();
1511     scphiwidth = p->PhiWidth();
1512     }
1513     else {
1514     scetawidth = s->EtaWidth();
1515     scphiwidth = s->PhiWidth();
1516     }
1517     isbarrel = (s->AbsEta()<1.5);
1518     isr9reco = (isbarrel && r9>0.94) || (!isbarrel && r9>0.95);
1519     isr9cat = (r9>0.94);
1520    
1521     eseed = b->Energy();
1522     etaseed = b->Eta();
1523     phiseed = b->Phi();
1524     ietaseed = b->IEta();
1525     iphiseed = b->IPhi();
1526     ixseed = b->IX();
1527     iyseed = b->IY();
1528     etacryseed = b->EtaCry();
1529     phicryseed = b->PhiCry();
1530     xcryseed = b->XCry();
1531     ycryseed = b->YCry();
1532     thetaaxisseed = b->ThetaAxis();
1533     phiaxisseed = b->PhiAxis();
1534     sigietaietaseed = TMath::Sqrt(b->CoviEtaiEta());
1535     sigiphiphiseed = TMath::Sqrt(b->CoviPhiiPhi());
1536     if (isnan(sigiphiphiseed)) sigiphiphiseed = -99.;
1537     covietaiphiseed = b->CoviEtaiPhi();
1538     if (isnan(covietaiphiseed)) covietaiphiseed = -99.;
1539     e3x3seed = b->E3x3();
1540     e5x5seed = b->E5x5();
1541     emaxseed = b->EMax();
1542     e2ndseed = b->E2nd();
1543     etopseed = b->ETop();
1544     ebottomseed = b->EBottom();
1545     eleftseed = b->ELeft();
1546     erightseed = b->ERight();
1547     e1x3seed = b->E1x3();
1548     e3x1seed = b->E3x1();
1549     e1x5seed = b->E1x5();
1550     e2x2seed = b->E2x2();
1551     e4x4seed = b->E4x4();
1552     e2x5maxseed = b->E2x5Max();
1553     e2x5topseed = b->E2x5Top();
1554     e2x5bottomseed = b->E2x5Bottom();
1555     e2x5leftseed = b->E2x5Left();
1556     e2x5rightseed = b->E2x5Right();
1557     xseedseed = b->Pos().X();
1558     yseedseed = b->Pos().Y();
1559     zseedseed = b->Pos().Z();
1560     nhitsseed = b->NHits();
1561    
1562     if (b2) {
1563     ebc2 = b2->Energy();
1564     etabc2 = b2->Eta();
1565     phibc2 = b2->Phi();
1566     ietabc2 = b2->IEta();
1567     iphibc2 = b2->IPhi();
1568     ixbc2 = b2->IX();
1569     iybc2 = b2->IY();
1570     etacrybc2 = b2->EtaCry();
1571     phicrybc2 = b2->PhiCry();
1572     xcrybc2 = b2->XCry();
1573     ycrybc2 = b2->YCry();
1574     thetaaxisbc2 = b2->ThetaAxis();
1575     phiaxisbc2 = b2->PhiAxis();
1576     sigietaietabc2 = TMath::Sqrt(b2->CoviEtaiEta());
1577     sigiphiphibc2 = TMath::Sqrt(b2->CoviPhiiPhi());
1578     if (isnan(sigiphiphibc2)) sigiphiphibc2 = -99.;
1579     covietaiphibc2 = b2->CoviEtaiPhi();
1580     if (isnan(covietaiphibc2)) covietaiphibc2 = -99.;
1581     e3x3bc2 = b2->E3x3();
1582     e5x5bc2 = b2->E5x5();
1583     emaxbc2 = b2->EMax();
1584     e2ndbc2 = b2->E2nd();
1585     etopbc2 = b2->ETop();
1586     ebottombc2 = b2->EBottom();
1587     eleftbc2 = b2->ELeft();
1588     erightbc2 = b2->ERight();
1589     e1x3bc2 = b2->E1x3();
1590     e3x1bc2 = b2->E3x1();
1591     e1x5bc2 = b2->E1x5();
1592     e2x2bc2 = b2->E2x2();
1593     e4x4bc2 = b2->E4x4();
1594     e2x5maxbc2 = b2->E2x5Max();
1595     e2x5topbc2 = b2->E2x5Top();
1596     e2x5bottombc2 = b2->E2x5Bottom();
1597     e2x5leftbc2 = b2->E2x5Left();
1598     e2x5rightbc2 = b2->E2x5Right();
1599     xbc2bc2 = b2->Pos().X();
1600     ybc2bc2 = b2->Pos().Y();
1601     zbc2bc2 = b2->Pos().Z();
1602     nhitsbc2= b2->NHits();
1603     }
1604     else {
1605     ebc2 = 0;
1606     etabc2 = 0;
1607     phibc2 = 0;
1608     ietabc2 = 0;
1609     iphibc2 = 0;
1610     ixbc2 = 0;
1611     iybc2 = 0;
1612     etacrybc2 = 0;
1613     phicrybc2 = 0;
1614     xcrybc2 = 0;
1615     ycrybc2 = 0;
1616     thetaaxisbc2 = 0;
1617     phiaxisbc2 = 0;
1618     sigietaietabc2 = 0;
1619     sigiphiphibc2 = 0;
1620     covietaiphibc2 = 0;
1621     e3x3bc2 = 0;
1622     e5x5bc2 = 0;
1623     emaxbc2 = 0;
1624     e2ndbc2 = 0;
1625     etopbc2 = 0;
1626     ebottombc2 = 0;
1627     eleftbc2 = 0;
1628     erightbc2 = 0;
1629     e1x3bc2 = 0;
1630     e3x1bc2 = 0;
1631     e1x5bc2 = 0;
1632     e2x2bc2 = 0;
1633     e4x4bc2 = 0;
1634     e2x5maxbc2 = 0;
1635     e2x5topbc2 = 0;
1636     e2x5bottombc2 = 0;
1637     e2x5leftbc2 = 0;
1638     e2x5rightbc2 = 0;
1639     xbc2bc2 = 0;
1640     ybc2bc2 = 0;
1641     zbc2bc2 = 0;
1642     nhitsbc2 = 0;
1643     }
1644 bendavid 1.5
1645 paus 1.12 if (bclast) {
1646     ebclast = bclast->Energy();
1647     etabclast = bclast->Eta();
1648     phibclast = bclast->Phi();
1649     ietabclast = bclast->IEta();
1650     iphibclast = bclast->IPhi();
1651     ixbclast = bclast->IX();
1652     iybclast = bclast->IY();
1653     etacrybclast = bclast->EtaCry();
1654     phicrybclast = bclast->PhiCry();
1655     xcrybclast = bclast->XCry();
1656     ycrybclast = bclast->YCry();
1657     thetaaxisbclast = bclast->ThetaAxis();
1658     phiaxisbclast = bclast->PhiAxis();
1659     sigietaietabclast = TMath::Sqrt(bclast->CoviEtaiEta());
1660     sigiphiphibclast = TMath::Sqrt(bclast->CoviPhiiPhi());
1661     if (isnan(sigiphiphibclast)) sigiphiphibclast = -99.;
1662     covietaiphibclast = bclast->CoviEtaiPhi();
1663     if (isnan(covietaiphibclast)) covietaiphibclast = -99.;
1664     e3x3bclast = bclast->E3x3();
1665     nhitsbclast = bclast->NHits();
1666     }
1667     else {
1668     ebclast = 0;
1669     etabclast = 0;
1670     phibclast = 0;
1671     ietabclast = 0;
1672     iphibclast = 0;
1673     ixbclast = 0;
1674     iybclast = 0;
1675     etacrybclast = 0;
1676     phicrybclast = 0;
1677     xcrybclast = 0;
1678     ycrybclast = 0;
1679     thetaaxisbclast = 0;
1680     phiaxisbclast = 0;
1681     sigietaietabclast = 0;
1682     sigiphiphibclast = 0;
1683     covietaiphibclast = 0;
1684     e3x3bclast = 0;
1685     nhitsbclast = 0;
1686     }
1687 bendavid 1.5
1688 paus 1.12 if (bclast2) {
1689     ebclast2 = bclast2->Energy();
1690     etabclast2 = bclast2->Eta();
1691     phibclast2 = bclast2->Phi();
1692     ietabclast2 = bclast2->IEta();
1693     iphibclast2 = bclast2->IPhi();
1694     ixbclast2 = bclast2->IX();
1695     iybclast2 = bclast2->IY();
1696     etacrybclast2 = bclast2->EtaCry();
1697     phicrybclast2 = bclast2->PhiCry();
1698     xcrybclast2 = bclast2->XCry();
1699     ycrybclast2 = bclast2->YCry();
1700     thetaaxisbclast2 = bclast2->ThetaAxis();
1701     phiaxisbclast2 = bclast2->PhiAxis();
1702     sigietaietabclast2 = TMath::Sqrt(bclast2->CoviEtaiEta());
1703     sigiphiphibclast2 = TMath::Sqrt(bclast2->CoviPhiiPhi());
1704     if (isnan(sigiphiphibclast2)) sigiphiphibclast2 = -99.;
1705     covietaiphibclast2 = bclast2->CoviEtaiPhi();
1706     if (isnan(covietaiphibclast2)) covietaiphibclast2 = -99.;
1707     e3x3bclast2 = bclast2->E3x3();
1708     nhitsbclast2 = bclast2->NHits();
1709     }
1710     else {
1711     ebclast2 = 0;
1712     etabclast2 = 0;
1713     phibclast2 = 0;
1714     ietabclast2 = 0;
1715     iphibclast2 = 0;
1716     ixbclast2 = 0;
1717     iybclast2 = 0;
1718     etacrybclast2 = 0;
1719     phicrybclast2 = 0;
1720     xcrybclast2 = 0;
1721     ycrybclast2 = 0;
1722     thetaaxisbclast2 = 0;
1723     phiaxisbclast2 = 0;
1724     sigietaietabclast2 = 0;
1725     sigiphiphibclast2 = 0;
1726     covietaiphibclast2 = 0;
1727     e3x3bclast2 = 0;
1728     nhitsbclast2 = 0;
1729     }
1730 bendavid 1.5
1731 bendavid 1.20 for (UInt_t iclus=0; iclus<NClus; ++iclus) {
1732     if (fillclusterarrays && iclus < s->ClusterSize() ) {
1733     const BasicCluster *ib =s->Cluster(iclus);
1734    
1735     ebcs[iclus] = ib->Energy();
1736     etabcs[iclus] = ib->Eta();
1737     phibcs[iclus] = ib->Phi();
1738     ietabcs[iclus] = ib->IEta();
1739     iphibcs[iclus] = ib->IPhi();
1740     ixbcs[iclus] = ib->IX();
1741     iybcs[iclus] = ib->IY();
1742     etacrybcs[iclus] = ib->EtaCry();
1743     phicrybcs[iclus] = ib->PhiCry();
1744     xcrybcs[iclus] = ib->XCry();
1745     ycrybcs[iclus] = ib->YCry();
1746     sigietaietabcs[iclus] = TMath::Sqrt(ib->CoviEtaiEta());
1747     sigiphiphibcs[iclus] = TMath::Sqrt(ib->CoviPhiiPhi());
1748     covietaiphibcs[iclus] = ib->CoviEtaiPhi();
1749     sigetaetabcs[iclus] = TMath::Sqrt(ib->CovEtaEta());
1750     sigphiphibcs[iclus] = TMath::Sqrt(ib->CovPhiPhi());
1751     covetaphibcs[iclus] = ib->CovEtaPhi();
1752     e3x3bcs[iclus] = ib->E3x3();
1753     e5x5bcs[iclus] = ib->E5x5();
1754     emaxbcs[iclus] = ib->EMax();
1755     e2ndbcs[iclus] = ib->E2nd();
1756     etopbcs[iclus] = ib->ETop();
1757     ebottombcs[iclus] = ib->EBottom();
1758     eleftbcs[iclus] = ib->ELeft();
1759     erightbcs[iclus] = ib->ERight();
1760     e1x3bcs[iclus] = ib->E1x3();
1761     e3x1bcs[iclus] = ib->E3x1();
1762     e1x5bcs[iclus] = ib->E1x5();
1763     e2x2bcs[iclus] = ib->E2x2();
1764     e4x4bcs[iclus] = ib->E4x4();
1765     e2x5maxbcs[iclus] = ib->E2x5Max();
1766     e2x5topbcs[iclus] = ib->E2x5Top();
1767     e2x5bottombcs[iclus] = ib->E2x5Bottom();
1768     e2x5leftbcs[iclus] = ib->E2x5Left();
1769     e2x5rightbcs[iclus] = ib->E2x5Right();
1770     nhitsbcs[iclus]= ib->NHits();
1771     }
1772     else {
1773     ebcs[iclus] = -999;
1774     etabcs[iclus] = -999;
1775     phibcs[iclus] = -999;
1776     ietabcs[iclus] = -999;
1777     iphibcs[iclus] = -999;
1778     ixbcs[iclus] = -999;
1779     iybcs[iclus] = -999;
1780     etacrybcs[iclus] = -999;
1781     phicrybcs[iclus] = -999;
1782     xcrybcs[iclus] = -999;
1783     ycrybcs[iclus] = -999;
1784     sigietaietabcs[iclus] = -999;
1785     sigiphiphibcs[iclus] = -999;
1786     covietaiphibcs[iclus] = -999;
1787     sigetaetabcs[iclus] = -999;
1788     sigphiphibcs[iclus] = -999;
1789     covetaphibcs[iclus] = -999;
1790     e3x3bcs[iclus] = -999;
1791     e5x5bcs[iclus] = -999;
1792     emaxbcs[iclus] = -999;
1793     e2ndbcs[iclus] = -999;
1794     etopbcs[iclus] = -999;
1795     ebottombcs[iclus] = -999;
1796     eleftbcs[iclus] = -999;
1797     erightbcs[iclus] = -999;
1798     e1x3bcs[iclus] = -999;
1799     e3x1bcs[iclus] = -999;
1800     e1x5bcs[iclus] = -999;
1801     e2x2bcs[iclus] = -999;
1802     e4x4bcs[iclus] = -999;
1803     e2x5maxbcs[iclus] = -999;
1804     e2x5topbcs[iclus] = -999;
1805     e2x5bottombcs[iclus] = -999;
1806     e2x5leftbcs[iclus] = -999;
1807     e2x5rightbcs[iclus] = -999;
1808     nhitsbcs[iclus] = -999;
1809     }
1810     }
1811    
1812     for (UInt_t iclus=0; iclus<NClus; ++iclus) {
1813     if (fillclusterarrays && pfsc && iclus < pfsc->ClusterSize() ) {
1814     const BasicCluster *ib =pfsc->Cluster(iclus);
1815    
1816     epfbcs[iclus] = ib->Energy();
1817     etapfbcs[iclus] = ib->Eta();
1818     phipfbcs[iclus] = ib->Phi();
1819     ietapfbcs[iclus] = ib->IEta();
1820     iphipfbcs[iclus] = ib->IPhi();
1821     ixpfbcs[iclus] = ib->IX();
1822     iypfbcs[iclus] = ib->IY();
1823     etacrypfbcs[iclus] = ib->EtaCry();
1824     phicrypfbcs[iclus] = ib->PhiCry();
1825     xcrypfbcs[iclus] = ib->XCry();
1826     ycrypfbcs[iclus] = ib->YCry();
1827     sigietaietapfbcs[iclus] = TMath::Sqrt(ib->CoviEtaiEta());
1828     sigiphiphipfbcs[iclus] = TMath::Sqrt(ib->CoviPhiiPhi());
1829     covietaiphipfbcs[iclus] = ib->CoviEtaiPhi();
1830     sigetaetapfbcs[iclus] = TMath::Sqrt(ib->CovEtaEta());
1831     sigphiphipfbcs[iclus] = TMath::Sqrt(ib->CovPhiPhi());
1832     covetaphipfbcs[iclus] = ib->CovEtaPhi();
1833     e3x3pfbcs[iclus] = ib->E3x3();
1834     e5x5pfbcs[iclus] = ib->E5x5();
1835     emaxpfbcs[iclus] = ib->EMax();
1836     e2ndpfbcs[iclus] = ib->E2nd();
1837     etoppfbcs[iclus] = ib->ETop();
1838     ebottompfbcs[iclus] = ib->EBottom();
1839     eleftpfbcs[iclus] = ib->ELeft();
1840     erightpfbcs[iclus] = ib->ERight();
1841     e1x3pfbcs[iclus] = ib->E1x3();
1842     e3x1pfbcs[iclus] = ib->E3x1();
1843     e1x5pfbcs[iclus] = ib->E1x5();
1844     e2x2pfbcs[iclus] = ib->E2x2();
1845     e4x4pfbcs[iclus] = ib->E4x4();
1846     e2x5maxpfbcs[iclus] = ib->E2x5Max();
1847     e2x5toppfbcs[iclus] = ib->E2x5Top();
1848     e2x5bottompfbcs[iclus] = ib->E2x5Bottom();
1849     e2x5leftpfbcs[iclus] = ib->E2x5Left();
1850     e2x5rightpfbcs[iclus] = ib->E2x5Right();
1851     nhitspfbcs[iclus]= ib->NHits();
1852     }
1853     else {
1854     epfbcs[iclus] = -999;
1855     etapfbcs[iclus] = -999;
1856     phipfbcs[iclus] = -999;
1857     ietapfbcs[iclus] = -999;
1858     iphipfbcs[iclus] = -999;
1859     ixpfbcs[iclus] = -999;
1860     iypfbcs[iclus] = -999;
1861     etacrypfbcs[iclus] = -999;
1862     phicrypfbcs[iclus] = -999;
1863     xcrypfbcs[iclus] = -999;
1864     ycrypfbcs[iclus] = -999;
1865     sigietaietapfbcs[iclus] = -999;
1866     sigiphiphipfbcs[iclus] = -999;
1867     covietaiphipfbcs[iclus] = -999;
1868     sigetaetapfbcs[iclus] = -999;
1869     sigphiphipfbcs[iclus] = -999;
1870     covetaphipfbcs[iclus] = -999;
1871     e3x3pfbcs[iclus] = -999;
1872     e5x5pfbcs[iclus] = -999;
1873     emaxpfbcs[iclus] = -999;
1874     e2ndpfbcs[iclus] = -999;
1875     etoppfbcs[iclus] = -999;
1876     ebottompfbcs[iclus] = -999;
1877     eleftpfbcs[iclus] = -999;
1878     erightpfbcs[iclus] = -999;
1879     e1x3pfbcs[iclus] = -999;
1880     e3x1pfbcs[iclus] = -999;
1881     e1x5pfbcs[iclus] = -999;
1882     e2x2pfbcs[iclus] = -999;
1883     e4x4pfbcs[iclus] = -999;
1884     e2x5maxpfbcs[iclus] = -999;
1885     e2x5toppfbcs[iclus] = -999;
1886     e2x5bottompfbcs[iclus] = -999;
1887     e2x5leftpfbcs[iclus] = -999;
1888     e2x5rightpfbcs[iclus] = -999;
1889     nhitspfbcs[iclus] = -999;
1890     }
1891     }
1892    
1893     for (UInt_t iclus=0; iclus<100; ++iclus) {
1894     if (fillclusterarrays && pfsc && iclus < pfsc->NPsClusts() ) {
1895     const PsCluster *ib = pfsc->PsClust(iclus);
1896    
1897     epsc[iclus] = ib->Energy();
1898     etapsc[iclus] = ib->Eta();
1899     phipsc[iclus] = ib->Phi();
1900     planepsc[iclus] = ib->PsPlane();
1901     }
1902     else {
1903     epsc[iclus] = -999;
1904     etapsc[iclus] = -999;
1905     phipsc[iclus] = -999;
1906     planepsc[iclus] = 0;
1907     }
1908     }
1909    
1910 paus 1.12 //initialize photon energy corrections if needed
1911     /*if (!PhotonFix::initialised()) {
1912     PhotonFix::initialise("4_2",std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/PhotonFix.dat")).Data()));
1913     }*/
1914    
1915     phfixph.setup(e,sceta,scphi,r9);
1916     phfixele.setup(e,sceta,scphi,r9);
1917    
1918     const Float_t dval = -99.;
1919     ecor = phfixph.fixedEnergy();
1920     ecorerr = phfixph.sigmaEnergy();
1921     ecorele = phfixele.fixedEnergy();
1922     ecoreleerr = phfixele.sigmaEnergy();
1923     if (phfixph.isbarrel()) {
1924     etac = phfixph.etaC();
1925     etas = phfixph.etaS();
1926     etam = phfixph.etaM();
1927     phic = phfixph.phiC();
1928     phis = phfixph.phiS();
1929     phim = phfixph.phiM();
1930     xz = dval;
1931     xc = dval;
1932     xs = dval;
1933     xm = dval;
1934     yz = dval;
1935     yc = dval;
1936     ys = dval;
1937     ym = dval;
1938     }
1939     else {
1940     etac = dval;
1941     etas = dval;
1942     etam = dval;
1943     phic = dval;
1944     phis = dval;
1945     phim = dval;
1946     xz = phfixph.xZ();
1947     xc = phfixph.xC();
1948     xs = phfixph.xS();
1949     xm = phfixph.xM();
1950     yz = phfixph.yZ();
1951     yc = phfixph.yC();
1952     ys = phfixph.yS();
1953     ym = phfixph.yM();
1954     }
1955    
1956     if (c) {
1957     hasconversion = kTRUE;
1958     convp = c->P();
1959     convpt = c->Pt();
1960     conveta = c->Eta();
1961     convphi = c->Phi();
1962     ThreeVector dirconvsc = ThreeVector(s->Point()) - c->Position();
1963     convdeta = c->Eta() - dirconvsc.Eta();
1964     convdphi = MathUtils::DeltaPhi(c->Phi(),dirconvsc.Phi());
1965     convvtxrho = c->Position().Rho();
1966     convvtxz = c->Position().Z();
1967     convvtxphi = c->Position().Phi();
1968    
1969     const StableData *leadsd = dynamic_cast<const StableData*>(c->DaughterDat(0));
1970     const StableData *trailsd = dynamic_cast<const StableData*>(c->DaughterDat(1));
1971     if (leadsd->Pt()<trailsd->Pt()) {
1972     const StableData *sdtmp = leadsd;
1973     leadsd = trailsd;
1974     trailsd = sdtmp;
1975     }
1976    
1977     const Track *leadtrack = dynamic_cast<const StableParticle*>(leadsd->Original())->Trk();
1978     const Track *trailtrack = dynamic_cast<const StableParticle*>(trailsd->Original())->Trk();
1979    
1980     convleadpt = leadsd->Pt();
1981     convtrailpt = trailsd->Pt();
1982     convleadtrackpt = leadtrack->Pt();
1983     convleadtrackalgo = leadtrack->Algo();
1984     if (convleadtrackalgo==29) convleadtrackalgos=2; //gsf track
1985     else if (convleadtrackalgo==15 ||convleadtrackalgo==16) convleadtrackalgos=1; //ecal-seeded track
1986     else convleadtrackalgos = 0; //std iterative track
1987     convleadtrackcharge = leadtrack->Charge();
1988     convtrailtrackpt = trailtrack->Pt();
1989     convtrailtrackalgo = trailtrack->Algo();
1990     if (convtrailtrackalgo==29) convtrailtrackalgos=2; //gsf track
1991     else if (convtrailtrackalgo==15 ||convtrailtrackalgo==16) convtrailtrackalgos=1; //ecal-seeded track
1992     else convtrailtrackalgos = 0; //std iterative track
1993     trailtrackcharge = trailtrack->Charge();
1994     }
1995     else {
1996     hasconversion = kFALSE;
1997     convp = -99.;
1998     convpt = -99.;
1999     conveta = -99.;
2000     convphi = -99.;
2001     convdeta = -99.;
2002     convdphi = -99.;
2003     convvtxrho = -99.;
2004     convvtxz = -999.;
2005     convvtxphi = -99.;
2006     convleadpt = -99.;
2007     convtrailpt = -99.;
2008     convleadtrackpt = -99.;
2009     convleadtrackalgo = -99;
2010     convleadtrackalgos = -99;
2011     convleadtrackcharge = 0;
2012     convtrailtrackpt = -99.;
2013     convtrailtrackalgo = -99;
2014     convtrailtrackalgos = -99;
2015     trailtrackcharge = 0;
2016     }
2017    
2018     //electron quantities
2019     if (ele) {
2020     haselectron = kTRUE;
2021     eleisecaldriven = ele->IsEcalDriven();
2022     eleistrackerdriven = ele->IsTrackerDriven();
2023     elee = ele->E();
2024     elept = ele->Pt();
2025     eleeta = ele->Eta();
2026     elephi = ele->Phi();
2027     elecharge = ele->Charge();
2028     elefbrem = ele->FBrem();
2029     eledeta = ele->DeltaEtaSuperClusterTrackAtVtx();
2030     eledphi = ele->DeltaPhiSuperClusterTrackAtVtx();
2031     elep = s->Energy()/ele->ESuperClusterOverP();
2032     elepin = ele->PIn();
2033     elepout = ele->POut();
2034     }
2035     else {
2036     haselectron = kFALSE;
2037     eleisecaldriven = kFALSE;
2038     eleistrackerdriven = kFALSE;
2039     elee = -99.;
2040     elept = -99.;
2041     eleeta = -99.;
2042     elephi = -99.;
2043     elecharge = -99;
2044     elefbrem = -99.;
2045     eledeta = -99.;
2046     eledphi = -99.;
2047     elep = -99.;
2048     elepin = -99.;
2049     elepout = -99.;
2050     }
2051    
2052     //pf supercluster quantities
2053     if (pfsc) {
2054     haspfsc = kTRUE;
2055     pfsce = pfsc->Energy();
2056     pfscrawe = pfsc->RawEnergy();
2057     pfsceta = pfsc->Eta();
2058     pfscphi = pfsc->Phi();
2059 bendavid 1.20 pfscnclusters = pfsc->NClusters();
2060     pfscnhits = pfsc->NHits();
2061     pfscetawidth = pfsc->EtaWidth();
2062     pfscphiwidth = pfsc->PhiWidth();
2063     pfscnpsclusters = pfsc->NPsClusts();
2064 paus 1.12 }
2065     else {
2066     haspfsc = kFALSE;
2067     pfsce = -99.;
2068     pfscrawe = -99.;
2069     pfsceta = -99.;
2070     pfscphi = -99.;
2071 bendavid 1.20 pfscnclusters = 0;
2072     pfscnhits = 0;
2073     pfscetawidth = -99.;
2074     pfscphiwidth = -99.;
2075     pfscnpsclusters = 0;
2076 paus 1.12 }
2077    
2078     genz = -99.;
2079     if (m) {
2080     ispromptgen = kTRUE;
2081     gene = m->E();
2082     genpt = m->Pt();
2083     geneta = m->Eta();
2084     genphi = m->Phi();
2085     const MCParticle *mm = m->DistinctMother();
2086     if (mm) genz = mm->DecayVertex().Z();
2087     pdgid = m->PdgId();
2088     if (mm) motherpdgid = mm->PdgId();
2089     else motherpdgid = -99;
2090     }
2091     else {
2092     ispromptgen = kFALSE;
2093     gene = -99.;
2094     genpt = -99.;
2095     geneta = -99.;
2096     genphi = -99.;
2097     pdgid = -99;
2098     motherpdgid = -99;
2099     }
2100 bendavid 1.1 }
2101 bendavid 1.22
2102     void PhotonTreeWriterVtx::SetVars(const Vertex *v, const Photon *p1, const Photon *p2, const PFCandidateCol *pfcands, Int_t idx, Int_t numvtx, Float_t genvtxz)
2103     {
2104    
2105     //printf("start\n");
2106    
2107     n = idx;
2108     nvtx = numvtx;
2109     zgen = genvtxz;
2110    
2111     x = v->X();
2112     y = v->Y();
2113     z = v->Z();
2114    
2115     Double_t dsumpt = 0.;
2116     Double_t dsumptsq = 0.;
2117    
2118     nchalltoward = 0;
2119     nchalltransverse = 0;
2120     nchallaway = 0;
2121     nchcuttoward = 0;
2122     nchcuttransverse = 0;
2123     nchcutaway = 0;
2124    
2125     ThreeVector vtxmom;
2126    
2127     //printf("mom\n");
2128     FourVectorM diphoton = p1->MomVtx(v->Position()) + p2->MomVtx(v->Position());
2129     //printf("done mom\n");
2130     ptgg = diphoton.Pt();
2131     phigg = diphoton.Phi();
2132     etagg = diphoton.Eta();
2133     mgg = diphoton.M();
2134     pxgg = diphoton.Px();
2135     pygg = diphoton.Py();
2136     pzgg = diphoton.Pz();
2137    
2138     //printf("loop\n");
2139    
2140     for (UInt_t i = 0; i<pfcands->GetEntries(); ++i) {
2141     const PFCandidate *pfc = pfcands->At(i);
2142     if (pfc->PFType()!=PFCandidate::eHadron || !pfc->HasTrackerTrk()) continue;
2143     if (TMath::Abs( pfc->TrackerTrk()->DzCorrected(*v) ) > 0.2) continue;
2144     if (TMath::Abs( pfc->TrackerTrk()->D0Corrected(*v) ) > 0.1) continue;
2145    
2146     vtxmom += ThreeVector(pfc->Px(),pfc->Py(),pfc->Pz());
2147    
2148     dsumpt += pfc->Pt();
2149     dsumptsq += pfc->Pt()*pfc->Pt();
2150    
2151     Double_t dphi = TMath::Abs(MathUtils::DeltaPhi(*pfc,diphoton));
2152     if (dphi<(TMath::Pi()/3.0)) {
2153     ++nchalltoward;
2154     if (pfc->Pt()>0.5) ++nchcuttoward;
2155     }
2156     else if (dphi>(2.0*TMath::Pi()/3.0)) {
2157     ++nchallaway;
2158     if (pfc->Pt()>0.5) ++nchcutaway;
2159     }
2160     else {
2161     ++nchalltransverse;
2162     if (pfc->Pt()>0.5) ++nchcuttransverse;
2163     }
2164    
2165     }
2166    
2167     //printf("doneloop\n");
2168    
2169    
2170     sumpt = dsumpt;
2171     sumptsq = dsumptsq;
2172    
2173     pt = vtxmom.Rho();
2174     phi = vtxmom.Phi();
2175     eta = vtxmom.Eta();
2176     px = vtxmom.X();
2177     py = vtxmom.Y();
2178     pz = vtxmom.Z();
2179    
2180     //printf("done\n");
2181    
2182     return;
2183    
2184     }