ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/PhotonTreeWriter.cc
Revision: 1.49
Committed: Fri Aug 30 12:02:37 2013 UTC (11 years, 8 months ago) by veverka
Content type: text/plain
Branch: MAIN
Changes since 1.48: +177 -17 lines
Log Message:
Putting back tth tag code accidentally removed on Jul 30

File Contents

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