ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
Revision: 1.49
Committed: Wed Apr 17 15:39:43 2013 UTC (12 years ago) by wulsin
Content type: text/plain
Branch: MAIN
Changes since 1.48: +121 -44 lines
Log Message:
When cut is applied to a pair of objects, set object flags for each constituent object in the setObjectFlags() function called for the pair.  This should ensure that only individual objects passing the paired-object cuts are used to fill histograms.

File Contents

# User Rev Content
1 lantonel 1.1 #include "OSUT3Analysis/AnaTools/plugins/OSUAnalysis.h"
2    
3     OSUAnalysis::OSUAnalysis (const edm::ParameterSet &cfg) :
4     // Retrieve parameters from the configuration file.
5     jets_ (cfg.getParameter<edm::InputTag> ("jets")),
6     muons_ (cfg.getParameter<edm::InputTag> ("muons")),
7     electrons_ (cfg.getParameter<edm::InputTag> ("electrons")),
8     events_ (cfg.getParameter<edm::InputTag> ("events")),
9     taus_ (cfg.getParameter<edm::InputTag> ("taus")),
10     mets_ (cfg.getParameter<edm::InputTag> ("mets")),
11     tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
12     genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
13     mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
14 ahart 1.45 stops_ (cfg.getParameter<edm::InputTag> ("stops")),
15 lantonel 1.1 primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
16     bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
17     photons_ (cfg.getParameter<edm::InputTag> ("photons")),
18     superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
19 lantonel 1.3 triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
20 lantonel 1.15 puFile_ (cfg.getParameter<std::string> ("puFile")),
21 jbrinson 1.25 deadEcalFile_ (cfg.getParameter<std::string> ("deadEcalFile")),
22 biliu 1.40 muonSFFile_ (cfg.getParameter<std::string> ("muonSFFile")),
23 lantonel 1.15 dataPU_ (cfg.getParameter<std::string> ("dataPU")),
24 ahart 1.31 electronSFID_ (cfg.getParameter<std::string> ("electronSFID")),
25     muonSF_ (cfg.getParameter<std::string> ("muonSF")),
26 lantonel 1.15 dataset_ (cfg.getParameter<std::string> ("dataset")),
27     datasetType_ (cfg.getParameter<std::string> ("datasetType")),
28 lantonel 1.9 channels_ (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
29 lantonel 1.14 histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
30 lantonel 1.30 plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
31 wulsin 1.37 doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
32 wulsin 1.42 printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
33 ahart 1.45 useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
34     stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau"))
35 wulsin 1.42
36 lantonel 1.1 {
37 lantonel 1.9
38 lantonel 1.1 TH1::SetDefaultSumw2 ();
39 lantonel 1.15
40     //create pile-up reweighting object, if necessary
41 ahart 1.31 if(datasetType_ != "data") {
42     if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
43 lantonel 1.36 // muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
44     // electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
45 ahart 1.31 }
46 ahart 1.45 #ifdef DISPLACED_SUSY
47     if (datasetType_ == "signalMC")
48     cTauWeight_ = new CTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
49     #endif
50 lantonel 1.1
51 wulsin 1.34
52 lantonel 1.1 // Construct Cutflow Objects. These store the results of cut decisions and
53     // handle filling cut flow histograms.
54     masterCutFlow_ = new CutFlow (fs_);
55     std::vector<TFileDirectory> directories;
56    
57 lantonel 1.9 //always get vertex collection so we can assign the primary vertex in the event
58 lantonel 1.29 objectsToGet.push_back("primaryvertexs");
59    
60 lantonel 1.48 //always make the plot of number of primary vertices (to check pile-up reweighting)
61 lantonel 1.14 objectsToPlot.push_back("primaryvertexs");
62 lantonel 1.9
63 lantonel 1.19 //always get the MC particles to do GEN-matching
64 lantonel 1.23 objectsToGet.push_back("mcparticles");
65 lantonel 1.19
66 lantonel 1.15 //always get the event collection to do pile-up reweighting
67 lantonel 1.23 objectsToGet.push_back("events");
68 lantonel 1.15
69 lantonel 1.9 //parse the histogram definitions
70     for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
71    
72 lantonel 1.17 string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
73     if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
74 wulsin 1.42 if(tempInputCollection == "event-track pairs") tempInputCollection = "track-event pairs";
75 lantonel 1.48 if(tempInputCollection == "secondary muon-muon pairs") tempInputCollection = "muon-secondary muon pairs";
76 ahart 1.31 if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
77 lantonel 1.48 if(tempInputCollection.find("secondary")!=std::string::npos){//secondary object
78     int spaceIndex = tempInputCollection.find(" ");
79     int secondWordLength = tempInputCollection.size() - spaceIndex;
80     objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
81     }
82     else{
83     objectsToGet.push_back(tempInputCollection);
84     }
85 lantonel 1.17 objectsToPlot.push_back(tempInputCollection);
86 lantonel 1.24 objectsToCut.push_back(tempInputCollection);
87 lantonel 1.17 }
88 lantonel 1.48 else{//pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
89 wulsin 1.49 string obj1;
90     string obj2;
91     getTwoObjs(tempInputCollection, obj1, obj2);
92     string obj2ToGet = getObjToGet(obj2);
93     objectsToCut.push_back(tempInputCollection);
94     objectsToCut.push_back(obj1);
95     objectsToCut.push_back(obj2);
96     objectsToPlot.push_back(tempInputCollection);
97     objectsToPlot.push_back(obj1);
98     objectsToPlot.push_back(obj2);
99 lantonel 1.23 objectsToGet.push_back(tempInputCollection);
100 wulsin 1.49 objectsToGet.push_back(obj1);
101     objectsToGet.push_back(obj2ToGet);
102 lantonel 1.23
103 wulsin 1.43 }
104 lantonel 1.17
105 lantonel 1.9 vector<edm::ParameterSet> histogramList_ (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
106 ahart 1.31
107 lantonel 1.9 for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
108    
109     histogram tempHistogram;
110     tempHistogram.inputCollection = tempInputCollection;
111     tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
112     tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
113     tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
114 lantonel 1.10 tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
115 ahart 1.31
116 lantonel 1.9 histograms.push_back(tempHistogram);
117    
118     }
119     }
120 lantonel 1.19 //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
121 lantonel 1.15 sort( objectsToPlot.begin(), objectsToPlot.end() );
122     objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
123 lantonel 1.9
124    
125 lantonel 1.1
126 lantonel 1.22 //add histograms with the gen-matched id, mother id, and grandmother id
127     for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
128    
129     string currentObject = objectsToPlot.at(currentObjectIndex);
130 lantonel 1.48 if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
131 lantonel 1.22
132     histogram tempIdHisto;
133     histogram tempMomIdHisto;
134     histogram tempGmaIdHisto;
135 lantonel 1.36 histogram tempIdVsMomIdHisto;
136 lantonel 1.22
137     tempIdHisto.inputCollection = currentObject;
138     tempMomIdHisto.inputCollection = currentObject;
139     tempGmaIdHisto.inputCollection = currentObject;
140 lantonel 1.36 tempIdVsMomIdHisto.inputCollection = currentObject;
141 lantonel 1.22
142 lantonel 1.48 if(currentObject == "secondary muons") currentObject = "secondaryMuons";
143    
144 lantonel 1.22 currentObject = currentObject.substr(0, currentObject.size()-1);
145     tempIdHisto.name = currentObject+"GenMatchId";
146     tempMomIdHisto.name = currentObject+"GenMatchMotherId";
147     tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
148 lantonel 1.36 tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
149 lantonel 1.22
150     currentObject.at(0) = toupper(currentObject.at(0));
151     tempIdHisto.title = currentObject+" Gen-matched Particle";
152     tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
153     tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
154 lantonel 1.36 tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
155 lantonel 1.22
156     int maxNum = 24;
157     vector<double> binVector;
158     binVector.push_back(maxNum);
159     binVector.push_back(0);
160     binVector.push_back(maxNum);
161    
162     tempIdHisto.bins = binVector;
163     tempIdHisto.inputVariables.push_back("genMatchedId");
164     tempMomIdHisto.bins = binVector;
165     tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
166     tempGmaIdHisto.bins = binVector;
167     tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
168 lantonel 1.36 binVector.push_back(maxNum);
169     binVector.push_back(0);
170     binVector.push_back(maxNum);
171     tempIdVsMomIdHisto.bins = binVector;
172     tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
173     tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
174 lantonel 1.22
175     histograms.push_back(tempIdHisto);
176     histograms.push_back(tempMomIdHisto);
177     histograms.push_back(tempGmaIdHisto);
178 lantonel 1.36 histograms.push_back(tempIdVsMomIdHisto);
179 lantonel 1.22 }
180    
181    
182 lantonel 1.1 channel tempChannel;
183     //loop over all channels (event selections)
184     for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
185 ahart 1.8
186 lantonel 1.1 //get name of channel
187     string channelName (channels_.at(currentChannel).getParameter<string>("name"));
188     tempChannel.name = channelName;
189     TString channelLabel = channelName;
190    
191 lantonel 1.3 //set triggers for this channel
192     vector<string> triggerNames;
193     triggerNames.clear();
194     tempChannel.triggers.clear();
195     if(channels_.at(currentChannel).exists("triggers")){
196     triggerNames = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
197     for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
198 ahart 1.8 tempChannel.triggers.push_back(triggerNames.at(trigger));
199 lantonel 1.23 objectsToGet.push_back("triggers");
200 lantonel 1.3 }
201    
202 lantonel 1.1
203 lantonel 1.9
204 lantonel 1.14
205 lantonel 1.1 //create cutFlow for this channel
206     cutFlows_.push_back (new CutFlow (fs_, channelName));
207    
208     //book a directory in the output file with the name of the channel
209     TFileDirectory subDir = fs_->mkdir( channelName );
210     directories.push_back(subDir);
211 lantonel 1.10
212     std::map<std::string, TH1D*> oneDhistoMap;
213     oneDHists_.push_back(oneDhistoMap);
214     std::map<std::string, TH2D*> twoDhistoMap;
215     twoDHists_.push_back(twoDhistoMap);
216 lantonel 1.1
217 lantonel 1.14
218 lantonel 1.36
219 lantonel 1.9 //book all histograms included in the configuration
220     for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
221     histogram currentHistogram = histograms.at(currentHistogramIndex);
222 lantonel 1.10 int numBinsElements = currentHistogram.bins.size();
223     int numInputVariables = currentHistogram.inputVariables.size();
224 lantonel 1.14
225 lantonel 1.10 if(numBinsElements != 3 && numBinsElements !=6) {
226 ahart 1.31 std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
227     exit(0);
228 lantonel 1.10 }
229     else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
230 ahart 1.31 std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
231     exit(0);
232 lantonel 1.10 }
233 lantonel 1.14 else if(numBinsElements == 3){
234 ahart 1.31 oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
235 lantonel 1.14 }
236     else if(numBinsElements == 6){
237 ahart 1.31 twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2),currentHistogram.bins.at(3),currentHistogram.bins.at(4),currentHistogram.bins.at(5));
238 lantonel 1.10
239 lantonel 1.14 }
240    
241 lantonel 1.10
242 lantonel 1.22 if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
243    
244 wulsin 1.43 // bin particle type
245     // --- -------------
246     // 0 unmatched
247     // 1 u
248     // 2 d
249     // 3 s
250     // 4 c
251     // 5 b
252     // 6 t
253     // 7 e
254     // 8 mu
255     // 9 tau
256     // 10 nu
257     // 11 g
258     // 12 gamma
259     // 13 Z
260     // 14 W
261     // 15 light meson
262     // 16 K meson
263     // 17 D meson
264     // 18 B meson
265     // 19 light baryon
266     // 20 strange baryon
267     // 21 charm baryon
268     // 22 bottom baryon
269     // 23 other
270 lantonel 1.22
271     vector<TString> labelArray;
272     labelArray.push_back("unmatched");
273     labelArray.push_back("u");
274     labelArray.push_back("d");
275     labelArray.push_back("s");
276     labelArray.push_back("c");
277     labelArray.push_back("b");
278     labelArray.push_back("t");
279     labelArray.push_back("e");
280     labelArray.push_back("#mu");
281     labelArray.push_back("#tau");
282     labelArray.push_back("#nu");
283     labelArray.push_back("g");
284     labelArray.push_back("#gamma");
285     labelArray.push_back("Z");
286     labelArray.push_back("W");
287     labelArray.push_back("light meson");
288     labelArray.push_back("K meson");
289     labelArray.push_back("D meson");
290     labelArray.push_back("B meson");
291     labelArray.push_back("light baryon");
292     labelArray.push_back("strange baryon");
293     labelArray.push_back("charm baryon");
294     labelArray.push_back("bottom baryon");
295     labelArray.push_back("other");
296    
297     for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
298 lantonel 1.36 if(currentHistogram.name.find("GenMatchIdVsMotherId")==std::string::npos) {
299     oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
300     }
301     else {
302     twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
303     twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
304     }
305     }
306     if(currentHistogram.name.find("GenMatchIdVsMotherId")!=std::string::npos) {
307     twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->CenterTitle();
308     twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->CenterTitle();
309 lantonel 1.22 }
310 lantonel 1.36
311 lantonel 1.9 }
312 qpython 1.27
313 wulsin 1.42 // Book a histogram for the number of each object type to be plotted.
314     // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
315 lantonel 1.9 for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
316     string currentObject = objectsToPlot.at(currentObjectIndex);
317     int maxNum = 10;
318     if(currentObject == "mcparticles") maxNum = 50;
319 lantonel 1.15 else if(currentObject == "primaryvertexs") maxNum = 50;
320 lantonel 1.48
321     if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
322     else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
323     else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
324     else if(currentObject == "track-event pairs") currentObject = "trackEventPairs";
325     else if(currentObject == "electron-track pairs") currentObject = "electronTrackPairs";
326     else if(currentObject == "muon-track pairs") currentObject = "muonTrackPairs";
327     else if(currentObject == "muon-tau pairs") currentObject = "muonTauPairs";
328     else if(currentObject == "tau-tau pairs") currentObject = "ditauPairs";
329 jbrinson 1.46 else if(currentObject == "tau-track pairs") currentObject = "tauTrackPairs";
330 lantonel 1.48 else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
331     else if(currentObject == "secondary muons") currentObject = "secondaryMuons";
332    
333 wulsin 1.43 currentObject.at(0) = toupper(currentObject.at(0));
334 lantonel 1.9 string histoName = "num" + currentObject;
335 lantonel 1.17
336 lantonel 1.16 if(histoName == "numPrimaryvertexs"){
337 ahart 1.31 string newHistoName = histoName + "BeforePileupCorrection";
338     oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
339     newHistoName = histoName + "AfterPileupCorrection";
340     oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
341 lantonel 1.16 }
342     else
343 ahart 1.31 oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
344 lantonel 1.9 }
345 lantonel 1.1
346    
347 ahart 1.31
348 lantonel 1.22
349 lantonel 1.1 //get list of cuts for this channel
350     vector<edm::ParameterSet> cuts_ (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
351    
352     //loop over and parse all cuts
353     for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
354 lantonel 1.17 cut tempCut;
355     //store input collection for cut
356     string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
357 wulsin 1.49 if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
358     if(tempInputCollection == "event-track pairs") tempInputCollection = "track-event pairs";
359     if(tempInputCollection == "secondary muon-muon pairs") tempInputCollection = "muon-secondary muon pairs";
360 lantonel 1.17 tempCut.inputCollection = tempInputCollection;
361 ahart 1.31 if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
362 lantonel 1.48 if(tempInputCollection.find("secondary")!=std::string::npos){//secondary object
363     int spaceIndex = tempInputCollection.find(" ");
364     int secondWordLength = tempInputCollection.size() - spaceIndex;
365     objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
366     }
367     else{
368     objectsToGet.push_back(tempInputCollection);
369     }
370     objectsToCut.push_back(tempInputCollection);
371 lantonel 1.17 }
372 wulsin 1.49 else{//pair of objects, need to add them both to objectsToGet
373     string obj1;
374     string obj2;
375     getTwoObjs(tempInputCollection, obj1, obj2);
376     string obj2ToGet = getObjToGet(obj2);
377     objectsToCut.push_back(tempInputCollection);
378     objectsToCut.push_back(obj1);
379     objectsToCut.push_back(obj2);
380 ahart 1.31 objectsToGet.push_back(tempInputCollection);
381 wulsin 1.49 objectsToGet.push_back(obj1);
382     objectsToGet.push_back(obj2ToGet);
383 lantonel 1.17
384     }
385    
386 lantonel 1.1
387    
388     //split cut string into parts and store them
389     string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
390     std::vector<string> cutStringVector = splitString(cutString);
391 lantonel 1.17 if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
392 ahart 1.31 std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
393     exit(0);
394 lantonel 1.10 }
395 lantonel 1.17 tempCut.numSubcuts = (cutStringVector.size()+1)/4;
396     for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
397 ahart 1.31 int indexOffset = 4 * subcutIndex;
398     string currentVariableString = cutStringVector.at(indexOffset);
399     if(currentVariableString.find("(")==std::string::npos){
400     tempCut.functions.push_back("");//no function was specified
401     tempCut.variables.push_back(currentVariableString);// variable to cut on
402     }
403     else{
404     tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
405     string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
406     tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
407     }
408     tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
409     tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
410     if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
411 lantonel 1.17 }
412 lantonel 1.1
413     //get number of objects required to pass cut for event to pass
414     string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
415     std::vector<string> numberRequiredVector = splitString(numberRequiredString);
416 lantonel 1.10 if(numberRequiredVector.size()!=2){
417 ahart 1.31 std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
418 lantonel 1.10 exit(0);
419     }
420 lantonel 1.1
421 ahart 1.8 int numberRequiredInt = atoi(numberRequiredVector.at(1).c_str());
422 lantonel 1.1 tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
423     tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
424 ahart 1.8
425 lantonel 1.17
426 lantonel 1.1 string tempCutName;
427     if(cuts_.at(currentCut).exists("alias")){
428 ahart 1.8 tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
429 lantonel 1.1 }
430     else{
431 ahart 1.8 //construct string for cutflow table
432     bool plural = numberRequiredInt != 1;
433 lantonel 1.17 string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
434 ahart 1.8 string cutName = numberRequiredString + " " + collectionString + " with " + cutString;
435     tempCutName = cutName;
436 lantonel 1.1 }
437     tempCut.name = tempCutName;
438    
439     tempChannel.cuts.push_back(tempCut);
440    
441    
442     }//end loop over cuts
443    
444     channels.push_back(tempChannel);
445     tempChannel.cuts.clear();
446    
447     }//end loop over channels
448    
449 lantonel 1.9
450 lantonel 1.23 //make unique vector of objects we need to get from the event
451     sort( objectsToGet.begin(), objectsToGet.end() );
452     objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
453     //make unique vector of objects we need to cut on
454     sort( objectsToCut.begin(), objectsToCut.end() );
455     objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
456 lantonel 1.1
457    
458     }
459    
460     OSUAnalysis::~OSUAnalysis ()
461     {
462     // Destroying the CutFlow objects causes the cut flow numbers and time
463     // information to be printed to standard output.
464     for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
465     delete cutFlows_.at(currentChannel);
466     }
467     }
468    
469     void
470     OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
471     {
472 lantonel 1.2
473 lantonel 1.1 // Retrieve necessary collections from the event.
474 lantonel 1.22
475 lantonel 1.23 if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
476 lantonel 1.3 event.getByLabel (triggers_, triggers);
477    
478 lantonel 1.23 if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
479 lantonel 1.1 event.getByLabel (jets_, jets);
480    
481 lantonel 1.23 if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
482 lantonel 1.1 event.getByLabel (muons_, muons);
483    
484 lantonel 1.23 if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
485 lantonel 1.1 event.getByLabel (electrons_, electrons);
486    
487 lantonel 1.23 if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
488 lantonel 1.1 event.getByLabel (events_, events);
489    
490 lantonel 1.23 if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
491 lantonel 1.1 event.getByLabel (taus_, taus);
492    
493 lantonel 1.23 if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
494 lantonel 1.1 event.getByLabel (mets_, mets);
495    
496 lantonel 1.23 if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
497 lantonel 1.1 event.getByLabel (tracks_, tracks);
498    
499 lantonel 1.23 if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
500 lantonel 1.1 event.getByLabel (genjets_, genjets);
501    
502 lantonel 1.23 if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
503 lantonel 1.29 event.getByLabel (mcparticles_, mcparticles);
504 lantonel 1.1
505 lantonel 1.23 if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
506 lantonel 1.1 event.getByLabel (primaryvertexs_, primaryvertexs);
507    
508 lantonel 1.23 if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
509 lantonel 1.1 event.getByLabel (bxlumis_, bxlumis);
510    
511 lantonel 1.23 if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
512 lantonel 1.1 event.getByLabel (photons_, photons);
513    
514 lantonel 1.23 if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
515 lantonel 1.1 event.getByLabel (superclusters_, superclusters);
516    
517 wulsin 1.42 if (useTrackCaloRhoCorr_) {
518     // Used only for pile-up correction of by-hand calculation of isolation energy.
519     // This rho collection is not available in all BEANs.
520     // For description of rho values for different jet reconstruction algorithms, see
521     // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
522     event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
523     }
524    
525    
526 lantonel 1.15 //get pile-up event weight
527 ahart 1.31 double scaleFactor = 1.00;
528     if(doPileupReweighting_ && datasetType_ != "data")
529     scaleFactor = puWeight_->at (events->at (0).numTruePV);
530 lantonel 1.26
531 ahart 1.45 cTauScaleFactor_ = 1.0;
532     #ifdef DISPLACED_SUSY
533     if (datasetType_ == "signalMC")
534     cTauScaleFactor_ = cTauWeight_->at (event);
535     #endif
536     scaleFactor *= cTauScaleFactor_;
537 lantonel 1.14
538 lantonel 1.1 //loop over all channels
539    
540     for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
541     channel currentChannel = channels.at(currentChannelIndex);
542 ahart 1.8
543     flagMap individualFlags;
544     counterMap passingCounter;
545 ahart 1.31 cumulativeFlags.clear ();
546 lantonel 1.1
547 lantonel 1.5 bool triggerDecision = true;
548 lantonel 1.3 if(currentChannel.triggers.size() != 0){ //triggers specified
549 lantonel 1.5 triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
550 lantonel 1.3 cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
551     }
552 lantonel 1.1
553     //loop over all cuts
554 lantonel 1.23
555    
556 lantonel 1.24
557 lantonel 1.1 for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
558     cut currentCut = currentChannel.cuts.at(currentCutIndex);
559    
560 lantonel 1.23 for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
561     string currentObject = objectsToCut.at(currentObjectIndex);
562 lantonel 1.1
563 ahart 1.31 //initialize maps to get ready to set cuts
564 ahart 1.8 individualFlags[currentObject].push_back (vector<bool> ());
565     cumulativeFlags[currentObject].push_back (vector<bool> ());
566    
567 lantonel 1.23 }
568     for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
569     string currentObject = objectsToCut.at(currentObjectIndex);
570    
571 ahart 1.31 int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
572    
573 lantonel 1.14
574 ahart 1.8 if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
575 lantonel 1.48
576 ahart 1.8 else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
577 lantonel 1.48
578     else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
579 ahart 1.8 else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
580     else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
581     else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
582     else if(currentObject == "mets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
583     else if(currentObject == "tracks") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
584     else if(currentObject == "genjets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
585     else if(currentObject == "mcparticles") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
586     else if(currentObject == "primaryvertexs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
587     else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
588     else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
589     else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
590 lantonel 1.1
591 ahart 1.31
592     else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
593     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
594     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
595     "muon-muon pairs");
596 lantonel 1.48
597     else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
598     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
599     cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
600     "muon-secondary muon pairs");
601    
602 ahart 1.31 else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
603     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
604     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
605     "electron-electron pairs");
606     else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
607     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
608     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
609     "electron-muon pairs");
610 wulsin 1.42 else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
611     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
612     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
613     "track-event pairs");
614 wulsin 1.43 else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
615     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
616     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
617     "electron-track pairs");
618     else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
619     cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
620     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
621     "muon-track pairs");
622     else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
623     cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
624     cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
625     "muon-tau pairs");
626 lantonel 1.48 else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
627 wulsin 1.43 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
628     cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
629     "tau-tau pairs");
630 jbrinson 1.46 else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
631     cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
632     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
633     "tau-track pairs");
634 wulsin 1.43
635 wulsin 1.42
636 lantonel 1.1 }
637    
638    
639    
640     }//end loop over all cuts
641 ahart 1.8
642 lantonel 1.1
643     //use cumulative flags to apply cuts at event level
644    
645     bool eventPassedAllCuts = true;
646    
647 lantonel 1.5 //apply trigger (true if none were specified)
648     eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
649 lantonel 1.4
650    
651 lantonel 1.1 for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
652    
653     //loop over all objects and count how many passed the cumulative selection up to this point
654     cut currentCut = currentChannel.cuts.at(currentCutIndex);
655     int numberPassing = 0;
656 lantonel 1.3
657 lantonel 1.17 for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
658 wulsin 1.43 if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
659 lantonel 1.17 }
660 lantonel 1.1 bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
661     cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
662     eventPassedAllCuts = eventPassedAllCuts && cutDecision;
663 wulsin 1.49
664 lantonel 1.1 }
665    
666 ahart 1.45 // if(datasetType_ != "data") {
667     // scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
668     // scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
669     // }
670    
671 ahart 1.31 cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
672 ahart 1.8
673 lantonel 1.1
674 lantonel 1.17
675 lantonel 1.1 if(!eventPassedAllCuts)continue;
676    
677 wulsin 1.37 if (printEventInfo_) {
678     // Write information about event to screen, for testing purposes.
679     cout << "Event passed all cuts in channel " << currentChannel.name
680     << ": run=" << events->at(0).run
681     << " lumi=" << events->at(0).lumi
682     << " event=" << events->at(0).evt
683     << endl;
684     }
685    
686 lantonel 1.1
687 lantonel 1.9 //filling histograms
688     for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
689     histogram currentHistogram = histograms.at(histogramIndex);
690    
691 lantonel 1.10 if(currentHistogram.inputVariables.size() == 1){
692 ahart 1.31 TH1D* histo;
693     histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
694 lantonel 1.23
695 ahart 1.31 if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
696 wulsin 1.43 else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
697 lantonel 1.48 else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").back(),scaleFactor);
698 ahart 1.31 else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
699     cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
700     cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
701 lantonel 1.48 else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
702     cumulativeFlags.at("muons").back(),cumulativeFlags.at("secondary muons").back(), \
703     cumulativeFlags.at("muon-secondary muon pairs").back(),scaleFactor);
704 ahart 1.31 else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
705     else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
706     cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
707     cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
708     else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
709 wulsin 1.43 cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
710     cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
711     else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
712     cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),
713     cumulativeFlags.at("electron-track pairs").back(),scaleFactor);
714     else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
715     cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),
716     cumulativeFlags.at("muon-track pairs").back(),scaleFactor);
717     else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
718     cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),
719     cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);
720     else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
721     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),
722     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);
723 jbrinson 1.46 else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
724     cumulativeFlags.at("taus").back(),cumulativeFlags.at("tracks").back(),
725     cumulativeFlags.at("tau-track pairs").back(),scaleFactor);
726    
727 ahart 1.31 else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
728     else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
729     else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
730     else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
731     else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
732     else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
733     else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
734     else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
735     else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
736     else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
737 lantonel 1.10 }
738     else if(currentHistogram.inputVariables.size() == 2){
739 ahart 1.31 TH2D* histo;
740     histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
741 lantonel 1.24
742 ahart 1.31 if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
743     else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
744 lantonel 1.48 else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").back(),scaleFactor);
745 ahart 1.31 else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
746     cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
747     cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
748 lantonel 1.48 else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
749     cumulativeFlags.at("muons").back(),cumulativeFlags.at("secondary muons").back(), \
750     cumulativeFlags.at("muon-secondary muon pairs").back(),scaleFactor);
751 ahart 1.31 else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
752     else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
753     cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
754     cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
755     else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
756 wulsin 1.43 cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
757     cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
758     else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
759     cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),
760     cumulativeFlags.at("electron-track pairs").back(),scaleFactor);
761     else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
762     cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),
763     cumulativeFlags.at("muon-track pairs").back(),scaleFactor);
764     else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
765     cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),
766     cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);
767     else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
768     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),
769     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);
770 jbrinson 1.46 else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
771     cumulativeFlags.at("taus").back(),cumulativeFlags.at("tracks").back(),
772     cumulativeFlags.at("tau-track pairs").back(),scaleFactor);
773 wulsin 1.43 else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
774 ahart 1.31 else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
775     else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
776     else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
777 wulsin 1.42 else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
778     cumulativeFlags.at("tracks").back(),cumulativeFlags.at("events").back(),
779     cumulativeFlags.at("track-event pairs").back(),scaleFactor);
780 ahart 1.31 else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
781     else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
782     else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
783     else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
784     else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
785     else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
786     }
787 lantonel 1.10 }
788 lantonel 1.4
789 lantonel 1.48
790    
791 lantonel 1.9 //fills histograms with the sizes of collections
792     for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
793 wulsin 1.42
794 lantonel 1.9 string currentObject = objectsToPlot.at(currentObjectIndex);
795 lantonel 1.17
796 wulsin 1.42 string objectToPlot = "";
797 lantonel 1.23
798 wulsin 1.42 // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
799 lantonel 1.23 if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
800     else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
801 wulsin 1.42 else if(currentObject == "electron-muon pairs") objectToPlot = "electronMuonPairs";
802 wulsin 1.43 else if(currentObject == "electron-track pairs") objectToPlot = "electronTrackPairs";
803     else if(currentObject == "muon-track pairs") objectToPlot = "muonTrackPairs";
804     else if(currentObject == "muon-tau pairs") objectToPlot = "muonTauPairs";
805     else if(currentObject == "tau-tau pairs") objectToPlot = "ditauPairs";
806 lantonel 1.48 else if(currentObject == "tau-track pairs") objectToPlot = "tauTrackPairs";
807     else if(currentObject == "track-event pairs") objectToPlot = "trackEventPairs";
808     else if(currentObject == "muon-secondary muon pairs") objectToPlot = "muonSecondaryMuonPairs";
809     else if(currentObject == "secondary muons") objectToPlot = "secondaryMuons";
810 lantonel 1.23 else objectToPlot = currentObject;
811 lantonel 1.48
812 lantonel 1.23 string tempCurrentObject = objectToPlot;
813 wulsin 1.43 tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
814 lantonel 1.9 string histoName = "num" + tempCurrentObject;
815    
816 lantonel 1.23 //set position of primary vertex in event, in order to calculate quantities relative to it
817     if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
818 ahart 1.31 vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
819 lantonel 1.48 int numToPlot = 0;
820 ahart 1.31 for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
821     if(lastCutFlags.at(currentFlag)) numToPlot++;
822     }
823     if(objectToPlot == "primaryvertexs"){
824     oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
825     oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
826     }
827 wulsin 1.42 else {
828 ahart 1.31 oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
829 wulsin 1.42 }
830 ahart 1.31 }
831     else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
832     else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
833 lantonel 1.48 else if(objectToPlot == "secondaryMuons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
834 ahart 1.31 else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
835 lantonel 1.48 else if(objectToPlot == "muonSecondaryMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
836 ahart 1.31 else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
837     else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
838     else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
839 wulsin 1.43 else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
840 ahart 1.31 else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
841     else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
842     else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
843     else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
844     else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
845     else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
846     else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
847     else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
848     else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
849 lantonel 1.23 else if(objectToPlot == "primaryvertexs"){
850 ahart 1.31 oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
851     oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
852 wulsin 1.42 }
853 lantonel 1.22
854 wulsin 1.42 } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
855 lantonel 1.22
856 lantonel 1.1 } //end loop over channel
857    
858 ahart 1.31 masterCutFlow_->fillCutFlow(scaleFactor);
859 lantonel 1.1
860 wulsin 1.42 } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
861 lantonel 1.1
862 lantonel 1.14
863 lantonel 1.1
864 ahart 1.8 bool
865 lantonel 1.1 OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
866    
867 lantonel 1.3
868 lantonel 1.1 if(comparison == ">") return testValue > cutValue;
869     else if(comparison == ">=") return testValue >= cutValue;
870     else if(comparison == "<") return testValue < cutValue;
871     else if(comparison == "<=") return testValue <= cutValue;
872 ahart 1.8 else if(comparison == "==") return testValue == cutValue;
873 lantonel 1.17 else if(comparison == "=") return testValue == cutValue;
874 ahart 1.8 else if(comparison == "!=") return testValue != cutValue;
875 lantonel 1.1 else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
876    
877     }
878    
879 lantonel 1.3 bool
880     OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
881    
882     bool triggerDecision = false;
883    
884     for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
885     {
886     if(trigger->pass != 1) continue;
887     for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
888     {
889     if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
890 ahart 1.8 triggerDecision = true;
891 lantonel 1.3 }
892     }
893     }
894     return triggerDecision;
895    
896     }
897    
898 lantonel 1.1 std::vector<std::string>
899     OSUAnalysis::splitString (string inputString){
900    
901     std::stringstream stringStream(inputString);
902     std::istream_iterator<std::string> begin(stringStream);
903     std::istream_iterator<std::string> end;
904     std::vector<std::string> stringVector(begin, end);
905     return stringVector;
906    
907     }
908    
909 wulsin 1.49
910     void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
911     // Set two object strings from the tempInputCollection string,
912     // For example, if tempInputCollection is "electron-muon pairs",
913     // then obj1 = "electrons" and obj2 = "muons".
914     // Note that the objects have an "s" appended.
915    
916     int dashIndex = tempInputCollection.find("-");
917     int spaceIndex = tempInputCollection.find_last_of(" ");
918     int secondWordLength = spaceIndex - dashIndex;
919     obj1 = tempInputCollection.substr(0,dashIndex) + "s";
920     obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
921    
922     }
923    
924    
925     string OSUAnalysis::getObjToGet(string obj) {
926     // Return the string corresponding to the object to get for the given obj string.
927     // Right now this only handles the case in which obj contains "secondary",
928     // e.g, "secondary muons".
929     // Note that "s" is NOT appended.
930    
931     if (obj.find("secondary")==std::string::npos) return obj; // "secondary" is not found
932     int firstSpaceIndex = obj.find_first_of(" ");
933     return obj.substr(firstSpaceIndex+1,obj.length()-1);
934    
935     }
936    
937    
938    
939 lantonel 1.1 double
940 lantonel 1.3 OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
941 lantonel 1.1
942     double value = 0.0;
943     if(variable == "energy") value = object->energy;
944     else if(variable == "et") value = object->et;
945     else if(variable == "pt") value = object->pt;
946     else if(variable == "px") value = object->px;
947     else if(variable == "py") value = object->py;
948     else if(variable == "pz") value = object->pz;
949     else if(variable == "phi") value = object->phi;
950     else if(variable == "eta") value = object->eta;
951     else if(variable == "theta") value = object->theta;
952     else if(variable == "Upt") value = object->Upt;
953     else if(variable == "Uenergy") value = object->Uenergy;
954     else if(variable == "L2pt") value = object->L2pt;
955     else if(variable == "L2L3pt") value = object->L2L3pt;
956     else if(variable == "L2L3respt") value = object->L2L3respt;
957     else if(variable == "respt") value = object->respt;
958     else if(variable == "EMfrac") value = object->EMfrac;
959     else if(variable == "Hadfrac") value = object->Hadfrac;
960     else if(variable == "charge") value = object->charge;
961     else if(variable == "mass") value = object->mass;
962     else if(variable == "area") value = object->area;
963     else if(variable == "fHPD") value = object->fHPD;
964     else if(variable == "approximatefHPD") value = object->approximatefHPD;
965     else if(variable == "genPartonET") value = object->genPartonET;
966     else if(variable == "genPartonPT") value = object->genPartonPT;
967     else if(variable == "genPartonEta") value = object->genPartonEta;
968     else if(variable == "genPartonPhi") value = object->genPartonPhi;
969     else if(variable == "genJetET") value = object->genJetET;
970     else if(variable == "genJetPT") value = object->genJetPT;
971     else if(variable == "genJetEta") value = object->genJetEta;
972     else if(variable == "genJetPhi") value = object->genJetPhi;
973     else if(variable == "btagTChighPur") value = object->btagTChighPur;
974     else if(variable == "btagTChighEff") value = object->btagTChighEff;
975     else if(variable == "btagJetProb") value = object->btagJetProb;
976     else if(variable == "btagJetBProb") value = object->btagJetBProb;
977     else if(variable == "btagSoftEle") value = object->btagSoftEle;
978     else if(variable == "btagSoftMuon") value = object->btagSoftMuon;
979     else if(variable == "btagSoftMuonNoIP") value = object->btagSoftMuonNoIP;
980     else if(variable == "btagSecVertex") value = object->btagSecVertex;
981     else if(variable == "btagSecVertexHighEff") value = object->btagSecVertexHighEff;
982     else if(variable == "btagSecVertexHighPur") value = object->btagSecVertexHighPur;
983     else if(variable == "btagCombinedSecVertex") value = object->btagCombinedSecVertex;
984     else if(variable == "btagCombinedSecVertexMVA") value = object->btagCombinedSecVertexMVA;
985     else if(variable == "btagSoftMuonByPt") value = object->btagSoftMuonByPt;
986     else if(variable == "btagSoftMuonByIP3") value = object->btagSoftMuonByIP3;
987     else if(variable == "btagSoftElectronByPt") value = object->btagSoftElectronByPt;
988     else if(variable == "btagSoftElectronByIP3") value = object->btagSoftElectronByIP3;
989     else if(variable == "n90Hits") value = object->n90Hits;
990     else if(variable == "hitsInN90") value = object->hitsInN90;
991     else if(variable == "chargedHadronEnergyFraction") value = object->chargedHadronEnergyFraction;
992     else if(variable == "neutralHadronEnergyFraction") value = object->neutralHadronEnergyFraction;
993     else if(variable == "chargedEmEnergyFraction") value = object->chargedEmEnergyFraction;
994     else if(variable == "neutralEmEnergyFraction") value = object->neutralEmEnergyFraction;
995     else if(variable == "fLong") value = object->fLong;
996     else if(variable == "fShort") value = object->fShort;
997     else if(variable == "etaetaMoment") value = object->etaetaMoment;
998     else if(variable == "phiphiMoment") value = object->phiphiMoment;
999     else if(variable == "JESunc") value = object->JESunc;
1000     else if(variable == "JECuncUp") value = object->JECuncUp;
1001     else if(variable == "JECuncDown") value = object->JECuncDown;
1002     else if(variable == "puJetMVA_full") value = object->puJetMVA_full;
1003     else if(variable == "puJetMVA_simple") value = object->puJetMVA_simple;
1004     else if(variable == "puJetMVA_cutbased") value = object->puJetMVA_cutbased;
1005     else if(variable == "dZ") value = object->dZ;
1006     else if(variable == "dR2Mean") value = object->dR2Mean;
1007     else if(variable == "dRMean") value = object->dRMean;
1008     else if(variable == "frac01") value = object->frac01;
1009     else if(variable == "frac02") value = object->frac02;
1010     else if(variable == "frac03") value = object->frac03;
1011     else if(variable == "frac04") value = object->frac04;
1012     else if(variable == "frac05") value = object->frac05;
1013     else if(variable == "frac06") value = object->frac06;
1014     else if(variable == "frac07") value = object->frac07;
1015     else if(variable == "beta") value = object->beta;
1016     else if(variable == "betaStar") value = object->betaStar;
1017     else if(variable == "betaClassic") value = object->betaClassic;
1018     else if(variable == "betaStarClassic") value = object->betaStarClassic;
1019     else if(variable == "ptD") value = object->ptD;
1020     else if(variable == "nvtx") value = object->nvtx;
1021     else if(variable == "d0") value = object->d0;
1022     else if(variable == "leadCandPt") value = object->leadCandPt;
1023     else if(variable == "leadCandVx") value = object->leadCandVx;
1024     else if(variable == "leadCandVy") value = object->leadCandVy;
1025     else if(variable == "leadCandVz") value = object->leadCandVz;
1026     else if(variable == "leadCandDistFromPV") value = object->leadCandDistFromPV;
1027     else if(variable == "flavour") value = object->flavour;
1028     else if(variable == "Nconst") value = object->Nconst;
1029     else if(variable == "jetIDMinimal") value = object->jetIDMinimal;
1030     else if(variable == "jetIDLooseAOD") value = object->jetIDLooseAOD;
1031     else if(variable == "jetIDLoose") value = object->jetIDLoose;
1032     else if(variable == "jetIDTight") value = object->jetIDTight;
1033     else if(variable == "genPartonId") value = object->genPartonId;
1034     else if(variable == "genPartonMotherId") value = object->genPartonMotherId;
1035     else if(variable == "genPartonMother0Id") value = object->genPartonMother0Id;
1036     else if(variable == "genPartonMother1Id") value = object->genPartonMother1Id;
1037     else if(variable == "genPartonGrandMotherId") value = object->genPartonGrandMotherId;
1038     else if(variable == "genPartonGrandMother00Id") value = object->genPartonGrandMother00Id;
1039     else if(variable == "genPartonGrandMother01Id") value = object->genPartonGrandMother01Id;
1040     else if(variable == "genPartonGrandMother10Id") value = object->genPartonGrandMother10Id;
1041     else if(variable == "genPartonGrandMother11Id") value = object->genPartonGrandMother11Id;
1042     else if(variable == "chargedMultiplicity") value = object->chargedMultiplicity;
1043     else if(variable == "neutralMultiplicity") value = object->neutralMultiplicity;
1044     else if(variable == "nconstituents") value = object->nconstituents;
1045     else if(variable == "nHit") value = object->nHit;
1046     else if(variable == "puJetId_full") value = object->puJetId_full;
1047     else if(variable == "puJetId_simple") value = object->puJetId_simple;
1048     else if(variable == "puJetId_cutbased") value = object->puJetId_cutbased;
1049     else if(variable == "puJetId_tight_full") value = object->puJetId_tight_full;
1050     else if(variable == "puJetId_tight_simple") value = object->puJetId_tight_simple;
1051     else if(variable == "puJetId_tight_cutbased") value = object->puJetId_tight_cutbased;
1052     else if(variable == "puJetId_medium_full") value = object->puJetId_medium_full;
1053     else if(variable == "puJetId_medium_simple") value = object->puJetId_medium_simple;
1054     else if(variable == "puJetId_medium_cutbased") value = object->puJetId_medium_cutbased;
1055     else if(variable == "puJetId_loose_full") value = object->puJetId_loose_full;
1056     else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1057     else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1058 ahart 1.8
1059    
1060 lantonel 1.1 else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1061 ahart 1.8
1062 lantonel 1.6 value = applyFunction(function, value);
1063 lantonel 1.1
1064     return value;
1065     }
1066    
1067    
1068    
1069     double
1070 lantonel 1.3 OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1071 lantonel 1.1
1072     double value = 0.0;
1073     if(variable == "energy") value = object->energy;
1074     else if(variable == "et") value = object->et;
1075     else if(variable == "pt") value = object->pt;
1076     else if(variable == "px") value = object->px;
1077     else if(variable == "py") value = object->py;
1078     else if(variable == "pz") value = object->pz;
1079     else if(variable == "phi") value = object->phi;
1080     else if(variable == "eta") value = object->eta;
1081     else if(variable == "theta") value = object->theta;
1082     else if(variable == "trackIso") value = object->trackIso;
1083     else if(variable == "ecalIso") value = object->ecalIso;
1084     else if(variable == "hcalIso") value = object->hcalIso;
1085     else if(variable == "caloIso") value = object->caloIso;
1086 lantonel 1.22 else if(variable == "trackIsDR03") value = object->trackIsoDR03;
1087 lantonel 1.1 else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
1088     else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
1089     else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
1090     else if(variable == "trackVetoIsoDR03") value = object->trackVetoIsoDR03;
1091     else if(variable == "ecalVetoIsoDR03") value = object->ecalVetoIsoDR03;
1092     else if(variable == "hcalVetoIsoDR03") value = object->hcalVetoIsoDR03;
1093     else if(variable == "caloVetoIsoDR03") value = object->caloVetoIsoDR03;
1094     else if(variable == "trackIsoDR05") value = object->trackIsoDR05;
1095     else if(variable == "ecalIsoDR05") value = object->ecalIsoDR05;
1096     else if(variable == "hcalIsoDR05") value = object->hcalIsoDR05;
1097     else if(variable == "caloIsoDR05") value = object->caloIsoDR05;
1098     else if(variable == "trackVetoIsoDR05") value = object->trackVetoIsoDR05;
1099     else if(variable == "ecalVetoIsoDR05") value = object->ecalVetoIsoDR05;
1100     else if(variable == "hcalVetoIsoDR05") value = object->hcalVetoIsoDR05;
1101     else if(variable == "caloVetoIsoDR05") value = object->caloVetoIsoDR05;
1102     else if(variable == "hcalE") value = object->hcalE;
1103     else if(variable == "ecalE") value = object->ecalE;
1104     else if(variable == "genET") value = object->genET;
1105     else if(variable == "genPT") value = object->genPT;
1106     else if(variable == "genPhi") value = object->genPhi;
1107     else if(variable == "genEta") value = object->genEta;
1108     else if(variable == "genMotherET") value = object->genMotherET;
1109     else if(variable == "genMotherPT") value = object->genMotherPT;
1110     else if(variable == "genMotherPhi") value = object->genMotherPhi;
1111     else if(variable == "genMotherEta") value = object->genMotherEta;
1112     else if(variable == "vx") value = object->vx;
1113     else if(variable == "vy") value = object->vy;
1114     else if(variable == "vz") value = object->vz;
1115     else if(variable == "tkNormChi2") value = object->tkNormChi2;
1116     else if(variable == "tkPT") value = object->tkPT;
1117     else if(variable == "tkEta") value = object->tkEta;
1118     else if(variable == "tkPhi") value = object->tkPhi;
1119     else if(variable == "tkDZ") value = object->tkDZ;
1120     else if(variable == "tkD0") value = object->tkD0;
1121     else if(variable == "tkD0bs") value = object->tkD0bs;
1122     else if(variable == "tkD0err") value = object->tkD0err;
1123     else if(variable == "samNormChi2") value = object->samNormChi2;
1124     else if(variable == "samPT") value = object->samPT;
1125     else if(variable == "samEta") value = object->samEta;
1126     else if(variable == "samPhi") value = object->samPhi;
1127     else if(variable == "samDZ") value = object->samDZ;
1128     else if(variable == "samD0") value = object->samD0;
1129     else if(variable == "samD0bs") value = object->samD0bs;
1130     else if(variable == "samD0err") value = object->samD0err;
1131     else if(variable == "comNormChi2") value = object->comNormChi2;
1132     else if(variable == "comPT") value = object->comPT;
1133     else if(variable == "comEta") value = object->comEta;
1134     else if(variable == "comPhi") value = object->comPhi;
1135     else if(variable == "comDZ") value = object->comDZ;
1136     else if(variable == "comD0") value = object->comD0;
1137     else if(variable == "comD0bs") value = object->comD0bs;
1138     else if(variable == "comD0err") value = object->comD0err;
1139     else if(variable == "isolationR03emVetoEt") value = object->isolationR03emVetoEt;
1140     else if(variable == "isolationR03hadVetoEt") value = object->isolationR03hadVetoEt;
1141     else if(variable == "normalizedChi2") value = object->normalizedChi2;
1142     else if(variable == "dVzPVz") value = object->dVzPVz;
1143     else if(variable == "dB") value = object->dB;
1144     else if(variable == "ptErr") value = object->ptErr;
1145     else if(variable == "innerTrackNormChi2") value = object->innerTrackNormChi2;
1146     else if(variable == "correctedD0") value = object->correctedD0;
1147     else if(variable == "correctedD0Vertex") value = object->correctedD0Vertex;
1148     else if(variable == "correctedDZ") value = object->correctedDZ;
1149     else if(variable == "particleIso") value = object->particleIso;
1150     else if(variable == "chargedHadronIso") value = object->chargedHadronIso;
1151     else if(variable == "neutralHadronIso") value = object->neutralHadronIso;
1152     else if(variable == "photonIso") value = object->photonIso;
1153     else if(variable == "puChargedHadronIso") value = object->puChargedHadronIso;
1154     else if(variable == "chargedHadronIsoDR03") value = object->chargedHadronIsoDR03;
1155     else if(variable == "neutralHadronIsoDR03") value = object->neutralHadronIsoDR03;
1156     else if(variable == "photonIsoDR03") value = object->photonIsoDR03;
1157     else if(variable == "puChargedHadronIsoDR03") value = object->puChargedHadronIsoDR03;
1158     else if(variable == "chargedHadronIsoDR04") value = object->chargedHadronIsoDR04;
1159     else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1160     else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1161     else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1162     else if(variable == "rhoPrime") value = object->rhoPrime;
1163     else if(variable == "AEffDr03") value = object->AEffDr03;
1164     else if(variable == "AEffDr04") value = object->AEffDr04;
1165     else if(variable == "pfIsoR03SumChargedHadronPt") value = object->pfIsoR03SumChargedHadronPt;
1166     else if(variable == "pfIsoR03SumNeutralHadronEt") value = object->pfIsoR03SumNeutralHadronEt;
1167     else if(variable == "pfIsoR03SumPhotonEt") value = object->pfIsoR03SumPhotonEt;
1168     else if(variable == "pfIsoR03SumPUPt") value = object->pfIsoR03SumPUPt;
1169     else if(variable == "pfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt;
1170     else if(variable == "pfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt;
1171     else if(variable == "pfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt;
1172     else if(variable == "pfIsoR04SumPUPt") value = object->pfIsoR04SumPUPt;
1173     else if(variable == "IP") value = object->IP;
1174     else if(variable == "IPError") value = object->IPError;
1175     else if(variable == "timeAtIpInOut") value = object->timeAtIpInOut;
1176     else if(variable == "timeAtIpInOutErr") value = object->timeAtIpInOutErr;
1177     else if(variable == "timeAtIpOutIn") value = object->timeAtIpOutIn;
1178     else if(variable == "timeAtIpOutInErr") value = object->timeAtIpOutInErr;
1179     else if(variable == "ecal_time") value = object->ecal_time;
1180     else if(variable == "hcal_time") value = object->hcal_time;
1181     else if(variable == "ecal_timeError") value = object->ecal_timeError;
1182     else if(variable == "hcal_timeError") value = object->hcal_timeError;
1183     else if(variable == "energy_ecal") value = object->energy_ecal;
1184     else if(variable == "energy_hcal") value = object->energy_hcal;
1185     else if(variable == "e3x3_ecal") value = object->e3x3_ecal;
1186     else if(variable == "e3x3_hcal") value = object->e3x3_hcal;
1187     else if(variable == "energyMax_ecal") value = object->energyMax_ecal;
1188     else if(variable == "energyMax_hcal") value = object->energyMax_hcal;
1189     else if(variable == "charge") value = object->charge;
1190     else if(variable == "IDGMPTight") value = object->IDGMPTight;
1191     else if(variable == "tkNumValidHits") value = object->tkNumValidHits;
1192     else if(variable == "tkCharge") value = object->tkCharge;
1193     else if(variable == "samNumValidHits") value = object->samNumValidHits;
1194     else if(variable == "samCharge") value = object->samCharge;
1195     else if(variable == "comNumValidHits") value = object->comNumValidHits;
1196     else if(variable == "comCharge") value = object->comCharge;
1197     else if(variable == "genId") value = object->genId;
1198     else if(variable == "genCharge") value = object->genCharge;
1199     else if(variable == "genNumberOfMothers") value = object->genNumberOfMothers;
1200     else if(variable == "genMotherId") value = object->genMotherId;
1201     else if(variable == "genMotherCharge") value = object->genMotherCharge;
1202     else if(variable == "genMother0Id") value = object->genMother0Id;
1203     else if(variable == "genMother1Id") value = object->genMother1Id;
1204     else if(variable == "genGrandMother00Id") value = object->genGrandMother00Id;
1205     else if(variable == "genGrandMother01Id") value = object->genGrandMother01Id;
1206     else if(variable == "genGrandMother10Id") value = object->genGrandMother10Id;
1207     else if(variable == "genGrandMother11Id") value = object->genGrandMother11Id;
1208     else if(variable == "isPFMuon") value = object->isPFMuon;
1209     else if(variable == "isGoodMuon_1StationTight") value = object->isGoodMuon_1StationTight;
1210     else if(variable == "isGlobalMuon") value = object->isGlobalMuon;
1211     else if(variable == "isTrackerMuon") value = object->isTrackerMuon;
1212     else if(variable == "isStandAloneMuon") value = object->isStandAloneMuon;
1213     else if(variable == "isGlobalMuonPromptTight") value = object->isGlobalMuonPromptTight;
1214     else if(variable == "numberOfValidMuonHits") value = object->numberOfValidMuonHits;
1215     else if(variable == "numberOfValidTrackerHits") value = object->numberOfValidTrackerHits;
1216     else if(variable == "numberOfLayersWithMeasurement") value = object->numberOfLayersWithMeasurement;
1217     else if(variable == "pixelLayersWithMeasurement") value = object->pixelLayersWithMeasurement;
1218     else if(variable == "numberOfMatches") value = object->numberOfMatches;
1219     else if(variable == "numberOfValidTrackerHitsInnerTrack") value = object->numberOfValidTrackerHitsInnerTrack;
1220     else if(variable == "numberOfValidPixelHits") value = object->numberOfValidPixelHits;
1221     else if(variable == "numberOfMatchedStations") value = object->numberOfMatchedStations;
1222     else if(variable == "time_ndof") value = object->time_ndof;
1223    
1224 lantonel 1.9 //user-defined variables
1225 ahart 1.31 else if(variable == "correctedD0VertexErr") value = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1226     else if(variable == "correctedD0VertexSig") value = object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1227 lantonel 1.19 else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1228 ahart 1.31 else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1229 lantonel 1.9 else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1230 ahart 1.31 else if(variable == "metMT") {
1231     const BNmet *met = chosenMET ();
1232     if (met)
1233     {
1234     TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1235 wulsin 1.43 p2 (met->px, met->py, 0.0, met->pt);
1236 ahart 1.31
1237     value = (p1 + p2).Mt ();
1238     }
1239     else
1240     value = -999;
1241     }
1242 lantonel 1.26
1243    
1244    
1245     else if(variable == "correctedD0VertexInEBPlus"){
1246     if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1247     else value = -999;
1248     }
1249     else if(variable == "correctedD0VertexOutEBPlus"){
1250     if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1251     else value = -999;
1252     }
1253     else if(variable == "correctedD0VertexEEPlus"){
1254     if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1255     else value = -999;
1256     }
1257    
1258     else if(variable == "correctedD0BeamspotInEBPlus"){
1259     if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1260     else value = -999;
1261     }
1262     else if(variable == "correctedD0BeamspotOutEBPlus"){
1263     if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1264     else value = -999;
1265     }
1266     else if(variable == "correctedD0BeamspotEEPlus"){
1267     if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1268     else value = -999;
1269     }
1270    
1271     else if(variable == "correctedD0VertexInEBMinus"){
1272     if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1273     else value = -999;
1274     }
1275     else if(variable == "correctedD0VertexOutEBMinus"){
1276     if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1277     else value = -999;
1278     }
1279     else if(variable == "correctedD0VertexEEMinus"){
1280     if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1281     else value = -999;
1282     }
1283    
1284     else if(variable == "correctedD0BeamspotInEBMinus"){
1285     if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1286     else value = -999;
1287     }
1288     else if(variable == "correctedD0BeamspotOutEBMinus"){
1289     if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1290     else value = -999;
1291     }
1292     else if(variable == "correctedD0BeamspotEEMinus"){
1293     if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1294     else value = -999;
1295     }
1296    
1297    
1298     else if(variable == "correctedD0VertexInEBPositiveCharge"){
1299     if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1300     else value = -999;
1301     }
1302     else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1303     if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1304     else value = -999;
1305     }
1306     else if(variable == "correctedD0VertexEEPositiveCharge"){
1307     if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1308     else value = -999;
1309     }
1310    
1311     else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1312     if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1313     else value = -999;
1314     }
1315     else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1316     if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1317     else value = -999;
1318     }
1319     else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1320     if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1321     else value = -999;
1322     }
1323    
1324     else if(variable == "correctedD0VertexInEBNegativeCharge"){
1325     if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1326     else value = -999;
1327     }
1328     else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1329     if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1330     else value = -999;
1331     }
1332     else if(variable == "correctedD0VertexEENegativeCharge"){
1333     if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1334     else value = -999;
1335     }
1336    
1337     else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1338     if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1339     else value = -999;
1340     }
1341     else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1342     if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1343     else value = -999;
1344     }
1345     else if(variable == "correctedD0BeamspotEENegativeCharge"){
1346     if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1347     else value = -999;
1348     }
1349    
1350    
1351 lantonel 1.10 else if(variable == "tightID") {
1352 ahart 1.31 value = object->isGlobalMuon > 0 \
1353     && object->isPFMuon > 0 \
1354     && object->normalizedChi2 < 10 \
1355 wulsin 1.43 && object->numberOfValidMuonHits > 0 \
1356 ahart 1.31 && object->numberOfMatchedStations > 1 \
1357     && fabs(object->correctedD0Vertex) < 0.2 \
1358     && fabs(object->correctedDZ) < 0.5 \
1359     && object->numberOfValidPixelHits > 0 \
1360 lantonel 1.11 && object->numberOfLayersWithMeasurement > 5;
1361 lantonel 1.10 }
1362     else if(variable == "tightIDdisplaced"){
1363 ahart 1.31 value = object->isGlobalMuon > 0 \
1364     && object->normalizedChi2 < 10 \
1365 wulsin 1.43 && object->numberOfValidMuonHits > 0 \
1366 ahart 1.31 && object->numberOfMatchedStations > 1 \
1367     && object->numberOfValidPixelHits > 0 \
1368 lantonel 1.11 && object->numberOfLayersWithMeasurement > 5;
1369 lantonel 1.10 }
1370 lantonel 1.9
1371 lantonel 1.36 else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1372 lantonel 1.26
1373 lantonel 1.36 else if(variable == "genMatchedPdgId"){
1374     int index = getGenMatchedParticleIndex(object);
1375     if(index == -1) value = 0;
1376     else value = mcparticles->at(index).id;
1377     }
1378 lantonel 1.26
1379 lantonel 1.22 else if(variable == "genMatchedId"){
1380     int index = getGenMatchedParticleIndex(object);
1381     if(index == -1) value = 0;
1382     else value = getPdgIdBinValue(mcparticles->at(index).id);
1383     }
1384     else if(variable == "genMatchedMotherId"){
1385     int index = getGenMatchedParticleIndex(object);
1386     if(index == -1) value = 0;
1387     else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1388     }
1389 lantonel 1.36 else if(variable == "genMatchedMotherIdReverse"){
1390     int index = getGenMatchedParticleIndex(object);
1391     if(index == -1) value = 23;
1392     else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1393     }
1394 lantonel 1.22 else if(variable == "genMatchedGrandmotherId"){
1395     int index = getGenMatchedParticleIndex(object);
1396     if(index == -1) value = 0;
1397     else if(fabs(mcparticles->at(index).motherId) == 15){
1398     int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1399     if(motherIndex == -1) value = 0;
1400     else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1401     }
1402     else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1403     }
1404 lantonel 1.19
1405    
1406    
1407 lantonel 1.1 else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1408 ahart 1.8
1409 lantonel 1.6 value = applyFunction(function, value);
1410 lantonel 1.1
1411     return value;
1412     }
1413    
1414    
1415     double
1416 lantonel 1.3 OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1417 lantonel 1.1
1418     double value = 0.0;
1419     if(variable == "energy") value = object->energy;
1420     else if(variable == "et") value = object->et;
1421     else if(variable == "gsfEt") value = object->gsfEt;
1422     else if(variable == "pt") value = object->pt;
1423     else if(variable == "px") value = object->px;
1424     else if(variable == "py") value = object->py;
1425     else if(variable == "pz") value = object->pz;
1426     else if(variable == "phi") value = object->phi;
1427     else if(variable == "eta") value = object->eta;
1428     else if(variable == "theta") value = object->theta;
1429     else if(variable == "pIn") value = object->pIn;
1430     else if(variable == "pOut") value = object->pOut;
1431     else if(variable == "EscOverPin") value = object->EscOverPin;
1432     else if(variable == "EseedOverPout") value = object->EseedOverPout;
1433     else if(variable == "hadOverEm") value = object->hadOverEm;
1434     else if(variable == "trackIso") value = object->trackIso;
1435     else if(variable == "ecalIso") value = object->ecalIso;
1436     else if(variable == "hcalIso") value = object->hcalIso;
1437     else if(variable == "caloIso") value = object->caloIso;
1438     else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
1439     else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
1440     else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
1441     else if(variable == "hcalIsoDR03depth1") value = object->hcalIsoDR03depth1;
1442     else if(variable == "hcalIsoDR03depth2") value = object->hcalIsoDR03depth2;
1443     else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
1444     else if(variable == "trackIsoDR04") value = object->trackIsoDR04;
1445     else if(variable == "ecalIsoDR04") value = object->ecalIsoDR04;
1446     else if(variable == "hcalIsoDR04") value = object->hcalIsoDR04;
1447     else if(variable == "hcalIsoDR04depth1") value = object->hcalIsoDR04depth1;
1448     else if(variable == "hcalIsoDR04depth2") value = object->hcalIsoDR04depth2;
1449     else if(variable == "caloIsoDR04") value = object->caloIsoDR04;
1450     else if(variable == "fbrem") value = object->fbrem;
1451     else if(variable == "absInvEMinusInvPin") value = object->absInvEMinusInvPin;
1452     else if(variable == "delPhiIn") value = object->delPhiIn;
1453     else if(variable == "delEtaIn") value = object->delEtaIn;
1454     else if(variable == "genET") value = object->genET;
1455     else if(variable == "genPT") value = object->genPT;
1456     else if(variable == "genPhi") value = object->genPhi;
1457     else if(variable == "genEta") value = object->genEta;
1458     else if(variable == "genMotherET") value = object->genMotherET;
1459     else if(variable == "genMotherPT") value = object->genMotherPT;
1460     else if(variable == "genMotherPhi") value = object->genMotherPhi;
1461     else if(variable == "genMotherEta") value = object->genMotherEta;
1462     else if(variable == "vx") value = object->vx;
1463     else if(variable == "vy") value = object->vy;
1464     else if(variable == "vz") value = object->vz;
1465     else if(variable == "scEnergy") value = object->scEnergy;
1466     else if(variable == "scRawEnergy") value = object->scRawEnergy;
1467     else if(variable == "scSigmaEtaEta") value = object->scSigmaEtaEta;
1468     else if(variable == "scSigmaIEtaIEta") value = object->scSigmaIEtaIEta;
1469     else if(variable == "scE1x5") value = object->scE1x5;
1470     else if(variable == "scE2x5Max") value = object->scE2x5Max;
1471     else if(variable == "scE5x5") value = object->scE5x5;
1472     else if(variable == "scEt") value = object->scEt;
1473     else if(variable == "scEta") value = object->scEta;
1474     else if(variable == "scPhi") value = object->scPhi;
1475     else if(variable == "scZ") value = object->scZ;
1476     else if(variable == "tkNormChi2") value = object->tkNormChi2;
1477     else if(variable == "tkPT") value = object->tkPT;
1478     else if(variable == "tkEta") value = object->tkEta;
1479     else if(variable == "tkPhi") value = object->tkPhi;
1480     else if(variable == "tkDZ") value = object->tkDZ;
1481     else if(variable == "tkD0") value = object->tkD0;
1482     else if(variable == "tkD0bs") value = object->tkD0bs;
1483     else if(variable == "tkD0err") value = object->tkD0err;
1484     else if(variable == "mva") value = object->mva;
1485     else if(variable == "mvaTrigV0") value = object->mvaTrigV0;
1486     else if(variable == "mvaNonTrigV0") value = object->mvaNonTrigV0;
1487     else if(variable == "dist") value = object->dist;
1488     else if(variable == "dcot") value = object->dcot;
1489     else if(variable == "convradius") value = object->convradius;
1490     else if(variable == "convPointX") value = object->convPointX;
1491     else if(variable == "convPointY") value = object->convPointY;
1492     else if(variable == "convPointZ") value = object->convPointZ;
1493     else if(variable == "eMax") value = object->eMax;
1494     else if(variable == "eLeft") value = object->eLeft;
1495     else if(variable == "eRight") value = object->eRight;
1496     else if(variable == "eTop") value = object->eTop;
1497     else if(variable == "eBottom") value = object->eBottom;
1498     else if(variable == "e3x3") value = object->e3x3;
1499     else if(variable == "swissCross") value = object->swissCross;
1500     else if(variable == "seedEnergy") value = object->seedEnergy;
1501     else if(variable == "seedTime") value = object->seedTime;
1502     else if(variable == "swissCrossNoI85") value = object->swissCrossNoI85;
1503     else if(variable == "swissCrossI85") value = object->swissCrossI85;
1504     else if(variable == "E2overE9NoI85") value = object->E2overE9NoI85;
1505     else if(variable == "E2overE9I85") value = object->E2overE9I85;
1506     else if(variable == "correctedD0") value = object->correctedD0;
1507     else if(variable == "correctedD0Vertex") value = object->correctedD0Vertex;
1508     else if(variable == "correctedDZ") value = object->correctedDZ;
1509     else if(variable == "particleIso") value = object->particleIso;
1510     else if(variable == "chargedHadronIso") value = object->chargedHadronIso;
1511     else if(variable == "neutralHadronIso") value = object->neutralHadronIso;
1512     else if(variable == "photonIso") value = object->photonIso;
1513     else if(variable == "puChargedHadronIso") value = object->puChargedHadronIso;
1514     else if(variable == "chargedHadronIsoDR03") value = object->chargedHadronIsoDR03;
1515     else if(variable == "neutralHadronIsoDR03") value = object->neutralHadronIsoDR03;
1516     else if(variable == "photonIsoDR03") value = object->photonIsoDR03;
1517     else if(variable == "puChargedHadronIsoDR03") value = object->puChargedHadronIsoDR03;
1518     else if(variable == "chargedHadronIsoDR04") value = object->chargedHadronIsoDR04;
1519     else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1520     else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1521     else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1522     else if(variable == "rhoPrime") value = object->rhoPrime;
1523     else if(variable == "AEffDr03") value = object->AEffDr03;
1524     else if(variable == "AEffDr04") value = object->AEffDr04;
1525     else if(variable == "IP") value = object->IP;
1526     else if(variable == "IPError") value = object->IPError;
1527     else if(variable == "charge") value = object->charge;
1528     else if(variable == "classification") value = object->classification;
1529     else if(variable == "genId") value = object->genId;
1530     else if(variable == "genCharge") value = object->genCharge;
1531     else if(variable == "genNumberOfMothers") value = object->genNumberOfMothers;
1532     else if(variable == "genMotherId") value = object->genMotherId;
1533     else if(variable == "genMotherCharge") value = object->genMotherCharge;
1534     else if(variable == "genMother0Id") value = object->genMother0Id;
1535     else if(variable == "genMother1Id") value = object->genMother1Id;
1536     else if(variable == "genGrandMother00Id") value = object->genGrandMother00Id;
1537     else if(variable == "genGrandMother01Id") value = object->genGrandMother01Id;
1538     else if(variable == "genGrandMother10Id") value = object->genGrandMother10Id;
1539     else if(variable == "genGrandMother11Id") value = object->genGrandMother11Id;
1540     else if(variable == "numClusters") value = object->numClusters;
1541     else if(variable == "tkNumValidHits") value = object->tkNumValidHits;
1542     else if(variable == "tkCharge") value = object->tkCharge;
1543     else if(variable == "gsfCharge") value = object->gsfCharge;
1544     else if(variable == "isEB") value = object->isEB;
1545     else if(variable == "isEE") value = object->isEE;
1546     else if(variable == "isGap") value = object->isGap;
1547     else if(variable == "isEBEEGap") value = object->isEBEEGap;
1548     else if(variable == "isEBGap") value = object->isEBGap;
1549     else if(variable == "isEEGap") value = object->isEEGap;
1550     else if(variable == "isEcalDriven") value = object->isEcalDriven;
1551     else if(variable == "isTrackerDriven") value = object->isTrackerDriven;
1552     else if(variable == "numberOfLostHits") value = object->numberOfLostHits;
1553     else if(variable == "numberOfExpectedInnerHits") value = object->numberOfExpectedInnerHits;
1554     else if(variable == "numberOfValidPixelHits") value = object->numberOfValidPixelHits;
1555     else if(variable == "numberOfValidPixelBarrelHits") value = object->numberOfValidPixelBarrelHits;
1556     else if(variable == "numberOfValidPixelEndcapHits") value = object->numberOfValidPixelEndcapHits;
1557     else if(variable == "isHEEP") value = object->isHEEP;
1558     else if(variable == "isHEEPnoEt") value = object->isHEEPnoEt;
1559     else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
1560     else if(variable == "eidRobustHighEnergy") value = object->eidRobustHighEnergy;
1561     else if(variable == "eidRobustLoose") value = object->eidRobustLoose;
1562     else if(variable == "eidRobustTight") value = object->eidRobustTight;
1563     else if(variable == "eidLoose") value = object->eidLoose;
1564     else if(variable == "eidTight") value = object->eidTight;
1565     else if(variable == "eidVeryLooseMC") value = object->eidVeryLooseMC;
1566     else if(variable == "eidLooseMC") value = object->eidLooseMC;
1567     else if(variable == "eidMediumMC") value = object->eidMediumMC;
1568     else if(variable == "eidTightMC") value = object->eidTightMC;
1569     else if(variable == "eidSuperTightMC") value = object->eidSuperTightMC;
1570     else if(variable == "eidHyperTight1MC") value = object->eidHyperTight1MC;
1571     else if(variable == "eidHyperTight2MC") value = object->eidHyperTight2MC;
1572     else if(variable == "eidHyperTight3MC") value = object->eidHyperTight3MC;
1573     else if(variable == "eidHyperTight4MC") value = object->eidHyperTight4MC;
1574     else if(variable == "passConvVeto") value = object->passConvVeto;
1575    
1576 lantonel 1.9 //user-defined variables
1577 ahart 1.31 else if(variable == "correctedD0VertexErr") value = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1578     else if(variable == "correctedD0VertexSig") value = object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1579 lantonel 1.13 else if(variable == "detIso") value = (object->trackIso) / object->pt;
1580 lantonel 1.10 else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1581 ahart 1.31 else if(variable == "metMT") {
1582     const BNmet *met = chosenMET ();
1583     if (met)
1584     {
1585     TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1586 wulsin 1.43 p2 (met->px, met->py, 0.0, met->pt);
1587 lantonel 1.26
1588 ahart 1.31 value = (p1 + p2).Mt ();
1589     }
1590     else
1591     value = -999;
1592     }
1593 lantonel 1.26
1594     else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
1595     if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
1596     else value = -999;
1597     }
1598     else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
1599     if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
1600 lantonel 1.19 else value = -999;
1601     }
1602 lantonel 1.26
1603     else if(variable == "correctedD0VertexInEBPlus"){
1604     if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1605     else value = -999;
1606     }
1607     else if(variable == "correctedD0VertexOutEBPlus"){
1608     if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1609     else value = -999;
1610     }
1611     else if(variable == "correctedD0VertexEEPlus"){
1612     if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
1613     else value = -999;
1614     }
1615    
1616     else if(variable == "correctedD0BeamspotInEBPlus"){
1617     if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1618     else value = -999;
1619     }
1620     else if(variable == "correctedD0BeamspotOutEBPlus"){
1621     if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1622 lantonel 1.19 else value = -999;
1623     }
1624 lantonel 1.26 else if(variable == "correctedD0BeamspotEEPlus"){
1625     if(object->isEE && object->eta > 0) value = object->correctedD0;
1626 lantonel 1.19 else value = -999;
1627     }
1628    
1629 lantonel 1.26 else if(variable == "correctedD0VertexInEBMinus"){
1630     if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1631 lantonel 1.19 else value = -999;
1632     }
1633 lantonel 1.26 else if(variable == "correctedD0VertexOutEBMinus"){
1634     if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1635 lantonel 1.19 else value = -999;
1636     }
1637 lantonel 1.26 else if(variable == "correctedD0VertexEEMinus"){
1638     if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
1639 lantonel 1.19 else value = -999;
1640     }
1641 lantonel 1.9
1642 lantonel 1.26 else if(variable == "correctedD0BeamspotInEBMinus"){
1643     if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1644 lantonel 1.19 else value = -999;
1645     }
1646 lantonel 1.26 else if(variable == "correctedD0BeamspotOutEBMinus"){
1647     if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1648 lantonel 1.19 else value = -999;
1649     }
1650 lantonel 1.26 else if(variable == "correctedD0BeamspotEEMinus"){
1651     if(object->isEE && object->eta < 0) value = object->correctedD0;
1652 lantonel 1.19 else value = -999;
1653     }
1654    
1655 ahart 1.31 else if(variable == "tightID"){
1656     if (object->isEB)
1657     {
1658     value = fabs(object->delEtaIn) < 0.004 \
1659     && fabs (object->delPhiIn) < 0.03 \
1660     && object->scSigmaIEtaIEta < 0.01 \
1661     && object->hadOverEm < 0.12 \
1662     && fabs (object->correctedD0Vertex) < 0.02 \
1663     && fabs (object->correctedDZ) < 0.1 \
1664     && object->absInvEMinusInvPin < 0.05 \
1665     && object->passConvVeto;
1666     }
1667     else
1668     {
1669     value = fabs(object->delEtaIn) < 0.005 \
1670     && fabs (object->delPhiIn) < 0.02 \
1671     && object->scSigmaIEtaIEta < 0.03 \
1672     && object->hadOverEm < 0.10 \
1673     && fabs (object->correctedD0Vertex) < 0.02 \
1674     && fabs (object->correctedDZ) < 0.1 \
1675     && object->absInvEMinusInvPin < 0.05 \
1676     && object->passConvVeto;
1677     }
1678     }
1679 lantonel 1.26
1680     else if(variable == "correctedD0VertexInEBPositiveCharge"){
1681     if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1682     else value = -999;
1683     }
1684     else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1685     if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1686     else value = -999;
1687     }
1688     else if(variable == "correctedD0VertexEEPositiveCharge"){
1689     if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
1690     else value = -999;
1691     }
1692    
1693     else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1694     if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1695     else value = -999;
1696     }
1697     else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1698     if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1699     else value = -999;
1700     }
1701     else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1702     if(object->isEE && object->charge > 0) value = object->correctedD0;
1703     else value = -999;
1704     }
1705    
1706     else if(variable == "correctedD0VertexInEBNegativeCharge"){
1707     if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1708     else value = -999;
1709     }
1710     else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1711     if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1712     else value = -999;
1713     }
1714     else if(variable == "correctedD0VertexEENegativeCharge"){
1715     if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
1716     else value = -999;
1717     }
1718    
1719     else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1720     if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1721     else value = -999;
1722     }
1723     else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1724     if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1725     else value = -999;
1726     }
1727     else if(variable == "correctedD0BeamspotEENegativeCharge"){
1728     if(object->isEE && object->charge < 0) value = object->correctedD0;
1729     else value = -999;
1730     }
1731    
1732    
1733 lantonel 1.19 else if(variable == "tightIDdisplaced"){
1734     if (object->isEB)
1735     {
1736 ahart 1.31 value = fabs(object->delEtaIn) < 0.004 \
1737     && fabs (object->delPhiIn) < 0.03 \
1738 lantonel 1.19 && object->scSigmaIEtaIEta < 0.01 \
1739     && object->hadOverEm < 0.12 \
1740 ahart 1.31 && object->absInvEMinusInvPin < 0.05;
1741 lantonel 1.19 }
1742     else
1743     {
1744 ahart 1.31 value = fabs (object->delEtaIn) < 0.005 \
1745     && fabs (object->delPhiIn) < 0.02 \
1746 lantonel 1.19 && object->scSigmaIEtaIEta < 0.03 \
1747     && object->hadOverEm < 0.10 \
1748 ahart 1.31 && object->absInvEMinusInvPin < 0.05;
1749 lantonel 1.19 }
1750     }
1751 lantonel 1.1
1752 lantonel 1.36
1753     else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1754    
1755     else if(variable == "genMatchedPdgId"){
1756     int index = getGenMatchedParticleIndex(object);
1757     if(index == -1) value = 0;
1758     else value = mcparticles->at(index).id;
1759     }
1760    
1761    
1762 lantonel 1.22 else if(variable == "genMatchedId"){
1763     int index = getGenMatchedParticleIndex(object);
1764     if(index == -1) value = 0;
1765     else value = getPdgIdBinValue(mcparticles->at(index).id);
1766     }
1767     else if(variable == "genMatchedMotherId"){
1768     int index = getGenMatchedParticleIndex(object);
1769     if(index == -1) value = 0;
1770     else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1771     }
1772 lantonel 1.36 else if(variable == "genMatchedMotherIdReverse"){
1773     int index = getGenMatchedParticleIndex(object);
1774     if(index == -1) value = 23;
1775     else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1776     }
1777 lantonel 1.22 else if(variable == "genMatchedGrandmotherId"){
1778     int index = getGenMatchedParticleIndex(object);
1779     if(index == -1) value = 0;
1780     else if(fabs(mcparticles->at(index).motherId) == 15){
1781     int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1782     if(motherIndex == -1) value = 0;
1783     else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1784     }
1785     else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1786     }
1787    
1788    
1789    
1790 lantonel 1.1 else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1791 ahart 1.8
1792 lantonel 1.6 value = applyFunction(function, value);
1793 lantonel 1.1
1794     return value;
1795     }
1796    
1797    
1798     double
1799 lantonel 1.3 OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
1800 lantonel 1.1
1801     double value = 0.0;
1802    
1803     if(variable == "weight") value = object->weight;
1804     else if(variable == "pthat") value = object->pthat;
1805     else if(variable == "qScale") value = object->qScale;
1806     else if(variable == "alphaQCD") value = object->alphaQCD;
1807     else if(variable == "alphaQED") value = object->alphaQED;
1808     else if(variable == "scalePDF") value = object->scalePDF;
1809     else if(variable == "x1") value = object->x1;
1810     else if(variable == "x2") value = object->x2;
1811     else if(variable == "xPDF1") value = object->xPDF1;
1812     else if(variable == "xPDF2") value = object->xPDF2;
1813     else if(variable == "BSx") value = object->BSx;
1814     else if(variable == "BSy") value = object->BSy;
1815     else if(variable == "BSz") value = object->BSz;
1816     else if(variable == "PVx") value = object->PVx;
1817     else if(variable == "PVy") value = object->PVy;
1818     else if(variable == "PVz") value = object->PVz;
1819     else if(variable == "bField") value = object->bField;
1820     else if(variable == "instLumi") value = object->instLumi;
1821     else if(variable == "bxLumi") value = object->bxLumi;
1822     else if(variable == "FilterOutScrapingFraction") value = object->FilterOutScrapingFraction;
1823     else if(variable == "sumNVtx") value = object->sumNVtx;
1824     else if(variable == "sumTrueNVtx") value = object->sumTrueNVtx;
1825     else if(variable == "nm1_true") value = object->nm1_true;
1826     else if(variable == "n0_true") value = object->n0_true;
1827     else if(variable == "np1_true") value = object->np1_true;
1828     else if(variable == "numTruePV") value = object->numTruePV;
1829     else if(variable == "Q2ScaleUpWgt") value = object->Q2ScaleUpWgt;
1830     else if(variable == "Q2ScaleDownWgt") value = object->Q2ScaleDownWgt;
1831     else if(variable == "rho_kt6PFJets") value = object->rho_kt6PFJets;
1832     else if(variable == "rho_kt6PFJetsCentralChargedPileUp") value = object->rho_kt6PFJetsCentralChargedPileUp;
1833     else if(variable == "rho_kt6PFJetsCentralNeutral") value = object->rho_kt6PFJetsCentralNeutral;
1834     else if(variable == "rho_kt6PFJetsCentralNeutralTight") value = object->rho_kt6PFJetsCentralNeutralTight;
1835     else if(variable == "run") value = object->run;
1836     else if(variable == "lumi") value = object->lumi;
1837     else if(variable == "sample") value = object->sample;
1838     else if(variable == "numPV") value = object->numPV;
1839     else if(variable == "W0decay") value = object->W0decay;
1840     else if(variable == "W1decay") value = object->W1decay;
1841     else if(variable == "Z0decay") value = object->Z0decay;
1842     else if(variable == "Z1decay") value = object->Z1decay;
1843     else if(variable == "H0decay") value = object->H0decay;
1844     else if(variable == "H1decay") value = object->H1decay;
1845     else if(variable == "hcalnoiseLoose") value = object->hcalnoiseLoose;
1846     else if(variable == "hcalnoiseTight") value = object->hcalnoiseTight;
1847     else if(variable == "GoodVertex") value = object->GoodVertex;
1848     else if(variable == "FilterOutScraping") value = object->FilterOutScraping;
1849     else if(variable == "HBHENoiseFilter") value = object->HBHENoiseFilter;
1850     else if(variable == "CSCLooseHaloId") value = object->CSCLooseHaloId;
1851     else if(variable == "CSCTightHaloId") value = object->CSCTightHaloId;
1852     else if(variable == "EcalLooseHaloId") value = object->EcalLooseHaloId;
1853     else if(variable == "EcalTightHaloId") value = object->EcalTightHaloId;
1854     else if(variable == "HcalLooseHaloId") value = object->HcalLooseHaloId;
1855     else if(variable == "HcalTightHaloId") value = object->HcalTightHaloId;
1856     else if(variable == "GlobalLooseHaloId") value = object->GlobalLooseHaloId;
1857     else if(variable == "GlobalTightHaloId") value = object->GlobalTightHaloId;
1858     else if(variable == "LooseId") value = object->LooseId;
1859     else if(variable == "TightId") value = object->TightId;
1860     else if(variable == "numGenPV") value = object->numGenPV;
1861     else if(variable == "nm1") value = object->nm1;
1862     else if(variable == "n0") value = object->n0;
1863     else if(variable == "np1") value = object->np1;
1864     else if(variable == "id1") value = object->id1;
1865     else if(variable == "id2") value = object->id2;
1866     else if(variable == "evt") value = object->evt;
1867 ahart 1.31 else if(variable == "puScaleFactor"){
1868     if(datasetType_ != "data")
1869     value = puWeight_->at (events->at (0).numTruePV);
1870     else
1871     value = 1.0;
1872     }
1873     else if(variable == "muonScaleFactor"){
1874     if(datasetType_ != "data")
1875 lantonel 1.36 // value = muonSFWeight_->at (chosenMuon ()->eta);
1876 wulsin 1.43 value = 1.0;
1877 ahart 1.31 else
1878     value = 1.0;
1879     }
1880     else if(variable == "electronScaleFactor"){
1881     if(datasetType_ != "data")
1882 lantonel 1.36 // value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1883 wulsin 1.43 value = 1.0;
1884 ahart 1.31 else
1885     value = 1.0;
1886     }
1887 ahart 1.45 else if(variable == "cTauScaleFactor")
1888     value = cTauScaleFactor_;
1889 lantonel 1.1
1890     else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1891 ahart 1.8
1892 lantonel 1.6 value = applyFunction(function, value);
1893 lantonel 1.1
1894     return value;
1895     }
1896    
1897     double
1898 lantonel 1.3 OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
1899 lantonel 1.1
1900     double value = 0.0;
1901    
1902     if(variable == "px") value = object->px;
1903     else if(variable == "py") value = object->py;
1904     else if(variable == "pz") value = object->pz;
1905     else if(variable == "energy") value = object->energy;
1906     else if(variable == "et") value = object->et;
1907     else if(variable == "pt") value = object->pt;
1908     else if(variable == "eta") value = object->eta;
1909     else if(variable == "phi") value = object->phi;
1910     else if(variable == "emFraction") value = object->emFraction;
1911     else if(variable == "leadingTrackPt") value = object->leadingTrackPt;
1912     else if(variable == "leadingTrackIpVtdxy") value = object->leadingTrackIpVtdxy;
1913     else if(variable == "leadingTrackIpVtdz") value = object->leadingTrackIpVtdz;
1914     else if(variable == "leadingTrackIpVtdxyError") value = object->leadingTrackIpVtdxyError;
1915     else if(variable == "leadingTrackIpVtdzError") value = object->leadingTrackIpVtdzError;
1916     else if(variable == "leadingTrackVx") value = object->leadingTrackVx;
1917     else if(variable == "leadingTrackVy") value = object->leadingTrackVy;
1918     else if(variable == "leadingTrackVz") value = object->leadingTrackVz;
1919     else if(variable == "leadingTrackValidHits") value = object->leadingTrackValidHits;
1920     else if(variable == "leadingTrackNormChiSqrd") value = object->leadingTrackNormChiSqrd;
1921     else if(variable == "numProngs") value = object->numProngs;
1922     else if(variable == "numSignalGammas") value = object->numSignalGammas;
1923     else if(variable == "numSignalNeutrals") value = object->numSignalNeutrals;
1924     else if(variable == "numSignalPiZeros") value = object->numSignalPiZeros;
1925     else if(variable == "decayMode") value = object->decayMode;
1926     else if(variable == "charge") value = object->charge;
1927     else if(variable == "inTheCracks") value = object->inTheCracks;
1928     else if(variable == "HPSagainstElectronLoose") value = object->HPSagainstElectronLoose;
1929     else if(variable == "HPSagainstElectronMVA") value = object->HPSagainstElectronMVA;
1930     else if(variable == "HPSagainstElectronMedium") value = object->HPSagainstElectronMedium;
1931     else if(variable == "HPSagainstElectronTight") value = object->HPSagainstElectronTight;
1932     else if(variable == "HPSagainstMuonLoose") value = object->HPSagainstMuonLoose;
1933     else if(variable == "HPSagainstMuonMedium") value = object->HPSagainstMuonMedium;
1934     else if(variable == "HPSagainstMuonTight") value = object->HPSagainstMuonTight;
1935     else if(variable == "HPSbyLooseCombinedIsolationDeltaBetaCorr") value = object->HPSbyLooseCombinedIsolationDeltaBetaCorr;
1936     else if(variable == "HPSbyMediumCombinedIsolationDeltaBetaCorr") value = object->HPSbyMediumCombinedIsolationDeltaBetaCorr;
1937     else if(variable == "HPSbyTightCombinedIsolationDeltaBetaCorr") value = object->HPSbyTightCombinedIsolationDeltaBetaCorr;
1938     else if(variable == "HPSbyVLooseCombinedIsolationDeltaBetaCorr") value = object->HPSbyVLooseCombinedIsolationDeltaBetaCorr;
1939     else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
1940     else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
1941    
1942    
1943 lantonel 1.36
1944     else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1945    
1946     else if(variable == "genMatchedPdgId"){
1947     int index = getGenMatchedParticleIndex(object);
1948     if(index == -1) value = 0;
1949     else value = mcparticles->at(index).id;
1950     }
1951    
1952 lantonel 1.22 else if(variable == "genMatchedId"){
1953     int index = getGenMatchedParticleIndex(object);
1954     if(index == -1) value = 0;
1955     else value = getPdgIdBinValue(mcparticles->at(index).id);
1956     }
1957     else if(variable == "genMatchedMotherId"){
1958     int index = getGenMatchedParticleIndex(object);
1959     if(index == -1) value = 0;
1960     else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1961     }
1962 lantonel 1.36 else if(variable == "genMatchedMotherIdReverse"){
1963     int index = getGenMatchedParticleIndex(object);
1964     if(index == -1) value = 23;
1965     else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1966     }
1967 lantonel 1.22 else if(variable == "genMatchedGrandmotherId"){
1968     int index = getGenMatchedParticleIndex(object);
1969     if(index == -1) value = 0;
1970     else if(fabs(mcparticles->at(index).motherId) == 15){
1971     int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1972     if(motherIndex == -1) value = 0;
1973     else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1974     }
1975     else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1976     }
1977    
1978    
1979 lantonel 1.1 else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1980 ahart 1.8
1981 lantonel 1.6 value = applyFunction(function, value);
1982 lantonel 1.1
1983     return value;
1984     }
1985    
1986     double
1987 lantonel 1.3 OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
1988 lantonel 1.1
1989     double value = 0.0;
1990    
1991     if(variable == "et") value = object->et;
1992     else if(variable == "pt") value = object->pt;
1993     else if(variable == "px") value = object->px;
1994     else if(variable == "py") value = object->py;
1995     else if(variable == "phi") value = object->phi;
1996     else if(variable == "Upt") value = object->Upt;
1997     else if(variable == "Uphi") value = object->Uphi;
1998     else if(variable == "NeutralEMFraction") value = object->NeutralEMFraction;
1999     else if(variable == "NeutralHadEtFraction") value = object->NeutralHadEtFraction;
2000     else if(variable == "ChargedEMEtFraction") value = object->ChargedEMEtFraction;
2001     else if(variable == "ChargedHadEtFraction") value = object->ChargedHadEtFraction;
2002     else if(variable == "MuonEtFraction") value = object->MuonEtFraction;
2003     else if(variable == "Type6EtFraction") value = object->Type6EtFraction;
2004     else if(variable == "Type7EtFraction") value = object->Type7EtFraction;
2005     else if(variable == "genPT") value = object->genPT;
2006     else if(variable == "genPhi") value = object->genPhi;
2007     else if(variable == "muonCorEx") value = object->muonCorEx;
2008     else if(variable == "muonCorEy") value = object->muonCorEy;
2009     else if(variable == "jet20CorEx") value = object->jet20CorEx;
2010     else if(variable == "jet20CorEy") value = object->jet20CorEy;
2011     else if(variable == "jet1CorEx") value = object->jet1CorEx;
2012     else if(variable == "jet1CorEy") value = object->jet1CorEy;
2013     else if(variable == "sumET") value = object->sumET;
2014     else if(variable == "corSumET") value = object->corSumET;
2015     else if(variable == "mEtSig") value = object->mEtSig;
2016     else if(variable == "metSignificance") value = object->metSignificance;
2017     else if(variable == "significance") value = object->significance;
2018     else if(variable == "sigmaX2") value = object->sigmaX2;
2019     else if(variable == "sigmaY2") value = object->sigmaY2;
2020     else if(variable == "sigmaXY") value = object->sigmaXY;
2021     else if(variable == "sigmaYX") value = object->sigmaYX;
2022     else if(variable == "maxEtInEmTowers") value = object->maxEtInEmTowers;
2023     else if(variable == "emEtFraction") value = object->emEtFraction;
2024     else if(variable == "emEtInEB") value = object->emEtInEB;
2025     else if(variable == "emEtInEE") value = object->emEtInEE;
2026     else if(variable == "emEtInHF") value = object->emEtInHF;
2027     else if(variable == "maxEtInHadTowers") value = object->maxEtInHadTowers;
2028     else if(variable == "hadEtFraction") value = object->hadEtFraction;
2029     else if(variable == "hadEtInHB") value = object->hadEtInHB;
2030     else if(variable == "hadEtInHE") value = object->hadEtInHE;
2031     else if(variable == "hadEtInHF") value = object->hadEtInHF;
2032     else if(variable == "hadEtInHO") value = object->hadEtInHO;
2033     else if(variable == "UDeltaPx") value = object->UDeltaPx;
2034     else if(variable == "UDeltaPy") value = object->UDeltaPy;
2035     else if(variable == "UDeltaP") value = object->UDeltaP;
2036     else if(variable == "Uscale") value = object->Uscale;
2037     else if(variable == "type2corPx") value = object->type2corPx;
2038     else if(variable == "type2corPy") value = object->type2corPy;
2039     else if(variable == "T2pt") value = object->T2pt;
2040     else if(variable == "T2px") value = object->T2px;
2041     else if(variable == "T2py") value = object->T2py;
2042     else if(variable == "T2phi") value = object->T2phi;
2043     else if(variable == "T2sumET") value = object->T2sumET;
2044     else if(variable == "pfT1jet1pt") value = object->pfT1jet1pt;
2045     else if(variable == "pfT1jet1phi") value = object->pfT1jet1phi;
2046     else if(variable == "pfT1jet6pt") value = object->pfT1jet6pt;
2047     else if(variable == "pfT1jet6phi") value = object->pfT1jet6phi;
2048     else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2049     else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2050    
2051     else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2052 ahart 1.8
2053 lantonel 1.6 value = applyFunction(function, value);
2054 lantonel 1.1
2055     return value;
2056     }
2057    
2058     double
2059 lantonel 1.3 OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2060 lantonel 1.1
2061     double value = 0.0;
2062 jbrinson 1.25 double pMag = sqrt(object->pt * object->pt +
2063 wulsin 1.42 object->pz * object->pz);
2064    
2065 lantonel 1.1 if(variable == "pt") value = object->pt;
2066     else if(variable == "px") value = object->px;
2067     else if(variable == "py") value = object->py;
2068     else if(variable == "pz") value = object->pz;
2069     else if(variable == "phi") value = object->phi;
2070     else if(variable == "eta") value = object->eta;
2071     else if(variable == "theta") value = object->theta;
2072     else if(variable == "normChi2") value = object->normChi2;
2073     else if(variable == "dZ") value = object->dZ;
2074     else if(variable == "d0") value = object->d0;
2075     else if(variable == "d0err") value = object->d0err;
2076     else if(variable == "vx") value = object->vx;
2077     else if(variable == "vy") value = object->vy;
2078     else if(variable == "vz") value = object->vz;
2079     else if(variable == "charge") value = object->charge;
2080     else if(variable == "numValidHits") value = object->numValidHits;
2081     else if(variable == "isHighPurity") value = object->isHighPurity;
2082 qpython 1.27
2083    
2084 ahart 1.31 //additional BNs info for disappTrks
2085 jbrinson 1.25 else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2086     else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2087     else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2088     else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2089     else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2090     else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2091     else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2092     else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2093     else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2094     else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2095 qpython 1.32
2096    
2097 jbrinson 1.25 //user defined variables
2098     else if(variable == "d0wrtBS") value = (object->vx-events->at(0).BSx)*object->py/object->pt - (object->vy-events->at(0).BSy)*object->px/object->pt;
2099     else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2100 wulsin 1.42 else if(variable == "caloTotDeltaRp5") value = (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2101     else if(variable == "caloTotDeltaRp5ByP") value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2102 wulsin 1.47 else if(variable == "caloTotDeltaRp5RhoCorr") value = getTrkCaloTotRhoCorr(object);
2103     else if(variable == "caloTotDeltaRp5ByPRhoCorr") value = getTrkCaloTotRhoCorr(object) / pMag;
2104 wulsin 1.42 else if(variable == "isIso") value = getTrkIsIso(object, tracks.product());
2105     else if(variable == "isMatchedDeadEcal") value = getTrkIsMatchedDeadEcal(object);
2106     else if(variable == "ptErrorByPt") value = (object->ptError/object->pt);
2107     else if(variable == "ptError") value = object->ptError;
2108     else if(variable == "ptRes") value = getTrkPtRes(object);
2109 wulsin 1.43 else if (variable == "d0wrtPV"){
2110     double vx = object->vx - chosenVertex ()->x,
2111     vy = object->vy - chosenVertex ()->y,
2112     px = object->px,
2113     py = object->py,
2114     pt = object->pt;
2115     value = (-vx * py + vy * px) / pt;
2116     }
2117     else if (variable == "dZwrtPV"){
2118     double vx = object->vx - chosenVertex ()->x,
2119     vy = object->vy - chosenVertex ()->y,
2120     vz = object->vz - chosenVertex ()->z,
2121     px = object->px,
2122     py = object->py,
2123     pz = object->pz,
2124     pt = object->pt;
2125     value = vz - (vx * px + vy * py)/pt * (pz/pt);
2126     }
2127 jbrinson 1.33 else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2128    
2129 lantonel 1.36 else if(variable == "genMatchedPdgId"){
2130 jbrinson 1.33 int index = getGenMatchedParticleIndex(object);
2131     if(index == -1) value = 0;
2132     else value = mcparticles->at(index).id;
2133     }
2134    
2135 biliu 1.40
2136 lantonel 1.22 else if(variable == "genMatchedId"){
2137     int index = getGenMatchedParticleIndex(object);
2138     if(index == -1) value = 0;
2139     else value = getPdgIdBinValue(mcparticles->at(index).id);
2140     }
2141     else if(variable == "genMatchedMotherId"){
2142     int index = getGenMatchedParticleIndex(object);
2143     if(index == -1) value = 0;
2144     else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2145     }
2146 lantonel 1.36 else if(variable == "genMatchedMotherIdReverse"){
2147     int index = getGenMatchedParticleIndex(object);
2148     if(index == -1) value = 23;
2149     else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2150     }
2151 lantonel 1.22 else if(variable == "genMatchedGrandmotherId"){
2152     int index = getGenMatchedParticleIndex(object);
2153     if(index == -1) value = 0;
2154     else if(fabs(mcparticles->at(index).motherId) == 15){
2155     int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2156     if(motherIndex == -1) value = 0;
2157     else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2158     }
2159     else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2160     }
2161    
2162    
2163    
2164 lantonel 1.1 else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2165 ahart 1.8
2166 lantonel 1.6 value = applyFunction(function, value);
2167 lantonel 1.1
2168     return value;
2169     }
2170    
2171     double
2172 lantonel 1.3 OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2173 lantonel 1.1
2174     double value = 0.0;
2175    
2176     if(variable == "pt") value = object->pt;
2177     else if(variable == "eta") value = object->eta;
2178     else if(variable == "phi") value = object->phi;
2179     else if(variable == "px") value = object->px;
2180     else if(variable == "py") value = object->py;
2181     else if(variable == "pz") value = object->pz;
2182     else if(variable == "et") value = object->et;
2183     else if(variable == "energy") value = object->energy;
2184     else if(variable == "mass") value = object->mass;
2185     else if(variable == "emEnergy") value = object->emEnergy;
2186     else if(variable == "hadEnergy") value = object->hadEnergy;
2187     else if(variable == "invisibleEnergy") value = object->invisibleEnergy;
2188     else if(variable == "auxiliaryEnergy") value = object->auxiliaryEnergy;
2189     else if(variable == "charge") value = object->charge;
2190    
2191    
2192     else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2193 ahart 1.8
2194 lantonel 1.6 value = applyFunction(function, value);
2195 lantonel 1.1
2196     return value;
2197     }
2198    
2199     double
2200 lantonel 1.3 OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2201 lantonel 1.1
2202     double value = 0.0;
2203    
2204     if(variable == "energy") value = object->energy;
2205     else if(variable == "et") value = object->et;
2206     else if(variable == "pt") value = object->pt;
2207     else if(variable == "px") value = object->px;
2208     else if(variable == "py") value = object->py;
2209     else if(variable == "pz") value = object->pz;
2210     else if(variable == "phi") value = object->phi;
2211     else if(variable == "eta") value = object->eta;
2212     else if(variable == "theta") value = object->theta;
2213     else if(variable == "mass") value = object->mass;
2214     else if(variable == "vx") value = object->vx;
2215     else if(variable == "vy") value = object->vy;
2216     else if(variable == "vz") value = object->vz;
2217     else if(variable == "motherET") value = object->motherET;
2218     else if(variable == "motherPT") value = object->motherPT;
2219     else if(variable == "motherPhi") value = object->motherPhi;
2220     else if(variable == "motherEta") value = object->motherEta;
2221     else if(variable == "mother0ET") value = object->mother0ET;
2222     else if(variable == "mother0PT") value = object->mother0PT;
2223     else if(variable == "mother0Phi") value = object->mother0Phi;
2224     else if(variable == "mother0Eta") value = object->mother0Eta;
2225     else if(variable == "mother1ET") value = object->mother1ET;
2226     else if(variable == "mother1PT") value = object->mother1PT;
2227     else if(variable == "mother1Phi") value = object->mother1Phi;
2228     else if(variable == "mother1Eta") value = object->mother1Eta;
2229     else if(variable == "daughter0ET") value = object->daughter0ET;
2230     else if(variable == "daughter0PT") value = object->daughter0PT;
2231     else if(variable == "daughter0Phi") value = object->daughter0Phi;
2232     else if(variable == "daughter0Eta") value = object->daughter0Eta;
2233     else if(variable == "daughter1ET") value = object->daughter1ET;
2234     else if(variable == "daughter1PT") value = object->daughter1PT;
2235     else if(variable == "daughter1Phi") value = object->daughter1Phi;
2236     else if(variable == "daughter1Eta") value = object->daughter1Eta;
2237     else if(variable == "grandMotherET") value = object->grandMotherET;
2238     else if(variable == "grandMotherPT") value = object->grandMotherPT;
2239     else if(variable == "grandMotherPhi") value = object->grandMotherPhi;
2240     else if(variable == "grandMotherEta") value = object->grandMotherEta;
2241     else if(variable == "grandMother00ET") value = object->grandMother00ET;
2242     else if(variable == "grandMother00PT") value = object->grandMother00PT;
2243     else if(variable == "grandMother00Phi") value = object->grandMother00Phi;
2244     else if(variable == "grandMother00Eta") value = object->grandMother00Eta;
2245     else if(variable == "grandMother01ET") value = object->grandMother01ET;
2246     else if(variable == "grandMother01PT") value = object->grandMother01PT;
2247     else if(variable == "grandMother01Phi") value = object->grandMother01Phi;
2248     else if(variable == "grandMother01Eta") value = object->grandMother01Eta;
2249     else if(variable == "grandMother10ET") value = object->grandMother10ET;
2250     else if(variable == "grandMother10PT") value = object->grandMother10PT;
2251     else if(variable == "grandMother10Phi") value = object->grandMother10Phi;
2252     else if(variable == "grandMother10Eta") value = object->grandMother10Eta;
2253     else if(variable == "grandMother11ET") value = object->grandMother11ET;
2254     else if(variable == "grandMother11PT") value = object->grandMother11PT;
2255     else if(variable == "grandMother11Phi") value = object->grandMother11Phi;
2256     else if(variable == "grandMother11Eta") value = object->grandMother11Eta;
2257     else if(variable == "charge") value = object->charge;
2258     else if(variable == "id") value = object->id;
2259     else if(variable == "status") value = object->status;
2260     else if(variable == "motherId") value = object->motherId;
2261     else if(variable == "motherCharge") value = object->motherCharge;
2262     else if(variable == "mother0Id") value = object->mother0Id;
2263     else if(variable == "mother0Status") value = object->mother0Status;
2264     else if(variable == "mother0Charge") value = object->mother0Charge;
2265     else if(variable == "mother1Id") value = object->mother1Id;
2266     else if(variable == "mother1Status") value = object->mother1Status;
2267     else if(variable == "mother1Charge") value = object->mother1Charge;
2268     else if(variable == "daughter0Id") value = object->daughter0Id;
2269     else if(variable == "daughter0Status") value = object->daughter0Status;
2270     else if(variable == "daughter0Charge") value = object->daughter0Charge;
2271     else if(variable == "daughter1Id") value = object->daughter1Id;
2272     else if(variable == "daughter1Status") value = object->daughter1Status;
2273     else if(variable == "daughter1Charge") value = object->daughter1Charge;
2274     else if(variable == "grandMotherId") value = object->grandMotherId;
2275     else if(variable == "grandMotherCharge") value = object->grandMotherCharge;
2276     else if(variable == "grandMother00Id") value = object->grandMother00Id;
2277     else if(variable == "grandMother00Status") value = object->grandMother00Status;
2278     else if(variable == "grandMother00Charge") value = object->grandMother00Charge;
2279     else if(variable == "grandMother01Id") value = object->grandMother01Id;
2280     else if(variable == "grandMother01Status") value = object->grandMother01Status;
2281     else if(variable == "grandMother01Charge") value = object->grandMother01Charge;
2282     else if(variable == "grandMother10Id") value = object->grandMother10Id;
2283     else if(variable == "grandMother10Status") value = object->grandMother10Status;
2284     else if(variable == "grandMother10Charge") value = object->grandMother10Charge;
2285     else if(variable == "grandMother11Id") value = object->grandMother11Id;
2286     else if(variable == "grandMother11Status") value = object->grandMother11Status;
2287     else if(variable == "grandMother11Charge") value = object->grandMother11Charge;
2288    
2289 lantonel 1.9 //user-defined variables
2290     else if (variable == "d0"){
2291 ahart 1.31 double vx = object->vx - chosenVertex ()->x,
2292     vy = object->vy - chosenVertex ()->y,
2293 lantonel 1.9 px = object->px,
2294     py = object->py,
2295     pt = object->pt;
2296     value = (-vx * py + vy * px) / pt;
2297     }
2298     else if (variable == "dz"){
2299 ahart 1.31 double vx = object->vx - chosenVertex ()->x,
2300     vy = object->vy - chosenVertex ()->y,
2301     vz = object->vz - chosenVertex ()->z,
2302 lantonel 1.9 px = object->px,
2303     py = object->py,
2304     pz = object->pz,
2305     pt = object->pt;
2306     value = vz - (vx * px + vy * py)/pt * (pz/pt);
2307     }
2308 lantonel 1.19 else if(variable == "v0"){
2309     value = sqrt(object->vx*object->vx + object->vy*object->vy);
2310     }
2311     else if(variable == "deltaV0"){
2312 ahart 1.31 value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
2313 lantonel 1.19 }
2314     else if (variable == "deltaVx"){
2315 ahart 1.31 value = object->vx - chosenVertex ()->x;
2316 lantonel 1.19 }
2317     else if (variable == "deltaVy"){
2318 ahart 1.31 value = object->vy - chosenVertex ()->y;
2319 lantonel 1.19 }
2320     else if (variable == "deltaVz"){
2321 ahart 1.31 value = object->vz - chosenVertex ()->z;
2322 lantonel 1.19 }
2323 lantonel 1.9
2324    
2325 lantonel 1.1 else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2326 ahart 1.8
2327 lantonel 1.6 value = applyFunction(function, value);
2328 lantonel 1.1
2329     return value;
2330     }
2331    
2332     double
2333 lantonel 1.3 OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2334 lantonel 1.1
2335     double value = 0.0;
2336    
2337     if(variable == "x") value = object->x;
2338     else if(variable == "xError") value = object->xError;
2339     else if(variable == "y") value = object->y;
2340     else if(variable == "yError") value = object->yError;
2341     else if(variable == "z") value = object->z;
2342     else if(variable == "zError") value = object->zError;
2343     else if(variable == "rho") value = object->rho;
2344     else if(variable == "normalizedChi2") value = object->normalizedChi2;
2345     else if(variable == "ndof") value = object->ndof;
2346     else if(variable == "isFake") value = object->isFake;
2347     else if(variable == "isValid") value = object->isValid;
2348     else if(variable == "tracksSize") value = object->tracksSize;
2349     else if(variable == "isGood") value = object->isGood;
2350    
2351    
2352     else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2353 ahart 1.8
2354 lantonel 1.6 value = applyFunction(function, value);
2355 lantonel 1.1
2356     return value;
2357     }
2358    
2359     double
2360 lantonel 1.3 OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2361 lantonel 1.1
2362     double value = 0.0;
2363    
2364     if(variable == "bx_B1_now") value = object->bx_B1_now;
2365     else if(variable == "bx_B2_now") value = object->bx_B2_now;
2366     else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2367    
2368    
2369     else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2370 ahart 1.8
2371 lantonel 1.6 value = applyFunction(function, value);
2372 lantonel 1.1
2373     return value;
2374     }
2375    
2376     double
2377 lantonel 1.3 OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2378 lantonel 1.1
2379     double value = 0.0;
2380    
2381     if(variable == "energy") value = object->energy;
2382     else if(variable == "et") value = object->et;
2383     else if(variable == "pt") value = object->pt;
2384     else if(variable == "px") value = object->px;
2385     else if(variable == "py") value = object->py;
2386     else if(variable == "pz") value = object->pz;
2387     else if(variable == "phi") value = object->phi;
2388     else if(variable == "eta") value = object->eta;
2389     else if(variable == "theta") value = object->theta;
2390     else if(variable == "trackIso") value = object->trackIso;
2391     else if(variable == "ecalIso") value = object->ecalIso;
2392     else if(variable == "hcalIso") value = object->hcalIso;
2393     else if(variable == "caloIso") value = object->caloIso;
2394     else if(variable == "trackIsoHollowConeDR03") value = object->trackIsoHollowConeDR03;
2395     else if(variable == "trackIsoSolidConeDR03") value = object->trackIsoSolidConeDR03;
2396     else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
2397     else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
2398     else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
2399     else if(variable == "trackIsoHollowConeDR04") value = object->trackIsoHollowConeDR04;
2400     else if(variable == "trackIsoSolidConeDR04") value = object->trackIsoSolidConeDR04;
2401     else if(variable == "ecalIsoDR04") value = object->ecalIsoDR04;
2402     else if(variable == "hcalIsoDR04") value = object->hcalIsoDR04;
2403     else if(variable == "caloIsoDR04") value = object->caloIsoDR04;
2404     else if(variable == "hadOverEm") value = object->hadOverEm;
2405     else if(variable == "sigmaEtaEta") value = object->sigmaEtaEta;
2406     else if(variable == "sigmaIetaIeta") value = object->sigmaIetaIeta;
2407     else if(variable == "r9") value = object->r9;
2408     else if(variable == "scEnergy") value = object->scEnergy;
2409     else if(variable == "scRawEnergy") value = object->scRawEnergy;
2410     else if(variable == "scSeedEnergy") value = object->scSeedEnergy;
2411     else if(variable == "scEta") value = object->scEta;
2412     else if(variable == "scPhi") value = object->scPhi;
2413     else if(variable == "scZ") value = object->scZ;
2414     else if(variable == "genET") value = object->genET;
2415     else if(variable == "genPT") value = object->genPT;
2416     else if(variable == "genPhi") value = object->genPhi;
2417     else if(variable == "genEta") value = object->genEta;
2418     else if(variable == "genMotherET") value = object->genMotherET;
2419     else if(variable == "genMotherPT") value = object->genMotherPT;
2420     else if(variable == "genMotherPhi") value = object->genMotherPhi;
2421     else if(variable == "genMotherEta") value = object->genMotherEta;
2422     else if(variable == "eMax") value = object->eMax;
2423     else if(variable == "eLeft") value = object->eLeft;
2424     else if(variable == "eRight") value = object->eRight;
2425     else if(variable == "eTop") value = object->eTop;
2426     else if(variable == "eBottom") value = object->eBottom;
2427     else if(variable == "e3x3") value = object->e3x3;
2428     else if(variable == "swissCross") value = object->swissCross;
2429     else if(variable == "seedEnergy") value = object->seedEnergy;
2430     else if(variable == "seedTime") value = object->seedTime;
2431     else if(variable == "swissCrossNoI85") value = object->swissCrossNoI85;
2432     else if(variable == "swissCrossI85") value = object->swissCrossI85;
2433     else if(variable == "E2overE9NoI85") value = object->E2overE9NoI85;
2434     else if(variable == "E2overE9I85") value = object->E2overE9I85;
2435     else if(variable == "IDTight") value = object->IDTight;
2436     else if(variable == "IDLoose") value = object->IDLoose;
2437     else if(variable == "IDLooseEM") value = object->IDLooseEM;
2438     else if(variable == "genId") value = object->genId;
2439     else if(variable == "genCharge") value = object->genCharge;
2440     else if(variable == "genMotherId") value = object->genMotherId;
2441     else if(variable == "genMotherCharge") value = object->genMotherCharge;
2442     else if(variable == "isEB") value = object->isEB;
2443     else if(variable == "isEE") value = object->isEE;
2444     else if(variable == "isGap") value = object->isGap;
2445     else if(variable == "isEBEEGap") value = object->isEBEEGap;
2446     else if(variable == "isEBGap") value = object->isEBGap;
2447     else if(variable == "isEEGap") value = object->isEEGap;
2448     else if(variable == "hasPixelSeed") value = object->hasPixelSeed;
2449     else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2450 biliu 1.40
2451    
2452 jbrinson 1.33
2453    
2454 lantonel 1.36 else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2455    
2456     else if(variable == "genMatchedPdgId"){
2457     int index = getGenMatchedParticleIndex(object);
2458     if(index == -1) value = 0;
2459     else value = mcparticles->at(index).id;
2460     }
2461 biliu 1.40
2462    
2463    
2464 lantonel 1.22 else if(variable == "genMatchedId"){
2465     int index = getGenMatchedParticleIndex(object);
2466     if(index == -1) value = 0;
2467     else value = getPdgIdBinValue(mcparticles->at(index).id);
2468     }
2469     else if(variable == "genMatchedMotherId"){
2470     int index = getGenMatchedParticleIndex(object);
2471     if(index == -1) value = 0;
2472     else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2473     }
2474 lantonel 1.36 else if(variable == "genMatchedMotherIdReverse"){
2475     int index = getGenMatchedParticleIndex(object);
2476     if(index == -1) value = 23;
2477     else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2478     }
2479 lantonel 1.22 else if(variable == "genMatchedGrandmotherId"){
2480     int index = getGenMatchedParticleIndex(object);
2481     if(index == -1) value = 0;
2482     else if(fabs(mcparticles->at(index).motherId) == 15){
2483     int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2484     if(motherIndex == -1) value = 0;
2485     else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2486     }
2487     else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2488     }
2489    
2490    
2491 lantonel 1.1 else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2492 ahart 1.8
2493 lantonel 1.6 value = applyFunction(function, value);
2494 lantonel 1.1
2495     return value;
2496     }
2497    
2498     double
2499 lantonel 1.3 OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
2500 lantonel 1.1
2501     double value = 0.0;
2502    
2503     if(variable == "energy") value = object->energy;
2504     else if(variable == "et") value = object->et;
2505     else if(variable == "ex") value = object->ex;
2506     else if(variable == "ey") value = object->ey;
2507     else if(variable == "ez") value = object->ez;
2508     else if(variable == "phi") value = object->phi;
2509     else if(variable == "eta") value = object->eta;
2510     else if(variable == "theta") value = object->theta;
2511    
2512    
2513     else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2514 ahart 1.8
2515 lantonel 1.6 value = applyFunction(function, value);
2516 lantonel 1.1
2517     return value;
2518     }
2519    
2520    
2521 lantonel 1.6 double
2522 lantonel 1.17 OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
2523    
2524     double value = 0.0;
2525    
2526 lantonel 1.23 if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2527 lantonel 1.44 else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2528 lantonel 1.23 else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2529 lantonel 1.17 else if(variable == "invMass"){
2530     TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2531     TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2532 lantonel 1.29 value = (fourVector1 + fourVector2).M();
2533     }
2534 lantonel 1.38 else if(variable == "pt"){
2535     TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2536     TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2537 biliu 1.41 value = (fourVector1 + fourVector2).Pt();
2538 lantonel 1.38 }
2539 qpython 1.20 else if(variable == "threeDAngle")
2540     {
2541     TVector3 threeVector1(object1->px, object1->py, object1->pz);
2542     TVector3 threeVector2(object2->px, object2->py, object2->pz);
2543     value = (threeVector1.Angle(threeVector2));
2544     }
2545 qpython 1.27 else if(variable == "alpha")
2546     {
2547     static const double pi = 3.1415926535897932384626433832795028841971693993751058;
2548     TVector3 threeVector1(object1->px, object1->py, object1->pz);
2549     TVector3 threeVector2(object2->px, object2->py, object2->pz);
2550 lantonel 1.29 value = (pi-threeVector1.Angle(threeVector2));
2551 qpython 1.27 }
2552 lantonel 1.18 else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2553     else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2554 lantonel 1.19 else if(variable == "d0Sign"){
2555     double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2556     if(d0Sign < 0) value = -0.5;
2557     else if (d0Sign > 0) value = 0.5;
2558     else value = -999;
2559     }
2560 lantonel 1.29 else if(variable == "chargeProduct"){
2561     value = object1->charge*object2->charge;
2562     }
2563 lantonel 1.19 else if(variable == "muon1CorrectedD0Vertex"){
2564     value = object1->correctedD0Vertex;
2565     }
2566     else if(variable == "muon2CorrectedD0Vertex"){
2567     value = object2->correctedD0Vertex;
2568     }
2569 wulsin 1.43 else if(variable == "muon1timeAtIpInOut"){
2570 qpython 1.27 value = object1->timeAtIpInOut;
2571     }
2572 wulsin 1.43 else if(variable == "muon2timeAtIpInOut"){
2573 qpython 1.27 value = object2->timeAtIpInOut;
2574     }
2575 wulsin 1.43 else if(variable == "muon1correctedD0")
2576     {
2577     value = object1->correctedD0;
2578     }
2579     else if(variable == "muon2correctedD0")
2580     {
2581     value = object2->correctedD0;
2582     }
2583 lantonel 1.36
2584 lantonel 1.19 else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2585    
2586 lantonel 1.17 value = applyFunction(function, value);
2587    
2588     return value;
2589     }
2590    
2591     double
2592     OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
2593    
2594     double value = 0.0;
2595    
2596 lantonel 1.23 if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2597 lantonel 1.44 else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2598 lantonel 1.23 else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2599 lantonel 1.17 else if(variable == "invMass"){
2600     TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2601     TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2602 lantonel 1.29 value = (fourVector1 + fourVector2).M();
2603     }
2604 lantonel 1.38 else if(variable == "pt"){
2605     TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2606     TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2607 biliu 1.41 value = (fourVector1 + fourVector2).Pt();
2608 lantonel 1.38 }
2609 lantonel 1.29 else if(variable == "threeDAngle")
2610 qpython 1.20 {
2611     TVector3 threeVector1(object1->px, object1->py, object1->pz);
2612     TVector3 threeVector2(object2->px, object2->py, object2->pz);
2613     value = (threeVector1.Angle(threeVector2));
2614     }
2615 lantonel 1.18 else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2616     else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2617 lantonel 1.19 else if(variable == "d0Sign"){
2618     double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2619     if(d0Sign < 0) value = -0.5;
2620     else if (d0Sign > 0) value = 0.5;
2621     else value = -999;
2622     }
2623 lantonel 1.29 else if(variable == "chargeProduct"){
2624     value = object1->charge*object2->charge;
2625     }
2626 lantonel 1.19 else if(variable == "electron1CorrectedD0Vertex"){
2627     value = object1->correctedD0Vertex;
2628     }
2629     else if(variable == "electron2CorrectedD0Vertex"){
2630     value = object2->correctedD0Vertex;
2631     }
2632 lantonel 1.36 else if(variable == "electron1CorrectedD0"){
2633     value = object1->correctedD0;
2634     }
2635     else if(variable == "electron2CorrectedD0"){
2636     value = object2->correctedD0;
2637     }
2638 qpython 1.20
2639 lantonel 1.17 else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2640    
2641     value = applyFunction(function, value);
2642    
2643     return value;
2644     }
2645    
2646     double
2647     OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
2648    
2649     double value = 0.0;
2650    
2651 lantonel 1.23 if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2652 lantonel 1.44 else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2653 lantonel 1.23 else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2654 lantonel 1.17 else if(variable == "invMass"){
2655     TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2656     TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2657 lantonel 1.29 value = (fourVector1 + fourVector2).M();
2658     }
2659 lantonel 1.38 else if(variable == "pt"){
2660     TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2661     TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2662 biliu 1.40 value = (fourVector1 + fourVector2).Pt();
2663 lantonel 1.38 }
2664 lantonel 1.29 else if(variable == "threeDAngle")
2665 qpython 1.20 {
2666     TVector3 threeVector1(object1->px, object1->py, object1->pz);
2667     TVector3 threeVector2(object2->px, object2->py, object2->pz);
2668     value = (threeVector1.Angle(threeVector2));
2669     }
2670 lantonel 1.18 else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2671     else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2672 lantonel 1.19 else if(variable == "d0Sign"){
2673     double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2674     if(d0Sign < 0) value = -0.5;
2675     else if (d0Sign > 0) value = 0.5;
2676     else value = -999;
2677     }
2678 lantonel 1.29 else if(variable == "chargeProduct"){
2679     value = object1->charge*object2->charge;
2680     }
2681 lantonel 1.19 else if(variable == "electronCorrectedD0Vertex"){
2682     value = object1->correctedD0Vertex;
2683     }
2684     else if(variable == "muonCorrectedD0Vertex"){
2685     value = object2->correctedD0Vertex;
2686     }
2687 lantonel 1.22 else if(variable == "electronCorrectedD0"){
2688     value = object1->correctedD0;
2689     }
2690     else if(variable == "muonCorrectedD0"){
2691     value = object2->correctedD0;
2692     }
2693 ahart 1.31 else if(variable == "electronDetIso"){
2694     value = (object1->trackIso) / object1->pt;
2695     }
2696     else if(variable == "muonDetIso"){
2697     value = (object2->trackIsoDR03) / object2->pt;
2698     }
2699 lantonel 1.44 else if(variable == "electronRelPFrhoIso"){
2700     value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
2701     }
2702     else if(variable == "muonRelPFdBetaIso"){
2703     value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
2704     }
2705 qpython 1.20
2706 lantonel 1.17 else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2707    
2708     value = applyFunction(function, value);
2709    
2710     return value;
2711     }
2712    
2713    
2714 wulsin 1.43 double
2715     OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function){
2716     double electronMass = 0.000511;
2717     double value = 0.0;
2718     TLorentzVector fourVector1(0, 0, 0, 0);
2719     TLorentzVector fourVector2(0, 0, 0, 0);
2720     if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2721 lantonel 1.44 else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2722 wulsin 1.43 else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2723     else if(variable == "invMass"){
2724     fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
2725     fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
2726    
2727     value = (fourVector1 + fourVector2).M();
2728     }
2729     else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2730     value = applyFunction(function, value);
2731     return value;
2732     }
2733    
2734    
2735    
2736     double
2737     OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function){
2738     double pionMass = 0.140;
2739     double muonMass = 0.106;
2740     double value = 0.0;
2741     TLorentzVector fourVector1(0, 0, 0, 0);
2742     TLorentzVector fourVector2(0, 0, 0, 0);
2743     if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2744 lantonel 1.44 else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2745 wulsin 1.43 else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2746     else if(variable == "invMass"){
2747     fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
2748     fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
2749    
2750     value = (fourVector1 + fourVector2).M();
2751     }
2752    
2753     else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2754     value = applyFunction(function, value);
2755     return value;
2756     }
2757    
2758    
2759     double
2760     OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function){
2761     double value = 0.0;
2762     if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2763 lantonel 1.44 else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2764 wulsin 1.43 else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2765     else if(variable == "invMass"){
2766     TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2767     TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2768     value = (fourVector1 + fourVector2).M();
2769     }
2770    
2771     else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2772     value = applyFunction(function, value);
2773     return value;
2774     }
2775    
2776    
2777     double
2778     OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function){
2779     double value = 0.0;
2780     if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2781 lantonel 1.44 else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2782 wulsin 1.43 else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2783     else if(variable == "invMass"){
2784     TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2785     TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2786     value = (fourVector1 + fourVector2).M();
2787     }
2788    
2789     else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2790     value = applyFunction(function, value);
2791     return value;
2792     }
2793 wulsin 1.42
2794 jbrinson 1.46 double
2795     OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function){
2796     double value = 0.0;
2797     if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2798     else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2799    
2800     else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2801     value = applyFunction(function, value);
2802     return value;
2803     }
2804    
2805    
2806 wulsin 1.42
2807     double
2808     OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function){
2809    
2810     double value = 0.0;
2811     double pMag = sqrt(object1->pt * object1->pt +
2812     object1->pz * object1->pz);
2813    
2814     if (variable == "numPV") value = object2->numPV;
2815     else if (variable == "caloTotDeltaRp5") value = (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
2816     else if (variable == "caloTotDeltaRp5ByP") value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
2817     else if (variable == "caloTotDeltaRp5_RhoCorr") value = getTrkCaloTotRhoCorr(object1);
2818     else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
2819    
2820     else { std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
2821    
2822     value = applyFunction(function, value);
2823    
2824     return value;
2825    
2826     }
2827    
2828 ahart 1.31 // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
2829     // Return true iff no other tracks are found in this cone.
2830     int
2831 jbrinson 1.25 OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
2832     for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
2833 ahart 1.31 if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
2834 jbrinson 1.28 double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
2835 jbrinson 1.25 if(deltaRtrk < 0.5) return 0;
2836     }
2837     return 1;
2838 ahart 1.31
2839 jbrinson 1.25 }
2840 jbrinson 1.28
2841    
2842 ahart 1.31 double
2843 jbrinson 1.28 OSUAnalysis::getTrkPtRes (const BNtrack* track1){
2844    
2845     double ptTrue = getTrkPtTrue(track1, mcparticles.product());
2846     double PtRes = (track1->pt - ptTrue) / ptTrue;
2847    
2848     return PtRes;
2849 ahart 1.31
2850 jbrinson 1.28 }
2851    
2852    
2853 ahart 1.31 double
2854 jbrinson 1.28 OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
2855     double value = -99;
2856     double genDeltaRLowest = 999;
2857    
2858     for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
2859     double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
2860     if (genDeltaRtemp < genDeltaRLowest) {
2861     genDeltaRLowest = genDeltaRtemp;
2862 ahart 1.31 if (genDeltaRLowest < 0.05) { // Only consider it truth-matched if DeltaR<0.15.
2863     double ptTrue = genPart->pt;
2864     value = ptTrue;
2865 jbrinson 1.28 }
2866 ahart 1.31 }
2867 jbrinson 1.28 }
2868    
2869     return value;
2870    
2871     }
2872    
2873 wulsin 1.42 double
2874     OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
2875     // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
2876     if (!useTrackCaloRhoCorr_) return -99;
2877     // if (!rhokt6CaloJetsHandle_) {
2878     // cout << "ERROR [getTrkCaloTotRhoCorr]: The collection rhokt6CaloJetsHandle is not available!" << endl;
2879     // return -99;
2880     // }
2881     double radDeltaRCone = 0.5;
2882     double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2); // Define effective area as pi*r^2, where r is radius of DeltaR cone.
2883     double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
2884     double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
2885     return caloTotRhoCorrCalo;
2886    
2887     }
2888    
2889    
2890    
2891    
2892 jbrinson 1.25 //creates a map of the dead Ecal channels in the barrel and endcap
2893     //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
2894     //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
2895 ahart 1.31 void
2896 jbrinson 1.25 OSUAnalysis::WriteDeadEcal (){
2897     double etaEcal, phiEcal;
2898     ifstream DeadEcalFile(deadEcalFile_);
2899     if(!DeadEcalFile) {
2900     cout << "Error: DeadEcalFile has not been found." << endl;
2901 ahart 1.31 return;
2902     }
2903     if(DeadEcalVec.size()!= 0){
2904 jbrinson 1.25 cout << "Error: DeadEcalVec has a nonzero size" << endl;
2905     return;
2906 ahart 1.31 }
2907 jbrinson 1.25 while(!DeadEcalFile.eof())
2908     {
2909     DeadEcalFile >> etaEcal >> phiEcal;
2910     DeadEcal newChan;
2911     newChan.etaEcal = etaEcal;
2912     newChan.phiEcal = phiEcal;
2913     DeadEcalVec.push_back(newChan);
2914     }
2915     if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
2916     }
2917    
2918     //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
2919 ahart 1.31 int
2920 jbrinson 1.25 OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
2921 jbrinson 1.28 double deltaRLowest = 999;
2922 jbrinson 1.25 int value = 0;
2923     if (DeadEcalVec.size() == 0) WriteDeadEcal();
2924     for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
2925     double eta = ecal->etaEcal;
2926     double phi = ecal->phiEcal;
2927 jbrinson 1.28 double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
2928     if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
2929 jbrinson 1.25 }
2930 jbrinson 1.28 if (deltaRLowest<0.05) {value = 1;}
2931     else {value = 0;}
2932 jbrinson 1.25 return value;
2933     }
2934    
2935 wulsin 1.34 // Returns the smallest DeltaR between the object and any generated true particle in the event.
2936 jbrinson 1.33 template <class InputObject>
2937     double OSUAnalysis::getGenDeltaRLowest(InputObject object){
2938     double genDeltaRLowest = 999.;
2939     for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
2940     double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
2941     if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
2942 wulsin 1.43 }
2943 jbrinson 1.33 return genDeltaRLowest;
2944     }
2945 jbrinson 1.25
2946 lantonel 1.17 double
2947 lantonel 1.6 OSUAnalysis::applyFunction(string function, double value){
2948    
2949 lantonel 1.9 if(function == "abs") value = fabs(value);
2950 lantonel 1.19 else if(function == "fabs") value = fabs(value);
2951 qpython 1.27 else if(function == "log10") value = log10(value);
2952     else if(function == "log") value = log10(value);
2953 lantonel 1.6
2954 lantonel 1.19 else if(function == "") value = value;
2955     else{std::cout << "WARNING: invalid function '" << function << "'\n";}
2956 lantonel 1.6
2957     return value;
2958    
2959     }
2960    
2961    
2962 ahart 1.8 template <class InputCollection>
2963 lantonel 1.1 void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
2964 lantonel 1.48
2965 wulsin 1.49 if (currentCut.inputCollection.find("pair")!=std::string::npos) {
2966     string obj1, obj2;
2967     getTwoObjs(currentCut.inputCollection, obj1, obj2);
2968     if (inputType==obj1 ||
2969     inputType==obj2) {
2970     // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
2971     // and the inputType is a member of the pair.
2972     // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
2973     // For example, if currentCut.inputCollection==electron-muon pairs,
2974     // then the flags should not be set here when inputType==muons or inputType==electrons.
2975     return;
2976     }
2977     }
2978    
2979 lantonel 1.1 for (uint object = 0; object != inputCollection->size(); object++){
2980 ahart 1.8
2981 lantonel 1.1 bool decision = true;//object passes if this cut doesn't cut on that type of object
2982 ahart 1.8
2983     if(currentCut.inputCollection == inputType){
2984    
2985 lantonel 1.17 vector<bool> subcutDecisions;
2986     for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
2987 ahart 1.31 double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
2988     subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
2989 wulsin 1.49
2990 lantonel 1.17 }
2991     if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
2992     else{
2993 ahart 1.31 bool tempDecision = true;
2994     for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
2995     if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
2996     tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
2997     else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
2998 lantonel 1.17 tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
2999 ahart 1.31 }
3000     decision = tempDecision;
3001 lantonel 1.17 }
3002 lantonel 1.1 }
3003 wulsin 1.49
3004 lantonel 1.14 individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3005 ahart 1.8
3006 lantonel 1.1 //set flags for objects that pass each cut AND all the previous cuts
3007     bool previousCumulativeFlag = true;
3008     for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3009 lantonel 1.14 if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
3010 lantonel 1.1 else{ previousCumulativeFlag = false; break;}
3011     }
3012 lantonel 1.14 cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3013 ahart 1.8
3014 lantonel 1.1 }
3015 ahart 1.8
3016 lantonel 1.1 }
3017    
3018    
3019 lantonel 1.17 template <class InputCollection1, class InputCollection2>
3020     void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
3021 ahart 1.31 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
3022 lantonel 1.17
3023    
3024     bool sameObjects = false;
3025     if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3026    
3027 wulsin 1.49 // Get the strings for the two objects that make up the pair.
3028     string obj1Type, obj2Type;
3029     getTwoObjs(inputType, obj1Type, obj2Type);
3030     bool isTwoTypesOfObject = true;
3031     if (obj1Type==obj2Type) isTwoTypesOfObject = false;
3032    
3033     // Initialize the flags for individual objects to all be false, if the cut is on the pair.
3034     // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
3035     if (currentCut.inputCollection == inputType) {
3036     for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
3037     individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3038     cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3039     }
3040     if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
3041     for (uint object2 = 0; object2 != inputCollection2->size(); object2++) {
3042     individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3043     cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3044     }
3045     }
3046     }
3047    
3048     int counter = 0;
3049 lantonel 1.23
3050 lantonel 1.17 for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3051     for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3052 ahart 1.31
3053 lantonel 1.17 if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3054    
3055    
3056     bool decision = true;//object passes if this cut doesn't cut on that type of object
3057    
3058     if(currentCut.inputCollection == inputType){
3059 ahart 1.31
3060     vector<bool> subcutDecisions;
3061     for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3062     double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3063     subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3064     }
3065    
3066     if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3067     else{
3068     bool tempDecision = subcutDecisions.at(0);
3069     for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
3070     if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
3071     tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
3072     else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
3073     tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
3074     }
3075     decision = tempDecision;
3076     }
3077 lantonel 1.17 }
3078 wulsin 1.49 // if (decision) isPassObj1.at(object1) = true;
3079     // if (decision) isPassObj2.at(object2) = true;
3080     individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3081     if (decision && currentCut.inputCollection == inputType) { // only set the flags for the individual objects if the pair object is being cut on
3082     individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;
3083     individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;
3084     }
3085 ahart 1.31
3086 lantonel 1.17 //set flags for objects that pass each cut AND all the previous cuts
3087     bool previousCumulativeFlag = true;
3088     for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3089 ahart 1.31 if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
3090     else{ previousCumulativeFlag = false; break;}
3091 lantonel 1.17 }
3092 lantonel 1.23 //apply flags for the components of the composite object as well
3093     bool currentCumulativeFlag = true;
3094     if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
3095     else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
3096     else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
3097     else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
3098     cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
3099 wulsin 1.49 if (currentCumulativeFlag && currentCut.inputCollection == inputType) { // only set the flags for the individual objects if the pair object is being cut on
3100     cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);
3101     cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);
3102     }
3103     counter++;
3104 lantonel 1.17
3105 wulsin 1.49 } // end for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3106     } // end for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3107 ahart 1.31
3108 wulsin 1.49 }
3109 lantonel 1.17
3110    
3111 wulsin 1.49 bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
3112     // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
3113     // all cuts up to currentCutIndex
3114     bool previousCumulativeFlag = true;
3115     for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
3116     if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
3117     else {
3118     previousCumulativeFlag = false; break;
3119     }
3120     }
3121     return previousCumulativeFlag;
3122     }
3123 lantonel 1.17
3124    
3125 lantonel 1.9 template <class InputCollection>
3126 ahart 1.31 void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3127 lantonel 1.14
3128     for (uint object = 0; object != inputCollection->size(); object++){
3129 lantonel 1.10
3130 lantonel 1.15 if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3131    
3132 lantonel 1.17 string currentString = parameters.inputVariables.at(0);
3133     string inputVariable = "";
3134     string function = "";
3135     if(currentString.find("(")==std::string::npos){
3136 ahart 1.31 inputVariable = currentString;// variable to cut on
3137 lantonel 1.17 }
3138     else{
3139 ahart 1.31 function = currentString.substr(0,currentString.find("("));//function comes before the "("
3140     inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3141     inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3142 lantonel 1.17 }
3143    
3144     double value = valueLookup(&inputCollection->at(object), inputVariable, function);
3145 ahart 1.31 histo->Fill(value,scaleFactor);
3146 lantonel 1.15
3147 wulsin 1.37 if (printEventInfo_) {
3148     // Write information about event to screen, for testing purposes.
3149     cout << " Info for event: value for histogram " << histo->GetName() << ": " << value << endl;
3150     }
3151    
3152 lantonel 1.15 }
3153     }
3154    
3155 lantonel 1.17 template <class InputCollection1, class InputCollection2>
3156 ahart 1.31 void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3157 lantonel 1.17
3158     bool sameObjects = false;
3159     if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3160    
3161 lantonel 1.48 int pairCounter = -1;
3162 lantonel 1.17 for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3163     for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3164 ahart 1.31
3165 lantonel 1.17 if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3166    
3167 lantonel 1.48 pairCounter++;
3168 lantonel 1.17 //only take objects which have passed all cuts and pairs which have passed all cuts
3169     if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3170     if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3171 lantonel 1.23 if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3172 lantonel 1.17
3173     string currentString = parameters.inputVariables.at(0);
3174     string inputVariable = "";
3175     string function = "";
3176     if(currentString.find("(")==std::string::npos){
3177 ahart 1.31 inputVariable = currentString;// variable to cut on
3178 lantonel 1.17 }
3179     else{
3180 ahart 1.31 function = currentString.substr(0,currentString.find("("));//function comes before the "("
3181     inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3182     inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3183 lantonel 1.17 }
3184 ahart 1.31
3185 lantonel 1.17 double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3186 ahart 1.31 histo->Fill(value,scaleFactor);
3187 lantonel 1.17
3188     }
3189     }
3190    
3191     }
3192    
3193    
3194 lantonel 1.15 template <class InputCollection>
3195 ahart 1.31 void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3196 lantonel 1.15
3197     for (uint object = 0; object != inputCollection->size(); object++){
3198    
3199     if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3200    
3201 lantonel 1.17 string currentString = parameters.inputVariables.at(0);
3202     string inputVariable = "";
3203     string function = "";
3204     if(currentString.find("(")==std::string::npos){
3205 ahart 1.31 inputVariable = currentString;// variable to cut on
3206 lantonel 1.17 }
3207     else{
3208 ahart 1.31 function = currentString.substr(0,currentString.find("("));//function comes before the "("
3209     inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3210     inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3211 lantonel 1.17 }
3212     double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
3213    
3214     currentString = parameters.inputVariables.at(1);
3215     inputVariable = "";
3216     function = "";
3217     if(currentString.find("(")==std::string::npos){
3218 ahart 1.31 inputVariable = currentString;// variable to cut on
3219 lantonel 1.17 }
3220     else{
3221 ahart 1.31 function = currentString.substr(0,currentString.find("("));//function comes before the "("
3222     inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3223     inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3224 lantonel 1.17 }
3225    
3226     double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
3227    
3228 ahart 1.31 histo->Fill(valueX,valueY,scaleFactor);
3229 lantonel 1.14
3230 lantonel 1.9 }
3231    
3232     }
3233    
3234 lantonel 1.17 template <class InputCollection1, class InputCollection2>
3235 ahart 1.31 void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3236 lantonel 1.17
3237     bool sameObjects = false;
3238     if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3239    
3240 lantonel 1.48 int pairCounter = -1;
3241 lantonel 1.17 for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3242     for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3243 ahart 1.31
3244 lantonel 1.17 if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3245    
3246 lantonel 1.48 pairCounter++;
3247    
3248 lantonel 1.17 //only take objects which have passed all cuts and pairs which have passed all cuts
3249     if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3250     if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3251 lantonel 1.23 if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3252 lantonel 1.17
3253     string currentString = parameters.inputVariables.at(0);
3254     string inputVariable = "";
3255     string function = "";
3256     if(currentString.find("(")==std::string::npos){
3257 ahart 1.31 inputVariable = currentString;// variable to cut on
3258 lantonel 1.17 }
3259     else{
3260 ahart 1.31 function = currentString.substr(0,currentString.find("("));//function comes before the "("
3261     inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3262     inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3263 lantonel 1.17 }
3264     double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3265    
3266     currentString = parameters.inputVariables.at(1);
3267     inputVariable = "";
3268     function = "";
3269     if(currentString.find("(")==std::string::npos){
3270 ahart 1.31 inputVariable = currentString;// variable to cut on
3271 lantonel 1.17 }
3272     else{
3273 ahart 1.31 function = currentString.substr(0,currentString.find("("));//function comes before the "("
3274     inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3275     inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3276 lantonel 1.17 }
3277     double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3278    
3279    
3280 ahart 1.31 histo->Fill(valueX,valueY,scaleFactor);
3281 lantonel 1.17
3282     }
3283     }
3284    
3285     }
3286 lantonel 1.1
3287    
3288 lantonel 1.22 template <class InputObject>
3289     int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
3290 lantonel 1.23
3291 lantonel 1.22 int bestMatchIndex = -1;
3292     double bestMatchDeltaR = 999;
3293 lantonel 1.23
3294 lantonel 1.22 for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3295    
3296     double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
3297     if(currentDeltaR > 0.05) continue;
3298 wulsin 1.43 // cout << std::setprecision(3) << std::setw(20)
3299     // << "\tcurrentParticle: eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
3300     // << std::setw(20)
3301     // << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
3302     // << std::setw(20)
3303     // << "\tdeltaR = " << currentDeltaR
3304     // << std::setprecision(1)
3305     // << std::setw(20)
3306     // << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
3307     // << std::setw(20)
3308     // << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
3309     // << std::setw(20)
3310     // << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
3311 lantonel 1.22 if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
3312     bestMatchIndex = mcparticle - mcparticles->begin();
3313     bestMatchDeltaR = currentDeltaR;
3314     }
3315    
3316     }
3317 wulsin 1.43 // if(bestMatchDeltaR != 999) cout << "bestMatch: deltaR = " << bestMatchDeltaR << " id = " << mcparticles->at(bestMatchIndex).id << " motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
3318     // else cout << "no match found..." << endl;
3319 lantonel 1.22 return bestMatchIndex;
3320    
3321     }
3322    
3323    
3324     int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
3325    
3326     int bestMatchIndex = -1;
3327     double bestMatchDeltaR = 999;
3328    
3329     for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3330    
3331     if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
3332    
3333     double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
3334     if(currentDeltaR > 0.05) continue;
3335    
3336     if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
3337     bestMatchIndex = mcparticle - mcparticles->begin();
3338     bestMatchDeltaR = currentDeltaR;
3339     }
3340    
3341     }
3342 lantonel 1.23
3343 lantonel 1.22 return bestMatchIndex;
3344     }
3345    
3346    
3347     // bin particle type
3348     // --- -------------
3349     // 0 unmatched
3350     // 1 u
3351     // 2 d
3352     // 3 s
3353     // 4 c
3354     // 5 b
3355     // 6 t
3356     // 7 e
3357     // 8 mu
3358     // 9 tau
3359     // 10 nu
3360     // 11 g
3361     // 12 gamma
3362     // 13 Z
3363     // 14 W
3364     // 15 light meson
3365     // 16 K meson
3366     // 17 D meson
3367     // 18 B meson
3368     // 19 light baryon
3369     // 20 strange baryon
3370     // 21 charm baryon
3371     // 22 bottom baryon
3372     // 23 other
3373    
3374     int OSUAnalysis::getPdgIdBinValue(int pdgId){
3375    
3376     int binValue = -999;
3377 ahart 1.31 int absPdgId = fabs(pdgId);
3378 lantonel 1.22 if(pdgId == -1) binValue = 0;
3379     else if(absPdgId <= 6 ) binValue = absPdgId;
3380     else if(absPdgId == 11 ) binValue = 7;
3381     else if(absPdgId == 13 ) binValue = 8;
3382     else if(absPdgId == 15 ) binValue = 9;
3383     else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
3384     else if(absPdgId == 21 ) binValue = 11;
3385     else if(absPdgId == 22 ) binValue = 12;
3386     else if(absPdgId == 23 ) binValue = 13;
3387     else if(absPdgId == 24 ) binValue = 14;
3388     else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130 ) binValue = 15;
3389     else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400) ) binValue = 16;
3390     else if(absPdgId > 400 && absPdgId < 500 ) binValue = 17;
3391     else if(absPdgId > 500 && absPdgId < 600 ) binValue = 18;
3392     else if(absPdgId > 1000 && absPdgId < 3000 ) binValue = 19;
3393     else if(absPdgId > 3000 && absPdgId < 4000 ) binValue = 20;
3394     else if(absPdgId > 4000 && absPdgId < 5000 ) binValue = 21;
3395     else if(absPdgId > 5000 && absPdgId < 6000 ) binValue = 22;
3396 lantonel 1.19
3397 lantonel 1.22 else binValue = 23;
3398    
3399     return binValue;
3400    
3401     }
3402 lantonel 1.19
3403 ahart 1.31 const BNprimaryvertex *
3404     OSUAnalysis::chosenVertex ()
3405     {
3406     const BNprimaryvertex *chosenVertex = 0;
3407     if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
3408     vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
3409 wulsin 1.43 cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
3410 ahart 1.31 for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
3411     if(!vertexFlags.at(vertexIndex)) continue;
3412     chosenVertex = & primaryvertexs->at(vertexIndex);
3413     break;
3414     }
3415     }
3416     else {
3417     chosenVertex = &primaryvertexs->at(0);
3418     }
3419    
3420     return chosenVertex;
3421     }
3422    
3423     const BNmet *
3424     OSUAnalysis::chosenMET ()
3425     {
3426     const BNmet *chosenMET = 0;
3427     if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
3428     vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
3429 wulsin 1.43 cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
3430 ahart 1.31 for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
3431     if(!metFlags.at(metIndex)) continue;
3432     chosenMET = & mets->at(metIndex);
3433     break;
3434     }
3435     }
3436     else {
3437     chosenMET = &mets->at(0);
3438     }
3439    
3440     return chosenMET;
3441     }
3442    
3443     const BNelectron *
3444     OSUAnalysis::chosenElectron ()
3445     {
3446     const BNelectron *chosenElectron = 0;
3447     if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
3448     vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
3449 wulsin 1.43 cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
3450 ahart 1.31 for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
3451     if(!electronFlags.at(electronIndex)) continue;
3452     chosenElectron = & electrons->at(electronIndex);
3453     break;
3454     }
3455     }
3456     else {
3457     chosenElectron = &electrons->at(0);
3458     }
3459    
3460     return chosenElectron;
3461     }
3462    
3463     const BNmuon *
3464     OSUAnalysis::chosenMuon ()
3465     {
3466     const BNmuon *chosenMuon = 0;
3467     if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
3468     vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
3469 wulsin 1.43 cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
3470 ahart 1.31 for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
3471     if(!muonFlags.at(muonIndex)) continue;
3472     chosenMuon = & muons->at(muonIndex);
3473     break;
3474     }
3475     }
3476     else {
3477     chosenMuon = &muons->at(0);
3478     }
3479 lantonel 1.1
3480 ahart 1.31 return chosenMuon;
3481     }
3482 lantonel 1.1
3483    
3484 ahart 1.31 DEFINE_FWK_MODULE(OSUAnalysis);