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.108 by wulsin, Wed Jul 24 16:24:44 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")),
# Line 28 | Line 27 | OSUAnalysis::OSUAnalysis (const edm::Par
27    datasetType_ (cfg.getParameter<string> ("datasetType")),
28    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
29    histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
30 +  useEDMFormat_   (cfg.getParameter<bool>("useEDMFormat")),
31 +  treeBranchSets_   (cfg.getParameter<vector<edm::ParameterSet> >("treeBranchSets")),
32    plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
33    doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
34    applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
35 <  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
35 >  applyBtagSF_ (cfg.getParameter<bool> ("applyBtagSF")),
36 >  minBtag_ (cfg.getParameter<int> ("minBtag")),
37 >  printEventInfo_      (cfg.getParameter<bool> ("printEventInfo")),
38 >  printAllTriggers_    (cfg.getParameter<bool> ("printAllTriggers")),
39    useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
40    stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
41 <  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
42 < {
41 >  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut")),
42 >  verbose_ (cfg.getParameter<int> ("verbose"))
43 > {
44  
45 <  TH1::SetDefaultSumw2 ();
45 >  if (verbose_) printEventInfo_ = true;  
46 >  if (verbose_) clog << "Beginning OSUAnalysis::OSUAnalysis constructor." << endl;  
47 >
48 >  TH1::SetDefaultSumw2();
49  
50    //create pile-up reweighting object, if necessary
51    if(datasetType_ != "data") {
# Line 46 | Line 54 | OSUAnalysis::OSUAnalysis (const edm::Par
54        muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
55        electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
56      }
57 +    if (applyBtagSF_){
58 +      bTagSFWeight_ = new BtagSFWeight;
59 +    }
60    }
61    if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
62 <    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
62 >    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at(0), stopCTau_.at(1), stops_);
63  
64  
65    // Construct Cutflow Objects. These store the results of cut decisions and
# Line 57 | Line 68 | OSUAnalysis::OSUAnalysis (const edm::Par
68  
69    //always get vertex collection so we can assign the primary vertex in the event
70    objectsToGet.push_back("primaryvertexs");
60
61  //always make the plot of number of primary vertices (to check pile-up reweighting)
71    objectsToPlot.push_back("primaryvertexs");
72 +  objectsToFlag.push_back("primaryvertexs");
73 +
74  
75    //always get the MC particles to do GEN-matching
76    objectsToGet.push_back("mcparticles");
# Line 67 | Line 78 | OSUAnalysis::OSUAnalysis (const edm::Par
78    //always get the event collection to do pile-up reweighting
79    objectsToGet.push_back("events");
80  
81 +
82 +  // Parse the tree variable definitions.
83 +  for (uint iBranchSet = 0; !useEDMFormat_ && iBranchSet<treeBranchSets_.size(); iBranchSet++) {
84 +    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
85 +    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; }
86 +    objectsToGet.push_back(tempInputCollection);
87 +    objectsToFlag.push_back(tempInputCollection);
88 +
89 +    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
90 +
91 +    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
92 +      BranchSpecs br;
93 +      br.inputCollection = tempInputCollection;
94 +      br.inputVariable = branchList.at(iBranch);
95 +      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);
96 +      br.name = string(newName.Data());
97 +      treeBranches_.push_back(br);
98 +      if (verbose_>3) clog << "   Adding branch to BNTree: " << br.name << endl;  
99 +    }
100 +
101 +  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++)
102 +
103 +
104    //parse the histogram definitions
105    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
106  
107      string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
108      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
109 +    if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
110 +    if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
111      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
112 +    if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
113      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
114 +    if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
115 +    if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
116 +    if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
117      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
118      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
119 +    if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
120 +    if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
121 +    if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
122 +    if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
123 +    if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
124      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
125      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
126      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
# Line 89 | Line 134 | OSUAnalysis::OSUAnalysis (const edm::Par
134          objectsToGet.push_back(tempInputCollection);
135        }
136        objectsToPlot.push_back(tempInputCollection);
137 <      objectsToCut.push_back(tempInputCollection);
138 <    }
94 <    else{//pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
137 >      objectsToFlag.push_back(tempInputCollection);
138 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
139        string obj1;
140        string obj2;
141        getTwoObjs(tempInputCollection, obj1, obj2);
142        string obj2ToGet = getObjToGet(obj2);
143 <      objectsToCut.push_back(tempInputCollection);
144 <      objectsToCut.push_back(obj1);
145 <      objectsToCut.push_back(obj2);
143 >      objectsToFlag.push_back(tempInputCollection);
144 >      objectsToFlag.push_back(obj1);
145 >      objectsToFlag.push_back(obj2);
146        objectsToPlot.push_back(tempInputCollection);
147        objectsToPlot.push_back(obj1);
148        objectsToPlot.push_back(obj2);
149        objectsToGet.push_back(tempInputCollection);
150        objectsToGet.push_back(obj1);
151        objectsToGet.push_back(obj2ToGet);
152 <
153 <    }
154 <
152 >    } // end else
153 >    if (find(objectsToPlot.begin(), objectsToPlot.end(), "events") != objectsToPlot.end())
154 >      objectsToGet.push_back("jets");
155 >    
156 >    
157      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
158  
159      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
# Line 127 | Line 173 | OSUAnalysis::OSUAnalysis (const edm::Par
173        histograms.push_back(tempHistogram);
174  
175      }
176 <  }
176 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
177 >
178    //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
179    sort( objectsToPlot.begin(), objectsToPlot.end() );
180    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
# Line 138 | Line 185 | OSUAnalysis::OSUAnalysis (const edm::Par
185    for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
186  
187      string currentObject = objectsToPlot.at(currentObjectIndex);
188 <    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
188 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "secondary photons"&& currentObject != "superclusters") continue;
189  
190      histogram tempIdHisto;
191      histogram tempMomIdHisto;
# Line 153 | Line 200 | OSUAnalysis::OSUAnalysis (const edm::Par
200      tempIdVsGmaIdHisto.inputCollection = currentObject;
201  
202      if(currentObject == "secondary muons") currentObject = "secondaryMuons";
203 +    if(currentObject == "secondary photons") currentObject = "secondaryPhotons";
204      if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
205  
206      currentObject = currentObject.substr(0, currentObject.size()-1);
# Line 208 | Line 256 | OSUAnalysis::OSUAnalysis (const edm::Par
256      string channelName  (channels_.at(currentChannel).getParameter<string>("name"));
257      tempChannel.name = channelName;
258      TString channelLabel = channelName;
259 +    if (verbose_) clog << "Processing channel:  " << channelName << endl;  
260  
261      //set triggers for this channel
262      vector<string> triggerNames;
263      triggerNames.clear();
264 +    vector<string> triggerToVetoNames;
265 +    triggerToVetoNames.clear();
266 +
267      tempChannel.triggers.clear();
268 +    tempChannel.triggersToVeto.clear();
269      if(channels_.at(currentChannel).exists("triggers")){
270        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
271        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
272          tempChannel.triggers.push_back(triggerNames.at(trigger));
273        objectsToGet.push_back("triggers");
274      }
275 <
275 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
276 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
277 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
278 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
279 >      objectsToGet.push_back("triggers");
280 >    }
281  
282  
283  
284      //create cutFlow for this channel
285      cutFlows_.push_back (new CutFlow (fs_, channelName));
286      vector<TFileDirectory> directories; //vector of directories in the output file.
287 +    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
288      vector<string> subSubDirNames;//subdirectories in each channel.
289      //get list of cuts for this channel
290      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
# Line 237 | Line 296 | OSUAnalysis::OSUAnalysis (const edm::Par
296        //store input collection for cut
297        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
298        if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
299 +      if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
300 +      if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
301        if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
302        if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
303 +      if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
304 +      if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
305 +      if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
306 +      if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
307        if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
308        if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
309 +      if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
310 +      if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
311 +      if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
312 +      if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
313 +      if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
314        if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
315        if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
316        if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
# Line 255 | Line 325 | OSUAnalysis::OSUAnalysis (const edm::Par
325            objectsToGet.push_back(tempInputCollection);
326          }
327          objectsToCut.push_back(tempInputCollection);
328 +        objectsToFlag.push_back(tempInputCollection);
329        }
330        else{//pair of objects, need to add them both to objectsToGet
331          string obj1;
# Line 264 | Line 335 | OSUAnalysis::OSUAnalysis (const edm::Par
335          objectsToCut.push_back(tempInputCollection);
336          objectsToCut.push_back(obj1);
337          objectsToCut.push_back(obj2);
338 +        objectsToFlag.push_back(tempInputCollection);
339 +        objectsToFlag.push_back(obj1);
340 +        objectsToFlag.push_back(obj2);
341          objectsToGet.push_back(tempInputCollection);
342          objectsToGet.push_back(obj1);
343          objectsToGet.push_back(obj2ToGet);
# Line 276 | Line 350 | OSUAnalysis::OSUAnalysis (const edm::Par
350        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
351        vector<string> cutStringVector = splitString(cutString);
352        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
353 <        cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
353 >        clog << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
354          exit(0);
355        }
356        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
# Line 302 | Line 376 | OSUAnalysis::OSUAnalysis (const edm::Par
376        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
377        vector<string> numberRequiredVector = splitString(numberRequiredString);
378        if(numberRequiredVector.size()!=2){
379 <        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
379 >        clog << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
380          exit(0);
381        }
382  
# Line 310 | Line 384 | OSUAnalysis::OSUAnalysis (const edm::Par
384        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
385        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
386  
387 <      //Set up vectors to store the directories and subDIrectories for each channel.
387 >      //Set up vectors to store the directories and subDirectories for each channel.
388        string subSubDirName;
389        string tempCutName;
390        if(cuts_.at(currentCut).exists("alias")){
391          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
392 <        subSubDirName = "After " + cuts_.at(currentCut).getParameter<string> ("alias") + " Cut Applied";
392 >        subSubDirName = "After " + tempCutName + " Cut Applied";
393        }
394        else{
395          //construct string for cutflow table
# Line 326 | Line 400 | OSUAnalysis::OSUAnalysis (const edm::Par
400          subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
401        }
402  
403 +      tempCut.isVeto = false;
404 +      if(cuts_.at(currentCut).exists("isVeto")){
405 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
406 +        if (isVeto == true) tempCut.isVeto = true;
407 +      }
408        subSubDirNames.push_back(subSubDirName);
409        tempCut.name = tempCutName;
410 +      if (verbose_) clog << "Setting up cut, index: " << currentCut << ", input collection: " << tempInputCollection<< ", name: " << tempCut.name << endl;  
411  
412        tempChannel.cuts.push_back(tempCut);
413  
# Line 340 | Line 420 | OSUAnalysis::OSUAnalysis (const edm::Par
420      TFileDirectory subDir = fs_->mkdir( channelName );
421      //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
422      if(GetPlotsAfterEachCut_){
423 <       for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
424 <            TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
425 <            directories.push_back(subSubDir);
426 <            map<string, TH1D*> oneDhistoMap;
427 <            oneDHistsTmp.push_back(oneDhistoMap);
428 <            map<string, TH2D*> twoDhistoMap;
429 <            twoDHistsTmp.push_back(twoDhistoMap);
423 >      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
424 >        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
425 >        directories.push_back(subSubDir);
426 >        map<string, TH1D*> oneDhistoMap;
427 >        oneDHistsTmp.push_back(oneDhistoMap);
428 >        map<string, TH2D*> twoDhistoMap;
429 >        twoDHistsTmp.push_back(twoDhistoMap);
430        }
431 +      treeDirectories.push_back(subDir);
432        oneDHists_.push_back(oneDHistsTmp);
433        twoDHists_.push_back(twoDHistsTmp);
434      }
435 <   //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
436 <   else{
435 >    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
436 >    else{
437        map<string, TH1D*> oneDhistoMap;
438        oneDHistsTmp.push_back(oneDhistoMap);
439        map<string, TH2D*> twoDhistoMap;
# Line 360 | Line 441 | OSUAnalysis::OSUAnalysis (const edm::Par
441        oneDHists_.push_back(oneDHistsTmp);
442        twoDHists_.push_back(twoDHistsTmp);
443        directories.push_back(subDir);
444 <   }
444 >      treeDirectories.push_back(subDir);
445 >
446 >    }
447 >
448 >    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
449 >      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
450 >      BNTrees_.push_back(newTree);
451 >      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
452 >        BranchSpecs currentVar = treeBranches_.at(iBranch);
453 >        vector<float> newVec;
454 >        BNTreeBranchVals_[currentVar.name] = newVec;
455 >        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
456 >      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
457 >    }
458 >
459      //book all histograms included in the configuration
460      for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
461 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
462 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
463 <      int numBinsElements = currentHistogram.bins.size();
464 <      int numInputVariables = currentHistogram.inputVariables.size();
465 <      int numBinEdgesX = currentHistogram.variableBinsX.size();
466 <      int numBinEdgesY = currentHistogram.variableBinsY.size();
467 <
468 <      if(numBinsElements == 1){
469 <        if(numBinEdgesX > 1){
470 <          if(numBinEdgesY > 1)
471 <            numBinsElements = 6;
461 >
462 >      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
463 >
464 >        histogram currentHistogram = histograms.at(currentHistogramIndex);
465 >        int numBinsElements = currentHistogram.bins.size();
466 >        int numInputVariables = currentHistogram.inputVariables.size();
467 >        int numBinEdgesX = currentHistogram.variableBinsX.size();
468 >        int numBinEdgesY = currentHistogram.variableBinsY.size();
469 >
470 >        if(numBinsElements == 1){
471 >          if(numBinEdgesX > 1){
472 >            if(numBinEdgesY > 1)
473 >              numBinsElements = 6;
474 >            else
475 >              numBinsElements = 3;
476 >          }
477 >        }
478 >        if(numBinsElements != 3 && numBinsElements !=6){
479 >          clog << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
480 >          exit(0);
481 >        }
482 >        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
483 >          clog << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
484 >          exit(0);
485 >        }
486 >        else if(numBinsElements == 3){
487 >          if (currentHistogram.bins.size () == 3)
488 >            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));
489            else
490 <            numBinsElements = 3;
490 >            {
491 >              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
492 >            }
493          }
494 <      }
495 <      if(numBinsElements != 3 && numBinsElements !=6){
496 <        cout << "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 <        cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
501 <        exit(0);
502 <      }
503 <      else if(numBinsElements == 3){
504 <        if (currentHistogram.bins.size () == 3)
505 <          oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
506 <        else
507 <          {
508 <            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
494 >        else if(numBinsElements == 6){
495 >          if (currentHistogram.bins.size () == 6)
496 >            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));
497 >          else
498 >            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 ());
499 >        }
500 >
501 >
502 >        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
503 >
504 >        // bin      particle type
505 >        // ---      -------------
506 >        //  0        unmatched
507 >        //  1        u
508 >        //  2        d
509 >        //  3        s
510 >        //  4        c
511 >        //  5        b
512 >        //  6        t
513 >        //  7        e
514 >        //  8        mu
515 >        //  9        tau
516 >        // 10        nu
517 >        // 11        g
518 >        // 12        gamma
519 >        // 13        Z
520 >        // 14        W
521 >        // 15        light meson
522 >        // 16        K meson
523 >        // 17        D meson
524 >        // 18        B meson
525 >        // 19        light baryon
526 >        // 20        strange baryon
527 >        // 21        charm baryon
528 >        // 22        bottom baryon
529 >        // 23        QCD string
530 >        // 24        other
531 >
532 >        vector<TString> labelArray;
533 >        labelArray.push_back("unmatched");
534 >        labelArray.push_back("u");
535 >        labelArray.push_back("d");
536 >        labelArray.push_back("s");
537 >        labelArray.push_back("c");
538 >        labelArray.push_back("b");
539 >        labelArray.push_back("t");
540 >        labelArray.push_back("e");
541 >        labelArray.push_back("#mu");
542 >        labelArray.push_back("#tau");
543 >        labelArray.push_back("#nu");
544 >        labelArray.push_back("g");
545 >        labelArray.push_back("#gamma");
546 >        labelArray.push_back("Z");
547 >        labelArray.push_back("W");
548 >        labelArray.push_back("light meson");
549 >        labelArray.push_back("K meson");
550 >        labelArray.push_back("D meson");
551 >        labelArray.push_back("B meson");
552 >        labelArray.push_back("light baryon");
553 >        labelArray.push_back("strange baryon");
554 >        labelArray.push_back("charm baryon");
555 >        labelArray.push_back("bottom baryon");
556 >        labelArray.push_back("QCD string");
557 >        labelArray.push_back("other");
558 >
559 >        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
560 >          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
561 >            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
562            }
563 <      }
564 <      else if(numBinsElements == 6){
565 <        if (currentHistogram.bins.size () == 6)
566 <          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));
567 <        else
568 <          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 ());
569 <      }
563 >          else {
564 >            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
565 >            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
566 >          }
567 >        }
568 >        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
569 >          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
570 >          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
571 >        }
572  
573 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
574  
405      if(currentHistogram.name.find("GenMatch")==string::npos) continue;
575  
576 <      // bin      particle type
577 <      // ---      -------------
578 <      //  0        unmatched
579 <      //  1        u
580 <      //  2        d
581 <      //  3        s
582 <      //  4        c
583 <      //  5        b
584 <      //  6        t
585 <      //  7        e
586 <      //  8        mu
587 <      //  9        tau
588 <      // 10        nu
589 <      // 11        g
590 <      // 12        gamma
591 <      // 13        Z
592 <      // 14        W
593 <      // 15        light meson
594 <      // 16        K meson
595 <      // 17        D meson
596 <      // 18        B meson
597 <      // 19        light baryon
598 <      // 20        strange baryon
599 <      // 21        charm baryon
600 <      // 22        bottom baryon
601 <      // 23        QCD string
602 <      // 24        other
603 <
604 <      vector<TString> labelArray;
605 <      labelArray.push_back("unmatched");
606 <      labelArray.push_back("u");
607 <      labelArray.push_back("d");
608 <      labelArray.push_back("s");
609 <      labelArray.push_back("c");
610 <      labelArray.push_back("b");
611 <      labelArray.push_back("t");
612 <      labelArray.push_back("e");
613 <      labelArray.push_back("#mu");
614 <      labelArray.push_back("#tau");
615 <      labelArray.push_back("#nu");
616 <      labelArray.push_back("g");
617 <      labelArray.push_back("#gamma");
618 <      labelArray.push_back("Z");
619 <      labelArray.push_back("W");
620 <      labelArray.push_back("light meson");
621 <      labelArray.push_back("K meson");
622 <      labelArray.push_back("D meson");
623 <      labelArray.push_back("B meson");
624 <      labelArray.push_back("light baryon");
625 <      labelArray.push_back("strange baryon");
626 <      labelArray.push_back("charm baryon");
458 <      labelArray.push_back("bottom baryon");
459 <      labelArray.push_back("QCD string");
460 <      labelArray.push_back("other");
461 <
462 <      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
463 <        if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
464 <          oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
465 <        }
466 <        else {
467 <          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
468 <          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
469 <        }
470 <      }
471 <      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
472 <        twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
473 <        twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
474 <      }
475 <
476 <    }
477 <
478 <    // Book a histogram for the number of each object type to be plotted.
479 <    // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
480 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
481 <      string currentObject = objectsToPlot.at(currentObjectIndex);
482 <      int maxNum = 10;
483 <      if(currentObject == "mcparticles") maxNum = 50;
484 <      else if(currentObject == "primaryvertexs") maxNum = 50;
485 <
486 <      if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
487 <      else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
488 <      else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
489 <      else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
490 <      else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
491 <      else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
492 <      else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
493 <      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);
576 >      // Book a histogram for the number of each object type to be plotted.
577 >      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
578 >      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
579 >        string currentObject = objectsToPlot.at(currentObjectIndex);
580 >        int maxNum = 10;
581 >        if(currentObject == "mcparticles") maxNum = 50;
582 >        else if(currentObject == "primaryvertexs") maxNum = 50;
583 >
584 >        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
585 >        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
586 >        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
587 >        else if(currentObject == "electron-photon pairs")     currentObject = "electronPhotonPairs";
588 >        else if(currentObject == "muon-photon pairs")         currentObject = "muonPhotonPairs";
589 >        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
590 >        else if(currentObject == "secondary photons")            currentObject = "secondaryPhotons";
591 >        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
592 >        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
593 >        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
594 >        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
595 >        else if(currentObject == "muon-event pairs")            currentObject = "muonEventPairs";
596 >        else if(currentObject == "photon-jet pairs")            currentObject = "photonJetPairs";
597 >        else if(currentObject == "met-jet pairs")             currentObject = "metJetPairs";
598 >        else if(currentObject == "track-jet pairs")           currentObject = "trackJetPairs";
599 >        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
600 >        else if(currentObject == "muon-secondary photon pairs")  currentObject = "muonSecondaryPhotonPairs";
601 >        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
602 >        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
603 >        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
604 >        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
605 >        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
606 >        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
607 >        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
608 >        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
609 >        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
610 >        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
611 >        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
612 >        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
613 >        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
614 >        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
615 >
616 >        currentObject.at(0) = toupper(currentObject.at(0));
617 >        string histoName = "num" + currentObject;
618 >
619 >        if(histoName == "numPrimaryvertexs"){
620 >          string newHistoName = histoName + "BeforePileupCorrection";
621 >          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);
622 >          newHistoName = histoName + "AfterPileupCorrection";
623 >          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);
624 >        }
625 >        else
626 >          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
627        }
628 <      else
629 <        oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
630 <    }
631 <   }//end of loop over directories
628 >
629 >      if (verbose_) {
630 >        clog << "List of 1D histograms booked for channel " << channelName << " and directory " << currentDir << ":" << endl;
631 >        for(map<string, TH1D*>::iterator
632 >              iter = oneDHists_.at(currentChannel).at(currentDir).begin();
633 >            iter  != oneDHists_.at(currentChannel).at(currentDir).end();
634 >            iter++) {
635 >          clog << " " << iter->first
636 >               << ":  name=" << iter->second->GetName()
637 >               << ", title=" << iter->second->GetTitle()
638 >               << ", bins=(" << iter->second->GetNbinsX()
639 >               << "," << iter->second->GetXaxis()->GetXmin()
640 >               << "," << iter->second->GetXaxis()->GetXmax()
641 >               << ")" << endl;
642 >        }  
643 >        clog << "List of 2D histograms booked for channel " << channelName << " and directory " << currentDir << ":" << endl;
644 >        for(map<string, TH2D*>::iterator
645 >              iter = twoDHists_.at(currentChannel).at(currentDir).begin();
646 >            iter  != twoDHists_.at(currentChannel).at(currentDir).end();
647 >            iter++) {
648 >          clog << " " << iter->first
649 >               << ":  name=" << iter->second->GetName()
650 >               << ", title=" << iter->second->GetTitle()
651 >               << ", binsX=(" << iter->second->GetNbinsX()
652 >               << "," << iter->second->GetXaxis()->GetXmin()
653 >               << "," << iter->second->GetXaxis()->GetXmax()
654 >               << ")"
655 >               << ", binsY=(" << iter->second->GetNbinsY()
656 >               << "," << iter->second->GetYaxis()->GetXmin()
657 >               << "," << iter->second->GetYaxis()->GetXmax()
658 >               << ")"
659 >               << endl;
660 >        }  
661 >      }
662 >
663 >    }//end of loop over directories
664      channels.push_back(tempChannel);
665      tempChannel.cuts.clear();
666    }//end loop over channels
667  
668  
669 +
670    //make unique vector of objects we need to get from the event
671    sort( objectsToGet.begin(), objectsToGet.end() );
672    objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
673    //make unique vector of objects we need to cut on
674    sort( objectsToCut.begin(), objectsToCut.end() );
675    objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
676 +  //make unique vector of objects we need to set flags for
677 +  sort( objectsToFlag.begin(), objectsToFlag.end() );
678 +  objectsToFlag.erase( unique( objectsToFlag.begin(), objectsToFlag.end() ), objectsToFlag.end() );
679  
680 +  // 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.  
681 +  for (uint i=0; i<objectsToFlag.size(); i++) {
682 +    if (objectsToFlag.at(i).find("pairs")!=string::npos) { // if it contains "pairs"
683 +      objectsToFlag.push_back(objectsToFlag.at(i));  
684 +      objectsToFlag.erase(objectsToFlag.begin()+i);  
685 +    }
686 +  }
687 +
688 +  if (verbose_) {
689 +    clog << "List of channels:" << endl;
690 +    for (uint i=0; i<channels.size(); i++) {
691 +      clog << " " << channels.at(i).name << endl;
692 +    }
693 +    clog << "List of objects to get:" << endl;
694 +    for (uint i=0; i<objectsToGet.size(); i++) {
695 +      clog << " " << objectsToGet.at(i) << endl;
696 +    }
697 +    clog << "List of objects to plot:" << endl;
698 +    for (uint i=0; i<objectsToPlot.size(); i++) {
699 +      clog << " " << objectsToPlot.at(i) << endl;
700 +    }
701 +    clog << "List of objects to cut:" << endl;
702 +    for (uint i=0; i<objectsToCut.size(); i++) {
703 +      clog << " " << objectsToCut.at(i) << endl;
704 +    }
705 +    clog << "List of objects to flag:" << endl;
706 +    for (uint i=0; i<objectsToFlag.size(); i++) {
707 +      clog << " " << objectsToFlag.at(i) << endl;
708 +    }
709 +  }
710 +
711 +  produces<map<string, bool> > ("channelDecisions");
712 +
713 +  if (printEventInfo_) {
714 +    findEventsLog = new ofstream();  
715 +    findEventsLog->open("findEvents.txt");  
716 +    clog << "Listing run:lumi:event in file findEvents.txt for events that pass full selection (of any channel)." << endl;  
717 +  } else {
718 +    findEventsLog = 0;
719 +  }  
720 +
721 +  isFirstEvent_ = true;  
722 +
723 +  if (verbose_) clog << "Finished OSUAnalysis::OSUAnalysis constructor." << endl;  
724 +
725 +
726 +  } // end constructor OSUAnalysis::OSUAnalysis()
727  
532 }
728  
729   OSUAnalysis::~OSUAnalysis ()
730   {
731 +
732 +  if (verbose_) clog << "Beginning OSUAnalysis::OSUAnalysis destructor." << endl;  
733 +
734    // Destroying the CutFlow objects causes the cut flow numbers and time
735    // information to be printed to standard output.
736    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
737      delete cutFlows_.at(currentChannel);
738    }
739 +
740 +  if (printEventInfo_ && findEventsLog) findEventsLog->close();  
741 +
742 +  clog << "=============================================" << endl;  
743 +  clog << "Successfully completed OSUAnalysis." << endl;  
744 +  clog << "=============================================" << endl;  
745 +
746 +  if (verbose_) clog << "Finished OSUAnalysis::OSUAnalysis destructor." << endl;  
747 +
748   }
749  
750   void
751 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
751 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
752   {
546
753    // Retrieve necessary collections from the event.
754  
755 +  if (verbose_) clog << "Beginning OSUAnalysis::produce." << endl;  
756 +
757    if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
758      event.getByLabel (triggers_, triggers);
759  
# Line 608 | Line 816 | OSUAnalysis::analyze (const edm::Event &
816  
817    //get pile-up event weight
818    if (doPileupReweighting_ && datasetType_ != "data") {
819 <    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  This will give an incorrect pile-up weight." << endl;  
820 < else
821 <    masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);  
819 >    //for "data" datasets, the numTruePV is always set to -1
820 >    if (events->at(0).numTruePV < 0 && isFirstEvent_) clog << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
821 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
822    }
823  
824    stopCTauScaleFactor_ = 1.0;
# Line 620 | Line 828 | else
828  
829    //loop over all channels
830  
831 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
832    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
833      channel currentChannel = channels.at(currentChannelIndex);
834 +    if (verbose_>1) clog << " Processing channel " << currentChannel.name << endl;
835  
836      flagMap individualFlags;
837      counterMap passingCounter;
838      cumulativeFlags.clear ();
839  
840 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
841 +         iter != BNTreeBranchVals_.end(); iter++) {
842 +      iter->second.clear();  // clear array
843 +    }
844 +
845      bool triggerDecision = true;
846 <    if(currentChannel.triggers.size() != 0){  //triggers specified
847 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
846 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
847 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
848        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
849      }
850  
851      //loop over all cuts
852      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
853        cut currentCut = currentChannel.cuts.at(currentCutIndex);
854 <      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
855 <        string currentObject = objectsToCut.at(currentObjectIndex);
854 >      if (verbose_>2) clog << "  Processing cut, index: " << currentCutIndex << ", input collection: " << currentCut.inputCollection << ", name: " << currentCut.name << endl;  
855 >
856 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
857 >        string currentObject = objectsToFlag.at(currentObjectIndex);
858  
859          //initialize maps to get ready to set cuts
860 <        individualFlags[currentObject].push_back (vector<bool> ());
861 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
860 >        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
861 >        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
862  
863        }
647      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
648        string currentObject = objectsToCut.at(currentObjectIndex);
864  
865 <        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
866 <
867 <
868 <        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
869 <        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
870 <        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
871 <        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
865 >      //set flags for all relevant objects
866 >      for(int currentObjectIndex = -1; currentObjectIndex != int(objectsToFlag.size()); currentObjectIndex++){
867 >        string currentObject;  
868 >        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.  
869 >        else currentObject = objectsToFlag.at(currentObjectIndex);
870 >        if (currentObjectIndex >= 0 && currentObject == currentCut.inputCollection) continue;  // Flags have already been set for the inputCollection object, so should not be set again.  
871 >
872 >        // single object collections
873 >        if     (currentObject == "jets")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
874 >        else if(currentObject == "secondary jets")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
875 >        else if(currentObject == "secondary photons")   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"secondary photons");
876 >        else if(currentObject == "muons")               setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
877 >        else if(currentObject == "secondary muons")     setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
878          else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
879 <        else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
880 <        else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
881 <        else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
882 <        else if(currentObject == "mets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
883 <        else if(currentObject == "tracks") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
884 <        else if(currentObject == "genjets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
885 <        else if(currentObject == "mcparticles") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
886 <        else if(currentObject == "primaryvertexs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
887 <        else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
888 <        else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
889 <        else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
890 <        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
891 <
892 <
893 <
894 <        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
895 <                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
896 <                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
897 <                                                                   "muon-muon pairs");
898 <
899 <        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
900 <                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
901 <                                                                   cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
902 <                                                                   "muon-secondary muon pairs");
903 <
904 <        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
905 <                                                                   cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
906 <                                                                   cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
907 <                                                                   "electron-secondary electron pairs");
908 <
909 <        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
910 <                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
911 <                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
912 <                                                                           "electron-electron pairs");
913 <        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
914 <                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
915 <                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
916 <                                                                       "electron-muon pairs");
917 <        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
918 <                                                                           cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
919 <                                                                           cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
920 <                                                                           "jet-jet pairs");
921 <        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
922 <                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
702 <                                                                       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");
879 >        else if(currentObject == "electrons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
880 >        else if(currentObject == "events")              setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
881 >        else if(currentObject == "taus")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
882 >        else if(currentObject == "mets")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
883 >        else if(currentObject == "tracks")              setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
884 >        else if(currentObject == "genjets")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
885 >        else if(currentObject == "mcparticles")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
886 >        else if(currentObject == "primaryvertexs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
887 >        else if(currentObject == "bxlumis")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
888 >        else if(currentObject == "photons")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
889 >        else if(currentObject == "superclusters")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
890 >        else if(currentObject == "trigobjs")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
891 >
892 >
893 >        // paired object collections  
894 >        else if(currentObject == "muon-muon pairs")                   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), "muon-muon pairs");
895 >        else if(currentObject == "muon-secondary muon pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), "muon-secondary muon pairs");
896 >
897 >        else if(currentObject == "muon-secondary photon pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), "muon-secondary photon pairs");
898 >        else if(currentObject == "muon-secondary jet pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), "muon-secondary jet pairs");
899 >        else if(currentObject == "photon-secondary jet pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), "photon-secondary jet pairs");
900 >        else if(currentObject == "electron-secondary jet pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), "electron-secondary jet pairs");
901 >        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), "electron-secondary electron pairs");
902 >
903 >        else if(currentObject == "electron-electron pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), "electron-electron pairs");
904 >        else if(currentObject == "electron-muon pairs")     setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), "electron-muon pairs");
905 >        else if(currentObject == "jet-jet pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), "jet-jet pairs");
906 >        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), "jet-secondary jet pairs");
907 >        else if(currentObject == "electron-jet pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), "electron-jet pairs");
908 >        else if(currentObject == "electron-photon pairs")   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), "electron-photon pairs");
909 >        else if(currentObject == "photon-jet pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), "photon-jet pairs");
910 >        else if(currentObject == "muon-jet pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), "muon-jet pairs");
911 >        else if(currentObject == "muon-event pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),events.product(), "muon-event pairs");
912 >        else if(currentObject == "met-jet pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),jets.product(), "met-jet pairs");
913 >        else if(currentObject == "track-jet pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),jets.product(), "track-jet pairs");
914 >        else if(currentObject == "muon-photon pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), "muon-photon pairs");
915 >        else if(currentObject == "track-event pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(), "track-event pairs");
916 >        else if(currentObject == "electron-track pairs")    setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),"electron-track pairs");
917 >        else if(currentObject == "muon-track pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),"muon-track pairs");
918 >        else if(currentObject == "muon-tau pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),"muon-tau pairs");
919 >        else if(currentObject == "tau-tau pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),"tau-tau pairs");
920 >        else if(currentObject == "tau-track pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),"tau-track pairs");
921 >        else if(currentObject == "electron-trigobj pairs")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),"electron-trigobj pairs");
922 >        else if(currentObject == "muon-trigobj pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),"muon-trigobj pairs");
923  
924          if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
925        }
926  
927 +    }//end loop over all cuts
928  
929  
746    }//end loop over all cuts
747    //use cumulative flags to apply cuts at event level
930  
931 +    //use cumulative flags to apply cuts at event level
932 +    vector<bool> eventPassedPreviousCuts;    //a vector to store cumulative cut descisions after each cut.
933      bool eventPassedAllCuts = true;
934 <    //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 <
934 >    eventPassedAllCuts = eventPassedAllCuts && triggerDecision;    //apply trigger (true if none were specified)
935  
936      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
937  
938        //loop over all objects and count how many passed the cumulative selection up to this point
939        cut currentCut = currentChannel.cuts.at(currentCutIndex);
940        int numberPassing = 0;
941 +      int numberPassingPrev = 0;  // number of objects that pass cuts up to the previous one
942  
943        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
944 <        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
944 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
945        }
946 <      bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
946 >      bool cutDecision;
947 >      if (!currentCut.isVeto) {
948 >        cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
949 >      } else {
950 >        int prevCutIndex = currentCutIndex - 1;
951 >        if (prevCutIndex<0) {
952 >          numberPassingPrev = cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size();  // count all objects in collection if cut is the first
953 >        } else {
954 >          for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(prevCutIndex).size() ; object++){
955 >            if (cumulativeFlags.at(currentCut.inputCollection).at(prevCutIndex).at(object).first) {
956 >              numberPassingPrev++;
957 >              if (verbose_>1) clog << " object passed previous cut" << endl;  
958 >            }
959 >          }  
960 >        }  
961 >        int numberFailCut = numberPassingPrev - numberPassing;
962 >        cutDecision = evaluateComparison(numberFailCut,currentCut.eventComparativeOperator,currentCut.numberRequired);  
963 >      }
964 >
965        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
966        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
967        eventPassedPreviousCuts.push_back(eventPassedAllCuts);
968 +      if (verbose_>1) clog << " Event passed cuts up to cut index " << currentCutIndex << endl;  
969 +
970      }
971 +    //applying all appropriate scale factors
972      double scaleFactor = masterScaleFactor;
973 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
974  
772    muonScaleFactor_ = electronScaleFactor_ = 1.0;
975      if(applyLeptonSF_ && datasetType_ != "data"){
976 <      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
977 <        vector<bool> muonFlags;
976 >      //only apply SFs if we've cut on this object
977 >      if(find(objectsToCut.begin(),objectsToCut.end(),"muons") != objectsToCut.end ()){
978 >        flagPair muonFlags;
979 >        //get the last valid flags in the flag map
980          for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
981            if (cumulativeFlags.at("muons").at(i).size()){
982              muonFlags = cumulativeFlags.at("muons").at(i);
983              break;
984            }
985          }
986 +        //apply the weight for each of those objects
987          for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
988 <          if(!muonFlags.at(muonIndex)) continue;
988 >          if(!muonFlags.at(muonIndex).second) continue;
989            muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
990          }
991        }
992 <      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
993 <        vector<bool> electronFlags;
992 >      //only apply SFs if we've cut on this object
993 >      if(find(objectsToCut.begin(),objectsToCut.end(),"electrons") != objectsToCut.end ()){
994 >        flagPair electronFlags;
995 >        //get the last valid flags in the flag map
996          for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
997            if (cumulativeFlags.at("electrons").at(i).size()){
998              electronFlags = cumulativeFlags.at("electrons").at(i);
999              break;
1000            }
1001          }
1002 +        //apply the weight for each of those objects
1003          for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
1004 <          if(!electronFlags.at(electronIndex)) continue;
1004 >          if(!electronFlags.at(electronIndex).second) continue;
1005            electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
1006          }
1007        }
1008      }
1009 +    if(applyBtagSF_ && datasetType_ != "data"){
1010 +      //only apply SFs if we've cut on this object
1011 +      if(find(objectsToCut.begin(),objectsToCut.end(),"jets") != objectsToCut.end ()){
1012 +        flagPair jetFlags;
1013 +        vector<double> jetSFs;
1014 +        //get the last valid flags in the flag map
1015 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
1016 +          if (cumulativeFlags.at("jets").at(i).size()){
1017 +            jetFlags = cumulativeFlags.at("jets").at(i);
1018 +            break;
1019 +          }
1020 +        }
1021 +        //apply the weight for each of those objects
1022 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
1023 +          if(!jetFlags.at(jetIndex).second) continue;
1024 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour, jets->at(jetIndex).eta);
1025 +          jetSFs.push_back(jetSFTmp);
1026 +        }
1027 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_);
1028 +      }
1029 +    }
1030      scaleFactor *= muonScaleFactor_;
1031      scaleFactor *= electronScaleFactor_;
1032 <
1032 >    scaleFactor *= bTagScaleFactor_;
1033      cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
1034 <    if(!(GetPlotsAfterEachCut_ || eventPassedAllCuts)) continue;
1034 >    if (verbose_>1) clog << " Scale factors applied:  "
1035 >                         << " muonScaleFactor_ = " << muonScaleFactor_
1036 >                         << ", electronScaleFactor_ = " << electronScaleFactor_
1037 >                         << ", bTagScaleFactor_ = " << bTagScaleFactor_
1038 >                         << ", total scale factor = " << scaleFactor
1039 >                         << endl;  
1040  
1041 <    if (printEventInfo_) {
1041 >
1042 >    if (printEventInfo_ && eventPassedAllCuts) {
1043        // Write information about event to screen, for testing purposes.
1044 <      cout << "Event passed all cuts in channel " <<  currentChannel.name
1045 <           << ": run="  << events->at(0).run
1046 <           << "  lumi=" << events->at(0).lumi
1047 <           << "  event=" << events->at(0).evt
1044 >      clog << "Event passed all cuts in channel " <<  currentChannel.name
1045 >           << ":  run:lumi:evt=  "  << events->at(0).run
1046 >           << ":" << events->at(0).lumi
1047 >           << ":" << events->at(0).evt
1048             << endl;
1049 +      if (findEventsLog) {
1050 +        (*findEventsLog) << events->at(0).run
1051 +                         << ":" << events->at(0).lumi
1052 +                         << ":" << events->at(0).evt << endl;
1053 +      }
1054 +
1055      }
1056 +
1057 +
1058      //filling histograms
1059 <    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
1060 <        uint currentDir;
1061 <        if(!GetPlotsAfterEachCut_){ currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size();}//if GetPlotsAfterEachCut_ is true, set currentDir point to the lat cut.
1062 <        else{
1063 <          currentDir = currentCut;
1064 <        }
1065 <        if(eventPassedPreviousCuts.at(currentDir)){
1059 >    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.
1060 >
1061 >      if (verbose_>2) clog << "  Filling histograms for currentcut = " << currentCut << endl;  
1062 >
1063 >      uint currentDir;
1064 >      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
1065 >      else{
1066 >        currentDir = currentCut;
1067 >      }
1068 >
1069 >
1070 >      if(eventPassedPreviousCuts.at(currentDir)){
1071 >
1072          for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1073            histogram currentHistogram = histograms.at(histogramIndex);
1074  
1075 <      if(currentHistogram.inputVariables.size() == 1){
1076 <        TH1D* histo;
1077 <        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 <    }
1075 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) clog << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
1076 >
1077 >          if (verbose_>1) clog << " Filling histogram " << currentHistogram.name << " for collection " << currentHistogram.inputCollection << endl;  
1078  
1079 +          if(currentHistogram.inputVariables.size() == 1){
1080 +            TH1D* histo;
1081 +            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1082 +            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1083 +            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1084 +            else if(currentHistogram.inputCollection == "secondary photons")  fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1085 +            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1086 +            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1087 +            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1088 +            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1089 +                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1090 +            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1091 +                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1092 +             else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1093 +                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1094 +             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1095 +                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1096 +             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1097 +                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1098 +             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1099 +                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1100 +
1101 +            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1102 +            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1103 +                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1104 +            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1105 +                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1106 +             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1107 +                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1108 +
1109 +            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1110 +                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1111 +            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(),
1112 +                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1113 +            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(),
1114 +                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1115 +            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(),
1116 +                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1117 +            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(),
1118 +                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1119 +            else if(currentHistogram.inputCollection == "muon-event pairs") fill1DHistogram(histo,currentHistogram, muons.product(),events.product(),
1120 +                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1121 +            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, mets.product(),jets.product(),
1122 +                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1123 +            else if(currentHistogram.inputCollection == "track-jet pairs")  fill1DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1124 +                                                                                          cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1125 +            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(),
1126 +                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1127 +            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(),
1128 +                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1129 +            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1130 +                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1131 +            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1132 +                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1133 +            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1134 +                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1135 +            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1136 +                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1137 +            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1138 +                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1139 +            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1140 +                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1141 +            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1142 +                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1143 +
1144 +            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1145 +            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1146 +            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1147 +            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1148 +            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1149 +            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1150 +            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1151 +            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1152 +            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1153 +            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1154 +            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1155 +            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1156 +          }
1157 +          else if(currentHistogram.inputVariables.size() == 2){
1158 +            TH2D* histo;
1159 +            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1160 +            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1161 +            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1162 +            else if(currentHistogram.inputCollection == "secondary photons")  fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1163 +            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1164 +            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1165 +            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1166 +                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1167 +            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1168 +                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1169 +            else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1170 +                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1171 +            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1172 +                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1173 +            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1174 +                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1175 +            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1176 +                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1177 +            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1178 +            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1179 +            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1180 +                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1181 +            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1182 +                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1183 +            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1184 +                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1185 +            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(),
1186 +                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1187 +            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1188 +                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1189 +            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(),
1190 +                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1191 +            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1192 +                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1193 +            else if(currentHistogram.inputCollection == "muon-event pairs") fill2DHistogram(histo,currentHistogram,muons.product(),events.product(),
1194 +                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1195 +            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,mets.product(),jets.product(),
1196 +                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1197 +            else if(currentHistogram.inputCollection == "track-jet pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1198 +                                                                                         cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1199 +            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1200 +                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1201 +            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1202 +                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1203 +            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1204 +                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1205 +            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1206 +                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1207 +            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1208 +                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1209 +            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1210 +                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1211 +            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1212 +                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1213 +            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1214 +                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1215 +            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1216 +                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1217 +            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1218 +            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1219 +            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1220 +            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1221 +            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1222 +                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1223 +            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1224 +            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1225 +            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1226 +            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1227 +            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1228 +            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1229 +            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1230 +            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1231 +          }
1232  
1233 +        }
1234  
968    //fills histograms with the sizes of collections
969    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
970
971      string currentObject = objectsToPlot.at(currentObjectIndex);
972      string objectToPlot = "";
973
974      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
975      if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
976      else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
977      else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
978      else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
979      else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
980      else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
981      else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
982      else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
983      else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
984      else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
985      else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
986      else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
987      else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
988      else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
989      else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
990      else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
991      else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
992      else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
993      else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
994      else objectToPlot = currentObject;
995
996      string tempCurrentObject = objectToPlot;
997      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
998      string histoName = "num" + tempCurrentObject;
999
1000      //set position of primary vertex in event, in order to calculate quantities relative to it
1001      if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1002        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1003        int numToPlot = 0;
1004        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1005          if(lastCutFlags.at(currentFlag)) numToPlot++;
1006        }
1007        if(objectToPlot == "primaryvertexs"){
1008          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1009          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1010        }
1011        else {
1012          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1013        }
1014      }
1015      else if(objectToPlot == "jets")           oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(jets->size(),scaleFactor);
1016      else if(objectToPlot == "secondaryJets")  oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(jets->size(),scaleFactor);
1017      else if(objectToPlot == "muons")          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size(),scaleFactor);
1018      else if(objectToPlot == "secondaryMuons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size(),scaleFactor);
1019      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
1020      else if(objectToPlot == "muonSecondaryMuonPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
1021      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size(),scaleFactor);
1022      else if(objectToPlot == "secondaryElectrons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size(),scaleFactor);
1023      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
1024      else if(objectToPlot == "electronSecondaryElectronPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
1025      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
1026      else if(objectToPlot == "electronJetPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*jets->size(),scaleFactor);
1027      else if(objectToPlot == "muonJetPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*jets->size(),scaleFactor);
1028      else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
1029      else if(objectToPlot == "electronTrigobjPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*trigobjs->size(),scaleFactor);
1030      else if(objectToPlot == "muonTrigobjPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*trigobjs->size(),scaleFactor);
1031      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(events->size(),scaleFactor);
1032      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(taus->size(),scaleFactor);
1033      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(mets->size(),scaleFactor);
1034      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(tracks->size(),scaleFactor);
1035      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(genjets->size(),scaleFactor);
1036      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(mcparticles->size(),scaleFactor);
1037      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(bxlumis->size(),scaleFactor);
1038      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(photons->size(),scaleFactor);
1039      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);
1235  
1236 <     } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1236 >        //fills histograms with the sizes of collections
1237 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1238 >
1239 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1240 >          string objectToPlot = "";
1241 >
1242 >          if (verbose_) clog << "Filling histogram of number of selected objects in collection: " << currentObject << endl;  
1243 >
1244 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1245 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1246 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1247 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1248 >          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1249 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1250 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1251 >          else if(currentObject == "muon-event pairs")                   objectToPlot = "muonEventPairs";
1252 >          else if(currentObject == "muon-photon pairs")                  objectToPlot = "muonPhotonPairs";
1253 >          else if(currentObject == "photon-jet pairs")                   objectToPlot = "photonJetPairs";
1254 >          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1255 >          else if(currentObject == "track-jet pairs")                    objectToPlot = "trackJetPairs";
1256 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1257 >          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1258 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1259 >          else if(currentObject == "secondary photons")                  objectToPlot = "secondaryPhotons";
1260 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1261 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1262 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1263 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1264 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1265 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1266 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1267 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1268 >          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1269 >          else if(currentObject == "muon-secondary photon pairs")        objectToPlot = "muonSecondaryJetPairs";
1270 >          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1271 >          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1272 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1273 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1274 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1275 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1276 >          else objectToPlot = currentObject;
1277 >
1278 >          string tempCurrentObject = objectToPlot;
1279 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1280 >          string histoName = "num" + tempCurrentObject;
1281 >
1282 >
1283 >          if(find(objectsToPlot.begin(), objectsToPlot.end(), currentObject) != objectsToPlot.end()) {
1284 >            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1285 >            int numToPlot = 0;
1286 >            for (uint iObj = 0; iObj != lastCutFlags.size(); iObj++){  // loop over all the objects  
1287 >              if(lastCutFlags.at(iObj).second) {
1288 >                numToPlot++;  
1289 >                if (verbose_>3) clog << "   Found object " << iObj << " in collection " << currentObject << " to plot." << endl;
1290 >              }
1291 >            }
1292 >
1293 >            if(objectToPlot == "primaryvertexs"){
1294 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1295 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1296 >            }
1297 >            else {
1298 >              if (printEventInfo_) clog << "Number of selected " << objectToPlot << " to plot:  " << numToPlot << endl;  
1299 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1300 >            }
1301 >          }
1302 >
1303 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1304 >
1305 >
1306 >      } // end if(eventPassedPreviousCuts.at(currentDir))
1307 >    } // end loop over cuts
1308 >
1309 >    if (!useEDMFormat_ && eventPassedAllCuts){
1310 >      // Assign BNTree variables
1311 >      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1312 >        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1313 >        string coll = brSpecs.inputCollection;
1314 >        if (cumulativeFlags.count(coll) == 0) clog << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1315 >
1316 >        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1317 >        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1318 >        else if(coll == "secondary photons")      assignTreeBranch(brSpecs,photons.product(),          cumulativeFlags.at(coll).back());
1319 >        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1320 >        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1321 >        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1322 >        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1323 >        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1324 >        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1325 >        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1326 >        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1327 >        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1328 >        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1329 >        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1330 >        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1331 >        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1332 >        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1333 >        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1334 >        else if(coll == "stops"
1335 >                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1336 >      } // end loop over branches
1337 >
1338 >      if (!BNTrees_.at(currentChannelIndex)) { clog << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1339 >      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1340      }
1341 <  }
1342 <  } //end loop over channel
1341 >
1342 >    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1343 >
1344 >  } // end loop over channel
1345  
1346    masterCutFlow_->fillCutFlow(masterScaleFactor);
1347  
1348 < } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1348 >  event.put (channelDecisions, "channelDecisions");
1349 >
1350 >  isFirstEvent_ = false;  
1351 >
1352 >  if (verbose_) clog << "Finished OSUAnalysis::produce." << endl;  
1353 >
1354 > } // end void OSUAnalysis::produce (const edm::Event &event, const edm::EventSetup &setup)
1355  
1356  
1357  
# Line 1066 | Line 1366 | OSUAnalysis::evaluateComparison (double
1366    else if(comparison == "==") return testValue == cutValue;
1367    else if(comparison == "=") return testValue == cutValue;
1368    else if(comparison == "!=") return testValue != cutValue;
1369 <  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1369 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1370  
1371   }
1372  
# Line 1079 | Line 1379 | OSUAnalysis::evaluateComparison (string
1379    else if(comparison == "<")  return testValue <  cutValue;
1380    else if(comparison == "<=") return testValue <= cutValue;
1381    else if(comparison == "==") return testValue == cutValue;
1382 <  else if(comparison == "=") return testValue == cutValue;
1382 >  else if(comparison == "=")  return testValue == cutValue;
1383    else if(comparison == "!=") return testValue != cutValue;
1384 <  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1384 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1385  
1386   }
1387  
1388   bool
1389 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1389 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1390  
1391 +  //initialize to false until a chosen trigger is passed
1392    bool triggerDecision = false;
1393  
1394 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1395 <    {
1396 <      if(trigger->pass != 1) continue;
1397 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1398 <        {
1399 <          if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos){
1400 <            triggerDecision = true;
1401 <          }
1402 <        }
1394 >  if (printAllTriggers_) clog << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1395 >  //loop over all triggers defined in the event
1396 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1397 >
1398 >    if (printAllTriggers_) clog << "   " << trigger->name << endl;
1399 >
1400 >    //we're only interested in triggers that actually passed
1401 >    if(trigger->pass != 1) continue;
1402 >
1403 >    //if the event passes one of the veto triggers, exit and return false
1404 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1405 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1406 >    }
1407 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1408 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1409 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1410      }
1411 <  return triggerDecision;
1411 >  }
1412  
1413 +  printAllTriggers_ = false;  // only print triggers once, not every event
1414 +
1415 +  //if none of the veto triggers fired:
1416 +  //return the OR of all the chosen triggers
1417 +  if (triggersToTest.size() != 0) return triggerDecision;
1418 +  //or if no triggers were defined return true
1419 +  else return true;
1420   }
1421  
1422 +
1423   vector<string>
1424   OSUAnalysis::splitString (string inputString){
1425  
# Line 1265 | Line 1581 | OSUAnalysis::valueLookup (const BNjet* o
1581    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1582    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1583  
1584 +  //user defined variable
1585 +  else if(variable == "disappTrkLeadingJetID") {
1586 +    value = object->pt > 110
1587 +      && fabs(object->eta) < 2.4
1588 +      && object->chargedHadronEnergyFraction > 0.2
1589 +      && object->neutralHadronEnergyFraction < 0.7
1590 +      && object->chargedEmEnergyFraction < 0.5
1591 +      && object->neutralEmEnergyFraction < 0.7;
1592 +  }
1593 +
1594 +  else if(variable == "disappTrkSubLeadingJetID") {
1595 +    value = object->pt > 30
1596 +      && fabs(object->eta) < 4.5
1597 +      && object->neutralHadronEnergyFraction < 0.7
1598 +      && object->chargedEmEnergyFraction < 0.5;
1599 +  }
1600 +
1601 +  else if(variable == "dPhiMet") {
1602 +    if (const BNmet *met = chosenMET ()) {
1603 +      value = deltaPhi (object->phi, met->phi);
1604 +    } else value = -999;
1605 +  }
1606 +
1607  
1608 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1608 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1609  
1610    value = applyFunction(function, value);
1611  
1612    return value;
1613 < }
1613 > } // end jet valueLookup
1614  
1615  
1616   //!muon valueLookup
# Line 1368 | Line 1707 | OSUAnalysis::valueLookup (const BNmuon*
1707    else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1708    else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1709    else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1710 +  else if(variable == "chargedHadronIsoDR04") value = object->chargedHadronIsoDR04;
1711 +  else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1712 +  else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1713 +  else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1714    else if(variable == "rhoPrime") value = object->rhoPrime;
1715    else if(variable == "AEffDr03") value = object->AEffDr03;
1716    else if(variable == "AEffDr04") value = object->AEffDr04;
# Line 1375 | Line 1718 | OSUAnalysis::valueLookup (const BNmuon*
1718    else if(variable == "pfIsoR03SumNeutralHadronEt") value = object->pfIsoR03SumNeutralHadronEt;
1719    else if(variable == "pfIsoR03SumPhotonEt") value = object->pfIsoR03SumPhotonEt;
1720    else if(variable == "pfIsoR03SumPUPt") value = object->pfIsoR03SumPUPt;
1721 +  else if(variable == "relpfIsoR04SumExceptChargedHad") value = (object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)/ object->pt;
1722 +  else if(variable == "relpfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt/object->pt;
1723 +  else if(variable == "relpfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt/object->pt;
1724 +  else if(variable == "relpfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt/object->pt;
1725 +  else if(variable == "relpfIsoR04SumPUPt") value = object->pfIsoR04SumPUPt/object->pt;
1726    else if(variable == "pfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt;
1727    else if(variable == "pfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt;
1728    else if(variable == "pfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt;
# Line 1431 | Line 1779 | OSUAnalysis::valueLookup (const BNmuon*
1779    else if(variable == "time_ndof") value = object->time_ndof;
1780  
1781    //user-defined variables
1782 +  else if(variable == "looseID") {
1783 +    value = object->pt > 10 &&
1784 +      (object->isGlobalMuon  > 0 ||
1785 +       object->isTrackerMuon > 0);
1786 +  }
1787    else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1788    else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1789    else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1790    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1791 +  else if(variable == "relPFdBetaIsoPseudo") value = (object->pfIsoR04SumChargedHadronPt + object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt) / object->pt;
1792    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1793    else if(variable == "metMT") {
1794      if (const BNmet *met = chosenMET ())
# Line 1558 | Line 1912 | OSUAnalysis::valueLookup (const BNmuon*
1912      value = object->isGlobalMuon > 0                \
1913        && object->isPFMuon > 0                        \
1914        && object->normalizedChi2 < 10                \
1915 <                                  && object->numberOfValidMuonHits > 0        \
1915 >      && object->numberOfValidMuonHits > 0        \
1916        && object->numberOfMatchedStations > 1        \
1917        && fabs(object->correctedD0Vertex) < 0.2        \
1918        && fabs(object->correctedDZ) < 0.5        \
# Line 1569 | Line 1923 | OSUAnalysis::valueLookup (const BNmuon*
1923      value = object->isGlobalMuon > 0                \
1924        && object->isPFMuon > 0                        \
1925        && object->normalizedChi2 < 10                \
1926 <                                  && object->numberOfValidMuonHits > 0        \
1926 >      && object->numberOfValidMuonHits > 0        \
1927        && object->numberOfMatchedStations > 1        \
1928        && object->numberOfValidPixelHits > 0        \
1929        && object->numberOfLayersWithMeasurement > 5;
# Line 1624 | Line 1978 | OSUAnalysis::valueLookup (const BNmuon*
1978      d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1979      dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1980      value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1981 <         || fabs (object->correctedD0Vertex / d0Error) > 99.0
1982 <         || fabs (object->correctedDZ / dzError) > 99.0;
1981 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1982 >      || fabs (object->correctedDZ / dzError) > 99.0;
1983      value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1984    }
1985  
1986  
1987  
1988 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1988 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1989  
1990    value = applyFunction(function, value);
1991  
1992    return value;
1993 < }
1993 > } // end muon valueLookup
1994 >
1995  
1996   //!electron valueLookup
1997   double
# Line 1805 | Line 2160 | OSUAnalysis::valueLookup (const BNelectr
2160    else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2161    else if(variable == "detIso") value = (object->trackIso) / object->pt;
2162    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2163 +  else if(variable == "relPFrhoIsoEB") value = object->isEB ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2164 +  else if(variable == "relPFrhoIsoEE") value = object->isEE ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2165    else if(variable == "metMT") {
2166      if (const BNmet *met = chosenMET ())
2167        {
# Line 1876 | Line 2233 | OSUAnalysis::valueLookup (const BNelectr
2233      else value = -999;
2234    }
2235  
2236 +  else if(variable == "looseID"){
2237 +    if (object->isEB)
2238 +      {
2239 +        value = fabs(object->delEtaIn) < 0.007 \
2240 +          && fabs (object->delPhiIn) < 0.15 \
2241 +          && object->scSigmaIEtaIEta < 0.01 \
2242 +          && object->hadOverEm < 0.12 \
2243 +          && fabs (object->correctedD0Vertex) < 0.02 \
2244 +          && fabs (object->correctedDZ) < 0.2 \
2245 +          && object->absInvEMinusInvPin < 0.05 \
2246 +          && object->passConvVeto;
2247 +      }
2248 +    else
2249 +      {
2250 +        value = fabs(object->delEtaIn) < 0.009 \
2251 +          && fabs (object->delPhiIn) < 0.10 \
2252 +          && object->scSigmaIEtaIEta < 0.03 \
2253 +          && object->hadOverEm < 0.10 \
2254 +          && fabs (object->correctedD0Vertex) < 0.02 \
2255 +          && fabs (object->correctedDZ) < 0.2 \
2256 +          && object->absInvEMinusInvPin < 0.05 \
2257 +          && object->passConvVeto;
2258 +      }
2259 +  }
2260 +
2261    else if(variable == "tightID"){
2262      if (object->isEB)
2263        {
# Line 1901 | Line 2283 | OSUAnalysis::valueLookup (const BNelectr
2283        }
2284    }
2285  
2286 +  else if(variable == "looseID_MVA"){
2287 +    value = object->pt > 10
2288 +      && object->mvaNonTrigV0 > 0;
2289 +      }
2290    else if(variable == "correctedD0VertexInEBPositiveCharge"){
2291      if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2292      else value = -999;
# Line 2024 | Line 2410 | OSUAnalysis::valueLookup (const BNelectr
2410      d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2411      dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2412      value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2413 <         || fabs (object->correctedD0Vertex / d0Error) > 99.0
2414 <         || fabs (object->correctedDZ / dzError) > 99.0;
2413 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2414 >      || fabs (object->correctedDZ / dzError) > 99.0;
2415      value = !value;
2416    }
2417  
2418  
2419  
2420 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2420 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2421  
2422    value = applyFunction(function, value);
2423  
2424    return value;
2425 < }
2425 > } // end electron valueLookup
2426 >
2427  
2428   //!event valueLookup
2429   double
# Line 2048 | Line 2435 | OSUAnalysis::valueLookup (const BNevent*
2435    else if(variable == "pthat") value = object->pthat;
2436    else if(variable == "qScale") value = object->qScale;
2437    else if(variable == "alphaQCD") value = object->alphaQCD;
2438 +  else if(variable == "Ht") value = getHt(jets.product());
2439    else if(variable == "alphaQED") value = object->alphaQED;
2440    else if(variable == "scalePDF") value = object->scalePDF;
2441    else if(variable == "x1") value = object->x1;
# Line 2117 | Line 2505 | OSUAnalysis::valueLookup (const BNevent*
2505    else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2506    else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2507    else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2508 <
2509 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2508 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2509 >  else if(variable == "ht") value = chosenHT ();
2510 >  else if(variable == "leadMuPairInvMass"){
2511 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2512 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2513 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2514 >    value = (p0 + p1).M ();
2515 >  }
2516 >  else if(variable == "leadMuPairPt"){
2517 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2518 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2519 >             pt1 (muPair.second->px, muPair.second->py);
2520 >    pt0 += pt1;
2521 >    value = pt0.Mod ();
2522 >  }
2523 >  else if(variable == "leadElPairInvMass"){
2524 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2525 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2526 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2527 >    value = (p0 + p1).M ();
2528 >  }
2529 >  else if(variable == "leadElPairPt"){
2530 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2531 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2532 >             pt1 (muPair.second->px, muPair.second->py);
2533 >    pt0 += pt1;
2534 >    value = pt0.Mod ();
2535 >  }
2536 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2537  
2538    value = applyFunction(function, value);
2539  
2540    return value;
2541 < }
2541 > } // end event valueLookup
2542 >
2543  
2544   //!tau valueLookup
2545   double
# Line 2171 | Line 2587 | OSUAnalysis::valueLookup (const BNtau* o
2587    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2588    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2589  
2590 <
2590 >  else if (variable == "looseHadronicID") {
2591 >    value = object->pt > 10
2592 >      && object->eta < 2.3
2593 >      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2594 >      && object->HPSdecayModeFinding > 0
2595 >      && object->HPSagainstElectronLoose > 0
2596 >      && object->HPSagainstMuonTight > 0;
2597 >  }
2598  
2599    else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2600  
# Line 2218 | Line 2641 | OSUAnalysis::valueLookup (const BNtau* o
2641    }
2642  
2643  
2644 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2644 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2645  
2646    value = applyFunction(function, value);
2647  
2648    return value;
2649 < }
2649 > } // end tau valueLookup
2650 >
2651  
2652   //!met valueLookup
2653   double
# Line 2291 | Line 2715 | OSUAnalysis::valueLookup (const BNmet* o
2715    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2716    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2717  
2718 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2718 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2719  
2720    value = applyFunction(function, value);
2721  
2722    return value;
2723 < }
2723 > } // end met valueLookup
2724 >
2725  
2726   //!track valueLookup
2727   double
# Line 2324 | Line 2749 | OSUAnalysis::valueLookup (const BNtrack*
2749    else if(variable == "numValidHits") value = object->numValidHits;
2750    else if(variable == "isHighPurity") value = object->isHighPurity;
2751  
2327
2752    //additional BNs info for disappTrks
2753 <  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2754 <  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2755 <  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2756 <  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2757 <  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2758 <  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2759 <  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2760 <  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2337 <  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2753 >  else if(variable == "caloEMDeltaRp3")     value = object->caloEMDeltaRp3;
2754 >  else if(variable == "caloHadDeltaRp3")    value = object->caloHadDeltaRp3;
2755 >  else if(variable == "caloEMDeltaRp4")     value = object->caloEMDeltaRp4;
2756 >  else if(variable == "caloHadDeltaRp4")    value = object->caloHadDeltaRp4;
2757 >  else if(variable == "caloEMDeltaRp5")     value = object->caloEMDeltaRp5;
2758 >  else if(variable == "caloHadDeltaRp5")    value = object->caloHadDeltaRp5;
2759 >  else if(variable == "nHitsMissingOuter")  value = object->nHitsMissingOuter;
2760 >  else if(variable == "nHitsMissingInner")  value = object->nHitsMissingInner;
2761    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2762 <  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2762 >  else if(variable == "depTrkRp3")          value = object->depTrkRp3;
2763 >  else if(variable == "trkRelIsoRp3")       value = (object->depTrkRp3 - object->pt) / object->pt;
2764 >  else if(variable == "trkRelIsoRp5")       value = (object->depTrkRp5 - object->pt) / object->pt;
2765 >  else if(variable == "depEcalRp3")         value = object->depEcalRp3;
2766 >  else if(variable == "depHcalRp3")         value = object->depHcalRp3;
2767 >  else if(variable == "depHoRp3")           value = object->depHoRp3;
2768 >  else if(variable == "nTracksRp3")         value = object->nTracksRp3;
2769 >  else if(variable == "trackerVetoPtRp3")   value = object->trackerVetoPtRp3;
2770 >  else if(variable == "emVetoEtRp3")        value = object->emVetoEtRp3;
2771 >  else if(variable == "hadVetoEtRp3")       value = object->hadVetoEtRp3;
2772 >  else if(variable == "hoVetoEtRp3")        value = object->hoVetoEtRp3;
2773 >  else if(variable == "depTrkRp5")          value = object->depTrkRp5;
2774 >  else if(variable == "depEcalRp5")         value = object->depEcalRp5;
2775 >  else if(variable == "depHcalRp5")         value = object->depHcalRp5;
2776 >  else if(variable == "depHoRp5")           value = object->depHoRp5;
2777 >  else if(variable == "nTracksRp5")         value = object->nTracksRp5;
2778 >  else if(variable == "trackerVetoPtRp5")   value = object->trackerVetoPtRp5;
2779 >  else if(variable == "emVetoEtRp5")        value = object->emVetoEtRp5;
2780 >  else if(variable == "hadVetoEtRp5")       value = object->hadVetoEtRp5;
2781 >  else if(variable == "hoVetoEtRp5")        value = object->hoVetoEtRp5;
2782  
2783    //user defined variables
2784    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;
2785    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2786 <  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2786 >  else if(variable == "depTrkRp5MinusPt"){
2787 >    if ( (object->depTrkRp5 - object->pt) < 0 ) {
2788 > //       clog << "Warning:  found track with depTrkRp5 < pt:  depTrkRp5=" << object->depTrkRp5
2789 > //         << "; pt=" << object->pt
2790 > //         << "; object->depTrkRp5 - object->pt = " << object->depTrkRp5 - object->pt
2791 > //         << endl;  
2792 >           value = 0;
2793 >         }
2794 >         else value =  (object->depTrkRp5 - object->pt);
2795 >  }
2796 >  else if(variable == "depTrkRp3MinusPt"){
2797 >    if ( (object->depTrkRp3 - object->pt) < 0 ) {
2798 >      value = 0;
2799 >    }
2800 >    else value =  (object->depTrkRp3 - object->pt);
2801 >  }
2802 >
2803 >  else if(variable == "dPhiMet") {
2804 >    if (const BNmet *met = chosenMET ()) {
2805 >      value = deltaPhi (object->phi, met->phi);
2806 >    } else value = -999;
2807 >  }
2808 >  
2809 >  
2810    else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2811    else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2812    else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2813    else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2814 +  else if(variable == "depTrkRp5RhoCorr")           value = getTrkDepTrkRp5RhoCorr(object);
2815 +  else if(variable == "depTrkRp3RhoCorr")           value = getTrkDepTrkRp3RhoCorr(object);
2816 +
2817 +  else if(variable == "depTrkRp5MinusPtRhoCorr")    {
2818 +    if ( (getTrkDepTrkRp5RhoCorr(object) - object->pt) < 0 ) value = 0;
2819 +    else {value = (getTrkDepTrkRp5RhoCorr(object) - object->pt );}
2820 +  }
2821 +  
2822 +  else if(variable == "depTrkRp3MinusPtRhoCorr")    
2823 +    {
2824 +      if ( (getTrkDepTrkRp3RhoCorr(object) - object->pt) < 0 ) value = 0;
2825 +      else {value = (getTrkDepTrkRp3RhoCorr(object) - object->pt );}
2826 +    }
2827 +
2828    else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2829    else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2830    else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
# Line 2369 | Line 2848 | OSUAnalysis::valueLookup (const BNtrack*
2848        pt = object->pt;
2849      value = vz - (vx * px + vy * py)/pt * (pz/pt);
2850    }
2851 +
2852 +
2853    else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2854  
2855    else if(variable == "genMatchedPdgId"){
# Line 2416 | Line 2897 | OSUAnalysis::valueLookup (const BNtrack*
2897  
2898  
2899  
2900 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2900 >  else{clog << "WARNING: invalid variable '" << variable << "' for BNtrack collection.\n"; value = -999;}
2901  
2902    value = applyFunction(function, value);
2903  
2904    return value;
2905 < }
2905 > } // end track valueLookup
2906 >
2907  
2908   //!genjet valueLookup
2909   double
# Line 2445 | Line 2927 | OSUAnalysis::valueLookup (const BNgenjet
2927    else if(variable == "charge") value = object->charge;
2928  
2929  
2930 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2930 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2931  
2932    value = applyFunction(function, value);
2933  
# Line 2579 | Line 3061 | OSUAnalysis::valueLookup (const BNmcpart
3061    }
3062  
3063  
3064 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3064 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3065  
3066    value = applyFunction(function, value);
3067  
3068    return value;
3069 < }
3069 > } // end mcparticle valueLookup
3070 >
3071  
3072   //!primaryvertex valueLookup
3073   double
# Line 2607 | Line 3090 | OSUAnalysis::valueLookup (const BNprimar
3090    else if(variable == "isGood") value = object->isGood;
3091  
3092  
3093 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3093 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3094  
3095    value = applyFunction(function, value);
3096  
# Line 2625 | Line 3108 | OSUAnalysis::valueLookup (const BNbxlumi
3108    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
3109  
3110  
3111 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3111 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3112  
3113    value = applyFunction(function, value);
3114  
# Line 2758 | Line 3241 | OSUAnalysis::valueLookup (const BNphoton
3241    }
3242  
3243  
3244 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3244 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3245  
3246    value = applyFunction(function, value);
3247  
3248    return value;
3249 < }
3249 > } // end photon valueLookup
3250 >
3251  
3252   //!supercluster valueLookup
3253   double
# Line 2781 | Line 3265 | OSUAnalysis::valueLookup (const BNsuperc
3265    else if(variable == "theta") value = object->theta;
3266  
3267  
3268 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3268 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3269  
3270    value = applyFunction(function, value);
3271  
# Line 2815 | Line 3299 | OSUAnalysis::valueLookup (const BNtrigob
3299        stringValue = "none";  // stringValue should only be empty if value is filled
3300    }
3301  
3302 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3302 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3303  
3304    value = applyFunction(function, value);
3305  
# Line 2886 | Line 3370 | OSUAnalysis::valueLookup (const BNmuon*
3370        value = object2->correctedD0;
3371      }
3372  
3373 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3373 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3374 >
3375 >  value = applyFunction(function, value);
3376 >
3377 >  return value;
3378 > } // end muon-muon pair valueLookup
3379 >
3380 >
3381 > //!muon-photon pair valueLookup
3382 > double
3383 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3384 >
3385 >  double value = 0.0;
3386 >
3387 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3388 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3389 >  else if(variable == "photonEta") value = object2->eta;
3390 >  else if(variable == "photonPt") value = object2->pt;
3391 >  else if(variable == "muonEta") value = object1->eta;
3392 >  else if(variable == "photonPhi") value = object2->phi;
3393 >  else if(variable == "muonPhi") value = object1->phi;
3394 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3395 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3396 >  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3397 >  else if(variable == "invMass"){
3398 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3399 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3400 >    value = (fourVector1 + fourVector2).M();
3401 >  }
3402 >  else if(variable == "pt"){
3403 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3404 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3405 >    value = (fourVector1 + fourVector2).Pt();
3406 >  }
3407 >  else if(variable == "threeDAngle")
3408 >    {
3409 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3410 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3411 >      value = (threeVector1.Angle(threeVector2));
3412 >    }
3413 >  else if(variable == "alpha")
3414 >    {
3415 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3416 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3417 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3418 >      value = (pi-threeVector1.Angle(threeVector2));
3419 >    }
3420 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3421 >
3422 >  value = applyFunction(function, value);
3423 >
3424 >  return value;
3425 > }
3426 >
3427 > //!electron-photon pair valueLookup
3428 > double
3429 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3430 >
3431 >  double value = 0.0;
3432 >
3433 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3434 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3435 >  else if(variable == "photonEta") value = object2->eta;
3436 >  else if(variable == "photonPt") value = object2->pt;
3437 >  else if(variable == "electronEta") value = object1->eta;
3438 >  else if(variable == "photonPhi") value = object2->phi;
3439 >  else if(variable == "electronPhi") value = object1->phi;
3440 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3441 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3442 >  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3443 >  else if(variable == "invMass"){
3444 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3445 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3446 >    value = (fourVector1 + fourVector2).M();
3447 >  }
3448 >  else if(variable == "pt"){
3449 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3450 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3451 >    value = (fourVector1 + fourVector2).Pt();
3452 >  }
3453 >  else if(variable == "threeDAngle")
3454 >    {
3455 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3456 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3457 >      value = (threeVector1.Angle(threeVector2));
3458 >    }
3459 >  else if(variable == "alpha")
3460 >    {
3461 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3462 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3463 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3464 >      value = (pi-threeVector1.Angle(threeVector2));
3465 >    }
3466 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3467  
3468    value = applyFunction(function, value);
3469  
# Line 2942 | Line 3519 | OSUAnalysis::valueLookup (const BNelectr
3519      value = object2->correctedD0;
3520    }
3521  
3522 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3522 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3523  
3524    value = applyFunction(function, value);
3525  
3526    return value;
3527   }
3528 +
3529   //!electron-muon pair valueLookup
3530   double
3531   OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
# Line 3008 | Line 3586 | OSUAnalysis::valueLookup (const BNelectr
3586    else if(variable == "muonRelPFdBetaIso"){
3587      value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3588    }
3589 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3589 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3590    value = applyFunction(function, value);
3591  
3592    return value;
3593 < }
3593 > } // end electron-muon pair valueLookup
3594 >
3595  
3596   //!electron-jet pair valueLookup
3597   double
# Line 3022 | Line 3601 | OSUAnalysis::valueLookup (const BNelectr
3601  
3602    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3603    else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3604 +  else if(variable == "jetEta") value = object2->eta;
3605 +  else if(variable == "jetPhi") value = object2->phi;
3606 +  else if(variable == "electronEta") value = object1->eta;
3607 +  else if(variable == "electronPhi") value = object1->phi;
3608    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3609    else if(variable == "invMass"){
3610      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 3043 | Line 3626 | OSUAnalysis::valueLookup (const BNelectr
3626      value = object1->charge*object2->charge;
3627    }
3628  
3629 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3629 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3630 >  value = applyFunction(function, value);
3631 >
3632 >  return value;
3633 > }
3634 >
3635 > //!photon-jet pair valueLookup
3636 > double
3637 > OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3638 >
3639 >  double value = 0.0;
3640 >
3641 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3642 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3643 >  else if(variable == "jetEta") value = object2->eta;
3644 >  else if(variable == "jetPhi") value = object2->phi;
3645 >  else if(variable == "photonEta") value = object1->eta;
3646 >  else if(variable == "photonPhi") value = object1->phi;
3647 >  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3648 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3649 >  else if(variable == "invMass"){
3650 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3651 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3652 >    value = (fourVector1 + fourVector2).M();
3653 >  }
3654 >  else if(variable == "pt"){
3655 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3656 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3657 >    value = (fourVector1 + fourVector2).Pt();
3658 >  }
3659 >  else if(variable == "threeDAngle")
3660 >    {
3661 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3662 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3663 >      value = (threeVector1.Angle(threeVector2));
3664 >    }
3665 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3666 >  value = applyFunction(function, value);
3667 >
3668 >  return value;
3669 > }
3670 >
3671 > // track-jet pair valueLookup
3672 > double
3673 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNjet* object2, string variable, string function, string &stringValue){
3674 >
3675 >  double value = 0.0;
3676 >
3677 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3678 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3679 >
3680 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3681    value = applyFunction(function, value);
3682  
3683    return value;
3684 +
3685   }
3686  
3687 +
3688 +
3689 + // met-jet pair valueLookup
3690 + double
3691 + OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3692 +
3693 +  double value = 0.0;
3694 +
3695 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3696 +
3697 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3698 +  value = applyFunction(function, value);
3699 +
3700 +  return value;
3701 +
3702 + }  
3703 +
3704 +
3705 +
3706   //!muon-jet pair valueLookup
3707   double
3708   OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
# Line 3056 | Line 3710 | OSUAnalysis::valueLookup (const BNmuon*
3710    double value = 0.0;
3711  
3712    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3713 <  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3713 >  else if(variable == "jetEta") value = object2->eta;
3714 >  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3715 >  else if(variable == "jetPt") value = object2->pt;
3716 >  else if(variable == "jetPhi") value = object2->phi;
3717 >  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3718 >  else if(variable == "muonEta") value = object1->eta;
3719 >  else if(variable == "muonPt") value = object1->pt;
3720 >  else if(variable == "muonPhi") value = object1->phi;
3721 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3722    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3723    else if(variable == "invMass"){
3724      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 3078 | Line 3740 | OSUAnalysis::valueLookup (const BNmuon*
3740      value = object1->charge*object2->charge;
3741    }
3742  
3743 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3743 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3744    value = applyFunction(function, value);
3745  
3746    return value;
3747   }
3748  
3749 + //!muon-event valueLookup
3750 + double
3751 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNevent* object2, string variable, string function, string &stringValue){
3752 +
3753 +  double value = 0.0;
3754 +
3755 +  if(variable == "muonEta") value = object1->eta;
3756 +  else if(variable == "muonPt") value = object1->pt;
3757 +  else if(variable == "muonPhi") value = object1->phi;
3758 +  else if(variable == "Ht") value = getHt(jets.product());
3759 +  else if(variable == "pthat")   value = object2->pthat;
3760 +  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3761 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3762 +  value = applyFunction(function, value);
3763 +
3764 +  return value;
3765 + }
3766   //!jet-jet pair valueLookup
3767   double
3768   OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
# Line 3092 | Line 3771 | OSUAnalysis::valueLookup (const BNjet* o
3771  
3772    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3773    else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3774 <  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3774 >  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3775    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3776    else if(variable == "invMass"){
3777      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 3114 | Line 3793 | OSUAnalysis::valueLookup (const BNjet* o
3793      value = object1->charge*object2->charge;
3794    }
3795  
3796 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3796 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3797    value = applyFunction(function, value);
3798  
3799    return value;
3800   }
3801 +
3802   //!electron-track pair valueLookup
3803   double
3804   OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
# Line 3138 | Line 3818 | OSUAnalysis::valueLookup (const BNelectr
3818    else if(variable == "chargeProduct"){
3819      value = object1->charge*object2->charge;
3820    }
3821 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3821 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3822    value = applyFunction(function, value);
3823    return value;
3824  
# Line 3166 | Line 3846 | OSUAnalysis::valueLookup (const BNmuon*
3846      value = object1->charge*object2->charge;
3847    }
3848  
3849 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3849 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3850    value = applyFunction(function, value);
3851    return value;
3852   }
# Line 3188 | Line 3868 | OSUAnalysis::valueLookup (const BNtau* o
3868      value = object1->charge*object2->charge;
3869    }
3870  
3871 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3871 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3872    value = applyFunction(function, value);
3873    return value;
3874   }
# Line 3210 | Line 3890 | OSUAnalysis::valueLookup (const BNmuon*
3890      value = object1->charge*object2->charge;
3891    }
3892  
3893 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3893 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3894    value = applyFunction(function, value);
3895    return value;
3896   }
# Line 3225 | Line 3905 | OSUAnalysis::valueLookup (const BNtau* o
3905      value = object1->charge*object2->charge;
3906    }
3907  
3908 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3908 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3909    value = applyFunction(function, value);
3910    return value;
3911   }
# Line 3245 | Line 3925 | OSUAnalysis::valueLookup (const BNtrack*
3925    else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3926    else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3927  
3928 <  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3928 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3929  
3930    value = applyFunction(function, value);
3931  
# Line 3267 | Line 3947 | OSUAnalysis::valueLookup (const BNelectr
3947        stringValue = "none";
3948    }
3949  
3950 <  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3950 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3951  
3952    value = applyFunction(function, value);
3953  
# Line 3283 | Line 3963 | OSUAnalysis::valueLookup (const BNmuon*
3963  
3964    if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3965  
3966 <  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3966 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3967  
3968    value = applyFunction(function, value);
3969  
# Line 3386 | Line 4066 | OSUAnalysis::valueLookup (const BNstop*
4066      for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4067        vertex_rank++;
4068        int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4069 <                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4070 <                   (object->vz-vertex->z)*(object->vz-vertex->z));
4069 >                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
4070 >                      (object->vz-vertex->z)*(object->vz-vertex->z));
4071  
4072        if(abs(dist) < abs(minDistToVertex)){
4073          value = vertex_rank;
# Line 3396 | Line 4076 | OSUAnalysis::valueLookup (const BNstop*
4076      }
4077    }
4078  
4079 +  else if (variable == "decaysToTau"){
4080 +    value = abs (object->daughter0Id) == 15 || abs (object->daughter1Id) == 15;
4081 +  }
4082 +
4083  
4084  
4085  
4086 <  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4086 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4087  
4088    value = applyFunction(function, value);
4089  
4090    return value;
4091  
4092 < }
4092 > } // end stop valueLookup
4093 >
4094  
4095  
4096  
# Line 3423 | Line 4108 | OSUAnalysis::getTrkIsIso (const BNtrack*
4108  
4109   }
4110  
4111 + //calculate the scalar sum of Jet Pt in the event.
4112 + double
4113 + OSUAnalysis::getHt (const BNjetCollection* jetColl){
4114 +  double Ht = 0;
4115 +  for(BNjetCollection::const_iterator jet = jetColl->begin(); jet !=jetColl->end(); jet++){
4116 +    Ht += abs(jet->pt);
4117 +  }
4118 +  return Ht;
4119 + }
4120  
4121   double
4122   OSUAnalysis::getTrkPtRes (const BNtrack* track1){
# Line 3460 | Line 4154 | OSUAnalysis::getTrkCaloTotRhoCorr(const
4154    // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
4155    if (!useTrackCaloRhoCorr_) return -99;
4156    // if (!rhokt6CaloJetsHandle_) {
4157 <  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
4157 >  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
4158    //   return -99;
4159    // }
4160    double radDeltaRCone = 0.5;
# Line 3471 | Line 4165 | OSUAnalysis::getTrkCaloTotRhoCorr(const
4165  
4166   }
4167  
4168 + double
4169 + OSUAnalysis::getTrkDepTrkRp5RhoCorr(const BNtrack* track) {
4170 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.              
4171 +  if (!useTrackCaloRhoCorr_) return -99;
4172 +  // if (!rhokt6CaloJetsHandle_) {                                                                                                    
4173 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;                        
4174 +  //   return -99;                                                                                                                    
4175 +  // }                                                                                                                                
4176 +  double radDeltaRCone = 0.5;
4177 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.                                                                                                          
4178 +  double rawDepTrkRp5 = track->depTrkRp5;
4179 + double depTrkRp5RhoCorr = TMath::Max(0., rawDepTrkRp5 - rhoCorr_kt6CaloJets);
4180 + return depTrkRp5RhoCorr;
4181 +
4182 + }
4183 +
4184 + double
4185 + OSUAnalysis::getTrkDepTrkRp3RhoCorr(const BNtrack* track) {
4186 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.                                                
4187 +  if (!useTrackCaloRhoCorr_) return -99;
4188 +  // if (!rhokt6CaloJetsHandle_) {                                                                                                                                      
4189 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;                                                          
4190 +  //   return -99;                                                                                                                                                      
4191 +  // }                                                                                                                                                                  
4192 +  double radDeltaRCone = 0.3;
4193 + // Define effective area as pi*r^2, where r is radius of DeltaR cone
4194 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  
4195 +  double rawDepTrkRp3 = track->depTrkRp3;
4196 +  double depTrkRp3RhoCorr = TMath::Max(0., rawDepTrkRp3 - rhoCorr_kt6CaloJets);
4197 +  return depTrkRp3RhoCorr;
4198 +  
4199 + }
4200 +
4201  
4202  
4203  
# Line 3482 | Line 4209 | OSUAnalysis::WriteDeadEcal (){
4209    double etaEcal, phiEcal;
4210    ifstream DeadEcalFile(deadEcalFile_);
4211    if(!DeadEcalFile) {
4212 <    cout << "Error: DeadEcalFile has not been found." << endl;
4212 >    clog << "Error: DeadEcalFile has not been found." << endl;
4213      return;
4214    }
4215    if(DeadEcalVec.size()!= 0){
4216 <    cout << "Error: DeadEcalVec has a nonzero size" << endl;
4216 >    clog << "Error: DeadEcalVec has a nonzero size" << endl;
4217      return;
4218    }
4219    while(!DeadEcalFile.eof())
# Line 3497 | Line 4224 | OSUAnalysis::WriteDeadEcal (){
4224        newChan.phiEcal = phiEcal;
4225        DeadEcalVec.push_back(newChan);
4226      }
4227 <  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
4227 >  if(DeadEcalVec.size() == 0) clog << "Warning: No dead Ecal channels have been found." << endl;
4228   }
4229  
4230   //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
# Line 3537 | Line 4264 | OSUAnalysis::applyFunction(string functi
4264    else if(function == "log") value = log10(value);
4265  
4266    else if(function == "") value = value;
4267 <  else{cout << "WARNING: invalid function '" << function << "'\n";}
4267 >  else{clog << "WARNING: invalid function '" << function << "'\n";}
4268  
4269    return value;
4270  
# Line 3547 | Line 4274 | OSUAnalysis::applyFunction(string functi
4274   template <class InputCollection>
4275   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
4276  
4277 +  if (verbose_>2) clog << "  Beginning setObjectFlags for cut " << currentCutIndex << ": " << currentCut.name
4278 +                       << ", inputType=" << inputType
4279 +                       << endl;  
4280    if (currentCut.inputCollection.find("pair")!=string::npos)  {
4281      string obj1, obj2;
4282      getTwoObjs(currentCut.inputCollection, obj1, obj2);
4283      if (inputType==obj1 ||
4284 <          inputType==obj2) {
4284 >        inputType==obj2) {
4285        // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
4286        // and the inputType is a member of the pair.
4287        // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
# Line 3563 | Line 4293 | void OSUAnalysis::setObjectFlags(cut &cu
4293  
4294    for (uint object = 0; object != inputCollection->size(); object++){
4295  
4296 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
4296 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4297 >    bool plotDecision = true;
4298  
4299      if(currentCut.inputCollection == inputType){
4300  
# Line 3575 | Line 4306 | void OSUAnalysis::setObjectFlags(cut &cu
4306          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4307  
4308        }
4309 <      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4309 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4310        else{
4311          bool tempDecision = true;
4312          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
# Line 3584 | Line 4315 | void OSUAnalysis::setObjectFlags(cut &cu
4315            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4316              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4317          }
4318 <        decision = tempDecision;
4318 >        cutDecision = tempDecision;
4319        }
4320 +      //invert the cut if this cut is a veto
4321 +      if(currentCut.isVeto) cutDecision = !cutDecision;
4322 +      plotDecision = cutDecision;
4323      }
4324  
4325 <    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4325 >    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4326  
4327 <    //set flags for objects that pass each cut AND all the previous cuts
4328 <    bool previousCumulativeFlag = true;
4327 >    //set flags for objects that pass this cut AND all the previous cuts
4328 >    bool previousCumulativeCutFlag = true;
4329 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4330 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4331 >      else{ previousCumulativeCutFlag = false; break;}
4332 >    }
4333 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4334 >    bool previousCumulativePlotFlag = true;
4335      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4336 <      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4337 <      else{ previousCumulativeFlag = false; break;}
4336 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4337 >      else{ previousCumulativePlotFlag = false; break;}
4338      }
4339 <    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4339 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4340 >
4341 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4342  
4343    }
4344  
4345 < }
4345 > } // end void OSUAnalysis::setObjectFlags
4346  
4347  
4348   template <class InputCollection1, class InputCollection2>
4349 < void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
4350 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
4351 <
4349 > void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags,
4350 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, string inputType){
4351 >  // This function sets the flags for the paired object collection.  
4352 >  // If the cut is applying on the given paired object collection, then the flags for the single object collections are also set.
4353 >  // If not, then the flags for the paired object collection are taken as the AND of the flags for each single object collection.  
4354 >
4355 >  if (verbose_>2) clog << "  Beginning setObjectFlags for cut=" << currentCut.name
4356 >                       << ", inputType=" << inputType
4357 >                       << endl;  
4358  
4359    bool sameObjects = false;
4360 <  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4360 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;  // FIXME:  is sameObjects just the not of isTwoTypesOfObject?  If so, it's redundant.  
4361  
4362    // Get the strings for the two objects that make up the pair.
4363    string obj1Type, obj2Type;
# Line 3621 | Line 4369 | void OSUAnalysis::setObjectFlags(cut &cu
4369    // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4370    if (currentCut.inputCollection == inputType) {
4371      for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4372 <      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
4373 <      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
4372 >      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4373 >      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4374      }
4375      if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4376        for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4377 <        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
4378 <        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
4377 >        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4378 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4379        }
4380      }
4381    }
# Line 3640 | Line 4388 | void OSUAnalysis::setObjectFlags(cut &cu
4388        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4389  
4390  
4391 <      bool decision = true;//object passes if this cut doesn't cut on that type of object
4391 >      bool cutDecision  = true;//object passes if this cut doesn't cut on that type of object
4392 >      bool plotDecision = true;
4393  
4394 +      // Determine whether each pair passes the cut, only if inputCollection is the same as the inputType.  
4395        if(currentCut.inputCollection == inputType){
4396  
4397          vector<bool> subcutDecisions;
4398          for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4399            string stringValue = "";
4400            double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4401 +          if (verbose_>1) clog << currentCut.variables.at(subcutIndex) << " = " << value
4402 +                               << endl;  
4403            if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4404            else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4405          }
4406  
4407 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4407 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4408          else{
4409            bool tempDecision = subcutDecisions.at(0);
4410            for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
# Line 3661 | Line 4413 | void OSUAnalysis::setObjectFlags(cut &cu
4413              else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4414                tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4415            }
4416 <          decision = tempDecision;
4416 >          cutDecision = tempDecision;
4417          }
4418 +        //invert the cut if this cut is a veto
4419 +        if (currentCut.isVeto) cutDecision = !cutDecision;
4420 +        plotDecision = cutDecision;
4421 +
4422 +        if (verbose_>1) clog << " cutDecision = " << cutDecision
4423 +                             << "; for currentCut.inputCollection = " << currentCut.inputCollection
4424 +                             << "; object1 (" << obj1Type << ") = " << object1
4425 +                             << "; object2 (" << obj2Type << ") = " << object2
4426 +                             << endl;  
4427 +        
4428 +        if (cutDecision) {  // only set the flags for the individual objects if the pair object is being cut on
4429 +          individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4430 +          individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4431 +        }
4432 +        if (plotDecision) {  // only set the flags for the individual objects if the pair object is being cut on
4433 +          individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4434 +          individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4435 +        }
4436 +        
4437 +
4438 +      } // if(currentCut.inputCollection == inputType){
4439 +
4440 +      // The individualFlags will be true if the inputCollection is not the same as the inputType.
4441 +      // They are also independent of the previous flags on the single objects.  
4442 +      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));  
4443 +
4444 +
4445 +
4446 +      // ************************************
4447 +      // Determine cumulative flags
4448 +      // ************************************
4449 +      // determine whether this paired object passes this cut AND all previous cuts
4450 +      bool previousCumulativeCutFlag = true;
4451 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4452 +        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4453 +        else{ previousCumulativeCutFlag = false; break;}
4454        }
4455 <      // 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 <      }
4455 >      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4456  
4457 <      //set flags for objects that pass each cut AND all the previous cuts
3676 <      bool previousCumulativeFlag = true;
4457 >      bool previousCumulativePlotFlag = true;
4458        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4459 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
4460 <        else{ previousCumulativeFlag = false; break;}
4459 >        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4460 >        else{ previousCumulativePlotFlag = false; break;}
4461        }
4462 <      //apply flags for the components of the composite object as well
4463 <      bool currentCumulativeFlag = true;
4464 <      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
4465 <      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
4466 <      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
4467 <      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
4468 <      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
4469 <      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4470 <        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);
4471 <        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);
4462 >      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4463 >      
4464 >      // 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.    
4465 >      int cutIdxFlagsObj1 = max(int(currentCutIndex-1),0);
4466 >      int cutIdxFlagsObj2 = max(int(currentCutIndex-1),0);
4467 >      // 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.
4468 >      // 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.  
4469 >      // 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).  
4470 >      if (currentCut.inputCollection != inputType) {  
4471 >        if (currentCut.inputCollection.find(obj1Type)!=string::npos) cutIdxFlagsObj1 = currentCutIndex;
4472 >        if (currentCut.inputCollection.find(obj2Type)!=string::npos) cutIdxFlagsObj2 = currentCutIndex;
4473 >      }  
4474 >      flagPair flags1 = cumulativeFlags.at(obj1Type).at(cutIdxFlagsObj1);  // flag for input collection 1
4475 >      flagPair flags2 = cumulativeFlags.at(obj2Type).at(cutIdxFlagsObj2);  // flag for input collection 2
4476 >      
4477 >      // The cumulative flag is only true if the paired object cumulative flag is true, and if the single object cumulative flags are true.  
4478 >      bool currentCumulativeCutFlag = true;
4479 >      bool currentCumulativePlotFlag = true;
4480 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4481 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4482 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4483 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4484 >
4485 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4486 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4487 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4488 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4489 >
4490 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));  // Set the flag for the paired object
4491 >
4492 >
4493 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // Set the flags for the individual objects if the paired object is being cut on.  
4494 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first  = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4495 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first  = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4496 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4497 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4498 >
4499 >        if (verbose_>1) clog << " previousCumulativeCutFlag for object1 = " << getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object1, "cut") << endl;  
4500 >        if (verbose_>1) clog << " previousCumulativeCutFlag for object2 = " << getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut") << endl;  
4501 >
4502        }
4503 +
4504        counter++;
4505  
4506      } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4507    }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4508  
4509 < }
4509 > } // end void OSUAnalysis::setObjectFlags
4510  
4511  
4512 < bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
4512 > bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4513    // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4514    // all cuts up to currentCutIndex
4515    bool previousCumulativeFlag = true;
4516    for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4517 <    if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
4517 >    bool tempFlag = false;
4518 >    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4519 >    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4520 >
4521 >    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4522      else {
4523        previousCumulativeFlag = false; break;
4524      }
# Line 3711 | Line 4527 | bool OSUAnalysis::getPreviousCumulativeF
4527   }
4528  
4529  
4530 +
4531 +
4532 + template <class InputCollection>
4533 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4534 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4535 +
4536 +  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;
4537 +  for (uint object = 0; object != inputCollection->size(); object++) {
4538 +
4539 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4540 +
4541 +    string inputVariable = parameters.inputVariable;
4542 +    string function = "";
4543 +    string stringValue = "";
4544 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4545 +    BNTreeBranchVals_.at(parameters.name).push_back(value);
4546 +
4547 +  }
4548 + }
4549 +
4550 +
4551   template <class InputCollection>
4552 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4552 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4553 >
4554 >  if (verbose_>2) clog << "  Filling histogram for " << parameters.name << endl;  
4555  
4556    for (uint object = 0; object != inputCollection->size(); object++){
4557  
4558 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4558 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4559  
4560      string currentString = parameters.inputVariables.at(0);
4561      string inputVariable = "";
# Line 3733 | Line 4572 | void OSUAnalysis::fill1DHistogram(TH1* h
4572      string stringValue = "";
4573      double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4574      histo->Fill(value,scaleFactor);
4575 +
4576      if (printEventInfo_) {
4577        // Write information about event to screen, for testing purposes.
4578 <      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
4578 >      clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << " (object number " << object << ")" << endl;
4579      }
4580  
4581    }
4582   }
4583  
4584   template <class InputCollection1, class InputCollection2>
4585 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4585 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2,
4586 >                                  flagPair pairFlags, double scaleFactor){
4587  
4588    bool sameObjects = false;
4589    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
# Line 3754 | Line 4595 | void OSUAnalysis::fill1DHistogram(TH1* h
4595        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4596  
4597        pairCounter++;
4598 <      //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;
4598 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4599  
4600        string currentString = parameters.inputVariables.at(0);
4601        string inputVariable = "";
# Line 3775 | Line 4613 | void OSUAnalysis::fill1DHistogram(TH1* h
4613        double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4614        histo->Fill(value,scaleFactor);
4615  
4616 +      if (printEventInfo_) {
4617 +        // Write information about event to screen, for testing purposes.
4618 +        clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value
4619 +             << " (object1 number " << object1 << "), "
4620 +             << " (object2 number " << object2 << ")"
4621 +             << endl;
4622 +      }
4623 +      
4624      }
4625    }
4626  
# Line 3782 | Line 4628 | void OSUAnalysis::fill1DHistogram(TH1* h
4628  
4629  
4630   template <class InputCollection>
4631 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4631 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4632  
4633    for (uint object = 0; object != inputCollection->size(); object++){
4634  
4635 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4635 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4636  
4637      string stringValue = "";
4638      string currentString = parameters.inputVariables.at(0);
# Line 3823 | Line 4669 | void OSUAnalysis::fill2DHistogram(TH2* h
4669   }
4670  
4671   template <class InputCollection1, class InputCollection2>
4672 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4672 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2,
4673 >                                  flagPair pairFlags, double scaleFactor){
4674  
4675    bool sameObjects = false;
4676    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
# Line 3836 | Line 4683 | void OSUAnalysis::fill2DHistogram(TH2* h
4683  
4684        pairCounter++;
4685  
4686 <      //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;
4686 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4687  
4688        string stringValue = "";
4689        string currentString = parameters.inputVariables.at(0);
# Line 3887 | Line 4731 | int OSUAnalysis::getGenMatchedParticleIn
4731  
4732      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4733      if(currentDeltaR > 0.05) continue;
4734 <    //     cout << setprecision(3) << setw(20)
4734 >    //     clog << setprecision(3) << setw(20)
4735      //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4736      //          << setw(20)
4737      //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
# Line 3906 | Line 4750 | int OSUAnalysis::getGenMatchedParticleIn
4750      }
4751  
4752    }
4753 <  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4754 <  //   else cout << "no match found..." << endl;
4753 >  //   if(bestMatchDeltaR != 999)  clog << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4754 >  //   else clog << "no match found..." << endl;
4755    return bestMatchIndex;
4756  
4757   }
# Line 3999 | Line 4843 | OSUAnalysis::chosenVertex ()
4843   {
4844    const BNprimaryvertex *chosenVertex = 0;
4845    if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4846 <    vector<bool> vertexFlags;
4846 >    flagPair vertexFlags;
4847      for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4848        if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4849          vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
# Line 4007 | Line 4851 | OSUAnalysis::chosenVertex ()
4851        }
4852      }
4853      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4854 <      if(!vertexFlags.at(vertexIndex)) continue;
4854 >      if(!vertexFlags.at(vertexIndex).first) continue;
4855        chosenVertex = & primaryvertexs->at(vertexIndex);
4856        break;
4857      }
# Line 4023 | Line 4867 | OSUAnalysis::chosenMET ()
4867   {
4868    const BNmet *chosenMET = 0;
4869    if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4870 <    vector<bool> metFlags;
4870 >    flagPair metFlags;
4871      for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4872        if (cumulativeFlags.at("mets").at(i).size()){
4873          metFlags = cumulativeFlags.at("mets").at(i);
# Line 4031 | Line 4875 | OSUAnalysis::chosenMET ()
4875        }
4876      }
4877      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4878 <      if(!metFlags.at(metIndex)) continue;
4878 >      if(!metFlags.at(metIndex).first) continue;
4879        chosenMET = & mets->at(metIndex);
4880        break;
4881      }
# Line 4047 | Line 4891 | OSUAnalysis::chosenElectron ()
4891   {
4892    const BNelectron *chosenElectron = 0;
4893    if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4894 <    vector<bool> electronFlags;
4894 >    flagPair electronFlags;
4895      for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4896        if (cumulativeFlags.at("electrons").at(i).size()){
4897          electronFlags = cumulativeFlags.at("electrons").at(i);
# Line 4055 | Line 4899 | OSUAnalysis::chosenElectron ()
4899        }
4900      }
4901      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4902 <      if(!electronFlags.at(electronIndex)) continue;
4902 >      if(!electronFlags.at(electronIndex).first) continue;
4903        chosenElectron = & electrons->at(electronIndex);
4904        break;
4905      }
# Line 4066 | Line 4910 | OSUAnalysis::chosenElectron ()
4910    return chosenElectron;
4911   }
4912  
4913 +
4914   const BNmuon *
4915   OSUAnalysis::chosenMuon ()
4916   {
4917    const BNmuon *chosenMuon = 0;
4918    if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4919 <    vector<bool> muonFlags;
4919 >    flagPair muonFlags;
4920      for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4921        if (cumulativeFlags.at("muons").at(i).size()){
4922          muonFlags = cumulativeFlags.at("muons").at(i);
# Line 4079 | Line 4924 | OSUAnalysis::chosenMuon ()
4924        }
4925      }
4926      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4927 <      if(!muonFlags.at(muonIndex)) continue;
4927 >      if(!muonFlags.at(muonIndex).first) continue;
4928        chosenMuon = & muons->at(muonIndex);
4929        break;
4930      }
# Line 4090 | Line 4935 | OSUAnalysis::chosenMuon ()
4935    return chosenMuon;
4936   }
4937  
4938 + double
4939 + OSUAnalysis::chosenHT ()
4940 + {
4941 +  double chosenHT = 0.0;
4942 +  if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
4943 +    flagPair jetFlags;
4944 +    for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
4945 +      if (cumulativeFlags.at("jets").at(i).size()){
4946 +        jetFlags = cumulativeFlags.at("jets").at(i);
4947 +        break;
4948 +      }
4949 +    }
4950 +    for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
4951 +      if(!jetFlags.at(jetIndex).first) continue;
4952 +      chosenHT += jets->at(jetIndex).pt;
4953 +    }
4954 +  }
4955 +
4956 +  return chosenHT;
4957 + }
4958 +
4959 + pair<const BNmuon *, const BNmuon *>
4960 + OSUAnalysis::leadMuonPair ()
4961 + {
4962 +  pair<const BNmuon *, const BNmuon *> leadMuonPair;
4963 +  leadMuonPair.first = leadMuonPair.second = 0;
4964 +
4965 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4966 +    flagPair muonFlags;
4967 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4968 +      if (cumulativeFlags.at("muons").at(i).size()){
4969 +        muonFlags = cumulativeFlags.at("muons").at(i);
4970 +        break;
4971 +      }
4972 +    }
4973 +    for (uint muonIndex0 = 0; muonIndex0 != muonFlags.size(); muonIndex0++){
4974 +      if(!muonFlags.at(muonIndex0).first) continue;
4975 +      for (uint muonIndex1 = muonIndex0 + 1; muonIndex1 < muonFlags.size(); muonIndex1++){
4976 +        if(!muonFlags.at(muonIndex1).first) continue;
4977 +        const BNmuon *mu0 = & muons->at(muonIndex0);
4978 +        const BNmuon *mu1 = & muons->at(muonIndex1);
4979 +        if(leadMuonPair.first == 0 || leadMuonPair.second == 0){
4980 +          leadMuonPair.first = mu0;
4981 +          leadMuonPair.second = mu1;
4982 +        }
4983 +        else{
4984 +          TVector2 newPt0 (mu0->px, mu0->py),
4985 +                   newPt1 (mu1->px, mu1->py),
4986 +                   oldPt0 (leadMuonPair.first->px, leadMuonPair.first->py),
4987 +                   oldPt1 (leadMuonPair.second->px, leadMuonPair.second->py);
4988 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
4989 +            {
4990 +              leadMuonPair.first = mu0;
4991 +              leadMuonPair.second = mu1;
4992 +            }
4993 +        }
4994 +      }
4995 +    }
4996 +  }
4997 +
4998 +  return leadMuonPair;
4999 + }
5000 +
5001 + pair<const BNelectron *, const BNelectron *>
5002 + OSUAnalysis::leadElectronPair ()
5003 + {
5004 +  pair<const BNelectron *, const BNelectron *> leadElectronPair;
5005 +  leadElectronPair.first = leadElectronPair.second = 0;
5006 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
5007 +    flagPair electronFlags;
5008 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
5009 +      if (cumulativeFlags.at("electrons").at(i).size()){
5010 +        electronFlags = cumulativeFlags.at("electrons").at(i);
5011 +        break;
5012 +      }
5013 +    }
5014 +    for (uint electronIndex0 = 0; electronIndex0 != electronFlags.size(); electronIndex0++){
5015 +      if(!electronFlags.at(electronIndex0).first) continue;
5016 +      for (uint electronIndex1 = electronIndex0 + 1; electronIndex1 < electronFlags.size(); electronIndex1++){
5017 +        if(!electronFlags.at(electronIndex1).first) continue;
5018 +        const BNelectron *el0 = & electrons->at(electronIndex0);
5019 +        const BNelectron *el1 = & electrons->at(electronIndex1);
5020 +        if(leadElectronPair.first == 0 || leadElectronPair.second == 0){
5021 +          leadElectronPair.first = el0;
5022 +          leadElectronPair.second = el1;
5023 +        }
5024 +        else{
5025 +          TVector2 newPt0 (el0->px, el0->py),
5026 +                   newPt1 (el1->px, el1->py),
5027 +                   oldPt0 (leadElectronPair.first->px, leadElectronPair.first->py),
5028 +                   oldPt1 (leadElectronPair.second->px, leadElectronPair.second->py);
5029 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
5030 +            {
5031 +              leadElectronPair.first = el0;
5032 +              leadElectronPair.second = el1;
5033 +            }
5034 +        }
5035 +      }
5036 +    }
5037 +  }
5038 +
5039 +  return leadElectronPair;
5040 + }
5041 +
5042   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines