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.78 by wulsin, Fri May 31 14:07:11 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 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
406 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
407 +        vector<float> newVec;  
408 +        BNTreeBranchVals_[currentVar.name] = newVec;  
409 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
410 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
411 +
412 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
413 +
414 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
415 +        int numBinsElements = currentHistogram.bins.size();
416 +        int numInputVariables = currentHistogram.inputVariables.size();
417 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
418 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
419 +        
420 +        if(numBinsElements == 1){
421 +          if(numBinEdgesX > 1){
422 +            if(numBinEdgesY > 1)
423 +              numBinsElements = 6;
424 +            else
425 +              numBinsElements = 3;
426 +          }
427 +        }
428 +        if(numBinsElements != 3 && numBinsElements !=6){
429 +          cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
430 +          exit(0);
431 +        }
432 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
433 +          cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
434 +          exit(0);
435 +        }
436 +        else if(numBinsElements == 3){
437 +          if (currentHistogram.bins.size () == 3)
438 +            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));
439 +          else
440 +            {
441 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
442 +            }
443 +        }
444 +        else if(numBinsElements == 6){
445 +          if (currentHistogram.bins.size () == 6)
446 +            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));
447 +          else
448 +            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 ());
449 +        }
450 +
451 +
452 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
453 +
454 +        // bin      particle type
455 +        // ---      -------------
456 +        //  0        unmatched
457 +        //  1        u
458 +        //  2        d
459 +        //  3        s
460 +        //  4        c
461 +        //  5        b
462 +        //  6        t
463 +        //  7        e
464 +        //  8        mu
465 +        //  9        tau
466 +        // 10        nu
467 +        // 11        g
468 +        // 12        gamma
469 +        // 13        Z
470 +        // 14        W
471 +        // 15        light meson
472 +        // 16        K meson
473 +        // 17        D meson
474 +        // 18        B meson
475 +        // 19        light baryon
476 +        // 20        strange baryon
477 +        // 21        charm baryon
478 +        // 22        bottom baryon
479 +        // 23        QCD string
480 +        // 24        other
481 +
482 +        vector<TString> labelArray;
483 +        labelArray.push_back("unmatched");
484 +        labelArray.push_back("u");
485 +        labelArray.push_back("d");
486 +        labelArray.push_back("s");
487 +        labelArray.push_back("c");
488 +        labelArray.push_back("b");
489 +        labelArray.push_back("t");
490 +        labelArray.push_back("e");
491 +        labelArray.push_back("#mu");
492 +        labelArray.push_back("#tau");
493 +        labelArray.push_back("#nu");
494 +        labelArray.push_back("g");
495 +        labelArray.push_back("#gamma");
496 +        labelArray.push_back("Z");
497 +        labelArray.push_back("W");
498 +        labelArray.push_back("light meson");
499 +        labelArray.push_back("K meson");
500 +        labelArray.push_back("D meson");
501 +        labelArray.push_back("B meson");
502 +        labelArray.push_back("light baryon");
503 +        labelArray.push_back("strange baryon");
504 +        labelArray.push_back("charm baryon");
505 +        labelArray.push_back("bottom baryon");
506 +        labelArray.push_back("QCD string");
507 +        labelArray.push_back("other");
508 +
509 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
510 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
511 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
512 +          }
513 +          else {
514 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
515 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
516 +          }
517 +        }
518 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
519 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
520 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
521 +        }
522 +
523 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
524 +
525 +
526 +      // Book a histogram for the number of each object type to be plotted.
527 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
528 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
529 +        string currentObject = objectsToPlot.at(currentObjectIndex);
530 +        int maxNum = 10;
531 +        if(currentObject == "mcparticles") maxNum = 50;
532 +        else if(currentObject == "primaryvertexs") maxNum = 50;
533 +
534 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
535 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
536 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
537 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
538 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
539 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
540 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
541 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
542 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
543 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
544 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
545 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
546 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
547 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
548 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
549 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
550 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
551 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
552 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
553 +
554 +        currentObject.at(0) = toupper(currentObject.at(0));
555 +        string histoName = "num" + currentObject;
556 +
557 +        if(histoName == "numPrimaryvertexs"){
558 +          string newHistoName = histoName + "BeforePileupCorrection";
559 +          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);
560 +          newHistoName = histoName + "AfterPileupCorrection";
561 +          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);
562 +        }
563 +        else
564 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
565 +      }
566 +    }//end of loop over directories
567      channels.push_back(tempChannel);
568      tempChannel.cuts.clear();
446
569    }//end loop over channels
570  
571  
# Line 472 | Line 594 | OSUAnalysis::analyze (const edm::Event &
594  
595    // Retrieve necessary collections from the event.
596  
597 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
597 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
598      event.getByLabel (triggers_, triggers);
599  
600 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
600 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
601 >    event.getByLabel (trigobjs_, trigobjs);
602 >
603 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
604      event.getByLabel (jets_, jets);
605  
606 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
606 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
607      event.getByLabel (muons_, muons);
608  
609 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
609 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
610      event.getByLabel (electrons_, electrons);
611  
612 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
612 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
613      event.getByLabel (events_, events);
614  
615 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
615 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
616      event.getByLabel (taus_, taus);
617  
618 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
618 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
619      event.getByLabel (mets_, mets);
620  
621 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
621 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
622      event.getByLabel (tracks_, tracks);
623  
624 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
624 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
625      event.getByLabel (genjets_, genjets);
626  
627 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
627 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
628      event.getByLabel (mcparticles_, mcparticles);
629  
630 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
630 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
631      event.getByLabel (primaryvertexs_, primaryvertexs);
632  
633 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
633 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
634      event.getByLabel (bxlumis_, bxlumis);
635  
636 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
636 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
637      event.getByLabel (photons_, photons);
638  
639 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
639 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
640      event.getByLabel (superclusters_, superclusters);
641  
642 <  if (useTrackCaloRhoCorr_) {  
643 <    // Used only for pile-up correction of by-hand calculation of isolation energy.  
644 <    // This rho collection is not available in all BEANs.  
642 >  if (datasetType_ == "signalMC"){
643 >    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
644 >      event.getByLabel (stops_, stops);
645 >  }
646 >
647 >  if (useTrackCaloRhoCorr_) {
648 >    // Used only for pile-up correction of by-hand calculation of isolation energy.
649 >    // This rho collection is not available in all BEANs.
650      // For description of rho values for different jet reconstruction algorithms, see
651 <    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms  
652 <    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
651 >    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
652 >    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
653    }
654  
655 +  double masterScaleFactor = 1.0;
656  
657    //get pile-up event weight
658 <  double scaleFactor = 1.00;
659 <  if(doPileupReweighting_ && datasetType_ != "data")
660 <    scaleFactor = puWeight_->at (events->at (0).numTruePV);
661 <
662 <  cTauScaleFactor_ = 1.0;
663 < #ifdef DISPLACED_SUSY
664 <  if (datasetType_ == "signalMC")
665 <    cTauScaleFactor_ = cTauWeight_->at (event);
666 < #endif
667 <  scaleFactor *= cTauScaleFactor_;
658 >  if (doPileupReweighting_ && datasetType_ != "data") {
659 >    //for "data" datasets, the numTruePV is always set to -1
660 >    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;  
661 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);  
662 >  }
663 >
664 >  stopCTauScaleFactor_ = 1.0;
665 >  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
666 >    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
667 >  masterScaleFactor *= stopCTauScaleFactor_;
668  
669    //loop over all channels
670  
# Line 544 | Line 675 | OSUAnalysis::analyze (const edm::Event &
675      counterMap passingCounter;
676      cumulativeFlags.clear ();
677  
678 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
679 +         iter != BNTreeBranchVals_.end(); iter++) {
680 +      iter->second.clear();  // clear array
681 +    }
682 +
683      bool triggerDecision = true;
684 <    if(currentChannel.triggers.size() != 0){  //triggers specified
685 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
684 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
685 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
686        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
687      }
688  
689      //loop over all cuts
554
555
556
690      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
691        cut currentCut = currentChannel.cuts.at(currentCutIndex);
559
692        for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
693          string currentObject = objectsToCut.at(currentObjectIndex);
694  
# Line 571 | Line 703 | OSUAnalysis::analyze (const edm::Event &
703          int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
704  
705  
706 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
707 <
708 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
577 <
706 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
707 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
708 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
709          else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
710 +        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
711          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
712          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
713          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 587 | Line 719 | OSUAnalysis::analyze (const edm::Event &
719          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
720          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
721          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
722 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
723 +
724  
725  
726          else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
# Line 595 | Line 729 | OSUAnalysis::analyze (const edm::Event &
729                                                                     "muon-muon pairs");
730  
731          else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
732 <                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
733 <                                                                   cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
734 <                                                                   "muon-secondary muon pairs");
732 >                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
733 >                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
734 >                                                                             "muon-secondary muon pairs");
735 >
736 >        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
737 >                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
738 >                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
739 >                                                                                     "electron-secondary electron pairs");
740  
741          else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
742                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
# Line 607 | Line 746 | OSUAnalysis::analyze (const edm::Event &
746                                                                         cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
747                                                                         cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
748                                                                         "electron-muon pairs");
749 <        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
750 <                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
751 <                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
752 <                                                                     "track-event pairs");
753 <        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
754 <                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
755 <                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
756 <                                                                        "electron-track pairs");
757 <        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
758 <                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
759 <                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
760 <                                                                    "muon-track pairs");
761 <        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
762 <                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
763 <                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
764 <                                                                  "muon-tau pairs");
765 <        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
766 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
767 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
768 <                                                                 "tau-tau pairs");
769 <        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
749 >        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
750 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
751 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
752 >                                                                 "jet-jet pairs");
753 >        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
754 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
755 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
756 >                                                                      "electron-jet pairs");
757 >        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
758 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
759 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
760 >                                                                  "muon-jet pairs");
761 >        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
762 >                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
763 >                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
764 >                                                                     "track-event pairs");
765 >        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
766 >                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
767 >                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
768 >                                                                        "electron-track pairs");
769 >        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
770 >                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
771 >                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
772 >                                                                    "muon-track pairs");
773 >        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
774 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
775 >                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
776 >                                                                  "muon-tau pairs");
777 >        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
778                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
779 <                                                                 cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
780 <                                                                 "tau-track pairs");
781 <        
782 <        
779 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
780 >                                                                 "tau-tau pairs");
781 >        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
782 >                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
783 >                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
784 >                                                                   "tau-track pairs");
785 >        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
786 >                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
787 >                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
788 >                                                                          "electron-trigobj pairs");
789 >        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
790 >                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
791 >                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
792 >                                                                      "muon-trigobj pairs");
793 >
794 >        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
795        }
796  
797  
798  
799      }//end loop over all cuts
641
642
800      //use cumulative flags to apply cuts at event level
801  
802      bool eventPassedAllCuts = true;
803 <
803 >    //a vector to store cumulative cut descisions after each cut.
804 >    vector<bool> eventPassedPreviousCuts;
805      //apply trigger (true if none were specified)
806      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
807  
650
808      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
809  
810        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 655 | Line 812 | OSUAnalysis::analyze (const edm::Event &
812        int numberPassing = 0;
813  
814        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
815 <        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
815 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
816        }
817        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
818        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
819        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
820 <
820 >      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
821      }
822 +    double scaleFactor = masterScaleFactor;
823  
824 <    //     if(datasetType_ != "data") {
825 <    //       scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
826 <    //       scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
827 <    //     }
824 >    muonScaleFactor_ = electronScaleFactor_ = 1.0;
825 >    if(applyLeptonSF_ && datasetType_ != "data"){
826 >      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
827 >        vector<bool> muonFlags;
828 >        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
829 >          if (cumulativeFlags.at("muons").at(i).size()){
830 >            muonFlags = cumulativeFlags.at("muons").at(i);
831 >            break;
832 >          }
833 >        }
834 >        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
835 >          if(!muonFlags.at(muonIndex)) continue;
836 >          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
837 >        }
838 >      }
839 >      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
840 >        vector<bool> electronFlags;
841 >        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
842 >          if (cumulativeFlags.at("electrons").at(i).size()){
843 >            electronFlags = cumulativeFlags.at("electrons").at(i);
844 >            break;
845 >          }
846 >        }
847 >        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
848 >          if(!electronFlags.at(electronIndex)) continue;
849 >          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
850 >        }
851 >      }
852 >    }
853 >    scaleFactor *= muonScaleFactor_;
854 >    scaleFactor *= electronScaleFactor_;
855  
856      cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
857  
673
674
675    if(!eventPassedAllCuts)continue;
676
858      if (printEventInfo_) {
859 <      // Write information about event to screen, for testing purposes.  
860 <      cout << "Event passed all cuts in channel " <<  currentChannel.name
861 <           << ": run="  << events->at(0).run
862 <           << "  lumi=" << events->at(0).lumi
863 <           << "  event=" << events->at(0).evt
864 <           << endl;  
859 >      // Write information about event to screen, for testing purposes.
860 >      cout << "Event passed all cuts in channel " <<  currentChannel.name
861 >           << ": run="  << events->at(0).run
862 >           << "  lumi=" << events->at(0).lumi
863 >           << "  event=" << events->at(0).evt
864 >           << endl;
865      }
866  
867  
868      //filling histograms
869 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
870 <      histogram currentHistogram = histograms.at(histogramIndex);
871 <
872 <      if(currentHistogram.inputVariables.size() == 1){
873 <        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);
869 >    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
870 >      uint currentDir;
871 >      if(!GetPlotsAfterEachCut_){ currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size();}//if GetPlotsAfterEachCut_ is true, set currentDir point to the lat cut.
872 >      else{
873 >        currentDir = currentCut;
874        }
875 <    }
875 >      if(eventPassedPreviousCuts.at(currentDir)){
876  
877 +        // Assign BNTree variables
878 +        for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
879 +          BranchSpecs brSpecs = treeBranches_.at(iBranch);  
880 +          string coll = brSpecs.inputCollection;  
881 +          if (cumulativeFlags.count(coll) == 0) cout << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
882 +
883 +          if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).at(currentDir));            
884 +          else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).at(currentDir));
885 +          else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).at(currentDir));        
886 +          else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).at(currentDir));
887 +          else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).at(currentDir));
888 +          else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).at(currentDir));
889 +          else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).at(currentDir));
890 +          else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).at(currentDir));
891 +          else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).at(currentDir));
892 +          else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).at(currentDir));
893 +          else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).at(currentDir));
894 +          else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).at(currentDir));
895 +          else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).at(currentDir));
896 +          else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).at(currentDir));
897 +          else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).at(currentDir));
898 +          else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).at(currentDir));
899 +          else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).at(currentDir));
900 +          else if(coll == "stops"
901 +                  && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).at(currentDir));
902 +        } // end loop over branches  
903 +                                                                                          
904 +        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
905 +          histogram currentHistogram = histograms.at(histogramIndex);
906 +
907 +          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) cout << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
908 +
909 +          if(currentHistogram.inputVariables.size() == 1){
910 +            TH1D* histo;  
911 +            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
912 +            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
913 +            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
914 +            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
915 +            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
916 +            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
917 +            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
918 +                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
919 +                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
920 +            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
921 +                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
922 +                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
923 +            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
924 +            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
925 +                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
926 +                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
927 +            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
928 +                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
929 +                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
930 +            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
931 +                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
932 +                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
933 +            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
934 +                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
935 +                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
936 +            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
937 +                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
938 +                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
939 +            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
940 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
941 +                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
942 +            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
943 +                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
944 +                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
945 +            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
946 +                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
947 +                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
948 +            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
949 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
950 +                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
951 +            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
952 +                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
953 +                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
954 +            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
955 +                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
956 +                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
957 +            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
958 +                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
959 +                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
960 +            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
961 +                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
962 +                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
963 +
964 +            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
965 +            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
966 +            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
967 +            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
968 +            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
969 +            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
970 +            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
971 +            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
972 +            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
973 +            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
974 +            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
975 +            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
976 +          }
977 +          else if(currentHistogram.inputVariables.size() == 2){
978 +            TH2D* histo;
979 +            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
980 +            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
981 +            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
982 +            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
983 +            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
984 +            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
985 +                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
986 +                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
987 +            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
988 +                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
989 +                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
990 +            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
991 +            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
992 +            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
993 +                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
994 +                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
995 +            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
996 +                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
997 +                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
998 +            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
999 +                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1000 +                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1001 +            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1002 +                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1003 +                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1004 +            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1005 +                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1006 +                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1007 +            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1008 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1009 +                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1010 +            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1011 +                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1012 +                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1013 +            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1014 +                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1015 +                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1016 +            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1017 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1018 +                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1019 +            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1020 +                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1021 +                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1022 +            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1023 +                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1024 +                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1025 +            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1026 +                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1027 +                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1028 +            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1029 +                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1030 +                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1031 +            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1032 +            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1033 +            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1034 +            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1035 +            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1036 +                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1037 +                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1038 +            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1039 +            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1040 +            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1041 +            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1042 +            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1043 +            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1044 +            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1045 +            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1046 +          }
1047 +          
1048 +        }
1049  
1050  
1051 <    //fills histograms with the sizes of collections
1052 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1053 <
1054 <      string currentObject = objectsToPlot.at(currentObjectIndex);
1055 <
1056 <      string objectToPlot = "";  
1057 <
1058 <      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().  
1059 <      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
1060 <      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
1061 <      else if(currentObject == "electron-muon pairs")     objectToPlot = "electronMuonPairs";
1062 <      else if(currentObject == "electron-track pairs")    objectToPlot = "electronTrackPairs";
1063 <      else if(currentObject == "muon-track pairs")        objectToPlot = "muonTrackPairs";      
1064 <      else if(currentObject == "muon-tau pairs")          objectToPlot = "muonTauPairs";        
1065 <      else if(currentObject == "tau-tau pairs")           objectToPlot = "ditauPairs";
1066 <      else if(currentObject == "tau-track pairs")         objectToPlot = "tauTrackPairs";
1067 <      else if(currentObject == "track-event pairs")       objectToPlot = "trackEventPairs";  
1068 <      else if(currentObject == "muon-secondary muon pairs")       objectToPlot = "muonSecondaryMuonPairs";  
1069 <      else if(currentObject == "secondary muons")         objectToPlot = "secondaryMuons";  
1070 <      else objectToPlot = currentObject;
1071 <
1072 <      string tempCurrentObject = objectToPlot;
1073 <      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));  
1074 <      string histoName = "num" + tempCurrentObject;
1075 <
1076 <      //set position of primary vertex in event, in order to calculate quantities relative to it
1077 <      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1078 <        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
1079 <        int numToPlot = 0;
1080 <        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1081 <          if(lastCutFlags.at(currentFlag)) numToPlot++;
1082 <        }
1083 <        if(objectToPlot == "primaryvertexs"){
1084 <          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1085 <          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1086 <        }
1087 <        else {
1088 <          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
1089 <        }
1090 <      }
1091 <      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
1092 <      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
1093 <      else if(objectToPlot == "secondaryMuons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
1094 <      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
1095 <      else if(objectToPlot == "muonSecondaryMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
1096 <      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
1097 <      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
1098 <      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
1099 <      else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
1100 <      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 <      }
1051 >        //fills histograms with the sizes of collections
1052 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1053 >
1054 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1055 >          string objectToPlot = "";
1056 >
1057 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1058 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1059 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1060 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1061 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1062 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1063 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1064 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1065 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1066 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1067 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1068 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1069 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1070 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1071 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1072 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1073 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1074 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1075 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1076 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1077 >          else objectToPlot = currentObject;
1078 >
1079 >          string tempCurrentObject = objectToPlot;
1080 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1081 >          string histoName = "num" + tempCurrentObject;
1082 >
1083 >          //set position of primary vertex in event, in order to calculate quantities relative to it
1084 >          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1085 >            vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1086 >            int numToPlot = 0;
1087 >            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1088 >              if(lastCutFlags.at(currentFlag)) numToPlot++;
1089 >            }
1090 >            if(objectToPlot == "primaryvertexs"){
1091 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1092 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1093 >            }
1094 >            else {
1095 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1096 >            }
1097 >          }
1098 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1099 >      } // end if(eventPassedPreviousCuts.at(currentDir)){
1100 >    } // end loop over cuts
1101  
1102 <    } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1102 >    BNTrees_.at(currentChannelIndex)->Fill();  
1103  
1104 <  } //end loop over channel
1104 >  } // end loop over channel
1105 >
1106 >  masterCutFlow_->fillCutFlow(masterScaleFactor);
1107  
858  masterCutFlow_->fillCutFlow(scaleFactor);
1108  
1109   } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1110  
# Line 872 | Line 1121 | OSUAnalysis::evaluateComparison (double
1121    else if(comparison == "==") return testValue == cutValue;
1122    else if(comparison == "=") return testValue == cutValue;
1123    else if(comparison == "!=") return testValue != cutValue;
1124 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1124 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1125 >
1126 > }
1127 >
1128 > bool
1129 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1130 >
1131 >
1132 >  if(comparison == ">")       return testValue >  cutValue;
1133 >  else if(comparison == ">=") return testValue >= cutValue;
1134 >  else if(comparison == "<")  return testValue <  cutValue;
1135 >  else if(comparison == "<=") return testValue <= cutValue;
1136 >  else if(comparison == "==") return testValue == cutValue;
1137 >  else if(comparison == "=") return testValue == cutValue;
1138 >  else if(comparison == "!=") return testValue != cutValue;
1139 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1140  
1141   }
1142  
1143   bool
1144 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1144 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1145  
1146 +  //initialize to false until a chosen trigger is passed
1147    bool triggerDecision = false;
1148  
1149 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1150 <    {
886 <      if(trigger->pass != 1) continue;
887 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
888 <        {
889 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
890 <            triggerDecision = true;
891 <          }
892 <        }
893 <    }
894 <  return triggerDecision;
1149 >  //loop over all triggers defined in the event
1150 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1151  
1152 +    //we're only interested in triggers that actually passed
1153 +    if(trigger->pass != 1) continue;
1154 +
1155 +    //if the event passes one of the veto triggers, exit and return false
1156 +    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1157 +      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1158 +    }
1159 +    //if the event passes one of the chosen triggers, set triggerDecision to true
1160 +    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1161 +      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1162 +    }  
1163 +  }
1164 +  //if none of the veto triggers fired:
1165 +  //return the OR of all the chosen triggers
1166 +  if (triggersToTest.size() != 0) return triggerDecision;
1167 +  //or if no triggers were defined return true
1168 +  else return true;
1169   }
1170  
1171 < std::vector<std::string>
1171 >
1172 > vector<string>
1173   OSUAnalysis::splitString (string inputString){
1174  
1175 <  std::stringstream stringStream(inputString);
1176 <  std::istream_iterator<std::string> begin(stringStream);
1177 <  std::istream_iterator<std::string> end;
1178 <  std::vector<std::string> stringVector(begin, end);
1175 >  stringstream stringStream(inputString);
1176 >  istream_iterator<string> begin(stringStream);
1177 >  istream_iterator<string> end;
1178 >  vector<string> stringVector(begin, end);
1179    return stringVector;
1180  
1181   }
1182  
1183  
1184   void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1185 <  // Set two object strings from the tempInputCollection string,
1186 <  // For example, if tempInputCollection is "electron-muon pairs",
1187 <  // then obj1 = "electrons" and obj2 = "muons".  
1188 <  // Note that the objects have an "s" appended.  
1185 >  // Set two object strings from the tempInputCollection string,
1186 >  // For example, if tempInputCollection is "electron-muon pairs",
1187 >  // then obj1 = "electrons" and obj2 = "muons".
1188 >  // Note that the objects have an "s" appended.
1189  
1190    int dashIndex = tempInputCollection.find("-");
1191    int spaceIndex = tempInputCollection.find_last_of(" ");
1192    int secondWordLength = spaceIndex - dashIndex;
1193 <  obj1 = tempInputCollection.substr(0,dashIndex) + "s";  
1193 >  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1194    obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1195 <  
1196 < }
1195 >
1196 > }
1197  
1198  
1199   string OSUAnalysis::getObjToGet(string obj) {
1200    // Return the string corresponding to the object to get for the given obj string.
1201 <  // Right now this only handles the case in which obj contains "secondary",
1202 <  // e.g, "secondary muons".  
1203 <  // 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);
1201 >  // Right now this only handles the case in which obj contains "secondary",
1202 >  // e.g, "secondary muons".
1203 >  // Note that "s" is NOT appended.
1204  
1205 < }  
1205 >  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1206 >  int firstSpaceIndex = obj.find_first_of(" ");
1207 >  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1208  
1209 + }
1210  
1211  
1212 + //!jet valueLookup
1213   double
1214 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1214 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1215  
1216    double value = 0.0;
1217    if(variable == "energy") value = object->energy;
# Line 1057 | Line 1331 | OSUAnalysis::valueLookup (const BNjet* o
1331    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1332  
1333  
1334 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1334 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1335  
1336    value = applyFunction(function, value);
1337  
# Line 1065 | Line 1339 | OSUAnalysis::valueLookup (const BNjet* o
1339   }
1340  
1341  
1342 <
1342 > //!muon valueLookup
1343   double
1344 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1344 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1345  
1346    double value = 0.0;
1347    if(variable == "energy") value = object->energy;
# Line 1228 | Line 1502 | OSUAnalysis::valueLookup (const BNmuon*
1502    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1503    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1504    else if(variable == "metMT") {
1505 <    const BNmet *met = chosenMET ();
1232 <    if (met)
1505 >    if (const BNmet *met = chosenMET ())
1506        {
1507 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1508 <          p2 (met->px, met->py, 0.0, met->pt);
1236 <
1237 <        value = (p1 + p2).Mt ();
1507 >        double dPhi = deltaPhi (object->phi, met->phi);
1508 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1509        }
1510      else
1511        value = -999;
# Line 1352 | Line 1623 | OSUAnalysis::valueLookup (const BNmuon*
1623      value = object->isGlobalMuon > 0                \
1624        && object->isPFMuon > 0                        \
1625        && object->normalizedChi2 < 10                \
1626 <                                  && object->numberOfValidMuonHits > 0        \
1626 >      && object->numberOfValidMuonHits > 0        \
1627        && object->numberOfMatchedStations > 1        \
1628        && fabs(object->correctedD0Vertex) < 0.2        \
1629        && fabs(object->correctedDZ) < 0.5        \
# Line 1361 | Line 1632 | OSUAnalysis::valueLookup (const BNmuon*
1632    }
1633    else if(variable == "tightIDdisplaced"){
1634      value = object->isGlobalMuon > 0                \
1635 +      && object->isPFMuon > 0                        \
1636        && object->normalizedChi2 < 10                \
1637 <                                  && object->numberOfValidMuonHits > 0        \
1637 >      && object->numberOfValidMuonHits > 0        \
1638        && object->numberOfMatchedStations > 1        \
1639        && object->numberOfValidPixelHits > 0        \
1640        && object->numberOfLayersWithMeasurement > 5;
1641    }
1642  
1643 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1643 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1644  
1645    else if(variable == "genMatchedPdgId"){
1646      int index = getGenMatchedParticleIndex(object);
# Line 1388 | Line 1660 | OSUAnalysis::valueLookup (const BNmuon*
1660    }
1661    else if(variable == "genMatchedMotherIdReverse"){
1662      int index = getGenMatchedParticleIndex(object);
1663 <    if(index == -1) value = 23;
1664 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1663 >    if(index == -1) value = 24;
1664 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1665    }
1666    else if(variable == "genMatchedGrandmotherId"){
1667      int index = getGenMatchedParticleIndex(object);
# Line 1401 | Line 1673 | OSUAnalysis::valueLookup (const BNmuon*
1673      }
1674      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1675    }
1676 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1677 +    int index = getGenMatchedParticleIndex(object);
1678 +    if(index == -1) value = 24;
1679 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1680 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1681 +      if(motherIndex == -1) value = 24;
1682 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1683 +    }
1684 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1685 +  }
1686 +  else if(variable == "pfMuonsFromVertex"){
1687 +    double d0Error, dzError;
1688  
1689 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1690 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1691 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1692 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1693 +      || fabs (object->correctedDZ / dzError) > 99.0;
1694 +    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1695 +  }
1696  
1697  
1698 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1698 >
1699 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1700  
1701    value = applyFunction(function, value);
1702  
1703    return value;
1704   }
1705  
1706 <
1706 > //!electron valueLookup
1707   double
1708 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1708 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1709  
1710    double value = 0.0;
1711    if(variable == "energy") value = object->energy;
# Line 1579 | Line 1871 | OSUAnalysis::valueLookup (const BNelectr
1871    else if(variable == "detIso") value = (object->trackIso) / object->pt;
1872    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1873    else if(variable == "metMT") {
1874 <    const BNmet *met = chosenMET ();
1583 <    if (met)
1874 >    if (const BNmet *met = chosenMET ())
1875        {
1876 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1877 <          p2 (met->px, met->py, 0.0, met->pt);
1587 <
1588 <        value = (p1 + p2).Mt ();
1876 >        double dPhi = deltaPhi (object->phi, met->phi);
1877 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1878        }
1879      else
1880        value = -999;
# Line 1750 | Line 2039 | OSUAnalysis::valueLookup (const BNelectr
2039    }
2040  
2041  
2042 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2042 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2043  
2044    else if(variable == "genMatchedPdgId"){
2045      int index = getGenMatchedParticleIndex(object);
# Line 1771 | Line 2060 | OSUAnalysis::valueLookup (const BNelectr
2060    }
2061    else if(variable == "genMatchedMotherIdReverse"){
2062      int index = getGenMatchedParticleIndex(object);
2063 <    if(index == -1) value = 23;
2064 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2063 >    if(index == -1) value = 24;
2064 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2065    }
2066    else if(variable == "genMatchedGrandmotherId"){
2067      int index = getGenMatchedParticleIndex(object);
# Line 1784 | Line 2073 | OSUAnalysis::valueLookup (const BNelectr
2073      }
2074      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2075    }
2076 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2077 +    int index = getGenMatchedParticleIndex(object);
2078 +    if(index == -1) value = 24;
2079 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2080 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2081 +      if(motherIndex == -1) value = 24;
2082 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2083 +    }
2084 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2085 +  }
2086 +  else if(variable == "pfElectronsFromVertex"){
2087 +    double d0Error, dzError;
2088  
2089 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2090 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2091 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2092 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2093 +      || fabs (object->correctedDZ / dzError) > 99.0;
2094 +    value = !value;
2095 +  }
2096  
2097  
2098 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2098 >
2099 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2100  
2101    value = applyFunction(function, value);
2102  
2103    return value;
2104   }
2105  
2106 <
2106 > //!event valueLookup
2107   double
2108 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2108 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2109  
2110    double value = 0.0;
2111  
# Line 1865 | Line 2174 | OSUAnalysis::valueLookup (const BNevent*
2174    else if(variable == "id2") value = object->id2;
2175    else if(variable == "evt") value = object->evt;
2176    else if(variable == "puScaleFactor"){
2177 <    if(datasetType_ != "data")
2177 >    if(doPileupReweighting_ && datasetType_ != "data")
2178        value = puWeight_->at (events->at (0).numTruePV);
2179      else
2180        value = 1.0;
2181    }
2182 <  else if(variable == "muonScaleFactor"){
2183 <    if(datasetType_ != "data")
2184 <      //      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_;
2182 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2183 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2184 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2185  
2186 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2186 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2187  
2188    value = applyFunction(function, value);
2189  
2190    return value;
2191   }
2192  
2193 + //!tau valueLookup
2194   double
2195 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2195 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2196  
2197    double value = 0.0;
2198  
# Line 1941 | Line 2238 | OSUAnalysis::valueLookup (const BNtau* o
2238  
2239  
2240  
2241 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2241 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2242  
2243    else if(variable == "genMatchedPdgId"){
2244      int index = getGenMatchedParticleIndex(object);
# Line 1961 | Line 2258 | OSUAnalysis::valueLookup (const BNtau* o
2258    }
2259    else if(variable == "genMatchedMotherIdReverse"){
2260      int index = getGenMatchedParticleIndex(object);
2261 <    if(index == -1) value = 23;
2262 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2261 >    if(index == -1) value = 24;
2262 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2263    }
2264    else if(variable == "genMatchedGrandmotherId"){
2265      int index = getGenMatchedParticleIndex(object);
# Line 1974 | Line 2271 | OSUAnalysis::valueLookup (const BNtau* o
2271      }
2272      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2273    }
2274 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2275 +    int index = getGenMatchedParticleIndex(object);
2276 +    if(index == -1) value = 24;
2277 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2278 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2279 +      if(motherIndex == -1) value = 24;
2280 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2281 +    }
2282 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2283 +  }
2284  
2285  
2286 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2286 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2287  
2288    value = applyFunction(function, value);
2289  
2290    return value;
2291   }
2292  
2293 + //!met valueLookup
2294   double
2295 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2295 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2296  
2297    double value = 0.0;
2298  
# Line 2048 | Line 2356 | OSUAnalysis::valueLookup (const BNmet* o
2356    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2357    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2358  
2359 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2359 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2360  
2361    value = applyFunction(function, value);
2362  
2363    return value;
2364   }
2365  
2366 + //!track valueLookup
2367   double
2368 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2368 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2369  
2370    double value = 0.0;
2371    double pMag = sqrt(object->pt * object->pt +
2372 <                     object->pz * object->pz);
2373 <  
2372 >                     object->pz * object->pz);
2373 >
2374    if(variable == "pt") value = object->pt;
2375    else if(variable == "px") value = object->px;
2376    else if(variable == "py") value = object->py;
# Line 2082 | Line 2391 | OSUAnalysis::valueLookup (const BNtrack*
2391  
2392  
2393    //additional BNs info for disappTrks
2085  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2394    else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2395    else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2396    else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2397    else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2398    else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2399    else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2400 +  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2401    else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2402    else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2403    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2404 <  
2404 >  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2405  
2406    //user defined variables
2407    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;
2408    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2409 +  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2410    else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2411    else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2412 <  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);  
2413 <  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;  
2412 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2413 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2414    else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2415    else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2416    else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2417    else if(variable == "ptError")                    value = object->ptError;
2418    else if(variable == "ptRes")                      value = getTrkPtRes(object);
2419 <  else if (variable == "d0wrtPV"){      
2420 <    double vx = object->vx - chosenVertex ()->x,        
2421 <      vy = object->vy - chosenVertex ()->y,      
2422 <      px = object->px,  
2423 <      py = object->py,  
2424 <      pt = object->pt;  
2425 <    value = (-vx * py + vy * px) / pt;  
2426 <  }      
2427 <  else if (variable == "dZwrtPV"){      
2428 <    double vx = object->vx - chosenVertex ()->x,        
2429 <      vy = object->vy - chosenVertex ()->y,      
2430 <      vz = object->vz - chosenVertex ()->z,      
2431 <      px = object->px,  
2432 <      py = object->py,  
2433 <      pz = object->pz,  
2434 <      pt = object->pt;  
2435 <    value = vz - (vx * px + vy * py)/pt * (pz/pt);      
2436 <  }    
2437 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2419 >  else if (variable == "d0wrtPV"){
2420 >    double vx = object->vx - chosenVertex ()->x,
2421 >      vy = object->vy - chosenVertex ()->y,
2422 >      px = object->px,
2423 >      py = object->py,
2424 >      pt = object->pt;
2425 >    value = (-vx * py + vy * px) / pt;
2426 >  }
2427 >  else if (variable == "dZwrtPV"){
2428 >    double vx = object->vx - chosenVertex ()->x,
2429 >      vy = object->vy - chosenVertex ()->y,
2430 >      vz = object->vz - chosenVertex ()->z,
2431 >      px = object->px,
2432 >      py = object->py,
2433 >      pz = object->pz,
2434 >      pt = object->pt;
2435 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2436 >  }
2437 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2438  
2439    else if(variable == "genMatchedPdgId"){
2440      int index = getGenMatchedParticleIndex(object);
# Line 2145 | Line 2455 | OSUAnalysis::valueLookup (const BNtrack*
2455    }
2456    else if(variable == "genMatchedMotherIdReverse"){
2457      int index = getGenMatchedParticleIndex(object);
2458 <    if(index == -1) value = 23;
2459 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2458 >    if(index == -1) value = 24;
2459 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2460    }
2461    else if(variable == "genMatchedGrandmotherId"){
2462      int index = getGenMatchedParticleIndex(object);
# Line 2158 | Line 2468 | OSUAnalysis::valueLookup (const BNtrack*
2468      }
2469      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2470    }
2471 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2472 +    int index = getGenMatchedParticleIndex(object);
2473 +    if(index == -1) value = 24;
2474 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2475 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2476 +      if(motherIndex == -1) value = 24;
2477 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2478 +    }
2479 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2480 +  }
2481  
2482  
2483  
2484 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2484 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2485  
2486    value = applyFunction(function, value);
2487  
2488    return value;
2489   }
2490  
2491 + //!genjet valueLookup
2492   double
2493 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2493 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2494  
2495    double value = 0.0;
2496  
# Line 2189 | Line 2510 | OSUAnalysis::valueLookup (const BNgenjet
2510    else if(variable == "charge") value = object->charge;
2511  
2512  
2513 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2513 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2514  
2515    value = applyFunction(function, value);
2516  
2517    return value;
2518   }
2519  
2520 + //!mcparticle valueLookup
2521   double
2522 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2522 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2523  
2524    double value = 0.0;
2525  
# Line 2322 | Line 2644 | OSUAnalysis::valueLookup (const BNmcpart
2644    }
2645  
2646  
2647 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2647 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2648  
2649    value = applyFunction(function, value);
2650  
2651    return value;
2652   }
2653  
2654 + //!primaryvertex valueLookup
2655   double
2656 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2656 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2657  
2658    double value = 0.0;
2659  
# Line 2349 | Line 2672 | OSUAnalysis::valueLookup (const BNprimar
2672    else if(variable == "isGood") value = object->isGood;
2673  
2674  
2675 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2675 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2676  
2677    value = applyFunction(function, value);
2678  
2679    return value;
2680   }
2681  
2682 + //!bxlumi valueLookup
2683   double
2684 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2684 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2685  
2686    double value = 0.0;
2687  
# Line 2366 | Line 2690 | OSUAnalysis::valueLookup (const BNbxlumi
2690    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2691  
2692  
2693 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2693 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2694  
2695    value = applyFunction(function, value);
2696  
2697    return value;
2698   }
2699  
2700 + //!photon valueLookup
2701   double
2702 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2702 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2703  
2704    double value = 0.0;
2705  
# Line 2449 | Line 2774 | OSUAnalysis::valueLookup (const BNphoton
2774    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2775  
2776  
2452
2777  
2778 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2778 >
2779 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2780  
2781    else if(variable == "genMatchedPdgId"){
2782      int index = getGenMatchedParticleIndex(object);
# Line 2473 | Line 2798 | OSUAnalysis::valueLookup (const BNphoton
2798    }
2799    else if(variable == "genMatchedMotherIdReverse"){
2800      int index = getGenMatchedParticleIndex(object);
2801 <    if(index == -1) value = 23;
2802 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2801 >    if(index == -1) value = 24;
2802 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2803    }
2804    else if(variable == "genMatchedGrandmotherId"){
2805      int index = getGenMatchedParticleIndex(object);
# Line 2486 | Line 2811 | OSUAnalysis::valueLookup (const BNphoton
2811      }
2812      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2813    }
2814 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2815 +    int index = getGenMatchedParticleIndex(object);
2816 +    if(index == -1) value = 24;
2817 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2818 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2819 +      if(motherIndex == -1) value = 24;
2820 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2821 +    }
2822 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2823 +  }
2824  
2825  
2826 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2826 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2827  
2828    value = applyFunction(function, value);
2829  
2830    return value;
2831   }
2832  
2833 + //!supercluster valueLookup
2834   double
2835 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
2835 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
2836  
2837    double value = 0.0;
2838  
# Line 2510 | Line 2846 | OSUAnalysis::valueLookup (const BNsuperc
2846    else if(variable == "theta") value = object->theta;
2847  
2848  
2849 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2849 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2850  
2851    value = applyFunction(function, value);
2852  
2853    return value;
2854   }
2855  
2856 + //!trigobj valueLookup
2857 + double
2858 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
2859  
2860 +  double value = 0.0;
2861 +
2862 +  if(variable == "pt") value = object->pt;
2863 +  else if(variable == "eta") value = object->eta;
2864 +  else if(variable == "phi") value = object->phi;
2865 +  else if(variable == "px") value = object->px;
2866 +  else if(variable == "py") value = object->py;
2867 +  else if(variable == "pz") value = object->pz;
2868 +  else if(variable == "et") value = object->et;
2869 +  else if(variable == "energy") value = object->energy;
2870 +  else if(variable == "etTotal") value = object->etTotal;
2871 +  else if(variable == "id") value = object->id;
2872 +  else if(variable == "charge") value = object->charge;
2873 +  else if(variable == "isIsolated") value = object->isIsolated;
2874 +  else if(variable == "isMip") value = object->isMip;
2875 +  else if(variable == "isForward") value = object->isForward;
2876 +  else if(variable == "isRPC") value = object->isRPC;
2877 +  else if(variable == "bx") value = object->bx;
2878 +  else if(variable == "filter") {
2879 +    if ((stringValue = object->filter) == "")
2880 +      stringValue = "none";  // stringValue should only be empty if value is filled
2881 +  }
2882 +
2883 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2884 +
2885 +  value = applyFunction(function, value);
2886 +
2887 +  return value;
2888 + }
2889 +
2890 + //!muon-muon pair valueLookup
2891   double
2892 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
2892 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
2893  
2894    double value = 0.0;
2895  
# Line 2581 | Line 2951 | OSUAnalysis::valueLookup (const BNmuon*
2951        value = object2->correctedD0;
2952      }
2953  
2954 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2954 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2955  
2956    value = applyFunction(function, value);
2957  
2958    return value;
2959   }
2960  
2961 + //!electron-electron pair valueLookup
2962   double
2963 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
2963 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
2964  
2965    double value = 0.0;
2966  
# Line 2636 | Line 3007 | OSUAnalysis::valueLookup (const BNelectr
3007      value = object2->correctedD0;
3008    }
3009  
3010 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3010 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3011  
3012    value = applyFunction(function, value);
3013  
3014    return value;
3015   }
3016 <
3016 > //!electron-muon pair valueLookup
3017   double
3018 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3018 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3019  
3020    double value = 0.0;
3021  
# Line 2702 | Line 3073 | OSUAnalysis::valueLookup (const BNelectr
3073    else if(variable == "muonRelPFdBetaIso"){
3074      value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3075    }
3076 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3077 +  value = applyFunction(function, value);
3078  
3079 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3079 >  return value;
3080 > }
3081 >
3082 > //!electron-jet pair valueLookup
3083 > double
3084 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3085 >
3086 >  double value = 0.0;
3087 >
3088 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3089 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3090 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3091 >  else if(variable == "invMass"){
3092 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3093 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3094 >    value = (fourVector1 + fourVector2).M();
3095 >  }
3096 >  else if(variable == "pt"){
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).Pt();
3100 >  }
3101 >  else if(variable == "threeDAngle")
3102 >    {
3103 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3104 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3105 >      value = (threeVector1.Angle(threeVector2));
3106 >    }
3107 >  else if(variable == "chargeProduct"){
3108 >    value = object1->charge*object2->charge;
3109 >  }
3110 >
3111 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3112 >  value = applyFunction(function, value);
3113 >
3114 >  return value;
3115 > }
3116 >
3117 > //!muon-jet pair valueLookup
3118 > double
3119 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3120 >
3121 >  double value = 0.0;
3122 >
3123 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3124 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3125 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3126 >  else if(variable == "invMass"){
3127 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3128 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3129 >    value = (fourVector1 + fourVector2).M();
3130 >  }
3131 >  else if(variable == "pt"){
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).Pt();
3135 >  }
3136 >  else if(variable == "threeDAngle")
3137 >    {
3138 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3139 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3140 >      value = (threeVector1.Angle(threeVector2));
3141 >    }
3142 >  else if(variable == "chargeProduct"){
3143 >    value = object1->charge*object2->charge;
3144 >  }
3145  
3146 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3147    value = applyFunction(function, value);
3148  
3149    return value;
3150   }
3151  
3152 + //!jet-jet pair valueLookup
3153 + double
3154 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3155 +
3156 +  double value = 0.0;
3157  
3158 < 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));  
3158 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3159    else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3160 <  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);    
3161 <  else if(variable == "invMass"){        
3162 <    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);    
3163 <    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );    
3164 <        
3165 <    value = (fourVector1 + fourVector2).M();    
3160 >  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3161 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3162 >  else if(variable == "invMass"){
3163 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3164 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3165 >    value = (fourVector1 + fourVector2).M();
3166    }
3167 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}  
3168 <  value = applyFunction(function, value);        
3169 <  return value;  
3167 >  else if(variable == "pt"){
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).Pt();
3171 >  }
3172 >  else if(variable == "threeDAngle")
3173 >    {
3174 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3175 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3176 >      value = (threeVector1.Angle(threeVector2));
3177 >    }
3178 >  else if(variable == "chargeProduct"){
3179 >    value = object1->charge*object2->charge;
3180 >  }
3181 >
3182 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3183 >  value = applyFunction(function, value);
3184 >
3185 >  return value;
3186   }
3187 + //!electron-track pair valueLookup
3188 + double
3189 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3190 +  double electronMass = 0.000511;
3191 +  double value = 0.0;
3192 +  TLorentzVector fourVector1(0, 0, 0, 0);
3193 +  TLorentzVector fourVector2(0, 0, 0, 0);
3194 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3195 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3196 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3197 +  else if(variable == "invMass"){
3198 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3199 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3200  
3201 +    value = (fourVector1 + fourVector2).M();
3202 +  }
3203 +  else if(variable == "chargeProduct"){
3204 +    value = object1->charge*object2->charge;
3205 +  }
3206 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3207 +  value = applyFunction(function, value);
3208 +  return value;
3209 +
3210 + }
3211  
3212  
3213 + //!muon-track pair valueLookup
3214   double
3215 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function){
3215 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3216    double pionMass = 0.140;
3217    double muonMass = 0.106;
3218    double value = 0.0;
# Line 2749 | Line 3227 | OSUAnalysis::valueLookup (const BNmuon*
3227  
3228      value = (fourVector1 + fourVector2).M();
3229    }
3230 +  else if(variable == "chargeProduct"){
3231 +    value = object1->charge*object2->charge;
3232 +  }
3233  
3234    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3235    value = applyFunction(function, value);
3236    return value;
3237   }
3238  
3239 <
3239 > //!tau-tau pair valueLookup
3240   double
3241 < OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function){
3241 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3242    double value = 0.0;
3243    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3244    else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
# Line 2768 | Line 3249 | OSUAnalysis::valueLookup (const BNtau* o
3249      value = (fourVector1 + fourVector2).M();
3250    }
3251  
3252 +  else if(variable == "chargeProduct"){
3253 +    value = object1->charge*object2->charge;
3254 +  }
3255 +
3256    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3257    value = applyFunction(function, value);
3258    return value;
3259   }
3260  
3261 <
3261 > //!muon-tau pair valueLookup
3262   double
3263 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function){
3263 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3264    double value = 0.0;
3265    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3266    else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
# Line 2786 | Line 3271 | OSUAnalysis::valueLookup (const BNmuon*
3271      value = (fourVector1 + fourVector2).M();
3272    }
3273  
3274 +  else if(variable == "chargeProduct"){
3275 +    value = object1->charge*object2->charge;
3276 +  }
3277 +
3278    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3279    value = applyFunction(function, value);
3280    return value;
3281   }
3282  
3283 + //!tau-track pair valueLookup
3284   double
3285 < OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function){
3285 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3286    double value = 0.0;
3287    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3288    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3289 +  else if(variable == "chargeProduct"){
3290 +    value = object1->charge*object2->charge;
3291 +  }
3292  
3293    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3294    value = applyFunction(function, value);
# Line 2803 | Line 3296 | OSUAnalysis::valueLookup (const BNtau* o
3296   }
3297  
3298  
3299 <
3299 > //!track-event pair valueLookup
3300   double
3301 < OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function){
3301 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3302  
3303    double value = 0.0;
3304    double pMag = sqrt(object1->pt * object1->pt +
3305 <                     object1->pz * object1->pz);  
3305 >                     object1->pz * object1->pz);
3306  
3307    if      (variable == "numPV")                      value = object2->numPV;
3308    else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3309    else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3310 <  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);  
3311 <  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;  
3310 >  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3311 >  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3312 >
3313 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3314 >
3315 >  value = applyFunction(function, value);
3316 >
3317 >  return value;
3318 >
3319 > }
3320 >
3321 > //!electron-trigobj pair valueLookup
3322 > double
3323 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3324 >
3325 >  double value = 0.0;
3326 >
3327 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3328 >  else if (variable == "match"){
3329 >    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3330 >      stringValue = object2->filter;
3331 >    else
3332 >      stringValue = "none";
3333 >  }
3334  
3335 <  else { std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3335 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3336  
3337    value = applyFunction(function, value);
3338  
3339    return value;
3340  
3341 < }  
3341 > }
3342 >
3343 > //!muon-trigobj pair valueLookup
3344 > double
3345 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3346 >
3347 >  double value = 0.0;
3348 >
3349 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3350 >
3351 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3352 >
3353 >  value = applyFunction(function, value);
3354 >
3355 >  return value;
3356 >
3357 > }
3358 >
3359 > //!stop valueLookup
3360 > double
3361 > OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3362 >
3363 >
3364 >  double value = 0.0;
3365 >
3366 >  if(variable == "ctau") value = object->ctau;
3367 >
3368 >  else if (variable == "d0"){
3369 >    double vx = object->vx - chosenVertex ()->x,
3370 >      vy = object->vy - chosenVertex ()->y,
3371 >      px = object->px,
3372 >      py = object->py,
3373 >      pt = object->pt;
3374 >    value = (-vx * py + vy * px) / pt;
3375 >  }
3376 >
3377 >  else if (variable == "dz"){
3378 >    double vx = object->vx - chosenVertex ()->x,
3379 >      vy = object->vy - chosenVertex ()->y,
3380 >      vz = object->vz - chosenVertex ()->z,
3381 >      px = object->px,
3382 >      py = object->py,
3383 >      pz = object->pz,
3384 >      pt = object->pt;
3385 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3386 >  }
3387 >
3388 >  else if (variable == "minD0"){
3389 >    double minD0=999;
3390 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3391 >      double vx = object->vx - vertex->x,
3392 >        vy = object->vy - vertex->y,
3393 >        px = object->px,
3394 >        py = object->py,
3395 >        pt = object->pt;
3396 >      value = (-vx * py + vy * px) / pt;
3397 >      if(abs(value) < abs(minD0)) minD0 = value;
3398 >    }
3399 >    value = minD0;
3400 >  }
3401 >  else if (variable == "minDz"){
3402 >    double minDz=999;
3403 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3404 >      double vx = object->vx - vertex->x,
3405 >        vy = object->vy - vertex->y,
3406 >        vz = object->vz - vertex->z,
3407 >        px = object->px,
3408 >        py = object->py,
3409 >        pz = object->pz,
3410 >        pt = object->pt;
3411 >      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3412 >      if(abs(value) < abs(minDz)) minDz = value;
3413 >    }
3414 >    value = minDz;
3415 >  }
3416 >  else if(variable == "distToVertex"){
3417 >    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3418 >                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3419 >                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3420 >  }
3421 >  else if (variable == "minDistToVertex"){
3422 >    double minDistToVertex=999;
3423 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3424 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3425 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3426 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
3427 >
3428 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3429 >    }
3430 >    value = minDistToVertex;
3431 >  }
3432 >  else if (variable == "distToVertexDifference"){
3433 >    double minDistToVertex=999;
3434 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3435 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3436 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3437 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
3438 >
3439 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3440 >    }
3441 >    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3442 >                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3443 >                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3444 >
3445 >    value = distToChosenVertex - minDistToVertex;
3446 >  }
3447 >
3448 >  else if (variable == "closestVertexRank"){
3449 >    double minDistToVertex=999;
3450 >    int vertex_rank = 0;
3451 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3452 >      vertex_rank++;
3453 >      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3454 >                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
3455 >                      (object->vz-vertex->z)*(object->vz-vertex->z));
3456 >
3457 >      if(abs(dist) < abs(minDistToVertex)){
3458 >        value = vertex_rank;
3459 >        minDistToVertex = dist;
3460 >      }
3461 >    }
3462 >  }
3463 >
3464 >
3465 >
3466 >
3467 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3468 >
3469 >  value = applyFunction(function, value);
3470 >
3471 >  return value;
3472 >
3473 > }
3474 >
3475 >
3476 >
3477  
3478   // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3479   // Return true iff no other tracks are found in this cone.
# Line 2872 | Line 3522 | OSUAnalysis::getTrkPtTrue (const BNtrack
3522  
3523   double
3524   OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3525 <  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.  
3526 <  if (!useTrackCaloRhoCorr_) return -99;  
3527 <  // if (!rhokt6CaloJetsHandle_) {
3528 <  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;  
3529 <  //   return -99;  
3525 >  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3526 >  if (!useTrackCaloRhoCorr_) return -99;
3527 >  // if (!rhokt6CaloJetsHandle_) {
3528 >  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3529 >  //   return -99;
3530    // }
3531 <  double radDeltaRCone = 0.5;  
3532 <  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.  
3533 <  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;  
3534 <  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);  
3535 <  return caloTotRhoCorrCalo;  
3536 <
3531 >  double radDeltaRCone = 0.5;
3532 >  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3533 >  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3534 >  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3535 >  return caloTotRhoCorrCalo;
3536 >
3537   }
3538  
3539  
# Line 2921 | Line 3571 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3571    double deltaRLowest = 999;
3572    int value = 0;
3573    if (DeadEcalVec.size() == 0) WriteDeadEcal();
3574 <  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3574 >  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3575      double eta = ecal->etaEcal;
3576      double phi = ecal->phiEcal;
3577 <    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
3577 >    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
3578      if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3579    }
3580    if (deltaRLowest<0.05) {value = 1;}
# Line 2932 | Line 3582 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3582    return value;
3583   }
3584  
3585 < // Returns the smallest DeltaR between the object and any generated true particle in the event.  
3585 > // Returns the smallest DeltaR between the object and any generated true particle in the event.
3586   template <class InputObject>
3587   double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3588    double genDeltaRLowest = 999.;
# Line 2952 | Line 3602 | OSUAnalysis::applyFunction(string functi
3602    else if(function == "log") value = log10(value);
3603  
3604    else if(function == "") value = value;
3605 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
3605 >  else{cout << "WARNING: invalid function '" << function << "'\n";}
3606  
3607    return value;
3608  
# Line 2961 | Line 3611 | OSUAnalysis::applyFunction(string functi
3611  
3612   template <class InputCollection>
3613   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
3614 <
3615 <  if (currentCut.inputCollection.find("pair")!=std::string::npos)  {
3616 <    string obj1, obj2;
3614 >
3615 >  if (currentCut.inputCollection.find("pair")!=string::npos)  {
3616 >    string obj1, obj2;
3617      getTwoObjs(currentCut.inputCollection, obj1, obj2);
3618      if (inputType==obj1 ||
3619 <        inputType==obj2) {
3619 >        inputType==obj2) {
3620        // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
3621 <      // and the inputType is a member of the pair.  
3622 <      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.  
3623 <      // For example, if currentCut.inputCollection==electron-muon pairs,
3624 <      // then the flags should not be set here when inputType==muons or inputType==electrons.  
3625 <      return;
3626 <    }  
3627 <  }    
3621 >      // and the inputType is a member of the pair.
3622 >      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
3623 >      // For example, if currentCut.inputCollection==electron-muon pairs,
3624 >      // then the flags should not be set here when inputType==muons or inputType==electrons.
3625 >      return;
3626 >    }
3627 >  }
3628  
3629    for (uint object = 0; object != inputCollection->size(); object++){
3630  
# Line 2984 | Line 3634 | void OSUAnalysis::setObjectFlags(cut &cu
3634  
3635        vector<bool> subcutDecisions;
3636        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3637 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3638 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3637 >        string stringValue = "";
3638 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3639 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3640 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3641  
3642        }
3643        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
# Line 3024 | Line 3676 | void OSUAnalysis::setObjectFlags(cut &cu
3676    bool sameObjects = false;
3677    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3678  
3679 <  // Get the strings for the two objects that make up the pair.  
3680 <  string obj1Type, obj2Type;
3679 >  // Get the strings for the two objects that make up the pair.
3680 >  string obj1Type, obj2Type;
3681    getTwoObjs(inputType, obj1Type, obj2Type);
3682    bool isTwoTypesOfObject = true;
3683 <  if (obj1Type==obj2Type) isTwoTypesOfObject = false;  
3683 >  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
3684  
3685 <  // Initialize the flags for individual objects to all be false, if the cut is on the pair.  
3686 <  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).  
3687 <  if (currentCut.inputCollection == inputType) {    
3685 >  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
3686 >  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
3687 >  if (currentCut.inputCollection == inputType) {
3688      for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
3689 <      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3689 >      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3690        cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3691      }
3692 <    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.  
3692 >    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
3693        for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
3694 <        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3695 <        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3694 >        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3695 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3696        }
3697      }
3698    }
3699 <  
3699 >
3700    int counter = 0;
3701  
3702    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
# Line 3059 | Line 3711 | void OSUAnalysis::setObjectFlags(cut &cu
3711  
3712          vector<bool> subcutDecisions;
3713          for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3714 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3715 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3714 >          string stringValue = "";
3715 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3716 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3717 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3718          }
3719  
3720          if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
# Line 3075 | Line 3729 | void OSUAnalysis::setObjectFlags(cut &cu
3729            decision = tempDecision;
3730          }
3731        }
3732 <      // if (decision) isPassObj1.at(object1) = true;
3733 <      // if (decision) isPassObj2.at(object2) = true;
3734 <      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);  
3735 <      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on  
3736 <        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;  
3737 <        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;  
3738 <      }  
3732 >      // if (decision) isPassObj1.at(object1) = true;
3733 >      // if (decision) isPassObj2.at(object2) = true;
3734 >      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3735 >      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3736 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;
3737 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;
3738 >      }
3739  
3740        //set flags for objects that pass each cut AND all the previous cuts
3741        bool previousCumulativeFlag = true;
# Line 3096 | Line 3750 | void OSUAnalysis::setObjectFlags(cut &cu
3750        else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
3751        else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
3752        cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
3753 <      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on  
3754 <        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);  
3755 <        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);  
3753 >      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3754 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);
3755 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);
3756        }
3757        counter++;
3758  
3759 <    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3760 <  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3759 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
3760 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
3761  
3762   }
3763  
3764  
3765   bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
3766 <  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
3767 <  // all cuts up to currentCutIndex  
3768 <  bool previousCumulativeFlag = true;  
3769 <  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {  
3766 >  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
3767 >  // all cuts up to currentCutIndex
3768 >  bool previousCumulativeFlag = true;
3769 >  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
3770      if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
3771 <    else {  
3772 <      previousCumulativeFlag = false; break;  
3771 >    else {
3772 >      previousCumulativeFlag = false; break;
3773      }
3774    }
3775 <  return previousCumulativeFlag;  
3776 < }  
3775 >  return previousCumulativeFlag;
3776 > }
3777 >
3778 >
3779 >
3780 > template <class InputCollection>
3781 > void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, vector<bool> flags){
3782 >  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree  
3783 >
3784 >  if (BNTreeBranchVals_.count(parameters.name)==0) cout << "Error[assignTreeBranch]:  trying to assign value to " << parameters.name << " that does not have a branch set up.  Will likely seg fault." << endl;  
3785 >  for (uint object = 0; object != inputCollection->size(); object++) {  
3786 >
3787 >    if (!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;  
3788 >
3789 >    string inputVariable = parameters.inputVariable;
3790 >    string function = "";
3791 >    string stringValue = "";  
3792 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);  
3793 >    BNTreeBranchVals_.at(parameters.name).push_back(value);  
3794 >
3795 >  }
3796 > }
3797  
3798  
3799   template <class InputCollection>
# Line 3132 | Line 3806 | void OSUAnalysis::fill1DHistogram(TH1* h
3806      string currentString = parameters.inputVariables.at(0);
3807      string inputVariable = "";
3808      string function = "";
3809 <    if(currentString.find("(")==std::string::npos){
3809 >    if(currentString.find("(")==string::npos){
3810        inputVariable = currentString;// variable to cut on
3811      }
3812      else{
3813        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3814        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3815        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3816 <    }
3816 >    }  
3817  
3818 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
3819 <    histo->Fill(value,scaleFactor);
3818 >    string stringValue = "";  
3819 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);  
3820 >    histo->Fill(value,scaleFactor);  
3821  
3822      if (printEventInfo_) {
3823 <      // Write information about event to screen, for testing purposes.  
3824 <      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;  
3823 >      // Write information about event to screen, for testing purposes.
3824 >      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
3825      }
3826 <    
3826 >
3827    }
3828   }
3829  
# Line 3173 | Line 3848 | void OSUAnalysis::fill1DHistogram(TH1* h
3848        string currentString = parameters.inputVariables.at(0);
3849        string inputVariable = "";
3850        string function = "";
3851 <      if(currentString.find("(")==std::string::npos){
3851 >      if(currentString.find("(")==string::npos){
3852          inputVariable = currentString;// variable to cut on
3853        }
3854        else{
# Line 3182 | Line 3857 | void OSUAnalysis::fill1DHistogram(TH1* h
3857          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3858        }
3859  
3860 <      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3860 >      string stringValue = "";
3861 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3862        histo->Fill(value,scaleFactor);
3863  
3864      }
# Line 3198 | Line 3874 | void OSUAnalysis::fill2DHistogram(TH2* h
3874  
3875      if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3876  
3877 +    string stringValue = "";
3878      string currentString = parameters.inputVariables.at(0);
3879      string inputVariable = "";
3880      string function = "";
3881 <    if(currentString.find("(")==std::string::npos){
3881 >    if(currentString.find("(")==string::npos){
3882        inputVariable = currentString;// variable to cut on
3883      }
3884      else{
# Line 3209 | Line 3886 | void OSUAnalysis::fill2DHistogram(TH2* h
3886        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3887        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3888      }
3889 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
3889 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3890  
3891      currentString = parameters.inputVariables.at(1);
3892      inputVariable = "";
3893      function = "";
3894 <    if(currentString.find("(")==std::string::npos){
3894 >    if(currentString.find("(")==string::npos){
3895        inputVariable = currentString;// variable to cut on
3896      }
3897      else{
# Line 3223 | Line 3900 | void OSUAnalysis::fill2DHistogram(TH2* h
3900        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3901      }
3902  
3903 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
3903 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3904  
3905      histo->Fill(valueX,valueY,scaleFactor);
3906  
# Line 3250 | Line 3927 | void OSUAnalysis::fill2DHistogram(TH2* h
3927        if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3928        if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3929  
3930 +      string stringValue = "";
3931        string currentString = parameters.inputVariables.at(0);
3932        string inputVariable = "";
3933        string function = "";
3934 <      if(currentString.find("(")==std::string::npos){
3934 >      if(currentString.find("(")==string::npos){
3935          inputVariable = currentString;// variable to cut on
3936        }
3937        else{
# Line 3261 | Line 3939 | void OSUAnalysis::fill2DHistogram(TH2* h
3939          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3940          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3941        }
3942 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3942 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3943  
3944        currentString = parameters.inputVariables.at(1);
3945        inputVariable = "";
3946        function = "";
3947 <      if(currentString.find("(")==std::string::npos){
3947 >      if(currentString.find("(")==string::npos){
3948          inputVariable = currentString;// variable to cut on
3949        }
3950        else{
# Line 3274 | Line 3952 | void OSUAnalysis::fill2DHistogram(TH2* h
3952          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3953          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3954        }
3955 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3955 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3956  
3957  
3958        histo->Fill(valueX,valueY,scaleFactor);
# Line 3295 | Line 3973 | int OSUAnalysis::getGenMatchedParticleIn
3973  
3974      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
3975      if(currentDeltaR > 0.05) continue;
3976 <    //     cout << std::setprecision(3) << std::setw(20)
3976 >    //     cout << setprecision(3) << setw(20)
3977      //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
3978 <    //          << std::setw(20)
3978 >    //          << setw(20)
3979      //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
3980 <    //          << std::setw(20)
3980 >    //          << setw(20)
3981      //          << "\tdeltaR = " << currentDeltaR
3982 <    //          << std::setprecision(1)
3983 <    //          << std::setw(20)
3982 >    //          << setprecision(1)
3983 >    //          << setw(20)
3984      //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
3985 <    //          << std::setw(20)
3985 >    //          << setw(20)
3986      //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
3987 <    //          << std::setw(20)
3987 >    //          << setw(20)
3988      //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
3989      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
3990        bestMatchIndex = mcparticle - mcparticles->begin();
# Line 3369 | Line 4047 | int OSUAnalysis::findTauMotherIndex(cons
4047   // 20        strange baryon
4048   // 21        charm baryon
4049   // 22        bottom baryon
4050 < // 23        other
4050 > // 23        QCD string
4051 > // 24        other
4052  
4053   int OSUAnalysis::getPdgIdBinValue(int pdgId){
4054  
# Line 3393 | Line 4072 | int OSUAnalysis::getPdgIdBinValue(int pd
4072    else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4073    else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4074    else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4075 +  else if(absPdgId == 92  ) binValue = 23;
4076  
4077 <  else binValue = 23;
4077 >  else binValue = 24;
4078  
4079    return binValue;
4080  
# Line 3404 | Line 4084 | const BNprimaryvertex *
4084   OSUAnalysis::chosenVertex ()
4085   {
4086    const BNprimaryvertex *chosenVertex = 0;
4087 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
4088 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
4089 <      cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
4087 >  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4088 >    vector<bool> vertexFlags;
4089 >    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4090 >      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4091 >        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4092 >        break;
4093 >      }
4094 >    }
4095      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4096        if(!vertexFlags.at(vertexIndex)) continue;
4097        chosenVertex = & primaryvertexs->at(vertexIndex);
4098        break;
4099      }
4100    }
4101 <  else {
4102 <    chosenVertex = &primaryvertexs->at(0);
3418 <  }
4101 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4102 >    chosenVertex = & primaryvertexs->at (0);
4103  
4104    return chosenVertex;
4105   }
# Line 3424 | Line 4108 | const BNmet *
4108   OSUAnalysis::chosenMET ()
4109   {
4110    const BNmet *chosenMET = 0;
4111 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
4112 <    vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
4113 <      cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
4111 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4112 >    vector<bool> metFlags;
4113 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4114 >      if (cumulativeFlags.at("mets").at(i).size()){
4115 >        metFlags = cumulativeFlags.at("mets").at(i);
4116 >        break;
4117 >      }
4118 >    }
4119      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4120        if(!metFlags.at(metIndex)) continue;
4121        chosenMET = & mets->at(metIndex);
4122        break;
4123      }
4124    }
4125 <  else {
4126 <    chosenMET = &mets->at(0);
3438 <  }
4125 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4126 >    chosenMET = & mets->at (0);
4127  
4128    return chosenMET;
4129   }
# Line 3444 | Line 4132 | const BNelectron *
4132   OSUAnalysis::chosenElectron ()
4133   {
4134    const BNelectron *chosenElectron = 0;
4135 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
4136 <    vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
4137 <      cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
4135 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4136 >    vector<bool> electronFlags;
4137 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4138 >      if (cumulativeFlags.at("electrons").at(i).size()){
4139 >        electronFlags = cumulativeFlags.at("electrons").at(i);
4140 >        break;
4141 >      }
4142 >    }
4143      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4144        if(!electronFlags.at(electronIndex)) continue;
4145        chosenElectron = & electrons->at(electronIndex);
4146        break;
4147      }
4148    }
4149 <  else {
4150 <    chosenElectron = &electrons->at(0);
3458 <  }
4149 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4150 >    chosenElectron = & electrons->at (0);
4151  
4152    return chosenElectron;
4153   }
# Line 3464 | Line 4156 | const BNmuon *
4156   OSUAnalysis::chosenMuon ()
4157   {
4158    const BNmuon *chosenMuon = 0;
4159 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
4160 <    vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
4161 <      cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
4159 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4160 >    vector<bool> muonFlags;
4161 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4162 >      if (cumulativeFlags.at("muons").at(i).size()){
4163 >        muonFlags = cumulativeFlags.at("muons").at(i);
4164 >        break;
4165 >      }
4166 >    }
4167      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4168        if(!muonFlags.at(muonIndex)) continue;
4169        chosenMuon = & muons->at(muonIndex);
4170        break;
4171      }
4172    }
4173 <  else {
4174 <    chosenMuon = &muons->at(0);
3478 <  }
4173 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4174 >    chosenMuon = & muons->at (0);
4175  
4176    return chosenMuon;
4177   }
4178  
3483
4179   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines