ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
Revision: 1.87
Committed: Thu Jun 20 16:20:24 2013 UTC (11 years, 10 months ago) by biliu
Content type: text/plain
Branch: MAIN
Changes since 1.86: +231 -6 lines
Log Message:
Added SFs for light jets and added muon-photon, electron-photon,photon-jet collections.

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