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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines