ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.h
Revision: 1.46
Committed: Tue Jul 9 08:36:11 2013 UTC (11 years, 9 months ago) by lantonel
Content type: text/plain
Branch: MAIN
Changes since 1.45: +2 -0 lines
Log Message:
added 'objectsToFlag' vector, to use for setting flags instead of 'objectsToCut'

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