ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
Revision: 1.83
Committed: Wed Jun 5 03:18:56 2013 UTC (11 years, 11 months ago) by biliu
Content type: text/plain
Branch: MAIN
Changes since 1.82: +29 -5 lines
Log Message:
Added BtagScalingFactors.

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