ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/PhotonTreeWriter.cc
Revision: 1.51
Committed: Sat Aug 31 05:37:04 2013 UTC (11 years, 8 months ago) by veverka
Content type: text/plain
Branch: MAIN
Changes since 1.50: +312 -128 lines
Log Message:
Fist crack at the VH(lep) tag

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