ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
Revision: 1.84
Committed: Thu Jun 6 11:44:32 2013 UTC (11 years, 11 months ago) by ahart
Content type: text/plain
Branch: MAIN
Changes since 1.83: +454 -445 lines
Log Message:
Fill only one TTree per channel with events passing all cuts even when GetPlotsAfterEachCut is true.

File Contents

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