ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
Revision: 1.80
Committed: Tue Jun 4 14:18:10 2013 UTC (11 years, 11 months ago) by wulsin
Content type: text/plain
Branch: MAIN
Changes since 1.79: +14 -4 lines
Log Message:
fix bug in filling of BNTree:  only fill for events that pass selection

File Contents

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