ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
Revision: 1.116
Committed: Sun Aug 4 21:17:37 2013 UTC (11 years, 9 months ago) by wulsin
Content type: text/plain
Branch: MAIN
Changes since 1.115: +25 -0 lines
Log Message:
Add variables for lepton-track collections:  deltaRLooseID, deltaRLooseHadronicID, deltaRLooseMvaId

File Contents

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