ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
(Generate patch)

Comparing UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc (file contents):
Revision 1.49 by wulsin, Wed Apr 17 15:39:43 2013 UTC vs.
Revision 1.76 by wulsin, Fri May 31 09:42:10 2013 UTC

# Line 17 | Line 17 | OSUAnalysis::OSUAnalysis (const edm::Par
17    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
18    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
19    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
20 <  puFile_ (cfg.getParameter<std::string> ("puFile")),
21 <  deadEcalFile_ (cfg.getParameter<std::string> ("deadEcalFile")),
22 <  muonSFFile_ (cfg.getParameter<std::string> ("muonSFFile")),
23 <  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
24 <  electronSFID_ (cfg.getParameter<std::string> ("electronSFID")),
25 <  muonSF_ (cfg.getParameter<std::string> ("muonSF")),
26 <  dataset_ (cfg.getParameter<std::string> ("dataset")),
27 <  datasetType_ (cfg.getParameter<std::string> ("datasetType")),
20 >  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
21 >  puFile_ (cfg.getParameter<string> ("puFile")),
22 >  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
23 >  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
24 >  dataPU_ (cfg.getParameter<string> ("dataPU")),
25 >  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
26 >  muonSF_ (cfg.getParameter<string> ("muonSF")),
27 >  dataset_ (cfg.getParameter<string> ("dataset")),
28 >  datasetType_ (cfg.getParameter<string> ("datasetType")),
29    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
30    histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
31 +  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")),
34 >  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
35 >  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
36    useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
37 <  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau"))
38 <
37 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
38 >  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
39   {
40  
41    TH1::SetDefaultSumw2 ();
# Line 40 | Line 43 | OSUAnalysis::OSUAnalysis (const edm::Par
43    //create pile-up reweighting object, if necessary
44    if(datasetType_ != "data") {
45      if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
46 <    //    muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
47 <    //    electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
46 >    if (applyLeptonSF_){
47 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
48 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
49 >    }
50    }
51 < #ifdef DISPLACED_SUSY
52 <  if (datasetType_ == "signalMC")
48 <    cTauWeight_ = new CTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
49 < #endif
51 >  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
52 >    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
53  
54  
55    // Construct Cutflow Objects. These store the results of cut decisions and
56    // handle filling cut flow histograms.
57    masterCutFlow_ = new CutFlow (fs_);
55  std::vector<TFileDirectory> directories;
58  
59    //always get vertex collection so we can assign the primary vertex in the event
60    objectsToGet.push_back("primaryvertexs");
59
60  //always make the plot of number of primary vertices (to check pile-up reweighting)
61    objectsToPlot.push_back("primaryvertexs");
62 +  objectsToCut.push_back("primaryvertexs");
63 +
64  
65    //always get the MC particles to do GEN-matching
66    objectsToGet.push_back("mcparticles");
# Line 66 | Line 68 | OSUAnalysis::OSUAnalysis (const edm::Par
68    //always get the event collection to do pile-up reweighting
69    objectsToGet.push_back("events");
70  
71 +
72 +  // Parse the tree variable definitions.    
73 +  for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++) {
74 +    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
75 +    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; }  
76 +    objectsToGet.push_back(tempInputCollection);
77 +    objectsToCut.push_back(tempInputCollection);
78 +
79 +    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
80 +
81 +    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
82 +      BranchSpecs br;
83 +      br.inputCollection = tempInputCollection;
84 +      br.inputVariable = branchList.at(iBranch);  
85 +      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);  
86 +      br.name = string(newName.Data());  
87 +      treeBranches_.push_back(br);
88 +    }  
89 +
90 +  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++) {
91 +
92 +
93    //parse the histogram definitions
94    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
95  
96      string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
97      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
98 +    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
99 +    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
100      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
101      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
102 <    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
103 <      if(tempInputCollection.find("secondary")!=std::string::npos){//secondary object
104 <        int spaceIndex = tempInputCollection.find(" ");
105 <        int secondWordLength = tempInputCollection.size() - spaceIndex;
106 <        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
102 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
103 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
104 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
105 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
106 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
107 >        int spaceIndex = tempInputCollection.find(" ");
108 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
109 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
110        }
111        else{
112 <        objectsToGet.push_back(tempInputCollection);
112 >        objectsToGet.push_back(tempInputCollection);
113        }
114        objectsToPlot.push_back(tempInputCollection);
115        objectsToCut.push_back(tempInputCollection);
116 <    }
117 <    else{//pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
89 <      string obj1;
116 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
117 >      string obj1;
118        string obj2;
119        getTwoObjs(tempInputCollection, obj1, obj2);
120 <      string obj2ToGet = getObjToGet(obj2);  
120 >      string obj2ToGet = getObjToGet(obj2);
121        objectsToCut.push_back(tempInputCollection);
122        objectsToCut.push_back(obj1);
123 <      objectsToCut.push_back(obj2);  
123 >      objectsToCut.push_back(obj2);
124        objectsToPlot.push_back(tempInputCollection);
125        objectsToPlot.push_back(obj1);
126 <      objectsToPlot.push_back(obj2);  
126 >      objectsToPlot.push_back(obj2);
127        objectsToGet.push_back(tempInputCollection);
128        objectsToGet.push_back(obj1);
129        objectsToGet.push_back(obj2ToGet);
130 +    } // end else
131 +
132  
103    }
133  
134      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
135  
136      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
137  
138 +      vector<double> defaultValue;
139 +      defaultValue.push_back (-1.0);
140 +
141        histogram tempHistogram;
142        tempHistogram.inputCollection = tempInputCollection;
143        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
144        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
145 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
145 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
146 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
147 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
148        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
149  
150        histograms.push_back(tempHistogram);
151  
152      }
153 <  }
153 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
154 >
155    //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
156    sort( objectsToPlot.begin(), objectsToPlot.end() );
157    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
# Line 127 | Line 162 | OSUAnalysis::OSUAnalysis (const edm::Par
162    for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
163  
164      string currentObject = objectsToPlot.at(currentObjectIndex);
165 <    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
165 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
166  
167      histogram tempIdHisto;
168      histogram tempMomIdHisto;
169      histogram tempGmaIdHisto;
170      histogram tempIdVsMomIdHisto;
171 +    histogram tempIdVsGmaIdHisto;
172  
173      tempIdHisto.inputCollection = currentObject;
174      tempMomIdHisto.inputCollection = currentObject;
175      tempGmaIdHisto.inputCollection = currentObject;
176      tempIdVsMomIdHisto.inputCollection = currentObject;
177 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
178  
179      if(currentObject == "secondary muons") currentObject = "secondaryMuons";
180 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
181  
182      currentObject = currentObject.substr(0, currentObject.size()-1);
183      tempIdHisto.name = currentObject+"GenMatchId";
184      tempMomIdHisto.name = currentObject+"GenMatchMotherId";
185      tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
186      tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
187 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
188  
189      currentObject.at(0) = toupper(currentObject.at(0));
190      tempIdHisto.title = currentObject+" Gen-matched Particle";
191      tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
192      tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
193      tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
194 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
195  
196 <    int maxNum = 24;
196 >
197 >    int maxNum = 25;
198      vector<double> binVector;
199      binVector.push_back(maxNum);
200      binVector.push_back(0);
# Line 171 | Line 212 | OSUAnalysis::OSUAnalysis (const edm::Par
212      tempIdVsMomIdHisto.bins = binVector;
213      tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
214      tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
215 +    tempIdVsGmaIdHisto.bins = binVector;
216 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
217 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
218  
219      histograms.push_back(tempIdHisto);
220      histograms.push_back(tempMomIdHisto);
221      histograms.push_back(tempGmaIdHisto);
222      histograms.push_back(tempIdVsMomIdHisto);
223 +    histograms.push_back(tempIdVsGmaIdHisto);
224    }
225  
226  
# Line 191 | Line 236 | OSUAnalysis::OSUAnalysis (const edm::Par
236      //set triggers for this channel
237      vector<string> triggerNames;
238      triggerNames.clear();
239 +    vector<string> triggerToVetoNames;
240 +    triggerToVetoNames.clear();
241 +
242      tempChannel.triggers.clear();
243 +    tempChannel.triggersToVeto.clear();
244      if(channels_.at(currentChannel).exists("triggers")){
245        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
246        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
247          tempChannel.triggers.push_back(triggerNames.at(trigger));
248        objectsToGet.push_back("triggers");
249      }
250 <
250 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
251 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
252 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
253 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
254 >      objectsToGet.push_back("triggers");
255 >    }
256  
257  
258  
259      //create cutFlow for this channel
260      cutFlows_.push_back (new CutFlow (fs_, channelName));
261 <
262 <    //book a directory in the output file with the name of the channel
209 <    TFileDirectory subDir = fs_->mkdir( channelName );
210 <    directories.push_back(subDir);
211 <
212 <    std::map<std::string, TH1D*> oneDhistoMap;
213 <    oneDHists_.push_back(oneDhistoMap);
214 <    std::map<std::string, TH2D*> twoDhistoMap;
215 <    twoDHists_.push_back(twoDhistoMap);
216 <
217 <
218 <
219 <    //book all histograms included in the configuration
220 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
221 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
222 <      int numBinsElements = currentHistogram.bins.size();
223 <      int numInputVariables = currentHistogram.inputVariables.size();
224 <
225 <      if(numBinsElements != 3 && numBinsElements !=6) {
226 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
227 <        exit(0);
228 <      }
229 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
230 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
231 <        exit(0);
232 <      }
233 <      else if(numBinsElements == 3){
234 <        oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
235 <      }
236 <      else if(numBinsElements == 6){
237 <        twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2),currentHistogram.bins.at(3),currentHistogram.bins.at(4),currentHistogram.bins.at(5));
238 <
239 <      }
240 <
241 <
242 <      if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
243 <
244 <      // bin      particle type
245 <      // ---      -------------
246 <      //  0        unmatched
247 <      //  1        u
248 <      //  2        d
249 <      //  3        s
250 <      //  4        c
251 <      //  5        b
252 <      //  6        t
253 <      //  7        e
254 <      //  8        mu
255 <      //  9        tau
256 <      // 10        nu
257 <      // 11        g
258 <      // 12        gamma
259 <      // 13        Z
260 <      // 14        W
261 <      // 15        light meson
262 <      // 16        K meson
263 <      // 17        D meson
264 <      // 18        B meson
265 <      // 19        light baryon
266 <      // 20        strange baryon
267 <      // 21        charm baryon
268 <      // 22        bottom baryon
269 <      // 23        other
270 <
271 <      vector<TString> labelArray;
272 <      labelArray.push_back("unmatched");
273 <      labelArray.push_back("u");
274 <      labelArray.push_back("d");
275 <      labelArray.push_back("s");
276 <      labelArray.push_back("c");
277 <      labelArray.push_back("b");
278 <      labelArray.push_back("t");
279 <      labelArray.push_back("e");
280 <      labelArray.push_back("#mu");
281 <      labelArray.push_back("#tau");
282 <      labelArray.push_back("#nu");
283 <      labelArray.push_back("g");
284 <      labelArray.push_back("#gamma");
285 <      labelArray.push_back("Z");
286 <      labelArray.push_back("W");
287 <      labelArray.push_back("light meson");
288 <      labelArray.push_back("K meson");
289 <      labelArray.push_back("D meson");
290 <      labelArray.push_back("B meson");
291 <      labelArray.push_back("light baryon");
292 <      labelArray.push_back("strange baryon");
293 <      labelArray.push_back("charm baryon");
294 <      labelArray.push_back("bottom baryon");
295 <      labelArray.push_back("other");
296 <
297 <      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
298 <        if(currentHistogram.name.find("GenMatchIdVsMotherId")==std::string::npos) {
299 <          oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
300 <        }
301 <        else {
302 <          twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
303 <          twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
304 <        }
305 <      }
306 <      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=std::string::npos) {
307 <        twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->CenterTitle();
308 <        twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->CenterTitle();
309 <      }
310 <
311 <    }
312 <
313 <    // Book a histogram for the number of each object type to be plotted.  
314 <    // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().  
315 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
316 <      string currentObject = objectsToPlot.at(currentObjectIndex);
317 <      int maxNum = 10;
318 <      if(currentObject == "mcparticles") maxNum = 50;
319 <      else if(currentObject == "primaryvertexs") maxNum = 50;
320 <
321 <      if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
322 <      else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
323 <      else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
324 <      else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
325 <      else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";        
326 <      else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";    
327 <      else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";      
328 <      else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
329 <      else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
330 <      else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
331 <      else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
332 <
333 <      currentObject.at(0) = toupper(currentObject.at(0));  
334 <      string histoName = "num" + currentObject;
335 <
336 <      if(histoName == "numPrimaryvertexs"){
337 <        string newHistoName = histoName + "BeforePileupCorrection";
338 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
339 <        newHistoName = histoName + "AfterPileupCorrection";
340 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
341 <      }
342 <      else
343 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
344 <    }
345 <
346 <
347 <
348 <
261 >    vector<TFileDirectory> directories; //vector of directories in the output file.
262 >    vector<string> subSubDirNames;//subdirectories in each channel.
263      //get list of cuts for this channel
264      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
265  
266 +
267      //loop over and parse all cuts
268      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
269        cut tempCut;
270        //store input collection for cut
271        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
272        if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
273 +      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
274 +      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
275        if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
276        if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
277 +      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
278 +      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
279 +      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
280        tempCut.inputCollection = tempInputCollection;
281 <      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
282 <        if(tempInputCollection.find("secondary")!=std::string::npos){//secondary object
283 <          int spaceIndex = tempInputCollection.find(" ");
284 <          int secondWordLength = tempInputCollection.size() - spaceIndex;
285 <          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
286 <        }
287 <        else{
288 <          objectsToGet.push_back(tempInputCollection);
289 <        }
290 <        objectsToCut.push_back(tempInputCollection);
281 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
282 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
283 >          int spaceIndex = tempInputCollection.find(" ");
284 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
285 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
286 >        }
287 >        else{
288 >          objectsToGet.push_back(tempInputCollection);
289 >        }
290 >        objectsToCut.push_back(tempInputCollection);
291        }
292        else{//pair of objects, need to add them both to objectsToGet
293 <        string obj1;
294 <        string obj2;
295 <        getTwoObjs(tempInputCollection, obj1, obj2);
296 <        string obj2ToGet = getObjToGet(obj2);  
293 >        string obj1;
294 >        string obj2;
295 >        getTwoObjs(tempInputCollection, obj1, obj2);
296 >        string obj2ToGet = getObjToGet(obj2);
297          objectsToCut.push_back(tempInputCollection);
298          objectsToCut.push_back(obj1);
299 <        objectsToCut.push_back(obj2);  
299 >        objectsToCut.push_back(obj2);
300          objectsToGet.push_back(tempInputCollection);
301          objectsToGet.push_back(obj1);
302          objectsToGet.push_back(obj2ToGet);
# Line 387 | Line 307 | OSUAnalysis::OSUAnalysis (const edm::Par
307  
308        //split cut string into parts and store them
309        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
310 <      std::vector<string> cutStringVector = splitString(cutString);
310 >      vector<string> cutStringVector = splitString(cutString);
311        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
312 <        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
312 >        cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
313          exit(0);
314        }
315        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
316        for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
317          int indexOffset = 4 * subcutIndex;
318          string currentVariableString = cutStringVector.at(indexOffset);
319 <        if(currentVariableString.find("(")==std::string::npos){
319 >        if(currentVariableString.find("(")==string::npos){
320            tempCut.functions.push_back("");//no function was specified
321            tempCut.variables.push_back(currentVariableString);// variable to cut on
322          }
# Line 407 | Line 327 | OSUAnalysis::OSUAnalysis (const edm::Par
327          }
328          tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
329          tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
330 +        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
331          if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
332        }
333  
334        //get number of objects required to pass cut for event to pass
335        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
336 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
336 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
337        if(numberRequiredVector.size()!=2){
338 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
338 >        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
339          exit(0);
340        }
341  
# Line 422 | Line 343 | OSUAnalysis::OSUAnalysis (const edm::Par
343        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
344        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
345  
346 <
346 >      //Set up vectors to store the directories and subDIrectories for each channel.
347 >      string subSubDirName;
348        string tempCutName;
349        if(cuts_.at(currentCut).exists("alias")){
350          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
351 +        subSubDirName = "After " + cuts_.at(currentCut).getParameter<string> ("alias") + " Cut Applied";
352        }
353        else{
354          //construct string for cutflow table
# Line 433 | Line 356 | OSUAnalysis::OSUAnalysis (const edm::Par
356          string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
357          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
358          tempCutName = cutName;
359 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
360        }
361 +
362 +      subSubDirNames.push_back(subSubDirName);
363        tempCut.name = tempCutName;
364  
365        tempChannel.cuts.push_back(tempCut);
# Line 441 | Line 367 | OSUAnalysis::OSUAnalysis (const edm::Par
367  
368      }//end loop over cuts
369  
370 +    vector<map<string, TH1D*>> oneDHistsTmp;
371 +    vector<map<string, TH2D*>> twoDHistsTmp;
372 +    //book a directory in the output file with the name of the channel
373 +    TFileDirectory subDir = fs_->mkdir( channelName );
374 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
375 +    if(GetPlotsAfterEachCut_){
376 +      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
377 +        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
378 +        directories.push_back(subSubDir);
379 +        map<string, TH1D*> oneDhistoMap;
380 +        oneDHistsTmp.push_back(oneDhistoMap);
381 +        map<string, TH2D*> twoDhistoMap;
382 +        twoDHistsTmp.push_back(twoDhistoMap);
383 +      }
384 +      oneDHists_.push_back(oneDHistsTmp);
385 +      twoDHists_.push_back(twoDHistsTmp);
386 +    }
387 +    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
388 +    else{
389 +      map<string, TH1D*> oneDhistoMap;
390 +      oneDHistsTmp.push_back(oneDhistoMap);
391 +      map<string, TH2D*> twoDhistoMap;
392 +      twoDHistsTmp.push_back(twoDhistoMap);
393 +      oneDHists_.push_back(oneDHistsTmp);
394 +      twoDHists_.push_back(twoDHistsTmp);
395 +      directories.push_back(subDir);
396 +
397 +    }
398 +
399 +
400 +    //book all histograms included in the configuration
401 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
402 +
403 +      TTree* newTree = directories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));  
404 +      BNTrees_.push_back(newTree);  
405 +      
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 +
412 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
413 +
414 +
415 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
416 +
417 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
418 +        int numBinsElements = currentHistogram.bins.size();
419 +        int numInputVariables = currentHistogram.inputVariables.size();
420 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
421 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
422 +        
423 +        if(numBinsElements == 1){
424 +          if(numBinEdgesX > 1){
425 +            if(numBinEdgesY > 1)
426 +              numBinsElements = 6;
427 +            else
428 +              numBinsElements = 3;
429 +          }
430 +        }
431 +        if(numBinsElements != 3 && numBinsElements !=6){
432 +          cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
433 +          exit(0);
434 +        }
435 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
436 +          cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
437 +          exit(0);
438 +        }
439 +        else if(numBinsElements == 3){
440 +          if (currentHistogram.bins.size () == 3)
441 +            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));
442 +          else
443 +            {
444 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
445 +            }
446 +        }
447 +        else if(numBinsElements == 6){
448 +          if (currentHistogram.bins.size () == 6)
449 +            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));
450 +          else
451 +            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 ());
452 +        }
453 +
454 +
455 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
456 +
457 +        // bin      particle type
458 +        // ---      -------------
459 +        //  0        unmatched
460 +        //  1        u
461 +        //  2        d
462 +        //  3        s
463 +        //  4        c
464 +        //  5        b
465 +        //  6        t
466 +        //  7        e
467 +        //  8        mu
468 +        //  9        tau
469 +        // 10        nu
470 +        // 11        g
471 +        // 12        gamma
472 +        // 13        Z
473 +        // 14        W
474 +        // 15        light meson
475 +        // 16        K meson
476 +        // 17        D meson
477 +        // 18        B meson
478 +        // 19        light baryon
479 +        // 20        strange baryon
480 +        // 21        charm baryon
481 +        // 22        bottom baryon
482 +        // 23        QCD string
483 +        // 24        other
484 +
485 +        vector<TString> labelArray;
486 +        labelArray.push_back("unmatched");
487 +        labelArray.push_back("u");
488 +        labelArray.push_back("d");
489 +        labelArray.push_back("s");
490 +        labelArray.push_back("c");
491 +        labelArray.push_back("b");
492 +        labelArray.push_back("t");
493 +        labelArray.push_back("e");
494 +        labelArray.push_back("#mu");
495 +        labelArray.push_back("#tau");
496 +        labelArray.push_back("#nu");
497 +        labelArray.push_back("g");
498 +        labelArray.push_back("#gamma");
499 +        labelArray.push_back("Z");
500 +        labelArray.push_back("W");
501 +        labelArray.push_back("light meson");
502 +        labelArray.push_back("K meson");
503 +        labelArray.push_back("D meson");
504 +        labelArray.push_back("B meson");
505 +        labelArray.push_back("light baryon");
506 +        labelArray.push_back("strange baryon");
507 +        labelArray.push_back("charm baryon");
508 +        labelArray.push_back("bottom baryon");
509 +        labelArray.push_back("QCD string");
510 +        labelArray.push_back("other");
511 +
512 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
513 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
514 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
515 +          }
516 +          else {
517 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
518 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
519 +          }
520 +        }
521 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
522 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
523 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
524 +        }
525 +
526 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
527 +
528 +
529 +      // Book a histogram for the number of each object type to be plotted.
530 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
531 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
532 +        string currentObject = objectsToPlot.at(currentObjectIndex);
533 +        int maxNum = 10;
534 +        if(currentObject == "mcparticles") maxNum = 50;
535 +        else if(currentObject == "primaryvertexs") maxNum = 50;
536 +
537 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
538 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
539 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
540 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
541 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
542 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
543 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
544 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
545 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
546 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
547 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
548 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
549 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
550 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
551 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
552 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
553 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
554 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
555 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
556 +
557 +        currentObject.at(0) = toupper(currentObject.at(0));
558 +        string histoName = "num" + currentObject;
559 +
560 +        if(histoName == "numPrimaryvertexs"){
561 +          string newHistoName = histoName + "BeforePileupCorrection";
562 +          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);
563 +          newHistoName = histoName + "AfterPileupCorrection";
564 +          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);
565 +        }
566 +        else
567 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
568 +      }
569 +    }//end of loop over directories
570      channels.push_back(tempChannel);
571      tempChannel.cuts.clear();
446
572    }//end loop over channels
573  
574  
# Line 472 | 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);
664 <
665 <  cTauScaleFactor_ = 1.0;
666 < #ifdef DISPLACED_SUSY
667 <  if (datasetType_ == "signalMC")
668 <    cTauScaleFactor_ = cTauWeight_->at (event);
669 < #endif
670 <  scaleFactor *= cTauScaleFactor_;
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 544 | 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 +
687      bool triggerDecision = true;
688 <    if(currentChannel.triggers.size() != 0){  //triggers specified
689 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
688 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
689 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
690        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
691      }
692  
693      //loop over all cuts
554
555
556
694      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
695        cut currentCut = currentChannel.cuts.at(currentCutIndex);
559
696        for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
697          string currentObject = objectsToCut.at(currentObjectIndex);
698  
# Line 571 | Line 707 | OSUAnalysis::analyze (const edm::Event &
707          int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
708  
709  
710 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
711 <
712 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
577 <
710 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
711 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
712 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
713          else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
714 +        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
715          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
716          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
717          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 587 | Line 723 | OSUAnalysis::analyze (const edm::Event &
723          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
724          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
725          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
726 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
727 +
728  
729  
730          else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
# Line 595 | Line 733 | OSUAnalysis::analyze (const edm::Event &
733                                                                     "muon-muon pairs");
734  
735          else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
736 <                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
737 <                                                                   cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
738 <                                                                   "muon-secondary muon pairs");
736 >                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
737 >                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
738 >                                                                             "muon-secondary muon pairs");
739 >
740 >        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
741 >                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
742 >                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
743 >                                                                                     "electron-secondary electron pairs");
744  
745          else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
746                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
# Line 607 | Line 750 | OSUAnalysis::analyze (const edm::Event &
750                                                                         cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
751                                                                         cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
752                                                                         "electron-muon pairs");
753 <        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
754 <                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
755 <                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
756 <                                                                     "track-event pairs");
757 <        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
758 <                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
759 <                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
760 <                                                                        "electron-track pairs");
761 <        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
762 <                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
763 <                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
764 <                                                                    "muon-track pairs");
765 <        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
766 <                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
767 <                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
768 <                                                                  "muon-tau pairs");
769 <        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
770 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
771 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
772 <                                                                 "tau-tau pairs");
773 <        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
753 >        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
754 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
755 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
756 >                                                                 "jet-jet pairs");
757 >        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
758 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
759 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
760 >                                                                      "electron-jet pairs");
761 >        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
762 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
763 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
764 >                                                                  "muon-jet pairs");
765 >        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
766 >                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
767 >                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
768 >                                                                     "track-event pairs");
769 >        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
770 >                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
771 >                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
772 >                                                                        "electron-track pairs");
773 >        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
774 >                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
775 >                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
776 >                                                                    "muon-track pairs");
777 >        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
778 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
779 >                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
780 >                                                                  "muon-tau pairs");
781 >        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
782                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
783 <                                                                 cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
784 <                                                                 "tau-track pairs");
785 <        
786 <        
783 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
784 >                                                                 "tau-tau pairs");
785 >        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
786 >                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
787 >                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
788 >                                                                   "tau-track pairs");
789 >        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
790 >                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
791 >                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
792 >                                                                          "electron-trigobj pairs");
793 >        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
794 >                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
795 >                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
796 >                                                                      "muon-trigobj pairs");
797 >
798 >        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
799        }
800  
801  
802  
803      }//end loop over all cuts
641
642
804      //use cumulative flags to apply cuts at event level
805  
806      bool eventPassedAllCuts = true;
807 <
807 >    //a vector to store cumulative cut descisions after each cut.
808 >    vector<bool> eventPassedPreviousCuts;
809      //apply trigger (true if none were specified)
810      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
811  
650
812      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
813  
814        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 655 | Line 816 | OSUAnalysis::analyze (const edm::Event &
816        int numberPassing = 0;
817  
818        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
819 <        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
819 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
820        }
821        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
822        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
823        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
824 <
824 >      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
825      }
826 +    double scaleFactor = masterScaleFactor;
827  
828 <    //     if(datasetType_ != "data") {
829 <    //       scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
830 <    //       scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
831 <    //     }
828 >    muonScaleFactor_ = electronScaleFactor_ = 1.0;
829 >    if(applyLeptonSF_ && datasetType_ != "data"){
830 >      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
831 >        vector<bool> muonFlags;
832 >        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
833 >          if (cumulativeFlags.at("muons").at(i).size()){
834 >            muonFlags = cumulativeFlags.at("muons").at(i);
835 >            break;
836 >          }
837 >        }
838 >        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
839 >          if(!muonFlags.at(muonIndex)) continue;
840 >          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
841 >        }
842 >      }
843 >      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
844 >        vector<bool> electronFlags;
845 >        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
846 >          if (cumulativeFlags.at("electrons").at(i).size()){
847 >            electronFlags = cumulativeFlags.at("electrons").at(i);
848 >            break;
849 >          }
850 >        }
851 >        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
852 >          if(!electronFlags.at(electronIndex)) continue;
853 >          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
854 >        }
855 >      }
856 >    }
857 >    scaleFactor *= muonScaleFactor_;
858 >    scaleFactor *= electronScaleFactor_;
859  
860      cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
861  
673
674
675    if(!eventPassedAllCuts)continue;
676
862      if (printEventInfo_) {
863 <      // Write information about event to screen, for testing purposes.  
864 <      cout << "Event passed all cuts in channel " <<  currentChannel.name
865 <           << ": run="  << events->at(0).run
866 <           << "  lumi=" << events->at(0).lumi
867 <           << "  event=" << events->at(0).evt
868 <           << endl;  
863 >      // Write information about event to screen, for testing purposes.
864 >      cout << "Event passed all cuts in channel " <<  currentChannel.name
865 >           << ": run="  << events->at(0).run
866 >           << "  lumi=" << events->at(0).lumi
867 >           << "  event=" << events->at(0).evt
868 >           << endl;
869      }
870  
871  
872      //filling histograms
873 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
874 <      histogram currentHistogram = histograms.at(histogramIndex);
875 <
876 <      if(currentHistogram.inputVariables.size() == 1){
877 <        TH1D* histo;
693 <        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
694 <
695 <        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
696 <        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
697 <        else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").back(),scaleFactor);
698 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
699 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
700 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
701 <        else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
702 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("secondary muons").back(), \
703 <                                                                                       cumulativeFlags.at("muon-secondary muon pairs").back(),scaleFactor);
704 <        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
705 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
706 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
707 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
708 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
709 <                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
710 <                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
711 <        else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),        
712 <                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),  
713 <                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);      
714 <        else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),        
715 <                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),  
716 <                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);      
717 <        else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),    
718 <                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),      
719 <                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);  
720 <        else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),      
721 <                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),        
722 <                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);    
723 <        else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
724 <                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("tracks").back(),
725 <                                                                                     cumulativeFlags.at("tau-track pairs").back(),scaleFactor);
726 <
727 <        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
728 <        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
729 <        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
730 <        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
731 <        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
732 <        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
733 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
734 <        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
735 <        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
736 <        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
737 <      }
738 <      else if(currentHistogram.inputVariables.size() == 2){
739 <        TH2D* histo;
740 <        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
741 <
742 <        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
743 <        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
744 <        else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").back(),scaleFactor);
745 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
746 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
747 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
748 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
749 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("secondary muons").back(), \
750 <                                                                                       cumulativeFlags.at("muon-secondary muon pairs").back(),scaleFactor);
751 <        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
752 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
753 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
754 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
755 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
756 <                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
757 <                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
758 <        else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),        
759 <                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),          
760 <                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);      
761 <        else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),        
762 <                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),          
763 <                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);      
764 <        else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),    
765 <                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),      
766 <                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);  
767 <        else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),      
768 <                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),        
769 <                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);    
770 <        else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
771 <                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("tracks").back(),
772 <                                                                                     cumulativeFlags.at("tau-track pairs").back(),scaleFactor);
773 <        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
774 <        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
775 <        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
776 <        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
777 <        else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
778 <                                                                                         cumulativeFlags.at("tracks").back(),cumulativeFlags.at("events").back(),
779 <                                                                                         cumulativeFlags.at("track-event pairs").back(),scaleFactor);  
780 <        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
781 <        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
782 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
783 <        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
784 <        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
785 <        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
873 >    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
874 >      uint currentDir;
875 >      if(!GetPlotsAfterEachCut_){ currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size();}//if GetPlotsAfterEachCut_ is true, set currentDir point to the lat cut.
876 >      else{
877 >        currentDir = currentCut;
878        }
879 <    }
879 >      if(eventPassedPreviousCuts.at(currentDir)){
880  
881 +        // Assign BNTree variables
882 +        for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
883 +          BranchSpecs brSpecs = treeBranches_.at(iBranch);  
884 +          string coll = brSpecs.inputCollection;  
885 +          if (cumulativeFlags.count(coll) == 0) cout << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
886 +
887 +          if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).at(currentDir));            
888 +          else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).at(currentDir));
889 +          else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).at(currentDir));        
890 +          else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).at(currentDir));
891 +          else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).at(currentDir));
892 +          else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).at(currentDir));
893 +          else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).at(currentDir));
894 +          else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).at(currentDir));
895 +          else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).at(currentDir));
896 +          else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).at(currentDir));
897 +          else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).at(currentDir));
898 +          else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).at(currentDir));
899 +          else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).at(currentDir));
900 +          else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).at(currentDir));
901 +          else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).at(currentDir));
902 +          else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).at(currentDir));
903 +          else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).at(currentDir));
904 +          else if(coll == "stops"
905 +                  && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).at(currentDir));
906 +        } // end loop over histograms  
907 +                                                                                          
908 +
909 +        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
910 +          histogram currentHistogram = histograms.at(histogramIndex);
911 +
912 +          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) cout << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
913 +
914 +          if(currentHistogram.inputVariables.size() == 1){
915 +            TH1D* histo;  
916 +            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
917 +            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
918 +            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
919 +            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
920 +            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
921 +            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
922 +            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
923 +                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
924 +                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
925 +            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
926 +                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
927 +                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
928 +            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
929 +            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
930 +                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
931 +                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
932 +            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
933 +                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
934 +                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
935 +            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
936 +                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
937 +                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
938 +            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
939 +                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
940 +                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
941 +            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
942 +                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
943 +                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
944 +            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
945 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
946 +                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
947 +            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
948 +                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
949 +                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
950 +            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
951 +                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
952 +                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
953 +            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
954 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
955 +                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
956 +            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
957 +                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
958 +                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
959 +            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
960 +                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
961 +                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
962 +            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
963 +                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
964 +                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
965 +            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
966 +                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
967 +                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
968 +
969 +            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
970 +            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
971 +            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
972 +            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
973 +            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
974 +            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
975 +            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
976 +            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
977 +            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
978 +            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
979 +            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
980 +            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
981 +          }
982 +          else if(currentHistogram.inputVariables.size() == 2){
983 +            TH2D* histo;
984 +            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
985 +            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
986 +            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
987 +            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
988 +            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
989 +            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
990 +                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
991 +                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
992 +            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
993 +                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
994 +                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
995 +            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
996 +            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
997 +            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
998 +                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
999 +                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1000 +            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1001 +                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1002 +                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1003 +            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1004 +                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1005 +                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1006 +            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1007 +                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1008 +                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1009 +            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1010 +                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1011 +                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1012 +            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1013 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1014 +                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1015 +            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1016 +                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1017 +                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1018 +            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1019 +                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1020 +                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1021 +            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1022 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1023 +                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1024 +            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1025 +                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1026 +                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1027 +            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1028 +                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1029 +                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1030 +            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1031 +                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1032 +                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1033 +            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1034 +                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1035 +                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1036 +            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1037 +            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1038 +            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1039 +            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1040 +            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1041 +                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1042 +                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1043 +            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1044 +            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1045 +            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1046 +            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1047 +            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1048 +            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1049 +            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1050 +            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1051 +          }
1052 +          
1053 +        }
1054  
1055  
1056 <    //fills histograms with the sizes of collections
1057 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1058 <
1059 <      string currentObject = objectsToPlot.at(currentObjectIndex);
1060 <
796 <      string objectToPlot = "";  
797 <
798 <      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().  
799 <      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
800 <      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
801 <      else if(currentObject == "electron-muon pairs")     objectToPlot = "electronMuonPairs";
802 <      else if(currentObject == "electron-track pairs")    objectToPlot = "electronTrackPairs";
803 <      else if(currentObject == "muon-track pairs")        objectToPlot = "muonTrackPairs";      
804 <      else if(currentObject == "muon-tau pairs")          objectToPlot = "muonTauPairs";        
805 <      else if(currentObject == "tau-tau pairs")           objectToPlot = "ditauPairs";
806 <      else if(currentObject == "tau-track pairs")         objectToPlot = "tauTrackPairs";
807 <      else if(currentObject == "track-event pairs")       objectToPlot = "trackEventPairs";  
808 <      else if(currentObject == "muon-secondary muon pairs")       objectToPlot = "muonSecondaryMuonPairs";  
809 <      else if(currentObject == "secondary muons")         objectToPlot = "secondaryMuons";  
810 <      else objectToPlot = currentObject;
811 <
812 <      string tempCurrentObject = objectToPlot;
813 <      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));  
814 <      string histoName = "num" + tempCurrentObject;
815 <
816 <      //set position of primary vertex in event, in order to calculate quantities relative to it
817 <      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
818 <        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
819 <        int numToPlot = 0;
820 <        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
821 <          if(lastCutFlags.at(currentFlag)) numToPlot++;
822 <        }
823 <        if(objectToPlot == "primaryvertexs"){
824 <          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
825 <          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
826 <        }
827 <        else {
828 <          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
829 <        }
830 <      }
831 <      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
832 <      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
833 <      else if(objectToPlot == "secondaryMuons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
834 <      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
835 <      else if(objectToPlot == "muonSecondaryMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
836 <      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
837 <      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
838 <      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
839 <      else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
840 <      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
841 <      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
842 <      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
843 <      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
844 <      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
845 <      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
846 <      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
847 <      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
848 <      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
849 <      else if(objectToPlot == "primaryvertexs"){
850 <        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
851 <        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
852 <      }
1056 >        //fills histograms with the sizes of collections
1057 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1058 >
1059 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1060 >          string objectToPlot = "";
1061  
1062 <    } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1062 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1063 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1064 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1065 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1066 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1067 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1068 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1069 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1070 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1071 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1072 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1073 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1074 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1075 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1076 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1077 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1078 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1079 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1080 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1081 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1082 >          else objectToPlot = currentObject;
1083 >
1084 >          string tempCurrentObject = objectToPlot;
1085 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1086 >          string histoName = "num" + tempCurrentObject;
1087 >
1088 >          //set position of primary vertex in event, in order to calculate quantities relative to it
1089 >          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1090 >            vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1091 >            int numToPlot = 0;
1092 >            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1093 >              if(lastCutFlags.at(currentFlag)) numToPlot++;
1094 >            }
1095 >            if(objectToPlot == "primaryvertexs"){
1096 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1097 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1098 >            }
1099 >            else {
1100 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1101 >            }
1102 >          }
1103 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1104 >      } // end if(eventPassedPreviousCuts.at(currentDir)){
1105 >    } // end loop over cuts
1106  
1107 <  } //end loop over channel
1107 >    BNTrees_.at(currentChannelIndex)->Fill();  
1108 >
1109 >  } // end loop over channel
1110 >
1111 >  masterCutFlow_->fillCutFlow(masterScaleFactor);
1112  
858  masterCutFlow_->fillCutFlow(scaleFactor);
1113  
1114   } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1115  
# Line 872 | Line 1126 | OSUAnalysis::evaluateComparison (double
1126    else if(comparison == "==") return testValue == cutValue;
1127    else if(comparison == "=") return testValue == cutValue;
1128    else if(comparison == "!=") return testValue != cutValue;
1129 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1129 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1130 >
1131 > }
1132 >
1133 > bool
1134 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1135 >
1136 >
1137 >  if(comparison == ">")       return testValue >  cutValue;
1138 >  else 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 {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1145  
1146   }
1147  
1148   bool
1149 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1149 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1150  
1151 +  //initialize to false until a chosen trigger is passed
1152    bool triggerDecision = false;
1153  
1154 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1155 <    {
1156 <      if(trigger->pass != 1) continue;
1157 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1158 <        {
889 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
890 <            triggerDecision = true;
891 <          }
892 <        }
893 <    }
894 <  return triggerDecision;
1154 >  //loop over all triggers defined in the event
1155 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1156 >
1157 >    //we're only interested in triggers that actually passed
1158 >    if(trigger->pass != 1) continue;
1159  
1160 +    //if the event passes one of the veto triggers, exit and return false
1161 +    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1162 +      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1163 +    }
1164 +    //if the event passes one of the chosen triggers, set triggerDecision to true
1165 +    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1166 +      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1167 +    }  
1168 +  }
1169 +  //if none of the veto triggers fired:
1170 +  //return the OR of all the chosen triggers
1171 +  if (triggersToTest.size() != 0) return triggerDecision;
1172 +  //or if no triggers were defined return true
1173 +  else return true;
1174   }
1175  
1176 < std::vector<std::string>
1176 >
1177 > vector<string>
1178   OSUAnalysis::splitString (string inputString){
1179  
1180 <  std::stringstream stringStream(inputString);
1181 <  std::istream_iterator<std::string> begin(stringStream);
1182 <  std::istream_iterator<std::string> end;
1183 <  std::vector<std::string> stringVector(begin, end);
1180 >  stringstream stringStream(inputString);
1181 >  istream_iterator<string> begin(stringStream);
1182 >  istream_iterator<string> end;
1183 >  vector<string> stringVector(begin, end);
1184    return stringVector;
1185  
1186   }
1187  
1188  
1189   void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1190 <  // Set two object strings from the tempInputCollection string,
1191 <  // For example, if tempInputCollection is "electron-muon pairs",
1192 <  // then obj1 = "electrons" and obj2 = "muons".  
1193 <  // Note that the objects have an "s" appended.  
1190 >  // Set two object strings from the tempInputCollection string,
1191 >  // For example, if tempInputCollection is "electron-muon pairs",
1192 >  // then obj1 = "electrons" and obj2 = "muons".
1193 >  // Note that the objects have an "s" appended.
1194  
1195    int dashIndex = tempInputCollection.find("-");
1196    int spaceIndex = tempInputCollection.find_last_of(" ");
1197    int secondWordLength = spaceIndex - dashIndex;
1198 <  obj1 = tempInputCollection.substr(0,dashIndex) + "s";  
1198 >  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1199    obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1200 <  
1201 < }
1200 >
1201 > }
1202  
1203  
1204   string OSUAnalysis::getObjToGet(string obj) {
1205    // Return the string corresponding to the object to get for the given obj string.
1206 <  // Right now this only handles the case in which obj contains "secondary",
1207 <  // e.g, "secondary muons".  
1208 <  // Note that "s" is NOT appended.  
930 <  
931 <  if (obj.find("secondary")==std::string::npos) return obj;  // "secondary" is not found  
932 <  int firstSpaceIndex = obj.find_first_of(" ");  
933 <  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1206 >  // Right now this only handles the case in which obj contains "secondary",
1207 >  // e.g, "secondary muons".
1208 >  // Note that "s" is NOT appended.
1209  
1210 < }  
1210 >  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1211 >  int firstSpaceIndex = obj.find_first_of(" ");
1212 >  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1213  
1214 + }
1215  
1216  
1217 + //!jet valueLookup
1218   double
1219 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1219 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1220  
1221    double value = 0.0;
1222    if(variable == "energy") value = object->energy;
# Line 1057 | Line 1336 | OSUAnalysis::valueLookup (const BNjet* o
1336    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1337  
1338  
1339 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1339 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1340  
1341    value = applyFunction(function, value);
1342  
# Line 1065 | Line 1344 | OSUAnalysis::valueLookup (const BNjet* o
1344   }
1345  
1346  
1347 <
1347 > //!muon valueLookup
1348   double
1349 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1349 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1350  
1351    double value = 0.0;
1352    if(variable == "energy") value = object->energy;
# Line 1228 | Line 1507 | OSUAnalysis::valueLookup (const BNmuon*
1507    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1508    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1509    else if(variable == "metMT") {
1510 <    const BNmet *met = chosenMET ();
1232 <    if (met)
1510 >    if (const BNmet *met = chosenMET ())
1511        {
1512 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1513 <          p2 (met->px, met->py, 0.0, met->pt);
1236 <
1237 <        value = (p1 + p2).Mt ();
1512 >        double dPhi = deltaPhi (object->phi, met->phi);
1513 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1514        }
1515      else
1516        value = -999;
# Line 1352 | Line 1628 | OSUAnalysis::valueLookup (const BNmuon*
1628      value = object->isGlobalMuon > 0                \
1629        && object->isPFMuon > 0                        \
1630        && object->normalizedChi2 < 10                \
1631 <                                  && object->numberOfValidMuonHits > 0        \
1631 >      && object->numberOfValidMuonHits > 0        \
1632        && object->numberOfMatchedStations > 1        \
1633        && fabs(object->correctedD0Vertex) < 0.2        \
1634        && fabs(object->correctedDZ) < 0.5        \
# Line 1361 | Line 1637 | OSUAnalysis::valueLookup (const BNmuon*
1637    }
1638    else if(variable == "tightIDdisplaced"){
1639      value = object->isGlobalMuon > 0                \
1640 +      && object->isPFMuon > 0                        \
1641        && object->normalizedChi2 < 10                \
1642 <                                  && object->numberOfValidMuonHits > 0        \
1642 >      && object->numberOfValidMuonHits > 0        \
1643        && object->numberOfMatchedStations > 1        \
1644        && object->numberOfValidPixelHits > 0        \
1645        && object->numberOfLayersWithMeasurement > 5;
1646    }
1647  
1648 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1648 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1649  
1650    else if(variable == "genMatchedPdgId"){
1651      int index = getGenMatchedParticleIndex(object);
# Line 1388 | Line 1665 | OSUAnalysis::valueLookup (const BNmuon*
1665    }
1666    else if(variable == "genMatchedMotherIdReverse"){
1667      int index = getGenMatchedParticleIndex(object);
1668 <    if(index == -1) value = 23;
1669 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1668 >    if(index == -1) value = 24;
1669 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1670    }
1671    else if(variable == "genMatchedGrandmotherId"){
1672      int index = getGenMatchedParticleIndex(object);
# Line 1401 | Line 1678 | OSUAnalysis::valueLookup (const BNmuon*
1678      }
1679      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1680    }
1681 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1682 +    int index = getGenMatchedParticleIndex(object);
1683 +    if(index == -1) value = 24;
1684 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1685 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1686 +      if(motherIndex == -1) value = 24;
1687 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1688 +    }
1689 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1690 +  }
1691 +  else if(variable == "pfMuonsFromVertex"){
1692 +    double d0Error, dzError;
1693 +
1694 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1695 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1696 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1697 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1698 +      || fabs (object->correctedDZ / dzError) > 99.0;
1699 +    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1700 +  }
1701  
1702  
1703  
1704 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1704 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1705  
1706    value = applyFunction(function, value);
1707  
1708    return value;
1709   }
1710  
1711 <
1711 > //!electron valueLookup
1712   double
1713 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1713 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1714  
1715    double value = 0.0;
1716    if(variable == "energy") value = object->energy;
# Line 1579 | Line 1876 | OSUAnalysis::valueLookup (const BNelectr
1876    else if(variable == "detIso") value = (object->trackIso) / object->pt;
1877    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1878    else if(variable == "metMT") {
1879 <    const BNmet *met = chosenMET ();
1583 <    if (met)
1879 >    if (const BNmet *met = chosenMET ())
1880        {
1881 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1882 <          p2 (met->px, met->py, 0.0, met->pt);
1587 <
1588 <        value = (p1 + p2).Mt ();
1881 >        double dPhi = deltaPhi (object->phi, met->phi);
1882 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1883        }
1884      else
1885        value = -999;
# Line 1750 | Line 2044 | OSUAnalysis::valueLookup (const BNelectr
2044    }
2045  
2046  
2047 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2047 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2048  
2049    else if(variable == "genMatchedPdgId"){
2050      int index = getGenMatchedParticleIndex(object);
# Line 1771 | Line 2065 | OSUAnalysis::valueLookup (const BNelectr
2065    }
2066    else if(variable == "genMatchedMotherIdReverse"){
2067      int index = getGenMatchedParticleIndex(object);
2068 <    if(index == -1) value = 23;
2069 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2068 >    if(index == -1) value = 24;
2069 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2070    }
2071    else if(variable == "genMatchedGrandmotherId"){
2072      int index = getGenMatchedParticleIndex(object);
# Line 1784 | Line 2078 | OSUAnalysis::valueLookup (const BNelectr
2078      }
2079      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2080    }
2081 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2082 +    int index = getGenMatchedParticleIndex(object);
2083 +    if(index == -1) value = 24;
2084 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2085 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2086 +      if(motherIndex == -1) value = 24;
2087 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2088 +    }
2089 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2090 +  }
2091 +  else if(variable == "pfElectronsFromVertex"){
2092 +    double d0Error, dzError;
2093  
2094 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2095 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2096 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2097 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2098 +      || fabs (object->correctedDZ / dzError) > 99.0;
2099 +    value = !value;
2100 +  }
2101  
2102  
2103 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2103 >
2104 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2105  
2106    value = applyFunction(function, value);
2107  
2108    return value;
2109   }
2110  
2111 <
2111 > //!event valueLookup
2112   double
2113 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2113 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2114  
2115    double value = 0.0;
2116  
# Line 1865 | Line 2179 | OSUAnalysis::valueLookup (const BNevent*
2179    else if(variable == "id2") value = object->id2;
2180    else if(variable == "evt") value = object->evt;
2181    else if(variable == "puScaleFactor"){
2182 <    if(datasetType_ != "data")
2182 >    if(doPileupReweighting_ && datasetType_ != "data")
2183        value = puWeight_->at (events->at (0).numTruePV);
2184      else
2185        value = 1.0;
2186    }
2187 <  else if(variable == "muonScaleFactor"){
2188 <    if(datasetType_ != "data")
2189 <      //      value = muonSFWeight_->at (chosenMuon ()->eta);
1876 <      value = 1.0;
1877 <    else
1878 <      value = 1.0;
1879 <  }
1880 <  else if(variable == "electronScaleFactor"){
1881 <    if(datasetType_ != "data")
1882 <      //      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1883 <      value = 1.0;
1884 <    else
1885 <      value = 1.0;
1886 <  }
1887 <  else if(variable == "cTauScaleFactor")
1888 <    value = cTauScaleFactor_;
2187 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2188 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2189 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2190  
2191 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2191 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2192  
2193    value = applyFunction(function, value);
2194  
2195    return value;
2196   }
2197  
2198 + //!tau valueLookup
2199   double
2200 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2200 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2201  
2202    double value = 0.0;
2203  
# Line 1941 | Line 2243 | OSUAnalysis::valueLookup (const BNtau* o
2243  
2244  
2245  
2246 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2246 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2247  
2248    else if(variable == "genMatchedPdgId"){
2249      int index = getGenMatchedParticleIndex(object);
# Line 1961 | Line 2263 | OSUAnalysis::valueLookup (const BNtau* o
2263    }
2264    else if(variable == "genMatchedMotherIdReverse"){
2265      int index = getGenMatchedParticleIndex(object);
2266 <    if(index == -1) value = 23;
2267 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2266 >    if(index == -1) value = 24;
2267 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2268    }
2269    else if(variable == "genMatchedGrandmotherId"){
2270      int index = getGenMatchedParticleIndex(object);
# Line 1974 | Line 2276 | OSUAnalysis::valueLookup (const BNtau* o
2276      }
2277      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2278    }
2279 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2280 +    int index = getGenMatchedParticleIndex(object);
2281 +    if(index == -1) value = 24;
2282 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2283 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2284 +      if(motherIndex == -1) value = 24;
2285 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2286 +    }
2287 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2288 +  }
2289  
2290  
2291 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2291 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2292  
2293    value = applyFunction(function, value);
2294  
2295    return value;
2296   }
2297  
2298 + //!met valueLookup
2299   double
2300 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2300 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2301  
2302    double value = 0.0;
2303  
# Line 2048 | Line 2361 | OSUAnalysis::valueLookup (const BNmet* o
2361    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2362    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2363  
2364 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2364 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2365  
2366    value = applyFunction(function, value);
2367  
2368    return value;
2369   }
2370  
2371 + //!track valueLookup
2372   double
2373 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2373 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2374  
2375    double value = 0.0;
2376    double pMag = sqrt(object->pt * object->pt +
2377 <                     object->pz * object->pz);
2378 <  
2377 >                     object->pz * object->pz);
2378 >
2379    if(variable == "pt") value = object->pt;
2380    else if(variable == "px") value = object->px;
2381    else if(variable == "py") value = object->py;
# Line 2082 | Line 2396 | OSUAnalysis::valueLookup (const BNtrack*
2396  
2397  
2398    //additional BNs info for disappTrks
2085  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2399    else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2400    else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2401    else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2402    else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2403    else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2404    else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2405 +  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2406    else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2407    else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2408    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2409 <  
2409 >  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2410  
2411    //user defined variables
2412    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;
2413    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2414 +  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2415    else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2416    else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2417 <  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);  
2418 <  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;  
2417 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2418 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2419    else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2420    else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2421    else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2422    else if(variable == "ptError")                    value = object->ptError;
2423    else if(variable == "ptRes")                      value = getTrkPtRes(object);
2424 <  else if (variable == "d0wrtPV"){      
2425 <    double vx = object->vx - chosenVertex ()->x,        
2426 <      vy = object->vy - chosenVertex ()->y,      
2427 <      px = object->px,  
2428 <      py = object->py,  
2429 <      pt = object->pt;  
2430 <    value = (-vx * py + vy * px) / pt;  
2431 <  }      
2432 <  else if (variable == "dZwrtPV"){      
2433 <    double vx = object->vx - chosenVertex ()->x,        
2434 <      vy = object->vy - chosenVertex ()->y,      
2435 <      vz = object->vz - chosenVertex ()->z,      
2436 <      px = object->px,  
2437 <      py = object->py,  
2438 <      pz = object->pz,  
2439 <      pt = object->pt;  
2440 <    value = vz - (vx * px + vy * py)/pt * (pz/pt);      
2441 <  }    
2442 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2424 >  else if (variable == "d0wrtPV"){
2425 >    double vx = object->vx - chosenVertex ()->x,
2426 >      vy = object->vy - chosenVertex ()->y,
2427 >      px = object->px,
2428 >      py = object->py,
2429 >      pt = object->pt;
2430 >    value = (-vx * py + vy * px) / pt;
2431 >  }
2432 >  else if (variable == "dZwrtPV"){
2433 >    double vx = object->vx - chosenVertex ()->x,
2434 >      vy = object->vy - chosenVertex ()->y,
2435 >      vz = object->vz - chosenVertex ()->z,
2436 >      px = object->px,
2437 >      py = object->py,
2438 >      pz = object->pz,
2439 >      pt = object->pt;
2440 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2441 >  }
2442 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2443  
2444    else if(variable == "genMatchedPdgId"){
2445      int index = getGenMatchedParticleIndex(object);
# Line 2145 | Line 2460 | OSUAnalysis::valueLookup (const BNtrack*
2460    }
2461    else if(variable == "genMatchedMotherIdReverse"){
2462      int index = getGenMatchedParticleIndex(object);
2463 <    if(index == -1) value = 23;
2464 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2463 >    if(index == -1) value = 24;
2464 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2465    }
2466    else if(variable == "genMatchedGrandmotherId"){
2467      int index = getGenMatchedParticleIndex(object);
# Line 2158 | Line 2473 | OSUAnalysis::valueLookup (const BNtrack*
2473      }
2474      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2475    }
2476 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2477 +    int index = getGenMatchedParticleIndex(object);
2478 +    if(index == -1) value = 24;
2479 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2480 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2481 +      if(motherIndex == -1) value = 24;
2482 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2483 +    }
2484 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2485 +  }
2486  
2487  
2488  
2489 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2489 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2490  
2491    value = applyFunction(function, value);
2492  
2493    return value;
2494   }
2495  
2496 + //!genjet valueLookup
2497   double
2498 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2498 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2499  
2500    double value = 0.0;
2501  
# Line 2189 | Line 2515 | OSUAnalysis::valueLookup (const BNgenjet
2515    else if(variable == "charge") value = object->charge;
2516  
2517  
2518 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2518 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2519  
2520    value = applyFunction(function, value);
2521  
2522    return value;
2523   }
2524  
2525 + //!mcparticle valueLookup
2526   double
2527 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2527 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2528  
2529    double value = 0.0;
2530  
# Line 2322 | Line 2649 | OSUAnalysis::valueLookup (const BNmcpart
2649    }
2650  
2651  
2652 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2652 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2653  
2654    value = applyFunction(function, value);
2655  
2656    return value;
2657   }
2658  
2659 + //!primaryvertex valueLookup
2660   double
2661 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2661 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2662  
2663    double value = 0.0;
2664  
# Line 2349 | Line 2677 | OSUAnalysis::valueLookup (const BNprimar
2677    else if(variable == "isGood") value = object->isGood;
2678  
2679  
2680 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2680 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2681  
2682    value = applyFunction(function, value);
2683  
2684    return value;
2685   }
2686  
2687 + //!bxlumi valueLookup
2688   double
2689 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2689 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2690  
2691    double value = 0.0;
2692  
# Line 2366 | Line 2695 | OSUAnalysis::valueLookup (const BNbxlumi
2695    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2696  
2697  
2698 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2698 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2699  
2700    value = applyFunction(function, value);
2701  
2702    return value;
2703   }
2704  
2705 + //!photon valueLookup
2706   double
2707 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2707 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2708  
2709    double value = 0.0;
2710  
# Line 2449 | Line 2779 | OSUAnalysis::valueLookup (const BNphoton
2779    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2780  
2781  
2452
2782  
2783 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2783 >
2784 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2785  
2786    else if(variable == "genMatchedPdgId"){
2787      int index = getGenMatchedParticleIndex(object);
# Line 2473 | Line 2803 | OSUAnalysis::valueLookup (const BNphoton
2803    }
2804    else if(variable == "genMatchedMotherIdReverse"){
2805      int index = getGenMatchedParticleIndex(object);
2806 <    if(index == -1) value = 23;
2807 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2806 >    if(index == -1) value = 24;
2807 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2808    }
2809    else if(variable == "genMatchedGrandmotherId"){
2810      int index = getGenMatchedParticleIndex(object);
# Line 2486 | Line 2816 | OSUAnalysis::valueLookup (const BNphoton
2816      }
2817      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2818    }
2819 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2820 +    int index = getGenMatchedParticleIndex(object);
2821 +    if(index == -1) value = 24;
2822 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2823 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2824 +      if(motherIndex == -1) value = 24;
2825 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2826 +    }
2827 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2828 +  }
2829  
2830  
2831 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2831 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2832  
2833    value = applyFunction(function, value);
2834  
2835    return value;
2836   }
2837  
2838 + //!supercluster valueLookup
2839   double
2840 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
2840 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
2841  
2842    double value = 0.0;
2843  
# Line 2510 | Line 2851 | OSUAnalysis::valueLookup (const BNsuperc
2851    else if(variable == "theta") value = object->theta;
2852  
2853  
2854 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2854 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2855  
2856    value = applyFunction(function, value);
2857  
2858    return value;
2859   }
2860  
2861 + //!trigobj valueLookup
2862 + double
2863 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
2864 +
2865 +  double value = 0.0;
2866 +
2867 +  if(variable == "pt") value = object->pt;
2868 +  else if(variable == "eta") value = object->eta;
2869 +  else if(variable == "phi") value = object->phi;
2870 +  else if(variable == "px") value = object->px;
2871 +  else if(variable == "py") value = object->py;
2872 +  else if(variable == "pz") value = object->pz;
2873 +  else if(variable == "et") value = object->et;
2874 +  else if(variable == "energy") value = object->energy;
2875 +  else if(variable == "etTotal") value = object->etTotal;
2876 +  else if(variable == "id") value = object->id;
2877 +  else if(variable == "charge") value = object->charge;
2878 +  else if(variable == "isIsolated") value = object->isIsolated;
2879 +  else if(variable == "isMip") value = object->isMip;
2880 +  else if(variable == "isForward") value = object->isForward;
2881 +  else if(variable == "isRPC") value = object->isRPC;
2882 +  else if(variable == "bx") value = object->bx;
2883 +  else if(variable == "filter") {
2884 +    if ((stringValue = object->filter) == "")
2885 +      stringValue = "none";  // stringValue should only be empty if value is filled
2886 +  }
2887 +
2888 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2889  
2890 +  value = applyFunction(function, value);
2891 +
2892 +  return value;
2893 + }
2894 +
2895 + //!muon-muon pair valueLookup
2896   double
2897 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
2897 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
2898  
2899    double value = 0.0;
2900  
# Line 2581 | Line 2956 | OSUAnalysis::valueLookup (const BNmuon*
2956        value = object2->correctedD0;
2957      }
2958  
2959 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2959 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2960  
2961    value = applyFunction(function, value);
2962  
2963    return value;
2964   }
2965  
2966 + //!electron-electron pair valueLookup
2967   double
2968 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
2968 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
2969  
2970    double value = 0.0;
2971  
# Line 2636 | Line 3012 | OSUAnalysis::valueLookup (const BNelectr
3012      value = object2->correctedD0;
3013    }
3014  
3015 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3015 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3016  
3017    value = applyFunction(function, value);
3018  
3019    return value;
3020   }
3021 <
3021 > //!electron-muon pair valueLookup
3022   double
3023 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3023 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3024  
3025    double value = 0.0;
3026  
# Line 2702 | Line 3078 | OSUAnalysis::valueLookup (const BNelectr
3078    else if(variable == "muonRelPFdBetaIso"){
3079      value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3080    }
3081 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3082 +  value = applyFunction(function, value);
3083  
3084 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3084 >  return value;
3085 > }
3086 >
3087 > //!electron-jet pair valueLookup
3088 > double
3089 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3090 >
3091 >  double value = 0.0;
3092 >
3093 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3094 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3095 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3096 >  else if(variable == "invMass"){
3097 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3098 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3099 >    value = (fourVector1 + fourVector2).M();
3100 >  }
3101 >  else if(variable == "pt"){
3102 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3103 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3104 >    value = (fourVector1 + fourVector2).Pt();
3105 >  }
3106 >  else if(variable == "threeDAngle")
3107 >    {
3108 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3109 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3110 >      value = (threeVector1.Angle(threeVector2));
3111 >    }
3112 >  else if(variable == "chargeProduct"){
3113 >    value = object1->charge*object2->charge;
3114 >  }
3115  
3116 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3117    value = applyFunction(function, value);
3118  
3119    return value;
3120   }
3121  
3122 + //!muon-jet pair valueLookup
3123 + double
3124 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3125 +
3126 +  double value = 0.0;
3127  
3128 < double  
2715 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function){  
2716 <  double electronMass = 0.000511;        
2717 <  double value = 0.0;    
2718 <  TLorentzVector fourVector1(0, 0, 0, 0);        
2719 <  TLorentzVector fourVector2(0, 0, 0, 0);        
2720 <  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));  
3128 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3129    else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3130 <  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);    
3131 <  else if(variable == "invMass"){        
3132 <    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);    
3133 <    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );    
3134 <        
2727 <    value = (fourVector1 + fourVector2).M();    
3130 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3131 >  else if(variable == "invMass"){
3132 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3133 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3134 >    value = (fourVector1 + fourVector2).M();
3135    }
3136 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}  
3137 <  value = applyFunction(function, value);        
3138 <  return value;  
3136 >  else if(variable == "pt"){
3137 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3138 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3139 >    value = (fourVector1 + fourVector2).Pt();
3140 >  }
3141 >  else if(variable == "threeDAngle")
3142 >    {
3143 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3144 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3145 >      value = (threeVector1.Angle(threeVector2));
3146 >    }
3147 >  else if(variable == "chargeProduct"){
3148 >    value = object1->charge*object2->charge;
3149 >  }
3150 >
3151 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3152 >  value = applyFunction(function, value);
3153 >
3154 >  return value;
3155   }
3156  
3157 + //!jet-jet pair valueLookup
3158 + double
3159 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3160 +
3161 +  double value = 0.0;
3162 +
3163 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3164 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3165 +  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3166 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3167 +  else if(variable == "invMass"){
3168 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3169 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3170 +    value = (fourVector1 + fourVector2).M();
3171 +  }
3172 +  else if(variable == "pt"){
3173 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3174 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3175 +    value = (fourVector1 + fourVector2).Pt();
3176 +  }
3177 +  else if(variable == "threeDAngle")
3178 +    {
3179 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3180 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3181 +      value = (threeVector1.Angle(threeVector2));
3182 +    }
3183 +  else if(variable == "chargeProduct"){
3184 +    value = object1->charge*object2->charge;
3185 +  }
3186  
3187 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3188 +  value = applyFunction(function, value);
3189  
3190 +  return value;
3191 + }
3192 + //!electron-track pair valueLookup
3193   double
3194 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function){
3194 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3195 >  double electronMass = 0.000511;
3196 >  double value = 0.0;
3197 >  TLorentzVector fourVector1(0, 0, 0, 0);
3198 >  TLorentzVector fourVector2(0, 0, 0, 0);
3199 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3200 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3201 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3202 >  else if(variable == "invMass"){
3203 >    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3204 >    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3205 >
3206 >    value = (fourVector1 + fourVector2).M();
3207 >  }
3208 >  else if(variable == "chargeProduct"){
3209 >    value = object1->charge*object2->charge;
3210 >  }
3211 >  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3212 >  value = applyFunction(function, value);
3213 >  return value;
3214 >
3215 > }
3216 >
3217 >
3218 > //!muon-track pair valueLookup
3219 > double
3220 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3221    double pionMass = 0.140;
3222    double muonMass = 0.106;
3223    double value = 0.0;
# Line 2749 | Line 3232 | OSUAnalysis::valueLookup (const BNmuon*
3232  
3233      value = (fourVector1 + fourVector2).M();
3234    }
3235 +  else if(variable == "chargeProduct"){
3236 +    value = object1->charge*object2->charge;
3237 +  }
3238  
3239    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3240    value = applyFunction(function, value);
3241    return value;
3242   }
3243  
3244 <
3244 > //!tau-tau pair valueLookup
3245   double
3246 < OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function){
3246 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3247    double value = 0.0;
3248    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3249    else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
# Line 2768 | Line 3254 | OSUAnalysis::valueLookup (const BNtau* o
3254      value = (fourVector1 + fourVector2).M();
3255    }
3256  
3257 +  else if(variable == "chargeProduct"){
3258 +    value = object1->charge*object2->charge;
3259 +  }
3260 +
3261    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3262    value = applyFunction(function, value);
3263    return value;
3264   }
3265  
3266 <
3266 > //!muon-tau pair valueLookup
3267   double
3268 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function){
3268 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3269    double value = 0.0;
3270    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3271    else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
# Line 2786 | Line 3276 | OSUAnalysis::valueLookup (const BNmuon*
3276      value = (fourVector1 + fourVector2).M();
3277    }
3278  
3279 +  else if(variable == "chargeProduct"){
3280 +    value = object1->charge*object2->charge;
3281 +  }
3282 +
3283    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3284    value = applyFunction(function, value);
3285    return value;
3286   }
3287  
3288 + //!tau-track pair valueLookup
3289   double
3290 < OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function){
3290 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3291    double value = 0.0;
3292    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3293    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
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);
# Line 2803 | Line 3301 | OSUAnalysis::valueLookup (const BNtau* o
3301   }
3302  
3303  
3304 <
3304 > //!track-event pair valueLookup
3305   double
3306 < OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function){
3306 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3307  
3308    double value = 0.0;
3309    double pMag = sqrt(object1->pt * object1->pt +
3310 <                     object1->pz * object1->pz);  
3310 >                     object1->pz * object1->pz);
3311  
3312    if      (variable == "numPV")                      value = object2->numPV;
3313    else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3314    else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3315 <  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);  
3316 <  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;  
3315 >  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3316 >  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3317 >
3318 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3319 >
3320 >  value = applyFunction(function, value);
3321 >
3322 >  return value;
3323 >
3324 > }
3325 >
3326 > //!electron-trigobj pair valueLookup
3327 > double
3328 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3329 >
3330 >  double value = 0.0;
3331 >
3332 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3333 >  else if (variable == "match"){
3334 >    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3335 >      stringValue = object2->filter;
3336 >    else
3337 >      stringValue = "none";
3338 >  }
3339 >
3340 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3341 >
3342 >  value = applyFunction(function, value);
3343 >
3344 >  return value;
3345 >
3346 > }
3347 >
3348 > //!muon-trigobj pair valueLookup
3349 > double
3350 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3351 >
3352 >  double value = 0.0;
3353 >
3354 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3355 >
3356 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3357 >
3358 >  value = applyFunction(function, value);
3359 >
3360 >  return value;
3361 >
3362 > }
3363 >
3364 > //!stop valueLookup
3365 > double
3366 > OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3367 >
3368 >
3369 >  double value = 0.0;
3370 >
3371 >  if(variable == "ctau") value = object->ctau;
3372 >
3373 >  else if (variable == "d0"){
3374 >    double vx = object->vx - chosenVertex ()->x,
3375 >      vy = object->vy - chosenVertex ()->y,
3376 >      px = object->px,
3377 >      py = object->py,
3378 >      pt = object->pt;
3379 >    value = (-vx * py + vy * px) / pt;
3380 >  }
3381 >
3382 >  else if (variable == "dz"){
3383 >    double vx = object->vx - chosenVertex ()->x,
3384 >      vy = object->vy - chosenVertex ()->y,
3385 >      vz = object->vz - chosenVertex ()->z,
3386 >      px = object->px,
3387 >      py = object->py,
3388 >      pz = object->pz,
3389 >      pt = object->pt;
3390 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3391 >  }
3392 >
3393 >  else if (variable == "minD0"){
3394 >    double minD0=999;
3395 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3396 >      double vx = object->vx - vertex->x,
3397 >        vy = object->vy - vertex->y,
3398 >        px = object->px,
3399 >        py = object->py,
3400 >        pt = object->pt;
3401 >      value = (-vx * py + vy * px) / pt;
3402 >      if(abs(value) < abs(minD0)) minD0 = value;
3403 >    }
3404 >    value = minD0;
3405 >  }
3406 >  else if (variable == "minDz"){
3407 >    double minDz=999;
3408 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3409 >      double vx = object->vx - vertex->x,
3410 >        vy = object->vy - vertex->y,
3411 >        vz = object->vz - vertex->z,
3412 >        px = object->px,
3413 >        py = object->py,
3414 >        pz = object->pz,
3415 >        pt = object->pt;
3416 >      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3417 >      if(abs(value) < abs(minDz)) minDz = value;
3418 >    }
3419 >    value = minDz;
3420 >  }
3421 >  else if(variable == "distToVertex"){
3422 >    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3423 >                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3424 >                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3425 >  }
3426 >  else if (variable == "minDistToVertex"){
3427 >    double minDistToVertex=999;
3428 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3429 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3430 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3431 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
3432 >
3433 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3434 >    }
3435 >    value = minDistToVertex;
3436 >  }
3437 >  else if (variable == "distToVertexDifference"){
3438 >    double minDistToVertex=999;
3439 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3440 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3441 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3442 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
3443 >
3444 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3445 >    }
3446 >    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3447 >                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3448 >                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3449 >
3450 >    value = distToChosenVertex - minDistToVertex;
3451 >  }
3452 >
3453 >  else if (variable == "closestVertexRank"){
3454 >    double minDistToVertex=999;
3455 >    int vertex_rank = 0;
3456 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3457 >      vertex_rank++;
3458 >      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3459 >                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
3460 >                      (object->vz-vertex->z)*(object->vz-vertex->z));
3461 >
3462 >      if(abs(dist) < abs(minDistToVertex)){
3463 >        value = vertex_rank;
3464 >        minDistToVertex = dist;
3465 >      }
3466 >    }
3467 >  }
3468  
3469 <  else { std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3469 >
3470 >
3471 >
3472 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3473  
3474    value = applyFunction(function, value);
3475  
3476    return value;
3477  
3478 < }  
3478 > }
3479 >
3480 >
3481 >
3482  
3483   // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3484   // Return true iff no other tracks are found in this cone.
# Line 2872 | Line 3527 | OSUAnalysis::getTrkPtTrue (const BNtrack
3527  
3528   double
3529   OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3530 <  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.  
3531 <  if (!useTrackCaloRhoCorr_) return -99;  
3532 <  // if (!rhokt6CaloJetsHandle_) {
3533 <  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;  
3534 <  //   return -99;  
3530 >  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3531 >  if (!useTrackCaloRhoCorr_) return -99;
3532 >  // if (!rhokt6CaloJetsHandle_) {
3533 >  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3534 >  //   return -99;
3535    // }
3536 <  double radDeltaRCone = 0.5;  
3537 <  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.  
3538 <  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;  
3539 <  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);  
3540 <  return caloTotRhoCorrCalo;  
3541 <
3536 >  double radDeltaRCone = 0.5;
3537 >  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3538 >  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3539 >  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3540 >  return caloTotRhoCorrCalo;
3541 >
3542   }
3543  
3544  
# Line 2921 | Line 3576 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3576    double deltaRLowest = 999;
3577    int value = 0;
3578    if (DeadEcalVec.size() == 0) WriteDeadEcal();
3579 <  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3579 >  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3580      double eta = ecal->etaEcal;
3581      double phi = ecal->phiEcal;
3582 <    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
3582 >    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
3583      if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3584    }
3585    if (deltaRLowest<0.05) {value = 1;}
# Line 2932 | Line 3587 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3587    return value;
3588   }
3589  
3590 < // Returns the smallest DeltaR between the object and any generated true particle in the event.  
3590 > // Returns the smallest DeltaR between the object and any generated true particle in the event.
3591   template <class InputObject>
3592   double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3593    double genDeltaRLowest = 999.;
# Line 2952 | Line 3607 | OSUAnalysis::applyFunction(string functi
3607    else if(function == "log") value = log10(value);
3608  
3609    else if(function == "") value = value;
3610 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
3610 >  else{cout << "WARNING: invalid function '" << function << "'\n";}
3611  
3612    return value;
3613  
# Line 2961 | Line 3616 | OSUAnalysis::applyFunction(string functi
3616  
3617   template <class InputCollection>
3618   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
3619 <
3620 <  if (currentCut.inputCollection.find("pair")!=std::string::npos)  {
3621 <    string obj1, obj2;
3619 >
3620 >  if (currentCut.inputCollection.find("pair")!=string::npos)  {
3621 >    string obj1, obj2;
3622      getTwoObjs(currentCut.inputCollection, obj1, obj2);
3623      if (inputType==obj1 ||
3624 <        inputType==obj2) {
3624 >        inputType==obj2) {
3625        // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
3626 <      // and the inputType is a member of the pair.  
3627 <      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.  
3628 <      // For example, if currentCut.inputCollection==electron-muon pairs,
3629 <      // then the flags should not be set here when inputType==muons or inputType==electrons.  
3630 <      return;
3631 <    }  
3632 <  }    
3626 >      // and the inputType is a member of the pair.
3627 >      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
3628 >      // For example, if currentCut.inputCollection==electron-muon pairs,
3629 >      // then the flags should not be set here when inputType==muons or inputType==electrons.
3630 >      return;
3631 >    }
3632 >  }
3633  
3634    for (uint object = 0; object != inputCollection->size(); object++){
3635  
# Line 2984 | Line 3639 | void OSUAnalysis::setObjectFlags(cut &cu
3639  
3640        vector<bool> subcutDecisions;
3641        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3642 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3643 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3642 >        string stringValue = "";
3643 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3644 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3645 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3646  
3647        }
3648        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
# Line 3024 | Line 3681 | void OSUAnalysis::setObjectFlags(cut &cu
3681    bool sameObjects = false;
3682    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3683  
3684 <  // Get the strings for the two objects that make up the pair.  
3685 <  string obj1Type, obj2Type;
3684 >  // Get the strings for the two objects that make up the pair.
3685 >  string obj1Type, obj2Type;
3686    getTwoObjs(inputType, obj1Type, obj2Type);
3687    bool isTwoTypesOfObject = true;
3688 <  if (obj1Type==obj2Type) isTwoTypesOfObject = false;  
3688 >  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
3689  
3690 <  // Initialize the flags for individual objects to all be false, if the cut is on the pair.  
3691 <  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).  
3692 <  if (currentCut.inputCollection == inputType) {    
3690 >  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
3691 >  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
3692 >  if (currentCut.inputCollection == inputType) {
3693      for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
3694 <      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3694 >      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3695        cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3696      }
3697 <    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.  
3697 >    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
3698        for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
3699 <        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3700 <        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3699 >        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3700 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3701        }
3702      }
3703    }
3704 <  
3704 >
3705    int counter = 0;
3706  
3707    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
# Line 3059 | Line 3716 | void OSUAnalysis::setObjectFlags(cut &cu
3716  
3717          vector<bool> subcutDecisions;
3718          for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3719 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3720 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3719 >          string stringValue = "";
3720 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3721 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3722 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3723          }
3724  
3725          if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
# Line 3075 | Line 3734 | void OSUAnalysis::setObjectFlags(cut &cu
3734            decision = tempDecision;
3735          }
3736        }
3737 <      // if (decision) isPassObj1.at(object1) = true;
3738 <      // if (decision) isPassObj2.at(object2) = true;
3739 <      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);  
3740 <      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on  
3741 <        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;  
3742 <        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;  
3743 <      }  
3737 >      // if (decision) isPassObj1.at(object1) = true;
3738 >      // if (decision) isPassObj2.at(object2) = true;
3739 >      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3740 >      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3741 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;
3742 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;
3743 >      }
3744  
3745        //set flags for objects that pass each cut AND all the previous cuts
3746        bool previousCumulativeFlag = true;
# Line 3096 | Line 3755 | void OSUAnalysis::setObjectFlags(cut &cu
3755        else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
3756        else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
3757        cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
3758 <      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on  
3759 <        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);  
3760 <        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);  
3758 >      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3759 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);
3760 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);
3761        }
3762        counter++;
3763  
3764 <    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3765 <  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3764 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
3765 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
3766  
3767   }
3768  
3769  
3770   bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
3771 <  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
3772 <  // all cuts up to currentCutIndex  
3773 <  bool previousCumulativeFlag = true;  
3774 <  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {  
3771 >  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
3772 >  // all cuts up to currentCutIndex
3773 >  bool previousCumulativeFlag = true;
3774 >  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
3775      if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
3776 <    else {  
3777 <      previousCumulativeFlag = false; break;  
3776 >    else {
3777 >      previousCumulativeFlag = false; break;
3778      }
3779    }
3780 <  return previousCumulativeFlag;  
3781 < }  
3780 >  return previousCumulativeFlag;
3781 > }
3782 >
3783 >
3784 >
3785 > template <class InputCollection>
3786 > void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, vector<bool> flags){
3787 >  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree  
3788 >
3789 >  for (uint object = 0; object != inputCollection->size(); object++){
3790 >
3791 >    if (!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3792 >
3793 >    string inputVariable = parameters.inputVariable;
3794 >    string function = "";
3795 >    string stringValue = "";  
3796 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);  
3797 >    BNTreeBranchVals_.at(parameters.name).push_back(value);  
3798 >
3799 >  }
3800 > }
3801  
3802  
3803   template <class InputCollection>
# Line 3132 | Line 3810 | void OSUAnalysis::fill1DHistogram(TH1* h
3810      string currentString = parameters.inputVariables.at(0);
3811      string inputVariable = "";
3812      string function = "";
3813 <    if(currentString.find("(")==std::string::npos){
3813 >    if(currentString.find("(")==string::npos){
3814        inputVariable = currentString;// variable to cut on
3815      }
3816      else{
3817        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3818        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3819        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3820 <    }
3820 >    }  
3821  
3822 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
3823 <    histo->Fill(value,scaleFactor);
3822 >    string stringValue = "";  
3823 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);  
3824 >    histo->Fill(value,scaleFactor);  
3825  
3826      if (printEventInfo_) {
3827 <      // Write information about event to screen, for testing purposes.  
3828 <      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;  
3827 >      // Write information about event to screen, for testing purposes.
3828 >      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
3829      }
3830 <    
3830 >
3831    }
3832   }
3833  
# Line 3173 | Line 3852 | void OSUAnalysis::fill1DHistogram(TH1* h
3852        string currentString = parameters.inputVariables.at(0);
3853        string inputVariable = "";
3854        string function = "";
3855 <      if(currentString.find("(")==std::string::npos){
3855 >      if(currentString.find("(")==string::npos){
3856          inputVariable = currentString;// variable to cut on
3857        }
3858        else{
# Line 3182 | Line 3861 | void OSUAnalysis::fill1DHistogram(TH1* h
3861          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3862        }
3863  
3864 <      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3864 >      string stringValue = "";
3865 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3866        histo->Fill(value,scaleFactor);
3867  
3868      }
# Line 3198 | Line 3878 | void OSUAnalysis::fill2DHistogram(TH2* h
3878  
3879      if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3880  
3881 +    string stringValue = "";
3882      string currentString = parameters.inputVariables.at(0);
3883      string inputVariable = "";
3884      string function = "";
3885 <    if(currentString.find("(")==std::string::npos){
3885 >    if(currentString.find("(")==string::npos){
3886        inputVariable = currentString;// variable to cut on
3887      }
3888      else{
# Line 3209 | Line 3890 | void OSUAnalysis::fill2DHistogram(TH2* h
3890        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3891        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3892      }
3893 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
3893 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3894  
3895      currentString = parameters.inputVariables.at(1);
3896      inputVariable = "";
3897      function = "";
3898 <    if(currentString.find("(")==std::string::npos){
3898 >    if(currentString.find("(")==string::npos){
3899        inputVariable = currentString;// variable to cut on
3900      }
3901      else{
# Line 3223 | Line 3904 | void OSUAnalysis::fill2DHistogram(TH2* h
3904        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3905      }
3906  
3907 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
3907 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3908  
3909      histo->Fill(valueX,valueY,scaleFactor);
3910  
# Line 3250 | Line 3931 | void OSUAnalysis::fill2DHistogram(TH2* h
3931        if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3932        if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3933  
3934 +      string stringValue = "";
3935        string currentString = parameters.inputVariables.at(0);
3936        string inputVariable = "";
3937        string function = "";
3938 <      if(currentString.find("(")==std::string::npos){
3938 >      if(currentString.find("(")==string::npos){
3939          inputVariable = currentString;// variable to cut on
3940        }
3941        else{
# Line 3261 | Line 3943 | void OSUAnalysis::fill2DHistogram(TH2* h
3943          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3944          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3945        }
3946 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3946 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3947  
3948        currentString = parameters.inputVariables.at(1);
3949        inputVariable = "";
3950        function = "";
3951 <      if(currentString.find("(")==std::string::npos){
3951 >      if(currentString.find("(")==string::npos){
3952          inputVariable = currentString;// variable to cut on
3953        }
3954        else{
# Line 3274 | Line 3956 | void OSUAnalysis::fill2DHistogram(TH2* h
3956          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3957          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3958        }
3959 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3959 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3960  
3961  
3962        histo->Fill(valueX,valueY,scaleFactor);
# Line 3295 | Line 3977 | int OSUAnalysis::getGenMatchedParticleIn
3977  
3978      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
3979      if(currentDeltaR > 0.05) continue;
3980 <    //     cout << std::setprecision(3) << std::setw(20)
3980 >    //     cout << setprecision(3) << setw(20)
3981      //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
3982 <    //          << std::setw(20)
3982 >    //          << setw(20)
3983      //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
3984 <    //          << std::setw(20)
3984 >    //          << setw(20)
3985      //          << "\tdeltaR = " << currentDeltaR
3986 <    //          << std::setprecision(1)
3987 <    //          << std::setw(20)
3986 >    //          << setprecision(1)
3987 >    //          << setw(20)
3988      //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
3989 <    //          << std::setw(20)
3989 >    //          << setw(20)
3990      //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
3991 <    //          << std::setw(20)
3991 >    //          << setw(20)
3992      //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
3993      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
3994        bestMatchIndex = mcparticle - mcparticles->begin();
# Line 3369 | Line 4051 | int OSUAnalysis::findTauMotherIndex(cons
4051   // 20        strange baryon
4052   // 21        charm baryon
4053   // 22        bottom baryon
4054 < // 23        other
4054 > // 23        QCD string
4055 > // 24        other
4056  
4057   int OSUAnalysis::getPdgIdBinValue(int pdgId){
4058  
# Line 3393 | Line 4076 | int OSUAnalysis::getPdgIdBinValue(int pd
4076    else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4077    else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4078    else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4079 +  else if(absPdgId == 92  ) binValue = 23;
4080  
4081 <  else binValue = 23;
4081 >  else binValue = 24;
4082  
4083    return binValue;
4084  
# Line 3404 | Line 4088 | const BNprimaryvertex *
4088   OSUAnalysis::chosenVertex ()
4089   {
4090    const BNprimaryvertex *chosenVertex = 0;
4091 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
4092 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
4093 <      cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
4091 >  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4092 >    vector<bool> vertexFlags;
4093 >    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4094 >      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4095 >        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4096 >        break;
4097 >      }
4098 >    }
4099      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4100        if(!vertexFlags.at(vertexIndex)) continue;
4101        chosenVertex = & primaryvertexs->at(vertexIndex);
4102        break;
4103      }
4104    }
4105 <  else {
4106 <    chosenVertex = &primaryvertexs->at(0);
3418 <  }
4105 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4106 >    chosenVertex = & primaryvertexs->at (0);
4107  
4108    return chosenVertex;
4109   }
# Line 3424 | Line 4112 | const BNmet *
4112   OSUAnalysis::chosenMET ()
4113   {
4114    const BNmet *chosenMET = 0;
4115 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
4116 <    vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
4117 <      cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
4115 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4116 >    vector<bool> metFlags;
4117 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4118 >      if (cumulativeFlags.at("mets").at(i).size()){
4119 >        metFlags = cumulativeFlags.at("mets").at(i);
4120 >        break;
4121 >      }
4122 >    }
4123      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4124        if(!metFlags.at(metIndex)) continue;
4125        chosenMET = & mets->at(metIndex);
4126        break;
4127      }
4128    }
4129 <  else {
4130 <    chosenMET = &mets->at(0);
3438 <  }
4129 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4130 >    chosenMET = & mets->at (0);
4131  
4132    return chosenMET;
4133   }
# Line 3444 | Line 4136 | const BNelectron *
4136   OSUAnalysis::chosenElectron ()
4137   {
4138    const BNelectron *chosenElectron = 0;
4139 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
4140 <    vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
4141 <      cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
4139 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4140 >    vector<bool> electronFlags;
4141 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4142 >      if (cumulativeFlags.at("electrons").at(i).size()){
4143 >        electronFlags = cumulativeFlags.at("electrons").at(i);
4144 >        break;
4145 >      }
4146 >    }
4147      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4148        if(!electronFlags.at(electronIndex)) continue;
4149        chosenElectron = & electrons->at(electronIndex);
4150        break;
4151      }
4152    }
4153 <  else {
4154 <    chosenElectron = &electrons->at(0);
3458 <  }
4153 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4154 >    chosenElectron = & electrons->at (0);
4155  
4156    return chosenElectron;
4157   }
# Line 3464 | Line 4160 | const BNmuon *
4160   OSUAnalysis::chosenMuon ()
4161   {
4162    const BNmuon *chosenMuon = 0;
4163 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
4164 <    vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
4165 <      cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
4163 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4164 >    vector<bool> muonFlags;
4165 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4166 >      if (cumulativeFlags.at("muons").at(i).size()){
4167 >        muonFlags = cumulativeFlags.at("muons").at(i);
4168 >        break;
4169 >      }
4170 >    }
4171      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4172        if(!muonFlags.at(muonIndex)) continue;
4173        chosenMuon = & muons->at(muonIndex);
4174        break;
4175      }
4176    }
4177 <  else {
4178 <    chosenMuon = &muons->at(0);
3478 <  }
4177 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4178 >    chosenMuon = & muons->at (0);
4179  
4180    return chosenMuon;
4181   }
4182  
3483
4183   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines