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.73 by lantonel, Thu May 30 18:09:58 2013 UTC vs.
Revision 1.111 by wulsin, Thu Jul 25 12:24:27 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 58 | Line 69 | OSUAnalysis::OSUAnalysis (const edm::Par
69    //always get vertex collection so we can assign the primary vertex in the event
70    objectsToGet.push_back("primaryvertexs");
71    objectsToPlot.push_back("primaryvertexs");
72 <  objectsToCut.push_back("primaryvertexs");
72 >  objectsToFlag.push_back("primaryvertexs");
73  
74  
75    //always get the MC particles to do GEN-matching
# 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 <
155 <
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 128 | 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 139 | 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 154 | 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 209 | 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;
# Line 236 | Line 284 | OSUAnalysis::OSUAnalysis (const edm::Par
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 247 | 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 265 | 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 274 | 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 286 | 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 312 | 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 320 | 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 336 | 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 350 | 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 370 | 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 >      BNTrees_.back()->Branch("event_runInt",  &BNTreeBranchVals_runInt_,  "event_runInt/I");      
452 >      BNTrees_.back()->Branch("event_lumiInt", &BNTreeBranchVals_lumiInt_, "event_lumiInt/I");      
453 >      BNTrees_.back()->Branch("event_evtLong", &BNTreeBranchVals_evtLong_, "event_evtLong/L");      
454 >      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
455 >        BranchSpecs currentVar = treeBranches_.at(iBranch);
456 >        vector<float> newVec;
457 >        BNTreeBranchVals_[currentVar.name] = newVec;
458 >        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
459 >      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
460 >    }
461 >
462      //book all histograms included in the configuration
463      for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
464 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
465 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
466 <      int numBinsElements = currentHistogram.bins.size();
467 <      int numInputVariables = currentHistogram.inputVariables.size();
468 <      int numBinEdgesX = currentHistogram.variableBinsX.size();
469 <      int numBinEdgesY = currentHistogram.variableBinsY.size();
470 <
471 <      if(numBinsElements == 1){
472 <        if(numBinEdgesX > 1){
473 <          if(numBinEdgesY > 1)
474 <            numBinsElements = 6;
464 >
465 >      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
466 >
467 >        histogram currentHistogram = histograms.at(currentHistogramIndex);
468 >        int numBinsElements = currentHistogram.bins.size();
469 >        int numInputVariables = currentHistogram.inputVariables.size();
470 >        int numBinEdgesX = currentHistogram.variableBinsX.size();
471 >        int numBinEdgesY = currentHistogram.variableBinsY.size();
472 >
473 >        if(numBinsElements == 1){
474 >          if(numBinEdgesX > 1){
475 >            if(numBinEdgesY > 1)
476 >              numBinsElements = 6;
477 >            else
478 >              numBinsElements = 3;
479 >          }
480 >        }
481 >        if(numBinsElements != 3 && numBinsElements !=6){
482 >          clog << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
483 >          exit(0);
484 >        }
485 >        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
486 >          clog << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
487 >          exit(0);
488 >        }
489 >        else if(numBinsElements == 3){
490 >          if (currentHistogram.bins.size () == 3)
491 >            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));
492            else
493 <            numBinsElements = 3;
493 >            {
494 >              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
495 >            }
496          }
497 <      }
498 <      if(numBinsElements != 3 && numBinsElements !=6){
499 <        cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
500 <        exit(0);
501 <      }
502 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
503 <        cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
504 <        exit(0);
505 <      }
506 <      else if(numBinsElements == 3){
507 <        if (currentHistogram.bins.size () == 3)
508 <          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));
509 <        else
510 <          {
511 <            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
497 >        else if(numBinsElements == 6){
498 >          if (currentHistogram.bins.size () == 6)
499 >            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));
500 >          else
501 >            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 ());
502 >        }
503 >
504 >
505 >        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
506 >
507 >        // bin      particle type
508 >        // ---      -------------
509 >        //  0        unmatched
510 >        //  1        u
511 >        //  2        d
512 >        //  3        s
513 >        //  4        c
514 >        //  5        b
515 >        //  6        t
516 >        //  7        e
517 >        //  8        mu
518 >        //  9        tau
519 >        // 10        nu
520 >        // 11        g
521 >        // 12        gamma
522 >        // 13        Z
523 >        // 14        W
524 >        // 15        light meson
525 >        // 16        K meson
526 >        // 17        D meson
527 >        // 18        B meson
528 >        // 19        light baryon
529 >        // 20        strange baryon
530 >        // 21        charm baryon
531 >        // 22        bottom baryon
532 >        // 23        QCD string
533 >        // 24        other
534 >
535 >        vector<TString> labelArray;
536 >        labelArray.push_back("unmatched");
537 >        labelArray.push_back("u");
538 >        labelArray.push_back("d");
539 >        labelArray.push_back("s");
540 >        labelArray.push_back("c");
541 >        labelArray.push_back("b");
542 >        labelArray.push_back("t");
543 >        labelArray.push_back("e");
544 >        labelArray.push_back("#mu");
545 >        labelArray.push_back("#tau");
546 >        labelArray.push_back("#nu");
547 >        labelArray.push_back("g");
548 >        labelArray.push_back("#gamma");
549 >        labelArray.push_back("Z");
550 >        labelArray.push_back("W");
551 >        labelArray.push_back("light meson");
552 >        labelArray.push_back("K meson");
553 >        labelArray.push_back("D meson");
554 >        labelArray.push_back("B meson");
555 >        labelArray.push_back("light baryon");
556 >        labelArray.push_back("strange baryon");
557 >        labelArray.push_back("charm baryon");
558 >        labelArray.push_back("bottom baryon");
559 >        labelArray.push_back("QCD string");
560 >        labelArray.push_back("other");
561 >
562 >        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
563 >          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
564 >            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
565            }
566 <      }
567 <      else if(numBinsElements == 6){
568 <        if (currentHistogram.bins.size () == 6)
569 <          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));
570 <        else
571 <          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 ());
572 <      }
566 >          else {
567 >            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
568 >            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
569 >          }
570 >        }
571 >        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
572 >          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
573 >          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
574 >        }
575  
576 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
577  
415      if(currentHistogram.name.find("GenMatch")==string::npos) continue;
578  
579 <      // bin      particle type
580 <      // ---      -------------
581 <      //  0        unmatched
582 <      //  1        u
583 <      //  2        d
584 <      //  3        s
585 <      //  4        c
586 <      //  5        b
587 <      //  6        t
588 <      //  7        e
589 <      //  8        mu
590 <      //  9        tau
591 <      // 10        nu
592 <      // 11        g
593 <      // 12        gamma
594 <      // 13        Z
595 <      // 14        W
596 <      // 15        light meson
597 <      // 16        K meson
598 <      // 17        D meson
599 <      // 18        B meson
600 <      // 19        light baryon
601 <      // 20        strange baryon
602 <      // 21        charm baryon
603 <      // 22        bottom baryon
604 <      // 23        QCD string
605 <      // 24        other
606 <
607 <      vector<TString> labelArray;
608 <      labelArray.push_back("unmatched");
609 <      labelArray.push_back("u");
610 <      labelArray.push_back("d");
611 <      labelArray.push_back("s");
612 <      labelArray.push_back("c");
613 <      labelArray.push_back("b");
614 <      labelArray.push_back("t");
615 <      labelArray.push_back("e");
616 <      labelArray.push_back("#mu");
617 <      labelArray.push_back("#tau");
618 <      labelArray.push_back("#nu");
619 <      labelArray.push_back("g");
620 <      labelArray.push_back("#gamma");
621 <      labelArray.push_back("Z");
622 <      labelArray.push_back("W");
623 <      labelArray.push_back("light meson");
624 <      labelArray.push_back("K meson");
625 <      labelArray.push_back("D meson");
626 <      labelArray.push_back("B meson");
627 <      labelArray.push_back("light baryon");
628 <      labelArray.push_back("strange baryon");
629 <      labelArray.push_back("charm baryon");
630 <      labelArray.push_back("bottom baryon");
631 <      labelArray.push_back("QCD string");
632 <      labelArray.push_back("other");
633 <
634 <      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
635 <        if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
636 <          oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
637 <        }
638 <        else {
639 <          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
640 <          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
641 <        }
642 <      }
643 <      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
644 <        twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
645 <        twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
646 <      }
647 <
648 <    }
649 <
650 <    // Book a histogram for the number of each object type to be plotted.
651 <    // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
652 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
653 <      string currentObject = objectsToPlot.at(currentObjectIndex);
654 <      int maxNum = 10;
655 <      if(currentObject == "mcparticles") maxNum = 50;
656 <      else if(currentObject == "primaryvertexs") maxNum = 50;
657 <
658 <      if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
659 <      else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
660 <      else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
661 <      else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
662 <      else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
663 <      else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
502 <      else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
503 <      else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
504 <      else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
505 <      else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
506 <      else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
507 <      else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
508 <      else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
509 <      else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
510 <      else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
511 <      else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
512 <      else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
513 <      else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
514 <      else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
515 <
516 <      currentObject.at(0) = toupper(currentObject.at(0));
517 <      string histoName = "num" + currentObject;
518 <
519 <      if(histoName == "numPrimaryvertexs"){
520 <        string newHistoName = histoName + "BeforePileupCorrection";
521 <        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);
522 <        newHistoName = histoName + "AfterPileupCorrection";
523 <        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);
579 >      // Book a histogram for the number of each object type to be plotted.
580 >      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
581 >      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
582 >        string currentObject = objectsToPlot.at(currentObjectIndex);
583 >        int maxNum = 10;
584 >        if(currentObject == "mcparticles") maxNum = 50;
585 >        else if(currentObject == "primaryvertexs") maxNum = 50;
586 >
587 >        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
588 >        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
589 >        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
590 >        else if(currentObject == "electron-photon pairs")     currentObject = "electronPhotonPairs";
591 >        else if(currentObject == "muon-photon pairs")         currentObject = "muonPhotonPairs";
592 >        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
593 >        else if(currentObject == "secondary photons")            currentObject = "secondaryPhotons";
594 >        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
595 >        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
596 >        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
597 >        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
598 >        else if(currentObject == "muon-event pairs")            currentObject = "muonEventPairs";
599 >        else if(currentObject == "photon-jet pairs")            currentObject = "photonJetPairs";
600 >        else if(currentObject == "met-jet pairs")             currentObject = "metJetPairs";
601 >        else if(currentObject == "track-jet pairs")           currentObject = "trackJetPairs";
602 >        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
603 >        else if(currentObject == "muon-secondary photon pairs")  currentObject = "muonSecondaryPhotonPairs";
604 >        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
605 >        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
606 >        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
607 >        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
608 >        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
609 >        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
610 >        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
611 >        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
612 >        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
613 >        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
614 >        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
615 >        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
616 >        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
617 >        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
618 >
619 >        currentObject.at(0) = toupper(currentObject.at(0));
620 >        string histoName = "num" + currentObject;
621 >
622 >        if(histoName == "numPrimaryvertexs"){
623 >          string newHistoName = histoName + "BeforePileupCorrection";
624 >          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);
625 >          newHistoName = histoName + "AfterPileupCorrection";
626 >          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);
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 >
632 >      if (verbose_) {
633 >        clog << "List of 1D histograms booked for channel " << channelName << " and directory " << currentDir << ":" << endl;
634 >        for(map<string, TH1D*>::iterator
635 >              iter = oneDHists_.at(currentChannel).at(currentDir).begin();
636 >            iter  != oneDHists_.at(currentChannel).at(currentDir).end();
637 >            iter++) {
638 >          clog << " " << iter->first
639 >               << ":  name=" << iter->second->GetName()
640 >               << ", title=" << iter->second->GetTitle()
641 >               << ", bins=(" << iter->second->GetNbinsX()
642 >               << "," << iter->second->GetXaxis()->GetXmin()
643 >               << "," << iter->second->GetXaxis()->GetXmax()
644 >               << ")" << endl;
645 >        }  
646 >        clog << "List of 2D histograms booked for channel " << channelName << " and directory " << currentDir << ":" << endl;
647 >        for(map<string, TH2D*>::iterator
648 >              iter = twoDHists_.at(currentChannel).at(currentDir).begin();
649 >            iter  != twoDHists_.at(currentChannel).at(currentDir).end();
650 >            iter++) {
651 >          clog << " " << iter->first
652 >               << ":  name=" << iter->second->GetName()
653 >               << ", title=" << iter->second->GetTitle()
654 >               << ", binsX=(" << iter->second->GetNbinsX()
655 >               << "," << iter->second->GetXaxis()->GetXmin()
656 >               << "," << iter->second->GetXaxis()->GetXmax()
657 >               << ")"
658 >               << ", binsY=(" << iter->second->GetNbinsY()
659 >               << "," << iter->second->GetYaxis()->GetXmin()
660 >               << "," << iter->second->GetYaxis()->GetXmax()
661 >               << ")"
662 >               << endl;
663 >        }  
664        }
665 <      else
666 <        oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
527 <    }
528 <   }//end of loop over directories
665 >
666 >    }//end of loop over directories
667      channels.push_back(tempChannel);
668      tempChannel.cuts.clear();
669    }//end loop over channels
670  
671  
672 +  // Create the cutflow histogram and fill with 0 weight, in case no events are found in the input file.  
673 +  for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
674 +    channel currentChannel = channels.at(currentChannelIndex);
675 +    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
676 +      cutFlows_.at(currentChannelIndex)->at("trigger") = true;  
677 +    }
678 +    for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
679 +      cut currentCut = currentChannel.cuts.at(currentCutIndex);
680 +      cutFlows_.at(currentChannelIndex)->at (currentCut.name) = true;
681 +    }
682 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(0);  // fill cutflow with 0 weight, just to create the cutflow histograms  
683 +  }
684 +
685    //make unique vector of objects we need to get from the event
686    sort( objectsToGet.begin(), objectsToGet.end() );
687    objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
688    //make unique vector of objects we need to cut on
689    sort( objectsToCut.begin(), objectsToCut.end() );
690    objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
691 +  //make unique vector of objects we need to set flags for
692 +  sort( objectsToFlag.begin(), objectsToFlag.end() );
693 +  objectsToFlag.erase( unique( objectsToFlag.begin(), objectsToFlag.end() ), objectsToFlag.end() );
694  
695 +  // 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.  
696 +  for (uint i=0; i<objectsToFlag.size(); i++) {
697 +    if (objectsToFlag.at(i).find("pairs")!=string::npos) { // if it contains "pairs"
698 +      objectsToFlag.push_back(objectsToFlag.at(i));  
699 +      objectsToFlag.erase(objectsToFlag.begin()+i);  
700 +    }
701 +  }
702 +
703 +  if (verbose_) {
704 +    clog << "List of channels:" << endl;
705 +    for (uint i=0; i<channels.size(); i++) {
706 +      clog << " " << channels.at(i).name << endl;
707 +    }
708 +    clog << "List of objects to get:" << endl;
709 +    for (uint i=0; i<objectsToGet.size(); i++) {
710 +      clog << " " << objectsToGet.at(i) << endl;
711 +    }
712 +    clog << "List of objects to plot:" << endl;
713 +    for (uint i=0; i<objectsToPlot.size(); i++) {
714 +      clog << " " << objectsToPlot.at(i) << endl;
715 +    }
716 +    clog << "List of objects to cut:" << endl;
717 +    for (uint i=0; i<objectsToCut.size(); i++) {
718 +      clog << " " << objectsToCut.at(i) << endl;
719 +    }
720 +    clog << "List of objects to flag:" << endl;
721 +    for (uint i=0; i<objectsToFlag.size(); i++) {
722 +      clog << " " << objectsToFlag.at(i) << endl;
723 +    }
724 +  }
725 +
726 +  produces<map<string, bool> > ("channelDecisions");
727 +
728 +  if (printEventInfo_) {
729 +    findEventsLog = new ofstream();  
730 +    findEventsLog->open("findEvents.txt");  
731 +    clog << "Listing run:lumi:event in file findEvents.txt for events that pass full selection (of any channel)." << endl;  
732 +  } else {
733 +    findEventsLog = 0;
734 +  }  
735 +
736 +  isFirstEvent_ = true;  
737 +
738 +  if (verbose_) clog << "Finished OSUAnalysis::OSUAnalysis constructor." << endl;  
739 +
740 +
741 +  } // end constructor OSUAnalysis::OSUAnalysis()
742  
542 }
743  
744   OSUAnalysis::~OSUAnalysis ()
745   {
746 +
747 +  if (verbose_) clog << "Beginning OSUAnalysis::OSUAnalysis destructor." << endl;  
748 +
749    // Destroying the CutFlow objects causes the cut flow numbers and time
750    // information to be printed to standard output.
751    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
752      delete cutFlows_.at(currentChannel);
753    }
754 +
755 +  if (printEventInfo_ && findEventsLog) findEventsLog->close();  
756 +
757 +  clog << "=============================================" << endl;  
758 +  clog << "Successfully completed OSUAnalysis." << endl;  
759 +  clog << "=============================================" << endl;  
760 +
761 +  if (verbose_) clog << "Finished OSUAnalysis::OSUAnalysis destructor." << endl;  
762 +
763   }
764  
765   void
766 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
766 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
767   {
556
768    // Retrieve necessary collections from the event.
769  
770 +  if (verbose_) clog << "Beginning OSUAnalysis::produce." << endl;  
771 +
772    if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
773      event.getByLabel (triggers_, triggers);
774  
# Line 619 | Line 832 | OSUAnalysis::analyze (const edm::Event &
832    //get pile-up event weight
833    if (doPileupReweighting_ && datasetType_ != "data") {
834      //for "data" datasets, the numTruePV is always set to -1
835 <    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;  
836 <    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);  
835 >    if (events->at(0).numTruePV < 0 && isFirstEvent_) clog << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
836 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
837    }
838  
839    stopCTauScaleFactor_ = 1.0;
# Line 630 | Line 843 | OSUAnalysis::analyze (const edm::Event &
843  
844    //loop over all channels
845  
846 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
847    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
848      channel currentChannel = channels.at(currentChannelIndex);
849 +    if (verbose_>1) clog << " Processing channel " << currentChannel.name << endl;
850  
851      flagMap individualFlags;
852      counterMap passingCounter;
853      cumulativeFlags.clear ();
854  
855 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
856 +         iter != BNTreeBranchVals_.end(); iter++) {
857 +      iter->second.clear();  // clear array
858 +    }
859 +
860      bool triggerDecision = true;
861      if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
862        triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
# Line 646 | Line 866 | OSUAnalysis::analyze (const edm::Event &
866      //loop over all cuts
867      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
868        cut currentCut = currentChannel.cuts.at(currentCutIndex);
869 <      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
870 <        string currentObject = objectsToCut.at(currentObjectIndex);
869 >      if (verbose_>2) clog << "  Processing cut, index: " << currentCutIndex << ", input collection: " << currentCut.inputCollection << ", name: " << currentCut.name << endl;  
870 >
871 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
872 >        string currentObject = objectsToFlag.at(currentObjectIndex);
873  
874          //initialize maps to get ready to set cuts
875 <        individualFlags[currentObject].push_back (vector<bool> ());
876 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
875 >        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
876 >        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
877  
878        }
657      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
658        string currentObject = objectsToCut.at(currentObjectIndex);
659
660        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
661
879  
880 <        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
881 <        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
882 <        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
883 <        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
880 >      //set flags for all relevant objects
881 >      for(int currentObjectIndex = -1; currentObjectIndex != int(objectsToFlag.size()); currentObjectIndex++){
882 >        string currentObject;  
883 >        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.  
884 >        else currentObject = objectsToFlag.at(currentObjectIndex);
885 >        if (currentObjectIndex >= 0 && currentObject == currentCut.inputCollection) continue;  // Flags have already been set for the inputCollection object, so should not be set again.  
886 >
887 >        // single object collections
888 >        if     (currentObject == "jets")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
889 >        else if(currentObject == "secondary jets")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
890 >        else if(currentObject == "secondary photons")   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"secondary photons");
891 >        else if(currentObject == "muons")               setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
892 >        else if(currentObject == "secondary muons")     setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
893          else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
894 <        else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
895 <        else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
896 <        else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
897 <        else if(currentObject == "mets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
898 <        else if(currentObject == "tracks") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
899 <        else if(currentObject == "genjets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
900 <        else if(currentObject == "mcparticles") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
901 <        else if(currentObject == "primaryvertexs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
902 <        else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
903 <        else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
904 <        else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
905 <        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
906 <
907 <
908 <
909 <        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
910 <                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
911 <                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
912 <                                                                   "muon-muon pairs");
913 <
914 <        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
915 <                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
916 <                                                                   cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
917 <                                                                   "muon-secondary muon pairs");
918 <
919 <        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
920 <                                                                   cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
921 <                                                                   cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
922 <                                                                   "electron-secondary electron pairs");
923 <
924 <        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
925 <                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
926 <                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
927 <                                                                           "electron-electron pairs");
928 <        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
929 <                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
930 <                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
931 <                                                                       "electron-muon pairs");
932 <        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
933 <                                                                           cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
934 <                                                                           cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
935 <                                                                           "jet-jet pairs");
936 <        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
937 <                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
712 <                                                                       cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
713 <                                                                       "electron-jet pairs");
714 <        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
715 <                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
716 <                                                                       cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
717 <                                                                       "muon-jet pairs");
718 <        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
719 <                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
720 <                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
721 <                                                                     "track-event pairs");
722 <        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
723 <                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
724 <                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
725 <                                                                        "electron-track pairs");
726 <        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
727 <                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
728 <                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
729 <                                                                    "muon-track pairs");
730 <        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
731 <                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
732 <                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
733 <                                                                  "muon-tau pairs");
734 <        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
735 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
736 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
737 <                                                                 "tau-tau pairs");
738 <        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
739 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
740 <                                                                 cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
741 <                                                                 "tau-track pairs");
742 <        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
743 <                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
744 <                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
745 <                                                                          "electron-trigobj pairs");
746 <        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
747 <                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
748 <                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
749 <                                                                      "muon-trigobj pairs");
894 >        else if(currentObject == "electrons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
895 >        else if(currentObject == "events")              setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
896 >        else if(currentObject == "taus")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
897 >        else if(currentObject == "mets")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
898 >        else if(currentObject == "tracks")              setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
899 >        else if(currentObject == "genjets")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
900 >        else if(currentObject == "mcparticles")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
901 >        else if(currentObject == "primaryvertexs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
902 >        else if(currentObject == "bxlumis")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
903 >        else if(currentObject == "photons")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
904 >        else if(currentObject == "superclusters")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
905 >        else if(currentObject == "trigobjs")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
906 >
907 >
908 >        // paired object collections  
909 >        else if(currentObject == "muon-muon pairs")                   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), "muon-muon pairs");
910 >        else if(currentObject == "muon-secondary muon pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), "muon-secondary muon pairs");
911 >
912 >        else if(currentObject == "muon-secondary photon pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), "muon-secondary photon pairs");
913 >        else if(currentObject == "muon-secondary jet pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), "muon-secondary jet pairs");
914 >        else if(currentObject == "photon-secondary jet pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), "photon-secondary jet pairs");
915 >        else if(currentObject == "electron-secondary jet pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), "electron-secondary jet pairs");
916 >        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), "electron-secondary electron pairs");
917 >
918 >        else if(currentObject == "electron-electron pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), "electron-electron pairs");
919 >        else if(currentObject == "electron-muon pairs")     setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), "electron-muon pairs");
920 >        else if(currentObject == "jet-jet pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), "jet-jet pairs");
921 >        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), "jet-secondary jet pairs");
922 >        else if(currentObject == "electron-jet pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), "electron-jet pairs");
923 >        else if(currentObject == "electron-photon pairs")   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), "electron-photon pairs");
924 >        else if(currentObject == "photon-jet pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), "photon-jet pairs");
925 >        else if(currentObject == "muon-jet pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), "muon-jet pairs");
926 >        else if(currentObject == "muon-event pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),events.product(), "muon-event pairs");
927 >        else if(currentObject == "met-jet pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),jets.product(), "met-jet pairs");
928 >        else if(currentObject == "track-jet pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),jets.product(), "track-jet pairs");
929 >        else if(currentObject == "muon-photon pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), "muon-photon pairs");
930 >        else if(currentObject == "track-event pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(), "track-event pairs");
931 >        else if(currentObject == "electron-track pairs")    setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),"electron-track pairs");
932 >        else if(currentObject == "muon-track pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),"muon-track pairs");
933 >        else if(currentObject == "muon-tau pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),"muon-tau pairs");
934 >        else if(currentObject == "tau-tau pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),"tau-tau pairs");
935 >        else if(currentObject == "tau-track pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),"tau-track pairs");
936 >        else if(currentObject == "electron-trigobj pairs")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),"electron-trigobj pairs");
937 >        else if(currentObject == "muon-trigobj pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),"muon-trigobj pairs");
938  
939          if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
940        }
941  
942 +    }//end loop over all cuts
943  
944  
756    }//end loop over all cuts
757    //use cumulative flags to apply cuts at event level
945  
946 +    //use cumulative flags to apply cuts at event level
947 +    vector<bool> eventPassedPreviousCuts;    //a vector to store cumulative cut descisions after each cut.
948      bool eventPassedAllCuts = true;
949 <    //a vector to store cumulative cut descisions after each cut.
761 <    vector<bool> eventPassedPreviousCuts;
762 <    //apply trigger (true if none were specified)
763 <    eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
764 <
949 >    eventPassedAllCuts = eventPassedAllCuts && triggerDecision;    //apply trigger (true if none were specified)
950  
951      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
952  
953        //loop over all objects and count how many passed the cumulative selection up to this point
954        cut currentCut = currentChannel.cuts.at(currentCutIndex);
955        int numberPassing = 0;
956 +      int numberPassingPrev = 0;  // number of objects that pass cuts up to the previous one
957  
958        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
959 <        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
959 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
960 >      }
961 >      bool cutDecision;
962 >      if (!currentCut.isVeto) {
963 >        cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
964 >      } else {
965 >        int prevCutIndex = currentCutIndex - 1;
966 >        if (prevCutIndex<0) {
967 >          numberPassingPrev = cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size();  // count all objects in collection if cut is the first
968 >        } else {
969 >          for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(prevCutIndex).size() ; object++){
970 >            if (cumulativeFlags.at(currentCut.inputCollection).at(prevCutIndex).at(object).first) {
971 >              numberPassingPrev++;
972 >              if (verbose_>1) clog << " object passed previous cut" << endl;  
973 >            }
974 >          }  
975 >        }  
976 >        int numberFailCut = numberPassingPrev - numberPassing;
977 >        cutDecision = evaluateComparison(numberFailCut,currentCut.eventComparativeOperator,currentCut.numberRequired);  
978        }
979 <      bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
979 >
980        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
981        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
982        eventPassedPreviousCuts.push_back(eventPassedAllCuts);
983 +      if (verbose_>1) clog << " Event passed cuts up to cut index " << currentCutIndex << endl;  
984 +
985      }
986 +    //applying all appropriate scale factors
987      double scaleFactor = masterScaleFactor;
988 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
989  
782    muonScaleFactor_ = electronScaleFactor_ = 1.0;
990      if(applyLeptonSF_ && datasetType_ != "data"){
991 <      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
992 <        vector<bool> muonFlags;
991 >      //only apply SFs if we've cut on this object
992 >      if(find(objectsToCut.begin(),objectsToCut.end(),"muons") != objectsToCut.end ()){
993 >        flagPair muonFlags;
994 >        //get the last valid flags in the flag map
995          for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
996            if (cumulativeFlags.at("muons").at(i).size()){
997              muonFlags = cumulativeFlags.at("muons").at(i);
998              break;
999            }
1000          }
1001 +        //apply the weight for each of those objects
1002          for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
1003 <          if(!muonFlags.at(muonIndex)) continue;
1003 >          if(!muonFlags.at(muonIndex).second) continue;
1004            muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
1005          }
1006        }
1007 <      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
1008 <        vector<bool> electronFlags;
1007 >      //only apply SFs if we've cut on this object
1008 >      if(find(objectsToCut.begin(),objectsToCut.end(),"electrons") != objectsToCut.end ()){
1009 >        flagPair electronFlags;
1010 >        //get the last valid flags in the flag map
1011          for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
1012            if (cumulativeFlags.at("electrons").at(i).size()){
1013              electronFlags = cumulativeFlags.at("electrons").at(i);
1014              break;
1015            }
1016          }
1017 +        //apply the weight for each of those objects
1018          for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
1019 <          if(!electronFlags.at(electronIndex)) continue;
1019 >          if(!electronFlags.at(electronIndex).second) continue;
1020            electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
1021          }
1022        }
1023      }
1024 +    if(applyBtagSF_ && datasetType_ != "data"){
1025 +      //only apply SFs if we've cut on this object
1026 +      if(find(objectsToCut.begin(),objectsToCut.end(),"jets") != objectsToCut.end ()){
1027 +        flagPair jetFlags;
1028 +        vector<double> jetSFs;
1029 +        //get the last valid flags in the flag map
1030 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
1031 +          if (cumulativeFlags.at("jets").at(i).size()){
1032 +            jetFlags = cumulativeFlags.at("jets").at(i);
1033 +            break;
1034 +          }
1035 +        }
1036 +        //apply the weight for each of those objects
1037 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
1038 +          if(!jetFlags.at(jetIndex).second) continue;
1039 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour, jets->at(jetIndex).eta);
1040 +          jetSFs.push_back(jetSFTmp);
1041 +        }
1042 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_);
1043 +      }
1044 +    }
1045      scaleFactor *= muonScaleFactor_;
1046      scaleFactor *= electronScaleFactor_;
1047 <
1047 >    scaleFactor *= bTagScaleFactor_;
1048      cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
1049 +    if (verbose_>1) clog << " Scale factors applied:  "
1050 +                         << " muonScaleFactor_ = " << muonScaleFactor_
1051 +                         << ", electronScaleFactor_ = " << electronScaleFactor_
1052 +                         << ", bTagScaleFactor_ = " << bTagScaleFactor_
1053 +                         << ", total scale factor = " << scaleFactor
1054 +                         << endl;  
1055  
1056  
1057 <    if (printEventInfo_) {
1057 >    if (printEventInfo_ && eventPassedAllCuts) {
1058        // Write information about event to screen, for testing purposes.
1059 <      cout << "Event passed all cuts in channel " <<  currentChannel.name
1060 <           << ": run="  << events->at(0).run
1061 <           << "  lumi=" << events->at(0).lumi
1062 <           << "  event=" << events->at(0).evt
1059 >      clog << "Event passed all cuts in channel " <<  currentChannel.name
1060 >           << ":  run:lumi:evt=  "  << events->at(0).run
1061 >           << ":" << events->at(0).lumi
1062 >           << ":" << events->at(0).evt
1063             << endl;
1064 <    }
1064 >      if (findEventsLog) {
1065 >        (*findEventsLog) << events->at(0).run
1066 >                         << ":" << events->at(0).lumi
1067 >                         << ":" << events->at(0).evt << endl;
1068 >      }
1069  
1070 +    }
1071  
1072  
1073      //filling histograms
1074 <    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
1074 >    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.
1075 >
1076 >      if (verbose_>2) clog << "  Filling histograms for currentcut = " << currentCut << endl;  
1077  
1078        uint currentDir;
1079 <      if(!GetPlotsAfterEachCut_){ currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size();}//if GetPlotsAfterEachCut_ is true, set currentDir point to the last cut.
1080 <      else currentDir = currentCut;
1079 >      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
1080 >      else{
1081 >        currentDir = currentCut;
1082 >      }
1083  
835      if(!eventPassedPreviousCuts.at(currentDir)) continue;
1084  
1085 +      if(eventPassedPreviousCuts.at(currentDir)){
1086  
1087 <      for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1088 <        histogram currentHistogram = histograms.at(histogramIndex);
1087 >        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1088 >          histogram currentHistogram = histograms.at(histogramIndex);
1089  
1090 <        if(currentHistogram.inputVariables.size() == 1){
1091 <          TH1D* histo;
1092 <          histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1093 <
1094 <          if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1095 <          else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1096 <          else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1097 <          else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1098 <          else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1099 <          else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1100 <                                                                                         cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1101 <                                                                                         cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1102 <          else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1103 <                                                                                                   cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1104 <                                                                                                   cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1105 <          else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1106 <          else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1107 <                                                                                                 cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1108 <                                                                                                 cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1109 <          else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1110 <                                                                                       cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1111 <                                                                                       cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1112 <          else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1113 <                                                                                                           cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1114 <                                                                                                           cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1115 <          else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
1116 <                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
1117 <                                                                                             cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1118 <          else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
1119 <                                                                                            cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1120 <                                                                                            cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1121 <          else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
1122 <                                                                                        cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1123 <                                                                                        cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1124 <          else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1125 <                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1126 <                                                                                              cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1127 <          else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1128 <                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1129 <                                                                                          cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1130 <          else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1131 <                                                                                        cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1132 <                                                                                        cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1133 <          else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1134 <                                                                                       cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1135 <                                                                                       cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1136 <          else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1137 <                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
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("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1141 <                                                                                                cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1142 <          else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1143 <                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1144 <                                                                                            cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1145 <          
1146 <          else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1147 <          else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1148 <          else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1149 <          else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1150 <          else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1151 <          else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1152 <          else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1153 <          else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1154 <          else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1155 <          else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1156 <          else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1157 <          else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1158 <        }
1159 <        else if(currentHistogram.inputVariables.size() == 2){
1160 <          TH2D* histo;
1161 <          histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1162 <
1163 <          if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1164 <          else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1165 <          else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1166 <          else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1167 <          else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1168 <                                                                                         cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1169 <                                                                                         cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1170 <          else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1171 <                                                                                                   cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1172 <                                                                                                   cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1173 <          else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1174 <          else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1175 <          else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1176 <                                                                                                 cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1177 <                                                                                                 cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1178 <          else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1179 <                                                                                       cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1180 <                                                                                       cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1181 <          else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1182 <                                                                                                           cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1183 <                                                                                                           cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1184 <          else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1185 <                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
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("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1189 <                                                                                            cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1190 <          else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1191 <                                                                                        cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1192 <                                                                                        cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1193 <          else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1194 <                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1195 <                                                                                              cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1196 <          else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1197 <                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1198 <                                                                                          cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1199 <          else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1200 <                                                                                        cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1201 <                                                                                        cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1202 <          else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1203 <                                                                                       cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1204 <                                                                                       cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1205 <          else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1206 <                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1207 <                                                                                         cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1208 <          else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1209 <                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1210 <                                                                                                cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1211 <          else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1212 <                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1213 <                                                                                            cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1214 <          else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1215 <          else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1216 <          else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1217 <          else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1218 <          else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1219 <                                                                                           cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1220 <                                                                                           cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1221 <          else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1222 <          else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1223 <          else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1224 <          else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1225 <          else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1226 <          else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1227 <          else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1228 <          else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1229 <        }
1230 <      }
1090 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) clog << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
1091 >
1092 >          if (verbose_>1) clog << " Filling histogram " << currentHistogram.name << " for collection " << currentHistogram.inputCollection << endl;  
1093 >
1094 >          if(currentHistogram.inputVariables.size() == 1){
1095 >            TH1D* histo;
1096 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1097 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1098 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1099 >            else if(currentHistogram.inputCollection == "secondary photons")  fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1100 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1101 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1102 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1103 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1104 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1105 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1106 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1107 >             else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1108 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1109 >             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1110 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1111 >             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1112 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1113 >             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1114 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1115 >
1116 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1117 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1118 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1119 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1120 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1121 >             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1122 >                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1123 >
1124 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1125 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1126 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(),
1127 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1128 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(),
1129 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1130 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(),
1131 >                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1132 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(),
1133 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1134 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill1DHistogram(histo,currentHistogram, muons.product(),events.product(),
1135 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1136 >            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, mets.product(),jets.product(),
1137 >                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1138 >            else if(currentHistogram.inputCollection == "track-jet pairs")  fill1DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1139 >                                                                                          cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1140 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(),
1141 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1142 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(),
1143 >                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1144 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1145 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1146 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1147 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1148 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1149 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1150 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1151 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1152 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1153 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1154 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1155 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1156 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1157 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1158 >
1159 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1160 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1161 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1162 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1163 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1164 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1165 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1166 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1167 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1168 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1169 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1170 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1171 >          }
1172 >          else if(currentHistogram.inputVariables.size() == 2){
1173 >            TH2D* histo;
1174 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1175 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1176 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1177 >            else if(currentHistogram.inputCollection == "secondary photons")  fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1178 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1179 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1180 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1181 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1182 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1183 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1184 >            else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1185 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1186 >            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1187 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1188 >            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1189 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1190 >            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1191 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1192 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1193 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1194 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1195 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1196 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1197 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1198 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1199 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1200 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(),
1201 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1202 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1203 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1204 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(),
1205 >                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1206 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1207 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1208 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill2DHistogram(histo,currentHistogram,muons.product(),events.product(),
1209 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1210 >            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,mets.product(),jets.product(),
1211 >                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1212 >            else if(currentHistogram.inputCollection == "track-jet pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1213 >                                                                                         cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1214 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1215 >                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1216 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1217 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1218 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1219 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1220 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1221 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1222 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1223 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1224 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1225 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1226 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1227 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1228 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1229 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1230 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1231 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1232 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1233 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1234 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1235 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1236 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1237 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1238 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1239 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1240 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1241 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1242 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1243 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1244 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1245 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1246 >          }
1247  
1248 <      //fills histograms with the sizes of collections
1248 >        }
1249  
985      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
986        
987        string currentObject = objectsToPlot.at(currentObjectIndex);
988        string objectToPlot = "";
989        
990        // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
991        if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
992        else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
993        else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
994        else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
995        else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
996        else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
997        else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
998        else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
999        else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1000        else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1001        else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1002        else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1003        else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1004        else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1005        else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1006        else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1007        else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1008        else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1009        else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1010        else objectToPlot = currentObject;
1011        
1012        string tempCurrentObject = objectToPlot;
1013        tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1014        string histoName = "num" + tempCurrentObject;
1015        
1250  
1251 <        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1251 >        //fills histograms with the sizes of collections
1252 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1253  
1254 <        //count the number of objects passing all cuts
1255 <        int numToPlot = 0;
1021 <        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1022 <          if(lastCutFlags.at(currentFlag)) numToPlot++;
1023 <        }
1254 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1255 >          string objectToPlot = "";
1256  
1257 <        if(objectToPlot == "primaryvertexs"){
1258 <          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1259 <          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1260 <        }
1261 <        else {
1262 <          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1263 <        }
1264 <      } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1257 >          if (verbose_) clog << "Filling histogram of number of selected objects in collection: " << currentObject << endl;  
1258 >
1259 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1260 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1261 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1262 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1263 >          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1264 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1265 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1266 >          else if(currentObject == "muon-event pairs")                   objectToPlot = "muonEventPairs";
1267 >          else if(currentObject == "muon-photon pairs")                  objectToPlot = "muonPhotonPairs";
1268 >          else if(currentObject == "photon-jet pairs")                   objectToPlot = "photonJetPairs";
1269 >          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1270 >          else if(currentObject == "track-jet pairs")                    objectToPlot = "trackJetPairs";
1271 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1272 >          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1273 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1274 >          else if(currentObject == "secondary photons")                  objectToPlot = "secondaryPhotons";
1275 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1276 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1277 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1278 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1279 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1280 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1281 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1282 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1283 >          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1284 >          else if(currentObject == "muon-secondary photon pairs")        objectToPlot = "muonSecondaryJetPairs";
1285 >          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1286 >          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1287 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1288 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1289 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1290 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1291 >          else objectToPlot = currentObject;
1292 >
1293 >          string tempCurrentObject = objectToPlot;
1294 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1295 >          string histoName = "num" + tempCurrentObject;
1296 >
1297 >
1298 >          if(find(objectsToPlot.begin(), objectsToPlot.end(), currentObject) != objectsToPlot.end()) {
1299 >            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1300 >            int numToPlot = 0;
1301 >            for (uint iObj = 0; iObj != lastCutFlags.size(); iObj++){  // loop over all the objects  
1302 >              if(lastCutFlags.at(iObj).second) {
1303 >                numToPlot++;  
1304 >                if (verbose_>3) clog << "   Found object " << iObj << " in collection " << currentObject << " to plot." << endl;
1305 >              }
1306 >            }
1307 >
1308 >            if(objectToPlot == "primaryvertexs"){
1309 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1310 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1311 >            }
1312 >            else {
1313 >              if (printEventInfo_) clog << "Number of selected " << objectToPlot << " to plot:  " << numToPlot << endl;  
1314 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1315 >            }
1316 >          }
1317 >
1318 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1319 >
1320 >
1321 >      } // end if(eventPassedPreviousCuts.at(currentDir))
1322 >    } // end loop over cuts
1323 >
1324 >    if (!useEDMFormat_ && eventPassedAllCuts){
1325 >      // Assign BNTree variables
1326 >      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1327 >        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1328 >        string coll = brSpecs.inputCollection;
1329 >        if (cumulativeFlags.count(coll) == 0) clog << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1330 >
1331 >        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1332 >        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1333 >        else if(coll == "secondary photons")      assignTreeBranch(brSpecs,photons.product(),          cumulativeFlags.at(coll).back());
1334 >        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1335 >        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1336 >        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1337 >        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1338 >        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1339 >        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1340 >        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1341 >        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1342 >        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1343 >        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1344 >        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1345 >        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1346 >        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1347 >        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1348 >        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1349 >        else if(coll == "stops"
1350 >                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1351 >      } // end loop over branches
1352 >      // set the evtLong, runInt, and lumiInt variables separately, since they are not type float  
1353 >      BNTreeBranchVals_evtLong_ = events->at(0).evt;
1354 >      BNTreeBranchVals_runInt_  = events->at(0).run;
1355 >      BNTreeBranchVals_lumiInt_ = events->at(0).lumi;
1356 >
1357 >      if (!BNTrees_.at(currentChannelIndex)) { clog << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1358 >      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1359      }
1360  
1361 <  } //end loop over channel
1361 >    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1362 >
1363 >  } // end loop over channel
1364  
1365    masterCutFlow_->fillCutFlow(masterScaleFactor);
1366  
1367 < } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1367 >  event.put (channelDecisions, "channelDecisions");
1368 >
1369 >  isFirstEvent_ = false;  
1370 >
1371 >  if (verbose_) clog << "Finished OSUAnalysis::produce." << endl;  
1372 >
1373 > } // end void OSUAnalysis::produce (const edm::Event &event, const edm::EventSetup &setup)
1374  
1375  
1376  
# Line 1051 | Line 1385 | OSUAnalysis::evaluateComparison (double
1385    else if(comparison == "==") return testValue == cutValue;
1386    else if(comparison == "=") return testValue == cutValue;
1387    else if(comparison == "!=") return testValue != cutValue;
1388 <  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1388 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1389  
1390   }
1391  
# Line 1064 | Line 1398 | OSUAnalysis::evaluateComparison (string
1398    else if(comparison == "<")  return testValue <  cutValue;
1399    else if(comparison == "<=") return testValue <= cutValue;
1400    else if(comparison == "==") return testValue == cutValue;
1401 <  else if(comparison == "=") return testValue == cutValue;
1401 >  else if(comparison == "=")  return testValue == cutValue;
1402    else if(comparison == "!=") return testValue != cutValue;
1403 <  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1403 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1404  
1405   }
1406  
# Line 1076 | Line 1410 | OSUAnalysis::evaluateTriggers (vector<st
1410    //initialize to false until a chosen trigger is passed
1411    bool triggerDecision = false;
1412  
1413 +  if (printAllTriggers_) clog << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1414    //loop over all triggers defined in the event
1415    for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1416  
1417 +    if (printAllTriggers_) clog << "   " << trigger->name << endl;
1418 +
1419      //we're only interested in triggers that actually passed
1420      if(trigger->pass != 1) continue;
1421  
# Line 1089 | Line 1426 | OSUAnalysis::evaluateTriggers (vector<st
1426      //if the event passes one of the chosen triggers, set triggerDecision to true
1427      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1428        if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1429 <    }  
1429 >    }
1430    }
1431 <  //if none of the veto triggers fired:
1431 >
1432 >  printAllTriggers_ = false;  // only print triggers once, not every event
1433 >
1434 >  //if none of the veto triggers fired:
1435    //return the OR of all the chosen triggers
1436    if (triggersToTest.size() != 0) return triggerDecision;
1437    //or if no triggers were defined return true
# Line 1260 | Line 1600 | OSUAnalysis::valueLookup (const BNjet* o
1600    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1601    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1602  
1603 +  //user defined variable
1604 +  else if(variable == "disappTrkLeadingJetID") {
1605 +    value = object->pt > 110
1606 +      && fabs(object->eta) < 2.4
1607 +      && object->chargedHadronEnergyFraction > 0.2
1608 +      && object->neutralHadronEnergyFraction < 0.7
1609 +      && object->chargedEmEnergyFraction < 0.5
1610 +      && object->neutralEmEnergyFraction < 0.7;
1611 +  }
1612 +
1613 +  else if(variable == "disappTrkSubLeadingJetID") {
1614 +    value = object->pt > 30
1615 +      && fabs(object->eta) < 4.5
1616 +      && object->neutralHadronEnergyFraction < 0.7
1617 +      && object->chargedEmEnergyFraction < 0.5;
1618 +  }
1619 +
1620 +  else if(variable == "dPhiMet") {
1621 +    if (const BNmet *met = chosenMET ()) {
1622 +      value = deltaPhi (object->phi, met->phi);
1623 +    } else value = -999;
1624 +  }
1625 +
1626  
1627 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1627 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1628  
1629    value = applyFunction(function, value);
1630  
1631    return value;
1632 < }
1632 > } // end jet valueLookup
1633  
1634  
1635   //!muon valueLookup
# Line 1363 | Line 1726 | OSUAnalysis::valueLookup (const BNmuon*
1726    else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1727    else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1728    else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1729 +  else if(variable == "chargedHadronIsoDR04") value = object->chargedHadronIsoDR04;
1730 +  else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1731 +  else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1732 +  else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1733    else if(variable == "rhoPrime") value = object->rhoPrime;
1734    else if(variable == "AEffDr03") value = object->AEffDr03;
1735    else if(variable == "AEffDr04") value = object->AEffDr04;
# Line 1370 | Line 1737 | OSUAnalysis::valueLookup (const BNmuon*
1737    else if(variable == "pfIsoR03SumNeutralHadronEt") value = object->pfIsoR03SumNeutralHadronEt;
1738    else if(variable == "pfIsoR03SumPhotonEt") value = object->pfIsoR03SumPhotonEt;
1739    else if(variable == "pfIsoR03SumPUPt") value = object->pfIsoR03SumPUPt;
1740 +  else if(variable == "relpfIsoR04SumExceptChargedHad") value = (object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)/ object->pt;
1741 +  else if(variable == "relpfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt/object->pt;
1742 +  else if(variable == "relpfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt/object->pt;
1743 +  else if(variable == "relpfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt/object->pt;
1744 +  else if(variable == "relpfIsoR04SumPUPt") value = object->pfIsoR04SumPUPt/object->pt;
1745    else if(variable == "pfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt;
1746    else if(variable == "pfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt;
1747    else if(variable == "pfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt;
# Line 1426 | Line 1798 | OSUAnalysis::valueLookup (const BNmuon*
1798    else if(variable == "time_ndof") value = object->time_ndof;
1799  
1800    //user-defined variables
1801 +  else if(variable == "looseID") {
1802 +    value = object->pt > 10 &&
1803 +      (object->isGlobalMuon  > 0 ||
1804 +       object->isTrackerMuon > 0);
1805 +  }
1806    else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1807    else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1808    else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1809    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1810 +  else if(variable == "relPFdBetaIsoPseudo") value = (object->pfIsoR04SumChargedHadronPt + object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt) / object->pt;
1811    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1812    else if(variable == "metMT") {
1813      if (const BNmet *met = chosenMET ())
# Line 1553 | Line 1931 | OSUAnalysis::valueLookup (const BNmuon*
1931      value = object->isGlobalMuon > 0                \
1932        && object->isPFMuon > 0                        \
1933        && object->normalizedChi2 < 10                \
1934 <                                  && object->numberOfValidMuonHits > 0        \
1934 >      && object->numberOfValidMuonHits > 0        \
1935        && object->numberOfMatchedStations > 1        \
1936        && fabs(object->correctedD0Vertex) < 0.2        \
1937        && fabs(object->correctedDZ) < 0.5        \
# Line 1564 | Line 1942 | OSUAnalysis::valueLookup (const BNmuon*
1942      value = object->isGlobalMuon > 0                \
1943        && object->isPFMuon > 0                        \
1944        && object->normalizedChi2 < 10                \
1945 <                                  && object->numberOfValidMuonHits > 0        \
1945 >      && object->numberOfValidMuonHits > 0        \
1946        && object->numberOfMatchedStations > 1        \
1947        && object->numberOfValidPixelHits > 0        \
1948        && object->numberOfLayersWithMeasurement > 5;
# Line 1619 | Line 1997 | OSUAnalysis::valueLookup (const BNmuon*
1997      d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1998      dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1999      value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2000 <         || fabs (object->correctedD0Vertex / d0Error) > 99.0
2001 <         || fabs (object->correctedDZ / dzError) > 99.0;
2000 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2001 >      || fabs (object->correctedDZ / dzError) > 99.0;
2002      value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
2003    }
2004  
2005  
2006  
2007 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2007 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2008  
2009    value = applyFunction(function, value);
2010  
2011    return value;
2012 < }
2012 > } // end muon valueLookup
2013 >
2014  
2015   //!electron valueLookup
2016   double
# Line 1800 | Line 2179 | OSUAnalysis::valueLookup (const BNelectr
2179    else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2180    else if(variable == "detIso") value = (object->trackIso) / object->pt;
2181    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2182 +  else if(variable == "relPFrhoIsoEB") value = object->isEB ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2183 +  else if(variable == "relPFrhoIsoEE") value = object->isEE ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2184    else if(variable == "metMT") {
2185      if (const BNmet *met = chosenMET ())
2186        {
# Line 1871 | Line 2252 | OSUAnalysis::valueLookup (const BNelectr
2252      else value = -999;
2253    }
2254  
2255 +  else if(variable == "looseID"){
2256 +    if (object->isEB)
2257 +      {
2258 +        value = fabs(object->delEtaIn) < 0.007 \
2259 +          && fabs (object->delPhiIn) < 0.15 \
2260 +          && object->scSigmaIEtaIEta < 0.01 \
2261 +          && object->hadOverEm < 0.12 \
2262 +          && fabs (object->correctedD0Vertex) < 0.02 \
2263 +          && fabs (object->correctedDZ) < 0.2 \
2264 +          && object->absInvEMinusInvPin < 0.05 \
2265 +          && object->passConvVeto;
2266 +      }
2267 +    else
2268 +      {
2269 +        value = fabs(object->delEtaIn) < 0.009 \
2270 +          && fabs (object->delPhiIn) < 0.10 \
2271 +          && object->scSigmaIEtaIEta < 0.03 \
2272 +          && object->hadOverEm < 0.10 \
2273 +          && fabs (object->correctedD0Vertex) < 0.02 \
2274 +          && fabs (object->correctedDZ) < 0.2 \
2275 +          && object->absInvEMinusInvPin < 0.05 \
2276 +          && object->passConvVeto;
2277 +      }
2278 +  }
2279 +
2280    else if(variable == "tightID"){
2281      if (object->isEB)
2282        {
# Line 1896 | Line 2302 | OSUAnalysis::valueLookup (const BNelectr
2302        }
2303    }
2304  
2305 +  else if(variable == "looseID_MVA"){
2306 +    value = object->pt > 10
2307 +      && object->mvaNonTrigV0 > 0;
2308 +      }
2309    else if(variable == "correctedD0VertexInEBPositiveCharge"){
2310      if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2311      else value = -999;
# Line 2019 | Line 2429 | OSUAnalysis::valueLookup (const BNelectr
2429      d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2430      dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2431      value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2432 <         || fabs (object->correctedD0Vertex / d0Error) > 99.0
2433 <         || fabs (object->correctedDZ / dzError) > 99.0;
2432 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2433 >      || fabs (object->correctedDZ / dzError) > 99.0;
2434      value = !value;
2435    }
2436  
2437  
2438  
2439 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2439 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2440  
2441    value = applyFunction(function, value);
2442  
2443    return value;
2444 < }
2444 > } // end electron valueLookup
2445 >
2446  
2447   //!event valueLookup
2448   double
# Line 2043 | Line 2454 | OSUAnalysis::valueLookup (const BNevent*
2454    else if(variable == "pthat") value = object->pthat;
2455    else if(variable == "qScale") value = object->qScale;
2456    else if(variable == "alphaQCD") value = object->alphaQCD;
2457 +  else if(variable == "Ht") value = getHt(jets.product());
2458    else if(variable == "alphaQED") value = object->alphaQED;
2459    else if(variable == "scalePDF") value = object->scalePDF;
2460    else if(variable == "x1") value = object->x1;
# Line 2112 | Line 2524 | OSUAnalysis::valueLookup (const BNevent*
2524    else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2525    else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2526    else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2527 <
2528 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2527 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2528 >  else if(variable == "ht") value = chosenHT ();
2529 >  else if(variable == "leadMuPairInvMass"){
2530 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2531 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2532 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2533 >    value = (p0 + p1).M ();
2534 >  }
2535 >  else if(variable == "leadMuPairPt"){
2536 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2537 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2538 >             pt1 (muPair.second->px, muPair.second->py);
2539 >    pt0 += pt1;
2540 >    value = pt0.Mod ();
2541 >  }
2542 >  else if(variable == "leadElPairInvMass"){
2543 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2544 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2545 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2546 >    value = (p0 + p1).M ();
2547 >  }
2548 >  else if(variable == "leadElPairPt"){
2549 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2550 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2551 >             pt1 (muPair.second->px, muPair.second->py);
2552 >    pt0 += pt1;
2553 >    value = pt0.Mod ();
2554 >  }
2555 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2556  
2557    value = applyFunction(function, value);
2558  
2559    return value;
2560 < }
2560 > } // end event valueLookup
2561 >
2562  
2563   //!tau valueLookup
2564   double
# Line 2166 | Line 2606 | OSUAnalysis::valueLookup (const BNtau* o
2606    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2607    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2608  
2609 <
2609 >  else if (variable == "looseHadronicID") {
2610 >    value = object->pt > 10
2611 >      && object->eta < 2.3
2612 >      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2613 >      && object->HPSdecayModeFinding > 0
2614 >      && object->HPSagainstElectronLoose > 0
2615 >      && object->HPSagainstMuonTight > 0;
2616 >  }
2617  
2618    else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2619  
# Line 2213 | Line 2660 | OSUAnalysis::valueLookup (const BNtau* o
2660    }
2661  
2662  
2663 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2663 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2664  
2665    value = applyFunction(function, value);
2666  
2667    return value;
2668 < }
2668 > } // end tau valueLookup
2669 >
2670  
2671   //!met valueLookup
2672   double
# Line 2286 | Line 2734 | OSUAnalysis::valueLookup (const BNmet* o
2734    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2735    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2736  
2737 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2737 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2738  
2739    value = applyFunction(function, value);
2740  
2741    return value;
2742 < }
2742 > } // end met valueLookup
2743 >
2744  
2745   //!track valueLookup
2746   double
# Line 2319 | Line 2768 | OSUAnalysis::valueLookup (const BNtrack*
2768    else if(variable == "numValidHits") value = object->numValidHits;
2769    else if(variable == "isHighPurity") value = object->isHighPurity;
2770  
2322
2771    //additional BNs info for disappTrks
2772 <  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2773 <  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2774 <  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2775 <  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2776 <  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2777 <  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2778 <  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2779 <  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2332 <  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2772 >  else if(variable == "caloEMDeltaRp3")     value = object->caloEMDeltaRp3;
2773 >  else if(variable == "caloHadDeltaRp3")    value = object->caloHadDeltaRp3;
2774 >  else if(variable == "caloEMDeltaRp4")     value = object->caloEMDeltaRp4;
2775 >  else if(variable == "caloHadDeltaRp4")    value = object->caloHadDeltaRp4;
2776 >  else if(variable == "caloEMDeltaRp5")     value = object->caloEMDeltaRp5;
2777 >  else if(variable == "caloHadDeltaRp5")    value = object->caloHadDeltaRp5;
2778 >  else if(variable == "nHitsMissingOuter")  value = object->nHitsMissingOuter;
2779 >  else if(variable == "nHitsMissingInner")  value = object->nHitsMissingInner;
2780    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2781 <  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2781 >  else if(variable == "depTrkRp3")          value = object->depTrkRp3;
2782 >  else if(variable == "trkRelIsoRp3")       value = (object->depTrkRp3 - object->pt) / object->pt;
2783 >  else if(variable == "trkRelIsoRp5")       value = (object->depTrkRp5 - object->pt) / object->pt;
2784 >  else if(variable == "depEcalRp3")         value = object->depEcalRp3;
2785 >  else if(variable == "depHcalRp3")         value = object->depHcalRp3;
2786 >  else if(variable == "depHoRp3")           value = object->depHoRp3;
2787 >  else if(variable == "nTracksRp3")         value = object->nTracksRp3;
2788 >  else if(variable == "trackerVetoPtRp3")   value = object->trackerVetoPtRp3;
2789 >  else if(variable == "emVetoEtRp3")        value = object->emVetoEtRp3;
2790 >  else if(variable == "hadVetoEtRp3")       value = object->hadVetoEtRp3;
2791 >  else if(variable == "hoVetoEtRp3")        value = object->hoVetoEtRp3;
2792 >  else if(variable == "depTrkRp5")          value = object->depTrkRp5;
2793 >  else if(variable == "depEcalRp5")         value = object->depEcalRp5;
2794 >  else if(variable == "depHcalRp5")         value = object->depHcalRp5;
2795 >  else if(variable == "depHoRp5")           value = object->depHoRp5;
2796 >  else if(variable == "nTracksRp5")         value = object->nTracksRp5;
2797 >  else if(variable == "trackerVetoPtRp5")   value = object->trackerVetoPtRp5;
2798 >  else if(variable == "emVetoEtRp5")        value = object->emVetoEtRp5;
2799 >  else if(variable == "hadVetoEtRp5")       value = object->hadVetoEtRp5;
2800 >  else if(variable == "hoVetoEtRp5")        value = object->hoVetoEtRp5;
2801  
2802    //user defined variables
2803    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;
2804    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2805 <  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2805 >  else if(variable == "depTrkRp5MinusPt"){
2806 >    if ( (object->depTrkRp5 - object->pt) < 0 ) {
2807 > //       clog << "Warning:  found track with depTrkRp5 < pt:  depTrkRp5=" << object->depTrkRp5
2808 > //         << "; pt=" << object->pt
2809 > //         << "; object->depTrkRp5 - object->pt = " << object->depTrkRp5 - object->pt
2810 > //         << endl;  
2811 >           value = 0;
2812 >         }
2813 >         else value =  (object->depTrkRp5 - object->pt);
2814 >  }
2815 >  else if(variable == "depTrkRp3MinusPt"){
2816 >    if ( (object->depTrkRp3 - object->pt) < 0 ) {
2817 >      value = 0;
2818 >    }
2819 >    else value =  (object->depTrkRp3 - object->pt);
2820 >  }
2821 >
2822 >  else if(variable == "dPhiMet") {
2823 >    if (const BNmet *met = chosenMET ()) {
2824 >      value = deltaPhi (object->phi, met->phi);
2825 >    } else value = -999;
2826 >  }
2827 >  
2828 >  
2829    else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2830    else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2831    else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2832    else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2833 +  else if(variable == "depTrkRp5RhoCorr")           value = getTrkDepTrkRp5RhoCorr(object);
2834 +  else if(variable == "depTrkRp3RhoCorr")           value = getTrkDepTrkRp3RhoCorr(object);
2835 +
2836 +  else if(variable == "depTrkRp5MinusPtRhoCorr")    {
2837 +    if ( (getTrkDepTrkRp5RhoCorr(object) - object->pt) < 0 ) value = 0;
2838 +    else {value = (getTrkDepTrkRp5RhoCorr(object) - object->pt );}
2839 +  }
2840 +  
2841 +  else if(variable == "depTrkRp3MinusPtRhoCorr")    
2842 +    {
2843 +      if ( (getTrkDepTrkRp3RhoCorr(object) - object->pt) < 0 ) value = 0;
2844 +      else {value = (getTrkDepTrkRp3RhoCorr(object) - object->pt );}
2845 +    }
2846 +
2847    else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2848    else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2849    else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
# Line 2364 | Line 2867 | OSUAnalysis::valueLookup (const BNtrack*
2867        pt = object->pt;
2868      value = vz - (vx * px + vy * py)/pt * (pz/pt);
2869    }
2870 +
2871 +  else if(variable == "deltaRMinSubLeadJet") {
2872 +    // calculate minimum deltaR between track and any other subleading jet  
2873 +    double trkJetDeltaRMin = 99.;  
2874 +    for (uint ijet = 0; ijet<jets->size(); ijet++) {
2875 +      string empty = "";  
2876 +      double isSubLeadingJet = valueLookup(&jets->at(ijet), "disappTrkSubLeadingJetID", "", empty);  
2877 +      if (!isSubLeadingJet) continue;  // only consider jets that pass the subleading jet ID criteria  
2878 +      double jetEta = valueLookup(&jets->at(ijet), "eta", "", empty);
2879 +      double jetPhi = valueLookup(&jets->at(ijet), "phi", "", empty);
2880 +      double trkJetDeltaR = deltaR(object->eta, object->phi, jetEta, jetPhi);  
2881 +      if (trkJetDeltaR < trkJetDeltaRMin) trkJetDeltaRMin = trkJetDeltaR;
2882 +    }
2883 +    value = trkJetDeltaRMin;  
2884 +  }  
2885 +  
2886    else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2887  
2888    else if(variable == "genMatchedPdgId"){
# Line 2411 | Line 2930 | OSUAnalysis::valueLookup (const BNtrack*
2930  
2931  
2932  
2933 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2933 >  else{clog << "WARNING: invalid variable '" << variable << "' for BNtrack collection.\n"; value = -999;}
2934  
2935    value = applyFunction(function, value);
2936  
2937    return value;
2938 < }
2938 > } // end track valueLookup
2939 >
2940  
2941   //!genjet valueLookup
2942   double
# Line 2440 | Line 2960 | OSUAnalysis::valueLookup (const BNgenjet
2960    else if(variable == "charge") value = object->charge;
2961  
2962  
2963 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2963 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2964  
2965    value = applyFunction(function, value);
2966  
# Line 2574 | Line 3094 | OSUAnalysis::valueLookup (const BNmcpart
3094    }
3095  
3096  
3097 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3097 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3098  
3099    value = applyFunction(function, value);
3100  
3101    return value;
3102 < }
3102 > } // end mcparticle valueLookup
3103 >
3104  
3105   //!primaryvertex valueLookup
3106   double
# Line 2602 | Line 3123 | OSUAnalysis::valueLookup (const BNprimar
3123    else if(variable == "isGood") value = object->isGood;
3124  
3125  
3126 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3126 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3127  
3128    value = applyFunction(function, value);
3129  
# Line 2620 | Line 3141 | OSUAnalysis::valueLookup (const BNbxlumi
3141    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
3142  
3143  
3144 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3144 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3145  
3146    value = applyFunction(function, value);
3147  
# Line 2753 | Line 3274 | OSUAnalysis::valueLookup (const BNphoton
3274    }
3275  
3276  
3277 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3277 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3278  
3279    value = applyFunction(function, value);
3280  
3281    return value;
3282 < }
3282 > } // end photon valueLookup
3283 >
3284  
3285   //!supercluster valueLookup
3286   double
# Line 2776 | Line 3298 | OSUAnalysis::valueLookup (const BNsuperc
3298    else if(variable == "theta") value = object->theta;
3299  
3300  
3301 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3301 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3302  
3303    value = applyFunction(function, value);
3304  
# Line 2810 | Line 3332 | OSUAnalysis::valueLookup (const BNtrigob
3332        stringValue = "none";  // stringValue should only be empty if value is filled
3333    }
3334  
3335 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3335 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3336  
3337    value = applyFunction(function, value);
3338  
# Line 2881 | Line 3403 | OSUAnalysis::valueLookup (const BNmuon*
3403        value = object2->correctedD0;
3404      }
3405  
3406 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3406 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3407 >
3408 >  value = applyFunction(function, value);
3409 >
3410 >  return value;
3411 > } // end muon-muon pair valueLookup
3412 >
3413 >
3414 > //!muon-photon pair valueLookup
3415 > double
3416 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3417 >
3418 >  double value = 0.0;
3419 >
3420 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3421 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3422 >  else if(variable == "photonEta") value = object2->eta;
3423 >  else if(variable == "photonPt") value = object2->pt;
3424 >  else if(variable == "muonEta") value = object1->eta;
3425 >  else if(variable == "photonPhi") value = object2->phi;
3426 >  else if(variable == "muonPhi") value = object1->phi;
3427 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3428 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3429 >  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3430 >  else if(variable == "invMass"){
3431 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3432 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3433 >    value = (fourVector1 + fourVector2).M();
3434 >  }
3435 >  else if(variable == "pt"){
3436 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3437 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3438 >    value = (fourVector1 + fourVector2).Pt();
3439 >  }
3440 >  else if(variable == "threeDAngle")
3441 >    {
3442 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3443 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3444 >      value = (threeVector1.Angle(threeVector2));
3445 >    }
3446 >  else if(variable == "alpha")
3447 >    {
3448 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3449 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3450 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3451 >      value = (pi-threeVector1.Angle(threeVector2));
3452 >    }
3453 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3454 >
3455 >  value = applyFunction(function, value);
3456 >
3457 >  return value;
3458 > }
3459 >
3460 > //!electron-photon pair valueLookup
3461 > double
3462 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3463 >
3464 >  double value = 0.0;
3465 >
3466 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3467 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3468 >  else if(variable == "photonEta") value = object2->eta;
3469 >  else if(variable == "photonPt") value = object2->pt;
3470 >  else if(variable == "electronEta") value = object1->eta;
3471 >  else if(variable == "photonPhi") value = object2->phi;
3472 >  else if(variable == "electronPhi") value = object1->phi;
3473 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3474 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3475 >  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3476 >  else if(variable == "invMass"){
3477 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3478 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3479 >    value = (fourVector1 + fourVector2).M();
3480 >  }
3481 >  else if(variable == "pt"){
3482 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3483 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3484 >    value = (fourVector1 + fourVector2).Pt();
3485 >  }
3486 >  else if(variable == "threeDAngle")
3487 >    {
3488 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3489 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3490 >      value = (threeVector1.Angle(threeVector2));
3491 >    }
3492 >  else if(variable == "alpha")
3493 >    {
3494 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3495 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3496 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3497 >      value = (pi-threeVector1.Angle(threeVector2));
3498 >    }
3499 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3500  
3501    value = applyFunction(function, value);
3502  
# Line 2937 | Line 3552 | OSUAnalysis::valueLookup (const BNelectr
3552      value = object2->correctedD0;
3553    }
3554  
3555 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3555 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3556  
3557    value = applyFunction(function, value);
3558  
3559    return value;
3560   }
3561 +
3562   //!electron-muon pair valueLookup
3563   double
3564   OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
# Line 3003 | Line 3619 | OSUAnalysis::valueLookup (const BNelectr
3619    else if(variable == "muonRelPFdBetaIso"){
3620      value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3621    }
3622 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3622 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3623    value = applyFunction(function, value);
3624  
3625    return value;
3626 < }
3626 > } // end electron-muon pair valueLookup
3627 >
3628  
3629   //!electron-jet pair valueLookup
3630   double
# Line 3017 | Line 3634 | OSUAnalysis::valueLookup (const BNelectr
3634  
3635    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3636    else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3637 +  else if(variable == "jetEta") value = object2->eta;
3638 +  else if(variable == "jetPhi") value = object2->phi;
3639 +  else if(variable == "electronEta") value = object1->eta;
3640 +  else if(variable == "electronPhi") value = object1->phi;
3641    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3642    else if(variable == "invMass"){
3643      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 3038 | Line 3659 | OSUAnalysis::valueLookup (const BNelectr
3659      value = object1->charge*object2->charge;
3660    }
3661  
3662 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3662 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3663 >  value = applyFunction(function, value);
3664 >
3665 >  return value;
3666 > }
3667 >
3668 > //!photon-jet pair valueLookup
3669 > double
3670 > OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3671 >
3672 >  double value = 0.0;
3673 >
3674 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3675 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3676 >  else if(variable == "jetEta") value = object2->eta;
3677 >  else if(variable == "jetPhi") value = object2->phi;
3678 >  else if(variable == "photonEta") value = object1->eta;
3679 >  else if(variable == "photonPhi") value = object1->phi;
3680 >  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3681 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3682 >  else if(variable == "invMass"){
3683 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3684 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3685 >    value = (fourVector1 + fourVector2).M();
3686 >  }
3687 >  else if(variable == "pt"){
3688 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3689 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3690 >    value = (fourVector1 + fourVector2).Pt();
3691 >  }
3692 >  else if(variable == "threeDAngle")
3693 >    {
3694 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3695 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3696 >      value = (threeVector1.Angle(threeVector2));
3697 >    }
3698 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3699 >  value = applyFunction(function, value);
3700 >
3701 >  return value;
3702 > }
3703 >
3704 > // track-jet pair valueLookup
3705 > double
3706 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNjet* object2, string variable, string function, string &stringValue){
3707 >
3708 >  double value = 0.0;
3709 >
3710 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3711 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3712 >
3713 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3714    value = applyFunction(function, value);
3715  
3716    return value;
3717 +
3718   }
3719  
3720 +
3721 +
3722 + // met-jet pair valueLookup
3723 + double
3724 + OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3725 +
3726 +  double value = 0.0;
3727 +
3728 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3729 +
3730 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3731 +  value = applyFunction(function, value);
3732 +
3733 +  return value;
3734 +
3735 + }  
3736 +
3737 +
3738 +
3739   //!muon-jet pair valueLookup
3740   double
3741   OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
# Line 3051 | Line 3743 | OSUAnalysis::valueLookup (const BNmuon*
3743    double value = 0.0;
3744  
3745    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3746 <  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3746 >  else if(variable == "jetEta") value = object2->eta;
3747 >  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3748 >  else if(variable == "jetPt") value = object2->pt;
3749 >  else if(variable == "jetPhi") value = object2->phi;
3750 >  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3751 >  else if(variable == "muonEta") value = object1->eta;
3752 >  else if(variable == "muonPt") value = object1->pt;
3753 >  else if(variable == "muonPhi") value = object1->phi;
3754 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3755    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3756    else if(variable == "invMass"){
3757      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 3073 | Line 3773 | OSUAnalysis::valueLookup (const BNmuon*
3773      value = object1->charge*object2->charge;
3774    }
3775  
3776 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3776 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3777    value = applyFunction(function, value);
3778  
3779    return value;
3780   }
3781  
3782 + //!muon-event valueLookup
3783 + double
3784 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNevent* object2, string variable, string function, string &stringValue){
3785 +
3786 +  double value = 0.0;
3787 +
3788 +  if(variable == "muonEta") value = object1->eta;
3789 +  else if(variable == "muonPt") value = object1->pt;
3790 +  else if(variable == "muonPhi") value = object1->phi;
3791 +  else if(variable == "Ht") value = getHt(jets.product());
3792 +  else if(variable == "pthat")   value = object2->pthat;
3793 +  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3794 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3795 +  value = applyFunction(function, value);
3796 +
3797 +  return value;
3798 + }
3799   //!jet-jet pair valueLookup
3800   double
3801   OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
# Line 3087 | Line 3804 | OSUAnalysis::valueLookup (const BNjet* o
3804  
3805    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3806    else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3807 <  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3807 >  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3808    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3809    else if(variable == "invMass"){
3810      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 3109 | Line 3826 | OSUAnalysis::valueLookup (const BNjet* o
3826      value = object1->charge*object2->charge;
3827    }
3828  
3829 <  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3829 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3830    value = applyFunction(function, value);
3831  
3832    return value;
3833   }
3834 +
3835   //!electron-track pair valueLookup
3836   double
3837   OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
# Line 3133 | Line 3851 | OSUAnalysis::valueLookup (const BNelectr
3851    else if(variable == "chargeProduct"){
3852      value = object1->charge*object2->charge;
3853    }
3854 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3854 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3855    value = applyFunction(function, value);
3856    return value;
3857  
# Line 3161 | Line 3879 | OSUAnalysis::valueLookup (const BNmuon*
3879      value = object1->charge*object2->charge;
3880    }
3881  
3882 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3882 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3883    value = applyFunction(function, value);
3884    return value;
3885   }
# Line 3183 | Line 3901 | OSUAnalysis::valueLookup (const BNtau* o
3901      value = object1->charge*object2->charge;
3902    }
3903  
3904 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3904 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3905    value = applyFunction(function, value);
3906    return value;
3907   }
# Line 3205 | Line 3923 | OSUAnalysis::valueLookup (const BNmuon*
3923      value = object1->charge*object2->charge;
3924    }
3925  
3926 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3926 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3927    value = applyFunction(function, value);
3928    return value;
3929   }
# Line 3220 | Line 3938 | OSUAnalysis::valueLookup (const BNtau* o
3938      value = object1->charge*object2->charge;
3939    }
3940  
3941 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3941 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3942    value = applyFunction(function, value);
3943    return value;
3944   }
# Line 3240 | Line 3958 | OSUAnalysis::valueLookup (const BNtrack*
3958    else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3959    else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3960  
3961 <  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3961 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3962  
3963    value = applyFunction(function, value);
3964  
# Line 3262 | Line 3980 | OSUAnalysis::valueLookup (const BNelectr
3980        stringValue = "none";
3981    }
3982  
3983 <  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3983 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3984  
3985    value = applyFunction(function, value);
3986  
# Line 3278 | Line 3996 | OSUAnalysis::valueLookup (const BNmuon*
3996  
3997    if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3998  
3999 <  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3999 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4000  
4001    value = applyFunction(function, value);
4002  
# Line 3381 | Line 4099 | OSUAnalysis::valueLookup (const BNstop*
4099      for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4100        vertex_rank++;
4101        int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4102 <                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4103 <                   (object->vz-vertex->z)*(object->vz-vertex->z));
4102 >                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
4103 >                      (object->vz-vertex->z)*(object->vz-vertex->z));
4104  
4105        if(abs(dist) < abs(minDistToVertex)){
4106          value = vertex_rank;
# Line 3391 | Line 4109 | OSUAnalysis::valueLookup (const BNstop*
4109      }
4110    }
4111  
4112 +  else if (variable == "decaysToTau"){
4113 +    value = abs (object->daughter0Id) == 15 || abs (object->daughter1Id) == 15;
4114 +  }
4115  
4116  
4117  
4118 <  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4118 >
4119 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4120  
4121    value = applyFunction(function, value);
4122  
4123    return value;
4124  
4125 < }
4125 > } // end stop valueLookup
4126 >
4127  
4128  
4129  
# Line 3418 | Line 4141 | OSUAnalysis::getTrkIsIso (const BNtrack*
4141  
4142   }
4143  
4144 + //calculate the scalar sum of Jet Pt in the event.
4145 + double
4146 + OSUAnalysis::getHt (const BNjetCollection* jetColl){
4147 +  double Ht = 0;
4148 +  for(BNjetCollection::const_iterator jet = jetColl->begin(); jet !=jetColl->end(); jet++){
4149 +    Ht += abs(jet->pt);
4150 +  }
4151 +  return Ht;
4152 + }
4153  
4154   double
4155   OSUAnalysis::getTrkPtRes (const BNtrack* track1){
# Line 3455 | Line 4187 | OSUAnalysis::getTrkCaloTotRhoCorr(const
4187    // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
4188    if (!useTrackCaloRhoCorr_) return -99;
4189    // if (!rhokt6CaloJetsHandle_) {
4190 <  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
4190 >  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
4191    //   return -99;
4192    // }
4193    double radDeltaRCone = 0.5;
# Line 3466 | Line 4198 | OSUAnalysis::getTrkCaloTotRhoCorr(const
4198  
4199   }
4200  
4201 + double
4202 + OSUAnalysis::getTrkDepTrkRp5RhoCorr(const BNtrack* track) {
4203 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.              
4204 +  if (!useTrackCaloRhoCorr_) return -99;
4205 +  // if (!rhokt6CaloJetsHandle_) {                                                                                                    
4206 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;                        
4207 +  //   return -99;                                                                                                                    
4208 +  // }                                                                                                                                
4209 +  double radDeltaRCone = 0.5;
4210 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.                                                                                                          
4211 +  double rawDepTrkRp5 = track->depTrkRp5;
4212 + double depTrkRp5RhoCorr = TMath::Max(0., rawDepTrkRp5 - rhoCorr_kt6CaloJets);
4213 + return depTrkRp5RhoCorr;
4214 +
4215 + }
4216 +
4217 + double
4218 + OSUAnalysis::getTrkDepTrkRp3RhoCorr(const BNtrack* track) {
4219 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.                                                
4220 +  if (!useTrackCaloRhoCorr_) return -99;
4221 +  // if (!rhokt6CaloJetsHandle_) {                                                                                                                                      
4222 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;                                                          
4223 +  //   return -99;                                                                                                                                                      
4224 +  // }                                                                                                                                                                  
4225 +  double radDeltaRCone = 0.3;
4226 + // Define effective area as pi*r^2, where r is radius of DeltaR cone
4227 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  
4228 +  double rawDepTrkRp3 = track->depTrkRp3;
4229 +  double depTrkRp3RhoCorr = TMath::Max(0., rawDepTrkRp3 - rhoCorr_kt6CaloJets);
4230 +  return depTrkRp3RhoCorr;
4231 +  
4232 + }
4233 +
4234  
4235  
4236  
# Line 3477 | Line 4242 | OSUAnalysis::WriteDeadEcal (){
4242    double etaEcal, phiEcal;
4243    ifstream DeadEcalFile(deadEcalFile_);
4244    if(!DeadEcalFile) {
4245 <    cout << "Error: DeadEcalFile has not been found." << endl;
4245 >    clog << "Error: DeadEcalFile has not been found." << endl;
4246      return;
4247    }
4248    if(DeadEcalVec.size()!= 0){
4249 <    cout << "Error: DeadEcalVec has a nonzero size" << endl;
4249 >    clog << "Error: DeadEcalVec has a nonzero size" << endl;
4250      return;
4251    }
4252    while(!DeadEcalFile.eof())
# Line 3492 | Line 4257 | OSUAnalysis::WriteDeadEcal (){
4257        newChan.phiEcal = phiEcal;
4258        DeadEcalVec.push_back(newChan);
4259      }
4260 <  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
4260 >  if(DeadEcalVec.size() == 0) clog << "Warning: No dead Ecal channels have been found." << endl;
4261   }
4262  
4263   //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
# Line 3532 | Line 4297 | OSUAnalysis::applyFunction(string functi
4297    else if(function == "log") value = log10(value);
4298  
4299    else if(function == "") value = value;
4300 <  else{cout << "WARNING: invalid function '" << function << "'\n";}
4300 >  else{clog << "WARNING: invalid function '" << function << "'\n";}
4301  
4302    return value;
4303  
# Line 3542 | Line 4307 | OSUAnalysis::applyFunction(string functi
4307   template <class InputCollection>
4308   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
4309  
4310 +  if (verbose_>2) clog << "  Beginning setObjectFlags for cut " << currentCutIndex << ": " << currentCut.name
4311 +                       << ", inputType=" << inputType
4312 +                       << endl;  
4313    if (currentCut.inputCollection.find("pair")!=string::npos)  {
4314      string obj1, obj2;
4315      getTwoObjs(currentCut.inputCollection, obj1, obj2);
4316      if (inputType==obj1 ||
4317 <          inputType==obj2) {
4317 >        inputType==obj2) {
4318        // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
4319        // and the inputType is a member of the pair.
4320        // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
# Line 3558 | Line 4326 | void OSUAnalysis::setObjectFlags(cut &cu
4326  
4327    for (uint object = 0; object != inputCollection->size(); object++){
4328  
4329 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
4329 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4330 >    bool plotDecision = true;
4331  
4332      if(currentCut.inputCollection == inputType){
4333  
# Line 3570 | Line 4339 | void OSUAnalysis::setObjectFlags(cut &cu
4339          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4340  
4341        }
4342 <      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4342 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4343        else{
4344          bool tempDecision = true;
4345          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
# Line 3579 | Line 4348 | void OSUAnalysis::setObjectFlags(cut &cu
4348            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4349              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4350          }
4351 <        decision = tempDecision;
4351 >        cutDecision = tempDecision;
4352        }
4353 +      //invert the cut if this cut is a veto
4354 +      if(currentCut.isVeto) cutDecision = !cutDecision;
4355 +      plotDecision = cutDecision;
4356      }
4357  
4358 <    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4358 >    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4359  
4360 <    //set flags for objects that pass each cut AND all the previous cuts
4361 <    bool previousCumulativeFlag = true;
4360 >    //set flags for objects that pass this cut AND all the previous cuts
4361 >    bool previousCumulativeCutFlag = true;
4362 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4363 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4364 >      else{ previousCumulativeCutFlag = false; break;}
4365 >    }
4366 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4367 >    bool previousCumulativePlotFlag = true;
4368      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4369 <      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4370 <      else{ previousCumulativeFlag = false; break;}
4369 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4370 >      else{ previousCumulativePlotFlag = false; break;}
4371      }
4372 <    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4372 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4373 >
4374 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4375  
4376    }
4377  
4378 < }
4378 > } // end void OSUAnalysis::setObjectFlags
4379  
4380  
4381   template <class InputCollection1, class InputCollection2>
4382 < void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
4383 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
4384 <
4382 > void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags,
4383 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, string inputType){
4384 >  // This function sets the flags for the paired object collection.  
4385 >  // If the cut is applying on the given paired object collection, then the flags for the single object collections are also set.
4386 >  // If not, then the flags for the paired object collection are taken as the AND of the flags for each single object collection.  
4387 >
4388 >  if (verbose_>2) clog << "  Beginning setObjectFlags for cut=" << currentCut.name
4389 >                       << ", inputType=" << inputType
4390 >                       << endl;  
4391  
4392    bool sameObjects = false;
4393 <  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4393 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;  // FIXME:  is sameObjects just the not of isTwoTypesOfObject?  If so, it's redundant.  
4394  
4395    // Get the strings for the two objects that make up the pair.
4396    string obj1Type, obj2Type;
# Line 3616 | Line 4402 | void OSUAnalysis::setObjectFlags(cut &cu
4402    // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4403    if (currentCut.inputCollection == inputType) {
4404      for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4405 <      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
4406 <      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
4405 >      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4406 >      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4407      }
4408      if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4409        for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4410 <        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
4411 <        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
4410 >        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4411 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4412        }
4413      }
4414    }
# Line 3635 | Line 4421 | void OSUAnalysis::setObjectFlags(cut &cu
4421        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4422  
4423  
4424 <      bool decision = true;//object passes if this cut doesn't cut on that type of object
4424 >      bool cutDecision  = true;//object passes if this cut doesn't cut on that type of object
4425 >      bool plotDecision = true;
4426  
4427 +      // Determine whether each pair passes the cut, only if inputCollection is the same as the inputType.  
4428        if(currentCut.inputCollection == inputType){
4429  
4430          vector<bool> subcutDecisions;
4431          for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4432            string stringValue = "";
4433            double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4434 +          if (verbose_>1) clog << currentCut.variables.at(subcutIndex) << " = " << value
4435 +                               << endl;  
4436            if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4437            else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4438          }
4439  
4440 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4440 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4441          else{
4442            bool tempDecision = subcutDecisions.at(0);
4443            for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
# Line 3656 | Line 4446 | void OSUAnalysis::setObjectFlags(cut &cu
4446              else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4447                tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4448            }
4449 <          decision = tempDecision;
4449 >          cutDecision = tempDecision;
4450          }
4451 +        //invert the cut if this cut is a veto
4452 +        if (currentCut.isVeto) cutDecision = !cutDecision;
4453 +        plotDecision = cutDecision;
4454 +
4455 +        if (verbose_>1) clog << " cutDecision = " << cutDecision
4456 +                             << "; for currentCut.inputCollection = " << currentCut.inputCollection
4457 +                             << "; object1 (" << obj1Type << ") = " << object1
4458 +                             << "; object2 (" << obj2Type << ") = " << object2
4459 +                             << endl;  
4460 +        
4461 +        if (cutDecision) {  // only set the flags for the individual objects if the pair object is being cut on
4462 +          individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4463 +          individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4464 +        }
4465 +        if (plotDecision) {  // only set the flags for the individual objects if the pair object is being cut on
4466 +          individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4467 +          individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4468 +        }
4469 +        
4470 +
4471 +      } // if(currentCut.inputCollection == inputType){
4472 +
4473 +      // The individualFlags will be true if the inputCollection is not the same as the inputType.
4474 +      // They are also independent of the previous flags on the single objects.  
4475 +      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));  
4476 +
4477 +
4478 +
4479 +      // ************************************
4480 +      // Determine cumulative flags
4481 +      // ************************************
4482 +      // determine whether this paired object passes this cut AND all previous cuts
4483 +      bool previousCumulativeCutFlag = true;
4484 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4485 +        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4486 +        else{ previousCumulativeCutFlag = false; break;}
4487        }
4488 <      // if (decision) isPassObj1.at(object1) = true;
3663 <      // if (decision) isPassObj2.at(object2) = true;
3664 <      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3665 <      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3666 <        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;
3667 <        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;
3668 <      }
4488 >      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4489  
4490 <      //set flags for objects that pass each cut AND all the previous cuts
3671 <      bool previousCumulativeFlag = true;
4490 >      bool previousCumulativePlotFlag = true;
4491        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4492 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
4493 <        else{ previousCumulativeFlag = false; break;}
4492 >        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4493 >        else{ previousCumulativePlotFlag = false; break;}
4494        }
4495 <      //apply flags for the components of the composite object as well
4496 <      bool currentCumulativeFlag = true;
4497 <      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
4498 <      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
4499 <      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
4500 <      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
4501 <      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
4502 <      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4503 <        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);
4504 <        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);
4495 >      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4496 >      
4497 >      // 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.    
4498 >      int cutIdxFlagsObj1 = max(int(currentCutIndex-1),0);
4499 >      int cutIdxFlagsObj2 = max(int(currentCutIndex-1),0);
4500 >      // 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.
4501 >      // 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.  
4502 >      // 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).  
4503 >      if (currentCut.inputCollection != inputType) {  
4504 >        if (currentCut.inputCollection.find(obj1Type)!=string::npos) cutIdxFlagsObj1 = currentCutIndex;
4505 >        if (currentCut.inputCollection.find(obj2Type)!=string::npos) cutIdxFlagsObj2 = currentCutIndex;
4506 >      }  
4507 >      flagPair flags1 = cumulativeFlags.at(obj1Type).at(cutIdxFlagsObj1);  // flag for input collection 1
4508 >      flagPair flags2 = cumulativeFlags.at(obj2Type).at(cutIdxFlagsObj2);  // flag for input collection 2
4509 >      
4510 >      // The cumulative flag is only true if the paired object cumulative flag is true, and if the single object cumulative flags are true.  
4511 >      bool currentCumulativeCutFlag = true;
4512 >      bool currentCumulativePlotFlag = true;
4513 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4514 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4515 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4516 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4517 >
4518 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4519 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4520 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4521 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4522 >
4523 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));  // Set the flag for the paired object
4524 >
4525 >
4526 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // Set the flags for the individual objects if the paired object is being cut on.  
4527 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first  = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4528 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first  = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4529 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4530 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4531 >
4532 >        if (verbose_>1) clog << " previousCumulativeCutFlag for object1 = " << getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object1, "cut") << endl;  
4533 >        if (verbose_>1) clog << " previousCumulativeCutFlag for object2 = " << getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut") << endl;  
4534 >
4535        }
4536 +
4537        counter++;
4538  
4539      } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4540    }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4541  
4542 < }
4542 > } // end void OSUAnalysis::setObjectFlags
4543  
4544  
4545 < bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
4545 > bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4546    // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4547    // all cuts up to currentCutIndex
4548    bool previousCumulativeFlag = true;
4549    for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4550 <    if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
4550 >    bool tempFlag = false;
4551 >    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4552 >    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4553 >
4554 >    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4555      else {
4556        previousCumulativeFlag = false; break;
4557      }
# Line 3706 | Line 4560 | bool OSUAnalysis::getPreviousCumulativeF
4560   }
4561  
4562  
4563 +
4564 +
4565   template <class InputCollection>
4566 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4566 > void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4567 >  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4568 >
4569 >  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;
4570 >  for (uint object = 0; object != inputCollection->size(); object++) {
4571 >
4572 >    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4573 >
4574 >    string inputVariable = parameters.inputVariable;
4575 >    string function = "";
4576 >    string stringValue = "";
4577 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4578 >    BNTreeBranchVals_.at(parameters.name).push_back(value);
4579 >
4580 >  }
4581 > }
4582 >
4583 >
4584 > template <class InputCollection>
4585 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4586 >
4587 >  if (verbose_>2) clog << "  Filling histogram for " << parameters.name << endl;  
4588  
4589    for (uint object = 0; object != inputCollection->size(); object++){
4590  
4591 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4591 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4592  
4593      string currentString = parameters.inputVariables.at(0);
4594      string inputVariable = "";
# Line 3728 | Line 4605 | void OSUAnalysis::fill1DHistogram(TH1* h
4605      string stringValue = "";
4606      double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4607      histo->Fill(value,scaleFactor);
4608 +
4609      if (printEventInfo_) {
4610        // Write information about event to screen, for testing purposes.
4611 <      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
4611 >      clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << " (object number " << object << ")" << endl;
4612      }
4613  
4614    }
4615   }
4616  
4617   template <class InputCollection1, class InputCollection2>
4618 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4618 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2,
4619 >                                  flagPair pairFlags, double scaleFactor){
4620  
4621    bool sameObjects = false;
4622    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
# Line 3749 | Line 4628 | void OSUAnalysis::fill1DHistogram(TH1* h
4628        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4629  
4630        pairCounter++;
4631 <      //only take objects which have passed all cuts and pairs which have passed all cuts
3753 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3754 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3755 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4631 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4632  
4633        string currentString = parameters.inputVariables.at(0);
4634        string inputVariable = "";
# Line 3770 | Line 4646 | void OSUAnalysis::fill1DHistogram(TH1* h
4646        double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4647        histo->Fill(value,scaleFactor);
4648  
4649 +      if (printEventInfo_) {
4650 +        // Write information about event to screen, for testing purposes.
4651 +        clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value
4652 +             << " (object1 number " << object1 << "), "
4653 +             << " (object2 number " << object2 << ")"
4654 +             << endl;
4655 +      }
4656 +      
4657      }
4658    }
4659  
# Line 3777 | Line 4661 | void OSUAnalysis::fill1DHistogram(TH1* h
4661  
4662  
4663   template <class InputCollection>
4664 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4664 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4665  
4666    for (uint object = 0; object != inputCollection->size(); object++){
4667  
4668 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4668 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4669  
4670      string stringValue = "";
4671      string currentString = parameters.inputVariables.at(0);
# Line 3818 | Line 4702 | void OSUAnalysis::fill2DHistogram(TH2* h
4702   }
4703  
4704   template <class InputCollection1, class InputCollection2>
4705 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4705 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2,
4706 >                                  flagPair pairFlags, double scaleFactor){
4707  
4708    bool sameObjects = false;
4709    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
# Line 3831 | Line 4716 | void OSUAnalysis::fill2DHistogram(TH2* h
4716  
4717        pairCounter++;
4718  
4719 <      //only take objects which have passed all cuts and pairs which have passed all cuts
3835 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3836 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3837 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4719 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4720  
4721        string stringValue = "";
4722        string currentString = parameters.inputVariables.at(0);
# Line 3882 | Line 4764 | int OSUAnalysis::getGenMatchedParticleIn
4764  
4765      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4766      if(currentDeltaR > 0.05) continue;
4767 <    //     cout << setprecision(3) << setw(20)
4767 >    //     clog << setprecision(3) << setw(20)
4768      //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4769      //          << setw(20)
4770      //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
# Line 3901 | Line 4783 | int OSUAnalysis::getGenMatchedParticleIn
4783      }
4784  
4785    }
4786 <  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4787 <  //   else cout << "no match found..." << endl;
4786 >  //   if(bestMatchDeltaR != 999)  clog << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4787 >  //   else clog << "no match found..." << endl;
4788    return bestMatchIndex;
4789  
4790   }
# Line 3994 | Line 4876 | OSUAnalysis::chosenVertex ()
4876   {
4877    const BNprimaryvertex *chosenVertex = 0;
4878    if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4879 <    vector<bool> vertexFlags;
4879 >    flagPair vertexFlags;
4880      for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4881        if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4882          vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
# Line 4002 | Line 4884 | OSUAnalysis::chosenVertex ()
4884        }
4885      }
4886      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4887 <      if(!vertexFlags.at(vertexIndex)) continue;
4887 >      if(!vertexFlags.at(vertexIndex).first) continue;
4888        chosenVertex = & primaryvertexs->at(vertexIndex);
4889        break;
4890      }
# Line 4018 | Line 4900 | OSUAnalysis::chosenMET ()
4900   {
4901    const BNmet *chosenMET = 0;
4902    if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4903 <    vector<bool> metFlags;
4903 >    flagPair metFlags;
4904      for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4905        if (cumulativeFlags.at("mets").at(i).size()){
4906          metFlags = cumulativeFlags.at("mets").at(i);
# Line 4026 | Line 4908 | OSUAnalysis::chosenMET ()
4908        }
4909      }
4910      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4911 <      if(!metFlags.at(metIndex)) continue;
4911 >      if(!metFlags.at(metIndex).first) continue;
4912        chosenMET = & mets->at(metIndex);
4913        break;
4914      }
# Line 4042 | Line 4924 | OSUAnalysis::chosenElectron ()
4924   {
4925    const BNelectron *chosenElectron = 0;
4926    if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4927 <    vector<bool> electronFlags;
4927 >    flagPair electronFlags;
4928      for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4929        if (cumulativeFlags.at("electrons").at(i).size()){
4930          electronFlags = cumulativeFlags.at("electrons").at(i);
# Line 4050 | Line 4932 | OSUAnalysis::chosenElectron ()
4932        }
4933      }
4934      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4935 <      if(!electronFlags.at(electronIndex)) continue;
4935 >      if(!electronFlags.at(electronIndex).first) continue;
4936        chosenElectron = & electrons->at(electronIndex);
4937        break;
4938      }
# Line 4061 | Line 4943 | OSUAnalysis::chosenElectron ()
4943    return chosenElectron;
4944   }
4945  
4946 +
4947   const BNmuon *
4948   OSUAnalysis::chosenMuon ()
4949   {
4950    const BNmuon *chosenMuon = 0;
4951    if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4952 <    vector<bool> muonFlags;
4952 >    flagPair muonFlags;
4953      for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4954        if (cumulativeFlags.at("muons").at(i).size()){
4955          muonFlags = cumulativeFlags.at("muons").at(i);
# Line 4074 | Line 4957 | OSUAnalysis::chosenMuon ()
4957        }
4958      }
4959      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4960 <      if(!muonFlags.at(muonIndex)) continue;
4960 >      if(!muonFlags.at(muonIndex).first) continue;
4961        chosenMuon = & muons->at(muonIndex);
4962        break;
4963      }
# Line 4085 | Line 4968 | OSUAnalysis::chosenMuon ()
4968    return chosenMuon;
4969   }
4970  
4971 + double
4972 + OSUAnalysis::chosenHT ()
4973 + {
4974 +  double chosenHT = 0.0;
4975 +  if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
4976 +    flagPair jetFlags;
4977 +    for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
4978 +      if (cumulativeFlags.at("jets").at(i).size()){
4979 +        jetFlags = cumulativeFlags.at("jets").at(i);
4980 +        break;
4981 +      }
4982 +    }
4983 +    for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
4984 +      if(!jetFlags.at(jetIndex).first) continue;
4985 +      chosenHT += jets->at(jetIndex).pt;
4986 +    }
4987 +  }
4988 +
4989 +  return chosenHT;
4990 + }
4991 +
4992 + pair<const BNmuon *, const BNmuon *>
4993 + OSUAnalysis::leadMuonPair ()
4994 + {
4995 +  pair<const BNmuon *, const BNmuon *> leadMuonPair;
4996 +  leadMuonPair.first = leadMuonPair.second = 0;
4997 +
4998 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4999 +    flagPair muonFlags;
5000 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
5001 +      if (cumulativeFlags.at("muons").at(i).size()){
5002 +        muonFlags = cumulativeFlags.at("muons").at(i);
5003 +        break;
5004 +      }
5005 +    }
5006 +    for (uint muonIndex0 = 0; muonIndex0 != muonFlags.size(); muonIndex0++){
5007 +      if(!muonFlags.at(muonIndex0).first) continue;
5008 +      for (uint muonIndex1 = muonIndex0 + 1; muonIndex1 < muonFlags.size(); muonIndex1++){
5009 +        if(!muonFlags.at(muonIndex1).first) continue;
5010 +        const BNmuon *mu0 = & muons->at(muonIndex0);
5011 +        const BNmuon *mu1 = & muons->at(muonIndex1);
5012 +        if(leadMuonPair.first == 0 || leadMuonPair.second == 0){
5013 +          leadMuonPair.first = mu0;
5014 +          leadMuonPair.second = mu1;
5015 +        }
5016 +        else{
5017 +          TVector2 newPt0 (mu0->px, mu0->py),
5018 +                   newPt1 (mu1->px, mu1->py),
5019 +                   oldPt0 (leadMuonPair.first->px, leadMuonPair.first->py),
5020 +                   oldPt1 (leadMuonPair.second->px, leadMuonPair.second->py);
5021 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
5022 +            {
5023 +              leadMuonPair.first = mu0;
5024 +              leadMuonPair.second = mu1;
5025 +            }
5026 +        }
5027 +      }
5028 +    }
5029 +  }
5030 +
5031 +  return leadMuonPair;
5032 + }
5033 +
5034 + pair<const BNelectron *, const BNelectron *>
5035 + OSUAnalysis::leadElectronPair ()
5036 + {
5037 +  pair<const BNelectron *, const BNelectron *> leadElectronPair;
5038 +  leadElectronPair.first = leadElectronPair.second = 0;
5039 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
5040 +    flagPair electronFlags;
5041 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
5042 +      if (cumulativeFlags.at("electrons").at(i).size()){
5043 +        electronFlags = cumulativeFlags.at("electrons").at(i);
5044 +        break;
5045 +      }
5046 +    }
5047 +    for (uint electronIndex0 = 0; electronIndex0 != electronFlags.size(); electronIndex0++){
5048 +      if(!electronFlags.at(electronIndex0).first) continue;
5049 +      for (uint electronIndex1 = electronIndex0 + 1; electronIndex1 < electronFlags.size(); electronIndex1++){
5050 +        if(!electronFlags.at(electronIndex1).first) continue;
5051 +        const BNelectron *el0 = & electrons->at(electronIndex0);
5052 +        const BNelectron *el1 = & electrons->at(electronIndex1);
5053 +        if(leadElectronPair.first == 0 || leadElectronPair.second == 0){
5054 +          leadElectronPair.first = el0;
5055 +          leadElectronPair.second = el1;
5056 +        }
5057 +        else{
5058 +          TVector2 newPt0 (el0->px, el0->py),
5059 +                   newPt1 (el1->px, el1->py),
5060 +                   oldPt0 (leadElectronPair.first->px, leadElectronPair.first->py),
5061 +                   oldPt1 (leadElectronPair.second->px, leadElectronPair.second->py);
5062 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
5063 +            {
5064 +              leadElectronPair.first = el0;
5065 +              leadElectronPair.second = el1;
5066 +            }
5067 +        }
5068 +      }
5069 +    }
5070 +  }
5071 +
5072 +  return leadElectronPair;
5073 + }
5074 +
5075   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines