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.49 by wulsin, Wed Apr 17 15:39:43 2013 UTC vs.
Revision 1.92 by wulsin, Mon Jul 1 11:54:18 2013 UTC

# Line 17 | Line 17 | OSUAnalysis::OSUAnalysis (const edm::Par
17    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
18    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
19    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
20 <  puFile_ (cfg.getParameter<std::string> ("puFile")),
21 <  deadEcalFile_ (cfg.getParameter<std::string> ("deadEcalFile")),
22 <  muonSFFile_ (cfg.getParameter<std::string> ("muonSFFile")),
23 <  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
24 <  electronSFID_ (cfg.getParameter<std::string> ("electronSFID")),
25 <  muonSF_ (cfg.getParameter<std::string> ("muonSF")),
26 <  dataset_ (cfg.getParameter<std::string> ("dataset")),
27 <  datasetType_ (cfg.getParameter<std::string> ("datasetType")),
20 >  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
21 >  puFile_ (cfg.getParameter<string> ("puFile")),
22 >  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
23 >  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
24 >  dataPU_ (cfg.getParameter<string> ("dataPU")),
25 >  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
26 >  muonSF_ (cfg.getParameter<string> ("muonSF")),
27 >  dataset_ (cfg.getParameter<string> ("dataset")),
28 >  datasetType_ (cfg.getParameter<string> ("datasetType")),
29    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
30    histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
31 +  useEDMFormat_   (cfg.getParameter<bool>("useEDMFormat")),
32 +  treeBranchSets_   (cfg.getParameter<vector<edm::ParameterSet> >("treeBranchSets")),
33    plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
34    doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
35 <  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
35 >  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
36 >  applyBtagSF_ (cfg.getParameter<bool> ("applyBtagSF")),
37 >  minBtag_ (cfg.getParameter<int> ("minBtag")),
38 >  maxBtag_ (cfg.getParameter<int> ("maxBtag")),
39 >  printEventInfo_      (cfg.getParameter<bool> ("printEventInfo")),
40 >  printAllTriggers_    (cfg.getParameter<bool> ("printAllTriggers")),
41    useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
42 <  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau"))
43 <
44 < {
42 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
43 >  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
44 > {
45  
46    TH1::SetDefaultSumw2 ();
47  
48    //create pile-up reweighting object, if necessary
49    if(datasetType_ != "data") {
50      if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
51 <    //    muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
52 <    //    electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
51 >    if (applyLeptonSF_){
52 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
53 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
54 >    }
55 >    if (applyBtagSF_){
56 >      bTagSFWeight_ = new BtagSFWeight;
57 >    }
58    }
59 < #ifdef DISPLACED_SUSY
60 <  if (datasetType_ == "signalMC")
48 <    cTauWeight_ = new CTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
49 < #endif
59 >  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
60 >    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
61  
62  
63    // Construct Cutflow Objects. These store the results of cut decisions and
64    // handle filling cut flow histograms.
65    masterCutFlow_ = new CutFlow (fs_);
55  std::vector<TFileDirectory> directories;
66  
67    //always get vertex collection so we can assign the primary vertex in the event
68    objectsToGet.push_back("primaryvertexs");
59
60  //always make the plot of number of primary vertices (to check pile-up reweighting)
69    objectsToPlot.push_back("primaryvertexs");
70 +  objectsToCut.push_back("primaryvertexs");
71 +
72  
73    //always get the MC particles to do GEN-matching
74    objectsToGet.push_back("mcparticles");
# Line 66 | Line 76 | OSUAnalysis::OSUAnalysis (const edm::Par
76    //always get the event collection to do pile-up reweighting
77    objectsToGet.push_back("events");
78  
79 +
80 +  // Parse the tree variable definitions.
81 +  for (uint iBranchSet = 0; !useEDMFormat_ && iBranchSet<treeBranchSets_.size(); iBranchSet++) {
82 +    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
83 +    if(tempInputCollection.find("pairs")!=string::npos) { cout << "Warning:  tree filling is not configured for pairs of objects, so will not work for collection: " << tempInputCollection << endl; }
84 +    objectsToGet.push_back(tempInputCollection);
85 +    objectsToCut.push_back(tempInputCollection);
86 +
87 +    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
88 +
89 +    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
90 +      BranchSpecs br;
91 +      br.inputCollection = tempInputCollection;
92 +      br.inputVariable = branchList.at(iBranch);
93 +      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);
94 +      br.name = string(newName.Data());
95 +      treeBranches_.push_back(br);
96 +    }
97 +
98 +  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++)
99 +
100 +
101    //parse the histogram definitions
102    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
103  
104      string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
105      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
106 +    if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
107 +    if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
108 +    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
109 +    if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
110 +    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
111 +    if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
112      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
113      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
114 <    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
115 <      if(tempInputCollection.find("secondary")!=std::string::npos){//secondary object
116 <        int spaceIndex = tempInputCollection.find(" ");
117 <        int secondWordLength = tempInputCollection.size() - spaceIndex;
118 <        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
114 >    if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
115 >    if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
116 >    if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
117 >    if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
118 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
119 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
120 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
121 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
122 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
123 >        int spaceIndex = tempInputCollection.find(" ");
124 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
125 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
126        }
127        else{
128 <        objectsToGet.push_back(tempInputCollection);
128 >        objectsToGet.push_back(tempInputCollection);
129        }
130        objectsToPlot.push_back(tempInputCollection);
131        objectsToCut.push_back(tempInputCollection);
132 <    }
133 <    else{//pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
89 <      string obj1;
132 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
133 >      string obj1;
134        string obj2;
135        getTwoObjs(tempInputCollection, obj1, obj2);
136 <      string obj2ToGet = getObjToGet(obj2);  
136 >      string obj2ToGet = getObjToGet(obj2);
137        objectsToCut.push_back(tempInputCollection);
138        objectsToCut.push_back(obj1);
139 <      objectsToCut.push_back(obj2);  
139 >      objectsToCut.push_back(obj2);
140        objectsToPlot.push_back(tempInputCollection);
141        objectsToPlot.push_back(obj1);
142 <      objectsToPlot.push_back(obj2);  
142 >      objectsToPlot.push_back(obj2);
143        objectsToGet.push_back(tempInputCollection);
144        objectsToGet.push_back(obj1);
145        objectsToGet.push_back(obj2ToGet);
146 +    } // end else
147 +
148  
103    }
149  
150      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
151  
152      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
153  
154 +      vector<double> defaultValue;
155 +      defaultValue.push_back (-1.0);
156 +
157        histogram tempHistogram;
158        tempHistogram.inputCollection = tempInputCollection;
159        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
160        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
161 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
161 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
162 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
163 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
164        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
165  
166        histograms.push_back(tempHistogram);
167  
168      }
169 <  }
169 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
170 >
171    //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
172    sort( objectsToPlot.begin(), objectsToPlot.end() );
173    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
# Line 127 | Line 178 | OSUAnalysis::OSUAnalysis (const edm::Par
178    for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
179  
180      string currentObject = objectsToPlot.at(currentObjectIndex);
181 <    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
181 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
182  
183      histogram tempIdHisto;
184      histogram tempMomIdHisto;
185      histogram tempGmaIdHisto;
186      histogram tempIdVsMomIdHisto;
187 +    histogram tempIdVsGmaIdHisto;
188  
189      tempIdHisto.inputCollection = currentObject;
190      tempMomIdHisto.inputCollection = currentObject;
191      tempGmaIdHisto.inputCollection = currentObject;
192      tempIdVsMomIdHisto.inputCollection = currentObject;
193 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
194  
195      if(currentObject == "secondary muons") currentObject = "secondaryMuons";
196 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
197  
198      currentObject = currentObject.substr(0, currentObject.size()-1);
199      tempIdHisto.name = currentObject+"GenMatchId";
200      tempMomIdHisto.name = currentObject+"GenMatchMotherId";
201      tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
202      tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
203 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
204  
205      currentObject.at(0) = toupper(currentObject.at(0));
206      tempIdHisto.title = currentObject+" Gen-matched Particle";
207      tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
208      tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
209      tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
210 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
211 +
212  
213 <    int maxNum = 24;
213 >    int maxNum = 25;
214      vector<double> binVector;
215      binVector.push_back(maxNum);
216      binVector.push_back(0);
# Line 171 | Line 228 | OSUAnalysis::OSUAnalysis (const edm::Par
228      tempIdVsMomIdHisto.bins = binVector;
229      tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
230      tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
231 +    tempIdVsGmaIdHisto.bins = binVector;
232 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
233 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
234  
235      histograms.push_back(tempIdHisto);
236      histograms.push_back(tempMomIdHisto);
237      histograms.push_back(tempGmaIdHisto);
238      histograms.push_back(tempIdVsMomIdHisto);
239 +    histograms.push_back(tempIdVsGmaIdHisto);
240    }
241  
242  
# Line 191 | Line 252 | OSUAnalysis::OSUAnalysis (const edm::Par
252      //set triggers for this channel
253      vector<string> triggerNames;
254      triggerNames.clear();
255 +    vector<string> triggerToVetoNames;
256 +    triggerToVetoNames.clear();
257 +
258      tempChannel.triggers.clear();
259 +    tempChannel.triggersToVeto.clear();
260      if(channels_.at(currentChannel).exists("triggers")){
261        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
262        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
263          tempChannel.triggers.push_back(triggerNames.at(trigger));
264        objectsToGet.push_back("triggers");
265      }
266 <
266 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
267 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
268 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
269 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
270 >      objectsToGet.push_back("triggers");
271 >    }
272  
273  
274  
275      //create cutFlow for this channel
276      cutFlows_.push_back (new CutFlow (fs_, channelName));
277 <
278 <    //book a directory in the output file with the name of the channel
279 <    TFileDirectory subDir = fs_->mkdir( channelName );
210 <    directories.push_back(subDir);
211 <
212 <    std::map<std::string, TH1D*> oneDhistoMap;
213 <    oneDHists_.push_back(oneDhistoMap);
214 <    std::map<std::string, TH2D*> twoDhistoMap;
215 <    twoDHists_.push_back(twoDhistoMap);
216 <
217 <
218 <
219 <    //book all histograms included in the configuration
220 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
221 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
222 <      int numBinsElements = currentHistogram.bins.size();
223 <      int numInputVariables = currentHistogram.inputVariables.size();
224 <
225 <      if(numBinsElements != 3 && numBinsElements !=6) {
226 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
227 <        exit(0);
228 <      }
229 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
230 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
231 <        exit(0);
232 <      }
233 <      else if(numBinsElements == 3){
234 <        oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
235 <      }
236 <      else if(numBinsElements == 6){
237 <        twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).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));
238 <
239 <      }
240 <
241 <
242 <      if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
243 <
244 <      // bin      particle type
245 <      // ---      -------------
246 <      //  0        unmatched
247 <      //  1        u
248 <      //  2        d
249 <      //  3        s
250 <      //  4        c
251 <      //  5        b
252 <      //  6        t
253 <      //  7        e
254 <      //  8        mu
255 <      //  9        tau
256 <      // 10        nu
257 <      // 11        g
258 <      // 12        gamma
259 <      // 13        Z
260 <      // 14        W
261 <      // 15        light meson
262 <      // 16        K meson
263 <      // 17        D meson
264 <      // 18        B meson
265 <      // 19        light baryon
266 <      // 20        strange baryon
267 <      // 21        charm baryon
268 <      // 22        bottom baryon
269 <      // 23        other
270 <
271 <      vector<TString> labelArray;
272 <      labelArray.push_back("unmatched");
273 <      labelArray.push_back("u");
274 <      labelArray.push_back("d");
275 <      labelArray.push_back("s");
276 <      labelArray.push_back("c");
277 <      labelArray.push_back("b");
278 <      labelArray.push_back("t");
279 <      labelArray.push_back("e");
280 <      labelArray.push_back("#mu");
281 <      labelArray.push_back("#tau");
282 <      labelArray.push_back("#nu");
283 <      labelArray.push_back("g");
284 <      labelArray.push_back("#gamma");
285 <      labelArray.push_back("Z");
286 <      labelArray.push_back("W");
287 <      labelArray.push_back("light meson");
288 <      labelArray.push_back("K meson");
289 <      labelArray.push_back("D meson");
290 <      labelArray.push_back("B meson");
291 <      labelArray.push_back("light baryon");
292 <      labelArray.push_back("strange baryon");
293 <      labelArray.push_back("charm baryon");
294 <      labelArray.push_back("bottom baryon");
295 <      labelArray.push_back("other");
296 <
297 <      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
298 <        if(currentHistogram.name.find("GenMatchIdVsMotherId")==std::string::npos) {
299 <          oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
300 <        }
301 <        else {
302 <          twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
303 <          twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
304 <        }
305 <      }
306 <      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=std::string::npos) {
307 <        twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->CenterTitle();
308 <        twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->CenterTitle();
309 <      }
310 <
311 <    }
312 <
313 <    // Book a histogram for the number of each object type to be plotted.  
314 <    // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().  
315 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
316 <      string currentObject = objectsToPlot.at(currentObjectIndex);
317 <      int maxNum = 10;
318 <      if(currentObject == "mcparticles") maxNum = 50;
319 <      else if(currentObject == "primaryvertexs") maxNum = 50;
320 <
321 <      if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
322 <      else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
323 <      else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
324 <      else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
325 <      else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";        
326 <      else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";    
327 <      else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";      
328 <      else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
329 <      else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
330 <      else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
331 <      else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
332 <
333 <      currentObject.at(0) = toupper(currentObject.at(0));  
334 <      string histoName = "num" + currentObject;
335 <
336 <      if(histoName == "numPrimaryvertexs"){
337 <        string newHistoName = histoName + "BeforePileupCorrection";
338 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
339 <        newHistoName = histoName + "AfterPileupCorrection";
340 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
341 <      }
342 <      else
343 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
344 <    }
345 <
346 <
347 <
348 <
277 >    vector<TFileDirectory> directories; //vector of directories in the output file.
278 >    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
279 >    vector<string> subSubDirNames;//subdirectories in each channel.
280      //get list of cuts for this channel
281      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
282  
283 +
284      //loop over and parse all cuts
285      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
286        cut tempCut;
287        //store input collection for cut
288        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
289        if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
290 +      if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
291 +      if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
292 +      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
293 +      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
294 +      if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
295 +      if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
296        if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
297        if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
298 +      if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
299 +      if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
300 +      if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
301 +      if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
302 +      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
303 +      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
304 +      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
305        tempCut.inputCollection = tempInputCollection;
306 <      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
307 <        if(tempInputCollection.find("secondary")!=std::string::npos){//secondary object
308 <          int spaceIndex = tempInputCollection.find(" ");
309 <          int secondWordLength = tempInputCollection.size() - spaceIndex;
310 <          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
311 <        }
312 <        else{
313 <          objectsToGet.push_back(tempInputCollection);
314 <        }
315 <        objectsToCut.push_back(tempInputCollection);
306 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
307 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
308 >          int spaceIndex = tempInputCollection.find(" ");
309 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
310 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
311 >        }
312 >        else{
313 >          objectsToGet.push_back(tempInputCollection);
314 >        }
315 >        objectsToCut.push_back(tempInputCollection);
316        }
317        else{//pair of objects, need to add them both to objectsToGet
318 <        string obj1;
319 <        string obj2;
320 <        getTwoObjs(tempInputCollection, obj1, obj2);
321 <        string obj2ToGet = getObjToGet(obj2);  
318 >        string obj1;
319 >        string obj2;
320 >        getTwoObjs(tempInputCollection, obj1, obj2);
321 >        string obj2ToGet = getObjToGet(obj2);
322          objectsToCut.push_back(tempInputCollection);
323          objectsToCut.push_back(obj1);
324 <        objectsToCut.push_back(obj2);  
324 >        objectsToCut.push_back(obj2);
325          objectsToGet.push_back(tempInputCollection);
326          objectsToGet.push_back(obj1);
327          objectsToGet.push_back(obj2ToGet);
# Line 387 | Line 332 | OSUAnalysis::OSUAnalysis (const edm::Par
332  
333        //split cut string into parts and store them
334        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
335 <      std::vector<string> cutStringVector = splitString(cutString);
335 >      vector<string> cutStringVector = splitString(cutString);
336        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
337 <        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
337 >        cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
338          exit(0);
339        }
340        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
341        for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
342          int indexOffset = 4 * subcutIndex;
343          string currentVariableString = cutStringVector.at(indexOffset);
344 <        if(currentVariableString.find("(")==std::string::npos){
344 >        if(currentVariableString.find("(")==string::npos){
345            tempCut.functions.push_back("");//no function was specified
346            tempCut.variables.push_back(currentVariableString);// variable to cut on
347          }
# Line 407 | Line 352 | OSUAnalysis::OSUAnalysis (const edm::Par
352          }
353          tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
354          tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
355 +        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
356          if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
357        }
358  
359        //get number of objects required to pass cut for event to pass
360        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
361 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
361 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
362        if(numberRequiredVector.size()!=2){
363 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
363 >        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
364          exit(0);
365        }
366  
# Line 422 | Line 368 | OSUAnalysis::OSUAnalysis (const edm::Par
368        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
369        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
370  
371 <
371 >      //Set up vectors to store the directories and subDirectories for each channel.
372 >      string subSubDirName;
373        string tempCutName;
374        if(cuts_.at(currentCut).exists("alias")){
375          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
376 +        subSubDirName = "After " + tempCutName + " Cut Applied";
377        }
378        else{
379          //construct string for cutflow table
# Line 433 | Line 381 | OSUAnalysis::OSUAnalysis (const edm::Par
381          string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
382          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
383          tempCutName = cutName;
384 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
385        }
386 +
387 +      tempCut.isVeto = false;
388 +      if(cuts_.at(currentCut).exists("isVeto")){
389 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
390 +        if (isVeto == true) tempCut.isVeto = true;
391 +      }
392 +      subSubDirNames.push_back(subSubDirName);
393        tempCut.name = tempCutName;
394  
395        tempChannel.cuts.push_back(tempCut);
# Line 441 | Line 397 | OSUAnalysis::OSUAnalysis (const edm::Par
397  
398      }//end loop over cuts
399  
400 +    vector<map<string, TH1D*>> oneDHistsTmp;
401 +    vector<map<string, TH2D*>> twoDHistsTmp;
402 +    //book a directory in the output file with the name of the channel
403 +    TFileDirectory subDir = fs_->mkdir( channelName );
404 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
405 +    if(GetPlotsAfterEachCut_){
406 +      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
407 +        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
408 +        directories.push_back(subSubDir);
409 +        map<string, TH1D*> oneDhistoMap;
410 +        oneDHistsTmp.push_back(oneDhistoMap);
411 +        map<string, TH2D*> twoDhistoMap;
412 +        twoDHistsTmp.push_back(twoDhistoMap);
413 +      }
414 +      treeDirectories.push_back(subDir);
415 +      oneDHists_.push_back(oneDHistsTmp);
416 +      twoDHists_.push_back(twoDHistsTmp);
417 +    }
418 +    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
419 +    else{
420 +      map<string, TH1D*> oneDhistoMap;
421 +      oneDHistsTmp.push_back(oneDhistoMap);
422 +      map<string, TH2D*> twoDhistoMap;
423 +      twoDHistsTmp.push_back(twoDhistoMap);
424 +      oneDHists_.push_back(oneDHistsTmp);
425 +      twoDHists_.push_back(twoDHistsTmp);
426 +      directories.push_back(subDir);
427 +      treeDirectories.push_back(subDir);
428 +
429 +    }
430 +
431 +    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
432 +      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
433 +      BNTrees_.push_back(newTree);
434 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
435 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
436 +        vector<float> newVec;
437 +        BNTreeBranchVals_[currentVar.name] = newVec;
438 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
439 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
440 +    }
441 +
442 +    //book all histograms included in the configuration
443 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
444 +
445 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
446 +
447 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
448 +        int numBinsElements = currentHistogram.bins.size();
449 +        int numInputVariables = currentHistogram.inputVariables.size();
450 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
451 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
452 +
453 +        if(numBinsElements == 1){
454 +          if(numBinEdgesX > 1){
455 +            if(numBinEdgesY > 1)
456 +              numBinsElements = 6;
457 +            else
458 +              numBinsElements = 3;
459 +          }
460 +        }
461 +        if(numBinsElements != 3 && numBinsElements !=6){
462 +          cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
463 +          exit(0);
464 +        }
465 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
466 +          cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
467 +          exit(0);
468 +        }
469 +        else if(numBinsElements == 3){
470 +          if (currentHistogram.bins.size () == 3)
471 +            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));
472 +          else
473 +            {
474 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
475 +            }
476 +        }
477 +        else if(numBinsElements == 6){
478 +          if (currentHistogram.bins.size () == 6)
479 +            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));
480 +          else
481 +            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 ());
482 +        }
483 +
484 +
485 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
486 +
487 +        // bin      particle type
488 +        // ---      -------------
489 +        //  0        unmatched
490 +        //  1        u
491 +        //  2        d
492 +        //  3        s
493 +        //  4        c
494 +        //  5        b
495 +        //  6        t
496 +        //  7        e
497 +        //  8        mu
498 +        //  9        tau
499 +        // 10        nu
500 +        // 11        g
501 +        // 12        gamma
502 +        // 13        Z
503 +        // 14        W
504 +        // 15        light meson
505 +        // 16        K meson
506 +        // 17        D meson
507 +        // 18        B meson
508 +        // 19        light baryon
509 +        // 20        strange baryon
510 +        // 21        charm baryon
511 +        // 22        bottom baryon
512 +        // 23        QCD string
513 +        // 24        other
514 +
515 +        vector<TString> labelArray;
516 +        labelArray.push_back("unmatched");
517 +        labelArray.push_back("u");
518 +        labelArray.push_back("d");
519 +        labelArray.push_back("s");
520 +        labelArray.push_back("c");
521 +        labelArray.push_back("b");
522 +        labelArray.push_back("t");
523 +        labelArray.push_back("e");
524 +        labelArray.push_back("#mu");
525 +        labelArray.push_back("#tau");
526 +        labelArray.push_back("#nu");
527 +        labelArray.push_back("g");
528 +        labelArray.push_back("#gamma");
529 +        labelArray.push_back("Z");
530 +        labelArray.push_back("W");
531 +        labelArray.push_back("light meson");
532 +        labelArray.push_back("K meson");
533 +        labelArray.push_back("D meson");
534 +        labelArray.push_back("B meson");
535 +        labelArray.push_back("light baryon");
536 +        labelArray.push_back("strange baryon");
537 +        labelArray.push_back("charm baryon");
538 +        labelArray.push_back("bottom baryon");
539 +        labelArray.push_back("QCD string");
540 +        labelArray.push_back("other");
541 +
542 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
543 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
544 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
545 +          }
546 +          else {
547 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
548 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
549 +          }
550 +        }
551 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
552 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
553 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
554 +        }
555 +
556 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
557 +
558 +
559 +      // Book a histogram for the number of each object type to be plotted.
560 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
561 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
562 +        string currentObject = objectsToPlot.at(currentObjectIndex);
563 +        int maxNum = 10;
564 +        if(currentObject == "mcparticles") maxNum = 50;
565 +        else if(currentObject == "primaryvertexs") maxNum = 50;
566 +
567 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
568 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
569 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
570 +        else if(currentObject == "electron-photon pairs")     currentObject = "electronPhotonPairs";
571 +        else if(currentObject == "muon-photon pairs")         currentObject = "muonPhotonPairs";
572 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
573 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
574 +        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
575 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
576 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
577 +        else if(currentObject == "photon-jet pairs")          currentObject = "photonJetPairs";
578 +        else if(currentObject == "met-jet pairs")             currentObject = "metJetPairs";
579 +        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
580 +        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
581 +        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
582 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
583 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
584 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
585 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
586 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
587 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
588 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
589 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
590 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
591 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
592 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
593 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
594 +
595 +        currentObject.at(0) = toupper(currentObject.at(0));
596 +        string histoName = "num" + currentObject;
597 +
598 +        if(histoName == "numPrimaryvertexs"){
599 +          string newHistoName = histoName + "BeforePileupCorrection";
600 +          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);
601 +          newHistoName = histoName + "AfterPileupCorrection";
602 +          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);
603 +        }
604 +        else
605 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
606 +      }
607 +    }//end of loop over directories
608      channels.push_back(tempChannel);
609      tempChannel.cuts.clear();
446
610    }//end loop over channels
611  
612  
# Line 454 | Line 617 | OSUAnalysis::OSUAnalysis (const edm::Par
617    sort( objectsToCut.begin(), objectsToCut.end() );
618    objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
619  
620 +  produces<map<string, bool> > ("channelDecisions");
621 +
622 + } // end constructor OSUAnalysis::OSUAnalysis()
623  
458 }
624  
625   OSUAnalysis::~OSUAnalysis ()
626   {
627 +
628    // Destroying the CutFlow objects causes the cut flow numbers and time
629    // information to be printed to standard output.
630    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
# Line 467 | Line 633 | OSUAnalysis::~OSUAnalysis ()
633   }
634  
635   void
636 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
636 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
637   {
472
638    // Retrieve necessary collections from the event.
639  
640 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
640 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
641      event.getByLabel (triggers_, triggers);
642  
643 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
643 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
644 >    event.getByLabel (trigobjs_, trigobjs);
645 >
646 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
647      event.getByLabel (jets_, jets);
648  
649 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
649 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
650      event.getByLabel (muons_, muons);
651  
652 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
652 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
653      event.getByLabel (electrons_, electrons);
654  
655 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
655 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
656      event.getByLabel (events_, events);
657  
658 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
658 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
659      event.getByLabel (taus_, taus);
660  
661 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
661 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
662      event.getByLabel (mets_, mets);
663  
664 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
664 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
665      event.getByLabel (tracks_, tracks);
666  
667 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
667 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
668      event.getByLabel (genjets_, genjets);
669  
670 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
670 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
671      event.getByLabel (mcparticles_, mcparticles);
672  
673 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
673 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
674      event.getByLabel (primaryvertexs_, primaryvertexs);
675  
676 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
676 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
677      event.getByLabel (bxlumis_, bxlumis);
678  
679 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
679 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
680      event.getByLabel (photons_, photons);
681  
682 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
682 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
683      event.getByLabel (superclusters_, superclusters);
684  
685 <  if (useTrackCaloRhoCorr_) {  
686 <    // Used only for pile-up correction of by-hand calculation of isolation energy.  
687 <    // This rho collection is not available in all BEANs.  
685 >  if (datasetType_ == "signalMC"){
686 >    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
687 >      event.getByLabel (stops_, stops);
688 >  }
689 >
690 >  if (useTrackCaloRhoCorr_) {
691 >    // Used only for pile-up correction of by-hand calculation of isolation energy.
692 >    // This rho collection is not available in all BEANs.
693      // For description of rho values for different jet reconstruction algorithms, see
694 <    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms  
695 <    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
694 >    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
695 >    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
696    }
697  
698 +  double masterScaleFactor = 1.0;
699  
700    //get pile-up event weight
701 <  double scaleFactor = 1.00;
702 <  if(doPileupReweighting_ && datasetType_ != "data")
703 <    scaleFactor = puWeight_->at (events->at (0).numTruePV);
704 <
705 <  cTauScaleFactor_ = 1.0;
706 < #ifdef DISPLACED_SUSY
707 <  if (datasetType_ == "signalMC")
708 <    cTauScaleFactor_ = cTauWeight_->at (event);
709 < #endif
710 <  scaleFactor *= cTauScaleFactor_;
701 >  if (doPileupReweighting_ && datasetType_ != "data") {
702 >    //for "data" datasets, the numTruePV is always set to -1
703 >    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
704 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
705 >  }
706 >
707 >  stopCTauScaleFactor_ = 1.0;
708 >  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
709 >    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
710 >  masterScaleFactor *= stopCTauScaleFactor_;
711  
712    //loop over all channels
713  
714 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
715    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
716      channel currentChannel = channels.at(currentChannelIndex);
717  
# Line 544 | Line 719 | OSUAnalysis::analyze (const edm::Event &
719      counterMap passingCounter;
720      cumulativeFlags.clear ();
721  
722 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
723 +         iter != BNTreeBranchVals_.end(); iter++) {
724 +      iter->second.clear();  // clear array
725 +    }
726 +
727      bool triggerDecision = true;
728 <    if(currentChannel.triggers.size() != 0){  //triggers specified
729 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
728 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
729 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
730        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
731      }
732  
733      //loop over all cuts
554
555
556
734      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
735        cut currentCut = currentChannel.cuts.at(currentCutIndex);
559
736        for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
737          string currentObject = objectsToCut.at(currentObjectIndex);
738  
739          //initialize maps to get ready to set cuts
740 <        individualFlags[currentObject].push_back (vector<bool> ());
741 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
740 >        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
741 >        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
742  
743        }
744        for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
# Line 571 | Line 747 | OSUAnalysis::analyze (const edm::Event &
747          int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
748  
749  
750 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
751 <
752 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
577 <
750 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
751 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
752 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
753          else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
754 +        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
755          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
756          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
757          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 587 | Line 763 | OSUAnalysis::analyze (const edm::Event &
763          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
764          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
765          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
766 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
767 +
768  
769  
770          else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
# Line 595 | Line 773 | OSUAnalysis::analyze (const edm::Event &
773                                                                     "muon-muon pairs");
774  
775          else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
776 <                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
777 <                                                                   cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
778 <                                                                   "muon-secondary muon pairs");
776 >                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
777 >                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
778 >                                                                             "muon-secondary muon pairs");
779 >
780 >        else if(currentObject == "muon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
781 >                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
782 >                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
783 >                                                                             "muon-secondary jet pairs");
784 >        else if(currentObject == "photon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
785 >                                                                             cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
786 >                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
787 >                                                                             "photon-secondary jet pairs");
788 >
789 >        else if(currentObject == "electron-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
790 >                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
791 >                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
792 >                                                                             "electron-secondary jet pairs");
793 >
794 >        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
795 >                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
796 >                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
797 >                                                                                     "electron-secondary electron pairs");
798  
799          else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
800                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
# Line 607 | Line 804 | OSUAnalysis::analyze (const edm::Event &
804                                                                         cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
805                                                                         cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
806                                                                         "electron-muon pairs");
807 <        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
808 <                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
809 <                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
810 <                                                                     "track-event pairs");
811 <        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
812 <                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
813 <                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
814 <                                                                        "electron-track pairs");
815 <        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
816 <                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
817 <                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
818 <                                                                    "muon-track pairs");
819 <        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
820 <                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
821 <                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
822 <                                                                  "muon-tau pairs");
823 <        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
824 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
825 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
826 <                                                                 "tau-tau pairs");
827 <        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
807 >        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
808 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
809 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
810 >                                                                 "jet-jet pairs");
811 >        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
812 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
813 >                                                                 cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex),\
814 >                                                                 "jet-secondary jet pairs");
815 >        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
816 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
817 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
818 >                                                                      "electron-jet pairs");
819 >        else if(currentObject == "electron-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), \
820 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
821 >                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
822 >                                                                      "electron-photon pairs");
823 >        else if(currentObject == "photon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
824 >                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
825 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
826 >                                                                      "photon-jet pairs");
827 >        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
828 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
829 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
830 >                                                                  "muon-jet pairs");
831 >        else if(currentObject == "met-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
832 >                                                                  cumulativeFlags.at("mets").at(flagsForPairCutsIndex), \
833 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
834 >                                                                  "met-jet pairs");
835 >        else if(currentObject == "muon-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
836 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
837 >                                                                  cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
838 >                                                                  "muon-photon pairs");
839 >        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
840 >                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
841 >                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
842 >                                                                     "track-event pairs");
843 >        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
844 >                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
845 >                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
846 >                                                                        "electron-track pairs");
847 >        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
848 >                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
849 >                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
850 >                                                                    "muon-track pairs");
851 >        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
852 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
853 >                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
854 >                                                                  "muon-tau pairs");
855 >        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
856                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
857 <                                                                 cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
858 <                                                                 "tau-track pairs");
859 <        
860 <        
857 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
858 >                                                                 "tau-tau pairs");
859 >        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
860 >                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
861 >                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
862 >                                                                   "tau-track pairs");
863 >        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
864 >                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
865 >                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
866 >                                                                          "electron-trigobj pairs");
867 >        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
868 >                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
869 >                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
870 >                                                                      "muon-trigobj pairs");
871 >
872 >        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
873        }
874  
875  
876  
877      }//end loop over all cuts
641
642
878      //use cumulative flags to apply cuts at event level
879  
880 +    //a vector to store cumulative cut descisions after each cut.
881 +    vector<bool> eventPassedPreviousCuts;
882      bool eventPassedAllCuts = true;
646
883      //apply trigger (true if none were specified)
884      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
885  
650
886      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
887  
888        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 655 | Line 890 | OSUAnalysis::analyze (const edm::Event &
890        int numberPassing = 0;
891  
892        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
893 <        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
893 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
894        }
895        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
896        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
897        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
898 +      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
899 +    }
900 +    double scaleFactor = masterScaleFactor;
901 +
902 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
903 +    if(applyLeptonSF_ && datasetType_ != "data"){
904 +      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
905 +        flagPair muonFlags;
906 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
907 +          if (cumulativeFlags.at("muons").at(i).size()){
908 +            muonFlags = cumulativeFlags.at("muons").at(i);
909 +            break;
910 +          }
911 +        }
912 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
913 +          if(!muonFlags.at(muonIndex).second) continue;
914 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
915 +        }
916 +      }
917 +      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
918 +        flagPair electronFlags;
919 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
920 +          if (cumulativeFlags.at("electrons").at(i).size()){
921 +            electronFlags = cumulativeFlags.at("electrons").at(i);
922 +            break;
923 +          }
924 +        }
925 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
926 +          if(!electronFlags.at(electronIndex).second) continue;
927 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
928 +        }
929 +      }
930 +    }
931 +    if(applyBtagSF_ && datasetType_ != "data"){
932 +     if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
933 +       flagPair jetFlags;
934 +        vector<double> jetSFs;
935 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
936 +          if (cumulativeFlags.at("jets").at(i).size()){
937 +            jetFlags = cumulativeFlags.at("jets").at(i);
938 +            break;
939 +          }
940 +        }
941 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
942 +          if(!jetFlags.at(jetIndex).second) continue;
943 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour);
944 +          jetSFs.push_back(jetSFTmp);
945 +        }
946 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_, maxBtag_ );
947 +      }
948 +    }
949 +    scaleFactor *= muonScaleFactor_;
950 +    scaleFactor *= electronScaleFactor_;
951 +    scaleFactor *= bTagScaleFactor_;
952 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
953  
954 +    if (printEventInfo_) {
955 +      // Write information about event to screen, for testing purposes.
956 +      cout << "Event passed all cuts in channel " <<  currentChannel.name
957 +           << ": run="  << events->at(0).run
958 +           << "  lumi=" << events->at(0).lumi
959 +           << "  event=" << events->at(0).evt
960 +           << endl;
961      }
962  
666    //     if(datasetType_ != "data") {
667    //       scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
668    //       scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
669    //     }
963  
964 <    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
964 >    //filling histograms
965 >    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
966 >      uint currentDir;
967 >      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
968 >      else{
969 >        currentDir = currentCut;
970 >      }
971  
972  
973 +      if(eventPassedPreviousCuts.at(currentDir)){
974  
975 <    if(!eventPassedAllCuts)continue;
975 >        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
976 >          histogram currentHistogram = histograms.at(histogramIndex);
977  
978 <    if (printEventInfo_) {
979 <      // Write information about event to screen, for testing purposes.  
980 <      cout << "Event passed all cuts in channel " <<  currentChannel.name
981 <           << ": run="  << events->at(0).run
982 <           << "  lumi=" << events->at(0).lumi
983 <           << "  event=" << events->at(0).evt
984 <           << endl;  
985 <    }
978 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) cout << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
979 >
980 >          if(currentHistogram.inputVariables.size() == 1){
981 >            TH1D* histo;
982 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
983 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
984 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
985 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
986 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
987 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
988 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
989 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
990 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
991 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
992 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
993 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
994 >             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
995 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
996 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
997 >             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
998 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
999 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1000 >             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1001 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1002 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1003 >
1004 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1005 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
1006 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
1007 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1008 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
1009 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
1010 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1011 >             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1012 >                                                                                                     cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1013 >                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1014 >
1015 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1016 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1017 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1018 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
1019 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
1020 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1021 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
1022 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1023 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1024 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(), \
1025 >                                                                                              cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1026 >                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1027 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
1028 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1029 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1030 >            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
1031 >                                                                                          cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1032 >                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1033 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(), \
1034 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1035 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1036 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(), \
1037 >                                                                                          cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1038 >                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1039 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1040 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1041 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1042 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1043 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1044 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1045 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1046 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1047 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1048 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1049 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1050 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1051 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1052 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1053 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1054 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1055 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1056 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1057 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1058 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1059 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1060 >
1061 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1062 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1063 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1064 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1065 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1066 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1067 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1068 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1069 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1070 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1071 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1072 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1073 >          }
1074 >          else if(currentHistogram.inputVariables.size() == 2){
1075 >            TH2D* histo;
1076 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1077 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1078 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1079 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1080 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1081 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1082 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1083 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1084 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1085 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1086 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1087 >            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1088 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1089 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1090 >            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1091 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1092 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1093 >            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1094 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1095 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1096 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1097 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1098 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1099 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1100 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1101 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1102 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1103 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1104 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1105 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1106 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1107 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1108 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1109 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1110 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1111 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1112 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1113 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(), \
1114 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1115 >                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1116 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1117 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1118 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1119 >            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1120 >                                                                                         cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1121 >                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1122 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1123 >                                                                                          cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1124 >                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1125 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1126 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1127 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1128 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1129 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1130 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1131 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1132 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1133 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1134 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1135 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1136 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1137 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1138 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1139 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1140 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1141 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1142 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1143 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1144 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1145 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1146 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1147 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1148 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1149 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1150 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1151 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1152 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1153 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1154 >                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1155 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1156 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1157 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1158 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1159 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1160 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1161 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1162 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1163 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1164 >          }
1165  
1166 +        }
1167  
687    //filling histograms
688    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
689      histogram currentHistogram = histograms.at(histogramIndex);
1168  
1169 <      if(currentHistogram.inputVariables.size() == 1){
1170 <        TH1D* histo;
1171 <        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
1172 <
1173 <        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
1174 <        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
1175 <        else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").back(),scaleFactor);
1176 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1177 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
1178 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
1179 <        else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1180 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("secondary muons").back(), \
1181 <                                                                                       cumulativeFlags.at("muon-secondary muon pairs").back(),scaleFactor);
1182 <        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
1183 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
1184 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
1185 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
1186 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
1187 <                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
1188 <                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
1189 <        else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),        
1190 <                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),  
1191 <                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);      
1192 <        else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),        
1193 <                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),  
1194 <                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);      
1195 <        else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),    
1196 <                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),      
1197 <                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);  
1198 <        else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),      
1199 <                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),        
1200 <                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);    
1201 <        else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1202 <                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("tracks").back(),
1203 <                                                                                     cumulativeFlags.at("tau-track pairs").back(),scaleFactor);
1204 <
1205 <        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
1206 <        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
1207 <        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
1208 <        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
1209 <        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
1210 <        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
1211 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
1212 <        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
1213 <        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
1214 <        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
1215 <      }
1216 <      else if(currentHistogram.inputVariables.size() == 2){
1217 <        TH2D* histo;
1218 <        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
1219 <
1220 <        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
1221 <        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
1222 <        else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").back(),scaleFactor);
1223 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1224 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
1225 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
748 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
749 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("secondary muons").back(), \
750 <                                                                                       cumulativeFlags.at("muon-secondary muon pairs").back(),scaleFactor);
751 <        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
752 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
753 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
754 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
755 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
756 <                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
757 <                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
758 <        else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),        
759 <                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),          
760 <                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);      
761 <        else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),        
762 <                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),          
763 <                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);      
764 <        else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),    
765 <                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),      
766 <                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);  
767 <        else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),      
768 <                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),        
769 <                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);    
770 <        else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
771 <                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("tracks").back(),
772 <                                                                                     cumulativeFlags.at("tau-track pairs").back(),scaleFactor);
773 <        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
774 <        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
775 <        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
776 <        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
777 <        else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
778 <                                                                                         cumulativeFlags.at("tracks").back(),cumulativeFlags.at("events").back(),
779 <                                                                                         cumulativeFlags.at("track-event pairs").back(),scaleFactor);  
780 <        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
781 <        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
782 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
783 <        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
784 <        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
785 <        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
786 <      }
787 <    }
1169 >        //fills histograms with the sizes of collections
1170 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1171 >
1172 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1173 >          string objectToPlot = "";
1174 >
1175 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1176 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1177 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1178 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1179 >          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1180 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1181 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1182 >          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1183 >          else if(currentObject == "muon-photon pairs")                  objectToPlot = "muonPhotonPairs";
1184 >          else if(currentObject == "photon-jet pairs")                   objectToPlot = "photonJetPairs";
1185 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1186 >          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1187 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1188 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1189 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1190 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1191 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1192 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1193 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1194 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1195 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1196 >          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1197 >          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1198 >          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1199 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1200 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1201 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1202 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1203 >          else objectToPlot = currentObject;
1204 >
1205 >          string tempCurrentObject = objectToPlot;
1206 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1207 >          string histoName = "num" + tempCurrentObject;
1208 >
1209 >
1210 >          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1211 >            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1212 >            int numToPlot = 0;
1213 >            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1214 >              if(lastCutFlags.at(currentFlag).second) numToPlot++;
1215 >            }
1216 >
1217 >            if(objectToPlot == "primaryvertexs"){
1218 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1219 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1220 >            }
1221 >            else {
1222 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1223 >            }
1224 >          }
1225 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1226  
1227  
1228 +      } // end if(eventPassedPreviousCuts.at(currentDir))
1229 +    } // end loop over cuts
1230  
1231 <    //fills histograms with the sizes of collections
1232 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1233 <
1234 <      string currentObject = objectsToPlot.at(currentObjectIndex);
1235 <
1236 <      string objectToPlot = "";  
1237 <
1238 <      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().  
1239 <      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
1240 <      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
1241 <      else if(currentObject == "electron-muon pairs")     objectToPlot = "electronMuonPairs";
1242 <      else if(currentObject == "electron-track pairs")    objectToPlot = "electronTrackPairs";
1243 <      else if(currentObject == "muon-track pairs")        objectToPlot = "muonTrackPairs";      
1244 <      else if(currentObject == "muon-tau pairs")          objectToPlot = "muonTauPairs";        
1245 <      else if(currentObject == "tau-tau pairs")           objectToPlot = "ditauPairs";
1246 <      else if(currentObject == "tau-track pairs")         objectToPlot = "tauTrackPairs";
1247 <      else if(currentObject == "track-event pairs")       objectToPlot = "trackEventPairs";  
1248 <      else if(currentObject == "muon-secondary muon pairs")       objectToPlot = "muonSecondaryMuonPairs";  
1249 <      else if(currentObject == "secondary muons")         objectToPlot = "secondaryMuons";  
1250 <      else objectToPlot = currentObject;
1251 <
1252 <      string tempCurrentObject = objectToPlot;
1253 <      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));  
1254 <      string histoName = "num" + tempCurrentObject;
1255 <
1256 <      //set position of primary vertex in event, in order to calculate quantities relative to it
1257 <      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1258 <        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
1259 <        int numToPlot = 0;
1260 <        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1261 <          if(lastCutFlags.at(currentFlag)) numToPlot++;
822 <        }
823 <        if(objectToPlot == "primaryvertexs"){
824 <          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
825 <          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
826 <        }
827 <        else {
828 <          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
829 <        }
830 <      }
831 <      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
832 <      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
833 <      else if(objectToPlot == "secondaryMuons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
834 <      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
835 <      else if(objectToPlot == "muonSecondaryMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
836 <      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
837 <      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
838 <      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
839 <      else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
840 <      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
841 <      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
842 <      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
843 <      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
844 <      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
845 <      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
846 <      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
847 <      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
848 <      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
849 <      else if(objectToPlot == "primaryvertexs"){
850 <        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
851 <        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
852 <      }
1231 >    if (!useEDMFormat_ && eventPassedAllCuts){
1232 >      // Assign BNTree variables
1233 >      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1234 >        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1235 >        string coll = brSpecs.inputCollection;
1236 >        if (cumulativeFlags.count(coll) == 0) cout << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1237 >
1238 >        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1239 >        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1240 >        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1241 >        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1242 >        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1243 >        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1244 >        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1245 >        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1246 >        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1247 >        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1248 >        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1249 >        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1250 >        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1251 >        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1252 >        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1253 >        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1254 >        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1255 >        else if(coll == "stops"
1256 >                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1257 >      } // end loop over branches
1258 >
1259 >      if (!BNTrees_.at(currentChannelIndex)) { cout << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1260 >      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1261 >    }
1262  
1263 <    } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1263 >    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1264  
1265 <  } //end loop over channel
1265 >  } // end loop over channel
1266  
1267 <  masterCutFlow_->fillCutFlow(scaleFactor);
1267 >  masterCutFlow_->fillCutFlow(masterScaleFactor);
1268 >
1269 >  event.put (channelDecisions, "channelDecisions");
1270  
1271   } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1272  
# Line 872 | Line 1283 | OSUAnalysis::evaluateComparison (double
1283    else if(comparison == "==") return testValue == cutValue;
1284    else if(comparison == "=") return testValue == cutValue;
1285    else if(comparison == "!=") return testValue != cutValue;
1286 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1286 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1287 >
1288 > }
1289 >
1290 > bool
1291 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1292 >
1293 >
1294 >  if(comparison == ">")       return testValue >  cutValue;
1295 >  else if(comparison == ">=") return testValue >= cutValue;
1296 >  else if(comparison == "<")  return testValue <  cutValue;
1297 >  else if(comparison == "<=") return testValue <= cutValue;
1298 >  else if(comparison == "==") return testValue == cutValue;
1299 >  else if(comparison == "=") return testValue == cutValue;
1300 >  else if(comparison == "!=") return testValue != cutValue;
1301 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1302  
1303   }
1304  
1305   bool
1306 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1306 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1307  
1308 +  //initialize to false until a chosen trigger is passed
1309    bool triggerDecision = false;
1310  
1311 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1312 <    {
1313 <      if(trigger->pass != 1) continue;
1314 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1315 <        {
1316 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1317 <            triggerDecision = true;
1318 <          }
1319 <        }
1311 >  if (printAllTriggers_) cout << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1312 >  //loop over all triggers defined in the event
1313 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1314 >
1315 >    if (printAllTriggers_) cout << "   " << trigger->name << endl;
1316 >
1317 >    //we're only interested in triggers that actually passed
1318 >    if(trigger->pass != 1) continue;
1319 >
1320 >    //if the event passes one of the veto triggers, exit and return false
1321 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1322 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1323 >    }
1324 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1325 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1326 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1327      }
1328 <  return triggerDecision;
1328 >  }
1329 >
1330 >  printAllTriggers_ = false;  // only print triggers once, not every event
1331  
1332 +  //if none of the veto triggers fired:
1333 +  //return the OR of all the chosen triggers
1334 +  if (triggersToTest.size() != 0) return triggerDecision;
1335 +  //or if no triggers were defined return true
1336 +  else return true;
1337   }
1338  
1339 < std::vector<std::string>
1339 >
1340 > vector<string>
1341   OSUAnalysis::splitString (string inputString){
1342  
1343 <  std::stringstream stringStream(inputString);
1344 <  std::istream_iterator<std::string> begin(stringStream);
1345 <  std::istream_iterator<std::string> end;
1346 <  std::vector<std::string> stringVector(begin, end);
1343 >  stringstream stringStream(inputString);
1344 >  istream_iterator<string> begin(stringStream);
1345 >  istream_iterator<string> end;
1346 >  vector<string> stringVector(begin, end);
1347    return stringVector;
1348  
1349   }
1350  
1351  
1352   void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1353 <  // Set two object strings from the tempInputCollection string,
1354 <  // For example, if tempInputCollection is "electron-muon pairs",
1355 <  // then obj1 = "electrons" and obj2 = "muons".  
1356 <  // Note that the objects have an "s" appended.  
1353 >  // Set two object strings from the tempInputCollection string,
1354 >  // For example, if tempInputCollection is "electron-muon pairs",
1355 >  // then obj1 = "electrons" and obj2 = "muons".
1356 >  // Note that the objects have an "s" appended.
1357  
1358    int dashIndex = tempInputCollection.find("-");
1359    int spaceIndex = tempInputCollection.find_last_of(" ");
1360    int secondWordLength = spaceIndex - dashIndex;
1361 <  obj1 = tempInputCollection.substr(0,dashIndex) + "s";  
1361 >  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1362    obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1363 <  
1364 < }
1363 >
1364 > }
1365  
1366  
1367   string OSUAnalysis::getObjToGet(string obj) {
1368    // Return the string corresponding to the object to get for the given obj string.
1369 <  // Right now this only handles the case in which obj contains "secondary",
1370 <  // e.g, "secondary muons".  
1371 <  // Note that "s" is NOT appended.  
930 <  
931 <  if (obj.find("secondary")==std::string::npos) return obj;  // "secondary" is not found  
932 <  int firstSpaceIndex = obj.find_first_of(" ");  
933 <  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1369 >  // Right now this only handles the case in which obj contains "secondary",
1370 >  // e.g, "secondary muons".
1371 >  // Note that "s" is NOT appended.
1372  
1373 < }  
1373 >  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1374 >  int firstSpaceIndex = obj.find_first_of(" ");
1375 >  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1376  
1377 + }
1378  
1379  
1380 + //!jet valueLookup
1381   double
1382 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1382 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1383  
1384    double value = 0.0;
1385    if(variable == "energy") value = object->energy;
# Line 1056 | Line 1498 | OSUAnalysis::valueLookup (const BNjet* o
1498    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1499    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1500  
1501 +  //user defined variable
1502 +  else if(variable == "disappTrkLeadingJetID") {
1503 +    value = object->pt > 110
1504 +      && fabs(object->eta) < 2.4
1505 +      && object->chargedHadronEnergyFraction > 0.2
1506 +      && object->neutralHadronEnergyFraction < 0.7
1507 +      && object->chargedEmEnergyFraction < 0.5
1508 +      && object->neutralEmEnergyFraction < 0.7;
1509 +  }
1510  
1511 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1511 >  else if(variable == "disappTrkSubLeadingJetID") {
1512 >    value = object->pt > 30
1513 >      && fabs(object->eta) < 4.5
1514 >      && object->neutralHadronEnergyFraction < 0.7
1515 >      && object->chargedEmEnergyFraction < 0.5;
1516 >  }
1517 >
1518 >  else if(variable == "dPhiMet") {
1519 >    if (const BNmet *met = chosenMET ()) {
1520 >      value = deltaPhi (object->phi, met->phi);
1521 >    } else value = -999;
1522 >  }
1523 >
1524 >
1525 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1526  
1527    value = applyFunction(function, value);
1528  
1529    return value;
1530 < }
1066 <
1530 > } // end jet valueLookup
1531  
1532  
1533 + //!muon valueLookup
1534   double
1535 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1535 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1536  
1537    double value = 0.0;
1538    if(variable == "energy") value = object->energy;
# Line 1222 | Line 1687 | OSUAnalysis::valueLookup (const BNmuon*
1687    else if(variable == "time_ndof") value = object->time_ndof;
1688  
1689    //user-defined variables
1690 +  else if(variable == "looseID") {
1691 +    value = object->pt > 10 &&
1692 +      (object->isGlobalMuon  > 0 ||
1693 +       object->isTrackerMuon > 0);
1694 +  }
1695    else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1696    else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1697    else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1698    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1699    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1700    else if(variable == "metMT") {
1701 <    const BNmet *met = chosenMET ();
1232 <    if (met)
1701 >    if (const BNmet *met = chosenMET ())
1702        {
1703 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1704 <          p2 (met->px, met->py, 0.0, met->pt);
1236 <
1237 <        value = (p1 + p2).Mt ();
1703 >        double dPhi = deltaPhi (object->phi, met->phi);
1704 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1705        }
1706      else
1707        value = -999;
# Line 1352 | Line 1819 | OSUAnalysis::valueLookup (const BNmuon*
1819      value = object->isGlobalMuon > 0                \
1820        && object->isPFMuon > 0                        \
1821        && object->normalizedChi2 < 10                \
1822 <                                  && object->numberOfValidMuonHits > 0        \
1822 >      && object->numberOfValidMuonHits > 0        \
1823        && object->numberOfMatchedStations > 1        \
1824        && fabs(object->correctedD0Vertex) < 0.2        \
1825        && fabs(object->correctedDZ) < 0.5        \
# Line 1361 | Line 1828 | OSUAnalysis::valueLookup (const BNmuon*
1828    }
1829    else if(variable == "tightIDdisplaced"){
1830      value = object->isGlobalMuon > 0                \
1831 +      && object->isPFMuon > 0                        \
1832        && object->normalizedChi2 < 10                \
1833 <                                  && object->numberOfValidMuonHits > 0        \
1833 >      && object->numberOfValidMuonHits > 0        \
1834        && object->numberOfMatchedStations > 1        \
1835        && object->numberOfValidPixelHits > 0        \
1836        && object->numberOfLayersWithMeasurement > 5;
1837    }
1838  
1839 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1839 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1840  
1841    else if(variable == "genMatchedPdgId"){
1842      int index = getGenMatchedParticleIndex(object);
# Line 1388 | Line 1856 | OSUAnalysis::valueLookup (const BNmuon*
1856    }
1857    else if(variable == "genMatchedMotherIdReverse"){
1858      int index = getGenMatchedParticleIndex(object);
1859 <    if(index == -1) value = 23;
1860 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1859 >    if(index == -1) value = 24;
1860 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1861    }
1862    else if(variable == "genMatchedGrandmotherId"){
1863      int index = getGenMatchedParticleIndex(object);
# Line 1401 | Line 1869 | OSUAnalysis::valueLookup (const BNmuon*
1869      }
1870      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1871    }
1872 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1873 +    int index = getGenMatchedParticleIndex(object);
1874 +    if(index == -1) value = 24;
1875 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1876 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1877 +      if(motherIndex == -1) value = 24;
1878 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1879 +    }
1880 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1881 +  }
1882 +  else if(variable == "pfMuonsFromVertex"){
1883 +    double d0Error, dzError;
1884  
1885 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1886 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1887 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1888 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1889 +      || fabs (object->correctedDZ / dzError) > 99.0;
1890 +    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1891 +  }
1892  
1893  
1894 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1894 >
1895 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1896  
1897    value = applyFunction(function, value);
1898  
1899    return value;
1900 < }
1900 > } // end muon valueLookup
1901  
1902  
1903 + //!electron valueLookup
1904   double
1905 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1905 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1906  
1907    double value = 0.0;
1908    if(variable == "energy") value = object->energy;
# Line 1579 | Line 2068 | OSUAnalysis::valueLookup (const BNelectr
2068    else if(variable == "detIso") value = (object->trackIso) / object->pt;
2069    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2070    else if(variable == "metMT") {
2071 <    const BNmet *met = chosenMET ();
1583 <    if (met)
2071 >    if (const BNmet *met = chosenMET ())
2072        {
2073 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
2074 <          p2 (met->px, met->py, 0.0, met->pt);
1587 <
1588 <        value = (p1 + p2).Mt ();
2073 >        double dPhi = deltaPhi (object->phi, met->phi);
2074 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2075        }
2076      else
2077        value = -999;
# Line 1677 | Line 2163 | OSUAnalysis::valueLookup (const BNelectr
2163        }
2164    }
2165  
2166 +  else if(variable == "looseID"){
2167 +    value = object->pt > 10
2168 +      && object->mvaNonTrigV0 > 0;
2169 +      }
2170    else if(variable == "correctedD0VertexInEBPositiveCharge"){
2171      if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2172      else value = -999;
# Line 1750 | Line 2240 | OSUAnalysis::valueLookup (const BNelectr
2240    }
2241  
2242  
2243 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2243 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2244  
2245    else if(variable == "genMatchedPdgId"){
2246      int index = getGenMatchedParticleIndex(object);
# Line 1771 | Line 2261 | OSUAnalysis::valueLookup (const BNelectr
2261    }
2262    else if(variable == "genMatchedMotherIdReverse"){
2263      int index = getGenMatchedParticleIndex(object);
2264 <    if(index == -1) value = 23;
2265 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2264 >    if(index == -1) value = 24;
2265 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2266    }
2267    else if(variable == "genMatchedGrandmotherId"){
2268      int index = getGenMatchedParticleIndex(object);
# Line 1784 | Line 2274 | OSUAnalysis::valueLookup (const BNelectr
2274      }
2275      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2276    }
2277 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2278 +    int index = getGenMatchedParticleIndex(object);
2279 +    if(index == -1) value = 24;
2280 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2281 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2282 +      if(motherIndex == -1) value = 24;
2283 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2284 +    }
2285 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2286 +  }
2287 +  else if(variable == "pfElectronsFromVertex"){
2288 +    double d0Error, dzError;
2289  
2290 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2291 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2292 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2293 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2294 +      || fabs (object->correctedDZ / dzError) > 99.0;
2295 +    value = !value;
2296 +  }
2297  
2298  
2299 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2299 >
2300 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2301  
2302    value = applyFunction(function, value);
2303  
2304    return value;
2305 < }
2305 > } // end electron valueLookup
2306  
2307  
2308 + //!event valueLookup
2309   double
2310 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2310 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2311  
2312    double value = 0.0;
2313  
# Line 1865 | Line 2376 | OSUAnalysis::valueLookup (const BNevent*
2376    else if(variable == "id2") value = object->id2;
2377    else if(variable == "evt") value = object->evt;
2378    else if(variable == "puScaleFactor"){
2379 <    if(datasetType_ != "data")
2379 >    if(doPileupReweighting_ && datasetType_ != "data")
2380        value = puWeight_->at (events->at (0).numTruePV);
2381      else
2382        value = 1.0;
2383    }
2384 <  else if(variable == "muonScaleFactor"){
2385 <    if(datasetType_ != "data")
2386 <      //      value = muonSFWeight_->at (chosenMuon ()->eta);
2387 <      value = 1.0;
2388 <    else
1878 <      value = 1.0;
1879 <  }
1880 <  else if(variable == "electronScaleFactor"){
1881 <    if(datasetType_ != "data")
1882 <      //      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1883 <      value = 1.0;
1884 <    else
1885 <      value = 1.0;
1886 <  }
1887 <  else if(variable == "cTauScaleFactor")
1888 <    value = cTauScaleFactor_;
1889 <
1890 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2384 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2385 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2386 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2387 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2388 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2389  
2390    value = applyFunction(function, value);
2391  
2392    return value;
2393 < }
2393 > } // end event valueLookup
2394 >
2395  
2396 + //!tau valueLookup
2397   double
2398 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2398 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2399  
2400    double value = 0.0;
2401  
# Line 1939 | Line 2439 | OSUAnalysis::valueLookup (const BNtau* o
2439    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2440    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2441  
2442 +  else if (variable == "looseHadronicID") {
2443 +    value = object->pt > 10
2444 +      && object->eta < 2.3
2445 +      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2446 +      && object->HPSdecayModeFinding > 0
2447 +      && object->HPSagainstElectronLoose > 0
2448 +      && object->HPSagainstMuonTight > 0;
2449 +  }
2450  
2451 <
1944 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2451 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2452  
2453    else if(variable == "genMatchedPdgId"){
2454      int index = getGenMatchedParticleIndex(object);
# Line 1961 | Line 2468 | OSUAnalysis::valueLookup (const BNtau* o
2468    }
2469    else if(variable == "genMatchedMotherIdReverse"){
2470      int index = getGenMatchedParticleIndex(object);
2471 <    if(index == -1) value = 23;
2472 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2471 >    if(index == -1) value = 24;
2472 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2473    }
2474    else if(variable == "genMatchedGrandmotherId"){
2475      int index = getGenMatchedParticleIndex(object);
# Line 1974 | Line 2481 | OSUAnalysis::valueLookup (const BNtau* o
2481      }
2482      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2483    }
2484 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2485 +    int index = getGenMatchedParticleIndex(object);
2486 +    if(index == -1) value = 24;
2487 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2488 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2489 +      if(motherIndex == -1) value = 24;
2490 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2491 +    }
2492 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2493 +  }
2494  
2495  
2496 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2496 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2497  
2498    value = applyFunction(function, value);
2499  
2500    return value;
2501 < }
2501 > } // end tau valueLookup
2502 >
2503  
2504 + //!met valueLookup
2505   double
2506 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2506 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2507  
2508    double value = 0.0;
2509  
# Line 2048 | Line 2567 | OSUAnalysis::valueLookup (const BNmet* o
2567    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2568    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2569  
2570 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2570 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2571  
2572    value = applyFunction(function, value);
2573  
2574    return value;
2575 < }
2575 > } // end met valueLookup
2576  
2577 +
2578 + //!track valueLookup
2579   double
2580 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2580 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2581  
2582    double value = 0.0;
2583    double pMag = sqrt(object->pt * object->pt +
2584 <                     object->pz * object->pz);
2585 <  
2584 >                     object->pz * object->pz);
2585 >
2586    if(variable == "pt") value = object->pt;
2587    else if(variable == "px") value = object->px;
2588    else if(variable == "py") value = object->py;
# Line 2080 | Line 2601 | OSUAnalysis::valueLookup (const BNtrack*
2601    else if(variable == "numValidHits") value = object->numValidHits;
2602    else if(variable == "isHighPurity") value = object->isHighPurity;
2603  
2083
2604    //additional BNs info for disappTrks
2605 <  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2606 <  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2607 <  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2608 <  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2609 <  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2610 <  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2611 <  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2612 <  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2093 <  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2605 >  else if(variable == "caloEMDeltaRp3")     value = object->caloEMDeltaRp3;
2606 >  else if(variable == "caloHadDeltaRp3")    value = object->caloHadDeltaRp3;
2607 >  else if(variable == "caloEMDeltaRp4")     value = object->caloEMDeltaRp4;
2608 >  else if(variable == "caloHadDeltaRp4")    value = object->caloHadDeltaRp4;
2609 >  else if(variable == "caloEMDeltaRp5")     value = object->caloEMDeltaRp5;
2610 >  else if(variable == "caloHadDeltaRp5")    value = object->caloHadDeltaRp5;
2611 >  else if(variable == "nHitsMissingOuter")  value = object->nHitsMissingOuter;
2612 >  else if(variable == "nHitsMissingInner")  value = object->nHitsMissingInner;
2613    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2614 <  
2614 >  else if(variable == "depTrkRp3")          value = object->depTrkRp3;
2615 >  else if(variable == "depEcalRp3")         value = object->depEcalRp3;
2616 >  else if(variable == "depHcalRp3")         value = object->depHcalRp3;
2617 >  else if(variable == "depHoRp3")           value = object->depHoRp3;
2618 >  else if(variable == "nTracksRp3")         value = object->nTracksRp3;
2619 >  else if(variable == "trackerVetoPtRp3")   value = object->trackerVetoPtRp3;
2620 >  else if(variable == "emVetoEtRp3")        value = object->emVetoEtRp3;
2621 >  else if(variable == "hadVetoEtRp3")       value = object->hadVetoEtRp3;
2622 >  else if(variable == "hoVetoEtRp3")        value = object->hoVetoEtRp3;
2623 >  else if(variable == "depTrkRp5")          value = object->depTrkRp5;
2624 >  else if(variable == "depEcalRp5")         value = object->depEcalRp5;
2625 >  else if(variable == "depHcalRp5")         value = object->depHcalRp5;
2626 >  else if(variable == "depHoRp5")           value = object->depHoRp5;
2627 >  else if(variable == "nTracksRp5")         value = object->nTracksRp5;
2628 >  else if(variable == "trackerVetoPtRp5")   value = object->trackerVetoPtRp5;
2629 >  else if(variable == "emVetoEtRp5")        value = object->emVetoEtRp5;
2630 >  else if(variable == "hadVetoEtRp5")       value = object->hadVetoEtRp5;
2631 >  else if(variable == "hoVetoEtRp5")        value = object->hoVetoEtRp5;
2632  
2633    //user defined variables
2634    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;
2635    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2636 +  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2637    else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2638    else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2639 <  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);  
2640 <  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;  
2639 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2640 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2641    else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2642    else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2643    else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2644    else if(variable == "ptError")                    value = object->ptError;
2645    else if(variable == "ptRes")                      value = getTrkPtRes(object);
2646 <  else if (variable == "d0wrtPV"){      
2647 <    double vx = object->vx - chosenVertex ()->x,        
2648 <      vy = object->vy - chosenVertex ()->y,      
2649 <      px = object->px,  
2650 <      py = object->py,  
2651 <      pt = object->pt;  
2652 <    value = (-vx * py + vy * px) / pt;  
2653 <  }      
2654 <  else if (variable == "dZwrtPV"){      
2655 <    double vx = object->vx - chosenVertex ()->x,        
2656 <      vy = object->vy - chosenVertex ()->y,      
2657 <      vz = object->vz - chosenVertex ()->z,      
2658 <      px = object->px,  
2659 <      py = object->py,  
2660 <      pz = object->pz,  
2661 <      pt = object->pt;  
2662 <    value = vz - (vx * px + vy * py)/pt * (pz/pt);      
2663 <  }    
2664 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2646 >  else if (variable == "d0wrtPV"){
2647 >    double vx = object->vx - chosenVertex ()->x,
2648 >      vy = object->vy - chosenVertex ()->y,
2649 >      px = object->px,
2650 >      py = object->py,
2651 >      pt = object->pt;
2652 >    value = (-vx * py + vy * px) / pt;
2653 >  }
2654 >  else if (variable == "dZwrtPV"){
2655 >    double vx = object->vx - chosenVertex ()->x,
2656 >      vy = object->vy - chosenVertex ()->y,
2657 >      vz = object->vz - chosenVertex ()->z,
2658 >      px = object->px,
2659 >      py = object->py,
2660 >      pz = object->pz,
2661 >      pt = object->pt;
2662 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2663 >  }
2664 >
2665 >
2666 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2667  
2668    else if(variable == "genMatchedPdgId"){
2669      int index = getGenMatchedParticleIndex(object);
# Line 2145 | Line 2684 | OSUAnalysis::valueLookup (const BNtrack*
2684    }
2685    else if(variable == "genMatchedMotherIdReverse"){
2686      int index = getGenMatchedParticleIndex(object);
2687 <    if(index == -1) value = 23;
2688 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2687 >    if(index == -1) value = 24;
2688 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2689    }
2690    else if(variable == "genMatchedGrandmotherId"){
2691      int index = getGenMatchedParticleIndex(object);
# Line 2158 | Line 2697 | OSUAnalysis::valueLookup (const BNtrack*
2697      }
2698      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2699    }
2700 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2701 +    int index = getGenMatchedParticleIndex(object);
2702 +    if(index == -1) value = 24;
2703 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2704 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2705 +      if(motherIndex == -1) value = 24;
2706 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2707 +    }
2708 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2709 +  }
2710  
2711  
2712  
2713 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2713 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2714  
2715    value = applyFunction(function, value);
2716  
2717    return value;
2718 < }
2718 > } // end track valueLookup
2719 >
2720  
2721 + //!genjet valueLookup
2722   double
2723 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2723 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2724  
2725    double value = 0.0;
2726  
# Line 2189 | Line 2740 | OSUAnalysis::valueLookup (const BNgenjet
2740    else if(variable == "charge") value = object->charge;
2741  
2742  
2743 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2743 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2744  
2745    value = applyFunction(function, value);
2746  
2747    return value;
2748   }
2749  
2750 + //!mcparticle valueLookup
2751   double
2752 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2752 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2753  
2754    double value = 0.0;
2755  
# Line 2322 | Line 2874 | OSUAnalysis::valueLookup (const BNmcpart
2874    }
2875  
2876  
2877 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2877 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2878  
2879    value = applyFunction(function, value);
2880  
2881    return value;
2882 < }
2882 > } // end mcparticle valueLookup
2883  
2884 +
2885 + //!primaryvertex valueLookup
2886   double
2887 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2887 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2888  
2889    double value = 0.0;
2890  
# Line 2349 | Line 2903 | OSUAnalysis::valueLookup (const BNprimar
2903    else if(variable == "isGood") value = object->isGood;
2904  
2905  
2906 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2906 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2907  
2908    value = applyFunction(function, value);
2909  
2910    return value;
2911   }
2912  
2913 + //!bxlumi valueLookup
2914   double
2915 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2915 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2916  
2917    double value = 0.0;
2918  
# Line 2366 | Line 2921 | OSUAnalysis::valueLookup (const BNbxlumi
2921    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2922  
2923  
2924 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2924 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2925  
2926    value = applyFunction(function, value);
2927  
2928    return value;
2929   }
2930  
2931 + //!photon valueLookup
2932   double
2933 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2933 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2934  
2935    double value = 0.0;
2936  
# Line 2449 | Line 3005 | OSUAnalysis::valueLookup (const BNphoton
3005    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
3006  
3007  
2452
3008  
3009 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3009 >
3010 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3011  
3012    else if(variable == "genMatchedPdgId"){
3013      int index = getGenMatchedParticleIndex(object);
# Line 2473 | Line 3029 | OSUAnalysis::valueLookup (const BNphoton
3029    }
3030    else if(variable == "genMatchedMotherIdReverse"){
3031      int index = getGenMatchedParticleIndex(object);
3032 <    if(index == -1) value = 23;
3033 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
3032 >    if(index == -1) value = 24;
3033 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
3034    }
3035    else if(variable == "genMatchedGrandmotherId"){
3036      int index = getGenMatchedParticleIndex(object);
# Line 2486 | Line 3042 | OSUAnalysis::valueLookup (const BNphoton
3042      }
3043      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3044    }
3045 +  else if(variable == "genMatchedGrandmotherIdReverse"){
3046 +    int index = getGenMatchedParticleIndex(object);
3047 +    if(index == -1) value = 24;
3048 +    else if(fabs(mcparticles->at(index).motherId) == 15){
3049 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3050 +      if(motherIndex == -1) value = 24;
3051 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3052 +    }
3053 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3054 +  }
3055  
3056  
3057 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3057 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3058  
3059    value = applyFunction(function, value);
3060  
3061    return value;
3062 < }
3062 > } // end photon valueLookup
3063 >
3064  
3065 + //!supercluster valueLookup
3066   double
3067 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
3067 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
3068  
3069    double value = 0.0;
3070  
# Line 2510 | Line 3078 | OSUAnalysis::valueLookup (const BNsuperc
3078    else if(variable == "theta") value = object->theta;
3079  
3080  
3081 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3081 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3082  
3083    value = applyFunction(function, value);
3084  
3085    return value;
3086   }
3087  
3088 + //!trigobj valueLookup
3089 + double
3090 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3091 +
3092 +  double value = 0.0;
3093 +
3094 +  if(variable == "pt") value = object->pt;
3095 +  else if(variable == "eta") value = object->eta;
3096 +  else if(variable == "phi") value = object->phi;
3097 +  else if(variable == "px") value = object->px;
3098 +  else if(variable == "py") value = object->py;
3099 +  else if(variable == "pz") value = object->pz;
3100 +  else if(variable == "et") value = object->et;
3101 +  else if(variable == "energy") value = object->energy;
3102 +  else if(variable == "etTotal") value = object->etTotal;
3103 +  else if(variable == "id") value = object->id;
3104 +  else if(variable == "charge") value = object->charge;
3105 +  else if(variable == "isIsolated") value = object->isIsolated;
3106 +  else if(variable == "isMip") value = object->isMip;
3107 +  else if(variable == "isForward") value = object->isForward;
3108 +  else if(variable == "isRPC") value = object->isRPC;
3109 +  else if(variable == "bx") value = object->bx;
3110 +  else if(variable == "filter") {
3111 +    if ((stringValue = object->filter) == "")
3112 +      stringValue = "none";  // stringValue should only be empty if value is filled
3113 +  }
3114 +
3115 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3116 +
3117 +  value = applyFunction(function, value);
3118 +
3119 +  return value;
3120 + }
3121  
3122 + //!muon-muon pair valueLookup
3123   double
3124 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
3124 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3125  
3126    double value = 0.0;
3127  
# Line 2581 | Line 3183 | OSUAnalysis::valueLookup (const BNmuon*
3183        value = object2->correctedD0;
3184      }
3185  
3186 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3186 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3187 >
3188 >  value = applyFunction(function, value);
3189 >
3190 >  return value;
3191 > } // end muon-muon pair valueLookup
3192 >
3193 >
3194 > //!muon-photon pair valueLookup
3195 > double
3196 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3197 >
3198 >  double value = 0.0;
3199 >
3200 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3201 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3202 >  else if(variable == "photonEta") value = object2->eta;
3203 >  else if(variable == "muonEta") value = object1->eta;
3204 >  else if(variable == "photonPhi") value = object2->phi;
3205 >  else if(variable == "muonPhi") value = object1->phi;
3206 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3207 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3208 >  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3209 >  else if(variable == "invMass"){
3210 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3211 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3212 >    value = (fourVector1 + fourVector2).M();
3213 >  }
3214 >  else if(variable == "pt"){
3215 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3216 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3217 >    value = (fourVector1 + fourVector2).Pt();
3218 >  }
3219 >  else if(variable == "threeDAngle")
3220 >    {
3221 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3222 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3223 >      value = (threeVector1.Angle(threeVector2));
3224 >    }
3225 >  else if(variable == "alpha")
3226 >    {
3227 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3228 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3229 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3230 >      value = (pi-threeVector1.Angle(threeVector2));
3231 >    }
3232 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3233  
3234    value = applyFunction(function, value);
3235  
3236    return value;
3237   }
3238  
3239 + //!electron-photon pair valueLookup
3240   double
3241 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
3241 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3242 >
3243 >  double value = 0.0;
3244 >
3245 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3246 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3247 >  else if(variable == "photonEta") value = object2->eta;
3248 >  else if(variable == "electronEta") value = object1->eta;
3249 >  else if(variable == "photonPhi") value = object2->phi;
3250 >  else if(variable == "electronPhi") value = object1->phi;
3251 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3252 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3253 >  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3254 >  else if(variable == "invMass"){
3255 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3256 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3257 >    value = (fourVector1 + fourVector2).M();
3258 >  }
3259 >  else if(variable == "pt"){
3260 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3261 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3262 >    value = (fourVector1 + fourVector2).Pt();
3263 >  }
3264 >  else if(variable == "threeDAngle")
3265 >    {
3266 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3267 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3268 >      value = (threeVector1.Angle(threeVector2));
3269 >    }
3270 >  else if(variable == "alpha")
3271 >    {
3272 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3273 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3274 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3275 >      value = (pi-threeVector1.Angle(threeVector2));
3276 >    }
3277 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3278 >
3279 >  value = applyFunction(function, value);
3280 >
3281 >  return value;
3282 > }
3283 >
3284 > //!electron-electron pair valueLookup
3285 > double
3286 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3287  
3288    double value = 0.0;
3289  
# Line 2636 | Line 3330 | OSUAnalysis::valueLookup (const BNelectr
3330      value = object2->correctedD0;
3331    }
3332  
3333 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3333 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3334  
3335    value = applyFunction(function, value);
3336  
3337    return value;
3338   }
3339  
3340 + //!electron-muon pair valueLookup
3341   double
3342 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3342 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3343  
3344    double value = 0.0;
3345  
# Line 2702 | Line 3397 | OSUAnalysis::valueLookup (const BNelectr
3397    else if(variable == "muonRelPFdBetaIso"){
3398      value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3399    }
3400 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3401 +  value = applyFunction(function, value);
3402  
3403 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3403 >  return value;
3404 > } // end electron-muon pair valueLookup
3405 >
3406 >
3407 > //!electron-jet pair valueLookup
3408 > double
3409 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3410 >
3411 >  double value = 0.0;
3412 >
3413 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3414 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3415 >  else if(variable == "jetEta") value = object2->eta;
3416 >  else if(variable == "jetPhi") value = object2->phi;
3417 >  else if(variable == "electronEta") value = object1->eta;
3418 >  else if(variable == "electronPhi") value = object1->phi;
3419 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3420 >  else if(variable == "invMass"){
3421 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3422 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3423 >    value = (fourVector1 + fourVector2).M();
3424 >  }
3425 >  else if(variable == "pt"){
3426 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3427 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3428 >    value = (fourVector1 + fourVector2).Pt();
3429 >  }
3430 >  else if(variable == "threeDAngle")
3431 >    {
3432 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3433 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3434 >      value = (threeVector1.Angle(threeVector2));
3435 >    }
3436 >  else if(variable == "chargeProduct"){
3437 >    value = object1->charge*object2->charge;
3438 >  }
3439  
3440 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3441    value = applyFunction(function, value);
3442  
3443    return value;
3444   }
3445  
3446 + //!photon-jet pair valueLookup
3447 + double
3448 + OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3449 +
3450 +  double value = 0.0;
3451  
3452 < double  
2715 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function){  
2716 <  double electronMass = 0.000511;        
2717 <  double value = 0.0;    
2718 <  TLorentzVector fourVector1(0, 0, 0, 0);        
2719 <  TLorentzVector fourVector2(0, 0, 0, 0);        
2720 <  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));  
3452 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3453    else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3454 <  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);    
3455 <  else if(variable == "invMass"){        
3456 <    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);    
3457 <    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );    
3458 <        
3459 <    value = (fourVector1 + fourVector2).M();    
3454 >  else if(variable == "jetEta") value = object2->eta;
3455 >  else if(variable == "jetPhi") value = object2->phi;
3456 >  else if(variable == "photonEta") value = object1->eta;
3457 >  else if(variable == "photonPhi") value = object1->phi;
3458 >  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3459 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3460 >  else if(variable == "invMass"){
3461 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3462 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3463 >    value = (fourVector1 + fourVector2).M();
3464 >  }
3465 >  else if(variable == "pt"){
3466 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3467 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3468 >    value = (fourVector1 + fourVector2).Pt();
3469 >  }
3470 >  else if(variable == "threeDAngle")
3471 >    {
3472 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3473 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3474 >      value = (threeVector1.Angle(threeVector2));
3475 >    }
3476 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3477 >  value = applyFunction(function, value);
3478 >
3479 >  return value;
3480 > }
3481 >
3482 > // met-jet pair valueLookup
3483 > double
3484 > OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3485 >
3486 >  double value = 0.0;
3487 >
3488 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3489 >
3490 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3491 >  value = applyFunction(function, value);
3492 >
3493 >  return value;
3494 >
3495 > }  
3496 >
3497 >
3498 >
3499 > //!muon-jet pair valueLookup
3500 > double
3501 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3502 >
3503 >  double value = 0.0;
3504 >
3505 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3506 >  else if(variable == "jetEta") value = object2->eta;
3507 >  else if(variable == "jetPhi") value = object2->phi;
3508 >  else if(variable == "muonEta") value = object1->eta;
3509 >  else if(variable == "muonPhi") value = object1->phi;
3510 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3511 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3512 >  else if(variable == "invMass"){
3513 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3514 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3515 >    value = (fourVector1 + fourVector2).M();
3516 >  }
3517 >  else if(variable == "pt"){
3518 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3519 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3520 >    value = (fourVector1 + fourVector2).Pt();
3521 >  }
3522 >  else if(variable == "threeDAngle")
3523 >    {
3524 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3525 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3526 >      value = (threeVector1.Angle(threeVector2));
3527 >    }
3528 >  else if(variable == "chargeProduct"){
3529 >    value = object1->charge*object2->charge;
3530    }
3531 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}  
3532 <  value = applyFunction(function, value);        
3533 <  return value;  
3531 >
3532 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3533 >  value = applyFunction(function, value);
3534 >
3535 >  return value;
3536   }
3537 + //!jet-jet pair valueLookup
3538 + double
3539 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3540 +
3541 +  double value = 0.0;
3542 +
3543 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3544 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3545 +  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3546 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3547 +  else if(variable == "invMass"){
3548 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3549 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3550 +    value = (fourVector1 + fourVector2).M();
3551 +  }
3552 +  else if(variable == "pt"){
3553 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3554 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3555 +    value = (fourVector1 + fourVector2).Pt();
3556 +  }
3557 +  else if(variable == "threeDAngle")
3558 +    {
3559 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3560 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3561 +      value = (threeVector1.Angle(threeVector2));
3562 +    }
3563 +  else if(variable == "chargeProduct"){
3564 +    value = object1->charge*object2->charge;
3565 +  }
3566  
3567 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3568 +  value = applyFunction(function, value);
3569  
3570 +  return value;
3571 + }
3572  
3573 + //!electron-track pair valueLookup
3574   double
3575 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function){
3575 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3576 >  double electronMass = 0.000511;
3577 >  double value = 0.0;
3578 >  TLorentzVector fourVector1(0, 0, 0, 0);
3579 >  TLorentzVector fourVector2(0, 0, 0, 0);
3580 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3581 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3582 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3583 >  else if(variable == "invMass"){
3584 >    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3585 >    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3586 >
3587 >    value = (fourVector1 + fourVector2).M();
3588 >  }
3589 >  else if(variable == "chargeProduct"){
3590 >    value = object1->charge*object2->charge;
3591 >  }
3592 >  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3593 >  value = applyFunction(function, value);
3594 >  return value;
3595 >
3596 > }
3597 >
3598 >
3599 > //!muon-track pair valueLookup
3600 > double
3601 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3602    double pionMass = 0.140;
3603    double muonMass = 0.106;
3604    double value = 0.0;
# Line 2749 | Line 3613 | OSUAnalysis::valueLookup (const BNmuon*
3613  
3614      value = (fourVector1 + fourVector2).M();
3615    }
3616 +  else if(variable == "chargeProduct"){
3617 +    value = object1->charge*object2->charge;
3618 +  }
3619  
3620    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3621    value = applyFunction(function, value);
3622    return value;
3623   }
3624  
3625 <
3625 > //!tau-tau pair valueLookup
3626   double
3627 < OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function){
3627 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3628    double value = 0.0;
3629    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3630    else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
# Line 2768 | Line 3635 | OSUAnalysis::valueLookup (const BNtau* o
3635      value = (fourVector1 + fourVector2).M();
3636    }
3637  
3638 +  else if(variable == "chargeProduct"){
3639 +    value = object1->charge*object2->charge;
3640 +  }
3641 +
3642    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3643    value = applyFunction(function, value);
3644    return value;
3645   }
3646  
3647 <
3647 > //!muon-tau pair valueLookup
3648   double
3649 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function){
3649 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3650    double value = 0.0;
3651    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3652    else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
# Line 2786 | Line 3657 | OSUAnalysis::valueLookup (const BNmuon*
3657      value = (fourVector1 + fourVector2).M();
3658    }
3659  
3660 +  else if(variable == "chargeProduct"){
3661 +    value = object1->charge*object2->charge;
3662 +  }
3663 +
3664    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3665    value = applyFunction(function, value);
3666    return value;
3667   }
3668  
3669 + //!tau-track pair valueLookup
3670   double
3671 < OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function){
3671 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3672    double value = 0.0;
3673    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3674    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3675 +  else if(variable == "chargeProduct"){
3676 +    value = object1->charge*object2->charge;
3677 +  }
3678  
3679    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3680    value = applyFunction(function, value);
# Line 2803 | Line 3682 | OSUAnalysis::valueLookup (const BNtau* o
3682   }
3683  
3684  
3685 <
3685 > //!track-event pair valueLookup
3686   double
3687 < OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function){
3687 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3688  
3689    double value = 0.0;
3690    double pMag = sqrt(object1->pt * object1->pt +
3691 <                     object1->pz * object1->pz);  
3691 >                     object1->pz * object1->pz);
3692  
3693    if      (variable == "numPV")                      value = object2->numPV;
3694    else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3695    else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3696 <  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);  
3697 <  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;  
3696 >  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3697 >  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3698  
3699 <  else { std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3699 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3700  
3701    value = applyFunction(function, value);
3702  
3703    return value;
3704  
3705 < }  
3705 > }
3706 >
3707 > //!electron-trigobj pair valueLookup
3708 > double
3709 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3710 >
3711 >  double value = 0.0;
3712 >
3713 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3714 >  else if (variable == "match"){
3715 >    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3716 >      stringValue = object2->filter;
3717 >    else
3718 >      stringValue = "none";
3719 >  }
3720 >
3721 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3722 >
3723 >  value = applyFunction(function, value);
3724 >
3725 >  return value;
3726 >
3727 > }
3728 >
3729 > //!muon-trigobj pair valueLookup
3730 > double
3731 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3732 >
3733 >  double value = 0.0;
3734 >
3735 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3736 >
3737 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3738 >
3739 >  value = applyFunction(function, value);
3740 >
3741 >  return value;
3742 >
3743 > }
3744 >
3745 > //!stop valueLookup
3746 > double
3747 > OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3748 >
3749 >
3750 >  double value = 0.0;
3751 >
3752 >  if(variable == "ctau") value = object->ctau;
3753 >
3754 >  else if (variable == "d0"){
3755 >    double vx = object->vx - chosenVertex ()->x,
3756 >      vy = object->vy - chosenVertex ()->y,
3757 >      px = object->px,
3758 >      py = object->py,
3759 >      pt = object->pt;
3760 >    value = (-vx * py + vy * px) / pt;
3761 >  }
3762 >
3763 >  else if (variable == "dz"){
3764 >    double vx = object->vx - chosenVertex ()->x,
3765 >      vy = object->vy - chosenVertex ()->y,
3766 >      vz = object->vz - chosenVertex ()->z,
3767 >      px = object->px,
3768 >      py = object->py,
3769 >      pz = object->pz,
3770 >      pt = object->pt;
3771 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3772 >  }
3773 >
3774 >  else if (variable == "minD0"){
3775 >    double minD0=999;
3776 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3777 >      double vx = object->vx - vertex->x,
3778 >        vy = object->vy - vertex->y,
3779 >        px = object->px,
3780 >        py = object->py,
3781 >        pt = object->pt;
3782 >      value = (-vx * py + vy * px) / pt;
3783 >      if(abs(value) < abs(minD0)) minD0 = value;
3784 >    }
3785 >    value = minD0;
3786 >  }
3787 >  else if (variable == "minDz"){
3788 >    double minDz=999;
3789 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3790 >      double vx = object->vx - vertex->x,
3791 >        vy = object->vy - vertex->y,
3792 >        vz = object->vz - vertex->z,
3793 >        px = object->px,
3794 >        py = object->py,
3795 >        pz = object->pz,
3796 >        pt = object->pt;
3797 >      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3798 >      if(abs(value) < abs(minDz)) minDz = value;
3799 >    }
3800 >    value = minDz;
3801 >  }
3802 >  else if(variable == "distToVertex"){
3803 >    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3804 >                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3805 >                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3806 >  }
3807 >  else if (variable == "minDistToVertex"){
3808 >    double minDistToVertex=999;
3809 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3810 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3811 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3812 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
3813 >
3814 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3815 >    }
3816 >    value = minDistToVertex;
3817 >  }
3818 >  else if (variable == "distToVertexDifference"){
3819 >    double minDistToVertex=999;
3820 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3821 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3822 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3823 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
3824 >
3825 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3826 >    }
3827 >    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3828 >                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3829 >                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3830 >
3831 >    value = distToChosenVertex - minDistToVertex;
3832 >  }
3833 >
3834 >  else if (variable == "closestVertexRank"){
3835 >    double minDistToVertex=999;
3836 >    int vertex_rank = 0;
3837 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3838 >      vertex_rank++;
3839 >      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3840 >                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
3841 >                      (object->vz-vertex->z)*(object->vz-vertex->z));
3842 >
3843 >      if(abs(dist) < abs(minDistToVertex)){
3844 >        value = vertex_rank;
3845 >        minDistToVertex = dist;
3846 >      }
3847 >    }
3848 >  }
3849 >
3850 >
3851 >
3852 >
3853 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3854 >
3855 >  value = applyFunction(function, value);
3856 >
3857 >  return value;
3858 >
3859 > } // end stop valueLookup
3860 >
3861 >
3862 >
3863 >
3864  
3865   // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3866   // Return true iff no other tracks are found in this cone.
# Line 2872 | Line 3909 | OSUAnalysis::getTrkPtTrue (const BNtrack
3909  
3910   double
3911   OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3912 <  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.  
3913 <  if (!useTrackCaloRhoCorr_) return -99;  
3914 <  // if (!rhokt6CaloJetsHandle_) {
3915 <  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;  
3916 <  //   return -99;  
3912 >  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3913 >  if (!useTrackCaloRhoCorr_) return -99;
3914 >  // if (!rhokt6CaloJetsHandle_) {
3915 >  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3916 >  //   return -99;
3917    // }
3918 <  double radDeltaRCone = 0.5;  
3919 <  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.  
3920 <  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;  
3921 <  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);  
3922 <  return caloTotRhoCorrCalo;  
3923 <
3918 >  double radDeltaRCone = 0.5;
3919 >  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3920 >  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3921 >  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3922 >  return caloTotRhoCorrCalo;
3923 >
3924   }
3925  
3926  
# Line 2921 | Line 3958 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3958    double deltaRLowest = 999;
3959    int value = 0;
3960    if (DeadEcalVec.size() == 0) WriteDeadEcal();
3961 <  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3961 >  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3962      double eta = ecal->etaEcal;
3963      double phi = ecal->phiEcal;
3964 <    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
3964 >    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
3965      if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3966    }
3967    if (deltaRLowest<0.05) {value = 1;}
# Line 2932 | Line 3969 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3969    return value;
3970   }
3971  
3972 < // Returns the smallest DeltaR between the object and any generated true particle in the event.  
3972 > // Returns the smallest DeltaR between the object and any generated true particle in the event.
3973   template <class InputObject>
3974   double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3975    double genDeltaRLowest = 999.;
# Line 2952 | Line 3989 | OSUAnalysis::applyFunction(string functi
3989    else if(function == "log") value = log10(value);
3990  
3991    else if(function == "") value = value;
3992 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
3992 >  else{cout << "WARNING: invalid function '" << function << "'\n";}
3993  
3994    return value;
3995  
# Line 2961 | Line 3998 | OSUAnalysis::applyFunction(string functi
3998  
3999   template <class InputCollection>
4000   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
4001 <
4002 <  if (currentCut.inputCollection.find("pair")!=std::string::npos)  {
4003 <    string obj1, obj2;
4001 >
4002 >  if (currentCut.inputCollection.find("pair")!=string::npos)  {
4003 >    string obj1, obj2;
4004      getTwoObjs(currentCut.inputCollection, obj1, obj2);
4005      if (inputType==obj1 ||
4006 <        inputType==obj2) {
4006 >        inputType==obj2) {
4007        // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
4008 <      // and the inputType is a member of the pair.  
4009 <      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.  
4010 <      // For example, if currentCut.inputCollection==electron-muon pairs,
4011 <      // then the flags should not be set here when inputType==muons or inputType==electrons.  
4012 <      return;
4013 <    }  
4014 <  }    
4008 >      // and the inputType is a member of the pair.
4009 >      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
4010 >      // For example, if currentCut.inputCollection==electron-muon pairs,
4011 >      // then the flags should not be set here when inputType==muons or inputType==electrons.
4012 >      return;
4013 >    }
4014 >  }
4015  
4016    for (uint object = 0; object != inputCollection->size(); object++){
4017  
4018 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
4018 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4019 >    bool plotDecision = true;
4020  
4021      if(currentCut.inputCollection == inputType){
4022  
4023        vector<bool> subcutDecisions;
4024        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4025 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4026 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4025 >        string stringValue = "";
4026 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4027 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4028 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4029  
4030        }
4031 <      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4031 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4032        else{
4033          bool tempDecision = true;
4034          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
# Line 2997 | Line 4037 | void OSUAnalysis::setObjectFlags(cut &cu
4037            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4038              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4039          }
4040 <        decision = tempDecision;
4040 >        cutDecision = tempDecision;
4041        }
4042 +      //invert the cut for plotting if this cut is a veto
4043 +      if(currentCut.isVeto) plotDecision = !cutDecision;
4044 +      else plotDecision = cutDecision;
4045      }
4046  
4047 <    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4047 >    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4048  
4049 <    //set flags for objects that pass each cut AND all the previous cuts
4050 <    bool previousCumulativeFlag = true;
4049 >    //set flags for objects that pass this cut AND all the previous cuts
4050 >    bool previousCumulativeCutFlag = true;
4051 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4052 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4053 >      else{ previousCumulativeCutFlag = false; break;}
4054 >    }
4055 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4056 >    bool previousCumulativePlotFlag = true;
4057      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4058 <      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4059 <      else{ previousCumulativeFlag = false; break;}
4058 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4059 >      else{ previousCumulativePlotFlag = false; break;}
4060      }
4061 <    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4061 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4062 >
4063 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4064  
4065    }
4066  
# Line 3018 | Line 4069 | void OSUAnalysis::setObjectFlags(cut &cu
4069  
4070   template <class InputCollection1, class InputCollection2>
4071   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
4072 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
4072 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, string inputType){
4073  
4074  
4075    bool sameObjects = false;
4076    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4077  
4078 <  // Get the strings for the two objects that make up the pair.  
4079 <  string obj1Type, obj2Type;
4078 >  // Get the strings for the two objects that make up the pair.
4079 >  string obj1Type, obj2Type;
4080    getTwoObjs(inputType, obj1Type, obj2Type);
4081    bool isTwoTypesOfObject = true;
4082 <  if (obj1Type==obj2Type) isTwoTypesOfObject = false;  
4082 >  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
4083  
4084 <  // Initialize the flags for individual objects to all be false, if the cut is on the pair.  
4085 <  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).  
4086 <  if (currentCut.inputCollection == inputType) {    
4084 >  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
4085 >  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4086 >  if (currentCut.inputCollection == inputType) {
4087      for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4088 <      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
4089 <      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
4088 >      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4089 >      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4090      }
4091 <    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.  
4091 >    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4092        for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4093 <        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
4094 <        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
4093 >        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4094 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4095        }
4096      }
4097    }
4098 <  
4098 >
4099    int counter = 0;
4100  
4101    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
# Line 3053 | Line 4104 | void OSUAnalysis::setObjectFlags(cut &cu
4104        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4105  
4106  
4107 <      bool decision = true;//object passes if this cut doesn't cut on that type of object
4107 >      bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4108 >      bool plotDecision = true;
4109  
4110        if(currentCut.inputCollection == inputType){
4111  
4112          vector<bool> subcutDecisions;
4113          for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4114 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4115 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4114 >          string stringValue = "";
4115 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4116 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4117 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4118          }
4119  
4120 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4120 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4121          else{
4122            bool tempDecision = subcutDecisions.at(0);
4123            for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
# Line 3072 | Line 4126 | void OSUAnalysis::setObjectFlags(cut &cu
4126              else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4127                tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4128            }
4129 <          decision = tempDecision;
4129 >          cutDecision = tempDecision;
4130          }
4131 +        //invert the cut for plotting if this cut is a veto
4132 +        if(currentCut.isVeto) plotDecision = !cutDecision;
4133 +        else plotDecision = cutDecision;
4134 +      }
4135 +      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4136 +      if (cutDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4137 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4138 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4139 +      }
4140 +      if (plotDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4141 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4142 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4143        }
3078      // if (decision) isPassObj1.at(object1) = true;
3079      // if (decision) isPassObj2.at(object2) = true;
3080      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);  
3081      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on  
3082        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;  
3083        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;  
3084      }  
4144  
4145 <      //set flags for objects that pass each cut AND all the previous cuts
4146 <      bool previousCumulativeFlag = true;
4145 >      //set flags for objects that pass this cut AND all the previous cuts
4146 >      bool previousCumulativeCutFlag = true;
4147        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4148 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
4149 <        else{ previousCumulativeFlag = false; break;}
4148 >        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4149 >        else{ previousCumulativeCutFlag = false; break;}
4150        }
4151 +      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4152 +
4153 +      bool previousCumulativePlotFlag = true;
4154 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4155 +        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4156 +        else{ previousCumulativePlotFlag = false; break;}
4157 +      }
4158 +      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4159 +      
4160        //apply flags for the components of the composite object as well
4161 <      bool currentCumulativeFlag = true;
4162 <      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
4163 <      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
4164 <      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
4165 <      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
4166 <      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
4167 <      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on  
4168 <        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);  
4169 <        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);  
4161 >      bool currentCumulativeCutFlag = true;
4162 >      bool currentCumulativePlotFlag = true;
4163 >
4164 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4165 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4166 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4167 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4168 >
4169 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4170 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4171 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4172 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4173 >
4174 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));
4175 >
4176 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4177 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4178 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4179 >      }
4180 >
4181 >      if (currentCumulativePlotFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4182 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4183 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4184        }
4185 +
4186        counter++;
4187  
4188 <    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4189 <  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4188 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4189 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4190  
4191   }
4192  
4193  
4194 < bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
4195 <  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4196 <  // all cuts up to currentCutIndex  
4197 <  bool previousCumulativeFlag = true;  
4198 <  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {  
4199 <    if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
4200 <    else {  
4201 <      previousCumulativeFlag = false; break;  
4194 > bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4195 >  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4196 >  // all cuts up to currentCutIndex
4197 >  bool previousCumulativeFlag = true;
4198 >  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4199 >    bool tempFlag = false;
4200 >    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4201 >    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4202 >
4203 >    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4204 >    else {
4205 >      previousCumulativeFlag = false; break;
4206      }
4207    }
4208 <  return previousCumulativeFlag;  
4209 < }  
4208 >  return previousCumulativeFlag;
4209 > }
4210 >
4211 >
4212  
4213  
4214   template <class InputCollection>
4215 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4215 > void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4216 >  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4217 >
4218 >  if (BNTreeBranchVals_.count(parameters.name)==0) cout << "Error[assignTreeBranch]:  trying to assign value to " << parameters.name << " that does not have a branch set up.  Will likely seg fault." << endl;
4219 >  for (uint object = 0; object != inputCollection->size(); object++) {
4220 >
4221 >    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4222 >
4223 >    string inputVariable = parameters.inputVariable;
4224 >    string function = "";
4225 >    string stringValue = "";
4226 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4227 >    BNTreeBranchVals_.at(parameters.name).push_back(value);
4228 >
4229 >  }
4230 > }
4231 >
4232 >
4233 > template <class InputCollection>
4234 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4235 >
4236  
4237    for (uint object = 0; object != inputCollection->size(); object++){
4238  
4239 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4239 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4240  
4241      string currentString = parameters.inputVariables.at(0);
4242      string inputVariable = "";
4243      string function = "";
4244 <    if(currentString.find("(")==std::string::npos){
4244 >    if(currentString.find("(")==string::npos){
4245        inputVariable = currentString;// variable to cut on
4246      }
4247      else{
# Line 3141 | Line 4250 | void OSUAnalysis::fill1DHistogram(TH1* h
4250        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4251      }
4252  
4253 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
4253 >    string stringValue = "";
4254 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4255      histo->Fill(value,scaleFactor);
4256  
4257      if (printEventInfo_) {
4258 <      // Write information about event to screen, for testing purposes.  
4259 <      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;  
4258 >      // Write information about event to screen, for testing purposes.
4259 >      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
4260      }
4261 <    
4261 >
4262    }
4263   }
4264  
4265   template <class InputCollection1, class InputCollection2>
4266 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4266 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4267  
4268    bool sameObjects = false;
4269    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
# Line 3166 | Line 4276 | void OSUAnalysis::fill1DHistogram(TH1* h
4276  
4277        pairCounter++;
4278        //only take objects which have passed all cuts and pairs which have passed all cuts
4279 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4280 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4281 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4279 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4280 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4281 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4282  
4283        string currentString = parameters.inputVariables.at(0);
4284        string inputVariable = "";
4285        string function = "";
4286 <      if(currentString.find("(")==std::string::npos){
4286 >      if(currentString.find("(")==string::npos){
4287          inputVariable = currentString;// variable to cut on
4288        }
4289        else{
# Line 3182 | Line 4292 | void OSUAnalysis::fill1DHistogram(TH1* h
4292          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4293        }
4294  
4295 <      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4295 >      string stringValue = "";
4296 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4297        histo->Fill(value,scaleFactor);
4298  
4299      }
# Line 3192 | Line 4303 | void OSUAnalysis::fill1DHistogram(TH1* h
4303  
4304  
4305   template <class InputCollection>
4306 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4306 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4307  
4308    for (uint object = 0; object != inputCollection->size(); object++){
4309  
4310 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4310 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4311  
4312 +    string stringValue = "";
4313      string currentString = parameters.inputVariables.at(0);
4314      string inputVariable = "";
4315      string function = "";
4316 <    if(currentString.find("(")==std::string::npos){
4316 >    if(currentString.find("(")==string::npos){
4317        inputVariable = currentString;// variable to cut on
4318      }
4319      else{
# Line 3209 | Line 4321 | void OSUAnalysis::fill2DHistogram(TH2* h
4321        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4322        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4323      }
4324 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
4324 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4325  
4326      currentString = parameters.inputVariables.at(1);
4327      inputVariable = "";
4328      function = "";
4329 <    if(currentString.find("(")==std::string::npos){
4329 >    if(currentString.find("(")==string::npos){
4330        inputVariable = currentString;// variable to cut on
4331      }
4332      else{
# Line 3223 | Line 4335 | void OSUAnalysis::fill2DHistogram(TH2* h
4335        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4336      }
4337  
4338 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
4338 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4339  
4340      histo->Fill(valueX,valueY,scaleFactor);
4341  
# Line 3232 | Line 4344 | void OSUAnalysis::fill2DHistogram(TH2* h
4344   }
4345  
4346   template <class InputCollection1, class InputCollection2>
4347 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4347 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4348  
4349    bool sameObjects = false;
4350    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
# Line 3246 | Line 4358 | void OSUAnalysis::fill2DHistogram(TH2* h
4358        pairCounter++;
4359  
4360        //only take objects which have passed all cuts and pairs which have passed all cuts
4361 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4362 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4363 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4361 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4362 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4363 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4364  
4365 +      string stringValue = "";
4366        string currentString = parameters.inputVariables.at(0);
4367        string inputVariable = "";
4368        string function = "";
4369 <      if(currentString.find("(")==std::string::npos){
4369 >      if(currentString.find("(")==string::npos){
4370          inputVariable = currentString;// variable to cut on
4371        }
4372        else{
# Line 3261 | Line 4374 | void OSUAnalysis::fill2DHistogram(TH2* h
4374          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4375          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4376        }
4377 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4377 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4378  
4379        currentString = parameters.inputVariables.at(1);
4380        inputVariable = "";
4381        function = "";
4382 <      if(currentString.find("(")==std::string::npos){
4382 >      if(currentString.find("(")==string::npos){
4383          inputVariable = currentString;// variable to cut on
4384        }
4385        else{
# Line 3274 | Line 4387 | void OSUAnalysis::fill2DHistogram(TH2* h
4387          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4388          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4389        }
4390 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4390 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4391  
4392  
4393        histo->Fill(valueX,valueY,scaleFactor);
# Line 3295 | Line 4408 | int OSUAnalysis::getGenMatchedParticleIn
4408  
4409      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4410      if(currentDeltaR > 0.05) continue;
4411 <    //     cout << std::setprecision(3) << std::setw(20)
4411 >    //     cout << setprecision(3) << setw(20)
4412      //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4413 <    //          << std::setw(20)
4413 >    //          << setw(20)
4414      //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4415 <    //          << std::setw(20)
4415 >    //          << setw(20)
4416      //          << "\tdeltaR = " << currentDeltaR
4417 <    //          << std::setprecision(1)
4418 <    //          << std::setw(20)
4417 >    //          << setprecision(1)
4418 >    //          << setw(20)
4419      //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4420 <    //          << std::setw(20)
4420 >    //          << setw(20)
4421      //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4422 <    //          << std::setw(20)
4422 >    //          << setw(20)
4423      //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4424      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4425        bestMatchIndex = mcparticle - mcparticles->begin();
# Line 3369 | Line 4482 | int OSUAnalysis::findTauMotherIndex(cons
4482   // 20        strange baryon
4483   // 21        charm baryon
4484   // 22        bottom baryon
4485 < // 23        other
4485 > // 23        QCD string
4486 > // 24        other
4487  
4488   int OSUAnalysis::getPdgIdBinValue(int pdgId){
4489  
# Line 3393 | Line 4507 | int OSUAnalysis::getPdgIdBinValue(int pd
4507    else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4508    else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4509    else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4510 +  else if(absPdgId == 92  ) binValue = 23;
4511  
4512 <  else binValue = 23;
4512 >  else binValue = 24;
4513  
4514    return binValue;
4515  
# Line 3404 | Line 4519 | const BNprimaryvertex *
4519   OSUAnalysis::chosenVertex ()
4520   {
4521    const BNprimaryvertex *chosenVertex = 0;
4522 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
4523 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
4524 <      cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
4522 >  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4523 >    flagPair vertexFlags;
4524 >    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4525 >      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4526 >        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4527 >        break;
4528 >      }
4529 >    }
4530      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4531 <      if(!vertexFlags.at(vertexIndex)) continue;
4531 >      if(!vertexFlags.at(vertexIndex).first) continue;
4532        chosenVertex = & primaryvertexs->at(vertexIndex);
4533        break;
4534      }
4535    }
4536 <  else {
4537 <    chosenVertex = &primaryvertexs->at(0);
3418 <  }
4536 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4537 >    chosenVertex = & primaryvertexs->at (0);
4538  
4539    return chosenVertex;
4540   }
# Line 3424 | Line 4543 | const BNmet *
4543   OSUAnalysis::chosenMET ()
4544   {
4545    const BNmet *chosenMET = 0;
4546 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
4547 <    vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
4548 <      cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
4546 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4547 >    flagPair metFlags;
4548 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4549 >      if (cumulativeFlags.at("mets").at(i).size()){
4550 >        metFlags = cumulativeFlags.at("mets").at(i);
4551 >        break;
4552 >      }
4553 >    }
4554      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4555 <      if(!metFlags.at(metIndex)) continue;
4555 >      if(!metFlags.at(metIndex).first) continue;
4556        chosenMET = & mets->at(metIndex);
4557        break;
4558      }
4559    }
4560 <  else {
4561 <    chosenMET = &mets->at(0);
3438 <  }
4560 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4561 >    chosenMET = & mets->at (0);
4562  
4563    return chosenMET;
4564   }
# Line 3444 | Line 4567 | const BNelectron *
4567   OSUAnalysis::chosenElectron ()
4568   {
4569    const BNelectron *chosenElectron = 0;
4570 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
4571 <    vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
4572 <      cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
4570 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4571 >    flagPair electronFlags;
4572 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4573 >      if (cumulativeFlags.at("electrons").at(i).size()){
4574 >        electronFlags = cumulativeFlags.at("electrons").at(i);
4575 >        break;
4576 >      }
4577 >    }
4578      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4579 <      if(!electronFlags.at(electronIndex)) continue;
4579 >      if(!electronFlags.at(electronIndex).first) continue;
4580        chosenElectron = & electrons->at(electronIndex);
4581        break;
4582      }
4583    }
4584 <  else {
4585 <    chosenElectron = &electrons->at(0);
3458 <  }
4584 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4585 >    chosenElectron = & electrons->at (0);
4586  
4587    return chosenElectron;
4588   }
4589  
4590 +
4591   const BNmuon *
4592   OSUAnalysis::chosenMuon ()
4593   {
4594    const BNmuon *chosenMuon = 0;
4595 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
4596 <    vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
4597 <      cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
4595 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4596 >    flagPair muonFlags;
4597 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4598 >      if (cumulativeFlags.at("muons").at(i).size()){
4599 >        muonFlags = cumulativeFlags.at("muons").at(i);
4600 >        break;
4601 >      }
4602 >    }
4603      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4604 <      if(!muonFlags.at(muonIndex)) continue;
4604 >      if(!muonFlags.at(muonIndex).first) continue;
4605        chosenMuon = & muons->at(muonIndex);
4606        break;
4607      }
4608    }
4609 <  else {
4610 <    chosenMuon = &muons->at(0);
3478 <  }
4609 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4610 >    chosenMuon = & muons->at (0);
4611  
4612    return chosenMuon;
4613   }
4614  
3483
4615   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines