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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines