ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
Revision: 1.94
Committed: Wed Jul 3 09:30:38 2013 UTC (11 years, 10 months ago) by jbrinson
Content type: text/plain
Branch: MAIN
CVS Tags: V02-03-01
Changes since 1.93: +35 -3 lines
Log Message:
Added track-jet value lookup and fixed typo in met-jet value lookup

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