ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
Revision: 1.86
Committed: Wed Jun 19 22:41:18 2013 UTC (11 years, 10 months ago) by lantonel
Content type: text/plain
Branch: MAIN
Changes since 1.85: +133 -75 lines
Log Message:
added option to add a bool, isVeto, to a cut definition.  This will cause only things FAILING this cut to be plotted

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