ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/PhotonMvaMod.cc
Revision: 1.6
Committed: Sun Jun 17 23:12:57 2012 UTC (12 years, 10 months ago) by bendavid
Content type: text/plain
Branch: MAIN
Changes since 1.5: +2 -1 lines
Log Message:
add support for shower shape rescaling for sigmaE computation

File Contents

# User Rev Content
1 bendavid 1.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 bendavid 1.6 fApplyShowerRescaling(false),
51 bendavid 1.1 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 bendavid 1.2 fRegWeights (gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/gbrv2ph_52x.root")),
72 bendavid 1.1 // ---------------------------------------
73     fApplyEleVeto (true),
74     //MVA
75     fRegressionVersion(2)
76     {
77     // Constructor.
78     }
79    
80     PhotonMvaMod::~PhotonMvaMod(){
81    
82     }
83    
84     //--------------------------------------------------------------------------------------------------
85     void PhotonMvaMod::Process()
86     {
87     // ------------------------------------------------------------
88     // Process entries of the tree.
89     LoadEventObject(fPhotonBranchName, fPhotons);
90    
91     // -----------------------------------------------------------
92     // OUtput Photon Collection. It will ALWAYS conatrin either 0 or 2 Photons
93     PhotonOArr *GoodPhotons = new PhotonOArr;
94     GoodPhotons->SetName(fGoodPhotonsName);
95     GoodPhotons->SetOwner(kTRUE);
96     // add to event for other modules to use
97     AddObjThisEvt(GoodPhotons);
98    
99     if (fPhotons->GetEntries()<2) return;
100    
101     LoadEventObject(fPVName, fPV);
102 bendavid 1.4 LoadEventObject(fPileUpDenName, fPileUpDen);
103 bendavid 1.1
104     // ------------------------------------------------------------
105     // here we'll store the preselected Photons (and which CiCCategory they are...)
106     PhotonOArr* preselPh = new PhotonOArr;
107    
108     // 1. we do the pre-selection; but keep the non-passing photons in a secont container...
109     for (UInt_t i=0; i<fPhotons->GetEntries(); ++i) {
110     const Photon *ph = fPhotons->At(i);
111    
112     if(ph->SCluster()->AbsEta()>= fPhotonEtaMax || (ph->SCluster()->AbsEta()>=1.4442 && ph->SCluster()->AbsEta()<=1.566)) continue;
113     if(ph->Et() < fPhotonPtMin) continue;
114     if(ph->HadOverEm() > 0.15) continue;
115     if(ph->IsEB()) {
116 bendavid 1.3 if(ph->CoviEtaiEta() > 0.015) continue;
117 bendavid 1.1 } else {
118 bendavid 1.3 if(ph->CoviEtaiEta() > 0.035) continue;
119 bendavid 1.1 }
120    
121     preselPh->Add(ph);
122     }
123    
124     if (preselPh->GetEntries()<2) return;
125    
126     // Sorry... need the second loop here in order to sort & assign the right Categories..
127     //preselPh->Sort();
128     for(unsigned int iPh = 0; iPh <preselPh->GetEntries(); ++iPh) {
129     const Photon* ph = preselPh->At(iPh);
130     Photon *outph = new Photon(*ph);
131    
132     if (fDoRegression) {
133     if (!egcor.IsInitialized()) {
134 bendavid 1.2 egcor.Initialize(fPhFixString,fPhFixFile,fRegWeights);
135 bendavid 1.1 }
136    
137 bendavid 1.5 if (fRegressionVersion>0)
138 bendavid 1.6 egcor.CorrectEnergyWithError(outph,fPV,fPileUpDen->At(0)->RhoKt6PFJets(),fRegressionVersion, fApplyShowerRescaling&&!fIsData);
139 bendavid 1.5
140 bendavid 1.1 ThreeVectorC scpos = outph->SCluster()->Point();
141     outph->SetCaloPosXYZ(scpos.X(),scpos.Y(),scpos.Z());
142    
143     }
144    
145     GoodPhotons->AddOwned(outph);
146    
147     }
148    
149    
150    
151     // sort according to pt
152     GoodPhotons->Sort();
153    
154     // delete auxiliary photon collection...
155     delete preselPh;
156     //delete[] theVtx;
157    
158     return;
159    
160     }
161    
162     //--------------------------------------------------------------------------------------------------
163     void PhotonMvaMod::SlaveBegin()
164     {
165     // Run startup code on the computer (slave) doing the actual analysis. Here,
166     // we just request the photon collection branch.
167    
168     ReqEventObject(fPhotonBranchName, fPhotons, fPhotonsFromBranch);
169     ReqEventObject(fTrackBranchName, fTracks, true);
170     ReqEventObject(fElectronName, fElectrons, true);
171     ReqEventObject(fGoodElectronName, fGoodElectrons, fGoodElectronsFromBranch);
172     ReqEventObject(fPileUpDenName, fPileUpDen, true);
173     ReqEventObject(fPVName, fPV, fPVFromBranch);
174     ReqEventObject(fConversionName, fConversions,true);
175     ReqEventObject(fBeamspotName, fBeamspot, true);
176     ReqEventObject(fPFCandName, fPFCands, true);
177    
178     if (!fIsData) {
179     ReqBranch(fPileUpName, fPileUp);
180     ReqBranch(fMCParticleName, fMCParticles);
181     }
182    
183    
184     if (fIsData) {
185     fPhFixFile = gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/PhotonFixGRPV22.dat");
186     }
187     else {
188     fPhFixFile = gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/PhotonFixSTART42V13.dat");
189     }
190    
191    
192     }
193