ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
Revision: 1.75
Committed: Fri May 31 09:15:04 2013 UTC (11 years, 11 months ago) by wulsin
Content type: text/plain
Branch: MAIN
Changes since 1.74: +1 -112 lines
Log Message:
Remove comments and debug statemets

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