ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/PhotonTreeWriter.cc
Revision: 1.77
Committed: Fri Dec 13 01:06:15 2013 UTC (11 years, 5 months ago) by bendavid
Content type: text/plain
Branch: MAIN
Changes since 1.76: +3 -3 lines
Log Message:
fix sigmaE and sigmaM inconsistencies

File Contents

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