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.43 by wulsin, Thu Mar 28 10:17:32 2013 UTC vs.
Revision 1.90 by wulsin, Wed Jun 26 06:17:12 2013 UTC

# Line 11 | Line 11 | OSUAnalysis::OSUAnalysis (const edm::Par
11    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
12    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
13    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
14 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
15    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
16    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
17    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
18    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
19    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
20 <  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")),
36 <  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr"))
37 <
38 < {
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 >  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 +  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_);
49  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");
53
54  //always make the plot of number of primary verticex (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 60 | 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.find("pairs")==std::string::npos){ //just a single object
114 <      objectsToGet.push_back(tempInputCollection);
113 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
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);
129 >      }
130        objectsToPlot.push_back(tempInputCollection);
131        objectsToCut.push_back(tempInputCollection);
132 <    }
133 <    else{//pair of objects, need to add them both to the things to objectsToGet
134 <      int dashIndex = tempInputCollection.find("-");
135 <      int spaceIndex = tempInputCollection.find(" ");
136 <      int secondWordLength = spaceIndex - dashIndex;
78 <      objectsToGet.push_back(tempInputCollection);
79 <      objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
80 <      objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
81 <      objectsToPlot.push_back(tempInputCollection);
82 <      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
83 <      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
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);
137        objectsToCut.push_back(tempInputCollection);
138 <      objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
139 <      objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
138 >      objectsToCut.push_back(obj1);
139 >      objectsToCut.push_back(obj2);
140 >      objectsToPlot.push_back(tempInputCollection);
141 >      objectsToPlot.push_back(obj1);
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  
88    }
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 112 | 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 != "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 <    int maxNum = 24;
212 >
213 >    int maxNum = 25;
214      vector<double> binVector;
215      binVector.push_back(maxNum);
216      binVector.push_back(0);
# Line 154 | 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 174 | 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 );
193 <    directories.push_back(subDir);
194 <
195 <    std::map<std::string, TH1D*> oneDhistoMap;
196 <    oneDHists_.push_back(oneDhistoMap);
197 <    std::map<std::string, TH2D*> twoDhistoMap;
198 <    twoDHists_.push_back(twoDhistoMap);
199 <
200 <
201 <
202 <    //book all histograms included in the configuration
203 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
204 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
205 <      int numBinsElements = currentHistogram.bins.size();
206 <      int numInputVariables = currentHistogram.inputVariables.size();
207 <
208 <      if(numBinsElements != 3 && numBinsElements !=6) {
209 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
210 <        exit(0);
211 <      }
212 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
213 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
214 <        exit(0);
215 <      }
216 <      else if(numBinsElements == 3){
217 <        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));
218 <      }
219 <      else if(numBinsElements == 6){
220 <        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));
221 <
222 <      }
223 <
224 <
225 <      if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
226 <
227 <      // bin      particle type
228 <      // ---      -------------
229 <      //  0        unmatched
230 <      //  1        u
231 <      //  2        d
232 <      //  3        s
233 <      //  4        c
234 <      //  5        b
235 <      //  6        t
236 <      //  7        e
237 <      //  8        mu
238 <      //  9        tau
239 <      // 10        nu
240 <      // 11        g
241 <      // 12        gamma
242 <      // 13        Z
243 <      // 14        W
244 <      // 15        light meson
245 <      // 16        K meson
246 <      // 17        D meson
247 <      // 18        B meson
248 <      // 19        light baryon
249 <      // 20        strange baryon
250 <      // 21        charm baryon
251 <      // 22        bottom baryon
252 <      // 23        other
253 <
254 <      vector<TString> labelArray;
255 <      labelArray.push_back("unmatched");
256 <      labelArray.push_back("u");
257 <      labelArray.push_back("d");
258 <      labelArray.push_back("s");
259 <      labelArray.push_back("c");
260 <      labelArray.push_back("b");
261 <      labelArray.push_back("t");
262 <      labelArray.push_back("e");
263 <      labelArray.push_back("#mu");
264 <      labelArray.push_back("#tau");
265 <      labelArray.push_back("#nu");
266 <      labelArray.push_back("g");
267 <      labelArray.push_back("#gamma");
268 <      labelArray.push_back("Z");
269 <      labelArray.push_back("W");
270 <      labelArray.push_back("light meson");
271 <      labelArray.push_back("K meson");
272 <      labelArray.push_back("D meson");
273 <      labelArray.push_back("B meson");
274 <      labelArray.push_back("light baryon");
275 <      labelArray.push_back("strange baryon");
276 <      labelArray.push_back("charm baryon");
277 <      labelArray.push_back("bottom baryon");
278 <      labelArray.push_back("other");
279 <
280 <      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
281 <        if(currentHistogram.name.find("GenMatchIdVsMotherId")==std::string::npos) {
282 <          oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
283 <        }
284 <        else {
285 <          twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
286 <          twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
287 <        }
288 <      }
289 <      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=std::string::npos) {
290 <        twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->CenterTitle();
291 <        twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->CenterTitle();
292 <      }
293 <
294 <    }
295 <
296 <    // Book a histogram for the number of each object type to be plotted.  
297 <    // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().  
298 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
299 <      string currentObject = objectsToPlot.at(currentObjectIndex);
300 <      int maxNum = 10;
301 <      if(currentObject == "mcparticles") maxNum = 50;
302 <      else if(currentObject == "primaryvertexs") maxNum = 50;
303 <      else if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
304 <      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
305 <      else if(currentObject == "electron-muon pairs")     currentObject = "electronMuonPairs";
306 <      else if(currentObject == "track-event pairs")       currentObject = "trackEventPairs";
307 <      else if(currentObject == "electron-track pairs")    currentObject = "electronTrackPairs";  
308 <      else if(currentObject == "muon-track pairs")        currentObject = "muonTrackPairs";      
309 <      else if(currentObject == "muon-tau pairs")          currentObject = "muonTauPairs";        
310 <      else if(currentObject == "tau-tau pairs")           currentObject = "ditauPairs";
311 <      currentObject.at(0) = toupper(currentObject.at(0));  
312 <      string histoName = "num" + currentObject;
313 <
314 <      if(histoName == "numPrimaryvertexs"){
315 <        string newHistoName = histoName + "BeforePileupCorrection";
316 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
317 <        newHistoName = histoName + "AfterPileupCorrection";
318 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
319 <      }
320 <      else
321 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
322 <    }
323 <
324 <
325 <
326 <
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 <        objectsToGet.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 the things to objectsToGet
318 <        int dashIndex = tempInputCollection.find("-");
319 <        int spaceIndex = tempInputCollection.find(" ");
320 <        int secondWordLength = spaceIndex - dashIndex;
321 <        objectsToGet.push_back(tempInputCollection);
345 <        objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
346 <        objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
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);
322          objectsToCut.push_back(tempInputCollection);
323 <        objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
324 <        objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
323 >        objectsToCut.push_back(obj1);
324 >        objectsToCut.push_back(obj2);
325 >        objectsToGet.push_back(tempInputCollection);
326 >        objectsToGet.push_back(obj1);
327 >        objectsToGet.push_back(obj2ToGet);
328  
329        }
330  
# Line 354 | 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 374 | 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 389 | 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 400 | 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        }
404      tempCut.name = tempCutName;
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);
396  
397  
410
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();
415
610    }//end loop over channels
611  
612  
# Line 423 | 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  
427 }
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 436 | 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   {
638 <
638 >  //cout << "**********************\n\n\n";
639    // Retrieve necessary collections from the event.
640  
641 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
641 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
642      event.getByLabel (triggers_, triggers);
643  
644 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
644 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
645 >    event.getByLabel (trigobjs_, trigobjs);
646 >
647 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
648      event.getByLabel (jets_, jets);
649  
650 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
650 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
651      event.getByLabel (muons_, muons);
652  
653 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
653 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
654      event.getByLabel (electrons_, electrons);
655  
656 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
656 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
657      event.getByLabel (events_, events);
658  
659 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
659 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
660      event.getByLabel (taus_, taus);
661  
662 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
662 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
663      event.getByLabel (mets_, mets);
664  
665 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
665 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
666      event.getByLabel (tracks_, tracks);
667  
668 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
668 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
669      event.getByLabel (genjets_, genjets);
670  
671 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
671 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
672      event.getByLabel (mcparticles_, mcparticles);
673  
674 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
674 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
675      event.getByLabel (primaryvertexs_, primaryvertexs);
676  
677 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
677 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
678      event.getByLabel (bxlumis_, bxlumis);
679  
680 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
680 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
681      event.getByLabel (photons_, photons);
682  
683 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
683 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
684      event.getByLabel (superclusters_, superclusters);
685  
686 <  if (useTrackCaloRhoCorr_) {  
687 <    // Used only for pile-up correction of by-hand calculation of isolation energy.  
688 <    // This rho collection is not available in all BEANs.  
686 >  if (datasetType_ == "signalMC"){
687 >    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
688 >      event.getByLabel (stops_, stops);
689 >  }
690 >
691 >  if (useTrackCaloRhoCorr_) {
692 >    // Used only for pile-up correction of by-hand calculation of isolation energy.
693 >    // This rho collection is not available in all BEANs.
694      // For description of rho values for different jet reconstruction algorithms, see
695 <    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms  
696 <    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
695 >    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
696 >    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
697    }
698  
699 +  double masterScaleFactor = 1.0;
700  
701    //get pile-up event weight
702 <  double scaleFactor = 1.00;
703 <  if(doPileupReweighting_ && datasetType_ != "data")
704 <    scaleFactor = puWeight_->at (events->at (0).numTruePV);
702 >  if (doPileupReweighting_ && datasetType_ != "data") {
703 >    //for "data" datasets, the numTruePV is always set to -1
704 >    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
705 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
706 >  }
707  
708 +  stopCTauScaleFactor_ = 1.0;
709 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
710 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
711 +  masterScaleFactor *= stopCTauScaleFactor_;
712  
713    //loop over all channels
714  
715 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
716    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
717      channel currentChannel = channels.at(currentChannelIndex);
718  
# Line 507 | Line 720 | OSUAnalysis::analyze (const edm::Event &
720      counterMap passingCounter;
721      cumulativeFlags.clear ();
722  
723 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
724 +         iter != BNTreeBranchVals_.end(); iter++) {
725 +      iter->second.clear();  // clear array
726 +    }
727 +
728      bool triggerDecision = true;
729 <    if(currentChannel.triggers.size() != 0){  //triggers specified
730 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
729 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
730 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
731        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
732      }
733  
734      //loop over all cuts
517
518
519
735      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
736        cut currentCut = currentChannel.cuts.at(currentCutIndex);
522
737        for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
738          string currentObject = objectsToCut.at(currentObjectIndex);
739  
740          //initialize maps to get ready to set cuts
741 <        individualFlags[currentObject].push_back (vector<bool> ());
742 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
741 >        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
742 >        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
743  
744        }
745        for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
# Line 534 | Line 748 | OSUAnalysis::analyze (const edm::Event &
748          int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
749  
750  
751 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
752 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
751 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
752 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
753 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
754 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
755 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
756          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
757          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
758          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 547 | Line 764 | OSUAnalysis::analyze (const edm::Event &
764          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
765          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
766          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
767 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
768 +
769  
770  
771          else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
772                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
773                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
774                                                                     "muon-muon pairs");
775 +
776 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
777 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
778 +                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
779 +                                                                             "muon-secondary muon pairs");
780 +
781 +        else if(currentObject == "muon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
782 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
783 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
784 +                                                                             "muon-secondary jet pairs");
785 +        else if(currentObject == "photon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
786 +                                                                             cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
787 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
788 +                                                                             "photon-secondary jet pairs");
789 +
790 +        else if(currentObject == "electron-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
791 +                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
792 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
793 +                                                                             "electron-secondary jet pairs");
794 +
795 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
796 +                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
797 +                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
798 +                                                                                     "electron-secondary electron pairs");
799 +
800          else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
801                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
802                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
# Line 561 | Line 805 | OSUAnalysis::analyze (const edm::Event &
805                                                                         cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
806                                                                         cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
807                                                                         "electron-muon pairs");
808 <        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
809 <                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
810 <                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
811 <                                                                     "track-event pairs");
812 <        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
813 <                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
814 <                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
815 <                                                                        "electron-track pairs");
816 <        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
817 <                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
818 <                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
819 <                                                                    "muon-track pairs");
820 <        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
821 <                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
822 <                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
823 <                                                                  "muon-tau pairs");
824 <        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),taus.product(),
825 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
826 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
827 <                                                                 "tau-tau pairs");
828 <        
829 <        
808 >        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
809 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
810 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
811 >                                                                 "jet-jet pairs");
812 >        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
813 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
814 >                                                                 cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex),\
815 >                                                                 "jet-secondary jet pairs");
816 >        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
817 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
818 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
819 >                                                                      "electron-jet pairs");
820 >        else if(currentObject == "electron-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), \
821 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
822 >                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
823 >                                                                      "electron-photon pairs");
824 >        else if(currentObject == "photon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
825 >                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
826 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
827 >                                                                      "photon-jet pairs");
828 >        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
829 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
830 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
831 >                                                                  "muon-jet pairs");
832 >        else if(currentObject == "met-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
833 >                                                                  cumulativeFlags.at("mets").at(flagsForPairCutsIndex), \
834 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
835 >                                                                  "met-jet pairs");
836 >        else if(currentObject == "muon-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
837 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
838 >                                                                  cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
839 >                                                                  "muon-photon pairs");
840 >        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
841 >                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
842 >                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
843 >                                                                     "track-event pairs");
844 >        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
845 >                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
846 >                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
847 >                                                                        "electron-track pairs");
848 >        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
849 >                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
850 >                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
851 >                                                                    "muon-track pairs");
852 >        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
853 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
854 >                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
855 >                                                                  "muon-tau pairs");
856 >        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
857 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
858 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
859 >                                                                 "tau-tau pairs");
860 >        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
861 >                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
862 >                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
863 >                                                                   "tau-track pairs");
864 >        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
865 >                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
866 >                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
867 >                                                                          "electron-trigobj pairs");
868 >        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
869 >                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
870 >                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
871 >                                                                      "muon-trigobj pairs");
872 >
873 >        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
874        }
875  
876  
877  
878      }//end loop over all cuts
591
592
879      //use cumulative flags to apply cuts at event level
880  
881 +    //a vector to store cumulative cut descisions after each cut.
882 +    vector<bool> eventPassedPreviousCuts;
883      bool eventPassedAllCuts = true;
596
884      //apply trigger (true if none were specified)
885      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
886  
600
601
887      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
888  
889        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 606 | Line 891 | OSUAnalysis::analyze (const edm::Event &
891        int numberPassing = 0;
892  
893        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
894 <        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
894 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
895        }
611
896        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
897        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
614
898        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
899 <
899 >      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
900      }
901 +    double scaleFactor = masterScaleFactor;
902  
903 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
904 +    if(applyLeptonSF_ && datasetType_ != "data"){
905 +      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
906 +        flagPair muonFlags;
907 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
908 +          if (cumulativeFlags.at("muons").at(i).size()){
909 +            muonFlags = cumulativeFlags.at("muons").at(i);
910 +            break;
911 +          }
912 +        }
913 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
914 +          if(!muonFlags.at(muonIndex).second) continue;
915 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
916 +        }
917 +      }
918 +      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
919 +        flagPair electronFlags;
920 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
921 +          if (cumulativeFlags.at("electrons").at(i).size()){
922 +            electronFlags = cumulativeFlags.at("electrons").at(i);
923 +            break;
924 +          }
925 +        }
926 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
927 +          if(!electronFlags.at(electronIndex).second) continue;
928 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
929 +        }
930 +      }
931 +    }
932 +    if(applyBtagSF_ && datasetType_ != "data"){
933 +     if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
934 +       flagPair jetFlags;
935 +        vector<double> jetSFs;
936 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
937 +          if (cumulativeFlags.at("jets").at(i).size()){
938 +            jetFlags = cumulativeFlags.at("jets").at(i);
939 +            break;
940 +          }
941 +        }
942 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
943 +          if(!jetFlags.at(jetIndex).second) continue;
944 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour);
945 +          jetSFs.push_back(jetSFTmp);
946 +        }
947 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_, maxBtag_ );
948 +      }
949 +    }
950 +    scaleFactor *= muonScaleFactor_;
951 +    scaleFactor *= electronScaleFactor_;
952 +    scaleFactor *= bTagScaleFactor_;
953      cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
954  
955 +    if (printEventInfo_) {
956 +      // Write information about event to screen, for testing purposes.
957 +      cout << "Event passed all cuts in channel " <<  currentChannel.name
958 +           << ": run="  << events->at(0).run
959 +           << "  lumi=" << events->at(0).lumi
960 +           << "  event=" << events->at(0).evt
961 +           << endl;
962 +    }
963  
964  
965 <    if(!eventPassedAllCuts)continue;
965 >    //filling histograms
966 >    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
967 >      uint currentDir;
968 >      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
969 >      else{
970 >        currentDir = currentCut;
971 >      }
972  
625    if (printEventInfo_) {
626      // Write information about event to screen, for testing purposes.  
627      cout << "Event passed all cuts in channel " <<  currentChannel.name
628           << ": run="  << events->at(0).run
629           << "  lumi=" << events->at(0).lumi
630           << "  event=" << events->at(0).evt
631           << endl;  
632    }
973  
974 +      if(eventPassedPreviousCuts.at(currentDir)){
975  
976 <    //     if(datasetType_ != "data") {
977 <    //       scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
637 <    //       scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
638 <    //     }
976 >        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
977 >          histogram currentHistogram = histograms.at(histogramIndex);
978  
979 <    //filling histograms
641 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
642 <      histogram currentHistogram = histograms.at(histogramIndex);
979 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) cout << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
980  
981 <      if(currentHistogram.inputVariables.size() == 1){
982 <        TH1D* histo;
983 <        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
984 <
985 <
986 <
987 <        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
988 <        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
989 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
990 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
991 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
992 <        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
993 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
994 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
995 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
996 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
997 <                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
998 <                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
999 <        else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),        
1000 <                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),  
1001 <                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);      
1002 <        else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),        
1003 <                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),  
1004 <                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);      
1005 <        else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),    
1006 <                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),      
1007 <                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);  
1008 <        else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),      
1009 <                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),        
1010 <                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);    
1011 <        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
1012 <        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
1013 <        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
1014 <        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
1015 <        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
1016 <        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
1017 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
1018 <        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
1019 <        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
1020 <        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
1021 <      }
1022 <      else if(currentHistogram.inputVariables.size() == 2){
1023 <        TH2D* histo;
1024 <        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
1025 <
1026 <
1027 <
1028 <        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
1029 <        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
1030 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1031 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
1032 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
1033 <        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
1034 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1035 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
1036 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
1037 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1038 <                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
1039 <                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
1040 <        else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),        
1041 <                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),          
1042 <                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);      
1043 <        else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),        
1044 <                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),          
1045 <                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);      
1046 <        else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),    
1047 <                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),      
1048 <                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);  
1049 <        else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),      
1050 <                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),        
1051 <                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);    
1052 <        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
1053 <        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
1054 <        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
1055 <        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
1056 <        else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1057 <                                                                                         cumulativeFlags.at("tracks").back(),cumulativeFlags.at("events").back(),
1058 <                                                                                         cumulativeFlags.at("track-event pairs").back(),scaleFactor);  
1059 <        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
1060 <        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
1061 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
1062 <        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
1063 <        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
1064 <        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
1065 <      }
1066 <    }
1067 <
1068 <    //fills histograms with the sizes of collections
1069 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1070 <
1071 <      string currentObject = objectsToPlot.at(currentObjectIndex);
1072 <
1073 <      string objectToPlot = "";  
1074 <
1075 <      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().  
1076 <      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
1077 <      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
1078 <      else if(currentObject == "electron-muon pairs")     objectToPlot = "electronMuonPairs";
1079 <      else if(currentObject == "electron-track pairs")    objectToPlot = "electronTrackPairs";
1080 <      else if(currentObject == "muon-track pairs")        objectToPlot = "muonTrackPairs";      
1081 <      else if(currentObject == "muon-tau pairs")          objectToPlot = "muonTauPairs";        
1082 <      else if(currentObject == "tau-tau pairs")           objectToPlot = "ditauPairs";
1083 <      else if(currentObject == "track-event pairs")       objectToPlot = "trackEventPairs";  
1084 <      else objectToPlot = currentObject;
1085 <      string tempCurrentObject = objectToPlot;
1086 <      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));  
1087 <      string histoName = "num" + tempCurrentObject;
1088 <
1089 <
1090 <      //set position of primary vertex in event, in order to calculate quantities relative to it
1091 <      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1092 <        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
1093 <        int numToPlot = 0;
1094 <        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1095 <          if(lastCutFlags.at(currentFlag)) numToPlot++;
1096 <        }
1097 <        if(objectToPlot == "primaryvertexs"){
1098 <          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1099 <          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1100 <        }
1101 <        else {
1102 <          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
1103 <        }
1104 <      }
1105 <      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
1106 <      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
1107 <      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
1108 <      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
1109 <      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
1110 <      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
1111 <      else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
1112 <      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
1113 <      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
1114 <      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
1115 <      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
1116 <      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
1117 <      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
1118 <      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
1119 <      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
1120 <      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
1121 <      else if(objectToPlot == "primaryvertexs"){
1122 <        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1123 <        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1124 <      }
981 >          if(currentHistogram.inputVariables.size() == 1){
982 >            TH1D* histo;
983 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
984 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
985 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
986 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
987 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
988 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
989 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
990 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
991 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
992 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
993 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
994 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
995 >             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
996 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
997 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
998 >             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
999 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1000 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1001 >             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1002 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1003 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1004 >
1005 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1006 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
1007 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
1008 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1009 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
1010 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
1011 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1012 >             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1013 >                                                                                                     cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1014 >                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1015 >
1016 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1017 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1018 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1019 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
1020 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
1021 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1022 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
1023 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1024 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1025 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(), \
1026 >                                                                                              cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1027 >                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1028 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
1029 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1030 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1031 >            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
1032 >                                                                                          cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1033 >                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1034 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(), \
1035 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1036 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1037 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(), \
1038 >                                                                                          cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1039 >                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1040 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1041 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1042 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1043 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1044 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1045 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1046 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1047 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1048 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1049 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1050 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1051 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1052 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1053 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1054 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1055 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1056 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1057 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1058 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1059 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1060 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1061 >
1062 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1063 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1064 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1065 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1066 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1067 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1068 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1069 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1070 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1071 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1072 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1073 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1074 >          }
1075 >          else if(currentHistogram.inputVariables.size() == 2){
1076 >            TH2D* histo;
1077 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1078 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1079 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1080 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1081 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1082 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1083 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1084 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1085 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1086 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1087 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1088 >            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1089 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1090 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1091 >            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1092 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1093 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1094 >            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1095 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1096 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1097 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1098 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1099 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1100 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1101 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1102 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1103 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1104 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1105 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1106 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1107 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1108 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1109 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1110 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1111 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1112 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1113 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1114 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(), \
1115 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1116 >                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1117 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1118 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1119 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1120 >            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1121 >                                                                                         cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1122 >                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1123 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1124 >                                                                                          cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1125 >                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1126 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1127 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1128 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1129 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1130 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1131 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1132 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1133 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1134 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1135 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1136 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1137 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1138 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1139 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1140 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1141 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1142 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1143 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1144 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1145 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1146 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1147 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1148 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1149 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1150 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1151 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1152 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1153 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1154 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1155 >                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1156 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1157 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1158 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1159 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1160 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1161 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1162 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1163 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1164 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1165 >          }
1166  
1167 <    } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1167 >        }
1168  
791  } //end loop over channel
1169  
1170 <  masterCutFlow_->fillCutFlow(scaleFactor);
1170 >        //fills histograms with the sizes of collections
1171 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1172 >
1173 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1174 >          string objectToPlot = "";
1175 >
1176 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1177 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1178 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1179 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1180 >          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1181 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1182 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1183 >          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1184 >          else if(currentObject == "muon-photon pairs")                  objectToPlot = "muonPhotonPairs";
1185 >          else if(currentObject == "photon-jet pairs")                   objectToPlot = "photonJetPairs";
1186 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1187 >          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1188 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1189 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1190 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1191 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1192 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1193 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1194 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1195 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1196 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1197 >          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1198 >          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1199 >          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1200 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1201 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1202 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1203 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1204 >          else objectToPlot = currentObject;
1205 >
1206 >          string tempCurrentObject = objectToPlot;
1207 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1208 >          string histoName = "num" + tempCurrentObject;
1209 >
1210 >
1211 >          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1212 >            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1213 >            int numToPlot = 0;
1214 >            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1215 >              if(lastCutFlags.at(currentFlag).second) numToPlot++;
1216 >            }
1217 >
1218 >            if(objectToPlot == "primaryvertexs"){
1219 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1220 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1221 >            }
1222 >            else {
1223 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1224 >            }
1225 >          }
1226 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1227 >
1228 >
1229 >      } // end if(eventPassedPreviousCuts.at(currentDir))
1230 >    } // end loop over cuts
1231 >
1232 >    if (!useEDMFormat_ && eventPassedAllCuts){
1233 >      // Assign BNTree variables
1234 >      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1235 >        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1236 >        string coll = brSpecs.inputCollection;
1237 >        if (cumulativeFlags.count(coll) == 0) cout << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1238 >
1239 >        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1240 >        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1241 >        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1242 >        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1243 >        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1244 >        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1245 >        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1246 >        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1247 >        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1248 >        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1249 >        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1250 >        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1251 >        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1252 >        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1253 >        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1254 >        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1255 >        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1256 >        else if(coll == "stops"
1257 >                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1258 >      } // end loop over branches
1259 >
1260 >      if (!BNTrees_.at(currentChannelIndex)) { cout << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1261 >      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1262 >    }
1263 >
1264 >    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1265 >
1266 >  } // end loop over channel
1267 >
1268 >  masterCutFlow_->fillCutFlow(masterScaleFactor);
1269 >
1270 >  event.put (channelDecisions, "channelDecisions");
1271  
1272   } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1273  
# Line 807 | Line 1284 | OSUAnalysis::evaluateComparison (double
1284    else if(comparison == "==") return testValue == cutValue;
1285    else if(comparison == "=") return testValue == cutValue;
1286    else if(comparison == "!=") return testValue != cutValue;
1287 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1287 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1288 >
1289 > }
1290 >
1291 > bool
1292 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1293 >
1294 >
1295 >  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 if(comparison == "!=") return testValue != cutValue;
1302 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1303  
1304   }
1305  
1306   bool
1307 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1307 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1308  
1309 +  //initialize to false until a chosen trigger is passed
1310    bool triggerDecision = false;
1311  
1312 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1313 <    {
1314 <      if(trigger->pass != 1) continue;
1315 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1316 <        {
1317 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1318 <            triggerDecision = true;
1319 <          }
1320 <        }
1312 >  if (printAllTriggers_) cout << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1313 >  //loop over all triggers defined in the event
1314 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1315 >
1316 >    if (printAllTriggers_) cout << "   " << trigger->name << endl;
1317 >
1318 >    //we're only interested in triggers that actually passed
1319 >    if(trigger->pass != 1) continue;
1320 >
1321 >    //if the event passes one of the veto triggers, exit and return false
1322 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1323 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1324      }
1325 <  return triggerDecision;
1325 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1326 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1327 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1328 >    }
1329 >  }
1330  
1331 +  printAllTriggers_ = false;  // only print triggers once, not every event
1332 +
1333 +  //if none of the veto triggers fired:
1334 +  //return the OR of all the chosen triggers
1335 +  if (triggersToTest.size() != 0) return triggerDecision;
1336 +  //or if no triggers were defined return true
1337 +  else return true;
1338   }
1339  
1340 < std::vector<std::string>
1340 >
1341 > vector<string>
1342   OSUAnalysis::splitString (string inputString){
1343  
1344 <  std::stringstream stringStream(inputString);
1345 <  std::istream_iterator<std::string> begin(stringStream);
1346 <  std::istream_iterator<std::string> end;
1347 <  std::vector<std::string> stringVector(begin, end);
1344 >  stringstream stringStream(inputString);
1345 >  istream_iterator<string> begin(stringStream);
1346 >  istream_iterator<string> end;
1347 >  vector<string> stringVector(begin, end);
1348    return stringVector;
1349  
1350   }
1351  
1352 +
1353 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1354 +  // Set two object strings from the tempInputCollection string,
1355 +  // For example, if tempInputCollection is "electron-muon pairs",
1356 +  // then obj1 = "electrons" and obj2 = "muons".
1357 +  // Note that the objects have an "s" appended.
1358 +
1359 +  int dashIndex = tempInputCollection.find("-");
1360 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1361 +  int secondWordLength = spaceIndex - dashIndex;
1362 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1363 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1364 +
1365 + }
1366 +
1367 +
1368 + string OSUAnalysis::getObjToGet(string obj) {
1369 +  // Return the string corresponding to the object to get for the given obj string.
1370 +  // Right now this only handles the case in which obj contains "secondary",
1371 +  // e.g, "secondary muons".
1372 +  // Note that "s" is NOT appended.
1373 +
1374 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1375 +  int firstSpaceIndex = obj.find_first_of(" ");
1376 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1377 +
1378 + }
1379 +
1380 +
1381 + //!jet valueLookup
1382   double
1383 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1383 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1384  
1385    double value = 0.0;
1386    if(variable == "energy") value = object->energy;
# Line 961 | Line 1499 | OSUAnalysis::valueLookup (const BNjet* o
1499    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1500    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1501  
1502 +  //user defined variable
1503 +  else if(variable == "disappTrkLeadingJetID") {
1504 +    value = object->pt > 110
1505 +      && fabs(object->eta) < 2.4
1506 +      && object->chargedHadronEnergyFraction > 0.2
1507 +      && object->neutralHadronEnergyFraction < 0.7
1508 +      && object->chargedEmEnergyFraction < 0.5
1509 +      && object->neutralEmEnergyFraction < 0.7;
1510 +  }
1511  
1512 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1512 >  else if(variable == "disappTrkSubLeadingJetID") {
1513 >    value = object->pt > 30
1514 >      && fabs(object->eta) < 4.5
1515 >      && object->neutralHadronEnergyFraction < 0.7
1516 >      && object->chargedEmEnergyFraction < 0.5;
1517 >  }
1518 >
1519 >  else if(variable == "dPhiMet") {
1520 >    if (const BNmet *met = chosenMET ()) {
1521 >      value = deltaPhi (object->phi, met->phi);
1522 >    } else value = -999;
1523 >  }
1524 >
1525 >
1526 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1527  
1528    value = applyFunction(function, value);
1529  
1530    return value;
1531 < }
971 <
1531 > } // end jet valueLookup
1532  
1533  
1534 + //!muon valueLookup
1535   double
1536 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1536 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1537  
1538    double value = 0.0;
1539    if(variable == "energy") value = object->energy;
# Line 1127 | Line 1688 | OSUAnalysis::valueLookup (const BNmuon*
1688    else if(variable == "time_ndof") value = object->time_ndof;
1689  
1690    //user-defined variables
1691 +  else if(variable == "looseID") {
1692 +    value = object->pt > 10 &&
1693 +      (object->isGlobalMuon  > 0 ||
1694 +       object->isTrackerMuon > 0);
1695 +  }
1696    else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1697    else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1698    else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1699    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1700    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1701    else if(variable == "metMT") {
1702 <    const BNmet *met = chosenMET ();
1137 <    if (met)
1702 >    if (const BNmet *met = chosenMET ())
1703        {
1704 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1705 <          p2 (met->px, met->py, 0.0, met->pt);
1141 <
1142 <        value = (p1 + p2).Mt ();
1704 >        double dPhi = deltaPhi (object->phi, met->phi);
1705 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1706        }
1707      else
1708        value = -999;
# Line 1257 | Line 1820 | OSUAnalysis::valueLookup (const BNmuon*
1820      value = object->isGlobalMuon > 0                \
1821        && object->isPFMuon > 0                        \
1822        && object->normalizedChi2 < 10                \
1823 <                                  && object->numberOfValidMuonHits > 0        \
1823 >      && object->numberOfValidMuonHits > 0        \
1824        && object->numberOfMatchedStations > 1        \
1825        && fabs(object->correctedD0Vertex) < 0.2        \
1826        && fabs(object->correctedDZ) < 0.5        \
# Line 1266 | Line 1829 | OSUAnalysis::valueLookup (const BNmuon*
1829    }
1830    else if(variable == "tightIDdisplaced"){
1831      value = object->isGlobalMuon > 0                \
1832 +      && object->isPFMuon > 0                        \
1833        && object->normalizedChi2 < 10                \
1834 <                                  && object->numberOfValidMuonHits > 0        \
1834 >      && object->numberOfValidMuonHits > 0        \
1835        && object->numberOfMatchedStations > 1        \
1836        && object->numberOfValidPixelHits > 0        \
1837        && object->numberOfLayersWithMeasurement > 5;
1838    }
1839  
1840 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1840 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1841  
1842    else if(variable == "genMatchedPdgId"){
1843      int index = getGenMatchedParticleIndex(object);
# Line 1293 | Line 1857 | OSUAnalysis::valueLookup (const BNmuon*
1857    }
1858    else if(variable == "genMatchedMotherIdReverse"){
1859      int index = getGenMatchedParticleIndex(object);
1860 <    if(index == -1) value = 23;
1861 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1860 >    if(index == -1) value = 24;
1861 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1862    }
1863    else if(variable == "genMatchedGrandmotherId"){
1864      int index = getGenMatchedParticleIndex(object);
# Line 1306 | Line 1870 | OSUAnalysis::valueLookup (const BNmuon*
1870      }
1871      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1872    }
1873 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1874 +    int index = getGenMatchedParticleIndex(object);
1875 +    if(index == -1) value = 24;
1876 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1877 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1878 +      if(motherIndex == -1) value = 24;
1879 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1880 +    }
1881 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1882 +  }
1883 +  else if(variable == "pfMuonsFromVertex"){
1884 +    double d0Error, dzError;
1885  
1886 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1887 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1888 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1889 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1890 +      || fabs (object->correctedDZ / dzError) > 99.0;
1891 +    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1892 +  }
1893  
1894  
1895 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1895 >
1896 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1897  
1898    value = applyFunction(function, value);
1899  
1900    return value;
1901 < }
1901 > } // end muon valueLookup
1902  
1903  
1904 + //!electron valueLookup
1905   double
1906 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1906 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1907  
1908    double value = 0.0;
1909    if(variable == "energy") value = object->energy;
# Line 1484 | Line 2069 | OSUAnalysis::valueLookup (const BNelectr
2069    else if(variable == "detIso") value = (object->trackIso) / object->pt;
2070    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2071    else if(variable == "metMT") {
2072 <    const BNmet *met = chosenMET ();
1488 <    if (met)
2072 >    if (const BNmet *met = chosenMET ())
2073        {
2074 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
2075 <          p2 (met->px, met->py, 0.0, met->pt);
1492 <
1493 <        value = (p1 + p2).Mt ();
2074 >        double dPhi = deltaPhi (object->phi, met->phi);
2075 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2076        }
2077      else
2078        value = -999;
# Line 1582 | Line 2164 | OSUAnalysis::valueLookup (const BNelectr
2164        }
2165    }
2166  
2167 +  else if(variable == "looseID"){
2168 +    value = object->pt > 10
2169 +      && object->mvaNonTrigV0 > 0;
2170 +      }
2171    else if(variable == "correctedD0VertexInEBPositiveCharge"){
2172      if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2173      else value = -999;
# Line 1655 | Line 2241 | OSUAnalysis::valueLookup (const BNelectr
2241    }
2242  
2243  
2244 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2244 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2245  
2246    else if(variable == "genMatchedPdgId"){
2247      int index = getGenMatchedParticleIndex(object);
# Line 1676 | Line 2262 | OSUAnalysis::valueLookup (const BNelectr
2262    }
2263    else if(variable == "genMatchedMotherIdReverse"){
2264      int index = getGenMatchedParticleIndex(object);
2265 <    if(index == -1) value = 23;
2266 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2265 >    if(index == -1) value = 24;
2266 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2267    }
2268    else if(variable == "genMatchedGrandmotherId"){
2269      int index = getGenMatchedParticleIndex(object);
# Line 1689 | Line 2275 | OSUAnalysis::valueLookup (const BNelectr
2275      }
2276      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2277    }
2278 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2279 +    int index = getGenMatchedParticleIndex(object);
2280 +    if(index == -1) value = 24;
2281 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2282 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2283 +      if(motherIndex == -1) value = 24;
2284 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2285 +    }
2286 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2287 +  }
2288 +  else if(variable == "pfElectronsFromVertex"){
2289 +    double d0Error, dzError;
2290  
2291 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2292 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2293 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2294 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2295 +      || fabs (object->correctedDZ / dzError) > 99.0;
2296 +    value = !value;
2297 +  }
2298  
2299  
2300 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2300 >
2301 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2302  
2303    value = applyFunction(function, value);
2304  
2305    return value;
2306 < }
2306 > } // end electron valueLookup
2307  
2308  
2309 + //!event valueLookup
2310   double
2311 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2311 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2312  
2313    double value = 0.0;
2314  
# Line 1770 | Line 2377 | OSUAnalysis::valueLookup (const BNevent*
2377    else if(variable == "id2") value = object->id2;
2378    else if(variable == "evt") value = object->evt;
2379    else if(variable == "puScaleFactor"){
2380 <    if(datasetType_ != "data")
2380 >    if(doPileupReweighting_ && datasetType_ != "data")
2381        value = puWeight_->at (events->at (0).numTruePV);
2382      else
2383        value = 1.0;
2384    }
2385 <  else if(variable == "muonScaleFactor"){
2386 <    if(datasetType_ != "data")
2387 <      //      value = muonSFWeight_->at (chosenMuon ()->eta);
2388 <      value = 1.0;
2389 <    else
1783 <      value = 1.0;
1784 <  }
1785 <  else if(variable == "electronScaleFactor"){
1786 <    if(datasetType_ != "data")
1787 <      //      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1788 <      value = 1.0;
1789 <    else
1790 <      value = 1.0;
1791 <  }
1792 <
1793 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2385 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2386 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2387 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2388 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2389 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2390  
2391    value = applyFunction(function, value);
2392  
2393    return value;
2394 < }
2394 > } // end event valueLookup
2395 >
2396  
2397 + //!tau valueLookup
2398   double
2399 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2399 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2400  
2401    double value = 0.0;
2402  
# Line 1842 | Line 2440 | OSUAnalysis::valueLookup (const BNtau* o
2440    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2441    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2442  
2443 +  else if (variable == "looseHadronicID") {
2444 +    value = object->pt > 10
2445 +      && object->eta < 2.3
2446 +      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2447 +      && object->HPSdecayModeFinding > 0
2448 +      && object->HPSagainstElectronLoose > 0
2449 +      && object->HPSagainstMuonTight > 0;
2450 +  }
2451  
2452 <
1847 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2452 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2453  
2454    else if(variable == "genMatchedPdgId"){
2455      int index = getGenMatchedParticleIndex(object);
# Line 1864 | Line 2469 | OSUAnalysis::valueLookup (const BNtau* o
2469    }
2470    else if(variable == "genMatchedMotherIdReverse"){
2471      int index = getGenMatchedParticleIndex(object);
2472 <    if(index == -1) value = 23;
2473 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2472 >    if(index == -1) value = 24;
2473 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2474    }
2475    else if(variable == "genMatchedGrandmotherId"){
2476      int index = getGenMatchedParticleIndex(object);
# Line 1877 | Line 2482 | OSUAnalysis::valueLookup (const BNtau* o
2482      }
2483      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2484    }
2485 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2486 +    int index = getGenMatchedParticleIndex(object);
2487 +    if(index == -1) value = 24;
2488 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2489 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2490 +      if(motherIndex == -1) value = 24;
2491 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2492 +    }
2493 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2494 +  }
2495  
2496  
2497 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2497 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2498  
2499    value = applyFunction(function, value);
2500  
2501    return value;
2502 < }
2502 > } // end tau valueLookup
2503  
2504 +
2505 + //!met valueLookup
2506   double
2507 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2507 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2508  
2509    double value = 0.0;
2510  
# Line 1951 | Line 2568 | OSUAnalysis::valueLookup (const BNmet* o
2568    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2569    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2570  
2571 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2571 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2572  
2573    value = applyFunction(function, value);
2574  
2575    return value;
2576 < }
2576 > } // end met valueLookup
2577  
2578 +
2579 + //!track valueLookup
2580   double
2581 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2581 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2582  
2583    double value = 0.0;
2584    double pMag = sqrt(object->pt * object->pt +
2585 <                     object->pz * object->pz);
2586 <  
2585 >                     object->pz * object->pz);
2586 >
2587    if(variable == "pt") value = object->pt;
2588    else if(variable == "px") value = object->px;
2589    else if(variable == "py") value = object->py;
# Line 1985 | Line 2604 | OSUAnalysis::valueLookup (const BNtrack*
2604  
2605  
2606    //additional BNs info for disappTrks
1988  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2607    else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2608    else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2609    else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2610    else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2611    else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2612    else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2613 +  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2614    else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2615    else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2616    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2617 <  
2617 >  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2618  
2619    //user defined variables
2620    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;
2621    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2622 +  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2623    else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2624    else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2625 <  else if(variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object);  
2626 <  else if(variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object) / pMag;  
2625 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2626 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2627    else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2628    else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2629    else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2630    else if(variable == "ptError")                    value = object->ptError;
2631    else if(variable == "ptRes")                      value = getTrkPtRes(object);
2632 <  else if (variable == "d0wrtPV"){      
2633 <    double vx = object->vx - chosenVertex ()->x,        
2634 <      vy = object->vy - chosenVertex ()->y,      
2635 <      px = object->px,  
2636 <      py = object->py,  
2637 <      pt = object->pt;  
2638 <    value = (-vx * py + vy * px) / pt;  
2639 <  }      
2640 <  else if (variable == "dZwrtPV"){      
2641 <    double vx = object->vx - chosenVertex ()->x,        
2642 <      vy = object->vy - chosenVertex ()->y,      
2643 <      vz = object->vz - chosenVertex ()->z,      
2644 <      px = object->px,  
2645 <      py = object->py,  
2646 <      pz = object->pz,  
2647 <      pt = object->pt;  
2648 <    value = vz - (vx * px + vy * py)/pt * (pz/pt);      
2649 <  }    
2650 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2632 >  else if (variable == "d0wrtPV"){
2633 >    double vx = object->vx - chosenVertex ()->x,
2634 >      vy = object->vy - chosenVertex ()->y,
2635 >      px = object->px,
2636 >      py = object->py,
2637 >      pt = object->pt;
2638 >    value = (-vx * py + vy * px) / pt;
2639 >  }
2640 >  else if (variable == "dZwrtPV"){
2641 >    double vx = object->vx - chosenVertex ()->x,
2642 >      vy = object->vy - chosenVertex ()->y,
2643 >      vz = object->vz - chosenVertex ()->z,
2644 >      px = object->px,
2645 >      py = object->py,
2646 >      pz = object->pz,
2647 >      pt = object->pt;
2648 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2649 >  }
2650 >
2651 >
2652 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2653  
2654    else if(variable == "genMatchedPdgId"){
2655      int index = getGenMatchedParticleIndex(object);
# Line 2048 | Line 2670 | OSUAnalysis::valueLookup (const BNtrack*
2670    }
2671    else if(variable == "genMatchedMotherIdReverse"){
2672      int index = getGenMatchedParticleIndex(object);
2673 <    if(index == -1) value = 23;
2674 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2673 >    if(index == -1) value = 24;
2674 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2675    }
2676    else if(variable == "genMatchedGrandmotherId"){
2677      int index = getGenMatchedParticleIndex(object);
# Line 2061 | Line 2683 | OSUAnalysis::valueLookup (const BNtrack*
2683      }
2684      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2685    }
2686 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2687 +    int index = getGenMatchedParticleIndex(object);
2688 +    if(index == -1) value = 24;
2689 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2690 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2691 +      if(motherIndex == -1) value = 24;
2692 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2693 +    }
2694 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2695 +  }
2696  
2697  
2698  
2699 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2699 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2700  
2701    value = applyFunction(function, value);
2702  
2703    return value;
2704 < }
2704 > } // end track valueLookup
2705  
2706 +
2707 + //!genjet valueLookup
2708   double
2709 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2709 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2710  
2711    double value = 0.0;
2712  
# Line 2092 | Line 2726 | OSUAnalysis::valueLookup (const BNgenjet
2726    else if(variable == "charge") value = object->charge;
2727  
2728  
2729 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2729 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2730  
2731    value = applyFunction(function, value);
2732  
2733    return value;
2734   }
2735  
2736 + //!mcparticle valueLookup
2737   double
2738 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2738 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2739  
2740    double value = 0.0;
2741  
# Line 2225 | Line 2860 | OSUAnalysis::valueLookup (const BNmcpart
2860    }
2861  
2862  
2863 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2863 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2864  
2865    value = applyFunction(function, value);
2866  
2867    return value;
2868 < }
2868 > } // end mcparticle valueLookup
2869 >
2870  
2871 + //!primaryvertex valueLookup
2872   double
2873 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2873 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2874  
2875    double value = 0.0;
2876  
# Line 2252 | Line 2889 | OSUAnalysis::valueLookup (const BNprimar
2889    else if(variable == "isGood") value = object->isGood;
2890  
2891  
2892 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2892 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2893  
2894    value = applyFunction(function, value);
2895  
2896    return value;
2897   }
2898  
2899 + //!bxlumi valueLookup
2900   double
2901 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2901 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2902  
2903    double value = 0.0;
2904  
# Line 2269 | Line 2907 | OSUAnalysis::valueLookup (const BNbxlumi
2907    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2908  
2909  
2910 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2910 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2911  
2912    value = applyFunction(function, value);
2913  
2914    return value;
2915   }
2916  
2917 + //!photon valueLookup
2918   double
2919 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2919 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2920  
2921    double value = 0.0;
2922  
# Line 2352 | Line 2991 | OSUAnalysis::valueLookup (const BNphoton
2991    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2992  
2993  
2355
2994  
2995 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2995 >
2996 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2997  
2998    else if(variable == "genMatchedPdgId"){
2999      int index = getGenMatchedParticleIndex(object);
# Line 2376 | Line 3015 | OSUAnalysis::valueLookup (const BNphoton
3015    }
3016    else if(variable == "genMatchedMotherIdReverse"){
3017      int index = getGenMatchedParticleIndex(object);
3018 <    if(index == -1) value = 23;
3019 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
3018 >    if(index == -1) value = 24;
3019 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
3020    }
3021    else if(variable == "genMatchedGrandmotherId"){
3022      int index = getGenMatchedParticleIndex(object);
# Line 2389 | Line 3028 | OSUAnalysis::valueLookup (const BNphoton
3028      }
3029      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3030    }
3031 +  else if(variable == "genMatchedGrandmotherIdReverse"){
3032 +    int index = getGenMatchedParticleIndex(object);
3033 +    if(index == -1) value = 24;
3034 +    else if(fabs(mcparticles->at(index).motherId) == 15){
3035 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3036 +      if(motherIndex == -1) value = 24;
3037 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3038 +    }
3039 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3040 +  }
3041  
3042  
3043 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3043 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3044  
3045    value = applyFunction(function, value);
3046  
3047    return value;
3048 < }
3048 > } // end photon valueLookup
3049 >
3050  
3051 + //!supercluster valueLookup
3052   double
3053 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
3053 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
3054  
3055    double value = 0.0;
3056  
# Line 2413 | Line 3064 | OSUAnalysis::valueLookup (const BNsuperc
3064    else if(variable == "theta") value = object->theta;
3065  
3066  
3067 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3067 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3068  
3069    value = applyFunction(function, value);
3070  
3071    return value;
3072   }
3073  
3074 + //!trigobj valueLookup
3075 + double
3076 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3077  
3078 +  double value = 0.0;
3079 +
3080 +  if(variable == "pt") value = object->pt;
3081 +  else if(variable == "eta") value = object->eta;
3082 +  else if(variable == "phi") value = object->phi;
3083 +  else if(variable == "px") value = object->px;
3084 +  else if(variable == "py") value = object->py;
3085 +  else if(variable == "pz") value = object->pz;
3086 +  else if(variable == "et") value = object->et;
3087 +  else if(variable == "energy") value = object->energy;
3088 +  else if(variable == "etTotal") value = object->etTotal;
3089 +  else if(variable == "id") value = object->id;
3090 +  else if(variable == "charge") value = object->charge;
3091 +  else if(variable == "isIsolated") value = object->isIsolated;
3092 +  else if(variable == "isMip") value = object->isMip;
3093 +  else if(variable == "isForward") value = object->isForward;
3094 +  else if(variable == "isRPC") value = object->isRPC;
3095 +  else if(variable == "bx") value = object->bx;
3096 +  else if(variable == "filter") {
3097 +    if ((stringValue = object->filter) == "")
3098 +      stringValue = "none";  // stringValue should only be empty if value is filled
3099 +  }
3100 +
3101 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3102 +
3103 +  value = applyFunction(function, value);
3104 +
3105 +  return value;
3106 + }
3107 +
3108 + //!muon-muon pair valueLookup
3109   double
3110 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
3110 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3111  
3112    double value = 0.0;
3113  
3114    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3115 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3116    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3117    else if(variable == "invMass"){
3118      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2483 | Line 3169 | OSUAnalysis::valueLookup (const BNmuon*
3169        value = object2->correctedD0;
3170      }
3171  
3172 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3172 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3173 >
3174 >  value = applyFunction(function, value);
3175 >
3176 >  return value;
3177 > } // end muon-muon pair valueLookup
3178 >
3179 >
3180 > //!muon-photon pair valueLookup
3181 > double
3182 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3183 >
3184 >  double value = 0.0;
3185 >
3186 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3187 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3188 >  else if(variable == "photonEta") value = object2->eta;
3189 >  else if(variable == "muonEta") value = object1->eta;
3190 >  else if(variable == "photonPhi") value = object2->phi;
3191 >  else if(variable == "muonPhi") value = object1->phi;
3192 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3193 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3194 >  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3195 >  else if(variable == "invMass"){
3196 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3197 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3198 >    value = (fourVector1 + fourVector2).M();
3199 >  }
3200 >  else if(variable == "pt"){
3201 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3202 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3203 >    value = (fourVector1 + fourVector2).Pt();
3204 >  }
3205 >  else if(variable == "threeDAngle")
3206 >    {
3207 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3208 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3209 >      value = (threeVector1.Angle(threeVector2));
3210 >    }
3211 >  else if(variable == "alpha")
3212 >    {
3213 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3214 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3215 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3216 >      value = (pi-threeVector1.Angle(threeVector2));
3217 >    }
3218 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3219 >
3220 >  value = applyFunction(function, value);
3221 >
3222 >  return value;
3223 > }
3224 >
3225 > //!electron-photon pair valueLookup
3226 > double
3227 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3228 >
3229 >  double value = 0.0;
3230 >
3231 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3232 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3233 >  else if(variable == "photonEta") value = object2->eta;
3234 >  else if(variable == "electronEta") value = object1->eta;
3235 >  else if(variable == "photonPhi") value = object2->phi;
3236 >  else if(variable == "electronPhi") value = object1->phi;
3237 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3238 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3239 >  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3240 >  else if(variable == "invMass"){
3241 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3242 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3243 >    value = (fourVector1 + fourVector2).M();
3244 >  }
3245 >  else if(variable == "pt"){
3246 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3247 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3248 >    value = (fourVector1 + fourVector2).Pt();
3249 >  }
3250 >  else if(variable == "threeDAngle")
3251 >    {
3252 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3253 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3254 >      value = (threeVector1.Angle(threeVector2));
3255 >    }
3256 >  else if(variable == "alpha")
3257 >    {
3258 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3259 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3260 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3261 >      value = (pi-threeVector1.Angle(threeVector2));
3262 >    }
3263 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3264  
3265    value = applyFunction(function, value);
3266  
3267    return value;
3268   }
3269  
3270 + //!electron-electron pair valueLookup
3271   double
3272 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
3272 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3273  
3274    double value = 0.0;
3275  
3276    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3277 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3278    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3279    else if(variable == "invMass"){
3280      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2537 | Line 3316 | OSUAnalysis::valueLookup (const BNelectr
3316      value = object2->correctedD0;
3317    }
3318  
3319 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3319 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3320  
3321    value = applyFunction(function, value);
3322  
3323    return value;
3324   }
3325  
3326 + //!electron-muon pair valueLookup
3327   double
3328 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3328 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3329  
3330    double value = 0.0;
3331  
3332    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3333 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3334    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3335    else if(variable == "invMass"){
3336      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2596 | Line 3377 | OSUAnalysis::valueLookup (const BNelectr
3377    else if(variable == "muonDetIso"){
3378      value = (object2->trackIsoDR03) / object2->pt;
3379    }
3380 +  else if(variable == "electronRelPFrhoIso"){
3381 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3382 +  }
3383 +  else if(variable == "muonRelPFdBetaIso"){
3384 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3385 +  }
3386 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3387 +  value = applyFunction(function, value);
3388 +
3389 +  return value;
3390 + } // end electron-muon pair valueLookup
3391  
3392  
3393 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3393 > //!electron-jet pair valueLookup
3394 > double
3395 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3396 >
3397 >  double value = 0.0;
3398 >
3399 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3400 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3401 >  else if(variable == "jetEta") value = object2->eta;
3402 >  else if(variable == "jetPhi") value = object2->phi;
3403 >  else if(variable == "electronEta") value = object1->eta;
3404 >  else if(variable == "electronPhi") value = object1->phi;
3405 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3406 >  else if(variable == "invMass"){
3407 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3408 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3409 >    value = (fourVector1 + fourVector2).M();
3410 >  }
3411 >  else if(variable == "pt"){
3412 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3413 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3414 >    value = (fourVector1 + fourVector2).Pt();
3415 >  }
3416 >  else if(variable == "threeDAngle")
3417 >    {
3418 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3419 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3420 >      value = (threeVector1.Angle(threeVector2));
3421 >    }
3422 >  else if(variable == "chargeProduct"){
3423 >    value = object1->charge*object2->charge;
3424 >  }
3425 >
3426 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3427 >  value = applyFunction(function, value);
3428 >
3429 >  return value;
3430 > }
3431 >
3432 > //!photon-jet pair valueLookup
3433 > double
3434 > OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3435 >
3436 >  double value = 0.0;
3437 >
3438 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3439 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3440 >  else if(variable == "jetEta") value = object2->eta;
3441 >  else if(variable == "jetPhi") value = object2->phi;
3442 >  else if(variable == "photonEta") value = object1->eta;
3443 >  else if(variable == "photonPhi") value = object1->phi;
3444 >  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3445 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3446 >  else if(variable == "invMass"){
3447 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3448 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3449 >    value = (fourVector1 + fourVector2).M();
3450 >  }
3451 >  else if(variable == "pt"){
3452 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3453 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3454 >    value = (fourVector1 + fourVector2).Pt();
3455 >  }
3456 >  else if(variable == "threeDAngle")
3457 >    {
3458 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3459 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3460 >      value = (threeVector1.Angle(threeVector2));
3461 >    }
3462 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3463 >  value = applyFunction(function, value);
3464 >
3465 >  return value;
3466 > }
3467 >
3468 > // met-jet pair valueLookup
3469 > double
3470 > OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3471 >
3472 >  double value = 0.0;
3473 >
3474 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3475  
3476 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3477 +  value = applyFunction(function, value);
3478 +
3479 +  return value;
3480 +
3481 + }  
3482 +
3483 +
3484 +
3485 + //!muon-jet pair valueLookup
3486 + double
3487 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3488 +
3489 +  double value = 0.0;
3490 +
3491 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3492 +  else if(variable == "jetEta") value = object2->eta;
3493 +  else if(variable == "jetPhi") value = object2->phi;
3494 +  else if(variable == "muonEta") value = object1->eta;
3495 +  else if(variable == "muonPhi") value = object1->phi;
3496 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3497 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3498 +  else if(variable == "invMass"){
3499 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3500 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3501 +    value = (fourVector1 + fourVector2).M();
3502 +  }
3503 +  else if(variable == "pt"){
3504 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3505 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3506 +    value = (fourVector1 + fourVector2).Pt();
3507 +  }
3508 +  else if(variable == "threeDAngle")
3509 +    {
3510 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3511 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3512 +      value = (threeVector1.Angle(threeVector2));
3513 +    }
3514 +  else if(variable == "chargeProduct"){
3515 +    value = object1->charge*object2->charge;
3516 +  }
3517 +
3518 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3519    value = applyFunction(function, value);
3520  
3521    return value;
3522   }
3523 + //!jet-jet pair valueLookup
3524 + double
3525 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3526  
3527 +  double value = 0.0;
3528  
3529 < double  
3530 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function){  
3531 <  double electronMass = 0.000511;        
3532 <  double value = 0.0;    
3533 <  TLorentzVector fourVector1(0, 0, 0, 0);        
3534 <  TLorentzVector fourVector2(0, 0, 0, 0);        
3535 <  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));  
3536 <  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);    
3537 <  else if(variable == "invMass"){        
3538 <    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);    
3539 <    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );    
3540 <        
3541 <    value = (fourVector1 + fourVector2).M();    
3529 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3530 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3531 >  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3532 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3533 >  else if(variable == "invMass"){
3534 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3535 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3536 >    value = (fourVector1 + fourVector2).M();
3537 >  }
3538 >  else if(variable == "pt"){
3539 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3540 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3541 >    value = (fourVector1 + fourVector2).Pt();
3542    }
3543 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}  
3544 <  value = applyFunction(function, value);        
3545 <  return value;  
3543 >  else if(variable == "threeDAngle")
3544 >    {
3545 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3546 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3547 >      value = (threeVector1.Angle(threeVector2));
3548 >    }
3549 >  else if(variable == "chargeProduct"){
3550 >    value = object1->charge*object2->charge;
3551 >  }
3552 >
3553 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3554 >  value = applyFunction(function, value);
3555 >
3556 >  return value;
3557   }
3558  
3559 + //!electron-track pair valueLookup
3560 + double
3561 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3562 +  double electronMass = 0.000511;
3563 +  double value = 0.0;
3564 +  TLorentzVector fourVector1(0, 0, 0, 0);
3565 +  TLorentzVector fourVector2(0, 0, 0, 0);
3566 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3567 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3568 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3569 +  else if(variable == "invMass"){
3570 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3571 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3572 +
3573 +    value = (fourVector1 + fourVector2).M();
3574 +  }
3575 +  else if(variable == "chargeProduct"){
3576 +    value = object1->charge*object2->charge;
3577 +  }
3578 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3579 +  value = applyFunction(function, value);
3580 +  return value;
3581 +
3582 + }
3583  
3584  
3585 + //!muon-track pair valueLookup
3586   double
3587 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function){
3587 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3588    double pionMass = 0.140;
3589    double muonMass = 0.106;
3590    double value = 0.0;
3591    TLorentzVector fourVector1(0, 0, 0, 0);
3592    TLorentzVector fourVector2(0, 0, 0, 0);
3593    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3594 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3595    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3596    else if(variable == "invMass"){
3597      fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
# Line 2642 | Line 3599 | OSUAnalysis::valueLookup (const BNmuon*
3599  
3600      value = (fourVector1 + fourVector2).M();
3601    }
3602 +  else if(variable == "chargeProduct"){
3603 +    value = object1->charge*object2->charge;
3604 +  }
3605  
3606    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3607    value = applyFunction(function, value);
3608    return value;
3609   }
3610  
3611 <
3611 > //!tau-tau pair valueLookup
3612   double
3613 < OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function){
3613 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3614    double value = 0.0;
3615    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3616 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3617    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3618    else if(variable == "invMass"){
3619      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2660 | Line 3621 | OSUAnalysis::valueLookup (const BNtau* o
3621      value = (fourVector1 + fourVector2).M();
3622    }
3623  
3624 +  else if(variable == "chargeProduct"){
3625 +    value = object1->charge*object2->charge;
3626 +  }
3627 +
3628    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3629    value = applyFunction(function, value);
3630    return value;
3631   }
3632  
3633 <
3633 > //!muon-tau pair valueLookup
3634   double
3635 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function){
3635 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3636    double value = 0.0;
3637    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3638 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3639    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3640    else if(variable == "invMass"){
3641      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2677 | Line 3643 | OSUAnalysis::valueLookup (const BNmuon*
3643      value = (fourVector1 + fourVector2).M();
3644    }
3645  
3646 +  else if(variable == "chargeProduct"){
3647 +    value = object1->charge*object2->charge;
3648 +  }
3649 +
3650 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3651 +  value = applyFunction(function, value);
3652 +  return value;
3653 + }
3654 +
3655 + //!tau-track pair valueLookup
3656 + double
3657 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3658 +  double value = 0.0;
3659 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3660 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3661 +  else if(variable == "chargeProduct"){
3662 +    value = object1->charge*object2->charge;
3663 +  }
3664 +
3665    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3666    value = applyFunction(function, value);
3667    return value;
3668   }
3669  
3670  
3671 + //!track-event pair valueLookup
3672   double
3673 < OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function){
3673 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3674  
3675    double value = 0.0;
3676    double pMag = sqrt(object1->pt * object1->pt +
3677 <                     object1->pz * object1->pz);  
3677 >                     object1->pz * object1->pz);
3678  
3679    if      (variable == "numPV")                      value = object2->numPV;
3680    else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3681    else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3682 <  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);  
3683 <  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;  
3682 >  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3683 >  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3684  
3685 <  else { std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3685 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3686  
3687    value = applyFunction(function, value);
3688  
3689    return value;
3690  
3691 < }  
3691 > }
3692 >
3693 > //!electron-trigobj pair valueLookup
3694 > double
3695 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3696 >
3697 >  double value = 0.0;
3698 >
3699 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3700 >  else if (variable == "match"){
3701 >    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3702 >      stringValue = object2->filter;
3703 >    else
3704 >      stringValue = "none";
3705 >  }
3706 >
3707 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3708 >
3709 >  value = applyFunction(function, value);
3710 >
3711 >  return value;
3712 >
3713 > }
3714 >
3715 > //!muon-trigobj pair valueLookup
3716 > double
3717 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3718 >
3719 >  double value = 0.0;
3720 >
3721 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3722 >
3723 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3724 >
3725 >  value = applyFunction(function, value);
3726 >
3727 >  return value;
3728 >
3729 > }
3730 >
3731 > //!stop valueLookup
3732 > double
3733 > OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3734 >
3735 >
3736 >  double value = 0.0;
3737 >
3738 >  if(variable == "ctau") value = object->ctau;
3739 >
3740 >  else if (variable == "d0"){
3741 >    double vx = object->vx - chosenVertex ()->x,
3742 >      vy = object->vy - chosenVertex ()->y,
3743 >      px = object->px,
3744 >      py = object->py,
3745 >      pt = object->pt;
3746 >    value = (-vx * py + vy * px) / pt;
3747 >  }
3748 >
3749 >  else if (variable == "dz"){
3750 >    double vx = object->vx - chosenVertex ()->x,
3751 >      vy = object->vy - chosenVertex ()->y,
3752 >      vz = object->vz - chosenVertex ()->z,
3753 >      px = object->px,
3754 >      py = object->py,
3755 >      pz = object->pz,
3756 >      pt = object->pt;
3757 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3758 >  }
3759 >
3760 >  else if (variable == "minD0"){
3761 >    double minD0=999;
3762 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3763 >      double vx = object->vx - vertex->x,
3764 >        vy = object->vy - vertex->y,
3765 >        px = object->px,
3766 >        py = object->py,
3767 >        pt = object->pt;
3768 >      value = (-vx * py + vy * px) / pt;
3769 >      if(abs(value) < abs(minD0)) minD0 = value;
3770 >    }
3771 >    value = minD0;
3772 >  }
3773 >  else if (variable == "minDz"){
3774 >    double minDz=999;
3775 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3776 >      double vx = object->vx - vertex->x,
3777 >        vy = object->vy - vertex->y,
3778 >        vz = object->vz - vertex->z,
3779 >        px = object->px,
3780 >        py = object->py,
3781 >        pz = object->pz,
3782 >        pt = object->pt;
3783 >      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3784 >      if(abs(value) < abs(minDz)) minDz = value;
3785 >    }
3786 >    value = minDz;
3787 >  }
3788 >  else if(variable == "distToVertex"){
3789 >    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3790 >                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3791 >                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3792 >  }
3793 >  else if (variable == "minDistToVertex"){
3794 >    double minDistToVertex=999;
3795 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3796 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3797 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3798 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
3799 >
3800 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3801 >    }
3802 >    value = minDistToVertex;
3803 >  }
3804 >  else if (variable == "distToVertexDifference"){
3805 >    double minDistToVertex=999;
3806 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3807 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3808 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3809 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
3810 >
3811 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3812 >    }
3813 >    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3814 >                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3815 >                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3816 >
3817 >    value = distToChosenVertex - minDistToVertex;
3818 >  }
3819 >
3820 >  else if (variable == "closestVertexRank"){
3821 >    double minDistToVertex=999;
3822 >    int vertex_rank = 0;
3823 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3824 >      vertex_rank++;
3825 >      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3826 >                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
3827 >                      (object->vz-vertex->z)*(object->vz-vertex->z));
3828 >
3829 >      if(abs(dist) < abs(minDistToVertex)){
3830 >        value = vertex_rank;
3831 >        minDistToVertex = dist;
3832 >      }
3833 >    }
3834 >  }
3835 >
3836 >
3837 >
3838 >
3839 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3840 >
3841 >  value = applyFunction(function, value);
3842 >
3843 >  return value;
3844 >
3845 > } // end stop valueLookup
3846 >
3847 >
3848 >
3849 >
3850  
3851   // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3852   // Return true iff no other tracks are found in this cone.
# Line 2751 | Line 3895 | OSUAnalysis::getTrkPtTrue (const BNtrack
3895  
3896   double
3897   OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3898 <  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.  
3899 <  if (!useTrackCaloRhoCorr_) return -99;  
3900 <  // if (!rhokt6CaloJetsHandle_) {
3901 <  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;  
3902 <  //   return -99;  
3898 >  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3899 >  if (!useTrackCaloRhoCorr_) return -99;
3900 >  // if (!rhokt6CaloJetsHandle_) {
3901 >  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3902 >  //   return -99;
3903    // }
3904 <  double radDeltaRCone = 0.5;  
3905 <  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.  
3906 <  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;  
3907 <  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);  
3908 <  return caloTotRhoCorrCalo;  
3909 <
3904 >  double radDeltaRCone = 0.5;
3905 >  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3906 >  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3907 >  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3908 >  return caloTotRhoCorrCalo;
3909 >
3910   }
3911  
3912  
# Line 2800 | Line 3944 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3944    double deltaRLowest = 999;
3945    int value = 0;
3946    if (DeadEcalVec.size() == 0) WriteDeadEcal();
3947 <  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3947 >  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3948      double eta = ecal->etaEcal;
3949      double phi = ecal->phiEcal;
3950 <    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
3950 >    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
3951      if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3952    }
3953    if (deltaRLowest<0.05) {value = 1;}
# Line 2811 | Line 3955 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3955    return value;
3956   }
3957  
3958 < // Returns the smallest DeltaR between the object and any generated true particle in the event.  
3958 > // Returns the smallest DeltaR between the object and any generated true particle in the event.
3959   template <class InputObject>
3960   double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3961    double genDeltaRLowest = 999.;
# Line 2831 | Line 3975 | OSUAnalysis::applyFunction(string functi
3975    else if(function == "log") value = log10(value);
3976  
3977    else if(function == "") value = value;
3978 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
3978 >  else{cout << "WARNING: invalid function '" << function << "'\n";}
3979  
3980    return value;
3981  
# Line 2841 | Line 3985 | OSUAnalysis::applyFunction(string functi
3985   template <class InputCollection>
3986   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
3987  
3988 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
3989 +    string obj1, obj2;
3990 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
3991 +    if (inputType==obj1 ||
3992 +        inputType==obj2) {
3993 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
3994 +      // and the inputType is a member of the pair.
3995 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
3996 +      // For example, if currentCut.inputCollection==electron-muon pairs,
3997 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
3998 +      return;
3999 +    }
4000 +  }
4001  
4002    for (uint object = 0; object != inputCollection->size(); object++){
4003  
4004 <
4005 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
2849 <
4004 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4005 >    bool plotDecision = true;
4006  
4007      if(currentCut.inputCollection == inputType){
4008  
4009        vector<bool> subcutDecisions;
4010        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4011 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4012 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4011 >        string stringValue = "";
4012 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4013 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4014 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4015 >
4016        }
4017 <      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4017 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4018        else{
4019          bool tempDecision = true;
4020          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
# Line 2864 | Line 4023 | void OSUAnalysis::setObjectFlags(cut &cu
4023            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4024              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4025          }
4026 <        decision = tempDecision;
4026 >        cutDecision = tempDecision;
4027        }
4028 +      //invert the cut for plotting if this cut is a veto
4029 +      if(currentCut.isVeto) plotDecision = !cutDecision;
4030 +      else plotDecision = cutDecision;
4031      }
2870    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4032  
4033 +    //if(cutDecision != plotDecision && currentCut.variables.at(0) == "pt") cout << "---------------\n" << cutDecision << " " << plotDecision << endl;
4034 +    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4035  
4036 <    //set flags for objects that pass each cut AND all the previous cuts
4037 <    bool previousCumulativeFlag = true;
4036 >    //set flags for objects that pass this cut AND all the previous cuts
4037 >    bool previousCumulativeCutFlag = true;
4038 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4039 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4040 >      else{ previousCumulativeCutFlag = false; break;}
4041 >    }
4042 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4043 >    bool previousCumulativePlotFlag = true;
4044      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4045 <      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4046 <      else{ previousCumulativeFlag = false; break;}
4045 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4046 >      else{ previousCumulativePlotFlag = false; break;}
4047      }
4048 <    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4048 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4049  
4050 +    //if(inputType == "muons") cout << previousCumulativeCutFlag << " " << previousCumulativePlotFlag << " " << currentCut.variables.at(0) << "\n---------------\n\n";
4051 +    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4052  
4053    }
4054  
# Line 2886 | Line 4057 | void OSUAnalysis::setObjectFlags(cut &cu
4057  
4058   template <class InputCollection1, class InputCollection2>
4059   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
4060 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
4060 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, string inputType){
4061  
4062  
4063    bool sameObjects = false;
4064    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4065  
4066 +  // Get the strings for the two objects that make up the pair.
4067 +  string obj1Type, obj2Type;
4068 +  getTwoObjs(inputType, obj1Type, obj2Type);
4069 +  bool isTwoTypesOfObject = true;
4070 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
4071 +
4072 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
4073 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4074 +  if (currentCut.inputCollection == inputType) {
4075 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4076 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4077 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4078 +    }
4079 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4080 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4081 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4082 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4083 +      }
4084 +    }
4085 +  }
4086  
4087    int counter = 0;
4088 +
4089    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4090      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4091  
4092        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4093  
4094  
4095 <      bool decision = true;//object passes if this cut doesn't cut on that type of object
4095 >      bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4096 >      bool plotDecision = true;
4097  
4098        if(currentCut.inputCollection == inputType){
4099  
4100          vector<bool> subcutDecisions;
4101          for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4102 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4103 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4102 >          string stringValue = "";
4103 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4104 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4105 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4106          }
4107  
4108 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4108 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4109          else{
4110            bool tempDecision = subcutDecisions.at(0);
4111            for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
# Line 2919 | Line 4114 | void OSUAnalysis::setObjectFlags(cut &cu
4114              else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4115                tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4116            }
4117 <          decision = tempDecision;
4117 >          cutDecision = tempDecision;
4118          }
4119 +        //invert the cut for plotting if this cut is a veto
4120 +        if(currentCut.isVeto) plotDecision = !cutDecision;
4121 +        else plotDecision = cutDecision;
4122 +      }
4123 +      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4124 +      if (cutDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4125 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4126 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4127 +      }
4128 +      if (plotDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4129 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4130 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4131        }
2925      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4132  
4133 <      //set flags for objects that pass each cut AND all the previous cuts
4134 <      bool previousCumulativeFlag = true;
4133 >      //set flags for objects that pass this cut AND all the previous cuts
4134 >      bool previousCumulativeCutFlag = true;
4135        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4136 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
4137 <        else{ previousCumulativeFlag = false; break;}
4136 >        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4137 >        else{ previousCumulativeCutFlag = false; break;}
4138        }
4139 +      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4140 +
4141 +      bool previousCumulativePlotFlag = true;
4142 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4143 +        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4144 +        else{ previousCumulativePlotFlag = false; break;}
4145 +      }
4146 +      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4147 +      
4148        //apply flags for the components of the composite object as well
4149 <      bool currentCumulativeFlag = true;
4150 <      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
4151 <      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
4152 <      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
4153 <      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
4154 <      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
4149 >      bool currentCumulativeCutFlag = true;
4150 >      bool currentCumulativePlotFlag = true;
4151 >
4152 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4153 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4154 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4155 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4156 >
4157 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4158 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4159 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4160 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4161 >
4162 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));
4163 >
4164 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4165 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4166 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4167 >      }
4168 >
4169 >      if (currentCumulativePlotFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4170 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4171 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4172 >      }
4173  
4174        counter++;
2942    }
4175  
4176 +    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4177 +  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4178 +
4179 + }
4180 +
4181 +
4182 + bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4183 +  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4184 +  // all cuts up to currentCutIndex
4185 +  bool previousCumulativeFlag = true;
4186 +  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4187 +    bool tempFlag = false;
4188 +    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4189 +    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4190 +
4191 +    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4192 +    else {
4193 +      previousCumulativeFlag = false; break;
4194 +    }
4195    }
4196 +  return previousCumulativeFlag;
4197 + }
4198  
4199  
4200 +
4201 +
4202 + template <class InputCollection>
4203 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4204 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4205 +
4206 +  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;
4207 +  for (uint object = 0; object != inputCollection->size(); object++) {
4208 +
4209 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4210 +
4211 +    string inputVariable = parameters.inputVariable;
4212 +    string function = "";
4213 +    string stringValue = "";
4214 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4215 +    BNTreeBranchVals_.at(parameters.name).push_back(value);
4216 +
4217 +  }
4218   }
4219  
4220  
4221   template <class InputCollection>
4222 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4222 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4223 >
4224  
4225    for (uint object = 0; object != inputCollection->size(); object++){
4226  
4227 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4227 >    //cout << "flags.at(object).second: " << flags.at(object).second << endl;
4228 >
4229 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4230  
4231      string currentString = parameters.inputVariables.at(0);
4232      string inputVariable = "";
4233      string function = "";
4234 <    if(currentString.find("(")==std::string::npos){
4234 >    if(currentString.find("(")==string::npos){
4235        inputVariable = currentString;// variable to cut on
4236      }
4237      else{
# Line 2966 | Line 4240 | void OSUAnalysis::fill1DHistogram(TH1* h
4240        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4241      }
4242  
4243 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
4243 >    string stringValue = "";
4244 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4245      histo->Fill(value,scaleFactor);
4246  
4247      if (printEventInfo_) {
4248 <      // Write information about event to screen, for testing purposes.  
4249 <      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;  
4248 >      // Write information about event to screen, for testing purposes.
4249 >      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
4250      }
4251 <    
4251 >
4252    }
4253   }
4254  
4255   template <class InputCollection1, class InputCollection2>
4256 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4256 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4257  
4258    bool sameObjects = false;
4259    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4260  
4261 <  int pairCounter = 0;
4261 >  int pairCounter = -1;
4262    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4263      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4264  
4265        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4266  
4267 +      pairCounter++;
4268        //only take objects which have passed all cuts and pairs which have passed all cuts
4269 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4270 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4271 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4269 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4270 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4271 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4272  
4273        string currentString = parameters.inputVariables.at(0);
4274        string inputVariable = "";
4275        string function = "";
4276 <      if(currentString.find("(")==std::string::npos){
4276 >      if(currentString.find("(")==string::npos){
4277          inputVariable = currentString;// variable to cut on
4278        }
4279        else{
# Line 3006 | Line 4282 | void OSUAnalysis::fill1DHistogram(TH1* h
4282          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4283        }
4284  
4285 <      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4285 >      string stringValue = "";
4286 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4287        histo->Fill(value,scaleFactor);
4288  
3012      pairCounter++;
4289      }
4290    }
4291  
# Line 3017 | Line 4293 | void OSUAnalysis::fill1DHistogram(TH1* h
4293  
4294  
4295   template <class InputCollection>
4296 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4296 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4297  
4298    for (uint object = 0; object != inputCollection->size(); object++){
4299  
4300 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4300 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4301  
4302 +    string stringValue = "";
4303      string currentString = parameters.inputVariables.at(0);
4304      string inputVariable = "";
4305      string function = "";
4306 <    if(currentString.find("(")==std::string::npos){
4306 >    if(currentString.find("(")==string::npos){
4307        inputVariable = currentString;// variable to cut on
4308      }
4309      else{
# Line 3034 | Line 4311 | void OSUAnalysis::fill2DHistogram(TH2* h
4311        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4312        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4313      }
4314 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
4314 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4315  
4316      currentString = parameters.inputVariables.at(1);
4317      inputVariable = "";
4318      function = "";
4319 <    if(currentString.find("(")==std::string::npos){
4319 >    if(currentString.find("(")==string::npos){
4320        inputVariable = currentString;// variable to cut on
4321      }
4322      else{
# Line 3048 | Line 4325 | void OSUAnalysis::fill2DHistogram(TH2* h
4325        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4326      }
4327  
4328 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
4328 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4329  
4330      histo->Fill(valueX,valueY,scaleFactor);
4331  
# Line 3057 | Line 4334 | void OSUAnalysis::fill2DHistogram(TH2* h
4334   }
4335  
4336   template <class InputCollection1, class InputCollection2>
4337 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4337 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4338  
4339    bool sameObjects = false;
4340    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4341  
4342 <  int pairCounter = 0;
4342 >  int pairCounter = -1;
4343    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4344      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4345  
4346        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4347  
4348 +      pairCounter++;
4349 +
4350        //only take objects which have passed all cuts and pairs which have passed all cuts
4351 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4352 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4353 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4351 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4352 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4353 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4354  
4355 +      string stringValue = "";
4356        string currentString = parameters.inputVariables.at(0);
4357        string inputVariable = "";
4358        string function = "";
4359 <      if(currentString.find("(")==std::string::npos){
4359 >      if(currentString.find("(")==string::npos){
4360          inputVariable = currentString;// variable to cut on
4361        }
4362        else{
# Line 3084 | Line 4364 | void OSUAnalysis::fill2DHistogram(TH2* h
4364          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4365          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4366        }
4367 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4367 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4368  
4369        currentString = parameters.inputVariables.at(1);
4370        inputVariable = "";
4371        function = "";
4372 <      if(currentString.find("(")==std::string::npos){
4372 >      if(currentString.find("(")==string::npos){
4373          inputVariable = currentString;// variable to cut on
4374        }
4375        else{
# Line 3097 | Line 4377 | void OSUAnalysis::fill2DHistogram(TH2* h
4377          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4378          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4379        }
4380 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4380 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4381  
4382  
4383        histo->Fill(valueX,valueY,scaleFactor);
4384  
3105      pairCounter++;
3106
4385      }
4386    }
4387  
# Line 3120 | Line 4398 | int OSUAnalysis::getGenMatchedParticleIn
4398  
4399      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4400      if(currentDeltaR > 0.05) continue;
4401 <    //     cout << std::setprecision(3) << std::setw(20)
4401 >    //     cout << setprecision(3) << setw(20)
4402      //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4403 <    //          << std::setw(20)
4403 >    //          << setw(20)
4404      //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4405 <    //          << std::setw(20)
4405 >    //          << setw(20)
4406      //          << "\tdeltaR = " << currentDeltaR
4407 <    //          << std::setprecision(1)
4408 <    //          << std::setw(20)
4407 >    //          << setprecision(1)
4408 >    //          << setw(20)
4409      //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4410 <    //          << std::setw(20)
4410 >    //          << setw(20)
4411      //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4412 <    //          << std::setw(20)
4412 >    //          << setw(20)
4413      //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4414      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4415        bestMatchIndex = mcparticle - mcparticles->begin();
# Line 3194 | Line 4472 | int OSUAnalysis::findTauMotherIndex(cons
4472   // 20        strange baryon
4473   // 21        charm baryon
4474   // 22        bottom baryon
4475 < // 23        other
4475 > // 23        QCD string
4476 > // 24        other
4477  
4478   int OSUAnalysis::getPdgIdBinValue(int pdgId){
4479  
# Line 3218 | Line 4497 | int OSUAnalysis::getPdgIdBinValue(int pd
4497    else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4498    else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4499    else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4500 +  else if(absPdgId == 92  ) binValue = 23;
4501  
4502 <  else binValue = 23;
4502 >  else binValue = 24;
4503  
4504    return binValue;
4505  
# Line 3229 | Line 4509 | const BNprimaryvertex *
4509   OSUAnalysis::chosenVertex ()
4510   {
4511    const BNprimaryvertex *chosenVertex = 0;
4512 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
4513 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
4514 <      cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
4512 >  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4513 >    flagPair vertexFlags;
4514 >    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4515 >      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4516 >        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4517 >        break;
4518 >      }
4519 >    }
4520      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4521 <      if(!vertexFlags.at(vertexIndex)) continue;
4521 >      if(!vertexFlags.at(vertexIndex).first) continue;
4522        chosenVertex = & primaryvertexs->at(vertexIndex);
4523        break;
4524      }
4525    }
4526 <  else {
4527 <    chosenVertex = &primaryvertexs->at(0);
3243 <  }
4526 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4527 >    chosenVertex = & primaryvertexs->at (0);
4528  
4529    return chosenVertex;
4530   }
# Line 3249 | Line 4533 | const BNmet *
4533   OSUAnalysis::chosenMET ()
4534   {
4535    const BNmet *chosenMET = 0;
4536 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
4537 <    vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
4538 <      cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
4536 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4537 >    flagPair metFlags;
4538 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4539 >      if (cumulativeFlags.at("mets").at(i).size()){
4540 >        metFlags = cumulativeFlags.at("mets").at(i);
4541 >        break;
4542 >      }
4543 >    }
4544      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4545 <      if(!metFlags.at(metIndex)) continue;
4545 >      if(!metFlags.at(metIndex).first) continue;
4546        chosenMET = & mets->at(metIndex);
4547        break;
4548      }
4549    }
4550 <  else {
4551 <    chosenMET = &mets->at(0);
3263 <  }
4550 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4551 >    chosenMET = & mets->at (0);
4552  
4553    return chosenMET;
4554   }
# Line 3269 | Line 4557 | const BNelectron *
4557   OSUAnalysis::chosenElectron ()
4558   {
4559    const BNelectron *chosenElectron = 0;
4560 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
4561 <    vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
4562 <      cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
4560 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4561 >    flagPair electronFlags;
4562 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4563 >      if (cumulativeFlags.at("electrons").at(i).size()){
4564 >        electronFlags = cumulativeFlags.at("electrons").at(i);
4565 >        break;
4566 >      }
4567 >    }
4568      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4569 <      if(!electronFlags.at(electronIndex)) continue;
4569 >      if(!electronFlags.at(electronIndex).first) continue;
4570        chosenElectron = & electrons->at(electronIndex);
4571        break;
4572      }
4573    }
4574 <  else {
4575 <    chosenElectron = &electrons->at(0);
3283 <  }
4574 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4575 >    chosenElectron = & electrons->at (0);
4576  
4577    return chosenElectron;
4578   }
4579  
4580 +
4581   const BNmuon *
4582   OSUAnalysis::chosenMuon ()
4583   {
4584    const BNmuon *chosenMuon = 0;
4585 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
4586 <    vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
4587 <      cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
4585 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4586 >    flagPair muonFlags;
4587 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4588 >      if (cumulativeFlags.at("muons").at(i).size()){
4589 >        muonFlags = cumulativeFlags.at("muons").at(i);
4590 >        break;
4591 >      }
4592 >    }
4593      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4594 <      if(!muonFlags.at(muonIndex)) continue;
4594 >      if(!muonFlags.at(muonIndex).first) continue;
4595        chosenMuon = & muons->at(muonIndex);
4596        break;
4597      }
4598    }
4599 <  else {
4600 <    chosenMuon = &muons->at(0);
3303 <  }
4599 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4600 >    chosenMuon = & muons->at (0);
4601  
4602    return chosenMuon;
4603   }
4604  
3308
4605   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines