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

Comparing UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc (file contents):
Revision 1.43 by wulsin, Thu Mar 28 10:17:32 2013 UTC vs.
Revision 1.81 by wulsin, Tue Jun 4 14:44:26 2013 UTC

# Line 11 | Line 11 | OSUAnalysis::OSUAnalysis (const edm::Par
11    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
12    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
13    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
14 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
15    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
16    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
17    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
18    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
19    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
20 <  puFile_ (cfg.getParameter<std::string> ("puFile")),
21 <  deadEcalFile_ (cfg.getParameter<std::string> ("deadEcalFile")),
22 <  muonSFFile_ (cfg.getParameter<std::string> ("muonSFFile")),
23 <  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
24 <  electronSFID_ (cfg.getParameter<std::string> ("electronSFID")),
25 <  muonSF_ (cfg.getParameter<std::string> ("muonSF")),
26 <  dataset_ (cfg.getParameter<std::string> ("dataset")),
27 <  datasetType_ (cfg.getParameter<std::string> ("datasetType")),
20 >  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
21 >  puFile_ (cfg.getParameter<string> ("puFile")),
22 >  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
23 >  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
24 >  dataPU_ (cfg.getParameter<string> ("dataPU")),
25 >  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
26 >  muonSF_ (cfg.getParameter<string> ("muonSF")),
27 >  dataset_ (cfg.getParameter<string> ("dataset")),
28 >  datasetType_ (cfg.getParameter<string> ("datasetType")),
29    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
30    histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
31 +  treeBranchSets_   (cfg.getParameter<vector<edm::ParameterSet> >("treeBranchSets")),
32    plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
33    doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
34 <  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
35 <  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr"))
36 <
34 >  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
35 >  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
36 >  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
37 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
38 >  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
39   {
40  
41    TH1::SetDefaultSumw2 ();
# Line 38 | 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 +  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_);
49  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");
53
54  //always make the plot of number of primary verticex (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 60 | 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.find("pairs")==std::string::npos){ //just a single object
102 <      objectsToGet.push_back(tempInputCollection);
101 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
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);
113 >      }
114        objectsToPlot.push_back(tempInputCollection);
115        objectsToCut.push_back(tempInputCollection);
116 <    }
117 <    else{//pair of objects, need to add them both to the things to objectsToGet
118 <      int dashIndex = tempInputCollection.find("-");
119 <      int spaceIndex = tempInputCollection.find(" ");
120 <      int secondWordLength = spaceIndex - dashIndex;
78 <      objectsToGet.push_back(tempInputCollection);
79 <      objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
80 <      objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
81 <      objectsToPlot.push_back(tempInputCollection);
82 <      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
83 <      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
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);
121        objectsToCut.push_back(tempInputCollection);
122 <      objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
123 <      objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
122 >      objectsToCut.push_back(obj1);
123 >      objectsToCut.push_back(obj2);
124 >      objectsToPlot.push_back(tempInputCollection);
125 >      objectsToPlot.push_back(obj1);
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  
88    }
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 112 | 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 != "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  
197 <    int maxNum = 24;
197 >    int maxNum = 25;
198      vector<double> binVector;
199      binVector.push_back(maxNum);
200      binVector.push_back(0);
# Line 154 | 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 174 | 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
192 <    TFileDirectory subDir = fs_->mkdir( channelName );
193 <    directories.push_back(subDir);
194 <
195 <    std::map<std::string, TH1D*> oneDhistoMap;
196 <    oneDHists_.push_back(oneDhistoMap);
197 <    std::map<std::string, TH2D*> twoDhistoMap;
198 <    twoDHists_.push_back(twoDhistoMap);
199 <
200 <
201 <
202 <    //book all histograms included in the configuration
203 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
204 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
205 <      int numBinsElements = currentHistogram.bins.size();
206 <      int numInputVariables = currentHistogram.inputVariables.size();
207 <
208 <      if(numBinsElements != 3 && numBinsElements !=6) {
209 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
210 <        exit(0);
211 <      }
212 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
213 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
214 <        exit(0);
215 <      }
216 <      else if(numBinsElements == 3){
217 <        oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
218 <      }
219 <      else if(numBinsElements == 6){
220 <        twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2),currentHistogram.bins.at(3),currentHistogram.bins.at(4),currentHistogram.bins.at(5));
221 <
222 <      }
223 <
224 <
225 <      if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
226 <
227 <      // bin      particle type
228 <      // ---      -------------
229 <      //  0        unmatched
230 <      //  1        u
231 <      //  2        d
232 <      //  3        s
233 <      //  4        c
234 <      //  5        b
235 <      //  6        t
236 <      //  7        e
237 <      //  8        mu
238 <      //  9        tau
239 <      // 10        nu
240 <      // 11        g
241 <      // 12        gamma
242 <      // 13        Z
243 <      // 14        W
244 <      // 15        light meson
245 <      // 16        K meson
246 <      // 17        D meson
247 <      // 18        B meson
248 <      // 19        light baryon
249 <      // 20        strange baryon
250 <      // 21        charm baryon
251 <      // 22        bottom baryon
252 <      // 23        other
253 <
254 <      vector<TString> labelArray;
255 <      labelArray.push_back("unmatched");
256 <      labelArray.push_back("u");
257 <      labelArray.push_back("d");
258 <      labelArray.push_back("s");
259 <      labelArray.push_back("c");
260 <      labelArray.push_back("b");
261 <      labelArray.push_back("t");
262 <      labelArray.push_back("e");
263 <      labelArray.push_back("#mu");
264 <      labelArray.push_back("#tau");
265 <      labelArray.push_back("#nu");
266 <      labelArray.push_back("g");
267 <      labelArray.push_back("#gamma");
268 <      labelArray.push_back("Z");
269 <      labelArray.push_back("W");
270 <      labelArray.push_back("light meson");
271 <      labelArray.push_back("K meson");
272 <      labelArray.push_back("D meson");
273 <      labelArray.push_back("B meson");
274 <      labelArray.push_back("light baryon");
275 <      labelArray.push_back("strange baryon");
276 <      labelArray.push_back("charm baryon");
277 <      labelArray.push_back("bottom baryon");
278 <      labelArray.push_back("other");
279 <
280 <      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
281 <        if(currentHistogram.name.find("GenMatchIdVsMotherId")==std::string::npos) {
282 <          oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
283 <        }
284 <        else {
285 <          twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
286 <          twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
287 <        }
288 <      }
289 <      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=std::string::npos) {
290 <        twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->CenterTitle();
291 <        twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->CenterTitle();
292 <      }
293 <
294 <    }
295 <
296 <    // Book a histogram for the number of each object type to be plotted.  
297 <    // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().  
298 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
299 <      string currentObject = objectsToPlot.at(currentObjectIndex);
300 <      int maxNum = 10;
301 <      if(currentObject == "mcparticles") maxNum = 50;
302 <      else if(currentObject == "primaryvertexs") maxNum = 50;
303 <      else if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
304 <      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
305 <      else if(currentObject == "electron-muon pairs")     currentObject = "electronMuonPairs";
306 <      else if(currentObject == "track-event pairs")       currentObject = "trackEventPairs";
307 <      else if(currentObject == "electron-track pairs")    currentObject = "electronTrackPairs";  
308 <      else if(currentObject == "muon-track pairs")        currentObject = "muonTrackPairs";      
309 <      else if(currentObject == "muon-tau pairs")          currentObject = "muonTauPairs";        
310 <      else if(currentObject == "tau-tau pairs")           currentObject = "ditauPairs";
311 <      currentObject.at(0) = toupper(currentObject.at(0));  
312 <      string histoName = "num" + currentObject;
313 <
314 <      if(histoName == "numPrimaryvertexs"){
315 <        string newHistoName = histoName + "BeforePileupCorrection";
316 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
317 <        newHistoName = histoName + "AfterPileupCorrection";
318 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
319 <      }
320 <      else
321 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
322 <    }
323 <
324 <
325 <
326 <
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 <        objectsToGet.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 the things to objectsToGet
293 <        int dashIndex = tempInputCollection.find("-");
294 <        int spaceIndex = tempInputCollection.find(" ");
295 <        int secondWordLength = spaceIndex - dashIndex;
296 <        objectsToGet.push_back(tempInputCollection);
345 <        objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
346 <        objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
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);
297          objectsToCut.push_back(tempInputCollection);
298 <        objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
299 <        objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
298 >        objectsToCut.push_back(obj1);
299 >        objectsToCut.push_back(obj2);
300 >        objectsToGet.push_back(tempInputCollection);
301 >        objectsToGet.push_back(obj1);
302 >        objectsToGet.push_back(obj2ToGet);
303  
304        }
305  
# Line 354 | 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 374 | 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 389 | 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 400 | 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        }
404      tempCut.name = tempCutName;
361  
362 +      subSubDirNames.push_back(subSubDirName);
363 +      tempCut.name = tempCutName;
364  
365        tempChannel.cuts.push_back(tempCut);
366  
367  
410
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();
415
569    }//end loop over channels
570  
571  
# Line 428 | Line 581 | OSUAnalysis::OSUAnalysis (const edm::Par
581  
582   OSUAnalysis::~OSUAnalysis ()
583   {
584 +
585    // Destroying the CutFlow objects causes the cut flow numbers and time
586    // information to be printed to standard output.
587    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
# Line 441 | Line 595 | OSUAnalysis::analyze (const edm::Event &
595  
596    // Retrieve necessary collections from the event.
597  
598 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
598 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
599      event.getByLabel (triggers_, triggers);
600  
601 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
601 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
602 >    event.getByLabel (trigobjs_, trigobjs);
603 >
604 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
605      event.getByLabel (jets_, jets);
606  
607 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
607 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
608      event.getByLabel (muons_, muons);
609  
610 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
610 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
611      event.getByLabel (electrons_, electrons);
612  
613 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
613 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
614      event.getByLabel (events_, events);
615  
616 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
616 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
617      event.getByLabel (taus_, taus);
618  
619 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
619 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
620      event.getByLabel (mets_, mets);
621  
622 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
622 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
623      event.getByLabel (tracks_, tracks);
624  
625 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
625 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
626      event.getByLabel (genjets_, genjets);
627  
628 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
628 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
629      event.getByLabel (mcparticles_, mcparticles);
630  
631 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
631 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
632      event.getByLabel (primaryvertexs_, primaryvertexs);
633  
634 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
634 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
635      event.getByLabel (bxlumis_, bxlumis);
636  
637 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
637 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
638      event.getByLabel (photons_, photons);
639  
640 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
640 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
641      event.getByLabel (superclusters_, superclusters);
642  
643 <  if (useTrackCaloRhoCorr_) {  
644 <    // Used only for pile-up correction of by-hand calculation of isolation energy.  
645 <    // This rho collection is not available in all BEANs.  
643 >  if (datasetType_ == "signalMC"){
644 >    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
645 >      event.getByLabel (stops_, stops);
646 >  }
647 >
648 >  if (useTrackCaloRhoCorr_) {
649 >    // Used only for pile-up correction of by-hand calculation of isolation energy.
650 >    // This rho collection is not available in all BEANs.
651      // For description of rho values for different jet reconstruction algorithms, see
652 <    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms  
653 <    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
652 >    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
653 >    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
654    }
655  
656 +  double masterScaleFactor = 1.0;
657  
658    //get pile-up event weight
659 <  double scaleFactor = 1.00;
660 <  if(doPileupReweighting_ && datasetType_ != "data")
661 <    scaleFactor = puWeight_->at (events->at (0).numTruePV);
659 >  if (doPileupReweighting_ && datasetType_ != "data") {
660 >    //for "data" datasets, the numTruePV is always set to -1
661 >    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;  
662 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);  
663 >  }
664  
665 +  stopCTauScaleFactor_ = 1.0;
666 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
667 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
668 +  masterScaleFactor *= stopCTauScaleFactor_;
669  
670    //loop over all channels
671  
# Line 507 | Line 676 | OSUAnalysis::analyze (const edm::Event &
676      counterMap passingCounter;
677      cumulativeFlags.clear ();
678  
679 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
680 +         iter != BNTreeBranchVals_.end(); iter++) {
681 +      iter->second.clear();  // clear array
682 +    }
683 +
684      bool triggerDecision = true;
685 <    if(currentChannel.triggers.size() != 0){  //triggers specified
686 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
685 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
686 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
687        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
688      }
689  
690      //loop over all cuts
517
518
519
691      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
692        cut currentCut = currentChannel.cuts.at(currentCutIndex);
522
693        for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
694          string currentObject = objectsToCut.at(currentObjectIndex);
695  
# Line 534 | Line 704 | OSUAnalysis::analyze (const edm::Event &
704          int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
705  
706  
707 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
708 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
707 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
708 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
709 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
710 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
711 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
712          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
713          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
714          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 547 | Line 720 | OSUAnalysis::analyze (const edm::Event &
720          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
721          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
722          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
723 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
724 +
725  
726  
727          else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
728                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
729                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
730                                                                     "muon-muon pairs");
731 +
732 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
733 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
734 +                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
735 +                                                                             "muon-secondary muon pairs");
736 +
737 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
738 +                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
739 +                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
740 +                                                                                     "electron-secondary electron pairs");
741 +
742          else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
743                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
744                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
# Line 561 | Line 747 | OSUAnalysis::analyze (const edm::Event &
747                                                                         cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
748                                                                         cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
749                                                                         "electron-muon pairs");
750 <        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
751 <                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
752 <                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
753 <                                                                     "track-event pairs");
754 <        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
755 <                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
756 <                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
757 <                                                                        "electron-track pairs");
758 <        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
759 <                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
760 <                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
761 <                                                                    "muon-track pairs");
762 <        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
763 <                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
764 <                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
765 <                                                                  "muon-tau pairs");
766 <        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),taus.product(),
767 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
768 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
769 <                                                                 "tau-tau pairs");
770 <        
771 <        
750 >        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
751 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
752 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
753 >                                                                 "jet-jet pairs");
754 >        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
755 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
756 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
757 >                                                                      "electron-jet pairs");
758 >        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
759 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
760 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
761 >                                                                  "muon-jet pairs");
762 >        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
763 >                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
764 >                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
765 >                                                                     "track-event pairs");
766 >        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
767 >                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
768 >                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
769 >                                                                        "electron-track pairs");
770 >        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
771 >                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
772 >                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
773 >                                                                    "muon-track pairs");
774 >        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
775 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
776 >                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
777 >                                                                  "muon-tau pairs");
778 >        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
779 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
780 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
781 >                                                                 "tau-tau pairs");
782 >        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
783 >                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
784 >                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
785 >                                                                   "tau-track pairs");
786 >        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
787 >                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
788 >                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
789 >                                                                          "electron-trigobj pairs");
790 >        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
791 >                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
792 >                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
793 >                                                                      "muon-trigobj pairs");
794 >
795 >        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
796        }
797  
798  
799  
800      }//end loop over all cuts
591
592
801      //use cumulative flags to apply cuts at event level
802  
803      bool eventPassedAllCuts = true;
804 <
804 >    //a vector to store cumulative cut descisions after each cut.
805 >    vector<bool> eventPassedPreviousCuts;
806      //apply trigger (true if none were specified)
807      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
808  
600
601
809      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
810  
811        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 606 | Line 813 | OSUAnalysis::analyze (const edm::Event &
813        int numberPassing = 0;
814  
815        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
816 <        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
816 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
817        }
611
818        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
819        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
614
820        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
821 +      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
822 +    }
823 +    double scaleFactor = masterScaleFactor;
824  
825 +    muonScaleFactor_ = electronScaleFactor_ = 1.0;
826 +    if(applyLeptonSF_ && datasetType_ != "data"){
827 +      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
828 +        vector<bool> muonFlags;
829 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
830 +          if (cumulativeFlags.at("muons").at(i).size()){
831 +            muonFlags = cumulativeFlags.at("muons").at(i);
832 +            break;
833 +          }
834 +        }
835 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
836 +          if(!muonFlags.at(muonIndex)) continue;
837 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
838 +        }
839 +      }
840 +      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
841 +        vector<bool> electronFlags;
842 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
843 +          if (cumulativeFlags.at("electrons").at(i).size()){
844 +            electronFlags = cumulativeFlags.at("electrons").at(i);
845 +            break;
846 +          }
847 +        }
848 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
849 +          if(!electronFlags.at(electronIndex)) continue;
850 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
851 +        }
852 +      }
853      }
854 +    scaleFactor *= muonScaleFactor_;
855 +    scaleFactor *= electronScaleFactor_;
856  
857      cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
858  
621
622
623    if(!eventPassedAllCuts)continue;
624
859      if (printEventInfo_) {
860 <      // Write information about event to screen, for testing purposes.  
861 <      cout << "Event passed all cuts in channel " <<  currentChannel.name
862 <           << ": run="  << events->at(0).run
863 <           << "  lumi=" << events->at(0).lumi
864 <           << "  event=" << events->at(0).evt
865 <           << endl;  
860 >      // Write information about event to screen, for testing purposes.
861 >      cout << "Event passed all cuts in channel " <<  currentChannel.name
862 >           << ": run="  << events->at(0).run
863 >           << "  lumi=" << events->at(0).lumi
864 >           << "  event=" << events->at(0).evt
865 >           << endl;
866      }
867  
868  
635    //     if(datasetType_ != "data") {
636    //       scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
637    //       scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
638    //     }
639
869      //filling histograms
870 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
871 <      histogram currentHistogram = histograms.at(histogramIndex);
870 >    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
871 >      uint currentDir;
872 >      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
873 >      else{
874 >        currentDir = currentCut;
875 >      }
876 >      if(eventPassedPreviousCuts.at(currentDir)){
877  
878 <      if(currentHistogram.inputVariables.size() == 1){
879 <        TH1D* histo;
880 <        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
881 <
882 <
883 <
884 <        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
885 <        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
886 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
887 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
888 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
889 <        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
890 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
891 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
892 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
893 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
894 <                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
895 <                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
896 <        else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),        
897 <                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),  
898 <                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);      
899 <        else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),        
900 <                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),  
901 <                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);      
902 <        else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),    
903 <                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),      
904 <                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);  
905 <        else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),      
906 <                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),        
907 <                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);    
908 <        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
909 <        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
910 <        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
911 <        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
912 <        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
913 <        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
914 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
915 <        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
916 <        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
917 <        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
918 <      }
919 <      else if(currentHistogram.inputVariables.size() == 2){
920 <        TH2D* histo;
921 <        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
922 <
923 <
924 <
925 <        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
926 <        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
927 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
928 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
929 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
930 <        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
931 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
932 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
933 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
934 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
935 <                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
936 <                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
937 <        else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),        
938 <                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),          
939 <                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);      
940 <        else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),        
941 <                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),          
942 <                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);      
943 <        else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),    
944 <                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),      
945 <                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);  
946 <        else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),      
947 <                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),        
948 <                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);    
949 <        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
950 <        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
951 <        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
952 <        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
953 <        else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
954 <                                                                                         cumulativeFlags.at("tracks").back(),cumulativeFlags.at("events").back(),
955 <                                                                                         cumulativeFlags.at("track-event pairs").back(),scaleFactor);  
956 <        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
957 <        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
958 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
959 <        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
960 <        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
961 <        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
962 <      }
963 <    }
964 <
965 <    //fills histograms with the sizes of collections
966 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
967 <
968 <      string currentObject = objectsToPlot.at(currentObjectIndex);
969 <
970 <      string objectToPlot = "";  
971 <
972 <      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().  
973 <      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
974 <      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
975 <      else if(currentObject == "electron-muon pairs")     objectToPlot = "electronMuonPairs";
976 <      else if(currentObject == "electron-track pairs")    objectToPlot = "electronTrackPairs";
977 <      else if(currentObject == "muon-track pairs")        objectToPlot = "muonTrackPairs";      
978 <      else if(currentObject == "muon-tau pairs")          objectToPlot = "muonTauPairs";        
979 <      else if(currentObject == "tau-tau pairs")           objectToPlot = "ditauPairs";
980 <      else if(currentObject == "track-event pairs")       objectToPlot = "trackEventPairs";  
981 <      else objectToPlot = currentObject;
982 <      string tempCurrentObject = objectToPlot;
983 <      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));  
984 <      string histoName = "num" + tempCurrentObject;
985 <
986 <
987 <      //set position of primary vertex in event, in order to calculate quantities relative to it
988 <      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
989 <        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
990 <        int numToPlot = 0;
991 <        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
992 <          if(lastCutFlags.at(currentFlag)) numToPlot++;
993 <        }
994 <        if(objectToPlot == "primaryvertexs"){
995 <          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
996 <          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
997 <        }
998 <        else {
999 <          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
878 >        // Assign BNTree variables
879 >        for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
880 >          BranchSpecs brSpecs = treeBranches_.at(iBranch);  
881 >          string coll = brSpecs.inputCollection;  
882 >          if (cumulativeFlags.count(coll) == 0) cout << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
883 >
884 >          if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).at(currentDir));            
885 >          else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).at(currentDir));
886 >          else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).at(currentDir));        
887 >          else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).at(currentDir));
888 >          else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).at(currentDir));
889 >          else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).at(currentDir));
890 >          else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).at(currentDir));
891 >          else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).at(currentDir));
892 >          else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).at(currentDir));
893 >          else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).at(currentDir));
894 >          else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).at(currentDir));
895 >          else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).at(currentDir));
896 >          else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).at(currentDir));
897 >          else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).at(currentDir));
898 >          else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).at(currentDir));
899 >          else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).at(currentDir));
900 >          else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).at(currentDir));
901 >          else if(coll == "stops"
902 >                  && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).at(currentDir));
903 >        } // end loop over branches  
904 >                                                                                          
905 >        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
906 >          histogram currentHistogram = histograms.at(histogramIndex);
907 >
908 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) cout << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
909 >
910 >          if(currentHistogram.inputVariables.size() == 1){
911 >            TH1D* histo;  
912 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
913 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
914 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
915 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
916 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
917 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
918 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
919 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
920 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
921 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
922 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
923 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
924 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
925 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
926 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
927 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
928 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
929 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
930 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
931 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
932 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
933 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
934 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
935 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
936 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
937 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
938 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
939 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
940 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
941 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
942 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
943 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
944 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
945 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
946 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
947 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
948 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
949 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
950 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
951 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
952 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
953 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
954 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
955 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
956 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
957 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
958 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
959 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
960 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
961 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
962 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
963 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
964 >
965 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
966 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
967 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
968 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
969 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
970 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
971 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
972 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
973 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
974 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
975 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
976 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
977 >          }
978 >          else if(currentHistogram.inputVariables.size() == 2){
979 >            TH2D* histo;
980 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
981 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
982 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
983 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
984 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
985 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
986 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
987 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
988 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
989 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
990 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
991 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
992 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
993 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
994 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
995 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
996 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
997 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
998 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
999 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1000 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1001 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1002 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1003 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1004 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1005 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1006 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1007 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1008 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1009 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1010 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1011 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1012 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1013 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1014 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1015 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1016 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1017 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1018 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1019 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1020 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1021 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1022 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1023 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1024 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1025 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1026 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1027 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1028 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1029 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1030 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1031 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1032 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1033 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1034 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1035 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1036 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1037 >                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1038 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1039 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1040 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1041 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1042 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1043 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1044 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1045 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1046 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1047 >          }
1048 >          
1049          }
767      }
768      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
769      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
770      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
771      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
772      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
773      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
774      else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
775      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
776      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
777      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
778      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
779      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
780      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
781      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
782      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
783      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
784      else if(objectToPlot == "primaryvertexs"){
785        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
786        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
787      }
1050  
789    } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1051  
1052 <  } //end loop over channel
1052 >        //fills histograms with the sizes of collections
1053 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1054 >
1055 >          string currentObject = objectsToPlot.at(currentObjectIndex);
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-jet pairs")                 objectToPlot = "electronJetPairs";
1063 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1064 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1065 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1066 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1067 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1068 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1069 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1070 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1071 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1072 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1073 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1074 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1075 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1076 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1077 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1078 >          else objectToPlot = currentObject;
1079 >
1080 >          string tempCurrentObject = objectToPlot;
1081 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1082 >          string histoName = "num" + tempCurrentObject;
1083 >
1084 >          //set position of primary vertex in event, in order to calculate quantities relative to it
1085 >          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1086 >            vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1087 >            int numToPlot = 0;
1088 >            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1089 >              if(lastCutFlags.at(currentFlag)) numToPlot++;
1090 >            }
1091 >            if(objectToPlot == "primaryvertexs"){
1092 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1093 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1094 >            }
1095 >            else {
1096 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1097 >            }
1098 >          }
1099 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1100 >        
1101 >        if (!BNTrees_.at(currentChannelIndex)) { cout << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }  
1102 >        BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts  
1103 >
1104 >      } // end if(eventPassedPreviousCuts.at(currentDir)){
1105 >    } // end loop over cuts
1106 >    
1107 >  } // end loop over channel
1108 >
1109 >
1110 >  masterCutFlow_->fillCutFlow(masterScaleFactor);
1111  
793  masterCutFlow_->fillCutFlow(scaleFactor);
1112  
1113   } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1114  
# Line 807 | Line 1125 | OSUAnalysis::evaluateComparison (double
1125    else if(comparison == "==") return testValue == cutValue;
1126    else if(comparison == "=") return testValue == cutValue;
1127    else if(comparison == "!=") return testValue != cutValue;
1128 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1128 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1129 >
1130 > }
1131 >
1132 > bool
1133 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1134 >
1135 >
1136 >  if(comparison == ">")       return testValue >  cutValue;
1137 >  else if(comparison == ">=") return testValue >= cutValue;
1138 >  else if(comparison == "<")  return testValue <  cutValue;
1139 >  else if(comparison == "<=") return testValue <= cutValue;
1140 >  else if(comparison == "==") return testValue == cutValue;
1141 >  else if(comparison == "=") return testValue == cutValue;
1142 >  else if(comparison == "!=") return testValue != cutValue;
1143 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1144  
1145   }
1146  
1147   bool
1148 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1148 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1149  
1150 +  //initialize to false until a chosen trigger is passed
1151    bool triggerDecision = false;
1152  
1153 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1154 <    {
821 <      if(trigger->pass != 1) continue;
822 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
823 <        {
824 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
825 <            triggerDecision = true;
826 <          }
827 <        }
828 <    }
829 <  return triggerDecision;
1153 >  //loop over all triggers defined in the event
1154 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1155  
1156 +    //we're only interested in triggers that actually passed
1157 +    if(trigger->pass != 1) continue;
1158 +
1159 +    //if the event passes one of the veto triggers, exit and return false
1160 +    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1161 +      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1162 +    }
1163 +    //if the event passes one of the chosen triggers, set triggerDecision to true
1164 +    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1165 +      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1166 +    }  
1167 +  }
1168 +  //if none of the veto triggers fired:
1169 +  //return the OR of all the chosen triggers
1170 +  if (triggersToTest.size() != 0) return triggerDecision;
1171 +  //or if no triggers were defined return true
1172 +  else return true;
1173   }
1174  
1175 < std::vector<std::string>
1175 >
1176 > vector<string>
1177   OSUAnalysis::splitString (string inputString){
1178  
1179 <  std::stringstream stringStream(inputString);
1180 <  std::istream_iterator<std::string> begin(stringStream);
1181 <  std::istream_iterator<std::string> end;
1182 <  std::vector<std::string> stringVector(begin, end);
1179 >  stringstream stringStream(inputString);
1180 >  istream_iterator<string> begin(stringStream);
1181 >  istream_iterator<string> end;
1182 >  vector<string> stringVector(begin, end);
1183    return stringVector;
1184  
1185   }
1186  
1187 +
1188 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1189 +  // Set two object strings from the tempInputCollection string,
1190 +  // For example, if tempInputCollection is "electron-muon pairs",
1191 +  // then obj1 = "electrons" and obj2 = "muons".
1192 +  // Note that the objects have an "s" appended.
1193 +
1194 +  int dashIndex = tempInputCollection.find("-");
1195 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1196 +  int secondWordLength = spaceIndex - dashIndex;
1197 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1198 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1199 +
1200 + }
1201 +
1202 +
1203 + string OSUAnalysis::getObjToGet(string obj) {
1204 +  // Return the string corresponding to the object to get for the given obj string.
1205 +  // Right now this only handles the case in which obj contains "secondary",
1206 +  // e.g, "secondary muons".
1207 +  // Note that "s" is NOT appended.
1208 +
1209 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1210 +  int firstSpaceIndex = obj.find_first_of(" ");
1211 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1212 +
1213 + }
1214 +
1215 +
1216 + //!jet valueLookup
1217   double
1218 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1218 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1219  
1220    double value = 0.0;
1221    if(variable == "energy") value = object->energy;
# Line 962 | Line 1335 | OSUAnalysis::valueLookup (const BNjet* o
1335    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1336  
1337  
1338 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1338 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1339  
1340    value = applyFunction(function, value);
1341  
# Line 970 | Line 1343 | OSUAnalysis::valueLookup (const BNjet* o
1343   }
1344  
1345  
1346 <
1346 > //!muon valueLookup
1347   double
1348 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1348 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1349  
1350    double value = 0.0;
1351    if(variable == "energy") value = object->energy;
# Line 1133 | Line 1506 | OSUAnalysis::valueLookup (const BNmuon*
1506    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1507    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1508    else if(variable == "metMT") {
1509 <    const BNmet *met = chosenMET ();
1137 <    if (met)
1509 >    if (const BNmet *met = chosenMET ())
1510        {
1511 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1512 <          p2 (met->px, met->py, 0.0, met->pt);
1141 <
1142 <        value = (p1 + p2).Mt ();
1511 >        double dPhi = deltaPhi (object->phi, met->phi);
1512 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1513        }
1514      else
1515        value = -999;
# Line 1257 | Line 1627 | OSUAnalysis::valueLookup (const BNmuon*
1627      value = object->isGlobalMuon > 0                \
1628        && object->isPFMuon > 0                        \
1629        && object->normalizedChi2 < 10                \
1630 <                                  && object->numberOfValidMuonHits > 0        \
1630 >      && object->numberOfValidMuonHits > 0        \
1631        && object->numberOfMatchedStations > 1        \
1632        && fabs(object->correctedD0Vertex) < 0.2        \
1633        && fabs(object->correctedDZ) < 0.5        \
# Line 1266 | Line 1636 | OSUAnalysis::valueLookup (const BNmuon*
1636    }
1637    else if(variable == "tightIDdisplaced"){
1638      value = object->isGlobalMuon > 0                \
1639 +      && object->isPFMuon > 0                        \
1640        && object->normalizedChi2 < 10                \
1641 <                                  && object->numberOfValidMuonHits > 0        \
1641 >      && object->numberOfValidMuonHits > 0        \
1642        && object->numberOfMatchedStations > 1        \
1643        && object->numberOfValidPixelHits > 0        \
1644        && object->numberOfLayersWithMeasurement > 5;
1645    }
1646  
1647 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1647 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1648  
1649    else if(variable == "genMatchedPdgId"){
1650      int index = getGenMatchedParticleIndex(object);
# Line 1293 | Line 1664 | OSUAnalysis::valueLookup (const BNmuon*
1664    }
1665    else if(variable == "genMatchedMotherIdReverse"){
1666      int index = getGenMatchedParticleIndex(object);
1667 <    if(index == -1) value = 23;
1668 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1667 >    if(index == -1) value = 24;
1668 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1669    }
1670    else if(variable == "genMatchedGrandmotherId"){
1671      int index = getGenMatchedParticleIndex(object);
# Line 1306 | Line 1677 | OSUAnalysis::valueLookup (const BNmuon*
1677      }
1678      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1679    }
1680 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1681 +    int index = getGenMatchedParticleIndex(object);
1682 +    if(index == -1) value = 24;
1683 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1684 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1685 +      if(motherIndex == -1) value = 24;
1686 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1687 +    }
1688 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1689 +  }
1690 +  else if(variable == "pfMuonsFromVertex"){
1691 +    double d0Error, dzError;
1692 +
1693 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1694 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1695 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1696 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1697 +      || fabs (object->correctedDZ / dzError) > 99.0;
1698 +    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1699 +  }
1700  
1701  
1702  
1703 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1703 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1704  
1705    value = applyFunction(function, value);
1706  
1707    return value;
1708   }
1709  
1710 <
1710 > //!electron valueLookup
1711   double
1712 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1712 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1713  
1714    double value = 0.0;
1715    if(variable == "energy") value = object->energy;
# Line 1484 | Line 1875 | OSUAnalysis::valueLookup (const BNelectr
1875    else if(variable == "detIso") value = (object->trackIso) / object->pt;
1876    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1877    else if(variable == "metMT") {
1878 <    const BNmet *met = chosenMET ();
1488 <    if (met)
1878 >    if (const BNmet *met = chosenMET ())
1879        {
1880 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1881 <          p2 (met->px, met->py, 0.0, met->pt);
1492 <
1493 <        value = (p1 + p2).Mt ();
1880 >        double dPhi = deltaPhi (object->phi, met->phi);
1881 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1882        }
1883      else
1884        value = -999;
# Line 1655 | Line 2043 | OSUAnalysis::valueLookup (const BNelectr
2043    }
2044  
2045  
2046 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2046 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2047  
2048    else if(variable == "genMatchedPdgId"){
2049      int index = getGenMatchedParticleIndex(object);
# Line 1676 | Line 2064 | OSUAnalysis::valueLookup (const BNelectr
2064    }
2065    else if(variable == "genMatchedMotherIdReverse"){
2066      int index = getGenMatchedParticleIndex(object);
2067 <    if(index == -1) value = 23;
2068 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2067 >    if(index == -1) value = 24;
2068 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2069    }
2070    else if(variable == "genMatchedGrandmotherId"){
2071      int index = getGenMatchedParticleIndex(object);
# Line 1689 | Line 2077 | OSUAnalysis::valueLookup (const BNelectr
2077      }
2078      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2079    }
2080 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2081 +    int index = getGenMatchedParticleIndex(object);
2082 +    if(index == -1) value = 24;
2083 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2084 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2085 +      if(motherIndex == -1) value = 24;
2086 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2087 +    }
2088 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2089 +  }
2090 +  else if(variable == "pfElectronsFromVertex"){
2091 +    double d0Error, dzError;
2092  
2093 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2094 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2095 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2096 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2097 +      || fabs (object->correctedDZ / dzError) > 99.0;
2098 +    value = !value;
2099 +  }
2100  
2101  
2102 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2102 >
2103 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2104  
2105    value = applyFunction(function, value);
2106  
2107    return value;
2108   }
2109  
2110 <
2110 > //!event valueLookup
2111   double
2112 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2112 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2113  
2114    double value = 0.0;
2115  
# Line 1770 | Line 2178 | OSUAnalysis::valueLookup (const BNevent*
2178    else if(variable == "id2") value = object->id2;
2179    else if(variable == "evt") value = object->evt;
2180    else if(variable == "puScaleFactor"){
2181 <    if(datasetType_ != "data")
2181 >    if(doPileupReweighting_ && datasetType_ != "data")
2182        value = puWeight_->at (events->at (0).numTruePV);
2183      else
2184        value = 1.0;
2185    }
2186 <  else if(variable == "muonScaleFactor"){
2187 <    if(datasetType_ != "data")
2188 <      //      value = muonSFWeight_->at (chosenMuon ()->eta);
1781 <      value = 1.0;
1782 <    else
1783 <      value = 1.0;
1784 <  }
1785 <  else if(variable == "electronScaleFactor"){
1786 <    if(datasetType_ != "data")
1787 <      //      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1788 <      value = 1.0;
1789 <    else
1790 <      value = 1.0;
1791 <  }
2186 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2187 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2188 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2189  
2190 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2190 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2191  
2192    value = applyFunction(function, value);
2193  
2194    return value;
2195   }
2196  
2197 + //!tau valueLookup
2198   double
2199 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2199 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2200  
2201    double value = 0.0;
2202  
# Line 1844 | Line 2242 | OSUAnalysis::valueLookup (const BNtau* o
2242  
2243  
2244  
2245 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2245 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2246  
2247    else if(variable == "genMatchedPdgId"){
2248      int index = getGenMatchedParticleIndex(object);
# Line 1864 | Line 2262 | OSUAnalysis::valueLookup (const BNtau* o
2262    }
2263    else if(variable == "genMatchedMotherIdReverse"){
2264      int index = getGenMatchedParticleIndex(object);
2265 <    if(index == -1) value = 23;
2266 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2265 >    if(index == -1) value = 24;
2266 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2267    }
2268    else if(variable == "genMatchedGrandmotherId"){
2269      int index = getGenMatchedParticleIndex(object);
# Line 1877 | Line 2275 | OSUAnalysis::valueLookup (const BNtau* o
2275      }
2276      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2277    }
2278 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2279 +    int index = getGenMatchedParticleIndex(object);
2280 +    if(index == -1) value = 24;
2281 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2282 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2283 +      if(motherIndex == -1) value = 24;
2284 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2285 +    }
2286 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2287 +  }
2288  
2289  
2290 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2290 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2291  
2292    value = applyFunction(function, value);
2293  
2294    return value;
2295   }
2296  
2297 + //!met valueLookup
2298   double
2299 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2299 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2300  
2301    double value = 0.0;
2302  
# Line 1951 | Line 2360 | OSUAnalysis::valueLookup (const BNmet* o
2360    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2361    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2362  
2363 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2363 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2364  
2365    value = applyFunction(function, value);
2366  
2367    return value;
2368   }
2369  
2370 + //!track valueLookup
2371   double
2372 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2372 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2373  
2374    double value = 0.0;
2375    double pMag = sqrt(object->pt * object->pt +
2376 <                     object->pz * object->pz);
2377 <  
2376 >                     object->pz * object->pz);
2377 >
2378    if(variable == "pt") value = object->pt;
2379    else if(variable == "px") value = object->px;
2380    else if(variable == "py") value = object->py;
# Line 1985 | Line 2395 | OSUAnalysis::valueLookup (const BNtrack*
2395  
2396  
2397    //additional BNs info for disappTrks
1988  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2398    else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2399    else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2400    else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2401    else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2402    else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2403    else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2404 +  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2405    else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2406    else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2407    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2408 <  
2408 >  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2409  
2410    //user defined variables
2411    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;
2412    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2413 +  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2414    else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2415    else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2416 <  else if(variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object);  
2417 <  else if(variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object) / pMag;  
2416 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2417 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2418    else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2419    else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2420    else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2421    else if(variable == "ptError")                    value = object->ptError;
2422    else if(variable == "ptRes")                      value = getTrkPtRes(object);
2423 <  else if (variable == "d0wrtPV"){      
2424 <    double vx = object->vx - chosenVertex ()->x,        
2425 <      vy = object->vy - chosenVertex ()->y,      
2426 <      px = object->px,  
2427 <      py = object->py,  
2428 <      pt = object->pt;  
2429 <    value = (-vx * py + vy * px) / pt;  
2430 <  }      
2431 <  else if (variable == "dZwrtPV"){      
2432 <    double vx = object->vx - chosenVertex ()->x,        
2433 <      vy = object->vy - chosenVertex ()->y,      
2434 <      vz = object->vz - chosenVertex ()->z,      
2435 <      px = object->px,  
2436 <      py = object->py,  
2437 <      pz = object->pz,  
2438 <      pt = object->pt;  
2439 <    value = vz - (vx * px + vy * py)/pt * (pz/pt);      
2440 <  }    
2441 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2423 >  else if (variable == "d0wrtPV"){
2424 >    double vx = object->vx - chosenVertex ()->x,
2425 >      vy = object->vy - chosenVertex ()->y,
2426 >      px = object->px,
2427 >      py = object->py,
2428 >      pt = object->pt;
2429 >    value = (-vx * py + vy * px) / pt;
2430 >  }
2431 >  else if (variable == "dZwrtPV"){
2432 >    double vx = object->vx - chosenVertex ()->x,
2433 >      vy = object->vy - chosenVertex ()->y,
2434 >      vz = object->vz - chosenVertex ()->z,
2435 >      px = object->px,
2436 >      py = object->py,
2437 >      pz = object->pz,
2438 >      pt = object->pt;
2439 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2440 >  }
2441 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2442  
2443    else if(variable == "genMatchedPdgId"){
2444      int index = getGenMatchedParticleIndex(object);
# Line 2048 | Line 2459 | OSUAnalysis::valueLookup (const BNtrack*
2459    }
2460    else if(variable == "genMatchedMotherIdReverse"){
2461      int index = getGenMatchedParticleIndex(object);
2462 <    if(index == -1) value = 23;
2463 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2462 >    if(index == -1) value = 24;
2463 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2464    }
2465    else if(variable == "genMatchedGrandmotherId"){
2466      int index = getGenMatchedParticleIndex(object);
# Line 2061 | Line 2472 | OSUAnalysis::valueLookup (const BNtrack*
2472      }
2473      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2474    }
2475 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2476 +    int index = getGenMatchedParticleIndex(object);
2477 +    if(index == -1) value = 24;
2478 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2479 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2480 +      if(motherIndex == -1) value = 24;
2481 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2482 +    }
2483 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2484 +  }
2485  
2486  
2487  
2488 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2488 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2489  
2490    value = applyFunction(function, value);
2491  
2492    return value;
2493   }
2494  
2495 + //!genjet valueLookup
2496   double
2497 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2497 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2498  
2499    double value = 0.0;
2500  
# Line 2092 | Line 2514 | OSUAnalysis::valueLookup (const BNgenjet
2514    else if(variable == "charge") value = object->charge;
2515  
2516  
2517 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2517 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2518  
2519    value = applyFunction(function, value);
2520  
2521    return value;
2522   }
2523  
2524 + //!mcparticle valueLookup
2525   double
2526 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2526 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2527  
2528    double value = 0.0;
2529  
# Line 2225 | Line 2648 | OSUAnalysis::valueLookup (const BNmcpart
2648    }
2649  
2650  
2651 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2651 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2652  
2653    value = applyFunction(function, value);
2654  
2655    return value;
2656   }
2657  
2658 + //!primaryvertex valueLookup
2659   double
2660 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2660 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2661  
2662    double value = 0.0;
2663  
# Line 2252 | Line 2676 | OSUAnalysis::valueLookup (const BNprimar
2676    else if(variable == "isGood") value = object->isGood;
2677  
2678  
2679 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2679 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2680  
2681    value = applyFunction(function, value);
2682  
2683    return value;
2684   }
2685  
2686 + //!bxlumi valueLookup
2687   double
2688 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2688 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2689  
2690    double value = 0.0;
2691  
# Line 2269 | Line 2694 | OSUAnalysis::valueLookup (const BNbxlumi
2694    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2695  
2696  
2697 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2697 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2698  
2699    value = applyFunction(function, value);
2700  
2701    return value;
2702   }
2703  
2704 + //!photon valueLookup
2705   double
2706 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2706 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2707  
2708    double value = 0.0;
2709  
# Line 2352 | Line 2778 | OSUAnalysis::valueLookup (const BNphoton
2778    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2779  
2780  
2355
2781  
2782 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2782 >
2783 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2784  
2785    else if(variable == "genMatchedPdgId"){
2786      int index = getGenMatchedParticleIndex(object);
# Line 2376 | Line 2802 | OSUAnalysis::valueLookup (const BNphoton
2802    }
2803    else if(variable == "genMatchedMotherIdReverse"){
2804      int index = getGenMatchedParticleIndex(object);
2805 <    if(index == -1) value = 23;
2806 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2805 >    if(index == -1) value = 24;
2806 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2807    }
2808    else if(variable == "genMatchedGrandmotherId"){
2809      int index = getGenMatchedParticleIndex(object);
# Line 2389 | Line 2815 | OSUAnalysis::valueLookup (const BNphoton
2815      }
2816      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2817    }
2818 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2819 +    int index = getGenMatchedParticleIndex(object);
2820 +    if(index == -1) value = 24;
2821 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2822 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2823 +      if(motherIndex == -1) value = 24;
2824 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2825 +    }
2826 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2827 +  }
2828  
2829  
2830 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2830 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2831  
2832    value = applyFunction(function, value);
2833  
2834    return value;
2835   }
2836  
2837 + //!supercluster valueLookup
2838   double
2839 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
2839 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
2840  
2841    double value = 0.0;
2842  
# Line 2413 | Line 2850 | OSUAnalysis::valueLookup (const BNsuperc
2850    else if(variable == "theta") value = object->theta;
2851  
2852  
2853 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2853 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2854  
2855    value = applyFunction(function, value);
2856  
2857    return value;
2858   }
2859  
2860 + //!trigobj valueLookup
2861 + double
2862 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
2863 +
2864 +  double value = 0.0;
2865 +
2866 +  if(variable == "pt") value = object->pt;
2867 +  else if(variable == "eta") value = object->eta;
2868 +  else if(variable == "phi") value = object->phi;
2869 +  else if(variable == "px") value = object->px;
2870 +  else if(variable == "py") value = object->py;
2871 +  else if(variable == "pz") value = object->pz;
2872 +  else if(variable == "et") value = object->et;
2873 +  else if(variable == "energy") value = object->energy;
2874 +  else if(variable == "etTotal") value = object->etTotal;
2875 +  else if(variable == "id") value = object->id;
2876 +  else if(variable == "charge") value = object->charge;
2877 +  else if(variable == "isIsolated") value = object->isIsolated;
2878 +  else if(variable == "isMip") value = object->isMip;
2879 +  else if(variable == "isForward") value = object->isForward;
2880 +  else if(variable == "isRPC") value = object->isRPC;
2881 +  else if(variable == "bx") value = object->bx;
2882 +  else if(variable == "filter") {
2883 +    if ((stringValue = object->filter) == "")
2884 +      stringValue = "none";  // stringValue should only be empty if value is filled
2885 +  }
2886 +
2887 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2888 +
2889 +  value = applyFunction(function, value);
2890 +
2891 +  return value;
2892 + }
2893  
2894 + //!muon-muon pair valueLookup
2895   double
2896 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
2896 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
2897  
2898    double value = 0.0;
2899  
2900    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2901 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2902    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2903    else if(variable == "invMass"){
2904      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2483 | Line 2955 | OSUAnalysis::valueLookup (const BNmuon*
2955        value = object2->correctedD0;
2956      }
2957  
2958 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2958 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2959  
2960    value = applyFunction(function, value);
2961  
2962    return value;
2963   }
2964  
2965 + //!electron-electron pair valueLookup
2966   double
2967 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
2967 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
2968  
2969    double value = 0.0;
2970  
2971    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2972 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2973    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2974    else if(variable == "invMass"){
2975      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2537 | Line 3011 | OSUAnalysis::valueLookup (const BNelectr
3011      value = object2->correctedD0;
3012    }
3013  
3014 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3014 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3015  
3016    value = applyFunction(function, value);
3017  
3018    return value;
3019   }
3020 <
3020 > //!electron-muon pair valueLookup
3021   double
3022 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3022 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3023  
3024    double value = 0.0;
3025  
3026    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3027 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3028    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3029    else if(variable == "invMass"){
3030      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2596 | Line 3071 | OSUAnalysis::valueLookup (const BNelectr
3071    else if(variable == "muonDetIso"){
3072      value = (object2->trackIsoDR03) / object2->pt;
3073    }
3074 +  else if(variable == "electronRelPFrhoIso"){
3075 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3076 +  }
3077 +  else if(variable == "muonRelPFdBetaIso"){
3078 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3079 +  }
3080 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3081 +  value = applyFunction(function, value);
3082 +
3083 +  return value;
3084 + }
3085  
3086 + //!electron-jet pair valueLookup
3087 + double
3088 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3089  
3090 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3090 >  double value = 0.0;
3091 >
3092 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3093 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3094 >  else if(variable == "jetEta") value = object2->eta;
3095 >  else if(variable == "jetPhi") value = object2->phi;
3096 >  else if(variable == "electronEta") value = object1->eta;
3097 >  else if(variable == "electronPhi") value = object1->phi;
3098 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3099 >  else if(variable == "invMass"){
3100 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3101 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3102 >    value = (fourVector1 + fourVector2).M();
3103 >  }
3104 >  else if(variable == "pt"){
3105 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3106 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3107 >    value = (fourVector1 + fourVector2).Pt();
3108 >  }
3109 >  else if(variable == "threeDAngle")
3110 >    {
3111 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3112 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3113 >      value = (threeVector1.Angle(threeVector2));
3114 >    }
3115 >  else if(variable == "chargeProduct"){
3116 >    value = object1->charge*object2->charge;
3117 >  }
3118 >
3119 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3120 >  value = applyFunction(function, value);
3121 >
3122 >  return value;
3123 > }
3124 >
3125 > //!muon-jet pair valueLookup
3126 > double
3127 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3128 >
3129 >  double value = 0.0;
3130 >
3131 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3132 >  else if(variable == "jetEta") value = object2->eta;
3133 >  else if(variable == "jetPhi") value = object2->phi;
3134 >  else if(variable == "muonEta") value = object1->eta;
3135 >  else if(variable == "muonPhi") value = object1->phi;
3136 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3137 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3138 >  else if(variable == "invMass"){
3139 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3140 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3141 >    value = (fourVector1 + fourVector2).M();
3142 >  }
3143 >  else if(variable == "pt"){
3144 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3145 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3146 >    value = (fourVector1 + fourVector2).Pt();
3147 >  }
3148 >  else if(variable == "threeDAngle")
3149 >    {
3150 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3151 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3152 >      value = (threeVector1.Angle(threeVector2));
3153 >    }
3154 >  else if(variable == "chargeProduct"){
3155 >    value = object1->charge*object2->charge;
3156 >  }
3157  
3158 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3159    value = applyFunction(function, value);
3160  
3161    return value;
3162   }
3163  
3164 + //!jet-jet pair valueLookup
3165 + double
3166 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3167  
3168 < double  
3169 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function){  
3170 <  double electronMass = 0.000511;        
3171 <  double value = 0.0;    
3172 <  TLorentzVector fourVector1(0, 0, 0, 0);        
3173 <  TLorentzVector fourVector2(0, 0, 0, 0);        
3174 <  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));  
3175 <  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);    
3176 <  else if(variable == "invMass"){        
3177 <    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);    
3178 <    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );    
3179 <        
3180 <    value = (fourVector1 + fourVector2).M();    
3168 >  double value = 0.0;
3169 >
3170 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3171 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3172 >  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3173 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3174 >  else if(variable == "invMass"){
3175 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3176 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3177 >    value = (fourVector1 + fourVector2).M();
3178 >  }
3179 >  else if(variable == "pt"){
3180 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3181 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3182 >    value = (fourVector1 + fourVector2).Pt();
3183    }
3184 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}  
3185 <  value = applyFunction(function, value);        
3186 <  return value;  
3184 >  else if(variable == "threeDAngle")
3185 >    {
3186 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3187 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3188 >      value = (threeVector1.Angle(threeVector2));
3189 >    }
3190 >  else if(variable == "chargeProduct"){
3191 >    value = object1->charge*object2->charge;
3192 >  }
3193 >
3194 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3195 >  value = applyFunction(function, value);
3196 >
3197 >  return value;
3198   }
3199 + //!electron-track pair valueLookup
3200 + double
3201 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3202 +  double electronMass = 0.000511;
3203 +  double value = 0.0;
3204 +  TLorentzVector fourVector1(0, 0, 0, 0);
3205 +  TLorentzVector fourVector2(0, 0, 0, 0);
3206 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3207 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3208 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3209 +  else if(variable == "invMass"){
3210 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3211 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3212  
3213 +    value = (fourVector1 + fourVector2).M();
3214 +  }
3215 +  else if(variable == "chargeProduct"){
3216 +    value = object1->charge*object2->charge;
3217 +  }
3218 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3219 +  value = applyFunction(function, value);
3220 +  return value;
3221 +
3222 + }
3223  
3224  
3225 + //!muon-track pair valueLookup
3226   double
3227 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function){
3227 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3228    double pionMass = 0.140;
3229    double muonMass = 0.106;
3230    double value = 0.0;
3231    TLorentzVector fourVector1(0, 0, 0, 0);
3232    TLorentzVector fourVector2(0, 0, 0, 0);
3233    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3234 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3235    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3236    else if(variable == "invMass"){
3237      fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
# Line 2642 | Line 3239 | OSUAnalysis::valueLookup (const BNmuon*
3239  
3240      value = (fourVector1 + fourVector2).M();
3241    }
3242 +  else if(variable == "chargeProduct"){
3243 +    value = object1->charge*object2->charge;
3244 +  }
3245  
3246    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3247    value = applyFunction(function, value);
3248    return value;
3249   }
3250  
3251 <
3251 > //!tau-tau pair valueLookup
3252   double
3253 < OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function){
3253 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3254    double value = 0.0;
3255    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3256 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3257    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3258    else if(variable == "invMass"){
3259      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2660 | Line 3261 | OSUAnalysis::valueLookup (const BNtau* o
3261      value = (fourVector1 + fourVector2).M();
3262    }
3263  
3264 +  else if(variable == "chargeProduct"){
3265 +    value = object1->charge*object2->charge;
3266 +  }
3267 +
3268    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3269    value = applyFunction(function, value);
3270    return value;
3271   }
3272  
3273 <
3273 > //!muon-tau pair valueLookup
3274   double
3275 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function){
3275 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3276    double value = 0.0;
3277    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3278 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3279    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3280    else if(variable == "invMass"){
3281      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2677 | Line 3283 | OSUAnalysis::valueLookup (const BNmuon*
3283      value = (fourVector1 + fourVector2).M();
3284    }
3285  
3286 +  else if(variable == "chargeProduct"){
3287 +    value = object1->charge*object2->charge;
3288 +  }
3289 +
3290    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3291    value = applyFunction(function, value);
3292    return value;
3293   }
3294  
3295 + //!tau-track pair valueLookup
3296 + double
3297 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3298 +  double value = 0.0;
3299 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3300 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3301 +  else if(variable == "chargeProduct"){
3302 +    value = object1->charge*object2->charge;
3303 +  }
3304 +
3305 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3306 +  value = applyFunction(function, value);
3307 +  return value;
3308 + }
3309  
3310 +
3311 + //!track-event pair valueLookup
3312   double
3313 < OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function){
3313 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3314  
3315    double value = 0.0;
3316    double pMag = sqrt(object1->pt * object1->pt +
3317 <                     object1->pz * object1->pz);  
3317 >                     object1->pz * object1->pz);
3318  
3319    if      (variable == "numPV")                      value = object2->numPV;
3320    else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3321    else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3322 <  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);  
3323 <  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;  
3322 >  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3323 >  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3324 >
3325 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3326 >
3327 >  value = applyFunction(function, value);
3328 >
3329 >  return value;
3330 >
3331 > }
3332  
3333 <  else { std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3333 > //!electron-trigobj pair valueLookup
3334 > double
3335 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3336 >
3337 >  double value = 0.0;
3338 >
3339 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3340 >  else if (variable == "match"){
3341 >    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3342 >      stringValue = object2->filter;
3343 >    else
3344 >      stringValue = "none";
3345 >  }
3346 >
3347 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3348  
3349    value = applyFunction(function, value);
3350  
3351    return value;
3352  
3353 < }  
3353 > }
3354 >
3355 > //!muon-trigobj pair valueLookup
3356 > double
3357 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3358 >
3359 >  double value = 0.0;
3360 >
3361 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3362 >
3363 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3364 >
3365 >  value = applyFunction(function, value);
3366 >
3367 >  return value;
3368 >
3369 > }
3370 >
3371 > //!stop valueLookup
3372 > double
3373 > OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3374 >
3375 >
3376 >  double value = 0.0;
3377 >
3378 >  if(variable == "ctau") value = object->ctau;
3379 >
3380 >  else if (variable == "d0"){
3381 >    double vx = object->vx - chosenVertex ()->x,
3382 >      vy = object->vy - chosenVertex ()->y,
3383 >      px = object->px,
3384 >      py = object->py,
3385 >      pt = object->pt;
3386 >    value = (-vx * py + vy * px) / pt;
3387 >  }
3388 >
3389 >  else if (variable == "dz"){
3390 >    double vx = object->vx - chosenVertex ()->x,
3391 >      vy = object->vy - chosenVertex ()->y,
3392 >      vz = object->vz - chosenVertex ()->z,
3393 >      px = object->px,
3394 >      py = object->py,
3395 >      pz = object->pz,
3396 >      pt = object->pt;
3397 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3398 >  }
3399 >
3400 >  else if (variable == "minD0"){
3401 >    double minD0=999;
3402 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3403 >      double vx = object->vx - vertex->x,
3404 >        vy = object->vy - vertex->y,
3405 >        px = object->px,
3406 >        py = object->py,
3407 >        pt = object->pt;
3408 >      value = (-vx * py + vy * px) / pt;
3409 >      if(abs(value) < abs(minD0)) minD0 = value;
3410 >    }
3411 >    value = minD0;
3412 >  }
3413 >  else if (variable == "minDz"){
3414 >    double minDz=999;
3415 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3416 >      double vx = object->vx - vertex->x,
3417 >        vy = object->vy - vertex->y,
3418 >        vz = object->vz - vertex->z,
3419 >        px = object->px,
3420 >        py = object->py,
3421 >        pz = object->pz,
3422 >        pt = object->pt;
3423 >      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3424 >      if(abs(value) < abs(minDz)) minDz = value;
3425 >    }
3426 >    value = minDz;
3427 >  }
3428 >  else if(variable == "distToVertex"){
3429 >    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3430 >                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3431 >                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3432 >  }
3433 >  else if (variable == "minDistToVertex"){
3434 >    double minDistToVertex=999;
3435 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3436 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3437 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3438 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
3439 >
3440 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3441 >    }
3442 >    value = minDistToVertex;
3443 >  }
3444 >  else if (variable == "distToVertexDifference"){
3445 >    double minDistToVertex=999;
3446 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3447 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3448 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3449 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
3450 >
3451 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3452 >    }
3453 >    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3454 >                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3455 >                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3456 >
3457 >    value = distToChosenVertex - minDistToVertex;
3458 >  }
3459 >
3460 >  else if (variable == "closestVertexRank"){
3461 >    double minDistToVertex=999;
3462 >    int vertex_rank = 0;
3463 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3464 >      vertex_rank++;
3465 >      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3466 >                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
3467 >                      (object->vz-vertex->z)*(object->vz-vertex->z));
3468 >
3469 >      if(abs(dist) < abs(minDistToVertex)){
3470 >        value = vertex_rank;
3471 >        minDistToVertex = dist;
3472 >      }
3473 >    }
3474 >  }
3475 >
3476 >
3477 >
3478 >
3479 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3480 >
3481 >  value = applyFunction(function, value);
3482 >
3483 >  return value;
3484 >
3485 > }
3486 >
3487 >
3488 >
3489  
3490   // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3491   // Return true iff no other tracks are found in this cone.
# Line 2751 | Line 3534 | OSUAnalysis::getTrkPtTrue (const BNtrack
3534  
3535   double
3536   OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3537 <  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.  
3538 <  if (!useTrackCaloRhoCorr_) return -99;  
3539 <  // if (!rhokt6CaloJetsHandle_) {
3540 <  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;  
3541 <  //   return -99;  
3537 >  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3538 >  if (!useTrackCaloRhoCorr_) return -99;
3539 >  // if (!rhokt6CaloJetsHandle_) {
3540 >  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3541 >  //   return -99;
3542    // }
3543 <  double radDeltaRCone = 0.5;  
3544 <  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.  
3545 <  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;  
3546 <  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);  
3547 <  return caloTotRhoCorrCalo;  
3548 <
3543 >  double radDeltaRCone = 0.5;
3544 >  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3545 >  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3546 >  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3547 >  return caloTotRhoCorrCalo;
3548 >
3549   }
3550  
3551  
# Line 2800 | Line 3583 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3583    double deltaRLowest = 999;
3584    int value = 0;
3585    if (DeadEcalVec.size() == 0) WriteDeadEcal();
3586 <  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3586 >  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3587      double eta = ecal->etaEcal;
3588      double phi = ecal->phiEcal;
3589 <    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
3589 >    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
3590      if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3591    }
3592    if (deltaRLowest<0.05) {value = 1;}
# Line 2811 | Line 3594 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3594    return value;
3595   }
3596  
3597 < // Returns the smallest DeltaR between the object and any generated true particle in the event.  
3597 > // Returns the smallest DeltaR between the object and any generated true particle in the event.
3598   template <class InputObject>
3599   double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3600    double genDeltaRLowest = 999.;
# Line 2831 | Line 3614 | OSUAnalysis::applyFunction(string functi
3614    else if(function == "log") value = log10(value);
3615  
3616    else if(function == "") value = value;
3617 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
3617 >  else{cout << "WARNING: invalid function '" << function << "'\n";}
3618  
3619    return value;
3620  
# Line 2841 | Line 3624 | OSUAnalysis::applyFunction(string functi
3624   template <class InputCollection>
3625   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
3626  
3627 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
3628 +    string obj1, obj2;
3629 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
3630 +    if (inputType==obj1 ||
3631 +        inputType==obj2) {
3632 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
3633 +      // and the inputType is a member of the pair.
3634 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
3635 +      // For example, if currentCut.inputCollection==electron-muon pairs,
3636 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
3637 +      return;
3638 +    }
3639 +  }
3640  
3641    for (uint object = 0; object != inputCollection->size(); object++){
3642  
2847
3643      bool decision = true;//object passes if this cut doesn't cut on that type of object
3644  
2850
3645      if(currentCut.inputCollection == inputType){
3646  
3647        vector<bool> subcutDecisions;
3648        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3649 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3650 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3649 >        string stringValue = "";
3650 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3651 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3652 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3653 >
3654        }
3655        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3656        else{
# Line 2867 | Line 3664 | void OSUAnalysis::setObjectFlags(cut &cu
3664          decision = tempDecision;
3665        }
3666      }
2870    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3667  
3668 +    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3669  
3670      //set flags for objects that pass each cut AND all the previous cuts
3671      bool previousCumulativeFlag = true;
# Line 2878 | Line 3675 | void OSUAnalysis::setObjectFlags(cut &cu
3675      }
3676      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3677  
2881
3678    }
3679  
3680   }
# Line 2892 | Line 3688 | void OSUAnalysis::setObjectFlags(cut &cu
3688    bool sameObjects = false;
3689    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3690  
3691 +  // Get the strings for the two objects that make up the pair.
3692 +  string obj1Type, obj2Type;
3693 +  getTwoObjs(inputType, obj1Type, obj2Type);
3694 +  bool isTwoTypesOfObject = true;
3695 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
3696 +
3697 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
3698 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
3699 +  if (currentCut.inputCollection == inputType) {
3700 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
3701 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3702 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3703 +    }
3704 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
3705 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
3706 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3707 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3708 +      }
3709 +    }
3710 +  }
3711  
3712    int counter = 0;
3713 +
3714    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3715      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3716  
# Line 2906 | Line 3723 | void OSUAnalysis::setObjectFlags(cut &cu
3723  
3724          vector<bool> subcutDecisions;
3725          for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3726 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3727 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3726 >          string stringValue = "";
3727 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3728 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3729 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3730          }
3731  
3732          if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
# Line 2922 | Line 3741 | void OSUAnalysis::setObjectFlags(cut &cu
3741            decision = tempDecision;
3742          }
3743        }
3744 +      // if (decision) isPassObj1.at(object1) = true;
3745 +      // if (decision) isPassObj2.at(object2) = true;
3746        individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3747 +      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3748 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;
3749 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;
3750 +      }
3751  
3752        //set flags for objects that pass each cut AND all the previous cuts
3753        bool previousCumulativeFlag = true;
# Line 2937 | Line 3762 | void OSUAnalysis::setObjectFlags(cut &cu
3762        else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
3763        else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
3764        cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
3765 <
3765 >      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3766 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);
3767 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);
3768 >      }
3769        counter++;
2942    }
3770  
3771 +    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
3772 +  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
3773 +
3774 + }
3775 +
3776 +
3777 + bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
3778 +  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
3779 +  // all cuts up to currentCutIndex
3780 +  bool previousCumulativeFlag = true;
3781 +  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
3782 +    if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
3783 +    else {
3784 +      previousCumulativeFlag = false; break;
3785 +    }
3786    }
3787 +  return previousCumulativeFlag;
3788 + }
3789  
3790  
3791 +
3792 + template <class InputCollection>
3793 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, vector<bool> flags){
3794 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree  
3795 +
3796 +  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;  
3797 +  for (uint object = 0; object != inputCollection->size(); object++) {  
3798 +
3799 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;  
3800 +
3801 +    string inputVariable = parameters.inputVariable;
3802 +    string function = "";
3803 +    string stringValue = "";  
3804 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);  
3805 +    BNTreeBranchVals_.at(parameters.name).push_back(value);  
3806 +
3807 +  }
3808   }
3809  
3810  
# Line 2957 | Line 3818 | void OSUAnalysis::fill1DHistogram(TH1* h
3818      string currentString = parameters.inputVariables.at(0);
3819      string inputVariable = "";
3820      string function = "";
3821 <    if(currentString.find("(")==std::string::npos){
3821 >    if(currentString.find("(")==string::npos){
3822        inputVariable = currentString;// variable to cut on
3823      }
3824      else{
3825        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3826        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3827        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3828 <    }
3828 >    }  
3829  
3830 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
3831 <    histo->Fill(value,scaleFactor);
3830 >    string stringValue = "";  
3831 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);  
3832 >    histo->Fill(value,scaleFactor);  
3833  
3834      if (printEventInfo_) {
3835 <      // Write information about event to screen, for testing purposes.  
3836 <      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;  
3835 >      // Write information about event to screen, for testing purposes.
3836 >      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
3837      }
3838 <    
3838 >
3839    }
3840   }
3841  
# Line 2983 | Line 3845 | void OSUAnalysis::fill1DHistogram(TH1* h
3845    bool sameObjects = false;
3846    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3847  
3848 <  int pairCounter = 0;
3848 >  int pairCounter = -1;
3849    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3850      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3851  
3852        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3853  
3854 +      pairCounter++;
3855        //only take objects which have passed all cuts and pairs which have passed all cuts
3856        if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3857        if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
# Line 2997 | Line 3860 | void OSUAnalysis::fill1DHistogram(TH1* h
3860        string currentString = parameters.inputVariables.at(0);
3861        string inputVariable = "";
3862        string function = "";
3863 <      if(currentString.find("(")==std::string::npos){
3863 >      if(currentString.find("(")==string::npos){
3864          inputVariable = currentString;// variable to cut on
3865        }
3866        else{
# Line 3006 | Line 3869 | void OSUAnalysis::fill1DHistogram(TH1* h
3869          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3870        }
3871  
3872 <      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3872 >      string stringValue = "";
3873 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3874        histo->Fill(value,scaleFactor);
3875  
3012      pairCounter++;
3876      }
3877    }
3878  
# Line 3023 | Line 3886 | void OSUAnalysis::fill2DHistogram(TH2* h
3886  
3887      if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3888  
3889 +    string stringValue = "";
3890      string currentString = parameters.inputVariables.at(0);
3891      string inputVariable = "";
3892      string function = "";
3893 <    if(currentString.find("(")==std::string::npos){
3893 >    if(currentString.find("(")==string::npos){
3894        inputVariable = currentString;// variable to cut on
3895      }
3896      else{
# Line 3034 | Line 3898 | void OSUAnalysis::fill2DHistogram(TH2* h
3898        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3899        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3900      }
3901 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
3901 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3902  
3903      currentString = parameters.inputVariables.at(1);
3904      inputVariable = "";
3905      function = "";
3906 <    if(currentString.find("(")==std::string::npos){
3906 >    if(currentString.find("(")==string::npos){
3907        inputVariable = currentString;// variable to cut on
3908      }
3909      else{
# Line 3048 | Line 3912 | void OSUAnalysis::fill2DHistogram(TH2* h
3912        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3913      }
3914  
3915 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
3915 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3916  
3917      histo->Fill(valueX,valueY,scaleFactor);
3918  
# Line 3062 | Line 3926 | void OSUAnalysis::fill2DHistogram(TH2* h
3926    bool sameObjects = false;
3927    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3928  
3929 <  int pairCounter = 0;
3929 >  int pairCounter = -1;
3930    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3931      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3932  
3933        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3934  
3935 +      pairCounter++;
3936 +
3937        //only take objects which have passed all cuts and pairs which have passed all cuts
3938        if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3939        if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3940        if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3941  
3942 +      string stringValue = "";
3943        string currentString = parameters.inputVariables.at(0);
3944        string inputVariable = "";
3945        string function = "";
3946 <      if(currentString.find("(")==std::string::npos){
3946 >      if(currentString.find("(")==string::npos){
3947          inputVariable = currentString;// variable to cut on
3948        }
3949        else{
# Line 3084 | Line 3951 | void OSUAnalysis::fill2DHistogram(TH2* h
3951          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3952          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3953        }
3954 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3954 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3955  
3956        currentString = parameters.inputVariables.at(1);
3957        inputVariable = "";
3958        function = "";
3959 <      if(currentString.find("(")==std::string::npos){
3959 >      if(currentString.find("(")==string::npos){
3960          inputVariable = currentString;// variable to cut on
3961        }
3962        else{
# Line 3097 | Line 3964 | void OSUAnalysis::fill2DHistogram(TH2* h
3964          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3965          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3966        }
3967 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3967 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3968  
3969  
3970        histo->Fill(valueX,valueY,scaleFactor);
3971  
3105      pairCounter++;
3106
3972      }
3973    }
3974  
# Line 3120 | Line 3985 | int OSUAnalysis::getGenMatchedParticleIn
3985  
3986      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
3987      if(currentDeltaR > 0.05) continue;
3988 <    //     cout << std::setprecision(3) << std::setw(20)
3988 >    //     cout << setprecision(3) << setw(20)
3989      //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
3990 <    //          << std::setw(20)
3990 >    //          << setw(20)
3991      //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
3992 <    //          << std::setw(20)
3992 >    //          << setw(20)
3993      //          << "\tdeltaR = " << currentDeltaR
3994 <    //          << std::setprecision(1)
3995 <    //          << std::setw(20)
3994 >    //          << setprecision(1)
3995 >    //          << setw(20)
3996      //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
3997 <    //          << std::setw(20)
3997 >    //          << setw(20)
3998      //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
3999 <    //          << std::setw(20)
3999 >    //          << setw(20)
4000      //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4001      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4002        bestMatchIndex = mcparticle - mcparticles->begin();
# Line 3194 | Line 4059 | int OSUAnalysis::findTauMotherIndex(cons
4059   // 20        strange baryon
4060   // 21        charm baryon
4061   // 22        bottom baryon
4062 < // 23        other
4062 > // 23        QCD string
4063 > // 24        other
4064  
4065   int OSUAnalysis::getPdgIdBinValue(int pdgId){
4066  
# Line 3218 | Line 4084 | int OSUAnalysis::getPdgIdBinValue(int pd
4084    else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4085    else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4086    else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4087 +  else if(absPdgId == 92  ) binValue = 23;
4088  
4089 <  else binValue = 23;
4089 >  else binValue = 24;
4090  
4091    return binValue;
4092  
# Line 3229 | Line 4096 | const BNprimaryvertex *
4096   OSUAnalysis::chosenVertex ()
4097   {
4098    const BNprimaryvertex *chosenVertex = 0;
4099 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
4100 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
4101 <      cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
4099 >  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4100 >    vector<bool> vertexFlags;
4101 >    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4102 >      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4103 >        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4104 >        break;
4105 >      }
4106 >    }
4107      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4108        if(!vertexFlags.at(vertexIndex)) continue;
4109        chosenVertex = & primaryvertexs->at(vertexIndex);
4110        break;
4111      }
4112    }
4113 <  else {
4114 <    chosenVertex = &primaryvertexs->at(0);
3243 <  }
4113 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4114 >    chosenVertex = & primaryvertexs->at (0);
4115  
4116    return chosenVertex;
4117   }
# Line 3249 | Line 4120 | const BNmet *
4120   OSUAnalysis::chosenMET ()
4121   {
4122    const BNmet *chosenMET = 0;
4123 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
4124 <    vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
4125 <      cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
4123 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4124 >    vector<bool> metFlags;
4125 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4126 >      if (cumulativeFlags.at("mets").at(i).size()){
4127 >        metFlags = cumulativeFlags.at("mets").at(i);
4128 >        break;
4129 >      }
4130 >    }
4131      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4132        if(!metFlags.at(metIndex)) continue;
4133        chosenMET = & mets->at(metIndex);
4134        break;
4135      }
4136    }
4137 <  else {
4138 <    chosenMET = &mets->at(0);
3263 <  }
4137 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4138 >    chosenMET = & mets->at (0);
4139  
4140    return chosenMET;
4141   }
# Line 3269 | Line 4144 | const BNelectron *
4144   OSUAnalysis::chosenElectron ()
4145   {
4146    const BNelectron *chosenElectron = 0;
4147 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
4148 <    vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
4149 <      cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
4147 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4148 >    vector<bool> electronFlags;
4149 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4150 >      if (cumulativeFlags.at("electrons").at(i).size()){
4151 >        electronFlags = cumulativeFlags.at("electrons").at(i);
4152 >        break;
4153 >      }
4154 >    }
4155      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4156        if(!electronFlags.at(electronIndex)) continue;
4157        chosenElectron = & electrons->at(electronIndex);
4158        break;
4159      }
4160    }
4161 <  else {
4162 <    chosenElectron = &electrons->at(0);
3283 <  }
4161 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4162 >    chosenElectron = & electrons->at (0);
4163  
4164    return chosenElectron;
4165   }
# Line 3289 | Line 4168 | const BNmuon *
4168   OSUAnalysis::chosenMuon ()
4169   {
4170    const BNmuon *chosenMuon = 0;
4171 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
4172 <    vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
4173 <      cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
4171 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4172 >    vector<bool> muonFlags;
4173 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4174 >      if (cumulativeFlags.at("muons").at(i).size()){
4175 >        muonFlags = cumulativeFlags.at("muons").at(i);
4176 >        break;
4177 >      }
4178 >    }
4179      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4180        if(!muonFlags.at(muonIndex)) continue;
4181        chosenMuon = & muons->at(muonIndex);
4182        break;
4183      }
4184    }
4185 <  else {
4186 <    chosenMuon = &muons->at(0);
3303 <  }
4185 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4186 >    chosenMuon = & muons->at (0);
4187  
4188    return chosenMuon;
4189   }
4190  
3308
4191   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines