ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
Revision: 1.77
Committed: Fri May 31 11:24:31 2013 UTC (11 years, 11 months ago) by wulsin
Content type: text/plain
Branch: MAIN
CVS Tags: V02-02-00
Changes since 1.76: +67 -61 lines
Log Message:
add flag to fill the BNTree or not

File Contents

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