ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.h
Revision: 1.56
Committed: Tue Sep 3 09:19:54 2013 UTC (11 years, 8 months ago) by lantonel
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.55: +7 -0 lines
Log Message:
added top pt reweighting and an overall event scale factor

File Contents

# User Rev Content
1 lantonel 1.1 #ifndef OSU_ANALYSIS
2    
3     #define OSU_ANALYSIS
4    
5     #include <map>
6     #include <string>
7     #include <vector>
8 jbrinson 1.13
9     #include <fstream>
10     #include <iostream>
11 lantonel 1.12 #include <algorithm>
12 ahart 1.29 #include <regex>
13 lantonel 1.6 #include "TH1.h"
14 lantonel 1.9 #include "TH2.h"
15 lantonel 1.1 #include "TH1D.h"
16     #include "TH2D.h"
17     #include "TLorentzVector.h"
18 ahart 1.48 #include "TVector3.h"
19     #include "TVector2.h"
20 wulsin 1.35 #include "TTree.h"
21 lantonel 1.1
22 ahart 1.41 #include "FWCore/Framework/interface/EDProducer.h"
23 lantonel 1.1 #include "FWCore/Framework/interface/Event.h"
24     #include "FWCore/Framework/interface/EventSetup.h"
25     #include "FWCore/ParameterSet/interface/ParameterSet.h"
26     #include "FWCore/ServiceRegistry/interface/Service.h"
27     #include "DataFormats/Common/interface/Handle.h"
28     #include "CommonTools/UtilAlgos/interface/TFileService.h"
29     #include "FWCore/Framework/interface/MakerMacros.h"
30 lantonel 1.10 #include "DataFormats/Math/interface/deltaPhi.h"
31     #include "DataFormats/Math/interface/deltaR.h"
32 lantonel 1.1
33     #include "ProductArea/BNcollections/interface/BNbxlumi.h"
34     #include "ProductArea/BNcollections/interface/BNelectron.h"
35     #include "ProductArea/BNcollections/interface/BNevent.h"
36     #include "ProductArea/BNcollections/interface/BNjet.h"
37     #include "ProductArea/BNcollections/interface/BNmcparticle.h"
38     #include "ProductArea/BNcollections/interface/BNmet.h"
39     #include "ProductArea/BNcollections/interface/BNmuon.h"
40     #include "ProductArea/BNcollections/interface/BNphoton.h"
41     #include "ProductArea/BNcollections/interface/BNprimaryvertex.h"
42     #include "ProductArea/BNcollections/interface/BNskimbits.h"
43     #include "ProductArea/BNcollections/interface/BNsupercluster.h"
44     #include "ProductArea/BNcollections/interface/BNtrack.h"
45     #include "ProductArea/BNcollections/interface/BNtrigger.h"
46     #include "ProductArea/BNcollections/interface/BNtrigobj.h"
47     #include "ProductArea/BNcollections/interface/BNtau.h"
48     #include "ProductArea/BNcollections/interface/BNgenjet.h"
49 lantonel 1.26
50 lantonel 1.1
51     #include "OSUT3Analysis/AnaTools/interface/CutFlow.h"
52 lantonel 1.9 #include "OSUT3Analysis/AnaTools/interface/PUWeight.h"
53 ahart 1.16 #include "OSUT3Analysis/AnaTools/interface/SFWeight.h"
54 biliu 1.40 #include "OSUT3Analysis/AnaTools/interface/BtagSFWeight.h"
55 ahart 1.29 #include "OSUT3Analysis/AnaTools/interface/StopCTauWeight.h"
56 lantonel 1.1
57     using namespace std;
58    
59 ahart 1.41 class OSUAnalysis : public edm::EDProducer
60 lantonel 1.1 {
61     public:
62     OSUAnalysis (const edm::ParameterSet &);
63     ~OSUAnalysis ();
64    
65 ahart 1.41 void produce (edm::Event &, const edm::EventSetup &);
66 lantonel 1.1 bool evaluateComparison (double, string, double);
67 ahart 1.31 bool evaluateComparison (string, string, string);
68 biliu 1.34 bool evaluateTriggers (vector<string>, vector<string>, const BNtriggerCollection*);
69 lantonel 1.3 double applyFunction(string, double);
70    
71 ahart 1.31 double valueLookup (const BNjet* object, string variable, string function, string &stringValue);
72     double valueLookup (const BNmuon* object, string variable, string function, string &stringValue);
73     double valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue);
74 lantonel 1.54
75 ahart 1.31 double valueLookup (const BNelectron* object, string variable, string function, string &stringValue);
76     double valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue);
77     double valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue);
78     double valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue);
79 biliu 1.43 double valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue);
80 lantonel 1.54
81 biliu 1.43 double valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue);
82 biliu 1.47 double valueLookup (const BNmuon* object1, const BNevent* object2, string variable, string function, string &stringValue);
83 lantonel 1.54
84 biliu 1.43 double valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue);
85 lantonel 1.54
86 ahart 1.31 double valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue);
87     double valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue);
88 wulsin 1.44 double valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue);
89 jbrinson 1.45 double valueLookup (const BNtrack* object1, const BNjet* object2, string variable, string function, string &stringValue);
90 ahart 1.31 double valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue);
91     double valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue);
92     double valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue);
93     double valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue);
94     double valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue);
95 lantonel 1.54
96 ahart 1.31 double valueLookup (const BNevent* object, string variable, string function, string &stringValue);
97     double valueLookup (const BNtau* object, string variable, string function, string &stringValue);
98     double valueLookup (const BNmet* object, string variable, string function, string &stringValue);
99     double valueLookup (const BNtrack* object, string variable, string function, string &stringValue);
100 lantonel 1.54
101 ahart 1.31 double valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue);
102     double valueLookup (const BNgenjet* object, string variable, string function, string &stringValue);
103     double valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue);
104 lantonel 1.54
105     double valueLookup (const BNelectron* object1, const BNmcparticle* object, string variable, string function, string &stringValue);
106    
107 ahart 1.31 double valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue);
108     double valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue);
109     double valueLookup (const BNphoton* object, string variable, string function, string &stringValue);
110     double valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue);
111     double valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue);
112     double valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue);
113     double valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue);
114     double valueLookup (const BNstop* object, string variable, string function, string &stringValue);
115 jbrinson 1.14
116 jbrinson 1.13 int getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl);
117 jbrinson 1.14 double getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl);
118 biliu 1.49 double getHt (const BNjetCollection* jetColl);
119 jbrinson 1.14 double getTrkPtRes (const BNtrack* track1);
120     double getTrkIsIso (const BNtrack* track1);
121 wulsin 1.20 double getTrkCaloTotRhoCorr(const BNtrack* track);
122 jbrinson 1.51 double getTrkDepTrkRp5RhoCorr(const BNtrack* track);
123     double getTrkDepTrkRp3RhoCorr(const BNtrack* track);
124 jbrinson 1.13 void WriteDeadEcal ();
125     int getTrkIsMatchedDeadEcal (const BNtrack* track1);
126    
127 lantonel 1.1 //BNskimbits
128     //BNtrigobj
129    
130     vector<string> splitString (string);
131 ahart 1.31 void getTwoObjs(string tempInputCollection, string& obj1, string& obj2);
132     string getObjToGet(string obj);
133 lantonel 1.1
134     private:
135    
136     //flagMap:
137     //string holds input collection type
138     //outer vector corresponds to each cut
139     //inner vector corresponds to each object in input collection
140 lantonel 1.42 //pair(bool) first bool counts towards the event passing, second bool determines whether to plot the object
141     typedef map<string, vector<vector<pair<bool,bool> > > > flagMap;
142    
143 wulsin 1.52 //flagPair (corresponds to flagMap):
144     //vector corresponds to each object in input collection
145     //pair(bool) first bool counts towards the event passing, second bool determines whether to plot the object
146 lantonel 1.42 typedef vector<pair<bool,bool> > flagPair;
147 ahart 1.16
148 lantonel 1.1 //counterMap:
149     //string holds input collection type
150     //vector corresponds to each cut
151     //int holds number of objects passing all cuts up to that point
152     typedef map<string ,vector <int> > counterMap;
153    
154     // Remember to define parameters to be retrieved from the configuration file.
155     edm::InputTag jets_;
156     edm::InputTag muons_;
157 wulsin 1.55 edm::InputTag secMuons_;
158 lantonel 1.1 edm::InputTag electrons_;
159     edm::InputTag events_;
160     edm::InputTag taus_;
161     edm::InputTag mets_;
162     edm::InputTag tracks_;
163     edm::InputTag genjets_;
164     edm::InputTag mcparticles_;
165 ahart 1.21 edm::InputTag stops_;
166 lantonel 1.1 edm::InputTag primaryvertexs_;
167     edm::InputTag bxlumis_;
168     edm::InputTag photons_;
169     edm::InputTag superclusters_;
170 lantonel 1.2 edm::InputTag triggers_;
171 ahart 1.31 edm::InputTag trigobjs_;
172     string puFile_;
173     string deadEcalFile_;
174     string muonSFFile_;
175     string dataPU_;
176     string electronSFID_;
177     string muonSF_;
178     string dataset_;
179     string datasetType_;
180 lantonel 1.1 vector<edm::ParameterSet> channels_;
181 lantonel 1.4 vector<edm::ParameterSet> histogramSets_;
182 ahart 1.41 bool useEDMFormat_;
183 wulsin 1.35 vector<edm::ParameterSet> treeBranchSets_;
184 lantonel 1.9 bool plotAllObjectsInPassingEvents_;
185 lantonel 1.15 bool doPileupReweighting_;
186 lantonel 1.56 bool doTopPtReweighting_;
187 ahart 1.28 bool applyLeptonSF_;
188 biliu 1.40 bool applyBtagSF_;
189     int minBtag_;
190 ahart 1.31 bool printEventInfo_;
191 wulsin 1.39 bool printAllTriggers_;
192 ahart 1.31 bool useTrackCaloRhoCorr_; // to use the calo-based rho correction for the by-hand calculation of the track isolation energy
193 ahart 1.21 vector<double> stopCTau_;
194 biliu 1.33 bool GetPlotsAfterEachCut_;
195 wulsin 1.52 int verbose_;
196 biliu 1.33
197 jbrinson 1.13 struct DeadEcal {
198 ahart 1.16 double etaEcal;
199     double phiEcal;
200 jbrinson 1.13 };
201 ahart 1.16
202 ahart 1.31 vector<DeadEcal> DeadEcalVec;
203 jbrinson 1.13
204 jbrinson 1.14
205 jbrinson 1.13 //Collections
206 lantonel 1.11 edm::Handle<BNtriggerCollection> triggers;
207 ahart 1.31 edm::Handle<BNtrigobjCollection> trigobjs;
208 lantonel 1.11 edm::Handle<BNjetCollection> jets;
209     edm::Handle<BNmuonCollection> muons;
210 wulsin 1.55 edm::Handle<BNmuonCollection> secMuons;
211 lantonel 1.11 edm::Handle<BNelectronCollection> electrons;
212     edm::Handle<BNeventCollection> events;
213     edm::Handle<BNtauCollection> taus;
214     edm::Handle<BNmetCollection> mets;
215     edm::Handle<BNtrackCollection> tracks;
216     edm::Handle<BNgenjetCollection> genjets;
217     edm::Handle<BNmcparticleCollection> mcparticles;
218     edm::Handle<BNprimaryvertexCollection> primaryvertexs;
219     edm::Handle<BNbxlumiCollection> bxlumis;
220     edm::Handle<BNphotonCollection> photons;
221     edm::Handle<BNsuperclusterCollection> superclusters;
222 lantonel 1.24 edm::Handle<BNstopCollection> stops;
223 lantonel 1.26
224 ahart 1.31 edm::Handle<double> rhokt6CaloJetsHandle_;
225 lantonel 1.11
226 ahart 1.16 flagMap cumulativeFlags;
227 lantonel 1.42 flagMap vetoFlags;
228 lantonel 1.8
229 biliu 1.33 vector<vector<map<string, TH1D*>>> oneDHists_;
230     vector<vector<map<string, TH2D*>>> twoDHists_;
231 wulsin 1.35 vector<TTree*> BNTrees_; // one tree per channel
232     map<string, vector<float>> BNTreeBranchVals_; // data structure to hold the values of the branches to be stored in the BNTrees_; the string is the name of a variable
233 wulsin 1.53 long BNTreeBranchVals_evtLong_; // event number
234     int BNTreeBranchVals_runInt_; // run number
235     int BNTreeBranchVals_lumiInt_; // lumi number
236 lantonel 1.1
237     edm::Service<TFileService> fs_;
238    
239     CutFlow *masterCutFlow_;
240     vector<CutFlow *> cutFlows_;
241    
242 lantonel 1.4 typedef struct {
243 ahart 1.16 string name;
244     string title;
245     vector<double> bins;
246 ahart 1.30 vector<double> variableBinsX;
247     vector<double> variableBinsY;
248 ahart 1.16 string inputCollection;
249     vector<string> inputVariables;
250 lantonel 1.4 } histogram;
251 lantonel 1.1
252 wulsin 1.35 typedef struct {
253     string name;
254     string inputCollection;
255     string inputVariable;
256     } BranchSpecs;
257    
258    
259 lantonel 1.1 struct cut {
260 ahart 1.16 string inputCollection;
261     vector<string> functions;
262     vector<string> variables;
263     vector<string> comparativeOperators;// >, <, =, etc.
264     vector<double> cutValues;
265 ahart 1.31 vector<string> cutStringValues;
266 ahart 1.16 vector<string> logicalOperators;//and, or
267 lantonel 1.42 int numSubcuts;
268 ahart 1.16 int numberRequired;
269     string eventComparativeOperator;
270     string name;
271 lantonel 1.42 bool isVeto;
272 lantonel 1.1 };
273    
274     struct channel {
275 ahart 1.16 string name;
276     vector<string> triggers;
277 biliu 1.34 vector<string> triggersToVeto;
278 ahart 1.16 vector<cut> cuts;
279 lantonel 1.1 };
280    
281 lantonel 1.12 vector<string> objectsToGet;
282     vector<string> objectsToCut;
283 lantonel 1.4 vector<string> objectsToPlot;
284 lantonel 1.46 vector<string> objectsToFlag;
285    
286 lantonel 1.1 vector<channel> channels;
287 lantonel 1.4 vector<histogram> histograms;
288 wulsin 1.35 vector<BranchSpecs> treeBranches_;
289 lantonel 1.1
290 lantonel 1.9 PUWeight *puWeight_;
291 ahart 1.16 MuonSFWeight *muonSFWeight_;
292 ahart 1.32 double muonScaleFactor_;
293 ahart 1.16 ElectronSFWeight *electronSFWeight_;
294 ahart 1.32 double electronScaleFactor_;
295 biliu 1.40 BtagSFWeight *bTagSFWeight_;
296     double bTagScaleFactor_;
297 ahart 1.29
298 lantonel 1.56 double topPtScaleFactor_;
299    
300 ahart 1.29 StopCTauWeight *stopCTauWeight_;
301     double stopCTauScaleFactor_;
302 lantonel 1.9
303 lantonel 1.56 double eventScaleFactor_;
304    
305 wulsin 1.50 ofstream* findEventsLog;
306     bool isFirstEvent_;
307    
308 lantonel 1.1 template <class InputCollection> void setObjectFlags(cut &, uint, flagMap &, flagMap &, InputCollection, string);
309 wulsin 1.52 template <class InputCollection1, class InputCollection2> void setObjectFlags(cut &, uint, flagMap &, flagMap &, InputCollection1, InputCollection2, string);
310 lantonel 1.42
311     template <class InputCollection> void assignTreeBranch(BranchSpecs brSpecs, InputCollection inputCollection, flagPair flags);
312     template <class InputCollection> void fill1DHistogram(TH1*, histogram, InputCollection, flagPair, double);
313 wulsin 1.52 template <class InputCollection1, class InputCollection2> void fill1DHistogram(TH1*, histogram, InputCollection1, InputCollection2, flagPair, double);
314 lantonel 1.42 template <class InputCollection> void fill2DHistogram(TH2*, histogram, InputCollection, flagPair, double);
315 wulsin 1.52 template <class InputCollection1, class InputCollection2> void fill2DHistogram(TH2*, histogram, InputCollection1, InputCollection2, flagPair, double);
316 lantonel 1.42 bool getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType);
317    
318 lantonel 1.12
319 lantonel 1.1
320 lantonel 1.11 template <class InputObject> int getGenMatchedParticleIndex(InputObject);
321     int getPdgIdBinValue(int);
322     int findTauMotherIndex(const BNmcparticle*);
323    
324 jbrinson 1.17 template <class InputObject> double getGenDeltaRLowest(InputObject);
325    
326    
327 ahart 1.16 const BNprimaryvertex *chosenVertex ();
328     const BNmet *chosenMET ();
329     const BNelectron *chosenElectron ();
330     const BNmuon *chosenMuon ();
331 ahart 1.48 double chosenHT ();
332 lantonel 1.56
333 ahart 1.48 pair<const BNmuon *, const BNmuon*> leadMuonPair ();
334     pair<const BNelectron *, const BNelectron*> leadElectronPair ();
335 jbrinson 1.13
336 lantonel 1.56 double getTopPtWeight();
337 lantonel 1.1 };
338    
339     #endif