ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
Revision: 1.125
Committed: Tue Sep 3 09:25:59 2013 UTC (11 years, 8 months ago) by lantonel
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.124: +244 -139 lines
Error occurred while calculating annotation data.
Log Message:
added secondary mcparticles, added top pt reweighting, added event-level scale factor variable

File Contents

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