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.42 by wulsin, Wed Mar 27 22:38:08 2013 UTC vs.
Revision 1.77 by wulsin, Fri May 31 11:24:31 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 +  treeBranchSets_   (cfg.getParameter<vector<edm::ParameterSet> >("treeBranchSets")),
32    plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
33    doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
34 <  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
35 <  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr"))
36 <
34 >  fillBNTree_ (cfg.getParameter<bool> ("fillBNTree")),
35 >  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
36 >  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
37 >  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
38 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
39 >  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
40   {
41  
42    TH1::SetDefaultSumw2 ();
# Line 38 | Line 44 | OSUAnalysis::OSUAnalysis (const edm::Par
44    //create pile-up reweighting object, if necessary
45    if(datasetType_ != "data") {
46      if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
47 <    //    muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
48 <    //    electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
47 >    if (applyLeptonSF_){
48 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
49 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
50 >    }
51    }
52 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
53 +    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
54  
55  
56    // Construct Cutflow Objects. These store the results of cut decisions and
57    // handle filling cut flow histograms.
58    masterCutFlow_ = new CutFlow (fs_);
49  std::vector<TFileDirectory> directories;
59  
60    //always get vertex collection so we can assign the primary vertex in the event
61    objectsToGet.push_back("primaryvertexs");
53
54  //always make the plot of number of primary verticex (to check pile-up reweighting)
62    objectsToPlot.push_back("primaryvertexs");
63 +  objectsToCut.push_back("primaryvertexs");
64 +
65  
66    //always get the MC particles to do GEN-matching
67    objectsToGet.push_back("mcparticles");
# Line 60 | Line 69 | OSUAnalysis::OSUAnalysis (const edm::Par
69    //always get the event collection to do pile-up reweighting
70    objectsToGet.push_back("events");
71  
72 +
73 +  // Parse the tree variable definitions.    
74 +  if (fillBNTree_) {
75 +
76 +    for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++) {
77 +      string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
78 +      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; }  
79 +      objectsToGet.push_back(tempInputCollection);
80 +      objectsToCut.push_back(tempInputCollection);
81 +
82 +      vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
83 +
84 +      for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
85 +        BranchSpecs br;
86 +        br.inputCollection = tempInputCollection;
87 +        br.inputVariable = branchList.at(iBranch);  
88 +        TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);  
89 +        br.name = string(newName.Data());  
90 +        treeBranches_.push_back(br);
91 +      }  
92 +
93 +    } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++) {
94 +  } // end if (fillBNTree_) {
95 +
96 +
97    //parse the histogram definitions
98    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
99  
100      string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
101      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
102 +    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
103 +    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
104      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
105 <    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
106 <      objectsToGet.push_back(tempInputCollection);
105 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
106 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
107 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
108 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
109 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
110 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
111 >        int spaceIndex = tempInputCollection.find(" ");
112 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
113 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
114 >      }
115 >      else{
116 >        objectsToGet.push_back(tempInputCollection);
117 >      }
118        objectsToPlot.push_back(tempInputCollection);
119        objectsToCut.push_back(tempInputCollection);
120 <    }
121 <    else{//pair of objects, need to add them both to the things to objectsToGet
122 <      int dashIndex = tempInputCollection.find("-");
123 <      int spaceIndex = tempInputCollection.find(" ");
124 <      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");
120 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
121 >      string obj1;
122 >      string obj2;
123 >      getTwoObjs(tempInputCollection, obj1, obj2);
124 >      string obj2ToGet = getObjToGet(obj2);
125        objectsToCut.push_back(tempInputCollection);
126 <      objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
127 <      objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
126 >      objectsToCut.push_back(obj1);
127 >      objectsToCut.push_back(obj2);
128 >      objectsToPlot.push_back(tempInputCollection);
129 >      objectsToPlot.push_back(obj1);
130 >      objectsToPlot.push_back(obj2);
131 >      objectsToGet.push_back(tempInputCollection);
132 >      objectsToGet.push_back(obj1);
133 >      objectsToGet.push_back(obj2ToGet);
134 >    } // end else
135 >
136  
88      }
137  
138      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
139  
140      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
141  
142 +      vector<double> defaultValue;
143 +      defaultValue.push_back (-1.0);
144 +
145        histogram tempHistogram;
146        tempHistogram.inputCollection = tempInputCollection;
147        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
148        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
149 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
149 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
150 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
151 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
152        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
153  
154        histograms.push_back(tempHistogram);
155  
156      }
157 <  }
157 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
158 >
159    //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
160    sort( objectsToPlot.begin(), objectsToPlot.end() );
161    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
# Line 112 | Line 166 | OSUAnalysis::OSUAnalysis (const edm::Par
166    for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
167  
168      string currentObject = objectsToPlot.at(currentObjectIndex);
169 <    if(currentObject != "muons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
169 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
170  
171      histogram tempIdHisto;
172      histogram tempMomIdHisto;
173      histogram tempGmaIdHisto;
174      histogram tempIdVsMomIdHisto;
175 +    histogram tempIdVsGmaIdHisto;
176  
177      tempIdHisto.inputCollection = currentObject;
178      tempMomIdHisto.inputCollection = currentObject;
179      tempGmaIdHisto.inputCollection = currentObject;
180      tempIdVsMomIdHisto.inputCollection = currentObject;
181 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
182 +
183 +    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
184 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
185  
186      currentObject = currentObject.substr(0, currentObject.size()-1);
187      tempIdHisto.name = currentObject+"GenMatchId";
188      tempMomIdHisto.name = currentObject+"GenMatchMotherId";
189      tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
190      tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
191 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
192  
193      currentObject.at(0) = toupper(currentObject.at(0));
194      tempIdHisto.title = currentObject+" Gen-matched Particle";
195      tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
196      tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
197      tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
198 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
199 +
200  
201 <    int maxNum = 24;
201 >    int maxNum = 25;
202      vector<double> binVector;
203      binVector.push_back(maxNum);
204      binVector.push_back(0);
# Line 154 | Line 216 | OSUAnalysis::OSUAnalysis (const edm::Par
216      tempIdVsMomIdHisto.bins = binVector;
217      tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
218      tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
219 +    tempIdVsGmaIdHisto.bins = binVector;
220 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
221 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
222  
223      histograms.push_back(tempIdHisto);
224      histograms.push_back(tempMomIdHisto);
225      histograms.push_back(tempGmaIdHisto);
226      histograms.push_back(tempIdVsMomIdHisto);
227 +    histograms.push_back(tempIdVsGmaIdHisto);
228    }
229  
230  
# Line 174 | Line 240 | OSUAnalysis::OSUAnalysis (const edm::Par
240      //set triggers for this channel
241      vector<string> triggerNames;
242      triggerNames.clear();
243 +    vector<string> triggerToVetoNames;
244 +    triggerToVetoNames.clear();
245 +
246      tempChannel.triggers.clear();
247 +    tempChannel.triggersToVeto.clear();
248      if(channels_.at(currentChannel).exists("triggers")){
249        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
250        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
251          tempChannel.triggers.push_back(triggerNames.at(trigger));
252        objectsToGet.push_back("triggers");
253      }
254 <
254 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
255 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
256 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
257 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
258 >      objectsToGet.push_back("triggers");
259 >    }
260  
261  
262  
263      //create cutFlow for this channel
264      cutFlows_.push_back (new CutFlow (fs_, channelName));
265 <
266 <    //book a directory in the output file with the name of the channel
192 <    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 <
308 <      currentObject.at(0) = toupper(currentObject.at(0));
309 <      string histoName = "num" + currentObject;
310 <
311 <      if(histoName == "numPrimaryvertexs"){
312 <        string newHistoName = histoName + "BeforePileupCorrection";
313 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
314 <        newHistoName = histoName + "AfterPileupCorrection";
315 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
316 <      }
317 <      else
318 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
319 <    }
320 <
321 <
322 <
323 <
265 >    vector<TFileDirectory> directories; //vector of directories in the output file.
266 >    vector<string> subSubDirNames;//subdirectories in each channel.
267      //get list of cuts for this channel
268      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
269  
270 +
271      //loop over and parse all cuts
272      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
273        cut tempCut;
274        //store input collection for cut
275        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
276 +      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
277 +      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
278 +      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
279 +      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
280 +      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
281 +      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
282 +      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
283 +      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
284        tempCut.inputCollection = tempInputCollection;
285 <      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
286 <        objectsToGet.push_back(tempInputCollection);
285 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
286 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
287 >          int spaceIndex = tempInputCollection.find(" ");
288 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
289 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
290 >        }
291 >        else{
292 >          objectsToGet.push_back(tempInputCollection);
293 >        }
294          objectsToCut.push_back(tempInputCollection);
295        }
296 <      else{//pair of objects, need to add them both to the things to objectsToGet
297 <        int dashIndex = tempInputCollection.find("-");
298 <        int spaceIndex = tempInputCollection.find(" ");
299 <        int secondWordLength = spaceIndex - dashIndex;
300 <        objectsToGet.push_back(tempInputCollection);
342 <        objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
343 <        objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
296 >      else{//pair of objects, need to add them both to objectsToGet
297 >        string obj1;
298 >        string obj2;
299 >        getTwoObjs(tempInputCollection, obj1, obj2);
300 >        string obj2ToGet = getObjToGet(obj2);
301          objectsToCut.push_back(tempInputCollection);
302 <        objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
303 <        objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
302 >        objectsToCut.push_back(obj1);
303 >        objectsToCut.push_back(obj2);
304 >        objectsToGet.push_back(tempInputCollection);
305 >        objectsToGet.push_back(obj1);
306 >        objectsToGet.push_back(obj2ToGet);
307  
308        }
309  
# Line 351 | Line 311 | OSUAnalysis::OSUAnalysis (const edm::Par
311  
312        //split cut string into parts and store them
313        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
314 <      std::vector<string> cutStringVector = splitString(cutString);
314 >      vector<string> cutStringVector = splitString(cutString);
315        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
316 <        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
316 >        cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
317          exit(0);
318        }
319        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
320        for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
321          int indexOffset = 4 * subcutIndex;
322          string currentVariableString = cutStringVector.at(indexOffset);
323 <        if(currentVariableString.find("(")==std::string::npos){
323 >        if(currentVariableString.find("(")==string::npos){
324            tempCut.functions.push_back("");//no function was specified
325            tempCut.variables.push_back(currentVariableString);// variable to cut on
326          }
# Line 371 | Line 331 | OSUAnalysis::OSUAnalysis (const edm::Par
331          }
332          tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
333          tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
334 +        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
335          if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
336        }
337  
338        //get number of objects required to pass cut for event to pass
339        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
340 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
340 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
341        if(numberRequiredVector.size()!=2){
342 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
342 >        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
343          exit(0);
344        }
345  
# Line 386 | Line 347 | OSUAnalysis::OSUAnalysis (const edm::Par
347        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
348        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
349  
350 <
350 >      //Set up vectors to store the directories and subDIrectories for each channel.
351 >      string subSubDirName;
352        string tempCutName;
353        if(cuts_.at(currentCut).exists("alias")){
354          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
355 +        subSubDirName = "After " + cuts_.at(currentCut).getParameter<string> ("alias") + " Cut Applied";
356        }
357        else{
358          //construct string for cutflow table
# Line 397 | Line 360 | OSUAnalysis::OSUAnalysis (const edm::Par
360          string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
361          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
362          tempCutName = cutName;
363 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
364        }
401      tempCut.name = tempCutName;
365  
366 +      subSubDirNames.push_back(subSubDirName);
367 +      tempCut.name = tempCutName;
368  
369        tempChannel.cuts.push_back(tempCut);
370  
371  
407
372      }//end loop over cuts
373  
374 +    vector<map<string, TH1D*>> oneDHistsTmp;
375 +    vector<map<string, TH2D*>> twoDHistsTmp;
376 +    //book a directory in the output file with the name of the channel
377 +    TFileDirectory subDir = fs_->mkdir( channelName );
378 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
379 +    if(GetPlotsAfterEachCut_){
380 +      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
381 +        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
382 +        directories.push_back(subSubDir);
383 +        map<string, TH1D*> oneDhistoMap;
384 +        oneDHistsTmp.push_back(oneDhistoMap);
385 +        map<string, TH2D*> twoDhistoMap;
386 +        twoDHistsTmp.push_back(twoDhistoMap);
387 +      }
388 +      oneDHists_.push_back(oneDHistsTmp);
389 +      twoDHists_.push_back(twoDHistsTmp);
390 +    }
391 +    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
392 +    else{
393 +      map<string, TH1D*> oneDhistoMap;
394 +      oneDHistsTmp.push_back(oneDhistoMap);
395 +      map<string, TH2D*> twoDhistoMap;
396 +      twoDHistsTmp.push_back(twoDhistoMap);
397 +      oneDHists_.push_back(oneDHistsTmp);
398 +      twoDHists_.push_back(twoDHistsTmp);
399 +      directories.push_back(subDir);
400 +
401 +    }
402 +
403 +
404 +    //book all histograms included in the configuration
405 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
406 +
407 +      if (fillBNTree_) {
408 +        TTree* newTree = directories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));  
409 +        BNTrees_.push_back(newTree);    
410 +        for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
411 +          BranchSpecs currentVar = treeBranches_.at(iBranch);
412 +          vector<float> newVec;  
413 +          BNTreeBranchVals_[currentVar.name] = newVec;  
414 +          BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
415 +        } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
416 +      }
417 +
418 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
419 +
420 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
421 +        int numBinsElements = currentHistogram.bins.size();
422 +        int numInputVariables = currentHistogram.inputVariables.size();
423 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
424 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
425 +        
426 +        if(numBinsElements == 1){
427 +          if(numBinEdgesX > 1){
428 +            if(numBinEdgesY > 1)
429 +              numBinsElements = 6;
430 +            else
431 +              numBinsElements = 3;
432 +          }
433 +        }
434 +        if(numBinsElements != 3 && numBinsElements !=6){
435 +          cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
436 +          exit(0);
437 +        }
438 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
439 +          cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
440 +          exit(0);
441 +        }
442 +        else if(numBinsElements == 3){
443 +          if (currentHistogram.bins.size () == 3)
444 +            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));
445 +          else
446 +            {
447 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
448 +            }
449 +        }
450 +        else if(numBinsElements == 6){
451 +          if (currentHistogram.bins.size () == 6)
452 +            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));
453 +          else
454 +            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 ());
455 +        }
456 +
457 +
458 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
459 +
460 +        // bin      particle type
461 +        // ---      -------------
462 +        //  0        unmatched
463 +        //  1        u
464 +        //  2        d
465 +        //  3        s
466 +        //  4        c
467 +        //  5        b
468 +        //  6        t
469 +        //  7        e
470 +        //  8        mu
471 +        //  9        tau
472 +        // 10        nu
473 +        // 11        g
474 +        // 12        gamma
475 +        // 13        Z
476 +        // 14        W
477 +        // 15        light meson
478 +        // 16        K meson
479 +        // 17        D meson
480 +        // 18        B meson
481 +        // 19        light baryon
482 +        // 20        strange baryon
483 +        // 21        charm baryon
484 +        // 22        bottom baryon
485 +        // 23        QCD string
486 +        // 24        other
487 +
488 +        vector<TString> labelArray;
489 +        labelArray.push_back("unmatched");
490 +        labelArray.push_back("u");
491 +        labelArray.push_back("d");
492 +        labelArray.push_back("s");
493 +        labelArray.push_back("c");
494 +        labelArray.push_back("b");
495 +        labelArray.push_back("t");
496 +        labelArray.push_back("e");
497 +        labelArray.push_back("#mu");
498 +        labelArray.push_back("#tau");
499 +        labelArray.push_back("#nu");
500 +        labelArray.push_back("g");
501 +        labelArray.push_back("#gamma");
502 +        labelArray.push_back("Z");
503 +        labelArray.push_back("W");
504 +        labelArray.push_back("light meson");
505 +        labelArray.push_back("K meson");
506 +        labelArray.push_back("D meson");
507 +        labelArray.push_back("B meson");
508 +        labelArray.push_back("light baryon");
509 +        labelArray.push_back("strange baryon");
510 +        labelArray.push_back("charm baryon");
511 +        labelArray.push_back("bottom baryon");
512 +        labelArray.push_back("QCD string");
513 +        labelArray.push_back("other");
514 +
515 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
516 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
517 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
518 +          }
519 +          else {
520 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
521 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
522 +          }
523 +        }
524 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
525 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
526 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
527 +        }
528 +
529 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
530 +
531 +
532 +      // Book a histogram for the number of each object type to be plotted.
533 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
534 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
535 +        string currentObject = objectsToPlot.at(currentObjectIndex);
536 +        int maxNum = 10;
537 +        if(currentObject == "mcparticles") maxNum = 50;
538 +        else if(currentObject == "primaryvertexs") maxNum = 50;
539 +
540 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
541 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
542 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
543 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
544 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
545 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
546 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
547 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
548 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
549 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
550 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
551 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
552 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
553 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
554 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
555 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
556 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
557 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
558 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
559 +
560 +        currentObject.at(0) = toupper(currentObject.at(0));
561 +        string histoName = "num" + currentObject;
562 +
563 +        if(histoName == "numPrimaryvertexs"){
564 +          string newHistoName = histoName + "BeforePileupCorrection";
565 +          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);
566 +          newHistoName = histoName + "AfterPileupCorrection";
567 +          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);
568 +        }
569 +        else
570 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
571 +      }
572 +    }//end of loop over directories
573      channels.push_back(tempChannel);
574      tempChannel.cuts.clear();
412
575    }//end loop over channels
576  
577  
# Line 438 | Line 600 | OSUAnalysis::analyze (const edm::Event &
600  
601    // Retrieve necessary collections from the event.
602  
603 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
603 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
604      event.getByLabel (triggers_, triggers);
605  
606 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
606 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
607 >    event.getByLabel (trigobjs_, trigobjs);
608 >
609 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
610      event.getByLabel (jets_, jets);
611  
612 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
612 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
613      event.getByLabel (muons_, muons);
614  
615 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
615 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
616      event.getByLabel (electrons_, electrons);
617  
618 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
618 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
619      event.getByLabel (events_, events);
620  
621 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
621 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
622      event.getByLabel (taus_, taus);
623  
624 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
624 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
625      event.getByLabel (mets_, mets);
626  
627 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
627 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
628      event.getByLabel (tracks_, tracks);
629  
630 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
630 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
631      event.getByLabel (genjets_, genjets);
632  
633 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
633 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
634      event.getByLabel (mcparticles_, mcparticles);
635  
636 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
636 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
637      event.getByLabel (primaryvertexs_, primaryvertexs);
638  
639 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
639 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
640      event.getByLabel (bxlumis_, bxlumis);
641  
642 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
642 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
643      event.getByLabel (photons_, photons);
644  
645 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
645 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
646      event.getByLabel (superclusters_, superclusters);
647  
648 <  if (useTrackCaloRhoCorr_) {  
649 <    // Used only for pile-up correction of by-hand calculation of isolation energy.  
650 <    // This rho collection is not available in all BEANs.  
648 >  if (datasetType_ == "signalMC"){
649 >    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
650 >      event.getByLabel (stops_, stops);
651 >  }
652 >
653 >  if (useTrackCaloRhoCorr_) {
654 >    // Used only for pile-up correction of by-hand calculation of isolation energy.
655 >    // This rho collection is not available in all BEANs.
656      // For description of rho values for different jet reconstruction algorithms, see
657 <    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms  
658 <    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
657 >    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
658 >    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
659    }
660  
661 +  double masterScaleFactor = 1.0;
662  
663    //get pile-up event weight
664 <  double scaleFactor = 1.00;
665 <  if(doPileupReweighting_ && datasetType_ != "data")
666 <    scaleFactor = puWeight_->at (events->at (0).numTruePV);
664 >  if (doPileupReweighting_ && datasetType_ != "data") {
665 >    //for "data" datasets, the numTruePV is always set to -1
666 >    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;  
667 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);  
668 >  }
669  
670 +  stopCTauScaleFactor_ = 1.0;
671 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
672 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
673 +  masterScaleFactor *= stopCTauScaleFactor_;
674  
675    //loop over all channels
676  
# Line 504 | Line 681 | OSUAnalysis::analyze (const edm::Event &
681      counterMap passingCounter;
682      cumulativeFlags.clear ();
683  
684 +    if (fillBNTree_) {
685 +      for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
686 +           iter != BNTreeBranchVals_.end(); iter++) {
687 +        iter->second.clear();  // clear array
688 +      }
689 +    }
690 +
691      bool triggerDecision = true;
692 <    if(currentChannel.triggers.size() != 0){  //triggers specified
693 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
692 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
693 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
694        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
695      }
696  
697      //loop over all cuts
514
515
516
698      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
699        cut currentCut = currentChannel.cuts.at(currentCutIndex);
519
700        for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
701          string currentObject = objectsToCut.at(currentObjectIndex);
702  
# Line 531 | Line 711 | OSUAnalysis::analyze (const edm::Event &
711          int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
712  
713  
714 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
715 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
714 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
715 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
716 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
717 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
718 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
719          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
720          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
721          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 544 | Line 727 | OSUAnalysis::analyze (const edm::Event &
727          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
728          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
729          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
730 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
731 +
732  
733  
734          else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
735                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
736                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
737                                                                     "muon-muon pairs");
738 +
739 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
740 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
741 +                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
742 +                                                                             "muon-secondary muon pairs");
743 +
744 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
745 +                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
746 +                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
747 +                                                                                     "electron-secondary electron pairs");
748 +
749          else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
750                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
751                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
# Line 558 | Line 754 | OSUAnalysis::analyze (const edm::Event &
754                                                                         cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
755                                                                         cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
756                                                                         "electron-muon pairs");
757 <        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
758 <                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
759 <                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
760 <                                                                     "track-event pairs");
761 <        
757 >        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
758 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
759 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
760 >                                                                 "jet-jet pairs");
761 >        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
762 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
763 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
764 >                                                                      "electron-jet pairs");
765 >        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
766 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
767 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
768 >                                                                  "muon-jet pairs");
769 >        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
770 >                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
771 >                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
772 >                                                                     "track-event pairs");
773 >        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
774 >                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
775 >                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
776 >                                                                        "electron-track pairs");
777 >        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
778 >                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
779 >                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
780 >                                                                    "muon-track pairs");
781 >        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
782 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
783 >                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
784 >                                                                  "muon-tau pairs");
785 >        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
786 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
787 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
788 >                                                                 "tau-tau pairs");
789 >        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
790 >                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
791 >                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
792 >                                                                   "tau-track pairs");
793 >        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
794 >                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
795 >                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
796 >                                                                          "electron-trigobj pairs");
797 >        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
798 >                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
799 >                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
800 >                                                                      "muon-trigobj pairs");
801  
802 +        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
803        }
804  
805  
806  
807      }//end loop over all cuts
572
573
808      //use cumulative flags to apply cuts at event level
809  
810      bool eventPassedAllCuts = true;
811 <
811 >    //a vector to store cumulative cut descisions after each cut.
812 >    vector<bool> eventPassedPreviousCuts;
813      //apply trigger (true if none were specified)
814      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
815  
581
582
816      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
817  
818        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 587 | Line 820 | OSUAnalysis::analyze (const edm::Event &
820        int numberPassing = 0;
821  
822        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
823 <          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
823 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
824        }
592
825        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
826        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
595
827        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
828 +      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
829 +    }
830 +    double scaleFactor = masterScaleFactor;
831  
832 +    muonScaleFactor_ = electronScaleFactor_ = 1.0;
833 +    if(applyLeptonSF_ && datasetType_ != "data"){
834 +      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
835 +        vector<bool> muonFlags;
836 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
837 +          if (cumulativeFlags.at("muons").at(i).size()){
838 +            muonFlags = cumulativeFlags.at("muons").at(i);
839 +            break;
840 +          }
841 +        }
842 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
843 +          if(!muonFlags.at(muonIndex)) continue;
844 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
845 +        }
846 +      }
847 +      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
848 +        vector<bool> electronFlags;
849 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
850 +          if (cumulativeFlags.at("electrons").at(i).size()){
851 +            electronFlags = cumulativeFlags.at("electrons").at(i);
852 +            break;
853 +          }
854 +        }
855 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
856 +          if(!electronFlags.at(electronIndex)) continue;
857 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
858 +        }
859 +      }
860      }
861 +    scaleFactor *= muonScaleFactor_;
862 +    scaleFactor *= electronScaleFactor_;
863  
864      cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
865  
602
603
604    if(!eventPassedAllCuts)continue;
605
866      if (printEventInfo_) {
867 <      // Write information about event to screen, for testing purposes.  
868 <      cout << "Event passed all cuts in channel " <<  currentChannel.name
869 <           << ": run="  << events->at(0).run
870 <           << "  lumi=" << events->at(0).lumi
871 <           << "  event=" << events->at(0).evt
872 <           << endl;  
867 >      // Write information about event to screen, for testing purposes.
868 >      cout << "Event passed all cuts in channel " <<  currentChannel.name
869 >           << ": run="  << events->at(0).run
870 >           << "  lumi=" << events->at(0).lumi
871 >           << "  event=" << events->at(0).evt
872 >           << endl;
873      }
874  
875  
616 //     if(datasetType_ != "data") {
617 //       scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
618 //       scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
619 //     }
620
876      //filling histograms
877 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
878 <      histogram currentHistogram = histograms.at(histogramIndex);
877 >    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
878 >      uint currentDir;
879 >      if(!GetPlotsAfterEachCut_){ currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size();}//if GetPlotsAfterEachCut_ is true, set currentDir point to the lat cut.
880 >      else{
881 >        currentDir = currentCut;
882 >      }
883 >      if(eventPassedPreviousCuts.at(currentDir)){
884  
885 <      if(currentHistogram.inputVariables.size() == 1){
886 <        TH1D* histo;
887 <        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
888 <
889 <
890 <
891 <        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
892 <         else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
893 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
894 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
895 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
896 <        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
897 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
898 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
899 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
900 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
901 <                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
902 <                                                                                              cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
903 <        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
904 <        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
905 <        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
906 <        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
907 <        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
908 <        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
909 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
910 <        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
911 <        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
912 <        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
913 <      }
914 <      else if(currentHistogram.inputVariables.size() == 2){
915 <        TH2D* histo;
916 <        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
917 <
918 <
919 <
920 <        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
921 <        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
922 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
923 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
924 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
925 <        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
926 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
927 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
928 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
929 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
930 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
931 <                                                                                               cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
932 <        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
933 <        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
934 <        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
935 <        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
936 <        else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
937 <                                                                                         cumulativeFlags.at("tracks").back(),cumulativeFlags.at("events").back(),
938 <                                                                                         cumulativeFlags.at("track-event pairs").back(),scaleFactor);  
939 <        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
940 <        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
941 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
942 <        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
943 <        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
944 <        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
945 <      }
946 <    }
947 <
948 <    //fills histograms with the sizes of collections
949 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
950 <
951 <      string currentObject = objectsToPlot.at(currentObjectIndex);
952 <
953 <      string objectToPlot = "";  
954 <
955 <      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().  
956 <      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
957 <      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
958 <      else if(currentObject == "electron-muon pairs")     objectToPlot = "electronMuonPairs";
959 <      else if(currentObject == "track-event pairs")       objectToPlot = "trackEventPairs";  
960 <      else objectToPlot = currentObject;
961 <      string tempCurrentObject = objectToPlot;
962 <      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));  // Capitalize the first letter.  
963 <      string histoName = "num" + tempCurrentObject;
964 <
965 <
966 <      //set position of primary vertex in event, in order to calculate quantities relative to it
967 <      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
968 <        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
969 <        int numToPlot = 0;
970 <        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
971 <          if(lastCutFlags.at(currentFlag)) numToPlot++;
972 <        }
973 <        if(objectToPlot == "primaryvertexs"){
974 <          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
975 <          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
976 <        }
977 <        else {
978 <          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
885 >        // Assign BNTree variables
886 >        if (fillBNTree_) {
887 >          for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
888 >            BranchSpecs brSpecs = treeBranches_.at(iBranch);  
889 >            string coll = brSpecs.inputCollection;  
890 >            if (cumulativeFlags.count(coll) == 0) cout << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
891 >            
892 >            if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).at(currentDir));          
893 >            else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).at(currentDir));
894 >            else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).at(currentDir));        
895 >            else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).at(currentDir));
896 >            else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).at(currentDir));
897 >            else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).at(currentDir));
898 >            else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).at(currentDir));
899 >            else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).at(currentDir));
900 >            else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).at(currentDir));
901 >            else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).at(currentDir));
902 >            else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).at(currentDir));
903 >            else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).at(currentDir));
904 >            else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).at(currentDir));
905 >            else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).at(currentDir));
906 >            else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).at(currentDir));
907 >            else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).at(currentDir));
908 >            else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).at(currentDir));
909 >            else if(coll == "stops"
910 >                    && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).at(currentDir));
911 >          } // end loop over branches  
912 >        } // end if (fillBNTree_) {                                                        
913 >
914 >        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
915 >          histogram currentHistogram = histograms.at(histogramIndex);
916 >
917 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) cout << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
918 >
919 >          if(currentHistogram.inputVariables.size() == 1){
920 >            TH1D* histo;  
921 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
922 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
923 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
924 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
925 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
926 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
927 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
928 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
929 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
930 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
931 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
932 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
933 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
934 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
935 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
936 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
937 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
938 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
939 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
940 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
941 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
942 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
943 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
944 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
945 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
946 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
947 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
948 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
949 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
950 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
951 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
952 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
953 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
954 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
955 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
956 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
957 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
958 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
959 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
960 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
961 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
962 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
963 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
964 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
965 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
966 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
967 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
968 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
969 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
970 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
971 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
972 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
973 >
974 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
975 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
976 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
977 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
978 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
979 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
980 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
981 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
982 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
983 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
984 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
985 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
986 >          }
987 >          else if(currentHistogram.inputVariables.size() == 2){
988 >            TH2D* histo;
989 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
990 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
991 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
992 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
993 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
994 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
995 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
996 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
997 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
998 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
999 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1000 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1001 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1002 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1003 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1004 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1005 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1006 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1007 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1008 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1009 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1010 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1011 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1012 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1013 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1014 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1015 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1016 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1017 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1018 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1019 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1020 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1021 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1022 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1023 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1024 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1025 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1026 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1027 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1028 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1029 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1030 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1031 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1032 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1033 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1034 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1035 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1036 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1037 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1038 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1039 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1040 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1041 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1042 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1043 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1044 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1045 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1046 >                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1047 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1048 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1049 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1050 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1051 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1052 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1053 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1054 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1055 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1056 >          }
1057 >          
1058          }
720      }
721      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
722      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
723      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
724      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
725      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
726      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
727      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
728      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
729      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
730      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
731      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
732      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
733      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
734      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
735      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
736      else if(objectToPlot == "primaryvertexs"){
737        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
738        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
739      }
1059  
741    } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1060  
1061 <  } //end loop over channel
1061 >        //fills histograms with the sizes of collections
1062 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1063 >
1064 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1065 >          string objectToPlot = "";
1066 >
1067 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1068 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1069 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1070 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1071 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1072 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1073 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1074 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1075 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1076 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1077 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1078 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1079 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1080 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1081 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1082 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1083 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1084 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1085 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1086 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1087 >          else objectToPlot = currentObject;
1088 >
1089 >          string tempCurrentObject = objectToPlot;
1090 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1091 >          string histoName = "num" + tempCurrentObject;
1092 >
1093 >          //set position of primary vertex in event, in order to calculate quantities relative to it
1094 >          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1095 >            vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1096 >            int numToPlot = 0;
1097 >            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1098 >              if(lastCutFlags.at(currentFlag)) numToPlot++;
1099 >            }
1100 >            if(objectToPlot == "primaryvertexs"){
1101 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1102 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1103 >            }
1104 >            else {
1105 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1106 >            }
1107 >          }
1108 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1109 >      } // end if(eventPassedPreviousCuts.at(currentDir)){
1110 >    } // end loop over cuts
1111 >
1112 >    if (fillBNTree_) BNTrees_.at(currentChannelIndex)->Fill();  
1113 >
1114 >  } // end loop over channel
1115 >
1116 >  masterCutFlow_->fillCutFlow(masterScaleFactor);
1117  
745  masterCutFlow_->fillCutFlow(scaleFactor);
1118  
1119   } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1120  
# Line 759 | Line 1131 | OSUAnalysis::evaluateComparison (double
1131    else if(comparison == "==") return testValue == cutValue;
1132    else if(comparison == "=") return testValue == cutValue;
1133    else if(comparison == "!=") return testValue != cutValue;
1134 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1134 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1135  
1136   }
1137  
1138   bool
1139 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1139 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1140  
1141 +
1142 +  if(comparison == ">")       return testValue >  cutValue;
1143 +  else if(comparison == ">=") return testValue >= cutValue;
1144 +  else if(comparison == "<")  return testValue <  cutValue;
1145 +  else if(comparison == "<=") return testValue <= cutValue;
1146 +  else if(comparison == "==") return testValue == cutValue;
1147 +  else if(comparison == "=") return testValue == cutValue;
1148 +  else if(comparison == "!=") return testValue != cutValue;
1149 +  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1150 +
1151 + }
1152 +
1153 + bool
1154 + OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1155 +
1156 +  //initialize to false until a chosen trigger is passed
1157    bool triggerDecision = false;
1158  
1159 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1160 <    {
773 <      if(trigger->pass != 1) continue;
774 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
775 <        {
776 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
777 <            triggerDecision = true;
778 <          }
779 <        }
780 <    }
781 <  return triggerDecision;
1159 >  //loop over all triggers defined in the event
1160 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1161  
1162 +    //we're only interested in triggers that actually passed
1163 +    if(trigger->pass != 1) continue;
1164 +
1165 +    //if the event passes one of the veto triggers, exit and return false
1166 +    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1167 +      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1168 +    }
1169 +    //if the event passes one of the chosen triggers, set triggerDecision to true
1170 +    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1171 +      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1172 +    }  
1173 +  }
1174 +  //if none of the veto triggers fired:
1175 +  //return the OR of all the chosen triggers
1176 +  if (triggersToTest.size() != 0) return triggerDecision;
1177 +  //or if no triggers were defined return true
1178 +  else return true;
1179   }
1180  
1181 < std::vector<std::string>
1181 >
1182 > vector<string>
1183   OSUAnalysis::splitString (string inputString){
1184  
1185 <  std::stringstream stringStream(inputString);
1186 <  std::istream_iterator<std::string> begin(stringStream);
1187 <  std::istream_iterator<std::string> end;
1188 <  std::vector<std::string> stringVector(begin, end);
1185 >  stringstream stringStream(inputString);
1186 >  istream_iterator<string> begin(stringStream);
1187 >  istream_iterator<string> end;
1188 >  vector<string> stringVector(begin, end);
1189    return stringVector;
1190  
1191   }
1192  
1193 +
1194 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1195 +  // Set two object strings from the tempInputCollection string,
1196 +  // For example, if tempInputCollection is "electron-muon pairs",
1197 +  // then obj1 = "electrons" and obj2 = "muons".
1198 +  // Note that the objects have an "s" appended.
1199 +
1200 +  int dashIndex = tempInputCollection.find("-");
1201 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1202 +  int secondWordLength = spaceIndex - dashIndex;
1203 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1204 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1205 +
1206 + }
1207 +
1208 +
1209 + string OSUAnalysis::getObjToGet(string obj) {
1210 +  // Return the string corresponding to the object to get for the given obj string.
1211 +  // Right now this only handles the case in which obj contains "secondary",
1212 +  // e.g, "secondary muons".
1213 +  // Note that "s" is NOT appended.
1214 +
1215 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1216 +  int firstSpaceIndex = obj.find_first_of(" ");
1217 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1218 +
1219 + }
1220 +
1221 +
1222 + //!jet valueLookup
1223   double
1224 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1224 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1225  
1226    double value = 0.0;
1227    if(variable == "energy") value = object->energy;
# Line 914 | Line 1341 | OSUAnalysis::valueLookup (const BNjet* o
1341    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1342  
1343  
1344 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1344 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1345  
1346    value = applyFunction(function, value);
1347  
# Line 922 | Line 1349 | OSUAnalysis::valueLookup (const BNjet* o
1349   }
1350  
1351  
1352 <
1352 > //!muon valueLookup
1353   double
1354 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1354 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1355  
1356    double value = 0.0;
1357    if(variable == "energy") value = object->energy;
# Line 1085 | Line 1512 | OSUAnalysis::valueLookup (const BNmuon*
1512    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1513    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1514    else if(variable == "metMT") {
1515 <    const BNmet *met = chosenMET ();
1089 <    if (met)
1515 >    if (const BNmet *met = chosenMET ())
1516        {
1517 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1518 <                       p2 (met->px, met->py, 0.0, met->pt);
1093 <
1094 <        value = (p1 + p2).Mt ();
1517 >        double dPhi = deltaPhi (object->phi, met->phi);
1518 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1519        }
1520      else
1521        value = -999;
# Line 1218 | Line 1642 | OSUAnalysis::valueLookup (const BNmuon*
1642    }
1643    else if(variable == "tightIDdisplaced"){
1644      value = object->isGlobalMuon > 0                \
1645 +      && object->isPFMuon > 0                        \
1646        && object->normalizedChi2 < 10                \
1647        && object->numberOfValidMuonHits > 0        \
1648        && object->numberOfMatchedStations > 1        \
# Line 1225 | Line 1650 | OSUAnalysis::valueLookup (const BNmuon*
1650        && object->numberOfLayersWithMeasurement > 5;
1651    }
1652  
1653 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1653 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1654  
1655    else if(variable == "genMatchedPdgId"){
1656      int index = getGenMatchedParticleIndex(object);
# Line 1245 | Line 1670 | OSUAnalysis::valueLookup (const BNmuon*
1670    }
1671    else if(variable == "genMatchedMotherIdReverse"){
1672      int index = getGenMatchedParticleIndex(object);
1673 <    if(index == -1) value = 23;
1674 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1673 >    if(index == -1) value = 24;
1674 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1675    }
1676    else if(variable == "genMatchedGrandmotherId"){
1677      int index = getGenMatchedParticleIndex(object);
# Line 1258 | Line 1683 | OSUAnalysis::valueLookup (const BNmuon*
1683      }
1684      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1685    }
1686 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1687 +    int index = getGenMatchedParticleIndex(object);
1688 +    if(index == -1) value = 24;
1689 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1690 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1691 +      if(motherIndex == -1) value = 24;
1692 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1693 +    }
1694 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1695 +  }
1696 +  else if(variable == "pfMuonsFromVertex"){
1697 +    double d0Error, dzError;
1698  
1699 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1700 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1701 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1702 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1703 +      || fabs (object->correctedDZ / dzError) > 99.0;
1704 +    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1705 +  }
1706  
1707  
1708 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1708 >
1709 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1710  
1711    value = applyFunction(function, value);
1712  
1713    return value;
1714   }
1715  
1716 <
1716 > //!electron valueLookup
1717   double
1718 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1718 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1719  
1720    double value = 0.0;
1721    if(variable == "energy") value = object->energy;
# Line 1436 | Line 1881 | OSUAnalysis::valueLookup (const BNelectr
1881    else if(variable == "detIso") value = (object->trackIso) / object->pt;
1882    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1883    else if(variable == "metMT") {
1884 <    const BNmet *met = chosenMET ();
1440 <    if (met)
1884 >    if (const BNmet *met = chosenMET ())
1885        {
1886 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1887 <                       p2 (met->px, met->py, 0.0, met->pt);
1444 <
1445 <        value = (p1 + p2).Mt ();
1886 >        double dPhi = deltaPhi (object->phi, met->phi);
1887 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1888        }
1889      else
1890        value = -999;
# Line 1607 | Line 2049 | OSUAnalysis::valueLookup (const BNelectr
2049    }
2050  
2051  
2052 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2052 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2053  
2054    else if(variable == "genMatchedPdgId"){
2055      int index = getGenMatchedParticleIndex(object);
# Line 1628 | Line 2070 | OSUAnalysis::valueLookup (const BNelectr
2070    }
2071    else if(variable == "genMatchedMotherIdReverse"){
2072      int index = getGenMatchedParticleIndex(object);
2073 <    if(index == -1) value = 23;
2074 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2073 >    if(index == -1) value = 24;
2074 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2075    }
2076    else if(variable == "genMatchedGrandmotherId"){
2077      int index = getGenMatchedParticleIndex(object);
# Line 1641 | Line 2083 | OSUAnalysis::valueLookup (const BNelectr
2083      }
2084      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2085    }
2086 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2087 +    int index = getGenMatchedParticleIndex(object);
2088 +    if(index == -1) value = 24;
2089 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2090 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2091 +      if(motherIndex == -1) value = 24;
2092 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2093 +    }
2094 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2095 +  }
2096 +  else if(variable == "pfElectronsFromVertex"){
2097 +    double d0Error, dzError;
2098  
2099 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2100 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2101 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2102 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2103 +      || fabs (object->correctedDZ / dzError) > 99.0;
2104 +    value = !value;
2105 +  }
2106  
2107  
2108 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2108 >
2109 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2110  
2111    value = applyFunction(function, value);
2112  
2113    return value;
2114   }
2115  
2116 <
2116 > //!event valueLookup
2117   double
2118 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2118 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2119  
2120    double value = 0.0;
2121  
# Line 1722 | Line 2184 | OSUAnalysis::valueLookup (const BNevent*
2184    else if(variable == "id2") value = object->id2;
2185    else if(variable == "evt") value = object->evt;
2186    else if(variable == "puScaleFactor"){
2187 <    if(datasetType_ != "data")
2187 >    if(doPileupReweighting_ && datasetType_ != "data")
2188        value = puWeight_->at (events->at (0).numTruePV);
2189      else
2190        value = 1.0;
2191    }
2192 <  else if(variable == "muonScaleFactor"){
2193 <    if(datasetType_ != "data")
2194 <      //      value = muonSFWeight_->at (chosenMuon ()->eta);
1733 <    value = 1.0;
1734 <    else
1735 <      value = 1.0;
1736 <  }
1737 <  else if(variable == "electronScaleFactor"){
1738 <    if(datasetType_ != "data")
1739 <      //      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1740 <    value = 1.0;
1741 <    else
1742 <      value = 1.0;
1743 <  }
2192 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2193 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2194 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2195  
2196 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2196 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2197  
2198    value = applyFunction(function, value);
2199  
2200    return value;
2201   }
2202  
2203 + //!tau valueLookup
2204   double
2205 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2205 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2206  
2207    double value = 0.0;
2208  
# Line 1796 | Line 2248 | OSUAnalysis::valueLookup (const BNtau* o
2248  
2249  
2250  
2251 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2251 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2252  
2253    else if(variable == "genMatchedPdgId"){
2254      int index = getGenMatchedParticleIndex(object);
# Line 1816 | Line 2268 | OSUAnalysis::valueLookup (const BNtau* o
2268    }
2269    else if(variable == "genMatchedMotherIdReverse"){
2270      int index = getGenMatchedParticleIndex(object);
2271 <    if(index == -1) value = 23;
2272 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2271 >    if(index == -1) value = 24;
2272 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2273    }
2274    else if(variable == "genMatchedGrandmotherId"){
2275      int index = getGenMatchedParticleIndex(object);
# Line 1829 | Line 2281 | OSUAnalysis::valueLookup (const BNtau* o
2281      }
2282      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2283    }
2284 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2285 +    int index = getGenMatchedParticleIndex(object);
2286 +    if(index == -1) value = 24;
2287 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2288 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2289 +      if(motherIndex == -1) value = 24;
2290 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2291 +    }
2292 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2293 +  }
2294  
2295  
2296 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2296 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2297  
2298    value = applyFunction(function, value);
2299  
2300    return value;
2301   }
2302  
2303 + //!met valueLookup
2304   double
2305 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2305 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2306  
2307    double value = 0.0;
2308  
# Line 1903 | Line 2366 | OSUAnalysis::valueLookup (const BNmet* o
2366    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2367    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2368  
2369 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2369 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2370  
2371    value = applyFunction(function, value);
2372  
2373    return value;
2374   }
2375  
2376 + //!track valueLookup
2377   double
2378 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2378 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2379  
2380    double value = 0.0;
2381    double pMag = sqrt(object->pt * object->pt +
2382 <                     object->pz * object->pz);
2383 <  
2382 >                     object->pz * object->pz);
2383 >
2384    if(variable == "pt") value = object->pt;
2385    else if(variable == "px") value = object->px;
2386    else if(variable == "py") value = object->py;
# Line 1937 | Line 2401 | OSUAnalysis::valueLookup (const BNtrack*
2401  
2402  
2403    //additional BNs info for disappTrks
1940  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2404    else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2405    else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2406    else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2407    else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2408    else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2409    else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2410 +  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2411    else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2412    else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2413    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2414 <  
2414 >  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2415  
2416    //user defined variables
2417    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;
2418    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2419 +  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2420    else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2421    else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2422 <  else if(variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object);  
2423 <  else if(variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object) / pMag;  
2422 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2423 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2424    else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2425    else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2426    else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2427    else if(variable == "ptError")                    value = object->ptError;
2428    else if(variable == "ptRes")                      value = getTrkPtRes(object);
2429 <
2430 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2429 >  else if (variable == "d0wrtPV"){
2430 >    double vx = object->vx - chosenVertex ()->x,
2431 >      vy = object->vy - chosenVertex ()->y,
2432 >      px = object->px,
2433 >      py = object->py,
2434 >      pt = object->pt;
2435 >    value = (-vx * py + vy * px) / pt;
2436 >  }
2437 >  else if (variable == "dZwrtPV"){
2438 >    double vx = object->vx - chosenVertex ()->x,
2439 >      vy = object->vy - chosenVertex ()->y,
2440 >      vz = object->vz - chosenVertex ()->z,
2441 >      px = object->px,
2442 >      py = object->py,
2443 >      pz = object->pz,
2444 >      pt = object->pt;
2445 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2446 >  }
2447 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2448  
2449    else if(variable == "genMatchedPdgId"){
2450      int index = getGenMatchedParticleIndex(object);
# Line 1983 | Line 2465 | OSUAnalysis::valueLookup (const BNtrack*
2465    }
2466    else if(variable == "genMatchedMotherIdReverse"){
2467      int index = getGenMatchedParticleIndex(object);
2468 <    if(index == -1) value = 23;
2469 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2468 >    if(index == -1) value = 24;
2469 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2470    }
2471    else if(variable == "genMatchedGrandmotherId"){
2472      int index = getGenMatchedParticleIndex(object);
# Line 1996 | Line 2478 | OSUAnalysis::valueLookup (const BNtrack*
2478      }
2479      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2480    }
2481 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2482 +    int index = getGenMatchedParticleIndex(object);
2483 +    if(index == -1) value = 24;
2484 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2485 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2486 +      if(motherIndex == -1) value = 24;
2487 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2488 +    }
2489 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2490 +  }
2491  
2492  
2493  
2494 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2494 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2495  
2496    value = applyFunction(function, value);
2497  
2498    return value;
2499   }
2500  
2501 + //!genjet valueLookup
2502   double
2503 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2503 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2504  
2505    double value = 0.0;
2506  
# Line 2027 | Line 2520 | OSUAnalysis::valueLookup (const BNgenjet
2520    else if(variable == "charge") value = object->charge;
2521  
2522  
2523 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2523 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2524  
2525    value = applyFunction(function, value);
2526  
2527    return value;
2528   }
2529  
2530 + //!mcparticle valueLookup
2531   double
2532 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2532 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2533  
2534    double value = 0.0;
2535  
# Line 2160 | Line 2654 | OSUAnalysis::valueLookup (const BNmcpart
2654    }
2655  
2656  
2657 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2657 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2658  
2659    value = applyFunction(function, value);
2660  
2661    return value;
2662   }
2663  
2664 + //!primaryvertex valueLookup
2665   double
2666 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2666 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2667  
2668    double value = 0.0;
2669  
# Line 2187 | Line 2682 | OSUAnalysis::valueLookup (const BNprimar
2682    else if(variable == "isGood") value = object->isGood;
2683  
2684  
2685 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2685 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2686  
2687    value = applyFunction(function, value);
2688  
2689    return value;
2690   }
2691  
2692 + //!bxlumi valueLookup
2693   double
2694 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2694 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2695  
2696    double value = 0.0;
2697  
# Line 2204 | Line 2700 | OSUAnalysis::valueLookup (const BNbxlumi
2700    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2701  
2702  
2703 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2703 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2704  
2705    value = applyFunction(function, value);
2706  
2707    return value;
2708   }
2709  
2710 + //!photon valueLookup
2711   double
2712 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2712 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2713  
2714    double value = 0.0;
2715  
# Line 2287 | Line 2784 | OSUAnalysis::valueLookup (const BNphoton
2784    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2785  
2786  
2290
2787  
2788 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2788 >
2789 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2790  
2791    else if(variable == "genMatchedPdgId"){
2792      int index = getGenMatchedParticleIndex(object);
# Line 2311 | Line 2808 | OSUAnalysis::valueLookup (const BNphoton
2808    }
2809    else if(variable == "genMatchedMotherIdReverse"){
2810      int index = getGenMatchedParticleIndex(object);
2811 <    if(index == -1) value = 23;
2812 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2811 >    if(index == -1) value = 24;
2812 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2813    }
2814    else if(variable == "genMatchedGrandmotherId"){
2815      int index = getGenMatchedParticleIndex(object);
# Line 2324 | Line 2821 | OSUAnalysis::valueLookup (const BNphoton
2821      }
2822      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2823    }
2824 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2825 +    int index = getGenMatchedParticleIndex(object);
2826 +    if(index == -1) value = 24;
2827 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2828 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2829 +      if(motherIndex == -1) value = 24;
2830 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2831 +    }
2832 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2833 +  }
2834  
2835  
2836 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2836 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2837  
2838    value = applyFunction(function, value);
2839  
2840    return value;
2841   }
2842  
2843 + //!supercluster valueLookup
2844   double
2845 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
2845 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
2846  
2847    double value = 0.0;
2848  
# Line 2348 | Line 2856 | OSUAnalysis::valueLookup (const BNsuperc
2856    else if(variable == "theta") value = object->theta;
2857  
2858  
2859 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2859 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2860  
2861    value = applyFunction(function, value);
2862  
2863    return value;
2864   }
2865  
2866 + //!trigobj valueLookup
2867 + double
2868 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
2869 +
2870 +  double value = 0.0;
2871 +
2872 +  if(variable == "pt") value = object->pt;
2873 +  else if(variable == "eta") value = object->eta;
2874 +  else if(variable == "phi") value = object->phi;
2875 +  else if(variable == "px") value = object->px;
2876 +  else if(variable == "py") value = object->py;
2877 +  else if(variable == "pz") value = object->pz;
2878 +  else if(variable == "et") value = object->et;
2879 +  else if(variable == "energy") value = object->energy;
2880 +  else if(variable == "etTotal") value = object->etTotal;
2881 +  else if(variable == "id") value = object->id;
2882 +  else if(variable == "charge") value = object->charge;
2883 +  else if(variable == "isIsolated") value = object->isIsolated;
2884 +  else if(variable == "isMip") value = object->isMip;
2885 +  else if(variable == "isForward") value = object->isForward;
2886 +  else if(variable == "isRPC") value = object->isRPC;
2887 +  else if(variable == "bx") value = object->bx;
2888 +  else if(variable == "filter") {
2889 +    if ((stringValue = object->filter) == "")
2890 +      stringValue = "none";  // stringValue should only be empty if value is filled
2891 +  }
2892 +
2893 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2894  
2895 +  value = applyFunction(function, value);
2896 +
2897 +  return value;
2898 + }
2899 +
2900 + //!muon-muon pair valueLookup
2901   double
2902 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
2902 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
2903  
2904    double value = 0.0;
2905  
2906    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2907 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2908    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2909    else if(variable == "invMass"){
2910      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2403 | Line 2946 | OSUAnalysis::valueLookup (const BNmuon*
2946    else if(variable == "muon2CorrectedD0Vertex"){
2947      value = object2->correctedD0Vertex;
2948    }
2949 < else if(variable == "muon1timeAtIpInOut"){
2949 >  else if(variable == "muon1timeAtIpInOut"){
2950      value = object1->timeAtIpInOut;
2951    }
2952 < else if(variable == "muon2timeAtIpInOut"){
2952 >  else if(variable == "muon2timeAtIpInOut"){
2953      value = object2->timeAtIpInOut;
2954    }
2955 < else if(variable == "muon1correctedD0")
2956 <   {
2957 <     value = object1->correctedD0;
2958 <   }
2959 < else if(variable == "muon2correctedD0")
2960 <   {
2961 <     value = object2->correctedD0;
2962 <   }
2955 >  else if(variable == "muon1correctedD0")
2956 >    {
2957 >      value = object1->correctedD0;
2958 >    }
2959 >  else if(variable == "muon2correctedD0")
2960 >    {
2961 >      value = object2->correctedD0;
2962 >    }
2963  
2964 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2964 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2965  
2966    value = applyFunction(function, value);
2967  
2968    return value;
2969   }
2970  
2971 + //!electron-electron pair valueLookup
2972   double
2973 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
2973 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
2974  
2975    double value = 0.0;
2976  
2977    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2978 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2979    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2980    else if(variable == "invMass"){
2981      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2472 | Line 3017 | OSUAnalysis::valueLookup (const BNelectr
3017      value = object2->correctedD0;
3018    }
3019  
3020 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3020 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3021  
3022    value = applyFunction(function, value);
3023  
3024    return value;
3025   }
3026 <
3026 > //!electron-muon pair valueLookup
3027   double
3028 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3028 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3029  
3030    double value = 0.0;
3031  
3032    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3033 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3034    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3035    else if(variable == "invMass"){
3036      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2531 | Line 3077 | OSUAnalysis::valueLookup (const BNelectr
3077    else if(variable == "muonDetIso"){
3078      value = (object2->trackIsoDR03) / object2->pt;
3079    }
3080 +  else if(variable == "electronRelPFrhoIso"){
3081 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3082 +  }
3083 +  else if(variable == "muonRelPFdBetaIso"){
3084 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3085 +  }
3086 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3087 +  value = applyFunction(function, value);
3088 +
3089 +  return value;
3090 + }
3091 +
3092 + //!electron-jet pair valueLookup
3093 + double
3094 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3095 +
3096 +  double value = 0.0;
3097 +
3098 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3099 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3100 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3101 +  else if(variable == "invMass"){
3102 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3103 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3104 +    value = (fourVector1 + fourVector2).M();
3105 +  }
3106 +  else if(variable == "pt"){
3107 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3108 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3109 +    value = (fourVector1 + fourVector2).Pt();
3110 +  }
3111 +  else if(variable == "threeDAngle")
3112 +    {
3113 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3114 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3115 +      value = (threeVector1.Angle(threeVector2));
3116 +    }
3117 +  else if(variable == "chargeProduct"){
3118 +    value = object1->charge*object2->charge;
3119 +  }
3120 +
3121 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3122 +  value = applyFunction(function, value);
3123 +
3124 +  return value;
3125 + }
3126 +
3127 + //!muon-jet pair valueLookup
3128 + double
3129 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3130 +
3131 +  double value = 0.0;
3132 +
3133 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3134 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3135 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3136 +  else if(variable == "invMass"){
3137 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3138 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3139 +    value = (fourVector1 + fourVector2).M();
3140 +  }
3141 +  else if(variable == "pt"){
3142 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3143 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3144 +    value = (fourVector1 + fourVector2).Pt();
3145 +  }
3146 +  else if(variable == "threeDAngle")
3147 +    {
3148 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3149 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3150 +      value = (threeVector1.Angle(threeVector2));
3151 +    }
3152 +  else if(variable == "chargeProduct"){
3153 +    value = object1->charge*object2->charge;
3154 +  }
3155  
3156 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3157 +  value = applyFunction(function, value);
3158  
3159 +  return value;
3160 + }
3161 +
3162 + //!jet-jet pair valueLookup
3163 + double
3164 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3165 +
3166 +  double value = 0.0;
3167 +
3168 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3169 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3170 +  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3171 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3172 +  else if(variable == "invMass"){
3173 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3174 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3175 +    value = (fourVector1 + fourVector2).M();
3176 +  }
3177 +  else if(variable == "pt"){
3178 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3179 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3180 +    value = (fourVector1 + fourVector2).Pt();
3181 +  }
3182 +  else if(variable == "threeDAngle")
3183 +    {
3184 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3185 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3186 +      value = (threeVector1.Angle(threeVector2));
3187 +    }
3188 +  else if(variable == "chargeProduct"){
3189 +    value = object1->charge*object2->charge;
3190 +  }
3191 +
3192 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3193 +  value = applyFunction(function, value);
3194 +
3195 +  return value;
3196 + }
3197 + //!electron-track pair valueLookup
3198 + double
3199 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3200 +  double electronMass = 0.000511;
3201 +  double value = 0.0;
3202 +  TLorentzVector fourVector1(0, 0, 0, 0);
3203 +  TLorentzVector fourVector2(0, 0, 0, 0);
3204 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3205 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3206 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3207 +  else if(variable == "invMass"){
3208 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3209 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3210 +
3211 +    value = (fourVector1 + fourVector2).M();
3212 +  }
3213 +  else if(variable == "chargeProduct"){
3214 +    value = object1->charge*object2->charge;
3215 +  }
3216    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3217 +  value = applyFunction(function, value);
3218 +  return value;
3219  
3220 + }
3221 +
3222 +
3223 + //!muon-track pair valueLookup
3224 + double
3225 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3226 +  double pionMass = 0.140;
3227 +  double muonMass = 0.106;
3228 +  double value = 0.0;
3229 +  TLorentzVector fourVector1(0, 0, 0, 0);
3230 +  TLorentzVector fourVector2(0, 0, 0, 0);
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 == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3234 +  else if(variable == "invMass"){
3235 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3236 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3237 +
3238 +    value = (fourVector1 + fourVector2).M();
3239 +  }
3240 +  else if(variable == "chargeProduct"){
3241 +    value = object1->charge*object2->charge;
3242 +  }
3243 +
3244 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3245 +  value = applyFunction(function, value);
3246 +  return value;
3247 + }
3248 +
3249 + //!tau-tau pair valueLookup
3250 + double
3251 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3252 +  double value = 0.0;
3253 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3254 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3255 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3256 +  else if(variable == "invMass"){
3257 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3258 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3259 +    value = (fourVector1 + fourVector2).M();
3260 +  }
3261 +
3262 +  else if(variable == "chargeProduct"){
3263 +    value = object1->charge*object2->charge;
3264 +  }
3265 +
3266 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3267    value = applyFunction(function, value);
3268 +  return value;
3269 + }
3270 +
3271 + //!muon-tau pair valueLookup
3272 + double
3273 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3274 +  double value = 0.0;
3275 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3276 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3277 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3278 +  else if(variable == "invMass"){
3279 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3280 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3281 +    value = (fourVector1 + fourVector2).M();
3282 +  }
3283  
3284 +  else if(variable == "chargeProduct"){
3285 +    value = object1->charge*object2->charge;
3286 +  }
3287 +
3288 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3289 +  value = applyFunction(function, value);
3290    return value;
3291   }
3292  
3293 + //!tau-track pair valueLookup
3294 + double
3295 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3296 +  double value = 0.0;
3297 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3298 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3299 +  else if(variable == "chargeProduct"){
3300 +    value = object1->charge*object2->charge;
3301 +  }
3302  
3303 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3304 +  value = applyFunction(function, value);
3305 +  return value;
3306 + }
3307  
3308  
3309 + //!track-event pair valueLookup
3310   double
3311 < OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function){
3311 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3312  
3313    double value = 0.0;
3314    double pMag = sqrt(object1->pt * object1->pt +
3315 <                     object1->pz * object1->pz);  
3315 >                     object1->pz * object1->pz);
3316  
3317    if      (variable == "numPV")                      value = object2->numPV;
3318    else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3319    else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3320 <  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);  
3321 <  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;  
3320 >  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3321 >  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3322 >
3323 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3324 >
3325 >  value = applyFunction(function, value);
3326 >
3327 >  return value;
3328 >
3329 > }
3330 >
3331 > //!electron-trigobj pair valueLookup
3332 > double
3333 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3334 >
3335 >  double value = 0.0;
3336 >
3337 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3338 >  else if (variable == "match"){
3339 >    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3340 >      stringValue = object2->filter;
3341 >    else
3342 >      stringValue = "none";
3343 >  }
3344 >
3345 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3346 >
3347 >  value = applyFunction(function, value);
3348  
3349 <  else { std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3349 >  return value;
3350 >
3351 > }
3352 >
3353 > //!muon-trigobj pair valueLookup
3354 > double
3355 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3356 >
3357 >  double value = 0.0;
3358 >
3359 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3360 >
3361 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3362  
3363    value = applyFunction(function, value);
3364  
3365    return value;
3366  
3367 < }  
3367 > }
3368 >
3369 > //!stop valueLookup
3370 > double
3371 > OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3372 >
3373 >
3374 >  double value = 0.0;
3375 >
3376 >  if(variable == "ctau") value = object->ctau;
3377 >
3378 >  else if (variable == "d0"){
3379 >    double vx = object->vx - chosenVertex ()->x,
3380 >      vy = object->vy - chosenVertex ()->y,
3381 >      px = object->px,
3382 >      py = object->py,
3383 >      pt = object->pt;
3384 >    value = (-vx * py + vy * px) / pt;
3385 >  }
3386 >
3387 >  else if (variable == "dz"){
3388 >    double vx = object->vx - chosenVertex ()->x,
3389 >      vy = object->vy - chosenVertex ()->y,
3390 >      vz = object->vz - chosenVertex ()->z,
3391 >      px = object->px,
3392 >      py = object->py,
3393 >      pz = object->pz,
3394 >      pt = object->pt;
3395 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3396 >  }
3397 >
3398 >  else if (variable == "minD0"){
3399 >    double minD0=999;
3400 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3401 >      double vx = object->vx - vertex->x,
3402 >        vy = object->vy - vertex->y,
3403 >        px = object->px,
3404 >        py = object->py,
3405 >        pt = object->pt;
3406 >      value = (-vx * py + vy * px) / pt;
3407 >      if(abs(value) < abs(minD0)) minD0 = value;
3408 >    }
3409 >    value = minD0;
3410 >  }
3411 >  else if (variable == "minDz"){
3412 >    double minDz=999;
3413 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3414 >      double vx = object->vx - vertex->x,
3415 >        vy = object->vy - vertex->y,
3416 >        vz = object->vz - vertex->z,
3417 >        px = object->px,
3418 >        py = object->py,
3419 >        pz = object->pz,
3420 >        pt = object->pt;
3421 >      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3422 >      if(abs(value) < abs(minDz)) minDz = value;
3423 >    }
3424 >    value = minDz;
3425 >  }
3426 >  else if(variable == "distToVertex"){
3427 >    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3428 >                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3429 >                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3430 >  }
3431 >  else if (variable == "minDistToVertex"){
3432 >    double minDistToVertex=999;
3433 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3434 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3435 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3436 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
3437 >
3438 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3439 >    }
3440 >    value = minDistToVertex;
3441 >  }
3442 >  else if (variable == "distToVertexDifference"){
3443 >    double minDistToVertex=999;
3444 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3445 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3446 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3447 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
3448 >
3449 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3450 >    }
3451 >    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3452 >                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3453 >                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3454 >
3455 >    value = distToChosenVertex - minDistToVertex;
3456 >  }
3457 >
3458 >  else if (variable == "closestVertexRank"){
3459 >    double minDistToVertex=999;
3460 >    int vertex_rank = 0;
3461 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3462 >      vertex_rank++;
3463 >      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3464 >                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
3465 >                      (object->vz-vertex->z)*(object->vz-vertex->z));
3466 >
3467 >      if(abs(dist) < abs(minDistToVertex)){
3468 >        value = vertex_rank;
3469 >        minDistToVertex = dist;
3470 >      }
3471 >    }
3472 >  }
3473 >
3474 >
3475 >
3476 >
3477 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3478 >
3479 >  value = applyFunction(function, value);
3480 >
3481 >  return value;
3482 >
3483 > }
3484 >
3485 >
3486 >
3487  
3488   // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3489   // Return true iff no other tracks are found in this cone.
# Line 2611 | Line 3532 | OSUAnalysis::getTrkPtTrue (const BNtrack
3532  
3533   double
3534   OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3535 <  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.  
3536 <  if (!useTrackCaloRhoCorr_) return -99;  
3537 <  // if (!rhokt6CaloJetsHandle_) {
3538 <  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;  
3539 <  //   return -99;  
3535 >  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3536 >  if (!useTrackCaloRhoCorr_) return -99;
3537 >  // if (!rhokt6CaloJetsHandle_) {
3538 >  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3539 >  //   return -99;
3540    // }
3541 <  double radDeltaRCone = 0.5;  
3542 <  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.  
3543 <  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;  
3544 <  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);  
3545 <  return caloTotRhoCorrCalo;  
3546 <
3541 >  double radDeltaRCone = 0.5;
3542 >  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3543 >  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3544 >  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3545 >  return caloTotRhoCorrCalo;
3546 >
3547   }
3548  
3549  
# Line 2660 | Line 3581 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3581    double deltaRLowest = 999;
3582    int value = 0;
3583    if (DeadEcalVec.size() == 0) WriteDeadEcal();
3584 <  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3584 >  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3585      double eta = ecal->etaEcal;
3586      double phi = ecal->phiEcal;
3587 <    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
3587 >    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
3588      if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3589    }
3590    if (deltaRLowest<0.05) {value = 1;}
# Line 2671 | Line 3592 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3592    return value;
3593   }
3594  
3595 < // Returns the smallest DeltaR between the object and any generated true particle in the event.  
3595 > // Returns the smallest DeltaR between the object and any generated true particle in the event.
3596   template <class InputObject>
3597   double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3598    double genDeltaRLowest = 999.;
3599    for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3600      double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
3601      if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
3602 < }
3602 >  }
3603    return genDeltaRLowest;
3604   }
3605  
# Line 2691 | Line 3612 | OSUAnalysis::applyFunction(string functi
3612    else if(function == "log") value = log10(value);
3613  
3614    else if(function == "") value = value;
3615 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
3615 >  else{cout << "WARNING: invalid function '" << function << "'\n";}
3616  
3617    return value;
3618  
# Line 2701 | Line 3622 | OSUAnalysis::applyFunction(string functi
3622   template <class InputCollection>
3623   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
3624  
3625 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
3626 +    string obj1, obj2;
3627 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
3628 +    if (inputType==obj1 ||
3629 +        inputType==obj2) {
3630 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
3631 +      // and the inputType is a member of the pair.
3632 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
3633 +      // For example, if currentCut.inputCollection==electron-muon pairs,
3634 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
3635 +      return;
3636 +    }
3637 +  }
3638  
3639    for (uint object = 0; object != inputCollection->size(); object++){
3640  
2707
3641      bool decision = true;//object passes if this cut doesn't cut on that type of object
3642  
2710
3643      if(currentCut.inputCollection == inputType){
3644  
3645        vector<bool> subcutDecisions;
3646        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3647 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3648 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3647 >        string stringValue = "";
3648 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3649 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3650 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3651 >
3652        }
3653        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3654        else{
# Line 2727 | Line 3662 | void OSUAnalysis::setObjectFlags(cut &cu
3662          decision = tempDecision;
3663        }
3664      }
2730    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3665  
3666 +    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3667  
3668      //set flags for objects that pass each cut AND all the previous cuts
3669      bool previousCumulativeFlag = true;
# Line 2738 | Line 3673 | void OSUAnalysis::setObjectFlags(cut &cu
3673      }
3674      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3675  
2741
3676    }
3677  
3678   }
# Line 2752 | Line 3686 | void OSUAnalysis::setObjectFlags(cut &cu
3686    bool sameObjects = false;
3687    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3688  
3689 +  // Get the strings for the two objects that make up the pair.
3690 +  string obj1Type, obj2Type;
3691 +  getTwoObjs(inputType, obj1Type, obj2Type);
3692 +  bool isTwoTypesOfObject = true;
3693 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
3694 +
3695 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
3696 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
3697 +  if (currentCut.inputCollection == inputType) {
3698 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
3699 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3700 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3701 +    }
3702 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
3703 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
3704 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3705 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3706 +      }
3707 +    }
3708 +  }
3709  
3710    int counter = 0;
3711 +
3712    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3713      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3714  
# Line 2766 | Line 3721 | void OSUAnalysis::setObjectFlags(cut &cu
3721  
3722          vector<bool> subcutDecisions;
3723          for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3724 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3725 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3724 >          string stringValue = "";
3725 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3726 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3727 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3728          }
3729  
3730          if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
# Line 2782 | Line 3739 | void OSUAnalysis::setObjectFlags(cut &cu
3739            decision = tempDecision;
3740          }
3741        }
3742 +      // if (decision) isPassObj1.at(object1) = true;
3743 +      // if (decision) isPassObj2.at(object2) = true;
3744        individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3745 +      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3746 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;
3747 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;
3748 +      }
3749  
3750        //set flags for objects that pass each cut AND all the previous cuts
3751        bool previousCumulativeFlag = true;
# Line 2797 | Line 3760 | void OSUAnalysis::setObjectFlags(cut &cu
3760        else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
3761        else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
3762        cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
3763 <
3763 >      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3764 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);
3765 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);
3766 >      }
3767        counter++;
2802    }
3768  
3769 +    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
3770 +  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
3771 +
3772 + }
3773 +
3774 +
3775 + bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
3776 +  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
3777 +  // all cuts up to currentCutIndex
3778 +  bool previousCumulativeFlag = true;
3779 +  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
3780 +    if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
3781 +    else {
3782 +      previousCumulativeFlag = false; break;
3783 +    }
3784    }
3785 +  return previousCumulativeFlag;
3786 + }
3787 +
3788  
3789  
3790 + template <class InputCollection>
3791 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, vector<bool> flags){
3792 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree  
3793 +
3794 +  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;  
3795 +  for (uint object = 0; object != inputCollection->size(); object++) {  
3796 +
3797 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;  
3798 +
3799 +    string inputVariable = parameters.inputVariable;
3800 +    string function = "";
3801 +    string stringValue = "";  
3802 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);  
3803 +    BNTreeBranchVals_.at(parameters.name).push_back(value);  
3804 +
3805 +  }
3806   }
3807  
3808  
# Line 2817 | Line 3816 | void OSUAnalysis::fill1DHistogram(TH1* h
3816      string currentString = parameters.inputVariables.at(0);
3817      string inputVariable = "";
3818      string function = "";
3819 <    if(currentString.find("(")==std::string::npos){
3819 >    if(currentString.find("(")==string::npos){
3820        inputVariable = currentString;// variable to cut on
3821      }
3822      else{
3823        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3824        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3825        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3826 <    }
3826 >    }  
3827  
3828 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
3829 <    histo->Fill(value,scaleFactor);
3828 >    string stringValue = "";  
3829 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);  
3830 >    histo->Fill(value,scaleFactor);  
3831  
3832      if (printEventInfo_) {
3833 <      // Write information about event to screen, for testing purposes.  
3834 <      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;  
3833 >      // Write information about event to screen, for testing purposes.
3834 >      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
3835      }
3836 <    
3836 >
3837    }
3838   }
3839  
# Line 2843 | Line 3843 | void OSUAnalysis::fill1DHistogram(TH1* h
3843    bool sameObjects = false;
3844    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3845  
3846 <  int pairCounter = 0;
3846 >  int pairCounter = -1;
3847    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3848      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3849  
3850        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3851  
3852 +      pairCounter++;
3853        //only take objects which have passed all cuts and pairs which have passed all cuts
3854        if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3855        if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
# Line 2857 | Line 3858 | void OSUAnalysis::fill1DHistogram(TH1* h
3858        string currentString = parameters.inputVariables.at(0);
3859        string inputVariable = "";
3860        string function = "";
3861 <      if(currentString.find("(")==std::string::npos){
3861 >      if(currentString.find("(")==string::npos){
3862          inputVariable = currentString;// variable to cut on
3863        }
3864        else{
# Line 2866 | Line 3867 | void OSUAnalysis::fill1DHistogram(TH1* h
3867          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3868        }
3869  
3870 <      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3870 >      string stringValue = "";
3871 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3872        histo->Fill(value,scaleFactor);
3873  
2872      pairCounter++;
3874      }
3875    }
3876  
# Line 2883 | Line 3884 | void OSUAnalysis::fill2DHistogram(TH2* h
3884  
3885      if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3886  
3887 +    string stringValue = "";
3888      string currentString = parameters.inputVariables.at(0);
3889      string inputVariable = "";
3890      string function = "";
3891 <    if(currentString.find("(")==std::string::npos){
3891 >    if(currentString.find("(")==string::npos){
3892        inputVariable = currentString;// variable to cut on
3893      }
3894      else{
# Line 2894 | Line 3896 | void OSUAnalysis::fill2DHistogram(TH2* h
3896        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3897        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3898      }
3899 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
3899 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3900  
3901      currentString = parameters.inputVariables.at(1);
3902      inputVariable = "";
3903      function = "";
3904 <    if(currentString.find("(")==std::string::npos){
3904 >    if(currentString.find("(")==string::npos){
3905        inputVariable = currentString;// variable to cut on
3906      }
3907      else{
# Line 2908 | Line 3910 | void OSUAnalysis::fill2DHistogram(TH2* h
3910        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3911      }
3912  
3913 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
3913 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3914  
3915      histo->Fill(valueX,valueY,scaleFactor);
3916  
# Line 2922 | Line 3924 | void OSUAnalysis::fill2DHistogram(TH2* h
3924    bool sameObjects = false;
3925    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3926  
3927 <  int pairCounter = 0;
3927 >  int pairCounter = -1;
3928    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3929      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3930  
3931        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3932  
3933 +      pairCounter++;
3934 +
3935        //only take objects which have passed all cuts and pairs which have passed all cuts
3936        if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3937        if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3938        if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3939  
3940 +      string stringValue = "";
3941        string currentString = parameters.inputVariables.at(0);
3942        string inputVariable = "";
3943        string function = "";
3944 <      if(currentString.find("(")==std::string::npos){
3944 >      if(currentString.find("(")==string::npos){
3945          inputVariable = currentString;// variable to cut on
3946        }
3947        else{
# Line 2944 | Line 3949 | void OSUAnalysis::fill2DHistogram(TH2* h
3949          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3950          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3951        }
3952 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3952 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3953  
3954        currentString = parameters.inputVariables.at(1);
3955        inputVariable = "";
3956        function = "";
3957 <      if(currentString.find("(")==std::string::npos){
3957 >      if(currentString.find("(")==string::npos){
3958          inputVariable = currentString;// variable to cut on
3959        }
3960        else{
# Line 2957 | Line 3962 | void OSUAnalysis::fill2DHistogram(TH2* h
3962          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3963          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3964        }
3965 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3965 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3966  
3967  
3968        histo->Fill(valueX,valueY,scaleFactor);
3969  
2965      pairCounter++;
2966
3970      }
3971    }
3972  
# Line 2980 | Line 3983 | int OSUAnalysis::getGenMatchedParticleIn
3983  
3984      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
3985      if(currentDeltaR > 0.05) continue;
3986 < //     cout << std::setprecision(3) << std::setw(20)
3987 < //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
3988 < //          << std::setw(20)
3989 < //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
3990 < //          << std::setw(20)
3991 < //          << "\tdeltaR = " << currentDeltaR
3992 < //          << std::setprecision(1)
3993 < //          << std::setw(20)
3994 < //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
3995 < //          << std::setw(20)
3996 < //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
3997 < //          << std::setw(20)
3998 < //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
3986 >    //     cout << setprecision(3) << setw(20)
3987 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
3988 >    //          << setw(20)
3989 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
3990 >    //          << setw(20)
3991 >    //          << "\tdeltaR = " << currentDeltaR
3992 >    //          << setprecision(1)
3993 >    //          << setw(20)
3994 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
3995 >    //          << setw(20)
3996 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
3997 >    //          << setw(20)
3998 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
3999      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4000        bestMatchIndex = mcparticle - mcparticles->begin();
4001        bestMatchDeltaR = currentDeltaR;
4002      }
4003  
4004    }
4005 < //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4006 < //   else cout << "no match found..." << endl;
4005 >  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4006 >  //   else cout << "no match found..." << endl;
4007    return bestMatchIndex;
4008  
4009   }
# Line 3054 | Line 4057 | int OSUAnalysis::findTauMotherIndex(cons
4057   // 20        strange baryon
4058   // 21        charm baryon
4059   // 22        bottom baryon
4060 < // 23        other
4060 > // 23        QCD string
4061 > // 24        other
4062  
4063   int OSUAnalysis::getPdgIdBinValue(int pdgId){
4064  
# Line 3078 | Line 4082 | int OSUAnalysis::getPdgIdBinValue(int pd
4082    else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4083    else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4084    else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4085 +  else if(absPdgId == 92  ) binValue = 23;
4086  
4087 <  else binValue = 23;
4087 >  else binValue = 24;
4088  
4089    return binValue;
4090  
# Line 3089 | Line 4094 | const BNprimaryvertex *
4094   OSUAnalysis::chosenVertex ()
4095   {
4096    const BNprimaryvertex *chosenVertex = 0;
4097 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
4098 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
4099 <                               cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
4097 >  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4098 >    vector<bool> vertexFlags;
4099 >    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4100 >      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4101 >        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4102 >        break;
4103 >      }
4104 >    }
4105      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4106        if(!vertexFlags.at(vertexIndex)) continue;
4107        chosenVertex = & primaryvertexs->at(vertexIndex);
4108        break;
4109      }
4110    }
4111 <  else {
4112 <    chosenVertex = &primaryvertexs->at(0);
3103 <  }
4111 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4112 >    chosenVertex = & primaryvertexs->at (0);
4113  
4114    return chosenVertex;
4115   }
# Line 3109 | Line 4118 | const BNmet *
4118   OSUAnalysis::chosenMET ()
4119   {
4120    const BNmet *chosenMET = 0;
4121 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
4122 <    vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
4123 <                            cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
4121 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4122 >    vector<bool> metFlags;
4123 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4124 >      if (cumulativeFlags.at("mets").at(i).size()){
4125 >        metFlags = cumulativeFlags.at("mets").at(i);
4126 >        break;
4127 >      }
4128 >    }
4129      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4130        if(!metFlags.at(metIndex)) continue;
4131        chosenMET = & mets->at(metIndex);
4132        break;
4133      }
4134    }
4135 <  else {
4136 <    chosenMET = &mets->at(0);
3123 <  }
4135 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4136 >    chosenMET = & mets->at (0);
4137  
4138    return chosenMET;
4139   }
# Line 3129 | Line 4142 | const BNelectron *
4142   OSUAnalysis::chosenElectron ()
4143   {
4144    const BNelectron *chosenElectron = 0;
4145 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
4146 <    vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
4147 <                                 cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
4145 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4146 >    vector<bool> electronFlags;
4147 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4148 >      if (cumulativeFlags.at("electrons").at(i).size()){
4149 >        electronFlags = cumulativeFlags.at("electrons").at(i);
4150 >        break;
4151 >      }
4152 >    }
4153      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4154        if(!electronFlags.at(electronIndex)) continue;
4155        chosenElectron = & electrons->at(electronIndex);
4156        break;
4157      }
4158    }
4159 <  else {
4160 <    chosenElectron = &electrons->at(0);
3143 <  }
4159 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4160 >    chosenElectron = & electrons->at (0);
4161  
4162    return chosenElectron;
4163   }
# Line 3149 | Line 4166 | const BNmuon *
4166   OSUAnalysis::chosenMuon ()
4167   {
4168    const BNmuon *chosenMuon = 0;
4169 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
4170 <    vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
4171 <                             cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
4169 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4170 >    vector<bool> muonFlags;
4171 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4172 >      if (cumulativeFlags.at("muons").at(i).size()){
4173 >        muonFlags = cumulativeFlags.at("muons").at(i);
4174 >        break;
4175 >      }
4176 >    }
4177      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4178        if(!muonFlags.at(muonIndex)) continue;
4179        chosenMuon = & muons->at(muonIndex);
4180        break;
4181      }
4182    }
4183 <  else {
4184 <    chosenMuon = &muons->at(0);
3163 <  }
4183 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4184 >    chosenMuon = & muons->at (0);
4185  
4186    return chosenMuon;
4187   }
4188  
3168
4189   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines