ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/PhotonTreeWriter.cc
Revision: 1.56
Committed: Thu Nov 7 17:15:46 2013 UTC (11 years, 6 months ago) by veverka
Content type: text/plain
Branch: MAIN
Changes since 1.55: +56 -8 lines
Log Message:
Fixed bug in dilepton selection for VH lep cat

File Contents

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