ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
(Generate patch)

Comparing UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc (file contents):
Revision 1.70 by qpython, Wed May 29 15:29:27 2013 UTC vs.
Revision 1.116 by wulsin, Sun Aug 4 21:17:37 2013 UTC

# Line 1 | Line 1
1   #include "OSUT3Analysis/AnaTools/plugins/OSUAnalysis.h"
2
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")),
# Line 28 | Line 28 | OSUAnalysis::OSUAnalysis (const edm::Par
28    datasetType_ (cfg.getParameter<string> ("datasetType")),
29    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
30    histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
31 +  useEDMFormat_   (cfg.getParameter<bool>("useEDMFormat")),
32 +  treeBranchSets_   (cfg.getParameter<vector<edm::ParameterSet> >("treeBranchSets")),
33    plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
34    doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
35    applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
36 <  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
36 >  applyBtagSF_ (cfg.getParameter<bool> ("applyBtagSF")),
37 >  minBtag_ (cfg.getParameter<int> ("minBtag")),
38 >  printEventInfo_      (cfg.getParameter<bool> ("printEventInfo")),
39 >  printAllTriggers_    (cfg.getParameter<bool> ("printAllTriggers")),
40    useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
41    stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
42 <  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
43 < {
42 >  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut")),
43 >  verbose_ (cfg.getParameter<int> ("verbose"))
44 > {
45 >
46 >  if (verbose_) printEventInfo_ = true;  
47 >  if (verbose_) clog << "Beginning OSUAnalysis::OSUAnalysis constructor." << endl;  
48  
49 <  TH1::SetDefaultSumw2 ();
49 >  TH1::SetDefaultSumw2();
50  
51    //create pile-up reweighting object, if necessary
52    if(datasetType_ != "data") {
# Line 46 | Line 55 | OSUAnalysis::OSUAnalysis (const edm::Par
55        muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
56        electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
57      }
58 +    if (applyBtagSF_){
59 +      bTagSFWeight_ = new BtagSFWeight;
60 +    }
61    }
62    if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
63 <    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
63 >    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at(0), stopCTau_.at(1), stops_);
64  
65  
66    // Construct Cutflow Objects. These store the results of cut decisions and
# Line 57 | Line 69 | OSUAnalysis::OSUAnalysis (const edm::Par
69  
70    //always get vertex collection so we can assign the primary vertex in the event
71    objectsToGet.push_back("primaryvertexs");
60
61  //always make the plot of number of primary vertices (to check pile-up reweighting)
72    objectsToPlot.push_back("primaryvertexs");
73 +  objectsToFlag.push_back("primaryvertexs");
74 +
75  
76    //always get the MC particles to do GEN-matching
77    objectsToGet.push_back("mcparticles");
# Line 67 | Line 79 | OSUAnalysis::OSUAnalysis (const edm::Par
79    //always get the event collection to do pile-up reweighting
80    objectsToGet.push_back("events");
81  
82 +
83 +  // Parse the tree variable definitions.
84 +  for (uint iBranchSet = 0; !useEDMFormat_ && iBranchSet<treeBranchSets_.size(); iBranchSet++) {
85 +    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
86 +    if(tempInputCollection.find("pairs")!=string::npos) { clog << "Warning:  tree filling is not configured for pairs of objects, so will not work for collection: " << tempInputCollection << endl; }
87 +    objectsToGet.push_back(tempInputCollection);
88 +    objectsToFlag.push_back(tempInputCollection);
89 +
90 +    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
91 +
92 +    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
93 +      BranchSpecs br;
94 +      br.inputCollection = tempInputCollection;
95 +      br.inputVariable = branchList.at(iBranch);
96 +      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);
97 +      br.name = string(newName.Data());
98 +      treeBranches_.push_back(br);
99 +      if (verbose_>3) clog << "   Adding branch to BNTree: " << br.name << endl;  
100 +    }
101 +
102 +  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++)
103 +
104 +
105    //parse the histogram definitions
106    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
107  
108      string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
109      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
110 +    if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
111 +    if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
112      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
113 +    if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
114      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
115 +    if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
116 +    if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
117 +    if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
118      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
119      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
120 +    if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
121 +    if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
122 +    if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
123 +    if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
124 +    if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
125      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
126      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
127      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
# Line 89 | Line 135 | OSUAnalysis::OSUAnalysis (const edm::Par
135          objectsToGet.push_back(tempInputCollection);
136        }
137        objectsToPlot.push_back(tempInputCollection);
138 <      objectsToCut.push_back(tempInputCollection);
139 <    }
94 <    else{//pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
138 >      objectsToFlag.push_back(tempInputCollection);
139 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
140        string obj1;
141        string obj2;
142        getTwoObjs(tempInputCollection, obj1, obj2);
143        string obj2ToGet = getObjToGet(obj2);
144 <      objectsToCut.push_back(tempInputCollection);
145 <      objectsToCut.push_back(obj1);
146 <      objectsToCut.push_back(obj2);
144 >      objectsToFlag.push_back(tempInputCollection);
145 >      objectsToFlag.push_back(obj1);
146 >      objectsToFlag.push_back(obj2);
147        objectsToPlot.push_back(tempInputCollection);
148        objectsToPlot.push_back(obj1);
149        objectsToPlot.push_back(obj2);
150        objectsToGet.push_back(tempInputCollection);
151        objectsToGet.push_back(obj1);
152        objectsToGet.push_back(obj2ToGet);
153 <
154 <    }
155 <
153 >    } // end else
154 >    if (find(objectsToPlot.begin(), objectsToPlot.end(), "events") != objectsToPlot.end())
155 >      objectsToGet.push_back("jets");
156 >    
157 >    
158      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
159  
160      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
# Line 127 | Line 174 | OSUAnalysis::OSUAnalysis (const edm::Par
174        histograms.push_back(tempHistogram);
175  
176      }
177 <  }
177 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
178 >
179    //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
180    sort( objectsToPlot.begin(), objectsToPlot.end() );
181    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
# Line 138 | Line 186 | OSUAnalysis::OSUAnalysis (const edm::Par
186    for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
187  
188      string currentObject = objectsToPlot.at(currentObjectIndex);
189 <    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
189 >    if(currentObject != "muons" &&
190 >       currentObject != "secondary muons" &&
191 >       currentObject != "secondary electrons" &&
192 >       currentObject != "electrons" &&
193 >       currentObject != "taus" &&
194 >       currentObject != "tracks" &&
195 >       currentObject != "photons" &&
196 >       currentObject != "secondary photons"&&
197 >       currentObject != "superclusters")
198 >      continue;
199  
200      histogram tempIdHisto;
201      histogram tempMomIdHisto;
# Line 153 | Line 210 | OSUAnalysis::OSUAnalysis (const edm::Par
210      tempIdVsGmaIdHisto.inputCollection = currentObject;
211  
212      if(currentObject == "secondary muons") currentObject = "secondaryMuons";
213 +    if(currentObject == "secondary photons") currentObject = "secondaryPhotons";
214      if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
215  
216      currentObject = currentObject.substr(0, currentObject.size()-1);
# Line 208 | Line 266 | OSUAnalysis::OSUAnalysis (const edm::Par
266      string channelName  (channels_.at(currentChannel).getParameter<string>("name"));
267      tempChannel.name = channelName;
268      TString channelLabel = channelName;
269 +    if (verbose_) clog << "Processing channel:  " << channelName << endl;  
270  
271      //set triggers for this channel
272      vector<string> triggerNames;
273      triggerNames.clear();
274 +    vector<string> triggerToVetoNames;
275 +    triggerToVetoNames.clear();
276 +
277      tempChannel.triggers.clear();
278 +    tempChannel.triggersToVeto.clear();
279      if(channels_.at(currentChannel).exists("triggers")){
280        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
281        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
282          tempChannel.triggers.push_back(triggerNames.at(trigger));
283        objectsToGet.push_back("triggers");
284      }
285 <
285 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
286 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
287 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
288 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
289 >      objectsToGet.push_back("triggers");
290 >    }
291  
292  
293  
294      //create cutFlow for this channel
295      cutFlows_.push_back (new CutFlow (fs_, channelName));
296      vector<TFileDirectory> directories; //vector of directories in the output file.
297 +    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
298      vector<string> subSubDirNames;//subdirectories in each channel.
299      //get list of cuts for this channel
300      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
# Line 237 | Line 306 | OSUAnalysis::OSUAnalysis (const edm::Par
306        //store input collection for cut
307        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
308        if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
309 +      if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
310 +      if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
311        if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
312        if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
313 +      if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
314 +      if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
315 +      if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
316 +      if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
317        if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
318        if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
319 +      if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
320 +      if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
321 +      if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
322 +      if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
323 +      if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
324        if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
325        if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
326        if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
327        tempCut.inputCollection = tempInputCollection;
328        if(tempInputCollection.find("pairs")==string::npos){ //just a single object
329          if(tempInputCollection.find("secondary")!=string::npos){//secondary object
330 <          int spaceIndex = tempInputCollection.find(" ");
331 <          int secondWordLength = tempInputCollection.size() - spaceIndex;
332 <          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
330 >          if(tempInputCollection.find("secondary muons")!=string::npos){//treat secondary muons differently; allow for a different input collection
331 >            objectsToGet.push_back("secondary muons");  
332 >          } else {
333 >            int spaceIndex = tempInputCollection.find(" ");
334 >            int secondWordLength = tempInputCollection.size() - spaceIndex;
335 >            objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
336 >          }
337          }
338          else{
339            objectsToGet.push_back(tempInputCollection);
340          }
341          objectsToCut.push_back(tempInputCollection);
342 +        objectsToFlag.push_back(tempInputCollection);
343        }
344        else{//pair of objects, need to add them both to objectsToGet
345          string obj1;
# Line 264 | Line 349 | OSUAnalysis::OSUAnalysis (const edm::Par
349          objectsToCut.push_back(tempInputCollection);
350          objectsToCut.push_back(obj1);
351          objectsToCut.push_back(obj2);
352 +        objectsToFlag.push_back(tempInputCollection);
353 +        objectsToFlag.push_back(obj1);
354 +        objectsToFlag.push_back(obj2);
355          objectsToGet.push_back(tempInputCollection);
356          objectsToGet.push_back(obj1);
357          objectsToGet.push_back(obj2ToGet);
# Line 276 | Line 364 | OSUAnalysis::OSUAnalysis (const edm::Par
364        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
365        vector<string> cutStringVector = splitString(cutString);
366        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
367 <        cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
367 >        clog << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
368          exit(0);
369        }
370        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
# Line 302 | Line 390 | OSUAnalysis::OSUAnalysis (const edm::Par
390        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
391        vector<string> numberRequiredVector = splitString(numberRequiredString);
392        if(numberRequiredVector.size()!=2){
393 <        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
393 >        clog << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
394          exit(0);
395        }
396  
# Line 310 | Line 398 | OSUAnalysis::OSUAnalysis (const edm::Par
398        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
399        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
400  
401 <      //Set up vectors to store the directories and subDIrectories for each channel.
401 >      //Set up vectors to store the directories and subDirectories for each channel.
402        string subSubDirName;
403        string tempCutName;
404        if(cuts_.at(currentCut).exists("alias")){
405          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
406 <        subSubDirName = "After " + cuts_.at(currentCut).getParameter<string> ("alias") + " Cut Applied";
406 >        subSubDirName = "After " + tempCutName + " Cut Applied";
407        }
408        else{
409          //construct string for cutflow table
# Line 326 | Line 414 | OSUAnalysis::OSUAnalysis (const edm::Par
414          subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
415        }
416  
417 +      tempCut.isVeto = false;
418 +      if(cuts_.at(currentCut).exists("isVeto")){
419 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
420 +        if (isVeto == true) tempCut.isVeto = true;
421 +      }
422        subSubDirNames.push_back(subSubDirName);
423        tempCut.name = tempCutName;
424 +      if (verbose_) clog << "Setting up cut, index: " << currentCut << ", input collection: " << tempInputCollection<< ", name: " << tempCut.name << endl;  
425  
426        tempChannel.cuts.push_back(tempCut);
427  
# Line 340 | Line 434 | OSUAnalysis::OSUAnalysis (const edm::Par
434      TFileDirectory subDir = fs_->mkdir( channelName );
435      //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
436      if(GetPlotsAfterEachCut_){
437 <       for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
438 <            TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
439 <            directories.push_back(subSubDir);
440 <            map<string, TH1D*> oneDhistoMap;
441 <            oneDHistsTmp.push_back(oneDhistoMap);
442 <            map<string, TH2D*> twoDhistoMap;
443 <            twoDHistsTmp.push_back(twoDhistoMap);
437 >      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
438 >        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
439 >        directories.push_back(subSubDir);
440 >        map<string, TH1D*> oneDhistoMap;
441 >        oneDHistsTmp.push_back(oneDhistoMap);
442 >        map<string, TH2D*> twoDhistoMap;
443 >        twoDHistsTmp.push_back(twoDhistoMap);
444        }
445 +      treeDirectories.push_back(subDir);
446        oneDHists_.push_back(oneDHistsTmp);
447        twoDHists_.push_back(twoDHistsTmp);
448      }
449 <   //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
450 <   else{
449 >    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
450 >    else{
451        map<string, TH1D*> oneDhistoMap;
452        oneDHistsTmp.push_back(oneDhistoMap);
453        map<string, TH2D*> twoDhistoMap;
# Line 360 | Line 455 | OSUAnalysis::OSUAnalysis (const edm::Par
455        oneDHists_.push_back(oneDHistsTmp);
456        twoDHists_.push_back(twoDHistsTmp);
457        directories.push_back(subDir);
458 <   }
458 >      treeDirectories.push_back(subDir);
459 >
460 >    }
461 >
462 >    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
463 >      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
464 >      BNTrees_.push_back(newTree);
465 >      BNTrees_.back()->Branch("event_runInt",  &BNTreeBranchVals_runInt_,  "event_runInt/I");      
466 >      BNTrees_.back()->Branch("event_lumiInt", &BNTreeBranchVals_lumiInt_, "event_lumiInt/I");      
467 >      BNTrees_.back()->Branch("event_evtLong", &BNTreeBranchVals_evtLong_, "event_evtLong/L");      
468 >      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
469 >        BranchSpecs currentVar = treeBranches_.at(iBranch);
470 >        vector<float> newVec;
471 >        BNTreeBranchVals_[currentVar.name] = newVec;
472 >        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
473 >      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
474 >    }
475 >
476      //book all histograms included in the configuration
477      for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
478 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
479 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
480 <      int numBinsElements = currentHistogram.bins.size();
481 <      int numInputVariables = currentHistogram.inputVariables.size();
482 <      int numBinEdgesX = currentHistogram.variableBinsX.size();
483 <      int numBinEdgesY = currentHistogram.variableBinsY.size();
484 <
485 <      if(numBinsElements == 1){
486 <        if(numBinEdgesX > 1){
487 <          if(numBinEdgesY > 1)
488 <            numBinsElements = 6;
478 >
479 >      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
480 >
481 >        histogram currentHistogram = histograms.at(currentHistogramIndex);
482 >        int numBinsElements = currentHistogram.bins.size();
483 >        int numInputVariables = currentHistogram.inputVariables.size();
484 >        int numBinEdgesX = currentHistogram.variableBinsX.size();
485 >        int numBinEdgesY = currentHistogram.variableBinsY.size();
486 >
487 >        if(numBinsElements == 1){
488 >          if(numBinEdgesX > 1){
489 >            if(numBinEdgesY > 1)
490 >              numBinsElements = 6;
491 >            else
492 >              numBinsElements = 3;
493 >          }
494 >        }
495 >        if(numBinsElements != 3 && numBinsElements !=6){
496 >          clog << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
497 >          exit(0);
498 >        }
499 >        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
500 >          clog << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
501 >          exit(0);
502 >        }
503 >        else if(numBinsElements == 3){
504 >          if (currentHistogram.bins.size () == 3)
505 >            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
506            else
507 <            numBinsElements = 3;
507 >            {
508 >              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
509 >            }
510          }
511 <      }
512 <      if(numBinsElements != 3 && numBinsElements !=6){
513 <        cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
514 <        exit(0);
515 <      }
516 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
517 <        cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
518 <        exit(0);
519 <      }
520 <      else if(numBinsElements == 3){
521 <        if (currentHistogram.bins.size () == 3)
522 <          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));
523 <        else
524 <          {
525 <            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
511 >        else if(numBinsElements == 6){
512 >          if (currentHistogram.bins.size () == 6)
513 >            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2),currentHistogram.bins.at(3),currentHistogram.bins.at(4),currentHistogram.bins.at(5));
514 >          else
515 >            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data (), numBinEdgesY - 1, currentHistogram.variableBinsY.data ());
516 >        }
517 >
518 >
519 >        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
520 >
521 >        // bin      particle type
522 >        // ---      -------------
523 >        //  0        unmatched
524 >        //  1        u
525 >        //  2        d
526 >        //  3        s
527 >        //  4        c
528 >        //  5        b
529 >        //  6        t
530 >        //  7        e
531 >        //  8        mu
532 >        //  9        tau
533 >        // 10        nu
534 >        // 11        g
535 >        // 12        gamma
536 >        // 13        Z
537 >        // 14        W
538 >        // 15        light meson
539 >        // 16        K meson
540 >        // 17        D meson
541 >        // 18        B meson
542 >        // 19        light baryon
543 >        // 20        strange baryon
544 >        // 21        charm baryon
545 >        // 22        bottom baryon
546 >        // 23        QCD string
547 >        // 24        other
548 >
549 >        vector<TString> labelArray;
550 >        labelArray.push_back("unmatched");
551 >        labelArray.push_back("u");
552 >        labelArray.push_back("d");
553 >        labelArray.push_back("s");
554 >        labelArray.push_back("c");
555 >        labelArray.push_back("b");
556 >        labelArray.push_back("t");
557 >        labelArray.push_back("e");
558 >        labelArray.push_back("#mu");
559 >        labelArray.push_back("#tau");
560 >        labelArray.push_back("#nu");
561 >        labelArray.push_back("g");
562 >        labelArray.push_back("#gamma");
563 >        labelArray.push_back("Z");
564 >        labelArray.push_back("W");
565 >        labelArray.push_back("light meson");
566 >        labelArray.push_back("K meson");
567 >        labelArray.push_back("D meson");
568 >        labelArray.push_back("B meson");
569 >        labelArray.push_back("light baryon");
570 >        labelArray.push_back("strange baryon");
571 >        labelArray.push_back("charm baryon");
572 >        labelArray.push_back("bottom baryon");
573 >        labelArray.push_back("QCD string");
574 >        labelArray.push_back("other");
575 >
576 >        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
577 >          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
578 >            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
579            }
580 <      }
581 <      else if(numBinsElements == 6){
582 <        if (currentHistogram.bins.size () == 6)
583 <          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));
584 <        else
585 <          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 ());
586 <      }
580 >          else {
581 >            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
582 >            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
583 >          }
584 >        }
585 >        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
586 >          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
587 >          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
588 >        }
589  
590 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
591  
405      if(currentHistogram.name.find("GenMatch")==string::npos) continue;
592  
593 <      // bin      particle type
594 <      // ---      -------------
595 <      //  0        unmatched
596 <      //  1        u
597 <      //  2        d
598 <      //  3        s
599 <      //  4        c
600 <      //  5        b
601 <      //  6        t
602 <      //  7        e
603 <      //  8        mu
604 <      //  9        tau
605 <      // 10        nu
606 <      // 11        g
607 <      // 12        gamma
608 <      // 13        Z
609 <      // 14        W
610 <      // 15        light meson
611 <      // 16        K meson
612 <      // 17        D meson
613 <      // 18        B meson
614 <      // 19        light baryon
615 <      // 20        strange baryon
616 <      // 21        charm baryon
617 <      // 22        bottom baryon
618 <      // 23        QCD string
619 <      // 24        other
620 <
621 <      vector<TString> labelArray;
622 <      labelArray.push_back("unmatched");
623 <      labelArray.push_back("u");
624 <      labelArray.push_back("d");
625 <      labelArray.push_back("s");
626 <      labelArray.push_back("c");
627 <      labelArray.push_back("b");
628 <      labelArray.push_back("t");
629 <      labelArray.push_back("e");
630 <      labelArray.push_back("#mu");
631 <      labelArray.push_back("#tau");
632 <      labelArray.push_back("#nu");
633 <      labelArray.push_back("g");
634 <      labelArray.push_back("#gamma");
635 <      labelArray.push_back("Z");
636 <      labelArray.push_back("W");
637 <      labelArray.push_back("light meson");
638 <      labelArray.push_back("K meson");
639 <      labelArray.push_back("D meson");
640 <      labelArray.push_back("B meson");
641 <      labelArray.push_back("light baryon");
642 <      labelArray.push_back("strange baryon");
643 <      labelArray.push_back("charm baryon");
644 <      labelArray.push_back("bottom baryon");
645 <      labelArray.push_back("QCD string");
646 <      labelArray.push_back("other");
647 <
648 <      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
649 <        if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
650 <          oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
651 <        }
652 <        else {
653 <          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
654 <          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
655 <        }
656 <      }
657 <      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
658 <        twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
659 <        twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
660 <      }
661 <
662 <    }
663 <
664 <    // Book a histogram for the number of each object type to be plotted.
665 <    // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
666 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
667 <      string currentObject = objectsToPlot.at(currentObjectIndex);
668 <      int maxNum = 10;
669 <      if(currentObject == "mcparticles") maxNum = 50;
670 <      else if(currentObject == "primaryvertexs") maxNum = 50;
671 <
672 <      if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
673 <      else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
674 <      else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
675 <      else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
676 <      else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
677 <      else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
678 <      else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
679 <      else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
494 <      else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
495 <      else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
496 <      else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
497 <      else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
498 <      else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
499 <      else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
500 <      else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
501 <      else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
502 <      else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
503 <      else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
504 <      else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
505 <
506 <      currentObject.at(0) = toupper(currentObject.at(0));
507 <      string histoName = "num" + currentObject;
508 <
509 <      if(histoName == "numPrimaryvertexs"){
510 <        string newHistoName = histoName + "BeforePileupCorrection";
511 <        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);
512 <        newHistoName = histoName + "AfterPileupCorrection";
513 <        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);
593 >      // Book a histogram for the number of each object type to be plotted.
594 >      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
595 >      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
596 >        string currentObject = objectsToPlot.at(currentObjectIndex);
597 >        int maxNum = 10;
598 >        if(currentObject == "mcparticles") maxNum = 50;
599 >        else if(currentObject == "primaryvertexs") maxNum = 50;
600 >
601 >        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
602 >        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
603 >        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
604 >        else if(currentObject == "electron-photon pairs")     currentObject = "electronPhotonPairs";
605 >        else if(currentObject == "muon-photon pairs")         currentObject = "muonPhotonPairs";
606 >        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
607 >        else if(currentObject == "secondary photons")            currentObject = "secondaryPhotons";
608 >        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
609 >        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
610 >        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
611 >        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
612 >        else if(currentObject == "muon-event pairs")            currentObject = "muonEventPairs";
613 >        else if(currentObject == "photon-jet pairs")            currentObject = "photonJetPairs";
614 >        else if(currentObject == "met-jet pairs")             currentObject = "metJetPairs";
615 >        else if(currentObject == "track-jet pairs")           currentObject = "trackJetPairs";
616 >        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
617 >        else if(currentObject == "muon-secondary photon pairs")  currentObject = "muonSecondaryPhotonPairs";
618 >        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
619 >        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
620 >        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
621 >        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
622 >        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
623 >        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
624 >        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
625 >        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
626 >        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
627 >        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
628 >        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
629 >        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
630 >        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
631 >        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
632 >        else if(currentObject == "electron-mcparticle pairs")   currentObject = "electronMCparticlePairs";
633 >
634 >
635 >        currentObject.at(0) = toupper(currentObject.at(0));
636 >        string histoName = "num" + currentObject;
637 >
638 >        if(histoName == "numPrimaryvertexs"){
639 >          string newHistoName = histoName + "BeforePileupCorrection";
640 >          oneDHists_.at(currentChannel).at(currentDir)[newHistoName] = directories.at(currentDir).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
641 >          newHistoName = histoName + "AfterPileupCorrection";
642 >          oneDHists_.at(currentChannel).at(currentDir)[newHistoName] = directories.at(currentDir).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
643 >        }
644 >        else
645 >          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
646 >      }
647 >
648 >      if (verbose_) {
649 >        clog << "List of 1D histograms booked for channel " << channelName << " and directory " << currentDir << ":" << endl;
650 >        for(map<string, TH1D*>::iterator
651 >              iter = oneDHists_.at(currentChannel).at(currentDir).begin();
652 >            iter  != oneDHists_.at(currentChannel).at(currentDir).end();
653 >            iter++) {
654 >          clog << " " << iter->first
655 >               << ":  name=" << iter->second->GetName()
656 >               << ", title=" << iter->second->GetTitle()
657 >               << ", bins=(" << iter->second->GetNbinsX()
658 >               << "," << iter->second->GetXaxis()->GetXmin()
659 >               << "," << iter->second->GetXaxis()->GetXmax()
660 >               << ")" << endl;
661 >        }  
662 >        clog << "List of 2D histograms booked for channel " << channelName << " and directory " << currentDir << ":" << endl;
663 >        for(map<string, TH2D*>::iterator
664 >              iter = twoDHists_.at(currentChannel).at(currentDir).begin();
665 >            iter  != twoDHists_.at(currentChannel).at(currentDir).end();
666 >            iter++) {
667 >          clog << " " << iter->first
668 >               << ":  name=" << iter->second->GetName()
669 >               << ", title=" << iter->second->GetTitle()
670 >               << ", binsX=(" << iter->second->GetNbinsX()
671 >               << "," << iter->second->GetXaxis()->GetXmin()
672 >               << "," << iter->second->GetXaxis()->GetXmax()
673 >               << ")"
674 >               << ", binsY=(" << iter->second->GetNbinsY()
675 >               << "," << iter->second->GetYaxis()->GetXmin()
676 >               << "," << iter->second->GetYaxis()->GetXmax()
677 >               << ")"
678 >               << endl;
679 >        }  
680        }
681 <      else
682 <        oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
517 <    }
518 <   }//end of loop over directories
681 >
682 >    }//end of loop over directories
683      channels.push_back(tempChannel);
684      tempChannel.cuts.clear();
685    }//end loop over channels
686  
687  
688 +  // Create the cutflow histogram and fill with 0 weight, in case no events are found in the input file.  
689 +  for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
690 +    channel currentChannel = channels.at(currentChannelIndex);
691 +    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
692 +      cutFlows_.at(currentChannelIndex)->at("trigger") = true;  
693 +    }
694 +    for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
695 +      cut currentCut = currentChannel.cuts.at(currentCutIndex);
696 +      cutFlows_.at(currentChannelIndex)->at (currentCut.name) = true;
697 +    }
698 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(0);  // fill cutflow with 0 weight, just to create the cutflow histograms  
699 +  }
700 +
701    //make unique vector of objects we need to get from the event
702    sort( objectsToGet.begin(), objectsToGet.end() );
703    objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
704    //make unique vector of objects we need to cut on
705    sort( objectsToCut.begin(), objectsToCut.end() );
706    objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
707 +  //make unique vector of objects we need to set flags for
708 +  sort( objectsToFlag.begin(), objectsToFlag.end() );
709 +  objectsToFlag.erase( unique( objectsToFlag.begin(), objectsToFlag.end() ), objectsToFlag.end() );
710  
711 +  // Move all paired objects to the end of the list, so that the flags for single objects are always set before those of paired objects.  
712 +  for (uint i=0; i<objectsToFlag.size(); i++) {
713 +    if (objectsToFlag.at(i).find("pairs")!=string::npos) { // if it contains "pairs"
714 +      objectsToFlag.push_back(objectsToFlag.at(i));  
715 +      objectsToFlag.erase(objectsToFlag.begin()+i);  
716 +    }
717 +  }
718 +
719 +  if (verbose_) {
720 +    clog << "List of channels:" << endl;
721 +    for (uint i=0; i<channels.size(); i++) {
722 +      clog << " " << channels.at(i).name << endl;
723 +    }
724 +    clog << "List of objects to get:" << endl;
725 +    for (uint i=0; i<objectsToGet.size(); i++) {
726 +      clog << " " << objectsToGet.at(i) << endl;
727 +    }
728 +    clog << "List of objects to plot:" << endl;
729 +    for (uint i=0; i<objectsToPlot.size(); i++) {
730 +      clog << " " << objectsToPlot.at(i) << endl;
731 +    }
732 +    clog << "List of objects to cut:" << endl;
733 +    for (uint i=0; i<objectsToCut.size(); i++) {
734 +      clog << " " << objectsToCut.at(i) << endl;
735 +    }
736 +    clog << "List of objects to flag:" << endl;
737 +    for (uint i=0; i<objectsToFlag.size(); i++) {
738 +      clog << " " << objectsToFlag.at(i) << endl;
739 +    }
740 +  }
741 +
742 +  produces<map<string, bool> > ("channelDecisions");
743 +
744 +  if (printEventInfo_) {
745 +    findEventsLog = new ofstream();  
746 +    findEventsLog->open("findEvents.txt");  
747 +    clog << "Listing run:lumi:event in file findEvents.txt for events that pass full selection (of any channel)." << endl;  
748 +  } else {
749 +    findEventsLog = 0;
750 +  }  
751 +
752 +  isFirstEvent_ = true;  
753 +
754 +  if (verbose_) clog << "Finished OSUAnalysis::OSUAnalysis constructor." << endl;  
755 +
756 +
757 +  } // end constructor OSUAnalysis::OSUAnalysis()
758  
532 }
759  
760   OSUAnalysis::~OSUAnalysis ()
761   {
762 +
763 +  if (verbose_) clog << "Beginning OSUAnalysis::OSUAnalysis destructor." << endl;  
764 +
765    // Destroying the CutFlow objects causes the cut flow numbers and time
766    // information to be printed to standard output.
767    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
768      delete cutFlows_.at(currentChannel);
769    }
770 +
771 +  if (printEventInfo_ && findEventsLog) findEventsLog->close();  
772 +
773 +  clog << "=============================================" << endl;  
774 +  clog << "Successfully completed OSUAnalysis." << endl;  
775 +  clog << "=============================================" << endl;  
776 +
777 +  if (verbose_) clog << "Finished OSUAnalysis::OSUAnalysis destructor." << endl;  
778 +
779   }
780  
781   void
782 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
782 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
783   {
546
784    // Retrieve necessary collections from the event.
785  
786 <  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
786 >  if (verbose_) clog << "Beginning OSUAnalysis::produce." << endl;  
787 >
788 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end()) {
789      event.getByLabel (triggers_, triggers);
790 +    if (!triggers.product()) cout << "ERROR:  could not get triggers input collection" << endl;  
791 +  }
792  
793 <  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
793 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end()) {
794      event.getByLabel (trigobjs_, trigobjs);
795 +    if (!trigobjs.product()) cout << "ERROR:  could not get trigobjs input collection" << endl;  
796 +  }
797  
798 <  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
798 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end()) {
799      event.getByLabel (jets_, jets);
800 +    if (!jets.product()) cout << "ERROR:  could not get jets input collection" << endl;  
801 +  }
802  
803 <  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
803 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end()) {
804      event.getByLabel (muons_, muons);
805 +    if (!muons.product()) cout << "ERROR:  could not get muons input collection" << endl;  
806 +  }
807  
808 <  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
808 >  if (find(objectsToGet.begin(), objectsToGet.end(), "secondary muons") != objectsToGet.end()) {
809 >    event.getByLabel (secMuons_, secMuons);
810 >    if (!secMuons.product()) cout << "ERROR:  could not get secMuons input collection" << endl;  
811 >  }
812 >
813 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end()) {
814      event.getByLabel (electrons_, electrons);
815 +    if (!electrons.product()) cout << "ERROR:  could not get electrons input collection" << endl;  
816 +  }
817  
818 <  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
818 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end()) {
819      event.getByLabel (events_, events);
820 +    if (!events.product()) cout << "ERROR:  could not get events input collection" << endl;  
821 +  }
822  
823 <  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
823 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end()) {
824      event.getByLabel (taus_, taus);
825 +    if (!taus.product()) cout << "ERROR:  could not get taus input collection" << endl;  
826 +  }
827  
828 <  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
828 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end()) {
829      event.getByLabel (mets_, mets);
830 +    if (!mets.product()) cout << "ERROR:  could not get mets input collection" << endl;  
831 +  }
832  
833 <  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
833 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end()) {
834      event.getByLabel (tracks_, tracks);
835 +    if (!tracks.product()) cout << "ERROR:  could not get tracks input collection" << endl;  
836 +  }
837  
838 <  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
838 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end()) {
839      event.getByLabel (genjets_, genjets);
840 +    if (!genjets.product()) cout << "ERROR:  could not get genjets input collection" << endl;  
841 +  }
842  
843 <  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
843 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end()) {
844      event.getByLabel (mcparticles_, mcparticles);
845 +    if (!mcparticles.product()) cout << "ERROR:  could not get mcparticles input collection" << endl;  
846 +  }
847  
848 <  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
848 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end()) {
849      event.getByLabel (primaryvertexs_, primaryvertexs);
850 +    if (!primaryvertexs.product()) cout << "ERROR:  could not get primaryvertexs input collection" << endl;  
851 +  }
852  
853 <  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
853 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end()) {
854      event.getByLabel (bxlumis_, bxlumis);
855 +    if (!bxlumis.product()) cout << "ERROR:  could not get bxlumis input collection" << endl;  
856 +  }
857  
858 <  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
858 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end()) {
859      event.getByLabel (photons_, photons);
860 +    if (!photons.product()) cout << "ERROR:  could not get photons input collection" << endl;  
861 +  }
862  
863 <  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
863 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end()) {
864      event.getByLabel (superclusters_, superclusters);
865 +    if (!superclusters.product()) cout << "ERROR:  could not get superclusters input collection" << endl;  
866 +  }
867  
868    if (datasetType_ == "signalMC"){
869 <    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
869 >    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end()) {
870        event.getByLabel (stops_, stops);
871 +      if (!stops.product()) cout << "ERROR:  could not get stops input collection" << endl;  
872 +    }
873    }
874  
875    if (useTrackCaloRhoCorr_) {
# Line 602 | Line 878 | OSUAnalysis::analyze (const edm::Event &
878      // For description of rho values for different jet reconstruction algorithms, see
879      // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
880      event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
881 +    if (!rhokt6CaloJetsHandle_.product()) cout << "ERROR:  could not get kt6CaloJets input collection" << endl;  
882    }
883  
884    double masterScaleFactor = 1.0;
885  
886    //get pile-up event weight
887    if (doPileupReweighting_ && datasetType_ != "data") {
888 <    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  This will give an incorrect pile-up weight." << endl;  
889 < else
890 <    masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);  
888 >    //for "data" datasets, the numTruePV is always set to -1
889 >    if (events->at(0).numTruePV < 0 && isFirstEvent_) clog << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
890 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
891    }
892  
893    stopCTauScaleFactor_ = 1.0;
# Line 620 | Line 897 | else
897  
898    //loop over all channels
899  
900 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
901    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
902      channel currentChannel = channels.at(currentChannelIndex);
903 +    if (verbose_>1) clog << " Processing channel " << currentChannel.name << endl;
904  
905      flagMap individualFlags;
906      counterMap passingCounter;
907      cumulativeFlags.clear ();
908  
909 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
910 +         iter != BNTreeBranchVals_.end(); iter++) {
911 +      iter->second.clear();  // clear array
912 +    }
913 +
914      bool triggerDecision = true;
915 <    if(currentChannel.triggers.size() != 0){  //triggers specified
916 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
915 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
916 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
917        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
918      }
919  
920      //loop over all cuts
921      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
922        cut currentCut = currentChannel.cuts.at(currentCutIndex);
923 <      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
924 <        string currentObject = objectsToCut.at(currentObjectIndex);
923 >      if (verbose_>2) clog << "  Processing cut, index: " << currentCutIndex << ", input collection: " << currentCut.inputCollection << ", name: " << currentCut.name << endl;  
924 >
925 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
926 >        string currentObject = objectsToFlag.at(currentObjectIndex);
927  
928          //initialize maps to get ready to set cuts
929 <        individualFlags[currentObject].push_back (vector<bool> ());
930 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
929 >        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
930 >        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
931  
932        }
647      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
648        string currentObject = objectsToCut.at(currentObjectIndex);
933  
934 <        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
935 <
936 <
937 <        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
938 <        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
939 <        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
940 <        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
934 >      //set flags for all relevant objects
935 >      for(int currentObjectIndex = -1; currentObjectIndex != int(objectsToFlag.size()); currentObjectIndex++){
936 >        string currentObject;  
937 >        if (currentObjectIndex < 0) currentObject = currentCut.inputCollection;  // In the first loop, set the flags for the collection that the cut is acting on.  That way other paired collections can access the correct flag for the current cut.  
938 >        else currentObject = objectsToFlag.at(currentObjectIndex);
939 >        if (currentObjectIndex >= 0 && currentObject == currentCut.inputCollection) continue;  // Flags have already been set for the inputCollection object, so should not be set again.  
940 >
941 >        // single object collections
942 >        if     (currentObject == "jets")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
943 >        else if(currentObject == "secondary jets")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
944 >        else if(currentObject == "secondary photons")   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"secondary photons");
945 >        else if(currentObject == "muons")               setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
946 >        else if(currentObject == "secondary muons")     setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,secMuons.product(),"secondary muons");
947          else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
948 <        else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
949 <        else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
950 <        else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
951 <        else if(currentObject == "mets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
952 <        else if(currentObject == "tracks") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
953 <        else if(currentObject == "genjets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
954 <        else if(currentObject == "mcparticles") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
955 <        else if(currentObject == "primaryvertexs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
956 <        else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
957 <        else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
958 <        else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
959 <        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
960 <
961 <
962 <
963 <        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
964 <                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
965 <                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
966 <                                                                   "muon-muon pairs");
967 <
968 <        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
969 <                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
970 <                                                                   cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
971 <                                                                   "muon-secondary muon pairs");
972 <
973 <        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
974 <                                                                   cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
975 <                                                                   cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
976 <                                                                   "electron-secondary electron pairs");
977 <
978 <        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
979 <                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
980 <                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
981 <                                                                           "electron-electron pairs");
982 <        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
983 <                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
984 <                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
985 <                                                                       "electron-muon pairs");
986 <        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
987 <                                                                           cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
988 <                                                                           cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
989 <                                                                           "jet-jet pairs");
990 <        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
991 <                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
992 <                                                                       cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
703 <                                                                       "electron-jet pairs");
704 <        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
705 <                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
706 <                                                                       cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
707 <                                                                       "muon-jet pairs");
708 <        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
709 <                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
710 <                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
711 <                                                                     "track-event pairs");
712 <        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
713 <                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
714 <                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
715 <                                                                        "electron-track pairs");
716 <        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
717 <                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
718 <                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
719 <                                                                    "muon-track pairs");
720 <        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
721 <                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
722 <                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
723 <                                                                  "muon-tau pairs");
724 <        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
725 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
726 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
727 <                                                                 "tau-tau pairs");
728 <        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
729 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
730 <                                                                 cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
731 <                                                                 "tau-track pairs");
732 <        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
733 <                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
734 <                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
735 <                                                                          "electron-trigobj pairs");
736 <        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
737 <                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
738 <                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
739 <                                                                      "muon-trigobj pairs");
948 >        else if(currentObject == "electrons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
949 >        else if(currentObject == "events")              setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
950 >        else if(currentObject == "taus")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
951 >        else if(currentObject == "mets")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
952 >        else if(currentObject == "tracks")              setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
953 >        else if(currentObject == "genjets")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
954 >        else if(currentObject == "mcparticles")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
955 >        else if(currentObject == "primaryvertexs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
956 >        else if(currentObject == "bxlumis")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
957 >        else if(currentObject == "photons")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
958 >        else if(currentObject == "superclusters")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
959 >        else if(currentObject == "trigobjs")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
960 >
961 >
962 >        // paired object collections  
963 >        else if(currentObject == "muon-muon pairs")                   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), "muon-muon pairs");
964 >        else if(currentObject == "muon-secondary muon pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),secMuons.product(), "muon-secondary muon pairs");
965 >
966 >        else if(currentObject == "muon-secondary photon pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), "muon-secondary photon pairs");
967 >        else if(currentObject == "muon-secondary jet pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), "muon-secondary jet pairs");
968 >        else if(currentObject == "photon-secondary jet pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), "photon-secondary jet pairs");
969 >        else if(currentObject == "electron-secondary jet pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), "electron-secondary jet pairs");
970 >        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), "electron-secondary electron pairs");
971 >
972 >        else if(currentObject == "electron-electron pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), "electron-electron pairs");
973 >        else if(currentObject == "electron-muon pairs")     setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), "electron-muon pairs");
974 >        else if(currentObject == "jet-jet pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), "jet-jet pairs");
975 >        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), "jet-secondary jet pairs");
976 >        else if(currentObject == "electron-jet pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), "electron-jet pairs");
977 >        else if(currentObject == "electron-photon pairs")   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), "electron-photon pairs");
978 >        else if(currentObject == "photon-jet pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), "photon-jet pairs");
979 >        else if(currentObject == "muon-jet pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), "muon-jet pairs");
980 >        else if(currentObject == "muon-event pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),events.product(), "muon-event pairs");
981 >        else if(currentObject == "met-jet pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),jets.product(), "met-jet pairs");
982 >        else if(currentObject == "track-jet pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),jets.product(), "track-jet pairs");
983 >        else if(currentObject == "muon-photon pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), "muon-photon pairs");
984 >        else if(currentObject == "track-event pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(), "track-event pairs");
985 >        else if(currentObject == "electron-track pairs")    setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),"electron-track pairs");
986 >        else if(currentObject == "muon-track pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),"muon-track pairs");
987 >        else if(currentObject == "muon-tau pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),"muon-tau pairs");
988 >        else if(currentObject == "tau-tau pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),"tau-tau pairs");
989 >        else if(currentObject == "tau-track pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),"tau-track pairs");
990 >        else if(currentObject == "electron-trigobj pairs")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),"electron-trigobj pairs");
991 >        else if(currentObject == "muon-trigobj pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),"muon-trigobj pairs");
992 >        else if(currentObject == "electron-mcparticle pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),mcparticles.product(),"electron-mcparticle pairs");
993  
994          if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
995        }
996  
997 +    }//end loop over all cuts
998  
999  
746    }//end loop over all cuts
747    //use cumulative flags to apply cuts at event level
1000  
1001 +    //use cumulative flags to apply cuts at event level
1002 +    vector<bool> eventPassedPreviousCuts;    //a vector to store cumulative cut descisions after each cut.
1003      bool eventPassedAllCuts = true;
1004 <    //a vector to store cumulative cut descisions after each cut.
751 <    vector<bool> eventPassedPreviousCuts;
752 <    //apply trigger (true if none were specified)
753 <    eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
754 <
1004 >    eventPassedAllCuts = eventPassedAllCuts && triggerDecision;    //apply trigger (true if none were specified)
1005  
1006      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
1007  
1008        //loop over all objects and count how many passed the cumulative selection up to this point
1009        cut currentCut = currentChannel.cuts.at(currentCutIndex);
1010        int numberPassing = 0;
1011 +      int numberPassingPrev = 0;  // number of objects that pass cuts up to the previous one
1012  
1013        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
1014 <        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
1014 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
1015 >      }
1016 >      bool cutDecision;
1017 >      if (!currentCut.isVeto) {
1018 >        cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
1019 >      } else {
1020 >        int prevCutIndex = currentCutIndex - 1;
1021 >        if (prevCutIndex<0) {
1022 >          numberPassingPrev = cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size();  // count all objects in collection if cut is the first
1023 >        } else {
1024 >          for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(prevCutIndex).size() ; object++){
1025 >            if (cumulativeFlags.at(currentCut.inputCollection).at(prevCutIndex).at(object).first) {
1026 >              numberPassingPrev++;
1027 >              if (verbose_>1) clog << " object passed previous cut" << endl;  
1028 >            }
1029 >          }  
1030 >        }  
1031 >        int numberFailCut = numberPassingPrev - numberPassing;
1032 >        cutDecision = evaluateComparison(numberFailCut,currentCut.eventComparativeOperator,currentCut.numberRequired);  
1033        }
1034 <      bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
1034 >
1035        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
1036        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
1037        eventPassedPreviousCuts.push_back(eventPassedAllCuts);
1038 +      if (verbose_>1) clog << " Event passed cuts up to cut index " << currentCutIndex << endl;  
1039 +
1040      }
1041 +    //applying all appropriate scale factors
1042      double scaleFactor = masterScaleFactor;
1043 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
1044  
772    muonScaleFactor_ = electronScaleFactor_ = 1.0;
1045      if(applyLeptonSF_ && datasetType_ != "data"){
1046 <      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
1047 <        vector<bool> muonFlags;
1046 >      //only apply SFs if we've cut on this object
1047 >      if(find(objectsToCut.begin(),objectsToCut.end(),"muons") != objectsToCut.end ()){
1048 >        flagPair muonFlags;
1049 >        //get the last valid flags in the flag map
1050          for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
1051            if (cumulativeFlags.at("muons").at(i).size()){
1052              muonFlags = cumulativeFlags.at("muons").at(i);
1053              break;
1054            }
1055          }
1056 +        //apply the weight for each of those objects
1057          for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
1058 <          if(!muonFlags.at(muonIndex)) continue;
1058 >          if(!muonFlags.at(muonIndex).second) continue;
1059            muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
1060          }
1061        }
1062 <      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
1063 <        vector<bool> electronFlags;
1062 >      //only apply SFs if we've cut on this object
1063 >      if(find(objectsToCut.begin(),objectsToCut.end(),"electrons") != objectsToCut.end ()){
1064 >        flagPair electronFlags;
1065 >        //get the last valid flags in the flag map
1066          for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
1067            if (cumulativeFlags.at("electrons").at(i).size()){
1068              electronFlags = cumulativeFlags.at("electrons").at(i);
1069              break;
1070            }
1071          }
1072 +        //apply the weight for each of those objects
1073          for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
1074 <          if(!electronFlags.at(electronIndex)) continue;
1074 >          if(!electronFlags.at(electronIndex).second) continue;
1075            electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
1076          }
1077        }
1078      }
1079 +    if(applyBtagSF_ && datasetType_ != "data"){
1080 +      //only apply SFs if we've cut on this object
1081 +      if(find(objectsToCut.begin(),objectsToCut.end(),"jets") != objectsToCut.end ()){
1082 +        flagPair jetFlags;
1083 +        vector<double> jetSFs;
1084 +        //get the last valid flags in the flag map
1085 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
1086 +          if (cumulativeFlags.at("jets").at(i).size()){
1087 +            jetFlags = cumulativeFlags.at("jets").at(i);
1088 +            break;
1089 +          }
1090 +        }
1091 +        //apply the weight for each of those objects
1092 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
1093 +          if(!jetFlags.at(jetIndex).second) continue;
1094 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour, jets->at(jetIndex).eta);
1095 +          jetSFs.push_back(jetSFTmp);
1096 +        }
1097 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_);
1098 +      }
1099 +    }
1100      scaleFactor *= muonScaleFactor_;
1101      scaleFactor *= electronScaleFactor_;
1102 <
1102 >    scaleFactor *= bTagScaleFactor_;
1103      cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
1104 <    if(!(GetPlotsAfterEachCut_ || eventPassedAllCuts)) continue;
1104 >    if (verbose_>1) clog << " Scale factors applied:  "
1105 >                         << " muonScaleFactor_ = " << muonScaleFactor_
1106 >                         << ", electronScaleFactor_ = " << electronScaleFactor_
1107 >                         << ", bTagScaleFactor_ = " << bTagScaleFactor_
1108 >                         << ", total scale factor = " << scaleFactor
1109 >                         << endl;  
1110  
1111 <    if (printEventInfo_) {
1111 >
1112 >    if (printEventInfo_ && eventPassedAllCuts) {
1113        // Write information about event to screen, for testing purposes.
1114 <      cout << "Event passed all cuts in channel " <<  currentChannel.name
1115 <           << ": run="  << events->at(0).run
1116 <           << "  lumi=" << events->at(0).lumi
1117 <           << "  event=" << events->at(0).evt
1114 >      clog << "Event passed all cuts in channel " <<  currentChannel.name
1115 >           << ":  run:lumi:evt=  "  << events->at(0).run
1116 >           << ":" << events->at(0).lumi
1117 >           << ":" << events->at(0).evt
1118             << endl;
1119 +      if (findEventsLog) {
1120 +        (*findEventsLog) << events->at(0).run
1121 +                         << ":" << events->at(0).lumi
1122 +                         << ":" << events->at(0).evt << endl;
1123 +      }
1124 +
1125      }
1126 +
1127 +
1128      //filling histograms
1129 <    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
1130 <        uint currentDir;
1131 <        if(!GetPlotsAfterEachCut_){ currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size();}//if GetPlotsAfterEachCut_ is true, set currentDir point to the lat cut.
1132 <        else{
1133 <          currentDir = currentCut;
1134 <        }
1135 <        if(eventPassedPreviousCuts.at(currentDir)){
1129 >    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the cuts in each channel; if GetPlotsAfterEachCut_ is false, only the last cut will be used.
1130 >
1131 >      if (verbose_>2) clog << "  Filling histograms for currentcut = " << currentCut << endl;  
1132 >
1133 >      uint currentDir;
1134 >      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
1135 >      else{
1136 >        currentDir = currentCut;
1137 >      }
1138 >
1139 >
1140 >      if(eventPassedPreviousCuts.at(currentDir)){
1141 >
1142          for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1143            histogram currentHistogram = histograms.at(histogramIndex);
1144  
1145 <      if(currentHistogram.inputVariables.size() == 1){
827 <        TH1D* histo;
828 <        histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
829 <        if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
830 <        else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
831 <        else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
832 <        else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
833 <        else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
834 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
835 <                                                                                       cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
836 <                                                                                       cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
837 <        else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
838 <                                                                                       cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
839 <                                                                                       cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
840 <        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
841 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
842 <                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
843 <                                                                                               cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
844 <        else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
845 <                                                                                               cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
846 <                                                                                               cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
847 <        else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
848 <                                                                                       cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
849 <                                                                                       cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
850 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
851 <                                                                                           cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
852 <                                                                                           cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
853 <        else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
854 <                                                                                           cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
855 <                                                                                           cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
856 <        else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
857 <                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
858 <                                                                                           cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
859 <        else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
860 <                                                                                            cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
861 <                                                                                            cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
862 <        else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
863 <                                                                                        cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
864 <                                                                                        cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
865 <        else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
866 <                                                                                      cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
867 <                                                                                      cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
868 <        else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
869 <                                                                                     cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
870 <                                                                                     cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
871 <        else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
872 <                                                                                     cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
873 <                                                                                     cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
874 <        else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
875 <                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
876 <                                                                                              cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
877 <        else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
878 <                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
879 <                                                                                          cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
880 <
881 <        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
882 <        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
883 <        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
884 <        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
885 <        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
886 <        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
887 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
888 <        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
889 <        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
890 <        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
891 <        else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
892 <        else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
893 <      }
894 <      else if(currentHistogram.inputVariables.size() == 2){
895 <        TH2D* histo;
896 <        histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
897 <        if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
898 <        else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
899 <        else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
900 <        else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
901 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
902 <                                                                                       cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
903 <                                                                                       cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
904 <        else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
905 <                                                                                       cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
906 <                                                                                       cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
907 <        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
908 <        else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
909 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
910 <                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
911 <                                                                                               cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
912 <        else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
913 <                                                                                               cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
914 <                                                                                               cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
915 <        else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
916 <                                                                                       cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
917 <                                                                                       cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
918 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
919 <                                                                                           cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
920 <                                                                                           cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
921 <        else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
922 <                                                                                           cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
923 <                                                                                           cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
924 <        else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
925 <                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
926 <                                                                                           cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
927 <        else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
928 <                                                                                            cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
929 <                                                                                            cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
930 <        else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
931 <                                                                                        cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
932 <                                                                                        cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
933 <        else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
934 <                                                                                      cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
935 <                                                                                      cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
936 <        else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
937 <                                                                                     cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
938 <                                                                                     cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
939 <        else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
940 <                                                                                     cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
941 <                                                                                     cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
942 <        else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
943 <                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
944 <                                                                                              cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
945 <        else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
946 <                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
947 <                                                                                          cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
948 <        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
949 <        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
950 <        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
951 <        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
952 <        else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
953 <                                                                                         cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
954 <                                                                                         cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
955 <        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
956 <        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
957 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
958 <        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
959 <        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
960 <        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
961 <        else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
962 <        else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
963 <      }
964 <    }
1145 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) clog << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
1146  
1147 +          if (verbose_>1) clog << " Filling histogram " << currentHistogram.name << " for collection " << currentHistogram.inputCollection << endl;  
1148  
1149 +          if(currentHistogram.inputVariables.size() == 1){
1150 +            TH1D* histo;
1151 +            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1152 +            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1153 +            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1154 +            else if(currentHistogram.inputCollection == "secondary photons")  fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1155 +            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1156 +            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,secMuons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1157 +            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1158 +            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1159 +                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1160 +            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),secMuons.product(),
1161 +                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1162 +             else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1163 +                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1164 +             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1165 +                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1166 +             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1167 +                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1168 +             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1169 +                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1170 +
1171 +            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1172 +            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1173 +                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1174 +            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1175 +                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1176 +             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1177 +                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1178 +
1179 +            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1180 +                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1181 +            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(),
1182 +                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1183 +            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(),
1184 +                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1185 +            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(),
1186 +                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1187 +            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(),
1188 +                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1189 +            else if(currentHistogram.inputCollection == "muon-event pairs") fill1DHistogram(histo,currentHistogram, muons.product(),events.product(),
1190 +                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1191 +            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, mets.product(),jets.product(),
1192 +                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1193 +            else if(currentHistogram.inputCollection == "track-jet pairs")  fill1DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1194 +                                                                                          cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1195 +            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(),
1196 +                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1197 +            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(),
1198 +                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1199 +            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1200 +                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1201 +            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1202 +                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1203 +            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1204 +                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1205 +            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1206 +                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1207 +            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1208 +                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1209 +            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1210 +                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1211 +            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1212 +                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1213 +
1214 +            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1215 +            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1216 +            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1217 +            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1218 +            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1219 +            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1220 +            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1221 +            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1222 +            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1223 +            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1224 +            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1225 +            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1226 +          }
1227 +          else if(currentHistogram.inputVariables.size() == 2){
1228 +            TH2D* histo;
1229 +            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1230 +            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1231 +            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1232 +            else if(currentHistogram.inputCollection == "secondary photons")  fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1233 +            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1234 +            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,secMuons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1235 +            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1236 +                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1237 +            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),secMuons.product(),
1238 +                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1239 +            else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1240 +                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1241 +            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1242 +                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1243 +            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1244 +                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1245 +            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1246 +                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1247 +            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1248 +            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1249 +            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1250 +                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1251 +            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1252 +                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1253 +            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1254 +                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1255 +            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(),
1256 +                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1257 +            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1258 +                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1259 +            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(),
1260 +                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1261 +            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1262 +                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1263 +            else if(currentHistogram.inputCollection == "muon-event pairs") fill2DHistogram(histo,currentHistogram,muons.product(),events.product(),
1264 +                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1265 +            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,mets.product(),jets.product(),
1266 +                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1267 +            else if(currentHistogram.inputCollection == "track-jet pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1268 +                                                                                         cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1269 +            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1270 +                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1271 +            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1272 +                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1273 +            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1274 +                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1275 +            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1276 +                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1277 +            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1278 +                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1279 +            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1280 +                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1281 +            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1282 +                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1283 +            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1284 +                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1285 +            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1286 +                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1287 +            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1288 +            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1289 +            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1290 +            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1291 +            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1292 +                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1293 +            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1294 +            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1295 +            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1296 +            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1297 +            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1298 +            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1299 +            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1300 +            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1301 +          }
1302  
1303 <    //fills histograms with the sizes of collections
1304 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1305 <
1306 <      string currentObject = objectsToPlot.at(currentObjectIndex);
1307 <      string objectToPlot = "";
1308 <
1309 <      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1310 <      if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1311 <      else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1312 <      else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1313 <      else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1314 <      else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1315 <      else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1316 <      else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1317 <      else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1318 <      else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1319 <      else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1320 <      else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1321 <      else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1322 <      else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1323 <      else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1324 <      else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1325 <      else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1326 <      else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1327 <      else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1328 <      else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1329 <      else objectToPlot = currentObject;
1330 <
1331 <      string tempCurrentObject = objectToPlot;
1332 <      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1333 <      string histoName = "num" + tempCurrentObject;
1334 <
1335 <      //set position of primary vertex in event, in order to calculate quantities relative to it
1336 <      if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1337 <        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1338 <        int numToPlot = 0;
1339 <        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1340 <          if(lastCutFlags.at(currentFlag)) numToPlot++;
1341 <        }
1342 <        if(objectToPlot == "primaryvertexs"){
1343 <          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1344 <          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1345 <        }
1346 <        else {
1347 <          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1348 <        }
1349 <      }
1350 <      else if(objectToPlot == "jets")           oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(jets->size(),scaleFactor);
1351 <      else if(objectToPlot == "secondaryJets")  oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(jets->size(),scaleFactor);
1352 <      else if(objectToPlot == "muons")          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size(),scaleFactor);
1353 <      else if(objectToPlot == "secondaryMuons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size(),scaleFactor);
1354 <      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
1355 <      else if(objectToPlot == "muonSecondaryMuonPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
1356 <      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size(),scaleFactor);
1357 <      else if(objectToPlot == "secondaryElectrons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size(),scaleFactor);
1358 <      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
1359 <      else if(objectToPlot == "electronSecondaryElectronPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
1360 <      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
1361 <      else if(objectToPlot == "electronJetPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*jets->size(),scaleFactor);
1362 <      else if(objectToPlot == "muonJetPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*jets->size(),scaleFactor);
1363 <      else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
1364 <      else if(objectToPlot == "electronTrigobjPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*trigobjs->size(),scaleFactor);
1365 <      else if(objectToPlot == "muonTrigobjPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*trigobjs->size(),scaleFactor);
1366 <      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(events->size(),scaleFactor);
1367 <      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(taus->size(),scaleFactor);
1368 <      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(mets->size(),scaleFactor);
1369 <      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(tracks->size(),scaleFactor);
1370 <      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(genjets->size(),scaleFactor);
1371 <      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(mcparticles->size(),scaleFactor);
1372 <      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(bxlumis->size(),scaleFactor);
1373 <      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(photons->size(),scaleFactor);
1374 <      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(superclusters->size(),scaleFactor);
1040 <      else if(objectToPlot == "trigobjs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(trigobjs->size(),scaleFactor);
1041 <      else if(objectToPlot == "primaryvertexs"){
1042 <        oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1043 <        oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1044 <      }
1045 <      if(objectToPlot == "stops" && datasetType_ == "signalMC") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(stops->size(),scaleFactor);
1303 >        }
1304 >
1305 >
1306 >        //fills histograms with the sizes of collections
1307 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1308 >
1309 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1310 >          string objectToPlot = "";
1311 >
1312 >          if (verbose_) clog << "Filling histogram of number of selected objects in collection: " << currentObject << endl;  
1313 >
1314 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1315 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1316 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1317 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1318 >          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1319 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1320 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1321 >          else if(currentObject == "muon-event pairs")                   objectToPlot = "muonEventPairs";
1322 >          else if(currentObject == "muon-photon pairs")                  objectToPlot = "muonPhotonPairs";
1323 >          else if(currentObject == "photon-jet pairs")                   objectToPlot = "photonJetPairs";
1324 >          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1325 >          else if(currentObject == "track-jet pairs")                    objectToPlot = "trackJetPairs";
1326 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1327 >          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1328 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1329 >          else if(currentObject == "secondary photons")                  objectToPlot = "secondaryPhotons";
1330 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1331 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1332 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1333 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1334 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1335 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1336 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1337 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1338 >          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1339 >          else if(currentObject == "muon-secondary photon pairs")        objectToPlot = "muonSecondaryJetPairs";
1340 >          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1341 >          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1342 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1343 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1344 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1345 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1346 >          else if(currentObject == "electron-mcparticle pairs")          objectToPlot = "electronMCparticlePairs";
1347 >          else objectToPlot = currentObject;
1348 >
1349 >          string tempCurrentObject = objectToPlot;
1350 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1351 >          string histoName = "num" + tempCurrentObject;
1352 >
1353 >
1354 >          if(find(objectsToPlot.begin(), objectsToPlot.end(), currentObject) != objectsToPlot.end()) {
1355 >            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1356 >            int numToPlot = 0;
1357 >            for (uint iObj = 0; iObj != lastCutFlags.size(); iObj++){  // loop over all the objects  
1358 >              if(lastCutFlags.at(iObj).second) {
1359 >                numToPlot++;  
1360 >                if (verbose_>3) clog << "   Found object " << iObj << " in collection " << currentObject << " to plot." << endl;
1361 >              }
1362 >            }
1363 >
1364 >            if(objectToPlot == "primaryvertexs"){
1365 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1366 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1367 >            }
1368 >            else {
1369 >              if (printEventInfo_) clog << "Number of selected " << objectToPlot << " to plot:  " << numToPlot << endl;  
1370 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1371 >            }
1372 >          }
1373 >
1374 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1375  
1376 <     } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1376 >
1377 >      } // end if(eventPassedPreviousCuts.at(currentDir))
1378 >    } // end loop over cuts
1379 >
1380 >    if (!useEDMFormat_ && eventPassedAllCuts){
1381 >      // Assign BNTree variables
1382 >      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1383 >        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1384 >        string coll = brSpecs.inputCollection;
1385 >        if (cumulativeFlags.count(coll) == 0) clog << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1386 >
1387 >        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1388 >        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1389 >        else if(coll == "secondary photons")   assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1390 >        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1391 >        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,secMuons.product(),      cumulativeFlags.at(coll).back());
1392 >        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1393 >        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1394 >        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1395 >        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1396 >        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1397 >        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1398 >        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1399 >        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1400 >        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1401 >        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1402 >        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1403 >        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1404 >        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1405 >        else if(coll == "stops"
1406 >                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1407 >      } // end loop over branches
1408 >      // set the evtLong, runInt, and lumiInt variables separately, since they are not type float  
1409 >      BNTreeBranchVals_evtLong_ = events->at(0).evt;
1410 >      BNTreeBranchVals_runInt_  = events->at(0).run;
1411 >      BNTreeBranchVals_lumiInt_ = events->at(0).lumi;
1412 >
1413 >      if (!BNTrees_.at(currentChannelIndex)) { clog << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1414 >      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1415      }
1416 <  }
1417 <  } //end loop over channel
1416 >
1417 >    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1418 >
1419 >  } // end loop over channel
1420  
1421    masterCutFlow_->fillCutFlow(masterScaleFactor);
1422  
1423 < } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1423 >  event.put (channelDecisions, "channelDecisions");
1424 >
1425 >  isFirstEvent_ = false;  
1426 >
1427 >  if (verbose_) clog << "Finished OSUAnalysis::produce." << endl;  
1428 >
1429 > } // end void OSUAnalysis::produce (const edm::Event &event, const edm::EventSetup &setup)
1430  
1431  
1432  
# Line 1066 | Line 1441 | OSUAnalysis::evaluateComparison (double
1441    else if(comparison == "==") return testValue == cutValue;
1442    else if(comparison == "=") return testValue == cutValue;
1443    else if(comparison == "!=") return testValue != cutValue;
1444 <  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1444 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1445  
1446   }
1447  
# Line 1079 | Line 1454 | OSUAnalysis::evaluateComparison (string
1454    else if(comparison == "<")  return testValue <  cutValue;
1455    else if(comparison == "<=") return testValue <= cutValue;
1456    else if(comparison == "==") return testValue == cutValue;
1457 <  else if(comparison == "=") return testValue == cutValue;
1457 >  else if(comparison == "=")  return testValue == cutValue;
1458    else if(comparison == "!=") return testValue != cutValue;
1459 <  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1459 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1460  
1461   }
1462  
1463   bool
1464 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1464 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1465  
1466 +  //initialize to false until a chosen trigger is passed
1467    bool triggerDecision = false;
1468  
1469 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1470 <    {
1471 <      if(trigger->pass != 1) continue;
1472 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1473 <        {
1474 <          if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos){
1475 <            triggerDecision = true;
1476 <          }
1477 <        }
1469 >  if (printAllTriggers_) clog << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1470 >  //loop over all triggers defined in the event
1471 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1472 >
1473 >    if (printAllTriggers_) clog << "   " << trigger->name << endl;
1474 >
1475 >    //we're only interested in triggers that actually passed
1476 >    if(trigger->pass != 1) continue;
1477 >
1478 >    //if the event passes one of the veto triggers, exit and return false
1479 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1480 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1481      }
1482 <  return triggerDecision;
1482 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1483 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1484 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1485 >    }
1486 >  }
1487  
1488 +  printAllTriggers_ = false;  // only print triggers once, not every event
1489 +
1490 +  //if none of the veto triggers fired:
1491 +  //return the OR of all the chosen triggers
1492 +  if (triggersToTest.size() != 0) return triggerDecision;
1493 +  //or if no triggers were defined return true
1494 +  else return true;
1495   }
1496  
1497 +
1498   vector<string>
1499   OSUAnalysis::splitString (string inputString){
1500  
# Line 1265 | Line 1656 | OSUAnalysis::valueLookup (const BNjet* o
1656    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1657    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1658  
1659 +  //user defined variable
1660 +  else if(variable == "disappTrkLeadingJetID") {
1661 +    value = object->pt > 110
1662 +      && fabs(object->eta) < 2.4
1663 +      && object->chargedHadronEnergyFraction > 0.2
1664 +      && object->neutralHadronEnergyFraction < 0.7
1665 +      && object->chargedEmEnergyFraction < 0.5
1666 +      && object->neutralEmEnergyFraction < 0.7;
1667 +  }
1668 +
1669 +  else if(variable == "disappTrkSubLeadingJetID") {
1670 +    value = object->pt > 30
1671 +      && fabs(object->eta) < 4.5
1672 +      && object->neutralHadronEnergyFraction < 0.7
1673 +      && object->chargedEmEnergyFraction < 0.5;
1674 +  }
1675 +
1676 +  else if(variable == "dPhiMet") {
1677 +    if (const BNmet *met = chosenMET ()) {
1678 +      value = deltaPhi (object->phi, met->phi);
1679 +    } else value = -999;
1680 +  }
1681 +
1682  
1683 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1683 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1684  
1685    value = applyFunction(function, value);
1686  
1687    return value;
1688 < }
1688 > } // end jet valueLookup
1689  
1690  
1691   //!muon valueLookup
# Line 1368 | Line 1782 | OSUAnalysis::valueLookup (const BNmuon*
1782    else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1783    else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1784    else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1785 +  else if(variable == "chargedHadronIsoDR04") value = object->chargedHadronIsoDR04;
1786 +  else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1787 +  else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1788 +  else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1789    else if(variable == "rhoPrime") value = object->rhoPrime;
1790    else if(variable == "AEffDr03") value = object->AEffDr03;
1791    else if(variable == "AEffDr04") value = object->AEffDr04;
# Line 1375 | Line 1793 | OSUAnalysis::valueLookup (const BNmuon*
1793    else if(variable == "pfIsoR03SumNeutralHadronEt") value = object->pfIsoR03SumNeutralHadronEt;
1794    else if(variable == "pfIsoR03SumPhotonEt") value = object->pfIsoR03SumPhotonEt;
1795    else if(variable == "pfIsoR03SumPUPt") value = object->pfIsoR03SumPUPt;
1796 +  else if(variable == "relpfIsoR04SumExceptChargedHad") value = (object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)/ object->pt;
1797 +  else if(variable == "relpfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt/object->pt;
1798 +  else if(variable == "relpfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt/object->pt;
1799 +  else if(variable == "relpfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt/object->pt;
1800 +  else if(variable == "relpfIsoR04SumPUPt") value = object->pfIsoR04SumPUPt/object->pt;
1801    else if(variable == "pfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt;
1802    else if(variable == "pfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt;
1803    else if(variable == "pfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt;
# Line 1431 | Line 1854 | OSUAnalysis::valueLookup (const BNmuon*
1854    else if(variable == "time_ndof") value = object->time_ndof;
1855  
1856    //user-defined variables
1857 +  else if(variable == "looseID") {
1858 +    value = object->pt > 10 &&
1859 +      (object->isGlobalMuon  > 0 ||
1860 +       object->isTrackerMuon > 0);
1861 +  }
1862 +  else if(variable == "looseIDGlobalMuon") {
1863 +    value = object->pt > 10 &&
1864 +      object->isGlobalMuon  > 0;
1865 +  }
1866    else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1867    else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1868    else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1869    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1870 +  else if(variable == "relPFdBetaIsoPseudo") value = (object->pfIsoR04SumChargedHadronPt + object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt) / object->pt;
1871    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1872    else if(variable == "metMT") {
1873      if (const BNmet *met = chosenMET ())
# Line 1445 | Line 1878 | OSUAnalysis::valueLookup (const BNmuon*
1878      else
1879        value = -999;
1880    }
1881 <
1882 <
1881 >  else if(variable == "ptPlusMet") {
1882 >    // Calculate the magnitude of the vector sum of the muon pT and the Met.  
1883 >    if (const BNmet *met = chosenMET ())
1884 >      {
1885 >        TVector2 p2Met;
1886 >        TVector2 p2Muon;
1887 >        p2Met. SetMagPhi(   met->pt,    met->phi);
1888 >        p2Muon.SetMagPhi(object->pt, object->phi);  
1889 >        TVector2 p2MetElec = p2Met + p2Muon;
1890 >        value = p2MetElec.Mod();  
1891 >      }
1892 >    else
1893 >      value = -999;
1894 >  }
1895  
1896    else if(variable == "correctedD0VertexInEBPlus"){
1897      if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
# Line 1558 | Line 2003 | OSUAnalysis::valueLookup (const BNmuon*
2003      value = object->isGlobalMuon > 0                \
2004        && object->isPFMuon > 0                        \
2005        && object->normalizedChi2 < 10                \
2006 <                                  && object->numberOfValidMuonHits > 0        \
2006 >      && object->numberOfValidMuonHits > 0        \
2007        && object->numberOfMatchedStations > 1        \
2008        && fabs(object->correctedD0Vertex) < 0.2        \
2009        && fabs(object->correctedDZ) < 0.5        \
# Line 1569 | Line 2014 | OSUAnalysis::valueLookup (const BNmuon*
2014      value = object->isGlobalMuon > 0                \
2015        && object->isPFMuon > 0                        \
2016        && object->normalizedChi2 < 10                \
2017 <                                  && object->numberOfValidMuonHits > 0        \
2017 >      && object->numberOfValidMuonHits > 0        \
2018        && object->numberOfMatchedStations > 1        \
2019        && object->numberOfValidPixelHits > 0        \
2020        && object->numberOfLayersWithMeasurement > 5;
# Line 1624 | Line 2069 | OSUAnalysis::valueLookup (const BNmuon*
2069      d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2070      dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2071      value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2072 <         || fabs (object->correctedD0Vertex / d0Error) > 99.0
2073 <         || fabs (object->correctedDZ / dzError) > 99.0;
2072 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2073 >      || fabs (object->correctedDZ / dzError) > 99.0;
2074      value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
2075    }
2076  
2077  
2078  
2079 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2079 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2080  
2081    value = applyFunction(function, value);
2082  
2083    return value;
2084 < }
2084 > } // end muon valueLookup
2085 >
2086  
2087   //!electron valueLookup
2088   double
# Line 1805 | Line 2251 | OSUAnalysis::valueLookup (const BNelectr
2251    else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2252    else if(variable == "detIso") value = (object->trackIso) / object->pt;
2253    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2254 +  else if(variable == "relPFrhoIsoEB") value = object->isEB ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2255 +  else if(variable == "relPFrhoIsoEE") value = object->isEE ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2256    else if(variable == "metMT") {
2257      if (const BNmet *met = chosenMET ())
2258        {
# Line 1815 | Line 2263 | OSUAnalysis::valueLookup (const BNelectr
2263        value = -999;
2264    }
2265  
2266 +  else if(variable == "ptPlusMet") {
2267 +    // Calculate the magnitude of the vector sum of the electron pT and the Met.  
2268 +    if (const BNmet *met = chosenMET ())
2269 +      {
2270 +        TVector2 p2Met;
2271 +        TVector2 p2Elec;
2272 +        p2Met. SetMagPhi(   met->pt,    met->phi);
2273 +        p2Elec.SetMagPhi(object->pt, object->phi);  
2274 +        TVector2 p2MetElec = p2Met + p2Elec;
2275 +        value = p2MetElec.Mod();  
2276 +      }
2277 +    else
2278 +      value = -999;
2279 +  }
2280 +
2281    else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
2282      if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
2283      else value = -999;
# Line 1876 | Line 2339 | OSUAnalysis::valueLookup (const BNelectr
2339      else value = -999;
2340    }
2341  
2342 +  else if(variable == "looseID"){
2343 +    if (object->isEB)
2344 +      {
2345 +        value = fabs(object->delEtaIn) < 0.007 \
2346 +          && fabs (object->delPhiIn) < 0.15 \
2347 +          && object->scSigmaIEtaIEta < 0.01 \
2348 +          && object->hadOverEm < 0.12 \
2349 +          && fabs (object->correctedD0Vertex) < 0.02 \
2350 +          && fabs (object->correctedDZ) < 0.2 \
2351 +          && object->absInvEMinusInvPin < 0.05 \
2352 +          && object->passConvVeto;
2353 +      }
2354 +    else
2355 +      {
2356 +        value = fabs(object->delEtaIn) < 0.009 \
2357 +          && fabs (object->delPhiIn) < 0.10 \
2358 +          && object->scSigmaIEtaIEta < 0.03 \
2359 +          && object->hadOverEm < 0.10 \
2360 +          && fabs (object->correctedD0Vertex) < 0.02 \
2361 +          && fabs (object->correctedDZ) < 0.2 \
2362 +          && object->absInvEMinusInvPin < 0.05 \
2363 +          && object->passConvVeto;
2364 +      }
2365 +  }
2366 +
2367    else if(variable == "tightID"){
2368      if (object->isEB)
2369        {
# Line 1901 | Line 2389 | OSUAnalysis::valueLookup (const BNelectr
2389        }
2390    }
2391  
2392 +  else if(variable == "looseID_MVA"){
2393 +    value = object->pt > 10
2394 +      && object->mvaNonTrigV0 > 0;
2395 +      }
2396    else if(variable == "correctedD0VertexInEBPositiveCharge"){
2397      if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2398      else value = -999;
# Line 2024 | Line 2516 | OSUAnalysis::valueLookup (const BNelectr
2516      d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2517      dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2518      value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2519 <         || fabs (object->correctedD0Vertex / d0Error) > 99.0
2520 <         || fabs (object->correctedDZ / dzError) > 99.0;
2519 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2520 >      || fabs (object->correctedDZ / dzError) > 99.0;
2521      value = !value;
2522    }
2523  
2524  
2525  
2526 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2526 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2527  
2528    value = applyFunction(function, value);
2529  
2530    return value;
2531 < }
2531 > } // end electron valueLookup
2532 >
2533  
2534   //!event valueLookup
2535   double
# Line 2117 | Line 2610 | OSUAnalysis::valueLookup (const BNevent*
2610    else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2611    else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2612    else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2613 +  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2614  
2615 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2615 >  else if(variable == "unfilteredHt") value = getHt(jets.product());
2616 >  else if(variable == "ht") value = chosenHT ();
2617 >
2618 >  else if(variable == "leadMuPairInvMass"){
2619 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2620 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2621 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2622 >    value = (p0 + p1).M ();
2623 >  }
2624 >  else if(variable == "leadMuPairPt"){
2625 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2626 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2627 >             pt1 (muPair.second->px, muPair.second->py);
2628 >    pt0 += pt1;
2629 >    value = pt0.Mod ();
2630 >  }
2631 >  else if(variable == "leadElPairInvMass"){
2632 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2633 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2634 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2635 >    value = (p0 + p1).M ();
2636 >  }
2637 >  else if(variable == "leadElPairPt"){
2638 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2639 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2640 >             pt1 (muPair.second->px, muPair.second->py);
2641 >    pt0 += pt1;
2642 >    value = pt0.Mod ();
2643 >  }
2644 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2645  
2646    value = applyFunction(function, value);
2647  
2648    return value;
2649 < }
2649 > } // end event valueLookup
2650 >
2651  
2652   //!tau valueLookup
2653   double
# Line 2171 | Line 2695 | OSUAnalysis::valueLookup (const BNtau* o
2695    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2696    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2697  
2698 <
2698 >  else if (variable == "looseHadronicID") {
2699 >    value = object->pt > 10
2700 >      && object->eta < 2.3
2701 >      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2702 >      && object->HPSdecayModeFinding > 0
2703 >      && object->HPSagainstElectronLoose > 0
2704 >      && object->HPSagainstMuonTight > 0;
2705 >  }
2706  
2707    else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2708  
# Line 2218 | Line 2749 | OSUAnalysis::valueLookup (const BNtau* o
2749    }
2750  
2751  
2752 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2752 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2753  
2754    value = applyFunction(function, value);
2755  
2756    return value;
2757 < }
2757 > } // end tau valueLookup
2758 >
2759  
2760   //!met valueLookup
2761   double
# Line 2291 | Line 2823 | OSUAnalysis::valueLookup (const BNmet* o
2823    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2824    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2825  
2826 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2826 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2827  
2828    value = applyFunction(function, value);
2829  
2830    return value;
2831 < }
2831 > } // end met valueLookup
2832 >
2833  
2834   //!track valueLookup
2835   double
# Line 2324 | Line 2857 | OSUAnalysis::valueLookup (const BNtrack*
2857    else if(variable == "numValidHits") value = object->numValidHits;
2858    else if(variable == "isHighPurity") value = object->isHighPurity;
2859  
2327
2860    //additional BNs info for disappTrks
2861 <  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2862 <  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2863 <  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2864 <  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2865 <  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2866 <  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2867 <  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2868 <  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2337 <  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2861 >  else if(variable == "caloEMDeltaRp3")     value = object->caloEMDeltaRp3;
2862 >  else if(variable == "caloHadDeltaRp3")    value = object->caloHadDeltaRp3;
2863 >  else if(variable == "caloEMDeltaRp4")     value = object->caloEMDeltaRp4;
2864 >  else if(variable == "caloHadDeltaRp4")    value = object->caloHadDeltaRp4;
2865 >  else if(variable == "caloEMDeltaRp5")     value = object->caloEMDeltaRp5;
2866 >  else if(variable == "caloHadDeltaRp5")    value = object->caloHadDeltaRp5;
2867 >  else if(variable == "nHitsMissingOuter")  value = object->nHitsMissingOuter;
2868 >  else if(variable == "nHitsMissingInner")  value = object->nHitsMissingInner;
2869    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2870 <  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2870 >  else if(variable == "depTrkRp3")          value = object->depTrkRp3;
2871 >  else if(variable == "trkRelIsoRp3")     { value = (object->depTrkRp3 - object->pt) / object->pt; if (value<0) value = 0; }
2872 >  else if(variable == "trkRelIsoRp5")     { value = (object->depTrkRp5 - object->pt) / object->pt; if (value<0) value = 0; }
2873 >  else if(variable == "depEcalRp3")         value = object->depEcalRp3;
2874 >  else if(variable == "depHcalRp3")         value = object->depHcalRp3;
2875 >  else if(variable == "depHoRp3")           value = object->depHoRp3;
2876 >  else if(variable == "nTracksRp3")         value = object->nTracksRp3;
2877 >  else if(variable == "trackerVetoPtRp3")   value = object->trackerVetoPtRp3;
2878 >  else if(variable == "emVetoEtRp3")        value = object->emVetoEtRp3;
2879 >  else if(variable == "hadVetoEtRp3")       value = object->hadVetoEtRp3;
2880 >  else if(variable == "hoVetoEtRp3")        value = object->hoVetoEtRp3;
2881 >  else if(variable == "depTrkRp5")          value = object->depTrkRp5;
2882 >  else if(variable == "depEcalRp5")         value = object->depEcalRp5;
2883 >  else if(variable == "depHcalRp5")         value = object->depHcalRp5;
2884 >  else if(variable == "depHoRp5")           value = object->depHoRp5;
2885 >  else if(variable == "nTracksRp5")         value = object->nTracksRp5;
2886 >  else if(variable == "trackerVetoPtRp5")   value = object->trackerVetoPtRp5;
2887 >  else if(variable == "emVetoEtRp5")        value = object->emVetoEtRp5;
2888 >  else if(variable == "hadVetoEtRp5")       value = object->hadVetoEtRp5;
2889 >  else if(variable == "hoVetoEtRp5")        value = object->hoVetoEtRp5;
2890  
2891    //user defined variables
2892    else if(variable == "d0wrtBS") value = (object->vx-events->at(0).BSx)*object->py/object->pt - (object->vy-events->at(0).BSy)*object->px/object->pt;
2893    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2894 <  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2894 >  else if(variable == "depTrkRp5MinusPt"){
2895 >    if ( (object->depTrkRp5 - object->pt) < 0 ) {
2896 > //       clog << "Warning:  found track with depTrkRp5 < pt:  depTrkRp5=" << object->depTrkRp5
2897 > //         << "; pt=" << object->pt
2898 > //         << "; object->depTrkRp5 - object->pt = " << object->depTrkRp5 - object->pt
2899 > //         << endl;  
2900 >           value = 0;
2901 >         }
2902 >         else value =  (object->depTrkRp5 - object->pt);
2903 >  }
2904 >  else if(variable == "depTrkRp3MinusPt"){
2905 >    if ( (object->depTrkRp3 - object->pt) < 0 ) {
2906 >      value = 0;
2907 >    }
2908 >    else value =  (object->depTrkRp3 - object->pt);
2909 >  }
2910 >
2911 >  else if(variable == "dPhiMet") {
2912 >    if (const BNmet *met = chosenMET ()) {
2913 >      value = deltaPhi (object->phi, met->phi);
2914 >    } else value = -999;
2915 >  }
2916 >  
2917 >  
2918    else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2919    else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2920    else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2921    else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2922 +  else if(variable == "depTrkRp5RhoCorr")           value = getTrkDepTrkRp5RhoCorr(object);
2923 +  else if(variable == "depTrkRp3RhoCorr")           value = getTrkDepTrkRp3RhoCorr(object);
2924 +
2925 +  else if(variable == "depTrkRp5MinusPtRhoCorr")    {
2926 +    if ( (getTrkDepTrkRp5RhoCorr(object) - object->pt) < 0 ) value = 0;
2927 +    else {value = (getTrkDepTrkRp5RhoCorr(object) - object->pt );}
2928 +  }
2929 +  
2930 +  else if(variable == "depTrkRp3MinusPtRhoCorr")    
2931 +    {
2932 +      if ( (getTrkDepTrkRp3RhoCorr(object) - object->pt) < 0 ) value = 0;
2933 +      else {value = (getTrkDepTrkRp3RhoCorr(object) - object->pt );}
2934 +    }
2935 +
2936    else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2937    else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2938    else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
# Line 2369 | Line 2956 | OSUAnalysis::valueLookup (const BNtrack*
2956        pt = object->pt;
2957      value = vz - (vx * px + vy * py)/pt * (pz/pt);
2958    }
2959 +
2960 +  else if(variable == "deltaRMinSubLeadJet") {
2961 +    // calculate minimum deltaR between track and any other subleading jet  
2962 +    double trkJetDeltaRMin = 99.;  
2963 +    for (uint ijet = 0; ijet<jets->size(); ijet++) {
2964 +      string empty = "";  
2965 +      double isSubLeadingJet = valueLookup(&jets->at(ijet), "disappTrkSubLeadingJetID", "", empty);  
2966 +      if (!isSubLeadingJet) continue;  // only consider jets that pass the subleading jet ID criteria  
2967 +      double jetEta = valueLookup(&jets->at(ijet), "eta", "", empty);
2968 +      double jetPhi = valueLookup(&jets->at(ijet), "phi", "", empty);
2969 +      double trkJetDeltaR = deltaR(object->eta, object->phi, jetEta, jetPhi);  
2970 +      if (trkJetDeltaR < trkJetDeltaRMin) trkJetDeltaRMin = trkJetDeltaR;
2971 +    }
2972 +    value = trkJetDeltaRMin;  
2973 +  }  
2974 +  
2975    else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2976  
2977    else if(variable == "genMatchedPdgId"){
# Line 2416 | Line 3019 | OSUAnalysis::valueLookup (const BNtrack*
3019  
3020  
3021  
3022 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3022 >  else{clog << "WARNING: invalid variable '" << variable << "' for BNtrack collection.\n"; value = -999;}
3023  
3024    value = applyFunction(function, value);
3025  
3026    return value;
3027 < }
3027 > } // end track valueLookup
3028 >
3029  
3030   //!genjet valueLookup
3031   double
# Line 2445 | Line 3049 | OSUAnalysis::valueLookup (const BNgenjet
3049    else if(variable == "charge") value = object->charge;
3050  
3051  
3052 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3052 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3053  
3054    value = applyFunction(function, value);
3055  
# Line 2579 | Line 3183 | OSUAnalysis::valueLookup (const BNmcpart
3183    }
3184  
3185  
3186 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3186 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3187  
3188    value = applyFunction(function, value);
3189  
3190    return value;
3191 < }
3191 > } // end mcparticle valueLookup
3192 >
3193  
3194   //!primaryvertex valueLookup
3195   double
# Line 2607 | Line 3212 | OSUAnalysis::valueLookup (const BNprimar
3212    else if(variable == "isGood") value = object->isGood;
3213  
3214  
3215 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3215 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3216  
3217    value = applyFunction(function, value);
3218  
# Line 2625 | Line 3230 | OSUAnalysis::valueLookup (const BNbxlumi
3230    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
3231  
3232  
3233 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3233 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3234  
3235    value = applyFunction(function, value);
3236  
# Line 2758 | Line 3363 | OSUAnalysis::valueLookup (const BNphoton
3363    }
3364  
3365  
3366 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3366 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3367  
3368    value = applyFunction(function, value);
3369  
3370    return value;
3371 < }
3371 > } // end photon valueLookup
3372 >
3373  
3374   //!supercluster valueLookup
3375   double
# Line 2781 | Line 3387 | OSUAnalysis::valueLookup (const BNsuperc
3387    else if(variable == "theta") value = object->theta;
3388  
3389  
3390 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3390 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3391  
3392    value = applyFunction(function, value);
3393  
# Line 2815 | Line 3421 | OSUAnalysis::valueLookup (const BNtrigob
3421        stringValue = "none";  // stringValue should only be empty if value is filled
3422    }
3423  
3424 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3424 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3425  
3426    value = applyFunction(function, value);
3427  
# Line 2886 | Line 3492 | OSUAnalysis::valueLookup (const BNmuon*
3492        value = object2->correctedD0;
3493      }
3494  
3495 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3495 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3496 >
3497 >  value = applyFunction(function, value);
3498 >
3499 >  return value;
3500 > } // end muon-muon pair valueLookup
3501 >
3502 >
3503 > //!muon-photon pair valueLookup
3504 > double
3505 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3506 >
3507 >  double value = 0.0;
3508 >
3509 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3510 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3511 >  else if(variable == "photonEta") value = object2->eta;
3512 >  else if(variable == "photonPt") value = object2->pt;
3513 >  else if(variable == "muonEta") value = object1->eta;
3514 >  else if(variable == "photonPhi") value = object2->phi;
3515 >  else if(variable == "muonPhi") value = object1->phi;
3516 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3517 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3518 >  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3519 >  else if(variable == "invMass"){
3520 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3521 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3522 >    value = (fourVector1 + fourVector2).M();
3523 >  }
3524 >  else if(variable == "pt"){
3525 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3526 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3527 >    value = (fourVector1 + fourVector2).Pt();
3528 >  }
3529 >  else if(variable == "threeDAngle")
3530 >    {
3531 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3532 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3533 >      value = (threeVector1.Angle(threeVector2));
3534 >    }
3535 >  else if(variable == "alpha")
3536 >    {
3537 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3538 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3539 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3540 >      value = (pi-threeVector1.Angle(threeVector2));
3541 >    }
3542 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3543 >
3544 >  value = applyFunction(function, value);
3545 >
3546 >  return value;
3547 > }
3548 >
3549 > //!electron-photon pair valueLookup
3550 > double
3551 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3552 >
3553 >  double value = 0.0;
3554 >
3555 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3556 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3557 >  else if(variable == "photonEta") value = object2->eta;
3558 >  else if(variable == "photonPt") value = object2->pt;
3559 >  else if(variable == "electronEta") value = object1->eta;
3560 >  else if(variable == "photonPhi") value = object2->phi;
3561 >  else if(variable == "electronPhi") value = object1->phi;
3562 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3563 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3564 >  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3565 >  else if(variable == "invMass"){
3566 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3567 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3568 >    value = (fourVector1 + fourVector2).M();
3569 >  }
3570 >  else if(variable == "pt"){
3571 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3572 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3573 >    value = (fourVector1 + fourVector2).Pt();
3574 >  }
3575 >  else if(variable == "threeDAngle")
3576 >    {
3577 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3578 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3579 >      value = (threeVector1.Angle(threeVector2));
3580 >    }
3581 >  else if(variable == "alpha")
3582 >    {
3583 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3584 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3585 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3586 >      value = (pi-threeVector1.Angle(threeVector2));
3587 >    }
3588 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3589  
3590    value = applyFunction(function, value);
3591  
# Line 2942 | Line 3641 | OSUAnalysis::valueLookup (const BNelectr
3641      value = object2->correctedD0;
3642    }
3643  
3644 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3644 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3645  
3646    value = applyFunction(function, value);
3647  
3648    return value;
3649   }
3650 +
3651   //!electron-muon pair valueLookup
3652   double
3653   OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
# Line 3008 | Line 3708 | OSUAnalysis::valueLookup (const BNelectr
3708    else if(variable == "muonRelPFdBetaIso"){
3709      value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3710    }
3711 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3711 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3712    value = applyFunction(function, value);
3713  
3714    return value;
3715 < }
3715 > } // end electron-muon pair valueLookup
3716  
3717 +
3718   //!electron-jet pair valueLookup
3719   double
3720   OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
# Line 3022 | Line 3723 | OSUAnalysis::valueLookup (const BNelectr
3723  
3724    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3725    else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3726 +  else if(variable == "jetEta") value = object2->eta;
3727 +  else if(variable == "jetPhi") value = object2->phi;
3728 +  else if(variable == "electronEta") value = object1->eta;
3729 +  else if(variable == "electronPhi") value = object1->phi;
3730    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3731    else if(variable == "invMass"){
3732      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 3043 | Line 3748 | OSUAnalysis::valueLookup (const BNelectr
3748      value = object1->charge*object2->charge;
3749    }
3750  
3751 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3751 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3752    value = applyFunction(function, value);
3753  
3754    return value;
3755   }
3756  
3757 + //!electron-mcparticle pair valueLookup
3758 + double
3759 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmcparticle* object2, string variable, string function, string &stringValue){
3760 +
3761 +  double value = 0.0;
3762 +
3763 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3764 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3765 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3766 +  else if(variable == "threeDAngle")
3767 +    {
3768 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3769 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3770 +      value = (threeVector1.Angle(threeVector2));
3771 +    }
3772 +  else if(variable == "chargeProduct"){
3773 +    value = object1->charge*object2->charge;
3774 +  }
3775 +
3776 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3777 +  value = applyFunction(function, value);
3778 +
3779 +  return value;
3780 + }
3781 +
3782 +
3783 + //!photon-jet pair valueLookup
3784 + double
3785 + OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3786 +
3787 +  double value = 0.0;
3788 +
3789 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3790 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3791 +  else if(variable == "jetEta") value = object2->eta;
3792 +  else if(variable == "jetPhi") value = object2->phi;
3793 +  else if(variable == "photonEta") value = object1->eta;
3794 +  else if(variable == "photonPhi") value = object1->phi;
3795 +  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3796 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3797 +  else if(variable == "invMass"){
3798 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3799 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3800 +    value = (fourVector1 + fourVector2).M();
3801 +  }
3802 +  else if(variable == "pt"){
3803 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3804 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3805 +    value = (fourVector1 + fourVector2).Pt();
3806 +  }
3807 +  else if(variable == "threeDAngle")
3808 +    {
3809 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3810 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3811 +      value = (threeVector1.Angle(threeVector2));
3812 +    }
3813 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3814 +  value = applyFunction(function, value);
3815 +
3816 +  return value;
3817 + }
3818 +
3819 + // track-jet pair valueLookup
3820 + double
3821 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNjet* object2, string variable, string function, string &stringValue){
3822 +
3823 +  double value = 0.0;
3824 +
3825 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3826 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3827 +
3828 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3829 +  value = applyFunction(function, value);
3830 +
3831 +  return value;
3832 +
3833 + }
3834 +
3835 +
3836 +
3837 + // met-jet pair valueLookup
3838 + double
3839 + OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3840 +
3841 +  double value = 0.0;
3842 +
3843 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3844 +
3845 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3846 +  value = applyFunction(function, value);
3847 +
3848 +  return value;
3849 +
3850 + }  
3851 +
3852 +
3853 +
3854   //!muon-jet pair valueLookup
3855   double
3856   OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
# Line 3056 | Line 3858 | OSUAnalysis::valueLookup (const BNmuon*
3858    double value = 0.0;
3859  
3860    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3861 <  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3861 >  else if(variable == "jetEta") value = object2->eta;
3862 >  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3863 >  else if(variable == "jetPt") value = object2->pt;
3864 >  else if(variable == "jetPhi") value = object2->phi;
3865 >  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3866 >  else if(variable == "muonEta") value = object1->eta;
3867 >  else if(variable == "muonPt") value = object1->pt;
3868 >  else if(variable == "muonPhi") value = object1->phi;
3869 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3870    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3871    else if(variable == "invMass"){
3872      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 3078 | Line 3888 | OSUAnalysis::valueLookup (const BNmuon*
3888      value = object1->charge*object2->charge;
3889    }
3890  
3891 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3891 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3892    value = applyFunction(function, value);
3893  
3894    return value;
3895   }
3896  
3897 + //!muon-event valueLookup
3898 + double
3899 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNevent* object2, string variable, string function, string &stringValue){
3900 +
3901 +  double value = 0.0;
3902 +
3903 +  if(variable == "muonEta") value = object1->eta;
3904 +  else if(variable == "muonPt") value = object1->pt;
3905 +  else if(variable == "muonPhi") value = object1->phi;
3906 +  else if(variable == "Ht") value = getHt(jets.product());
3907 +  else if(variable == "pthat")   value = object2->pthat;
3908 +  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3909 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3910 +  value = applyFunction(function, value);
3911 +
3912 +  return value;
3913 + }
3914   //!jet-jet pair valueLookup
3915   double
3916   OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
# Line 3092 | Line 3919 | OSUAnalysis::valueLookup (const BNjet* o
3919  
3920    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3921    else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3922 <  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3922 >  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3923    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3924    else if(variable == "invMass"){
3925      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 3114 | Line 3941 | OSUAnalysis::valueLookup (const BNjet* o
3941      value = object1->charge*object2->charge;
3942    }
3943  
3944 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3944 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3945    value = applyFunction(function, value);
3946  
3947    return value;
3948   }
3949 +
3950   //!electron-track pair valueLookup
3951   double
3952   OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
# Line 3129 | Line 3957 | OSUAnalysis::valueLookup (const BNelectr
3957    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3958    else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3959    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3960 +  else if(variable == "deltaRLooseMvaId") {
3961 +    // only consider electrons that pass "loose MVA id", i.e., mvaNonTrigV0 > 0;
3962 +    // otherwise return very large value (99)  
3963 +    if (object1->mvaNonTrigV0>0) value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3964 +    else                         value = 99.;  
3965 +  }
3966    else if(variable == "invMass"){
3967      fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3968      fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
# Line 3138 | Line 3972 | OSUAnalysis::valueLookup (const BNelectr
3972    else if(variable == "chargeProduct"){
3973      value = object1->charge*object2->charge;
3974    }
3975 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3975 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3976    value = applyFunction(function, value);
3977    return value;
3978  
# Line 3156 | Line 3990 | OSUAnalysis::valueLookup (const BNmuon*
3990    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3991    else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3992    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3993 +  else if(variable == "deltaRLooseID") {
3994 +    // only consider muons that pass looseId criteria; otherwise return very large value (99.)  
3995 +    string empty = "";  
3996 +    double isLooseId = valueLookup(object1, "looseID", "", empty);    
3997 +    if (isLooseId) value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3998 +    else           value = 99.;  
3999 +  }
4000    else if(variable == "invMass"){
4001      fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
4002      fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
# Line 3166 | Line 4007 | OSUAnalysis::valueLookup (const BNmuon*
4007      value = object1->charge*object2->charge;
4008    }
4009  
4010 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4010 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4011    value = applyFunction(function, value);
4012    return value;
4013   }
# Line 3188 | Line 4029 | OSUAnalysis::valueLookup (const BNtau* o
4029      value = object1->charge*object2->charge;
4030    }
4031  
4032 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4032 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4033    value = applyFunction(function, value);
4034    return value;
4035   }
# Line 3210 | Line 4051 | OSUAnalysis::valueLookup (const BNmuon*
4051      value = object1->charge*object2->charge;
4052    }
4053  
4054 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4054 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4055    value = applyFunction(function, value);
4056    return value;
4057   }
# Line 3221 | Line 4062 | OSUAnalysis::valueLookup (const BNtau* o
4062    double value = 0.0;
4063    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
4064    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4065 +  else if(variable == "deltaRLooseHadronicID") {
4066 +    // only consider tau's that pass the loose hadronic ID criteria; otherwise return very large value (99)  
4067 +    string empty = "";  
4068 +    double isLooseHadronicID = valueLookup(object1, "looseHadronicID", "", empty);    
4069 +  
4070 +    if (isLooseHadronicID) value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4071 +    else                   value = 99.;  
4072 +  }
4073    else if(variable == "chargeProduct"){
4074      value = object1->charge*object2->charge;
4075    }
4076  
4077 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4077 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4078    value = applyFunction(function, value);
4079    return value;
4080   }
# Line 3245 | Line 4094 | OSUAnalysis::valueLookup (const BNtrack*
4094    else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
4095    else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
4096  
4097 <  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4097 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4098  
4099    value = applyFunction(function, value);
4100  
# Line 3267 | Line 4116 | OSUAnalysis::valueLookup (const BNelectr
4116        stringValue = "none";
4117    }
4118  
4119 <  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4119 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4120  
4121    value = applyFunction(function, value);
4122  
# Line 3283 | Line 4132 | OSUAnalysis::valueLookup (const BNmuon*
4132  
4133    if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4134  
4135 <  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4135 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4136  
4137    value = applyFunction(function, value);
4138  
# Line 3386 | Line 4235 | OSUAnalysis::valueLookup (const BNstop*
4235      for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4236        vertex_rank++;
4237        int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4238 <                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4239 <                   (object->vz-vertex->z)*(object->vz-vertex->z));
4238 >                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
4239 >                      (object->vz-vertex->z)*(object->vz-vertex->z));
4240  
4241        if(abs(dist) < abs(minDistToVertex)){
4242          value = vertex_rank;
# Line 3396 | Line 4245 | OSUAnalysis::valueLookup (const BNstop*
4245      }
4246    }
4247  
4248 +  else if (variable == "decaysToTau"){
4249 +    value = abs (object->daughter0Id) == 15 || abs (object->daughter1Id) == 15;
4250 +  }
4251 +
4252  
4253  
4254  
4255 <  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4255 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4256  
4257    value = applyFunction(function, value);
4258  
4259    return value;
4260  
4261 < }
4261 > } // end stop valueLookup
4262 >
4263  
4264  
4265  
# Line 3423 | Line 4277 | OSUAnalysis::getTrkIsIso (const BNtrack*
4277  
4278   }
4279  
4280 + //calculate the scalar sum of Jet Pt in the event.
4281 + double
4282 + OSUAnalysis::getHt (const BNjetCollection* jetColl){
4283 +  double Ht = 0;
4284 +  for(BNjetCollection::const_iterator jet = jetColl->begin(); jet !=jetColl->end(); jet++){
4285 +    Ht += abs(jet->pt);
4286 +  }
4287 +  return Ht;
4288 + }
4289  
4290   double
4291   OSUAnalysis::getTrkPtRes (const BNtrack* track1){
# Line 3460 | Line 4323 | OSUAnalysis::getTrkCaloTotRhoCorr(const
4323    // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
4324    if (!useTrackCaloRhoCorr_) return -99;
4325    // if (!rhokt6CaloJetsHandle_) {
4326 <  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
4326 >  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
4327    //   return -99;
4328    // }
4329    double radDeltaRCone = 0.5;
# Line 3471 | Line 4334 | OSUAnalysis::getTrkCaloTotRhoCorr(const
4334  
4335   }
4336  
4337 + double
4338 + OSUAnalysis::getTrkDepTrkRp5RhoCorr(const BNtrack* track) {
4339 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.              
4340 +  if (!useTrackCaloRhoCorr_) return -99;
4341 +  // if (!rhokt6CaloJetsHandle_) {                                                                                                    
4342 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;                        
4343 +  //   return -99;                                                                                                                    
4344 +  // }                                                                                                                                
4345 +  double radDeltaRCone = 0.5;
4346 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.                                                                                                          
4347 +  double rawDepTrkRp5 = track->depTrkRp5;
4348 + double depTrkRp5RhoCorr = TMath::Max(0., rawDepTrkRp5 - rhoCorr_kt6CaloJets);
4349 + return depTrkRp5RhoCorr;
4350 +
4351 + }
4352 +
4353 + double
4354 + OSUAnalysis::getTrkDepTrkRp3RhoCorr(const BNtrack* track) {
4355 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.                                                
4356 +  if (!useTrackCaloRhoCorr_) return -99;
4357 +  // if (!rhokt6CaloJetsHandle_) {                                                                                                                                      
4358 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;                                                          
4359 +  //   return -99;                                                                                                                                                      
4360 +  // }                                                                                                                                                                  
4361 +  double radDeltaRCone = 0.3;
4362 + // Define effective area as pi*r^2, where r is radius of DeltaR cone
4363 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  
4364 +  double rawDepTrkRp3 = track->depTrkRp3;
4365 +  double depTrkRp3RhoCorr = TMath::Max(0., rawDepTrkRp3 - rhoCorr_kt6CaloJets);
4366 +  return depTrkRp3RhoCorr;
4367 +  
4368 + }
4369 +
4370  
4371  
4372  
# Line 3482 | Line 4378 | OSUAnalysis::WriteDeadEcal (){
4378    double etaEcal, phiEcal;
4379    ifstream DeadEcalFile(deadEcalFile_);
4380    if(!DeadEcalFile) {
4381 <    cout << "Error: DeadEcalFile has not been found." << endl;
4381 >    clog << "Error: DeadEcalFile has not been found." << endl;
4382      return;
4383    }
4384    if(DeadEcalVec.size()!= 0){
4385 <    cout << "Error: DeadEcalVec has a nonzero size" << endl;
4385 >    clog << "Error: DeadEcalVec has a nonzero size" << endl;
4386      return;
4387    }
4388    while(!DeadEcalFile.eof())
# Line 3497 | Line 4393 | OSUAnalysis::WriteDeadEcal (){
4393        newChan.phiEcal = phiEcal;
4394        DeadEcalVec.push_back(newChan);
4395      }
4396 <  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
4396 >  if(DeadEcalVec.size() == 0) clog << "Warning: No dead Ecal channels have been found." << endl;
4397   }
4398  
4399   //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
# Line 3537 | Line 4433 | OSUAnalysis::applyFunction(string functi
4433    else if(function == "log") value = log10(value);
4434  
4435    else if(function == "") value = value;
4436 <  else{cout << "WARNING: invalid function '" << function << "'\n";}
4436 >  else{clog << "WARNING: invalid function '" << function << "'\n";}
4437  
4438    return value;
4439  
# Line 3547 | Line 4443 | OSUAnalysis::applyFunction(string functi
4443   template <class InputCollection>
4444   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
4445  
4446 +  if (verbose_>2) clog << "  Beginning setObjectFlags for cut " << currentCutIndex << ": " << currentCut.name
4447 +                       << ", inputType=" << inputType
4448 +                       << endl;  
4449    if (currentCut.inputCollection.find("pair")!=string::npos)  {
4450      string obj1, obj2;
4451      getTwoObjs(currentCut.inputCollection, obj1, obj2);
4452 +    if (verbose_>2) clog << "  Two object types:  " << obj1 << ", " << obj2 << endl;
4453      if (inputType==obj1 ||
4454 <          inputType==obj2) {
4454 >        inputType==obj2) {
4455        // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
4456        // and the inputType is a member of the pair.
4457        // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
# Line 3561 | Line 4461 | void OSUAnalysis::setObjectFlags(cut &cu
4461      }
4462    }
4463  
4464 +  if (!inputCollection) cout << "ERROR:  invalid input collection for inputType=" << inputType << endl;  
4465 +
4466 +  if (verbose_>3) clog << "   Collection size:  " << inputCollection->size() << endl;
4467 +
4468    for (uint object = 0; object != inputCollection->size(); object++){
4469  
4470 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
4470 >    if (verbose_>4) clog << "    Setting flags for object " << object << endl;
4471 >
4472 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4473 >    bool plotDecision = true;
4474  
4475      if(currentCut.inputCollection == inputType){
4476  
# Line 3575 | Line 4482 | void OSUAnalysis::setObjectFlags(cut &cu
4482          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4483  
4484        }
4485 <      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4485 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4486        else{
4487          bool tempDecision = true;
4488          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
# Line 3584 | Line 4491 | void OSUAnalysis::setObjectFlags(cut &cu
4491            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4492              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4493          }
4494 <        decision = tempDecision;
4494 >        cutDecision = tempDecision;
4495        }
4496 +      //invert the cut if this cut is a veto
4497 +      if(currentCut.isVeto) cutDecision = !cutDecision;
4498 +      plotDecision = cutDecision;
4499      }
4500  
4501 <    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4501 >    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4502  
4503 <    //set flags for objects that pass each cut AND all the previous cuts
4504 <    bool previousCumulativeFlag = true;
4503 >    //set flags for objects that pass this cut AND all the previous cuts
4504 >    bool previousCumulativeCutFlag = true;
4505      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4506 <      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4507 <      else{ previousCumulativeFlag = false; break;}
4506 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4507 >      else{ previousCumulativeCutFlag = false; break;}
4508      }
4509 <    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4509 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4510 >    bool previousCumulativePlotFlag = true;
4511 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4512 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4513 >      else{ previousCumulativePlotFlag = false; break;}
4514 >    }
4515 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4516  
4517 <  }
4517 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4518  
4519 < }
4519 >  }  //   for (uint object = 0; object != inputCollection->size(); object++){
4520  
4521 + } // end void OSUAnalysis::setObjectFlags
4522  
3606 template <class InputCollection1, class InputCollection2>
3607 void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
3608                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
4523  
4524 + template <class InputCollection1, class InputCollection2>
4525 + void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags,
4526 +                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, string inputType){
4527 +  // This function sets the flags for the paired object collection.  
4528 +  // If the cut is applying on the given paired object collection, then the flags for the single object collections are also set.
4529 +  // If not, then the flags for the paired object collection are taken as the AND of the flags for each single object collection.  
4530 +
4531 +  if (verbose_>2) clog << "  Beginning setObjectFlags for cut=" << currentCut.name
4532 +                       << ", inputType=" << inputType
4533 +                       << endl;  
4534  
4535    bool sameObjects = false;
4536 <  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4536 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;  // FIXME:  is sameObjects just the not of isTwoTypesOfObject?  If so, it's redundant.  
4537  
4538    // Get the strings for the two objects that make up the pair.
4539    string obj1Type, obj2Type;
# Line 3621 | Line 4545 | void OSUAnalysis::setObjectFlags(cut &cu
4545    // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4546    if (currentCut.inputCollection == inputType) {
4547      for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4548 <      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
4549 <      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
4548 >      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4549 >      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4550      }
4551      if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4552        for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4553 <        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
4554 <        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
4553 >        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4554 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4555        }
4556      }
4557    }
# Line 3640 | Line 4564 | void OSUAnalysis::setObjectFlags(cut &cu
4564        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4565  
4566  
4567 <      bool decision = true;//object passes if this cut doesn't cut on that type of object
4567 >      bool cutDecision  = true;//object passes if this cut doesn't cut on that type of object
4568 >      bool plotDecision = true;
4569  
4570 +      // Determine whether each pair passes the cut, only if inputCollection is the same as the inputType.  
4571        if(currentCut.inputCollection == inputType){
4572  
4573          vector<bool> subcutDecisions;
4574          for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4575            string stringValue = "";
4576            double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4577 +          if (verbose_>1) clog << currentCut.variables.at(subcutIndex) << " = " << value
4578 +                               << endl;  
4579            if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4580            else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4581          }
4582  
4583 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4583 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4584          else{
4585            bool tempDecision = subcutDecisions.at(0);
4586            for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
# Line 3661 | Line 4589 | void OSUAnalysis::setObjectFlags(cut &cu
4589              else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4590                tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4591            }
4592 <          decision = tempDecision;
4592 >          cutDecision = tempDecision;
4593          }
4594 +        //invert the cut if this cut is a veto
4595 +        if (currentCut.isVeto) cutDecision = !cutDecision;
4596 +        plotDecision = cutDecision;
4597 +
4598 +        if (verbose_>1) clog << " cutDecision = " << cutDecision
4599 +                             << "; for currentCut.inputCollection = " << currentCut.inputCollection
4600 +                             << "; object1 (" << obj1Type << ") = " << object1
4601 +                             << "; object2 (" << obj2Type << ") = " << object2
4602 +                             << endl;  
4603 +        
4604 +        if (cutDecision) {  // only set the flags for the individual objects if the pair object is being cut on
4605 +          individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4606 +          individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4607 +        }
4608 +        if (plotDecision) {  // only set the flags for the individual objects if the pair object is being cut on
4609 +          individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4610 +          individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4611 +        }
4612 +        
4613 +
4614 +      } // if(currentCut.inputCollection == inputType){
4615 +
4616 +      // The individualFlags will be true if the inputCollection is not the same as the inputType.
4617 +      // They are also independent of the previous flags on the single objects.  
4618 +      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));  
4619 +
4620 +
4621 +
4622 +      // ************************************
4623 +      // Determine cumulative flags
4624 +      // ************************************
4625 +      // determine whether this paired object passes this cut AND all previous cuts
4626 +      bool previousCumulativeCutFlag = true;
4627 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4628 +        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4629 +        else{ previousCumulativeCutFlag = false; break;}
4630        }
4631 <      // if (decision) isPassObj1.at(object1) = true;
3668 <      // if (decision) isPassObj2.at(object2) = true;
3669 <      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3670 <      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3671 <        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;
3672 <        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;
3673 <      }
4631 >      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4632  
4633 <      //set flags for objects that pass each cut AND all the previous cuts
3676 <      bool previousCumulativeFlag = true;
4633 >      bool previousCumulativePlotFlag = true;
4634        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4635 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
4636 <        else{ previousCumulativeFlag = false; break;}
4635 >        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4636 >        else{ previousCumulativePlotFlag = false; break;}
4637        }
4638 <      //apply flags for the components of the composite object as well
4639 <      bool currentCumulativeFlag = true;
4640 <      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
4641 <      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
4642 <      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
4643 <      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
4644 <      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
4645 <      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4646 <        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);
4647 <        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);
4638 >      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4639 >      
4640 >      // Get the index for the flags of each of the single objects in the pair.  Usually this is the index of the previous cut, i.e., currentCutIndex-1.    
4641 >      int cutIdxFlagsObj1 = max(int(currentCutIndex-1),0);
4642 >      int cutIdxFlagsObj2 = max(int(currentCutIndex-1),0);
4643 >      // If the inputCollection of the cut is not equal to the inputType but the inputCollection includes objects that are contained in inputType, then use the currentCutIndex for those collections.
4644 >      // For example, if the inputType is jet-jet pairs, and the inputCollection is track-jet pairs, then use currentCutIndex for cutIdxFlagsObj{1,2}, i.e., for both jets.  
4645 >      // For example, if the inputType is jets, and the inputCollection is track-jet pairs, then use currentCutIndex for cutIdxFlagsObj2 (jets) and currentCutIndex-1 for cutIdxFlagsObj1 (tracks).  
4646 >      if (currentCut.inputCollection != inputType) {  
4647 >        if (currentCut.inputCollection.find(obj1Type)!=string::npos) cutIdxFlagsObj1 = currentCutIndex;
4648 >        if (currentCut.inputCollection.find(obj2Type)!=string::npos) cutIdxFlagsObj2 = currentCutIndex;
4649 >      }  
4650 >      flagPair flags1 = cumulativeFlags.at(obj1Type).at(cutIdxFlagsObj1);  // flag for input collection 1
4651 >      flagPair flags2 = cumulativeFlags.at(obj2Type).at(cutIdxFlagsObj2);  // flag for input collection 2
4652 >      
4653 >      // The cumulative flag is only true if the paired object cumulative flag is true, and if the single object cumulative flags are true.  
4654 >      bool currentCumulativeCutFlag = true;
4655 >      bool currentCumulativePlotFlag = true;
4656 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4657 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4658 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4659 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4660 >
4661 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4662 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4663 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4664 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4665 >
4666 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));  // Set the flag for the paired object
4667 >
4668 >
4669 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // Set the flags for the individual objects if the paired object is being cut on.  
4670 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first  = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4671 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first  = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4672 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4673 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4674 >
4675 >        if (verbose_>1) clog << " previousCumulativeCutFlag for object1 = " << getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object1, "cut") << endl;  
4676 >        if (verbose_>1) clog << " previousCumulativeCutFlag for object2 = " << getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut") << endl;  
4677 >
4678        }
4679 +
4680        counter++;
4681  
4682      } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4683    }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4684  
4685 < }
4685 > } // end void OSUAnalysis::setObjectFlags
4686  
4687  
4688 < bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
4688 > bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4689    // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4690    // all cuts up to currentCutIndex
4691    bool previousCumulativeFlag = true;
4692    for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4693 <    if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
4693 >    bool tempFlag = false;
4694 >    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4695 >    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4696 >
4697 >    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4698      else {
4699        previousCumulativeFlag = false; break;
4700      }
# Line 3711 | Line 4703 | bool OSUAnalysis::getPreviousCumulativeF
4703   }
4704  
4705  
4706 +
4707 +
4708 + template <class InputCollection>
4709 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4710 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4711 +
4712 +  if (BNTreeBranchVals_.count(parameters.name)==0) clog << "Error[assignTreeBranch]:  trying to assign value to " << parameters.name << " that does not have a branch set up.  Will likely seg fault." << endl;
4713 +  for (uint object = 0; object != inputCollection->size(); object++) {
4714 +
4715 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4716 +
4717 +    string inputVariable = parameters.inputVariable;
4718 +    string function = "";
4719 +    string stringValue = "";
4720 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4721 +    BNTreeBranchVals_.at(parameters.name).push_back(value);
4722 +
4723 +  }
4724 + }
4725 +
4726 +
4727   template <class InputCollection>
4728 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4728 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4729 >
4730 >  if (verbose_>2) clog << "  Filling histogram for " << parameters.name << endl;  
4731  
4732    for (uint object = 0; object != inputCollection->size(); object++){
4733  
4734 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4734 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4735  
4736      string currentString = parameters.inputVariables.at(0);
4737      string inputVariable = "";
# Line 3733 | Line 4748 | void OSUAnalysis::fill1DHistogram(TH1* h
4748      string stringValue = "";
4749      double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4750      histo->Fill(value,scaleFactor);
4751 +
4752      if (printEventInfo_) {
4753        // Write information about event to screen, for testing purposes.
4754 <      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
4754 >      clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << " (object number " << object << ")" << endl;
4755      }
4756  
4757    }
4758   }
4759  
4760   template <class InputCollection1, class InputCollection2>
4761 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4761 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2,
4762 >                                  flagPair pairFlags, double scaleFactor){
4763  
4764    bool sameObjects = false;
4765    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
# Line 3754 | Line 4771 | void OSUAnalysis::fill1DHistogram(TH1* h
4771        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4772  
4773        pairCounter++;
4774 <      //only take objects which have passed all cuts and pairs which have passed all cuts
3758 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3759 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3760 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4774 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4775  
4776        string currentString = parameters.inputVariables.at(0);
4777        string inputVariable = "";
# Line 3775 | Line 4789 | void OSUAnalysis::fill1DHistogram(TH1* h
4789        double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4790        histo->Fill(value,scaleFactor);
4791  
4792 +      if (printEventInfo_) {
4793 +        // Write information about event to screen, for testing purposes.
4794 +        clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value
4795 +             << " (object1 number " << object1 << "), "
4796 +             << " (object2 number " << object2 << ")"
4797 +             << endl;
4798 +      }
4799 +      
4800      }
4801    }
4802  
# Line 3782 | Line 4804 | void OSUAnalysis::fill1DHistogram(TH1* h
4804  
4805  
4806   template <class InputCollection>
4807 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4807 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4808  
4809    for (uint object = 0; object != inputCollection->size(); object++){
4810  
4811 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4811 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4812  
4813      string stringValue = "";
4814      string currentString = parameters.inputVariables.at(0);
# Line 3823 | Line 4845 | void OSUAnalysis::fill2DHistogram(TH2* h
4845   }
4846  
4847   template <class InputCollection1, class InputCollection2>
4848 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4848 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2,
4849 >                                  flagPair pairFlags, double scaleFactor){
4850  
4851    bool sameObjects = false;
4852    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
# Line 3836 | Line 4859 | void OSUAnalysis::fill2DHistogram(TH2* h
4859  
4860        pairCounter++;
4861  
4862 <      //only take objects which have passed all cuts and pairs which have passed all cuts
3840 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3841 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3842 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4862 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4863  
4864        string stringValue = "";
4865        string currentString = parameters.inputVariables.at(0);
# Line 3887 | Line 4907 | int OSUAnalysis::getGenMatchedParticleIn
4907  
4908      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4909      if(currentDeltaR > 0.05) continue;
4910 <    //     cout << setprecision(3) << setw(20)
4910 >    //     clog << setprecision(3) << setw(20)
4911      //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4912      //          << setw(20)
4913      //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
# Line 3906 | Line 4926 | int OSUAnalysis::getGenMatchedParticleIn
4926      }
4927  
4928    }
4929 <  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4930 <  //   else cout << "no match found..." << endl;
4929 >  //   if(bestMatchDeltaR != 999)  clog << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4930 >  //   else clog << "no match found..." << endl;
4931    return bestMatchIndex;
4932  
4933   }
# Line 3999 | Line 5019 | OSUAnalysis::chosenVertex ()
5019   {
5020    const BNprimaryvertex *chosenVertex = 0;
5021    if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
5022 <    vector<bool> vertexFlags;
5022 >    flagPair vertexFlags;
5023      for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
5024        if (cumulativeFlags.at("primaryvertexs").at(i).size()){
5025          vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
# Line 4007 | Line 5027 | OSUAnalysis::chosenVertex ()
5027        }
5028      }
5029      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
5030 <      if(!vertexFlags.at(vertexIndex)) continue;
5030 >      if(!vertexFlags.at(vertexIndex).first) continue;
5031        chosenVertex = & primaryvertexs->at(vertexIndex);
5032        break;
5033      }
# Line 4023 | Line 5043 | OSUAnalysis::chosenMET ()
5043   {
5044    const BNmet *chosenMET = 0;
5045    if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
5046 <    vector<bool> metFlags;
5046 >    flagPair metFlags;
5047      for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
5048        if (cumulativeFlags.at("mets").at(i).size()){
5049          metFlags = cumulativeFlags.at("mets").at(i);
# Line 4031 | Line 5051 | OSUAnalysis::chosenMET ()
5051        }
5052      }
5053      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
5054 <      if(!metFlags.at(metIndex)) continue;
5054 >      if(!metFlags.at(metIndex).first) continue;
5055        chosenMET = & mets->at(metIndex);
5056        break;
5057      }
# Line 4047 | Line 5067 | OSUAnalysis::chosenElectron ()
5067   {
5068    const BNelectron *chosenElectron = 0;
5069    if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
5070 <    vector<bool> electronFlags;
5070 >    flagPair electronFlags;
5071      for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
5072        if (cumulativeFlags.at("electrons").at(i).size()){
5073          electronFlags = cumulativeFlags.at("electrons").at(i);
# Line 4055 | Line 5075 | OSUAnalysis::chosenElectron ()
5075        }
5076      }
5077      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
5078 <      if(!electronFlags.at(electronIndex)) continue;
5078 >      if(!electronFlags.at(electronIndex).first) continue;
5079        chosenElectron = & electrons->at(electronIndex);
5080        break;
5081      }
# Line 4066 | Line 5086 | OSUAnalysis::chosenElectron ()
5086    return chosenElectron;
5087   }
5088  
5089 +
5090   const BNmuon *
5091   OSUAnalysis::chosenMuon ()
5092   {
5093    const BNmuon *chosenMuon = 0;
5094    if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
5095 <    vector<bool> muonFlags;
5095 >    flagPair muonFlags;
5096      for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
5097        if (cumulativeFlags.at("muons").at(i).size()){
5098          muonFlags = cumulativeFlags.at("muons").at(i);
# Line 4079 | Line 5100 | OSUAnalysis::chosenMuon ()
5100        }
5101      }
5102      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
5103 <      if(!muonFlags.at(muonIndex)) continue;
5103 >      if(!muonFlags.at(muonIndex).first) continue;
5104        chosenMuon = & muons->at(muonIndex);
5105        break;
5106      }
# Line 4090 | Line 5111 | OSUAnalysis::chosenMuon ()
5111    return chosenMuon;
5112   }
5113  
5114 + double
5115 + OSUAnalysis::chosenHT ()
5116 + {
5117 +  double chosenHT = 0.0;
5118 +  if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
5119 +    flagPair jetFlags;
5120 +    for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
5121 +      if (cumulativeFlags.at("jets").at(i).size()){
5122 +        jetFlags = cumulativeFlags.at("jets").at(i);
5123 +        break;
5124 +      }
5125 +    }
5126 +    for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
5127 +      if(!jetFlags.at(jetIndex).first) continue;
5128 +      chosenHT += jets->at(jetIndex).pt;
5129 +    }
5130 +  }
5131 +
5132 +  return chosenHT;
5133 + }
5134 +
5135 + pair<const BNmuon *, const BNmuon *>
5136 + OSUAnalysis::leadMuonPair ()
5137 + {
5138 +  pair<const BNmuon *, const BNmuon *> leadMuonPair;
5139 +  leadMuonPair.first = leadMuonPair.second = 0;
5140 +
5141 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
5142 +    flagPair muonFlags;
5143 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
5144 +      if (cumulativeFlags.at("muons").at(i).size()){
5145 +        muonFlags = cumulativeFlags.at("muons").at(i);
5146 +        break;
5147 +      }
5148 +    }
5149 +    for (uint muonIndex0 = 0; muonIndex0 != muonFlags.size(); muonIndex0++){
5150 +      if(!muonFlags.at(muonIndex0).first) continue;
5151 +      for (uint muonIndex1 = muonIndex0 + 1; muonIndex1 < muonFlags.size(); muonIndex1++){
5152 +        if(!muonFlags.at(muonIndex1).first) continue;
5153 +        const BNmuon *mu0 = & muons->at(muonIndex0);
5154 +        const BNmuon *mu1 = & muons->at(muonIndex1);
5155 +        if(leadMuonPair.first == 0 || leadMuonPair.second == 0){
5156 +          leadMuonPair.first = mu0;
5157 +          leadMuonPair.second = mu1;
5158 +        }
5159 +        else{
5160 +          TVector2 newPt0 (mu0->px, mu0->py),
5161 +                   newPt1 (mu1->px, mu1->py),
5162 +                   oldPt0 (leadMuonPair.first->px, leadMuonPair.first->py),
5163 +                   oldPt1 (leadMuonPair.second->px, leadMuonPair.second->py);
5164 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
5165 +            {
5166 +              leadMuonPair.first = mu0;
5167 +              leadMuonPair.second = mu1;
5168 +            }
5169 +        }
5170 +      }
5171 +    }
5172 +  }
5173 +
5174 +  return leadMuonPair;
5175 + }
5176 +
5177 + pair<const BNelectron *, const BNelectron *>
5178 + OSUAnalysis::leadElectronPair ()
5179 + {
5180 +  pair<const BNelectron *, const BNelectron *> leadElectronPair;
5181 +  leadElectronPair.first = leadElectronPair.second = 0;
5182 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
5183 +    flagPair electronFlags;
5184 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
5185 +      if (cumulativeFlags.at("electrons").at(i).size()){
5186 +        electronFlags = cumulativeFlags.at("electrons").at(i);
5187 +        break;
5188 +      }
5189 +    }
5190 +    for (uint electronIndex0 = 0; electronIndex0 != electronFlags.size(); electronIndex0++){
5191 +      if(!electronFlags.at(electronIndex0).first) continue;
5192 +      for (uint electronIndex1 = electronIndex0 + 1; electronIndex1 < electronFlags.size(); electronIndex1++){
5193 +        if(!electronFlags.at(electronIndex1).first) continue;
5194 +        const BNelectron *el0 = & electrons->at(electronIndex0);
5195 +        const BNelectron *el1 = & electrons->at(electronIndex1);
5196 +        if(leadElectronPair.first == 0 || leadElectronPair.second == 0){
5197 +          leadElectronPair.first = el0;
5198 +          leadElectronPair.second = el1;
5199 +        }
5200 +        else{
5201 +          TVector2 newPt0 (el0->px, el0->py),
5202 +                   newPt1 (el1->px, el1->py),
5203 +                   oldPt0 (leadElectronPair.first->px, leadElectronPair.first->py),
5204 +                   oldPt1 (leadElectronPair.second->px, leadElectronPair.second->py);
5205 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
5206 +            {
5207 +              leadElectronPair.first = el0;
5208 +              leadElectronPair.second = el1;
5209 +            }
5210 +        }
5211 +      }
5212 +    }
5213 +  }
5214 +
5215 +  return leadElectronPair;
5216 + }
5217 +
5218   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines