ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/PhotonMvaMod.cc
Revision: 1.7
Committed: Tue Jul 24 10:13:45 2012 UTC (12 years, 9 months ago) by fabstoec
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_029c, Mit_029b, Mit_029a
Changes since 1.6: +18 -13 lines
Log Message:
some fixes

File Contents

# Content
1 #include "MitPhysics/Mods/interface/PhotonMvaMod.h"
2 #include "MitAna/DataTree/interface/PhotonCol.h"
3 #include "MitAna/DataTree/interface/PFCandidateCol.h"
4 #include "MitAna/DataTree/interface/StableData.h"
5 #include "MitAna/DataTree/interface/StableParticle.h"
6 #include "MitPhysics/Init/interface/ModNames.h"
7 #include "MitPhysics/Utils/interface/IsolationTools.h"
8 #include "MitPhysics/Utils/interface/PhotonTools.h"
9 #include "MitPhysics/Utils/interface/VertexTools.h"
10 #include "MitPhysics/Utils/interface/PhotonFix.h"
11 #include "MitPhysics/Utils/interface/MVATools.h"
12 #include "TDataMember.h"
13 #include <TNtuple.h>
14 #include <TRandom3.h>
15 #include <TSystem.h>
16 #include <TH1D.h>
17
18 using namespace mithep;
19
20 ClassImp(mithep::PhotonMvaMod)
21
22 //--------------------------------------------------------------------------------------------------
23 PhotonMvaMod::PhotonMvaMod(const char *name, const char *title) :
24 // Base Module...
25 BaseMod (name,title),
26
27 // define all the Branches to load
28 fPhotonBranchName (Names::gkPhotonBrn),
29 fElectronName (Names::gkElectronBrn),
30 fGoodElectronName (Names::gkElectronBrn),
31 fConversionName (Names::gkMvfConversionBrn),
32 fTrackBranchName (Names::gkTrackBrn),
33 fPileUpDenName (Names::gkPileupEnergyDensityBrn),
34 fPVName (Names::gkPVBeamSpotBrn),
35 fBeamspotName (Names::gkBeamSpotBrn),
36 fPFCandName (Names::gkPFCandidatesBrn),
37 // MC specific stuff...
38 fMCParticleName (Names::gkMCPartBrn),
39 fPileUpName (Names::gkPileupInfoBrn),
40
41 fGoodPhotonsName (ModNames::gkGoodPhotonsName),
42
43
44
45 // ----------------------------------------
46 fPhotonPtMin (20.0),
47 fPhotonEtaMax (2.5),
48
49 fIsData (false),
50 fApplyShowerRescaling(false),
51 fPhotonsFromBranch (true),
52 fPVFromBranch (true),
53 fGoodElectronsFromBranch (kTRUE),
54
55 // ----------------------------------------
56 // collections....
57 fPhotons (0),
58 fElectrons (0),
59 fConversions (0),
60 fTracks (0),
61 fPileUpDen (0),
62 fPV (0),
63 fBeamspot (0),
64 fPFCands (0),
65 fMCParticles (0),
66 fPileUp (0),
67
68 // ---------------------------------------
69 fDoRegression (kTRUE),
70 fPhFixString ("4_2"),
71 fRegWeights (gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/gbrv2ph_52x.root")),
72 // ---------------------------------------
73 fApplyEleVeto (true),
74 //MVA
75 fRegressionVersion (2),
76 fMinNumPhotons (2),
77 fDoPreselection (kTRUE)
78
79 {
80 // Constructor.
81 }
82
83 PhotonMvaMod::~PhotonMvaMod(){
84
85 }
86
87 //--------------------------------------------------------------------------------------------------
88 void PhotonMvaMod::Process()
89 {
90 // ------------------------------------------------------------
91 // Process entries of the tree.
92 LoadEventObject(fPhotonBranchName, fPhotons);
93
94 // -----------------------------------------------------------
95 // OUtput Photon Collection. It will ALWAYS conatrin either 0 or 2 Photons
96 PhotonOArr *GoodPhotons = new PhotonOArr;
97 GoodPhotons->SetName(fGoodPhotonsName);
98 GoodPhotons->SetOwner(kTRUE);
99 // add to event for other modules to use
100 AddObjThisEvt(GoodPhotons);
101
102 if ( fPhotons->GetEntries() < fMinNumPhotons ) return;
103
104 LoadEventObject(fPVName, fPV);
105 LoadEventObject(fPileUpDenName, fPileUpDen);
106
107 // ------------------------------------------------------------
108 // here we'll store the preselected Photons (and which CiCCategory they are...)
109 PhotonOArr* preselPh = new PhotonOArr;
110
111 // 1. we do the pre-selection; but keep the non-passing photons in a secont container...
112 for (UInt_t i=0; i<fPhotons->GetEntries(); ++i) {
113 const Photon *ph = fPhotons->At(i);
114
115 if( fDoPreselection ) {
116 if(ph->SCluster()->AbsEta()>= fPhotonEtaMax || (ph->SCluster()->AbsEta()>=1.4442 && ph->SCluster()->AbsEta()<=1.566)) continue;
117 if(ph->Et() < fPhotonPtMin) continue;
118 if(ph->HadOverEm() > 0.15) continue;
119 if(ph->IsEB()) {
120 if(ph->CoviEtaiEta() > 0.015) continue;
121 } else {
122 if(ph->CoviEtaiEta() > 0.035) continue;
123 }
124 }
125
126 preselPh->Add(ph);
127 }
128
129 if ( preselPh->GetEntries() < fMinNumPhotons ) return;
130
131 // Sorry... need the second loop here in order to sort & assign the right Categories..
132 //preselPh->Sort();
133 for(unsigned int iPh = 0; iPh <preselPh->GetEntries(); ++iPh) {
134 const Photon* ph = preselPh->At(iPh);
135 Photon *outph = new Photon(*ph);
136
137 if (fDoRegression) {
138 if (!egcor.IsInitialized()) {
139 egcor.Initialize(fPhFixString,fPhFixFile,fRegWeights);
140 }
141
142 if (fRegressionVersion>0)
143 egcor.CorrectEnergyWithError(outph,fPV,fPileUpDen->At(0)->RhoKt6PFJets(),fRegressionVersion, fApplyShowerRescaling&&!fIsData);
144
145 ThreeVectorC scpos = outph->SCluster()->Point();
146 outph->SetCaloPosXYZ(scpos.X(),scpos.Y(),scpos.Z());
147
148 }
149
150 GoodPhotons->AddOwned(outph);
151
152 }
153
154
155
156 // sort according to pt
157 GoodPhotons->Sort();
158
159 // delete auxiliary photon collection...
160 delete preselPh;
161 //delete[] theVtx;
162
163 return;
164
165 }
166
167 //--------------------------------------------------------------------------------------------------
168 void PhotonMvaMod::SlaveBegin()
169 {
170 // Run startup code on the computer (slave) doing the actual analysis. Here,
171 // we just request the photon collection branch.
172
173 ReqEventObject(fPhotonBranchName, fPhotons, fPhotonsFromBranch);
174 ReqEventObject(fTrackBranchName, fTracks, true);
175 ReqEventObject(fElectronName, fElectrons, true);
176 ReqEventObject(fGoodElectronName, fGoodElectrons, fGoodElectronsFromBranch);
177 ReqEventObject(fPileUpDenName, fPileUpDen, true);
178 ReqEventObject(fPVName, fPV, fPVFromBranch);
179 ReqEventObject(fConversionName, fConversions,true);
180 ReqEventObject(fBeamspotName, fBeamspot, true);
181 ReqEventObject(fPFCandName, fPFCands, true);
182
183 if (!fIsData) {
184 ReqBranch(fPileUpName, fPileUp);
185 ReqBranch(fMCParticleName, fMCParticles);
186 }
187
188
189 if (fIsData) {
190 fPhFixFile = gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/PhotonFixGRPV22.dat");
191 }
192 else {
193 fPhFixFile = gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/PhotonFixSTART42V13.dat");
194 }
195
196
197 }
198