ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
Revision: 1.103
Committed: Mon Jul 22 15:27:58 2013 UTC (11 years, 9 months ago) by wulsin
Content type: text/plain
Branch: MAIN
Changes since 1.102: +1 -1 lines
Log Message:
Rename electron looseId as looseID_MVA to avoid redundancy with cut-based looseID

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