ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
Revision: 1.41
Committed: Wed Mar 27 20:16:13 2013 UTC (12 years, 1 month ago) by biliu
Content type: text/plain
Branch: MAIN
Changes since 1.40: +2 -2 lines
Log Message:
Change Et() to Pt() for electron pair pt and muon pair pt as well.

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