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.39 by jbrinson, Wed Mar 27 16:52:25 2013 UTC vs.
Revision 1.100 by ahart, Tue Jul 16 19:48:04 2013 UTC

# Line 1 | Line 1
1   #include "OSUT3Analysis/AnaTools/plugins/OSUAnalysis.h"
2
2   OSUAnalysis::OSUAnalysis (const edm::ParameterSet &cfg) :
3    // Retrieve parameters from the configuration file.
4    jets_ (cfg.getParameter<edm::InputTag> ("jets")),
# Line 11 | Line 10 | OSUAnalysis::OSUAnalysis (const edm::Par
10    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
11    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
12    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
13 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
14    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
15    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
16    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
17    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
18    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
19 <  puFile_ (cfg.getParameter<std::string> ("puFile")),
20 <  deadEcalFile_ (cfg.getParameter<std::string> ("deadEcalFile")),
21 <  
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")),
19 >  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
20 >  puFile_ (cfg.getParameter<string> ("puFile")),
21 >  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
22 >  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
23 >  dataPU_ (cfg.getParameter<string> ("dataPU")),
24 >  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
25 >  muonSF_ (cfg.getParameter<string> ("muonSF")),
26 >  dataset_ (cfg.getParameter<string> ("dataset")),
27 >  datasetType_ (cfg.getParameter<string> ("datasetType")),
28    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
29    histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
30 +  useEDMFormat_   (cfg.getParameter<bool>("useEDMFormat")),
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 < {
34 >  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
35 >  applyBtagSF_ (cfg.getParameter<bool> ("applyBtagSF")),
36 >  minBtag_ (cfg.getParameter<int> ("minBtag")),
37 >  printEventInfo_      (cfg.getParameter<bool> ("printEventInfo")),
38 >  printAllTriggers_    (cfg.getParameter<bool> ("printAllTriggers")),
39 >  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
40 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
41 >  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
42 > {
43  
44    TH1::SetDefaultSumw2 ();
45  
46    //create pile-up reweighting object, if necessary
47    if(datasetType_ != "data") {
48      if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
49 <    //    muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
50 <    //    electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
49 >    if (applyLeptonSF_){
50 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
51 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
52 >    }
53 >    if (applyBtagSF_){
54 >      bTagSFWeight_ = new BtagSFWeight;
55 >    }
56    }
57 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
58 +    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
59  
60  
61    // Construct Cutflow Objects. These store the results of cut decisions and
62    // handle filling cut flow histograms.
63    masterCutFlow_ = new CutFlow (fs_);
48  std::vector<TFileDirectory> directories;
64  
65    //always get vertex collection so we can assign the primary vertex in the event
66    objectsToGet.push_back("primaryvertexs");
52
53  //always make the plot of number of primary verticex (to check pile-up reweighting)
67    objectsToPlot.push_back("primaryvertexs");
68 +  objectsToFlag.push_back("primaryvertexs");
69 +
70  
71    //always get the MC particles to do GEN-matching
72    objectsToGet.push_back("mcparticles");
# Line 59 | Line 74 | muonSFFile_ (cfg.getParameter<std::strin
74    //always get the event collection to do pile-up reweighting
75    objectsToGet.push_back("events");
76  
77 +
78 +  // Parse the tree variable definitions.
79 +  for (uint iBranchSet = 0; !useEDMFormat_ && iBranchSet<treeBranchSets_.size(); iBranchSet++) {
80 +    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
81 +    if(tempInputCollection.find("pairs")!=string::npos) { clog << "Warning:  tree filling is not configured for pairs of objects, so will not work for collection: " << tempInputCollection << endl; }
82 +    objectsToGet.push_back(tempInputCollection);
83 +    objectsToFlag.push_back(tempInputCollection);
84 +
85 +    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
86 +
87 +    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
88 +      BranchSpecs br;
89 +      br.inputCollection = tempInputCollection;
90 +      br.inputVariable = branchList.at(iBranch);
91 +      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);
92 +      br.name = string(newName.Data());
93 +      treeBranches_.push_back(br);
94 +    }
95 +
96 +  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++)
97 +
98 +
99    //parse the histogram definitions
100    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
101  
102      string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
103      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
104 <    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
105 <      objectsToGet.push_back(tempInputCollection);
104 >    if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
105 >    if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
106 >    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
107 >    if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
108 >    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
109 >    if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
110 >    if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
111 >    if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
112 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
113 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
114 >    if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
115 >    if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
116 >    if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
117 >    if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
118 >    if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
119 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
120 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
121 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
122 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
123 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
124 >        int spaceIndex = tempInputCollection.find(" ");
125 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
126 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
127 >      }
128 >      else{
129 >        objectsToGet.push_back(tempInputCollection);
130 >      }
131        objectsToPlot.push_back(tempInputCollection);
132 <      objectsToCut.push_back(tempInputCollection);
133 <    }
134 <    else{//pair of objects, need to add them both to the things to objectsToGet
135 <      int dashIndex = tempInputCollection.find("-");
136 <      int spaceIndex = tempInputCollection.find(" ");
137 <      int secondWordLength = spaceIndex - dashIndex;
138 <      objectsToGet.push_back(tempInputCollection);
139 <      objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
140 <      objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
132 >      objectsToFlag.push_back(tempInputCollection);
133 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
134 >      string obj1;
135 >      string obj2;
136 >      getTwoObjs(tempInputCollection, obj1, obj2);
137 >      string obj2ToGet = getObjToGet(obj2);
138 >      objectsToFlag.push_back(tempInputCollection);
139 >      objectsToFlag.push_back(obj1);
140 >      objectsToFlag.push_back(obj2);
141        objectsToPlot.push_back(tempInputCollection);
142 <      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
143 <      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
144 <      objectsToCut.push_back(tempInputCollection);
145 <      objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
146 <      objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
142 >      objectsToPlot.push_back(obj1);
143 >      objectsToPlot.push_back(obj2);
144 >      objectsToGet.push_back(tempInputCollection);
145 >      objectsToGet.push_back(obj1);
146 >      objectsToGet.push_back(obj2ToGet);
147 >    } // end else
148 >      if (find(objectsToPlot.begin(), objectsToPlot.end(), "events") != objectsToPlot.end())
149 >        objectsToGet.push_back("jets");
150  
86      }
151  
152      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
153  
154      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
155  
156 +      vector<double> defaultValue;
157 +      defaultValue.push_back (-1.0);
158 +
159        histogram tempHistogram;
160        tempHistogram.inputCollection = tempInputCollection;
161        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
162        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
163 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
163 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
164 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
165 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
166        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
167  
168        histograms.push_back(tempHistogram);
169  
170      }
171 <  }
171 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
172 >
173    //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
174    sort( objectsToPlot.begin(), objectsToPlot.end() );
175    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
# Line 110 | Line 180 | muonSFFile_ (cfg.getParameter<std::strin
180    for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
181  
182      string currentObject = objectsToPlot.at(currentObjectIndex);
183 <    if(currentObject != "muons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
183 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "secondary photons"&& currentObject != "superclusters") continue;
184  
185      histogram tempIdHisto;
186      histogram tempMomIdHisto;
187      histogram tempGmaIdHisto;
188      histogram tempIdVsMomIdHisto;
189 +    histogram tempIdVsGmaIdHisto;
190  
191      tempIdHisto.inputCollection = currentObject;
192      tempMomIdHisto.inputCollection = currentObject;
193      tempGmaIdHisto.inputCollection = currentObject;
194      tempIdVsMomIdHisto.inputCollection = currentObject;
195 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
196 +
197 +    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
198 +    if(currentObject == "secondary photons") currentObject = "secondaryPhotons";
199 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
200  
201      currentObject = currentObject.substr(0, currentObject.size()-1);
202      tempIdHisto.name = currentObject+"GenMatchId";
203      tempMomIdHisto.name = currentObject+"GenMatchMotherId";
204      tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
205      tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
206 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
207  
208      currentObject.at(0) = toupper(currentObject.at(0));
209      tempIdHisto.title = currentObject+" Gen-matched Particle";
210      tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
211      tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
212      tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
213 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
214  
215 <    int maxNum = 24;
215 >
216 >    int maxNum = 25;
217      vector<double> binVector;
218      binVector.push_back(maxNum);
219      binVector.push_back(0);
# Line 152 | Line 231 | muonSFFile_ (cfg.getParameter<std::strin
231      tempIdVsMomIdHisto.bins = binVector;
232      tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
233      tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
234 +    tempIdVsGmaIdHisto.bins = binVector;
235 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
236 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
237  
238      histograms.push_back(tempIdHisto);
239      histograms.push_back(tempMomIdHisto);
240      histograms.push_back(tempGmaIdHisto);
241      histograms.push_back(tempIdVsMomIdHisto);
242 +    histograms.push_back(tempIdVsGmaIdHisto);
243    }
244  
245  
# Line 172 | Line 255 | muonSFFile_ (cfg.getParameter<std::strin
255      //set triggers for this channel
256      vector<string> triggerNames;
257      triggerNames.clear();
258 +    vector<string> triggerToVetoNames;
259 +    triggerToVetoNames.clear();
260 +
261      tempChannel.triggers.clear();
262 +    tempChannel.triggersToVeto.clear();
263      if(channels_.at(currentChannel).exists("triggers")){
264        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
265        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
266          tempChannel.triggers.push_back(triggerNames.at(trigger));
267        objectsToGet.push_back("triggers");
268      }
269 <
269 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
270 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
271 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
272 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
273 >      objectsToGet.push_back("triggers");
274 >    }
275  
276  
277  
278      //create cutFlow for this channel
279      cutFlows_.push_back (new CutFlow (fs_, channelName));
280 <
281 <    //book a directory in the output file with the name of the channel
282 <    TFileDirectory subDir = fs_->mkdir( channelName );
191 <    directories.push_back(subDir);
192 <
193 <    std::map<std::string, TH1D*> oneDhistoMap;
194 <    oneDHists_.push_back(oneDhistoMap);
195 <    std::map<std::string, TH2D*> twoDhistoMap;
196 <    twoDHists_.push_back(twoDhistoMap);
197 <
198 <
199 <
200 <    //book all histograms included in the configuration
201 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
202 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
203 <      int numBinsElements = currentHistogram.bins.size();
204 <      int numInputVariables = currentHistogram.inputVariables.size();
205 <
206 <      if(numBinsElements != 3 && numBinsElements !=6) {
207 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
208 <        exit(0);
209 <      }
210 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
211 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
212 <        exit(0);
213 <      }
214 <      else if(numBinsElements == 3){
215 <        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));
216 <      }
217 <      else if(numBinsElements == 6){
218 <        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));
219 <
220 <      }
221 <
222 <
223 <      if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
224 <
225 < // bin      particle type
226 < // ---      -------------
227 < //  0        unmatched
228 < //  1        u
229 < //  2        d
230 < //  3        s
231 < //  4        c
232 < //  5        b
233 < //  6        t
234 < //  7        e
235 < //  8        mu
236 < //  9        tau
237 < // 10        nu
238 < // 11        g
239 < // 12        gamma
240 < // 13        Z
241 < // 14        W
242 < // 15        light meson
243 < // 16        K meson
244 < // 17        D meson
245 < // 18        B meson
246 < // 19        light baryon
247 < // 20        strange baryon
248 < // 21        charm baryon
249 < // 22        bottom baryon
250 < // 23        other
251 <
252 <      vector<TString> labelArray;
253 <      labelArray.push_back("unmatched");
254 <      labelArray.push_back("u");
255 <      labelArray.push_back("d");
256 <      labelArray.push_back("s");
257 <      labelArray.push_back("c");
258 <      labelArray.push_back("b");
259 <      labelArray.push_back("t");
260 <      labelArray.push_back("e");
261 <      labelArray.push_back("#mu");
262 <      labelArray.push_back("#tau");
263 <      labelArray.push_back("#nu");
264 <      labelArray.push_back("g");
265 <      labelArray.push_back("#gamma");
266 <      labelArray.push_back("Z");
267 <      labelArray.push_back("W");
268 <      labelArray.push_back("light meson");
269 <      labelArray.push_back("K meson");
270 <      labelArray.push_back("D meson");
271 <      labelArray.push_back("B meson");
272 <      labelArray.push_back("light baryon");
273 <      labelArray.push_back("strange baryon");
274 <      labelArray.push_back("charm baryon");
275 <      labelArray.push_back("bottom baryon");
276 <      labelArray.push_back("other");
277 <
278 <      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
279 <        if(currentHistogram.name.find("GenMatchIdVsMotherId")==std::string::npos) {
280 <          oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
281 <        }
282 <        else {
283 <          twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
284 <          twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
285 <        }
286 <      }
287 <      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=std::string::npos) {
288 <        twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->CenterTitle();
289 <        twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->CenterTitle();
290 <      }
291 <
292 <    }
293 <
294 <    //book a histogram for the number of each object type to be plotted
295 <
296 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
297 <      string currentObject = objectsToPlot.at(currentObjectIndex);
298 <      int maxNum = 10;
299 <      if(currentObject == "mcparticles") maxNum = 50;
300 <      else if(currentObject == "primaryvertexs") maxNum = 50;
301 <      else if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
302 <      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
303 <      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
304 <
305 <      else if(currentObject == "electron-track pairs") currentObject = "electronTrackPairs";
306 <      else if(currentObject == "muon-track pairs") currentObject = "muonTrackPairs";
307 <      else if(currentObject == "muon-tau pairs") currentObject = "muonTauPairs";
308 <      else if(currentObject == "tau-tau pairs") currentObject = "ditauPairs";
309 <
310 <      currentObject.at(0) = toupper(currentObject.at(0));
311 <      string histoName = "num" + currentObject;
312 <
313 <      if(histoName == "numPrimaryvertexs"){
314 <        string newHistoName = histoName + "BeforePileupCorrection";
315 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
316 <        newHistoName = histoName + "AfterPileupCorrection";
317 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
318 <      }
319 <      else
320 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
321 <    }
322 <
323 <
324 <
325 <
280 >    vector<TFileDirectory> directories; //vector of directories in the output file.
281 >    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
282 >    vector<string> subSubDirNames;//subdirectories in each channel.
283      //get list of cuts for this channel
284      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
285  
286 +
287      //loop over and parse all cuts
288      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
289        cut tempCut;
290        //store input collection for cut
291        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
292 +      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
293 +      if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
294 +      if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
295 +      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
296 +      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
297 +      if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
298 +      if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
299 +      if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
300 +      if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
301 +      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
302 +      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
303 +      if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
304 +      if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
305 +      if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
306 +      if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
307 +      if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
308 +      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
309 +      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
310 +      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
311        tempCut.inputCollection = tempInputCollection;
312 <      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
313 <        objectsToGet.push_back(tempInputCollection);
312 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
313 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
314 >          int spaceIndex = tempInputCollection.find(" ");
315 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
316 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
317 >        }
318 >        else{
319 >          objectsToGet.push_back(tempInputCollection);
320 >        }
321          objectsToCut.push_back(tempInputCollection);
322 +        objectsToFlag.push_back(tempInputCollection);
323        }
324 <      else{//pair of objects, need to add them both to the things to objectsToGet
325 <        int dashIndex = tempInputCollection.find("-");
326 <        int spaceIndex = tempInputCollection.find(" ");
327 <        int secondWordLength = spaceIndex - dashIndex;
328 <        objectsToGet.push_back(tempInputCollection);
344 <        objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
345 <        objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
324 >      else{//pair of objects, need to add them both to objectsToGet
325 >        string obj1;
326 >        string obj2;
327 >        getTwoObjs(tempInputCollection, obj1, obj2);
328 >        string obj2ToGet = getObjToGet(obj2);
329          objectsToCut.push_back(tempInputCollection);
330 <        objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
331 <        objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
330 >        objectsToCut.push_back(obj1);
331 >        objectsToCut.push_back(obj2);
332 >        objectsToFlag.push_back(tempInputCollection);
333 >        objectsToFlag.push_back(obj1);
334 >        objectsToFlag.push_back(obj2);
335 >        objectsToGet.push_back(tempInputCollection);
336 >        objectsToGet.push_back(obj1);
337 >        objectsToGet.push_back(obj2ToGet);
338  
339        }
340  
# Line 353 | Line 342 | muonSFFile_ (cfg.getParameter<std::strin
342  
343        //split cut string into parts and store them
344        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
345 <      std::vector<string> cutStringVector = splitString(cutString);
345 >      vector<string> cutStringVector = splitString(cutString);
346        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
347 <        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
347 >        clog << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
348          exit(0);
349        }
350        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
351        for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
352          int indexOffset = 4 * subcutIndex;
353          string currentVariableString = cutStringVector.at(indexOffset);
354 <        if(currentVariableString.find("(")==std::string::npos){
354 >        if(currentVariableString.find("(")==string::npos){
355            tempCut.functions.push_back("");//no function was specified
356            tempCut.variables.push_back(currentVariableString);// variable to cut on
357          }
# Line 373 | Line 362 | muonSFFile_ (cfg.getParameter<std::strin
362          }
363          tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
364          tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
365 +        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
366          if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
367        }
368  
369        //get number of objects required to pass cut for event to pass
370        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
371 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
371 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
372        if(numberRequiredVector.size()!=2){
373 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
373 >        clog << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
374          exit(0);
375        }
376  
# Line 388 | Line 378 | muonSFFile_ (cfg.getParameter<std::strin
378        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
379        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
380  
381 <
381 >      //Set up vectors to store the directories and subDirectories for each channel.
382 >      string subSubDirName;
383        string tempCutName;
384        if(cuts_.at(currentCut).exists("alias")){
385          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
386 +        subSubDirName = "After " + tempCutName + " Cut Applied";
387        }
388        else{
389          //construct string for cutflow table
# Line 399 | Line 391 | muonSFFile_ (cfg.getParameter<std::strin
391          string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
392          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
393          tempCutName = cutName;
394 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
395        }
403      tempCut.name = tempCutName;
396  
397 +      tempCut.isVeto = false;
398 +      if(cuts_.at(currentCut).exists("isVeto")){
399 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
400 +        if (isVeto == true) tempCut.isVeto = true;
401 +      }
402 +      subSubDirNames.push_back(subSubDirName);
403 +      tempCut.name = tempCutName;
404  
405        tempChannel.cuts.push_back(tempCut);
406  
407  
409
408      }//end loop over cuts
409  
410 +    vector<map<string, TH1D*>> oneDHistsTmp;
411 +    vector<map<string, TH2D*>> twoDHistsTmp;
412 +    //book a directory in the output file with the name of the channel
413 +    TFileDirectory subDir = fs_->mkdir( channelName );
414 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
415 +    if(GetPlotsAfterEachCut_){
416 +      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
417 +        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
418 +        directories.push_back(subSubDir);
419 +        map<string, TH1D*> oneDhistoMap;
420 +        oneDHistsTmp.push_back(oneDhistoMap);
421 +        map<string, TH2D*> twoDhistoMap;
422 +        twoDHistsTmp.push_back(twoDhistoMap);
423 +      }
424 +      treeDirectories.push_back(subDir);
425 +      oneDHists_.push_back(oneDHistsTmp);
426 +      twoDHists_.push_back(twoDHistsTmp);
427 +    }
428 +    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
429 +    else{
430 +      map<string, TH1D*> oneDhistoMap;
431 +      oneDHistsTmp.push_back(oneDhistoMap);
432 +      map<string, TH2D*> twoDhistoMap;
433 +      twoDHistsTmp.push_back(twoDhistoMap);
434 +      oneDHists_.push_back(oneDHistsTmp);
435 +      twoDHists_.push_back(twoDHistsTmp);
436 +      directories.push_back(subDir);
437 +      treeDirectories.push_back(subDir);
438 +
439 +    }
440 +
441 +    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
442 +      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
443 +      BNTrees_.push_back(newTree);
444 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
445 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
446 +        vector<float> newVec;
447 +        BNTreeBranchVals_[currentVar.name] = newVec;
448 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
449 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
450 +    }
451 +
452 +    //book all histograms included in the configuration
453 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
454 +
455 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
456 +
457 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
458 +        int numBinsElements = currentHistogram.bins.size();
459 +        int numInputVariables = currentHistogram.inputVariables.size();
460 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
461 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
462 +
463 +        if(numBinsElements == 1){
464 +          if(numBinEdgesX > 1){
465 +            if(numBinEdgesY > 1)
466 +              numBinsElements = 6;
467 +            else
468 +              numBinsElements = 3;
469 +          }
470 +        }
471 +        if(numBinsElements != 3 && numBinsElements !=6){
472 +          clog << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
473 +          exit(0);
474 +        }
475 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
476 +          clog << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
477 +          exit(0);
478 +        }
479 +        else if(numBinsElements == 3){
480 +          if (currentHistogram.bins.size () == 3)
481 +            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));
482 +          else
483 +            {
484 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
485 +            }
486 +        }
487 +        else if(numBinsElements == 6){
488 +          if (currentHistogram.bins.size () == 6)
489 +            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));
490 +          else
491 +            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 ());
492 +        }
493 +
494 +
495 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
496 +
497 +        // bin      particle type
498 +        // ---      -------------
499 +        //  0        unmatched
500 +        //  1        u
501 +        //  2        d
502 +        //  3        s
503 +        //  4        c
504 +        //  5        b
505 +        //  6        t
506 +        //  7        e
507 +        //  8        mu
508 +        //  9        tau
509 +        // 10        nu
510 +        // 11        g
511 +        // 12        gamma
512 +        // 13        Z
513 +        // 14        W
514 +        // 15        light meson
515 +        // 16        K meson
516 +        // 17        D meson
517 +        // 18        B meson
518 +        // 19        light baryon
519 +        // 20        strange baryon
520 +        // 21        charm baryon
521 +        // 22        bottom baryon
522 +        // 23        QCD string
523 +        // 24        other
524 +
525 +        vector<TString> labelArray;
526 +        labelArray.push_back("unmatched");
527 +        labelArray.push_back("u");
528 +        labelArray.push_back("d");
529 +        labelArray.push_back("s");
530 +        labelArray.push_back("c");
531 +        labelArray.push_back("b");
532 +        labelArray.push_back("t");
533 +        labelArray.push_back("e");
534 +        labelArray.push_back("#mu");
535 +        labelArray.push_back("#tau");
536 +        labelArray.push_back("#nu");
537 +        labelArray.push_back("g");
538 +        labelArray.push_back("#gamma");
539 +        labelArray.push_back("Z");
540 +        labelArray.push_back("W");
541 +        labelArray.push_back("light meson");
542 +        labelArray.push_back("K meson");
543 +        labelArray.push_back("D meson");
544 +        labelArray.push_back("B meson");
545 +        labelArray.push_back("light baryon");
546 +        labelArray.push_back("strange baryon");
547 +        labelArray.push_back("charm baryon");
548 +        labelArray.push_back("bottom baryon");
549 +        labelArray.push_back("QCD string");
550 +        labelArray.push_back("other");
551 +
552 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
553 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
554 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
555 +          }
556 +          else {
557 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
558 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
559 +          }
560 +        }
561 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
562 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
563 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
564 +        }
565 +
566 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
567 +
568 +
569 +      // Book a histogram for the number of each object type to be plotted.
570 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
571 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
572 +        string currentObject = objectsToPlot.at(currentObjectIndex);
573 +        int maxNum = 10;
574 +        if(currentObject == "mcparticles") maxNum = 50;
575 +        else if(currentObject == "primaryvertexs") maxNum = 50;
576 +
577 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
578 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
579 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
580 +        else if(currentObject == "electron-photon pairs")     currentObject = "electronPhotonPairs";
581 +        else if(currentObject == "muon-photon pairs")         currentObject = "muonPhotonPairs";
582 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
583 +        else if(currentObject == "secondary photons")            currentObject = "secondaryPhotons";
584 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
585 +        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
586 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
587 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
588 +        else if(currentObject == "muon-event pairs")            currentObject = "muonEventPairs";
589 +        else if(currentObject == "photon-jet pairs")            currentObject = "photonJetPairs";
590 +        else if(currentObject == "met-jet pairs")             currentObject = "metJetPairs";
591 +        else if(currentObject == "track-jet pairs")           currentObject = "trackJetPairs";
592 +        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
593 +        else if(currentObject == "muon-secondary photon pairs")  currentObject = "muonSecondaryPhotonPairs";
594 +        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
595 +        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
596 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
597 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
598 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
599 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
600 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
601 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
602 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
603 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
604 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
605 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
606 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
607 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
608 +
609 +        currentObject.at(0) = toupper(currentObject.at(0));
610 +        string histoName = "num" + currentObject;
611 +
612 +        if(histoName == "numPrimaryvertexs"){
613 +          string newHistoName = histoName + "BeforePileupCorrection";
614 +          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);
615 +          newHistoName = histoName + "AfterPileupCorrection";
616 +          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);
617 +        }
618 +        else
619 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
620 +      }
621 +    }//end of loop over directories
622      channels.push_back(tempChannel);
623      tempChannel.cuts.clear();
414
624    }//end loop over channels
625  
626  
# Line 421 | Line 630 | muonSFFile_ (cfg.getParameter<std::strin
630    //make unique vector of objects we need to cut on
631    sort( objectsToCut.begin(), objectsToCut.end() );
632    objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
633 +  //make unique vector of objects we need to set flags for
634 +  sort( objectsToFlag.begin(), objectsToFlag.end() );
635 +  objectsToFlag.erase( unique( objectsToFlag.begin(), objectsToFlag.end() ), objectsToFlag.end() );
636  
637 +  produces<map<string, bool> > ("channelDecisions");
638 +
639 + } // end constructor OSUAnalysis::OSUAnalysis()
640  
426 }
641  
642   OSUAnalysis::~OSUAnalysis ()
643   {
644 +
645    // Destroying the CutFlow objects causes the cut flow numbers and time
646    // information to be printed to standard output.
647    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
648      delete cutFlows_.at(currentChannel);
649    }
650 +
651 +  clog << "=============================================" << endl;  
652 +  clog << "Successfully completed OSUAnalysis." << endl;  
653 +  clog << "=============================================" << endl;  
654 +
655   }
656  
657   void
658 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
658 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
659   {
440
660    // Retrieve necessary collections from the event.
661  
662 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
662 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
663      event.getByLabel (triggers_, triggers);
664  
665 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
665 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
666 >    event.getByLabel (trigobjs_, trigobjs);
667 >
668 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
669      event.getByLabel (jets_, jets);
670  
671 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
671 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
672      event.getByLabel (muons_, muons);
673  
674 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
674 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
675      event.getByLabel (electrons_, electrons);
676  
677 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
677 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
678      event.getByLabel (events_, events);
679  
680 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
680 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
681      event.getByLabel (taus_, taus);
682  
683 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
683 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
684      event.getByLabel (mets_, mets);
685  
686 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
686 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
687      event.getByLabel (tracks_, tracks);
688  
689 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
689 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
690      event.getByLabel (genjets_, genjets);
691  
692 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
692 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
693      event.getByLabel (mcparticles_, mcparticles);
694  
695 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
695 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
696      event.getByLabel (primaryvertexs_, primaryvertexs);
697  
698 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
698 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
699      event.getByLabel (bxlumis_, bxlumis);
700  
701 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
701 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
702      event.getByLabel (photons_, photons);
703  
704 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
704 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
705      event.getByLabel (superclusters_, superclusters);
706  
707 +  if (datasetType_ == "signalMC"){
708 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
709 +      event.getByLabel (stops_, stops);
710 +  }
711 +
712 +  if (useTrackCaloRhoCorr_) {
713 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
714 +    // This rho collection is not available in all BEANs.
715 +    // For description of rho values for different jet reconstruction algorithms, see
716 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
717 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
718 +  }
719 +
720 +  double masterScaleFactor = 1.0;
721 +
722    //get pile-up event weight
723 <  double scaleFactor = 1.00;
724 <  if(doPileupReweighting_ && datasetType_ != "data")
725 <    scaleFactor = puWeight_->at (events->at (0).numTruePV);
723 >  if (doPileupReweighting_ && datasetType_ != "data") {
724 >    //for "data" datasets, the numTruePV is always set to -1
725 >    if (events->at(0).numTruePV < 0) clog << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
726 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
727 >  }
728  
729 +  stopCTauScaleFactor_ = 1.0;
730 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
731 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
732 +  masterScaleFactor *= stopCTauScaleFactor_;
733  
734    //loop over all channels
735  
736 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
737    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
738      channel currentChannel = channels.at(currentChannelIndex);
739  
# Line 497 | Line 741 | OSUAnalysis::analyze (const edm::Event &
741      counterMap passingCounter;
742      cumulativeFlags.clear ();
743  
744 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
745 +         iter != BNTreeBranchVals_.end(); iter++) {
746 +      iter->second.clear();  // clear array
747 +    }
748 +
749      bool triggerDecision = true;
750 <    if(currentChannel.triggers.size() != 0){  //triggers specified
751 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
750 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
751 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
752        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
753      }
754  
755      //loop over all cuts
507
508
509
756      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
757        cut currentCut = currentChannel.cuts.at(currentCutIndex);
758  
759 <      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
760 <        string currentObject = objectsToCut.at(currentObjectIndex);
759 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
760 >        string currentObject = objectsToFlag.at(currentObjectIndex);
761  
762          //initialize maps to get ready to set cuts
763 <        individualFlags[currentObject].push_back (vector<bool> ());
764 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
763 >        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
764 >        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
765  
766        }
767 <      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
768 <        string currentObject = objectsToCut.at(currentObjectIndex);
767 >
768 >      //set flags for all relevant objects
769 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
770 >        string currentObject = objectsToFlag.at(currentObjectIndex);
771  
772          int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
773  
774  
775 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
776 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
775 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
776 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
777 >        else if(currentObject == "secondary photons")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"secondary photons");
778 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
779 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
780 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
781          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
782          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
783          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 537 | Line 789 | OSUAnalysis::analyze (const edm::Event &
789          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
790          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
791          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
792 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
793 +
794  
795  
796          else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
797                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
798                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
799                                                                     "muon-muon pairs");
800 +
801 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
802 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
803 +                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
804 +                                                                             "muon-secondary muon pairs");
805 +
806 +        else if(currentObject == "muon-secondary photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
807 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
808 +                                                                             cumulativeFlags.at("secondary photons").at(flagsForPairCutsIndex), \
809 +                                                                             "muon-secondary photon pairs");
810 +        else if(currentObject == "muon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
811 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
812 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
813 +                                                                             "muon-secondary jet pairs");
814 +        else if(currentObject == "photon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
815 +                                                                             cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
816 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
817 +                                                                             "photon-secondary jet pairs");
818 +
819 +        else if(currentObject == "electron-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
820 +                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
821 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
822 +                                                                             "electron-secondary jet pairs");
823 +
824 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
825 +                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
826 +                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
827 +                                                                                     "electron-secondary electron pairs");
828 +
829          else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
830                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
831                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
# Line 551 | Line 834 | OSUAnalysis::analyze (const edm::Event &
834                                                                         cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
835                                                                         cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
836                                                                         "electron-muon pairs");
837 <        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(), \
838 <                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
839 <                                                                       cumulativeFlags.at("tracks").at(flagsForPairCutsIndex), \
840 <                                                                       "electron-track pairs");
841 <        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(), \
842 <                                                                        cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
843 <                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex), \
844 <                                                                        "muon-track pairs");
845 <        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(), \
846 <                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
847 <                                                                    cumulativeFlags.at("taus").at(flagsForPairCutsIndex), \
848 <                                                                    "muon-tau pairs");
849 <
850 <        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),taus.product(), \
851 <                                                                        cumulativeFlags.at("taus").at(flagsForPairCutsIndex), \
852 <                                                                        cumulativeFlags.at("taus").at(flagsForPairCutsIndex), \
853 <                                                                        "tau-tau pairs");
854 <
837 >        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
838 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
839 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
840 >                                                                 "jet-jet pairs");
841 >        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
842 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
843 >                                                                 cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex),\
844 >                                                                 "jet-secondary jet pairs");
845 >        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
846 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
847 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
848 >                                                                      "electron-jet pairs");
849 >        else if(currentObject == "electron-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), \
850 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
851 >                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
852 >                                                                      "electron-photon pairs");
853 >        else if(currentObject == "photon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
854 >                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
855 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
856 >                                                                      "photon-jet pairs");
857 >        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
858 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
859 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
860 >                                                                  "muon-jet pairs");
861 >        else if(currentObject == "muon-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),events.product(), \
862 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
863 >                                                                  cumulativeFlags.at("events").at(flagsForPairCutsIndex), \
864 >                                                                  "muon-event pairs");
865 >        else if(currentObject == "met-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),jets.product(), \
866 >                                                                  cumulativeFlags.at("mets").at(flagsForPairCutsIndex), \
867 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
868 >                                                                  "met-jet pairs");
869 >        else if(currentObject == "track-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),jets.product(), \
870 >                                                                 cumulativeFlags.at("tracks").at(flagsForPairCutsIndex), \
871 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
872 >                                                                 "track-jet pairs");
873 >        else if(currentObject == "muon-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
874 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
875 >                                                                  cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
876 >                                                                  "muon-photon pairs");
877 >        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
878 >                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
879 >                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
880 >                                                                     "track-event pairs");
881 >        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
882 >                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
883 >                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
884 >                                                                        "electron-track pairs");
885 >        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
886 >                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
887 >                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
888 >                                                                    "muon-track pairs");
889 >        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
890 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
891 >                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
892 >                                                                  "muon-tau pairs");
893 >        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
894 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
895 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
896 >                                                                 "tau-tau pairs");
897 >        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
898 >                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
899 >                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
900 >                                                                   "tau-track pairs");
901 >        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
902 >                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
903 >                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
904 >                                                                          "electron-trigobj pairs");
905 >        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
906 >                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
907 >                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
908 >                                                                      "muon-trigobj pairs");
909  
910 +        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
911        }
912  
913  
914  
915      }//end loop over all cuts
578
579
916      //use cumulative flags to apply cuts at event level
917  
918 +    //a vector to store cumulative cut descisions after each cut.
919 +    vector<bool> eventPassedPreviousCuts;
920      bool eventPassedAllCuts = true;
583
921      //apply trigger (true if none were specified)
922      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
923  
587
588
924      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
925  
926        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 593 | Line 928 | OSUAnalysis::analyze (const edm::Event &
928        int numberPassing = 0;
929  
930        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
931 <          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
931 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
932        }
598
933        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
934        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
601
935        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
936 <
936 >      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
937      }
938 <
938 >    //applying all appropriate scale factors
939 >    double scaleFactor = masterScaleFactor;
940 >    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
941 >
942 >    if(applyLeptonSF_ && datasetType_ != "data"){
943 >      //only apply SFs if we've cut on this object
944 >      if(find(objectsToCut.begin(),objectsToCut.end(),"muons") != objectsToCut.end ()){
945 >        flagPair muonFlags;
946 >        //get the last valid flags in the flag map
947 >        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
948 >          if (cumulativeFlags.at("muons").at(i).size()){
949 >            muonFlags = cumulativeFlags.at("muons").at(i);
950 >            break;
951 >          }
952 >        }
953 >        //apply the weight for each of those objects
954 >        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
955 >          if(!muonFlags.at(muonIndex).second) continue;
956 >          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
957 >        }
958 >      }
959 >      //only apply SFs if we've cut on this object
960 >      if(find(objectsToCut.begin(),objectsToCut.end(),"electrons") != objectsToCut.end ()){
961 >        flagPair electronFlags;
962 >        //get the last valid flags in the flag map
963 >        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
964 >          if (cumulativeFlags.at("electrons").at(i).size()){
965 >            electronFlags = cumulativeFlags.at("electrons").at(i);
966 >            break;
967 >          }
968 >        }
969 >        //apply the weight for each of those objects
970 >        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
971 >          if(!electronFlags.at(electronIndex).second) continue;
972 >          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
973 >        }
974 >      }
975 >    }
976 >    if(applyBtagSF_ && datasetType_ != "data"){
977 >      //only apply SFs if we've cut on this object
978 >      if(find(objectsToCut.begin(),objectsToCut.end(),"jets") != objectsToCut.end ()){
979 >        flagPair jetFlags;
980 >        vector<double> jetSFs;
981 >        //get the last valid flags in the flag map
982 >        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
983 >          if (cumulativeFlags.at("jets").at(i).size()){
984 >            jetFlags = cumulativeFlags.at("jets").at(i);
985 >            break;
986 >          }
987 >        }
988 >        //apply the weight for each of those objects
989 >        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
990 >          if(!jetFlags.at(jetIndex).second) continue;
991 >          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour, jets->at(jetIndex).eta);
992 >          jetSFs.push_back(jetSFTmp);
993 >        }
994 >        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_);
995 >      }
996 >    }
997 >    scaleFactor *= muonScaleFactor_;
998 >    scaleFactor *= electronScaleFactor_;
999 >    scaleFactor *= bTagScaleFactor_;
1000      cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
1001  
1002 +    if (printEventInfo_) {
1003 +      // Write information about event to screen, for testing purposes.
1004 +      clog << "Event passed all cuts in channel " <<  currentChannel.name
1005 +           << ": run="  << events->at(0).run
1006 +           << "  lumi=" << events->at(0).lumi
1007 +           << "  event=" << events->at(0).evt
1008 +           << endl;
1009 +    }
1010 +
1011  
1012 +    //filling histograms
1013 +    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
1014 +      uint currentDir;
1015 +      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
1016 +      else{
1017 +        currentDir = currentCut;
1018 +      }
1019  
610    if(!eventPassedAllCuts)continue;
1020  
1021 <    if (printEventInfo_) {
613 <      // Write information about event to screen, for testing purposes.  
614 <      cout << "Event passed all cuts in channel " <<  currentChannel.name
615 <           << ": run="  << events->at(0).run
616 <           << "  lumi=" << events->at(0).lumi
617 <           << "  event=" << events->at(0).evt
618 <           << endl;  
619 <    }
1021 >      if(eventPassedPreviousCuts.at(currentDir)){
1022  
1023 +        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1024 +          histogram currentHistogram = histograms.at(histogramIndex);
1025  
1026 < //     if(datasetType_ != "data") {
623 < //       scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
624 < //       scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
625 < //     }
1026 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) clog << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
1027  
1028 <    //filling histograms
1029 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1030 <      histogram currentHistogram = histograms.at(histogramIndex);
1028 >          if(currentHistogram.inputVariables.size() == 1){
1029 >            TH1D* histo;
1030 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1031 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1032 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1033 >            else if(currentHistogram.inputCollection == "secondary photons")  fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1034 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1035 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1036 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1037 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1038 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1039 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1040 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1041 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1042 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1043 >             else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1044 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary photons").at(currentDir), \
1045 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1046 >             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1047 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1048 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1049 >             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1050 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1051 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1052 >             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1053 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1054 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1055 >
1056 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1057 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
1058 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
1059 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1060 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
1061 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
1062 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1063 >             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1064 >                                                                                                     cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1065 >                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1066 >
1067 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1068 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1069 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1070 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
1071 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
1072 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1073 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
1074 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1075 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1076 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(), \
1077 >                                                                                              cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1078 >                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1079 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
1080 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1081 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1082 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill1DHistogram(histo,currentHistogram, muons.product(),events.product(), \
1083 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1084 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1085 >            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, mets.product(),jets.product(), \
1086 >                                                                                          cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1087 >                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1088 >            else if(currentHistogram.inputCollection == "track-jet pairs")  fill1DHistogram(histo,currentHistogram,tracks.product(),jets.product(), \
1089 >                                                                                          cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1090 >                                                                                          cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1091 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(), \
1092 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1093 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1094 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(), \
1095 >                                                                                          cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1096 >                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1097 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1098 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1099 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1100 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1101 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1102 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1103 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1104 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1105 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1106 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1107 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1108 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1109 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1110 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1111 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1112 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1113 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1114 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1115 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1116 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1117 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1118 >
1119 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1120 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1121 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1122 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1123 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1124 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1125 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1126 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1127 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1128 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1129 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1130 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1131 >          }
1132 >          else if(currentHistogram.inputVariables.size() == 2){
1133 >            TH2D* histo;
1134 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1135 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1136 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1137 >            else if(currentHistogram.inputCollection == "secondary photons")  fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1138 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1139 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1140 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1141 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1142 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1143 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1144 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1145 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1146 >            else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1147 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary photons").at(currentDir), \
1148 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1149 >            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1150 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1151 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1152 >            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1153 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1154 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1155 >            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1156 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1157 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1158 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1159 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1160 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1161 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1162 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1163 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1164 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1165 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1166 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1167 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1168 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1169 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1170 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1171 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1172 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1173 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1174 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1175 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(), \
1176 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1177 >                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1178 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1179 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1180 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1181 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill2DHistogram(histo,currentHistogram,muons.product(),events.product(), \
1182 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("events").at(currentDir), \
1183 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1184 >            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,mets.product(),jets.product(), \
1185 >                                                                                         cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1186 >                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1187 >            else if(currentHistogram.inputCollection == "track-jet pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1188 >                                                                                         cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1189 >                                                                                         cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1190 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1191 >                                                                                          cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1192 >                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1193 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1194 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1195 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1196 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1197 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1198 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1199 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1200 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1201 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1202 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1203 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1204 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1205 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1206 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1207 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1208 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1209 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1210 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1211 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1212 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1213 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1214 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1215 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1216 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1217 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1218 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1219 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1220 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1221 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1222 >                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1223 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1224 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1225 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1226 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1227 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1228 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1229 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1230 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1231 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1232 >          }
1233  
631      if(currentHistogram.inputVariables.size() == 1){
632        TH1D* histo;
633        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
634
635
636
637        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
638         else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
639        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
640                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
641                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
642        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
643        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
644                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
645                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
646        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
647                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
648                                                                                              cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
649        else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(), \
650                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),
651                                                                                           cumulativeFlags.at("electron-track pairs").back(),scaleFactor);
652        else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(), \
653                                                                                            cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),
654                                                                                            cumulativeFlags.at("muon-track pairs").back(),scaleFactor);
655        else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(), \
656                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),
657                                                                                        cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);
658
659        else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(), \
660                                                                                            cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),
661                                                                                            cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);
662        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
663        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
664        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
665        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
666        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
667        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
668        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
669        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
670        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
671        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
672      }
673      else if(currentHistogram.inputVariables.size() == 2){
674        TH2D* histo;
675        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
676
677
678
679        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
680        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
681        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
682                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
683                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
684        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
685        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
686                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
687                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
688        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
689                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
690                                                                                               cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
691        else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(), \
692                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(), \
693                                                                                           cumulativeFlags.at("electron-track pairs").back(),scaleFactor);
694        else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(), \
695                                                                                            cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(), \
696                                                                                            cumulativeFlags.at("muon-track pairs").back(),scaleFactor);
697        else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(), \
698                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(), \
699                                                                                        cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);
700        else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(), \
701                                                                                            cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(), \
702                                                                                            cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);
703        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
704        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
705        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
706        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
707        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
708        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
709        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
710        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
711        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
712        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
713      }
714    }
715
716    //fills histograms with the sizes of collections
717    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
718      string currentObject = objectsToPlot.at(currentObjectIndex);
719
720      string objectToPlot = "";
721
722      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
723      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
724      else if(currentObject == "electron-muon pairs") objectToPlot = "electronMuonPairs";
725      else if(currentObject == "electron-track pairs") objectToPlot = "electronTrackPairs";
726      else if(currentObject == "muon-track pairs") objectToPlot = "muonTrackPairs";
727      else if(currentObject == "muon-tau pairs") objectToPlot = "muonTauPairs";
728      else if(currentObject == "tau-tau pairs") objectToPlot = "ditauPairs";
729      else objectToPlot = currentObject;
730      string tempCurrentObject = objectToPlot;
731      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
732      string histoName = "num" + tempCurrentObject;
733
734
735
736
737      //set position of primary vertex in event, in order to calculate quantities relative to it
738      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
739        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
740        int numToPlot = 0;
741        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
742          if(lastCutFlags.at(currentFlag)) numToPlot++;
743        }
744        if(objectToPlot == "primaryvertexs"){
745          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
746          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1234          }
748        else
749          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
750      }
751      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
752      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
753      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
754      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
755      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
756      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
757      else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
758      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
759      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
760      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
761      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
762      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
763      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
764      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
765      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
766      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
767      else if(objectToPlot == "primaryvertexs"){
768        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
769        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
770      }
1235  
772    }
1236  
1237 +        //fills histograms with the sizes of collections
1238 +        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1239  
1240 +          string currentObject = objectsToPlot.at(currentObjectIndex);
1241 +          string objectToPlot = "";
1242  
1243 +          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1244 +          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1245 +          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1246 +          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1247 +          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1248 +          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1249 +          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1250 +          else if(currentObject == "muon-event pairs")                     objectToPlot = "muonEventPairs";
1251 +          else if(currentObject == "muon-photon pairs")                     objectToPlot = "muonPhotonPairs";
1252 +          else if(currentObject == "photon-jet pairs")                     objectToPlot = "photonJetPairs";
1253 +          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1254 +          else if(currentObject == "track-jet pairs")                    objectToPlot = "trackJetPairs";
1255 +          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1256 +          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1257 +          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1258 +          else if(currentObject == "secondary photons")                     objectToPlot = "secondaryPhotons";
1259 +          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1260 +          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1261 +          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1262 +          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1263 +          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1264 +          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1265 +          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1266 +          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1267 +          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1268 +          else if(currentObject == "muon-secondary photon pairs")           objectToPlot = "muonSecondaryJetPairs";
1269 +          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1270 +          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1271 +          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1272 +          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1273 +          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1274 +          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1275 +          else objectToPlot = currentObject;
1276 +
1277 +          string tempCurrentObject = objectToPlot;
1278 +          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1279 +          string histoName = "num" + tempCurrentObject;
1280 +
1281 +
1282 +          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1283 +            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1284 +            int numToPlot = 0;
1285 +            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1286 +              if(lastCutFlags.at(currentFlag).second) numToPlot++;
1287 +            }
1288 +
1289 +            if(objectToPlot == "primaryvertexs"){
1290 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1291 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1292 +            }
1293 +            else {
1294 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1295 +            }
1296 +          }
1297 +        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1298  
777  } //end loop over channel
1299  
1300 <  masterCutFlow_->fillCutFlow(scaleFactor);
1300 >      } // end if(eventPassedPreviousCuts.at(currentDir))
1301 >    } // end loop over cuts
1302  
1303 +    if (!useEDMFormat_ && eventPassedAllCuts){
1304 +      // Assign BNTree variables
1305 +      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1306 +        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1307 +        string coll = brSpecs.inputCollection;
1308 +        if (cumulativeFlags.count(coll) == 0) clog << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1309 +
1310 +        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1311 +        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1312 +        else if(coll == "secondary photons")      assignTreeBranch(brSpecs,photons.product(),          cumulativeFlags.at(coll).back());
1313 +        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1314 +        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1315 +        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1316 +        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1317 +        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1318 +        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1319 +        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1320 +        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1321 +        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1322 +        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1323 +        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1324 +        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1325 +        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1326 +        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1327 +        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1328 +        else if(coll == "stops"
1329 +                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1330 +      } // end loop over branches
1331  
1332 +      if (!BNTrees_.at(currentChannelIndex)) { clog << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1333 +      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1334 +    }
1335 +
1336 +    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1337 +
1338 +  } // end loop over channel
1339 +
1340 +  masterCutFlow_->fillCutFlow(masterScaleFactor);
1341 +
1342 +  event.put (channelDecisions, "channelDecisions");
1343 +
1344 + } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1345  
783 }
1346  
1347  
1348   bool
# Line 794 | Line 1356 | OSUAnalysis::evaluateComparison (double
1356    else if(comparison == "==") return testValue == cutValue;
1357    else if(comparison == "=") return testValue == cutValue;
1358    else if(comparison == "!=") return testValue != cutValue;
1359 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1359 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1360  
1361   }
1362  
1363   bool
1364 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1364 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1365 >
1366  
1367 +  if(comparison == ">")       return testValue >  cutValue;
1368 +  else if(comparison == ">=") return testValue >= cutValue;
1369 +  else if(comparison == "<")  return testValue <  cutValue;
1370 +  else if(comparison == "<=") return testValue <= cutValue;
1371 +  else if(comparison == "==") return testValue == cutValue;
1372 +  else if(comparison == "=") return testValue == cutValue;
1373 +  else if(comparison == "!=") return testValue != cutValue;
1374 +  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1375 +
1376 + }
1377 +
1378 + bool
1379 + OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1380 +
1381 +  //initialize to false until a chosen trigger is passed
1382    bool triggerDecision = false;
1383  
1384 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1385 <    {
1386 <      if(trigger->pass != 1) continue;
1387 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1388 <        {
1389 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1390 <            triggerDecision = true;
1391 <          }
1392 <        }
1384 >  if (printAllTriggers_) clog << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1385 >  //loop over all triggers defined in the event
1386 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1387 >
1388 >    if (printAllTriggers_) clog << "   " << trigger->name << endl;
1389 >
1390 >    //we're only interested in triggers that actually passed
1391 >    if(trigger->pass != 1) continue;
1392 >
1393 >    //if the event passes one of the veto triggers, exit and return false
1394 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1395 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1396 >    }
1397 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1398 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1399 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1400      }
1401 <  return triggerDecision;
1401 >  }
1402 >
1403 >  printAllTriggers_ = false;  // only print triggers once, not every event
1404  
1405 +  //if none of the veto triggers fired:
1406 +  //return the OR of all the chosen triggers
1407 +  if (triggersToTest.size() != 0) return triggerDecision;
1408 +  //or if no triggers were defined return true
1409 +  else return true;
1410   }
1411  
1412 < std::vector<std::string>
1412 >
1413 > vector<string>
1414   OSUAnalysis::splitString (string inputString){
1415  
1416 <  std::stringstream stringStream(inputString);
1417 <  std::istream_iterator<std::string> begin(stringStream);
1418 <  std::istream_iterator<std::string> end;
1419 <  std::vector<std::string> stringVector(begin, end);
1416 >  stringstream stringStream(inputString);
1417 >  istream_iterator<string> begin(stringStream);
1418 >  istream_iterator<string> end;
1419 >  vector<string> stringVector(begin, end);
1420    return stringVector;
1421  
1422   }
1423  
1424 +
1425 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1426 +  // Set two object strings from the tempInputCollection string,
1427 +  // For example, if tempInputCollection is "electron-muon pairs",
1428 +  // then obj1 = "electrons" and obj2 = "muons".
1429 +  // Note that the objects have an "s" appended.
1430 +
1431 +  int dashIndex = tempInputCollection.find("-");
1432 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1433 +  int secondWordLength = spaceIndex - dashIndex;
1434 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1435 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1436 +
1437 + }
1438 +
1439 +
1440 + string OSUAnalysis::getObjToGet(string obj) {
1441 +  // Return the string corresponding to the object to get for the given obj string.
1442 +  // Right now this only handles the case in which obj contains "secondary",
1443 +  // e.g, "secondary muons".
1444 +  // Note that "s" is NOT appended.
1445 +
1446 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1447 +  int firstSpaceIndex = obj.find_first_of(" ");
1448 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1449 +
1450 + }
1451 +
1452 +
1453 + //!jet valueLookup
1454   double
1455 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1455 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1456  
1457    double value = 0.0;
1458    if(variable == "energy") value = object->energy;
# Line 948 | Line 1571 | OSUAnalysis::valueLookup (const BNjet* o
1571    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1572    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1573  
1574 +  //user defined variable
1575 +  else if(variable == "disappTrkLeadingJetID") {
1576 +    value = object->pt > 110
1577 +      && fabs(object->eta) < 2.4
1578 +      && object->chargedHadronEnergyFraction > 0.2
1579 +      && object->neutralHadronEnergyFraction < 0.7
1580 +      && object->chargedEmEnergyFraction < 0.5
1581 +      && object->neutralEmEnergyFraction < 0.7;
1582 +  }
1583 +
1584 +  else if(variable == "disappTrkSubLeadingJetID") {
1585 +    value = object->pt > 30
1586 +      && fabs(object->eta) < 4.5
1587 +      && object->neutralHadronEnergyFraction < 0.7
1588 +      && object->chargedEmEnergyFraction < 0.5;
1589 +  }
1590 +
1591 +  else if(variable == "dPhiMet") {
1592 +    if (const BNmet *met = chosenMET ()) {
1593 +      value = deltaPhi (object->phi, met->phi);
1594 +    } else value = -999;
1595 +  }
1596 +
1597  
1598 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1598 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1599  
1600    value = applyFunction(function, value);
1601  
1602    return value;
1603 < }
958 <
1603 > } // end jet valueLookup
1604  
1605  
1606 + //!muon valueLookup
1607   double
1608 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1608 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1609  
1610    double value = 0.0;
1611    if(variable == "energy") value = object->energy;
# Line 1051 | Line 1697 | OSUAnalysis::valueLookup (const BNmuon*
1697    else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1698    else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1699    else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1700 +  else if(variable == "chargedHadronIsoDR04") value = object->chargedHadronIsoDR04;
1701 +  else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1702 +  else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1703 +  else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1704    else if(variable == "rhoPrime") value = object->rhoPrime;
1705    else if(variable == "AEffDr03") value = object->AEffDr03;
1706    else if(variable == "AEffDr04") value = object->AEffDr04;
# Line 1058 | Line 1708 | OSUAnalysis::valueLookup (const BNmuon*
1708    else if(variable == "pfIsoR03SumNeutralHadronEt") value = object->pfIsoR03SumNeutralHadronEt;
1709    else if(variable == "pfIsoR03SumPhotonEt") value = object->pfIsoR03SumPhotonEt;
1710    else if(variable == "pfIsoR03SumPUPt") value = object->pfIsoR03SumPUPt;
1711 +  else if(variable == "relpfIsoR04SumExceptChargedHad") value = (object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)/ object->pt;
1712 +  else if(variable == "relpfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt/object->pt;
1713 +  else if(variable == "relpfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt/object->pt;
1714 +  else if(variable == "relpfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt/object->pt;
1715 +  else if(variable == "relpfIsoR04SumPUPt") value = object->pfIsoR04SumPUPt/object->pt;
1716    else if(variable == "pfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt;
1717    else if(variable == "pfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt;
1718    else if(variable == "pfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt;
# Line 1114 | Line 1769 | OSUAnalysis::valueLookup (const BNmuon*
1769    else if(variable == "time_ndof") value = object->time_ndof;
1770  
1771    //user-defined variables
1772 +  else if(variable == "looseID") {
1773 +    value = object->pt > 10 &&
1774 +      (object->isGlobalMuon  > 0 ||
1775 +       object->isTrackerMuon > 0);
1776 +  }
1777    else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1778    else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1779    else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1780    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1781 +  else if(variable == "relPFdBetaIsoPseudo") value = (object->pfIsoR04SumChargedHadronPt + object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt) / object->pt;
1782    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1783    else if(variable == "metMT") {
1784 <    const BNmet *met = chosenMET ();
1124 <    if (met)
1784 >    if (const BNmet *met = chosenMET ())
1785        {
1786 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1787 <                       p2 (met->px, met->py, 0.0, met->pt);
1128 <
1129 <        value = (p1 + p2).Mt ();
1786 >        double dPhi = deltaPhi (object->phi, met->phi);
1787 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1788        }
1789      else
1790        value = -999;
# Line 1253 | Line 1911 | OSUAnalysis::valueLookup (const BNmuon*
1911    }
1912    else if(variable == "tightIDdisplaced"){
1913      value = object->isGlobalMuon > 0                \
1914 +      && object->isPFMuon > 0                        \
1915        && object->normalizedChi2 < 10                \
1916        && object->numberOfValidMuonHits > 0        \
1917        && object->numberOfMatchedStations > 1        \
# Line 1260 | Line 1919 | OSUAnalysis::valueLookup (const BNmuon*
1919        && object->numberOfLayersWithMeasurement > 5;
1920    }
1921  
1922 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1922 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1923  
1924    else if(variable == "genMatchedPdgId"){
1925      int index = getGenMatchedParticleIndex(object);
# Line 1280 | Line 1939 | OSUAnalysis::valueLookup (const BNmuon*
1939    }
1940    else if(variable == "genMatchedMotherIdReverse"){
1941      int index = getGenMatchedParticleIndex(object);
1942 <    if(index == -1) value = 23;
1943 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1942 >    if(index == -1) value = 24;
1943 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1944    }
1945    else if(variable == "genMatchedGrandmotherId"){
1946      int index = getGenMatchedParticleIndex(object);
# Line 1293 | Line 1952 | OSUAnalysis::valueLookup (const BNmuon*
1952      }
1953      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1954    }
1955 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1956 +    int index = getGenMatchedParticleIndex(object);
1957 +    if(index == -1) value = 24;
1958 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1959 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1960 +      if(motherIndex == -1) value = 24;
1961 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1962 +    }
1963 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1964 +  }
1965 +  else if(variable == "pfMuonsFromVertex"){
1966 +    double d0Error, dzError;
1967 +
1968 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1969 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1970 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1971 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1972 +      || fabs (object->correctedDZ / dzError) > 99.0;
1973 +    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1974 +  }
1975  
1976  
1977  
1978 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1978 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1979  
1980    value = applyFunction(function, value);
1981  
1982    return value;
1983 < }
1983 > } // end muon valueLookup
1984  
1985  
1986 + //!electron valueLookup
1987   double
1988 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1988 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1989  
1990    double value = 0.0;
1991    if(variable == "energy") value = object->energy;
# Line 1470 | Line 2150 | OSUAnalysis::valueLookup (const BNelectr
2150    else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2151    else if(variable == "detIso") value = (object->trackIso) / object->pt;
2152    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2153 +  else if(variable == "relPFrhoIsoEB") value = object->isEB ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2154 +  else if(variable == "relPFrhoIsoEE") value = object->isEE ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2155    else if(variable == "metMT") {
2156 <    const BNmet *met = chosenMET ();
1475 <    if (met)
2156 >    if (const BNmet *met = chosenMET ())
2157        {
2158 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
2159 <                       p2 (met->px, met->py, 0.0, met->pt);
1479 <
1480 <        value = (p1 + p2).Mt ();
2158 >        double dPhi = deltaPhi (object->phi, met->phi);
2159 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2160        }
2161      else
2162        value = -999;
# Line 1544 | Line 2223 | OSUAnalysis::valueLookup (const BNelectr
2223      else value = -999;
2224    }
2225  
2226 +  else if(variable == "looseID"){
2227 +    if (object->isEB)
2228 +      {
2229 +        value = fabs(object->delEtaIn) < 0.007 \
2230 +          && fabs (object->delPhiIn) < 0.15 \
2231 +          && object->scSigmaIEtaIEta < 0.01 \
2232 +          && object->hadOverEm < 0.12 \
2233 +          && fabs (object->correctedD0Vertex) < 0.02 \
2234 +          && fabs (object->correctedDZ) < 0.2 \
2235 +          && object->absInvEMinusInvPin < 0.05 \
2236 +          && object->passConvVeto;
2237 +      }
2238 +    else
2239 +      {
2240 +        value = fabs(object->delEtaIn) < 0.009 \
2241 +          && fabs (object->delPhiIn) < 0.10 \
2242 +          && object->scSigmaIEtaIEta < 0.03 \
2243 +          && object->hadOverEm < 0.10 \
2244 +          && fabs (object->correctedD0Vertex) < 0.02 \
2245 +          && fabs (object->correctedDZ) < 0.2 \
2246 +          && object->absInvEMinusInvPin < 0.05 \
2247 +          && object->passConvVeto;
2248 +      }
2249 +  }
2250 +
2251    else if(variable == "tightID"){
2252      if (object->isEB)
2253        {
# Line 1569 | Line 2273 | OSUAnalysis::valueLookup (const BNelectr
2273        }
2274    }
2275  
2276 +  else if(variable == "looseID"){
2277 +    value = object->pt > 10
2278 +      && object->mvaNonTrigV0 > 0;
2279 +      }
2280    else if(variable == "correctedD0VertexInEBPositiveCharge"){
2281      if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2282      else value = -999;
# Line 1642 | Line 2350 | OSUAnalysis::valueLookup (const BNelectr
2350    }
2351  
2352  
2353 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2353 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2354  
2355    else if(variable == "genMatchedPdgId"){
2356      int index = getGenMatchedParticleIndex(object);
# Line 1663 | Line 2371 | OSUAnalysis::valueLookup (const BNelectr
2371    }
2372    else if(variable == "genMatchedMotherIdReverse"){
2373      int index = getGenMatchedParticleIndex(object);
2374 <    if(index == -1) value = 23;
2375 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2374 >    if(index == -1) value = 24;
2375 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2376    }
2377    else if(variable == "genMatchedGrandmotherId"){
2378      int index = getGenMatchedParticleIndex(object);
# Line 1676 | Line 2384 | OSUAnalysis::valueLookup (const BNelectr
2384      }
2385      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2386    }
2387 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2388 +    int index = getGenMatchedParticleIndex(object);
2389 +    if(index == -1) value = 24;
2390 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2391 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2392 +      if(motherIndex == -1) value = 24;
2393 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2394 +    }
2395 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2396 +  }
2397 +  else if(variable == "pfElectronsFromVertex"){
2398 +    double d0Error, dzError;
2399 +
2400 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2401 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2402 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2403 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2404 +      || fabs (object->correctedDZ / dzError) > 99.0;
2405 +    value = !value;
2406 +  }
2407  
2408  
2409  
2410 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2410 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2411  
2412    value = applyFunction(function, value);
2413  
2414    return value;
2415 < }
2415 > } // end electron valueLookup
2416  
2417  
2418 + //!event valueLookup
2419   double
2420 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2420 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2421  
2422    double value = 0.0;
2423  
# Line 1696 | Line 2425 | OSUAnalysis::valueLookup (const BNevent*
2425    else if(variable == "pthat") value = object->pthat;
2426    else if(variable == "qScale") value = object->qScale;
2427    else if(variable == "alphaQCD") value = object->alphaQCD;
2428 +  else if(variable == "Ht") value = getHt(jets.product());
2429    else if(variable == "alphaQED") value = object->alphaQED;
2430    else if(variable == "scalePDF") value = object->scalePDF;
2431    else if(variable == "x1") value = object->x1;
# Line 1757 | Line 2487 | OSUAnalysis::valueLookup (const BNevent*
2487    else if(variable == "id2") value = object->id2;
2488    else if(variable == "evt") value = object->evt;
2489    else if(variable == "puScaleFactor"){
2490 <    if(datasetType_ != "data")
2490 >    if(doPileupReweighting_ && datasetType_ != "data")
2491        value = puWeight_->at (events->at (0).numTruePV);
2492      else
2493        value = 1.0;
2494    }
2495 <  else if(variable == "muonScaleFactor"){
2496 <    if(datasetType_ != "data")
2497 <      //      value = muonSFWeight_->at (chosenMuon ()->eta);
2498 <    value = 1.0;
2499 <    else
2500 <      value = 1.0;
2501 <  }
2502 <  else if(variable == "electronScaleFactor"){
2503 <    if(datasetType_ != "data")
2504 <      //      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
2505 <    value = 1.0;
2506 <    else
2507 <      value = 1.0;
2495 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2496 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2497 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2498 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2499 >  else if(variable == "ht") value = chosenHT ();
2500 >  else if(variable == "leadMuPairInvMass"){
2501 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2502 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2503 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2504 >    value = (p0 + p1).M ();
2505 >  }
2506 >  else if(variable == "leadMuPairPt"){
2507 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2508 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2509 >             pt1 (muPair.second->px, muPair.second->py);
2510 >    pt0 += pt1;
2511 >    value = pt0.Mod ();
2512 >  }
2513 >  else if(variable == "leadElPairInvMass"){
2514 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2515 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2516 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2517 >    value = (p0 + p1).M ();
2518 >  }
2519 >  else if(variable == "leadElPairPt"){
2520 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2521 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2522 >             pt1 (muPair.second->px, muPair.second->py);
2523 >    pt0 += pt1;
2524 >    value = pt0.Mod ();
2525    }
2526 <
1780 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2526 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2527  
2528    value = applyFunction(function, value);
2529  
2530    return value;
2531 < }
2531 > } // end event valueLookup
2532 >
2533  
2534 + //!tau valueLookup
2535   double
2536 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2536 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2537  
2538    double value = 0.0;
2539  
# Line 1829 | Line 2577 | OSUAnalysis::valueLookup (const BNtau* o
2577    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2578    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2579  
2580 +  else if (variable == "looseHadronicID") {
2581 +    value = object->pt > 10
2582 +      && object->eta < 2.3
2583 +      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2584 +      && object->HPSdecayModeFinding > 0
2585 +      && object->HPSagainstElectronLoose > 0
2586 +      && object->HPSagainstMuonTight > 0;
2587 +  }
2588  
2589 <
1834 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2589 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2590  
2591    else if(variable == "genMatchedPdgId"){
2592      int index = getGenMatchedParticleIndex(object);
# Line 1851 | Line 2606 | OSUAnalysis::valueLookup (const BNtau* o
2606    }
2607    else if(variable == "genMatchedMotherIdReverse"){
2608      int index = getGenMatchedParticleIndex(object);
2609 <    if(index == -1) value = 23;
2610 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2609 >    if(index == -1) value = 24;
2610 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2611    }
2612    else if(variable == "genMatchedGrandmotherId"){
2613      int index = getGenMatchedParticleIndex(object);
# Line 1864 | Line 2619 | OSUAnalysis::valueLookup (const BNtau* o
2619      }
2620      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2621    }
2622 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2623 +    int index = getGenMatchedParticleIndex(object);
2624 +    if(index == -1) value = 24;
2625 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2626 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2627 +      if(motherIndex == -1) value = 24;
2628 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2629 +    }
2630 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2631 +  }
2632  
2633  
2634 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2634 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2635  
2636    value = applyFunction(function, value);
2637  
2638    return value;
2639 < }
2639 > } // end tau valueLookup
2640 >
2641  
2642 + //!met valueLookup
2643   double
2644 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2644 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2645  
2646    double value = 0.0;
2647  
# Line 1938 | Line 2705 | OSUAnalysis::valueLookup (const BNmet* o
2705    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2706    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2707  
2708 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2708 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2709  
2710    value = applyFunction(function, value);
2711  
2712    return value;
2713 < }
2713 > } // end met valueLookup
2714 >
2715  
2716 + //!track valueLookup
2717   double
2718 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2718 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2719  
2720    double value = 0.0;
2721    double pMag = sqrt(object->pt * object->pt +
2722 <                         object->pz * object->pz);
2722 >                     object->pz * object->pz);
2723  
2724    if(variable == "pt") value = object->pt;
2725    else if(variable == "px") value = object->px;
# Line 1970 | Line 2739 | OSUAnalysis::valueLookup (const BNtrack*
2739    else if(variable == "numValidHits") value = object->numValidHits;
2740    else if(variable == "isHighPurity") value = object->isHighPurity;
2741  
1973
2742    //additional BNs info for disappTrks
2743 <  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2744 <  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2745 <  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2746 <  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2747 <  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2748 <  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2749 <  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2750 <  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
1983 <  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2743 >  else if(variable == "caloEMDeltaRp3")     value = object->caloEMDeltaRp3;
2744 >  else if(variable == "caloHadDeltaRp3")    value = object->caloHadDeltaRp3;
2745 >  else if(variable == "caloEMDeltaRp4")     value = object->caloEMDeltaRp4;
2746 >  else if(variable == "caloHadDeltaRp4")    value = object->caloHadDeltaRp4;
2747 >  else if(variable == "caloEMDeltaRp5")     value = object->caloEMDeltaRp5;
2748 >  else if(variable == "caloHadDeltaRp5")    value = object->caloHadDeltaRp5;
2749 >  else if(variable == "nHitsMissingOuter")  value = object->nHitsMissingOuter;
2750 >  else if(variable == "nHitsMissingInner")  value = object->nHitsMissingInner;
2751    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2752 <  
2752 >  else if(variable == "depTrkRp3")          value = object->depTrkRp3;
2753 >  else if(variable == "depEcalRp3")         value = object->depEcalRp3;
2754 >  else if(variable == "depHcalRp3")         value = object->depHcalRp3;
2755 >  else if(variable == "depHoRp3")           value = object->depHoRp3;
2756 >  else if(variable == "nTracksRp3")         value = object->nTracksRp3;
2757 >  else if(variable == "trackerVetoPtRp3")   value = object->trackerVetoPtRp3;
2758 >  else if(variable == "emVetoEtRp3")        value = object->emVetoEtRp3;
2759 >  else if(variable == "hadVetoEtRp3")       value = object->hadVetoEtRp3;
2760 >  else if(variable == "hoVetoEtRp3")        value = object->hoVetoEtRp3;
2761 >  else if(variable == "depTrkRp5")          value = object->depTrkRp5;
2762 >  else if(variable == "depEcalRp5")         value = object->depEcalRp5;
2763 >  else if(variable == "depHcalRp5")         value = object->depHcalRp5;
2764 >  else if(variable == "depHoRp5")           value = object->depHoRp5;
2765 >  else if(variable == "nTracksRp5")         value = object->nTracksRp5;
2766 >  else if(variable == "trackerVetoPtRp5")   value = object->trackerVetoPtRp5;
2767 >  else if(variable == "emVetoEtRp5")        value = object->emVetoEtRp5;
2768 >  else if(variable == "hadVetoEtRp5")       value = object->hadVetoEtRp5;
2769 >  else if(variable == "hoVetoEtRp5")        value = object->hoVetoEtRp5;
2770  
2771    //user defined variables
2772    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;
2773    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2774 <  else if(variable == "caloTotDeltaRp5") value =(object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2775 <  else if(variable == "caloTotDeltaRp5ByP") value =( (object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2776 <  else if(variable == "isIso") value = getTrkIsIso(object, tracks.product());
2777 <  else if(variable == "isMatchedDeadEcal") value = getTrkIsMatchedDeadEcal(object);
2778 <  else if(variable == "ptErrorByPt") value = (object->ptError/object->pt);
2779 <  else if(variable == "ptError") value = object->ptError;
2780 <  else if(variable == "ptRes") value = getTrkPtRes(object);
2774 >  else if(variable == "depTrkRp5MinusPt"){
2775 >    if ( (object->depTrkRp5 - object->pt) < 0 ) {
2776 >           value = 0;
2777 >         }
2778 >         else value =  (object->depTrkRp5 - object->pt);
2779 >  }
2780 >  else if(variable == "depTrkRp3MinusPt"){
2781 >    if ( (object->depTrkRp3 - object->pt) < 0 ) {
2782 >      value = 0;
2783 >    }
2784 >    else value =  (object->depTrkRp3 - object->pt);
2785 >  }
2786  
2787 +  else if(variable == "dPhiMet") {
2788 +    if (const BNmet *met = chosenMET ()) {
2789 +      value = deltaPhi (object->phi, met->phi);
2790 +    } else value = -999;
2791 +  }
2792 +  
2793 +  
2794 +  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2795 +  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2796 +  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2797 +  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2798 +  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2799 +  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2800 +  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2801 +  else if(variable == "ptError")                    value = object->ptError;
2802 +  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2803    else if (variable == "d0wrtPV"){
2804      double vx = object->vx - chosenVertex ()->x,
2805        vy = object->vy - chosenVertex ()->y,
# Line 2015 | Line 2820 | OSUAnalysis::valueLookup (const BNtrack*
2820    }
2821  
2822  
2823 <
2019 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2823 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2824  
2825    else if(variable == "genMatchedPdgId"){
2826      int index = getGenMatchedParticleIndex(object);
# Line 2024 | Line 2828 | OSUAnalysis::valueLookup (const BNtrack*
2828      else value = mcparticles->at(index).id;
2829    }
2830  
2831 +
2832    else if(variable == "genMatchedId"){
2833      int index = getGenMatchedParticleIndex(object);
2834      if(index == -1) value = 0;
# Line 2036 | Line 2841 | OSUAnalysis::valueLookup (const BNtrack*
2841    }
2842    else if(variable == "genMatchedMotherIdReverse"){
2843      int index = getGenMatchedParticleIndex(object);
2844 <    if(index == -1) value = 23;
2845 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2844 >    if(index == -1) value = 24;
2845 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2846    }
2847    else if(variable == "genMatchedGrandmotherId"){
2848      int index = getGenMatchedParticleIndex(object);
# Line 2049 | Line 2854 | OSUAnalysis::valueLookup (const BNtrack*
2854      }
2855      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2856    }
2857 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2858 +    int index = getGenMatchedParticleIndex(object);
2859 +    if(index == -1) value = 24;
2860 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2861 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2862 +      if(motherIndex == -1) value = 24;
2863 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2864 +    }
2865 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2866 +  }
2867  
2868  
2869  
2870 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2870 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2871  
2872    value = applyFunction(function, value);
2873  
2874    return value;
2875 < }
2875 > } // end track valueLookup
2876 >
2877  
2878 + //!genjet valueLookup
2879   double
2880 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2880 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2881  
2882    double value = 0.0;
2883  
# Line 2080 | Line 2897 | OSUAnalysis::valueLookup (const BNgenjet
2897    else if(variable == "charge") value = object->charge;
2898  
2899  
2900 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2900 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2901  
2902    value = applyFunction(function, value);
2903  
2904    return value;
2905   }
2906  
2907 + //!mcparticle valueLookup
2908   double
2909 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2909 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2910  
2911    double value = 0.0;
2912  
# Line 2213 | Line 3031 | OSUAnalysis::valueLookup (const BNmcpart
3031    }
3032  
3033  
3034 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3034 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3035  
3036    value = applyFunction(function, value);
3037  
3038    return value;
3039 < }
3039 > } // end mcparticle valueLookup
3040  
3041 +
3042 + //!primaryvertex valueLookup
3043   double
3044 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
3044 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
3045  
3046    double value = 0.0;
3047  
# Line 2240 | Line 3060 | OSUAnalysis::valueLookup (const BNprimar
3060    else if(variable == "isGood") value = object->isGood;
3061  
3062  
3063 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3063 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3064  
3065    value = applyFunction(function, value);
3066  
3067    return value;
3068   }
3069  
3070 + //!bxlumi valueLookup
3071   double
3072 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
3072 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
3073  
3074    double value = 0.0;
3075  
# Line 2257 | Line 3078 | OSUAnalysis::valueLookup (const BNbxlumi
3078    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
3079  
3080  
3081 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3081 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3082  
3083    value = applyFunction(function, value);
3084  
3085    return value;
3086   }
3087  
3088 + //!photon valueLookup
3089   double
3090 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
3090 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
3091  
3092    double value = 0.0;
3093  
# Line 2338 | Line 3160 | OSUAnalysis::valueLookup (const BNphoton
3160    else if(variable == "isEEGap") value = object->isEEGap;
3161    else if(variable == "hasPixelSeed") value = object->hasPixelSeed;
3162    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2341
3163  
3164 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3164 >
3165 >
3166 >
3167 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3168  
3169    else if(variable == "genMatchedPdgId"){
3170      int index = getGenMatchedParticleIndex(object);
3171      if(index == -1) value = 0;
3172      else value = mcparticles->at(index).id;
3173    }
3174 +
3175 +
3176 +
3177    else if(variable == "genMatchedId"){
3178      int index = getGenMatchedParticleIndex(object);
3179      if(index == -1) value = 0;
# Line 2359 | Line 3186 | OSUAnalysis::valueLookup (const BNphoton
3186    }
3187    else if(variable == "genMatchedMotherIdReverse"){
3188      int index = getGenMatchedParticleIndex(object);
3189 <    if(index == -1) value = 23;
3190 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
3189 >    if(index == -1) value = 24;
3190 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
3191    }
3192    else if(variable == "genMatchedGrandmotherId"){
3193      int index = getGenMatchedParticleIndex(object);
# Line 2372 | Line 3199 | OSUAnalysis::valueLookup (const BNphoton
3199      }
3200      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3201    }
3202 +  else if(variable == "genMatchedGrandmotherIdReverse"){
3203 +    int index = getGenMatchedParticleIndex(object);
3204 +    if(index == -1) value = 24;
3205 +    else if(fabs(mcparticles->at(index).motherId) == 15){
3206 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3207 +      if(motherIndex == -1) value = 24;
3208 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3209 +    }
3210 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3211 +  }
3212  
3213  
3214 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3214 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3215  
3216    value = applyFunction(function, value);
3217  
3218    return value;
3219 < }
3219 > } // end photon valueLookup
3220 >
3221  
3222 + //!supercluster valueLookup
3223   double
3224 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
3224 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
3225  
3226    double value = 0.0;
3227  
# Line 2396 | Line 3235 | OSUAnalysis::valueLookup (const BNsuperc
3235    else if(variable == "theta") value = object->theta;
3236  
3237  
3238 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3238 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3239  
3240    value = applyFunction(function, value);
3241  
3242    return value;
3243   }
3244  
3245 + //!trigobj valueLookup
3246 + double
3247 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3248  
3249 +  double value = 0.0;
3250 +
3251 +  if(variable == "pt") value = object->pt;
3252 +  else if(variable == "eta") value = object->eta;
3253 +  else if(variable == "phi") value = object->phi;
3254 +  else if(variable == "px") value = object->px;
3255 +  else if(variable == "py") value = object->py;
3256 +  else if(variable == "pz") value = object->pz;
3257 +  else if(variable == "et") value = object->et;
3258 +  else if(variable == "energy") value = object->energy;
3259 +  else if(variable == "etTotal") value = object->etTotal;
3260 +  else if(variable == "id") value = object->id;
3261 +  else if(variable == "charge") value = object->charge;
3262 +  else if(variable == "isIsolated") value = object->isIsolated;
3263 +  else if(variable == "isMip") value = object->isMip;
3264 +  else if(variable == "isForward") value = object->isForward;
3265 +  else if(variable == "isRPC") value = object->isRPC;
3266 +  else if(variable == "bx") value = object->bx;
3267 +  else if(variable == "filter") {
3268 +    if ((stringValue = object->filter) == "")
3269 +      stringValue = "none";  // stringValue should only be empty if value is filled
3270 +  }
3271 +
3272 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3273 +
3274 +  value = applyFunction(function, value);
3275 +
3276 +  return value;
3277 + }
3278 +
3279 + //!muon-muon pair valueLookup
3280   double
3281 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
3281 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3282  
3283    double value = 0.0;
3284  
3285    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3286 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3287    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3288    else if(variable == "invMass"){
3289      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2419 | Line 3293 | OSUAnalysis::valueLookup (const BNmuon*
3293    else if(variable == "pt"){
3294      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3295      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3296 <    value = (fourVector1 + fourVector2).Et();
3296 >    value = (fourVector1 + fourVector2).Pt();
3297    }
3298    else if(variable == "threeDAngle")
3299      {
# Line 2451 | Line 3325 | OSUAnalysis::valueLookup (const BNmuon*
3325    else if(variable == "muon2CorrectedD0Vertex"){
3326      value = object2->correctedD0Vertex;
3327    }
3328 < else if(variable == "muon1timeAtIpInOut"){
3328 >  else if(variable == "muon1timeAtIpInOut"){
3329      value = object1->timeAtIpInOut;
3330    }
3331 < else if(variable == "muon2timeAtIpInOut"){
3331 >  else if(variable == "muon2timeAtIpInOut"){
3332      value = object2->timeAtIpInOut;
3333    }
3334 < else if(variable == "muon1correctedD0")
3335 <   {
3336 <     value = object1->correctedD0;
3337 <   }
3338 < else if(variable == "muon2correctedD0")
3339 <   {
3340 <     value = object2->correctedD0;
3341 <   }
3334 >  else if(variable == "muon1correctedD0")
3335 >    {
3336 >      value = object1->correctedD0;
3337 >    }
3338 >  else if(variable == "muon2correctedD0")
3339 >    {
3340 >      value = object2->correctedD0;
3341 >    }
3342 >
3343 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3344 >
3345 >  value = applyFunction(function, value);
3346 >
3347 >  return value;
3348 > } // end muon-muon pair valueLookup
3349  
3350 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3350 >
3351 > //!muon-photon pair valueLookup
3352 > double
3353 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3354 >
3355 >  double value = 0.0;
3356 >
3357 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3358 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3359 >  else if(variable == "photonEta") value = object2->eta;
3360 >  else if(variable == "photonPt") value = object2->pt;
3361 >  else if(variable == "muonEta") value = object1->eta;
3362 >  else if(variable == "photonPhi") value = object2->phi;
3363 >  else if(variable == "muonPhi") value = object1->phi;
3364 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3365 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3366 >  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3367 >  else if(variable == "invMass"){
3368 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3369 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3370 >    value = (fourVector1 + fourVector2).M();
3371 >  }
3372 >  else if(variable == "pt"){
3373 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3374 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3375 >    value = (fourVector1 + fourVector2).Pt();
3376 >  }
3377 >  else if(variable == "threeDAngle")
3378 >    {
3379 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3380 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3381 >      value = (threeVector1.Angle(threeVector2));
3382 >    }
3383 >  else if(variable == "alpha")
3384 >    {
3385 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3386 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3387 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3388 >      value = (pi-threeVector1.Angle(threeVector2));
3389 >    }
3390 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3391  
3392    value = applyFunction(function, value);
3393  
3394    return value;
3395   }
3396  
3397 + //!electron-photon pair valueLookup
3398   double
3399 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
3399 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3400  
3401    double value = 0.0;
3402  
3403    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3404 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3405 +  else if(variable == "photonEta") value = object2->eta;
3406 +  else if(variable == "photonPt") value = object2->pt;
3407 +  else if(variable == "electronEta") value = object1->eta;
3408 +  else if(variable == "photonPhi") value = object2->phi;
3409 +  else if(variable == "electronPhi") value = object1->phi;
3410    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3411 +  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3412 +  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3413    else if(variable == "invMass"){
3414      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3415      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
# Line 2488 | Line 3418 | OSUAnalysis::valueLookup (const BNelectr
3418    else if(variable == "pt"){
3419      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3420      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3421 <    value = (fourVector1 + fourVector2).Et();
3421 >    value = (fourVector1 + fourVector2).Pt();
3422 >  }
3423 >  else if(variable == "threeDAngle")
3424 >    {
3425 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3426 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3427 >      value = (threeVector1.Angle(threeVector2));
3428 >    }
3429 >  else if(variable == "alpha")
3430 >    {
3431 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3432 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3433 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3434 >      value = (pi-threeVector1.Angle(threeVector2));
3435 >    }
3436 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3437 >
3438 >  value = applyFunction(function, value);
3439 >
3440 >  return value;
3441 > }
3442 >
3443 > //!electron-electron pair valueLookup
3444 > double
3445 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3446 >
3447 >  double value = 0.0;
3448 >
3449 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3450 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3451 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3452 >  else if(variable == "invMass"){
3453 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3454 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3455 >    value = (fourVector1 + fourVector2).M();
3456 >  }
3457 >  else if(variable == "pt"){
3458 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3459 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3460 >    value = (fourVector1 + fourVector2).Pt();
3461    }
3462    else if(variable == "threeDAngle")
3463      {
# Line 2520 | Line 3489 | OSUAnalysis::valueLookup (const BNelectr
3489      value = object2->correctedD0;
3490    }
3491  
3492 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3492 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3493  
3494    value = applyFunction(function, value);
3495  
3496    return value;
3497   }
3498  
3499 + //!electron-muon pair valueLookup
3500   double
3501 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3501 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3502  
3503    double value = 0.0;
3504  
3505    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3506 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3507    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3508    else if(variable == "invMass"){
3509      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2542 | Line 3513 | OSUAnalysis::valueLookup (const BNelectr
3513    else if(variable == "pt"){
3514      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3515      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3516 <    value = (fourVector1 + fourVector2).Et();
3516 >    value = (fourVector1 + fourVector2).Pt();
3517    }
3518    else if(variable == "threeDAngle")
3519      {
# Line 2579 | Line 3550 | OSUAnalysis::valueLookup (const BNelectr
3550    else if(variable == "muonDetIso"){
3551      value = (object2->trackIsoDR03) / object2->pt;
3552    }
3553 +  else if(variable == "electronRelPFrhoIso"){
3554 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3555 +  }
3556 +  else if(variable == "muonRelPFdBetaIso"){
3557 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3558 +  }
3559 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3560 +  value = applyFunction(function, value);
3561 +
3562 +  return value;
3563 + } // end electron-muon pair valueLookup
3564  
3565  
3566 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3566 > //!electron-jet pair valueLookup
3567 > double
3568 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3569  
3570 +  double value = 0.0;
3571 +
3572 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3573 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3574 +  else if(variable == "jetEta") value = object2->eta;
3575 +  else if(variable == "jetPhi") value = object2->phi;
3576 +  else if(variable == "electronEta") value = object1->eta;
3577 +  else if(variable == "electronPhi") value = object1->phi;
3578 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3579 +  else if(variable == "invMass"){
3580 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3581 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3582 +    value = (fourVector1 + fourVector2).M();
3583 +  }
3584 +  else if(variable == "pt"){
3585 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3586 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3587 +    value = (fourVector1 + fourVector2).Pt();
3588 +  }
3589 +  else if(variable == "threeDAngle")
3590 +    {
3591 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3592 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3593 +      value = (threeVector1.Angle(threeVector2));
3594 +    }
3595 +  else if(variable == "chargeProduct"){
3596 +    value = object1->charge*object2->charge;
3597 +  }
3598 +
3599 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3600    value = applyFunction(function, value);
3601  
3602    return value;
3603   }
3604  
3605 + //!photon-jet pair valueLookup
3606 + double
3607 + OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3608  
3609 +  double value = 0.0;
3610 +
3611 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3612 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3613 +  else if(variable == "jetEta") value = object2->eta;
3614 +  else if(variable == "jetPhi") value = object2->phi;
3615 +  else if(variable == "photonEta") value = object1->eta;
3616 +  else if(variable == "photonPhi") value = object1->phi;
3617 +  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3618 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3619 +  else if(variable == "invMass"){
3620 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3621 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3622 +    value = (fourVector1 + fourVector2).M();
3623 +  }
3624 +  else if(variable == "pt"){
3625 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3626 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3627 +    value = (fourVector1 + fourVector2).Pt();
3628 +  }
3629 +  else if(variable == "threeDAngle")
3630 +    {
3631 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3632 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3633 +      value = (threeVector1.Angle(threeVector2));
3634 +    }
3635 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3636 +  value = applyFunction(function, value);
3637 +
3638 +  return value;
3639 + }
3640 +
3641 + // track-jet pair valueLookup
3642 + double
3643 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNjet* object2, string variable, string function, string &stringValue){
3644 +
3645 +  double value = 0.0;
3646 +
3647 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3648 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3649 +
3650 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3651 +  value = applyFunction(function, value);
3652 +
3653 +  return value;
3654 +
3655 + }
3656 +
3657 +
3658 +
3659 + // met-jet pair valueLookup
3660   double
3661 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function){
3661 > OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3662 >
3663 >  double value = 0.0;
3664 >
3665 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3666 >
3667 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3668 >  value = applyFunction(function, value);
3669 >
3670 >  return value;
3671 >
3672 > }  
3673 >
3674 >
3675 >
3676 > //!muon-jet pair valueLookup
3677 > double
3678 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3679 >
3680 >  double value = 0.0;
3681 >
3682 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3683 >  else if(variable == "jetEta") value = object2->eta;
3684 >  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3685 >  else if(variable == "jetPt") value = object2->pt;
3686 >  else if(variable == "jetPhi") value = object2->phi;
3687 >  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3688 >  else if(variable == "muonEta") value = object1->eta;
3689 >  else if(variable == "muonPt") value = object1->pt;
3690 >  else if(variable == "muonPhi") value = object1->phi;
3691 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3692 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3693 >  else if(variable == "invMass"){
3694 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3695 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3696 >    value = (fourVector1 + fourVector2).M();
3697 >  }
3698 >  else if(variable == "pt"){
3699 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3700 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3701 >    value = (fourVector1 + fourVector2).Pt();
3702 >  }
3703 >  else if(variable == "threeDAngle")
3704 >    {
3705 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3706 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3707 >      value = (threeVector1.Angle(threeVector2));
3708 >    }
3709 >  else if(variable == "chargeProduct"){
3710 >    value = object1->charge*object2->charge;
3711 >  }
3712 >
3713 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3714 >  value = applyFunction(function, value);
3715 >
3716 >  return value;
3717 > }
3718 >
3719 > //!muon-event valueLookup
3720 > double
3721 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNevent* object2, string variable, string function, string &stringValue){
3722 >
3723 >  double value = 0.0;
3724 >
3725 >  if(variable == "muonEta") value = object1->eta;
3726 >  else if(variable == "muonPt") value = object1->pt;
3727 >  else if(variable == "muonPhi") value = object1->phi;
3728 >  else if(variable == "Ht") value = getHt(jets.product());
3729 >  else if(variable == "pthat")   value = object2->pthat;
3730 >  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3731 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3732 >  value = applyFunction(function, value);
3733 >
3734 >  return value;
3735 > }
3736 > //!jet-jet pair valueLookup
3737 > double
3738 > OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3739 >
3740 >  double value = 0.0;
3741 >
3742 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3743 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3744 >  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3745 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3746 >  else if(variable == "invMass"){
3747 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3748 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3749 >    value = (fourVector1 + fourVector2).M();
3750 >  }
3751 >  else if(variable == "pt"){
3752 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3753 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3754 >    value = (fourVector1 + fourVector2).Pt();
3755 >  }
3756 >  else if(variable == "threeDAngle")
3757 >    {
3758 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3759 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3760 >      value = (threeVector1.Angle(threeVector2));
3761 >    }
3762 >  else if(variable == "chargeProduct"){
3763 >    value = object1->charge*object2->charge;
3764 >  }
3765 >
3766 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3767 >  value = applyFunction(function, value);
3768 >
3769 >  return value;
3770 > }
3771 >
3772 > //!electron-track pair valueLookup
3773 > double
3774 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3775    double electronMass = 0.000511;
3776    double value = 0.0;
3777 <  TLorentzVector fourVector1(0, 0, 0, 0);  
3778 <  TLorentzVector fourVector2(0, 0, 0, 0);  
3777 >  TLorentzVector fourVector1(0, 0, 0, 0);
3778 >  TLorentzVector fourVector2(0, 0, 0, 0);
3779    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3780 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3781    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3782    else if(variable == "invMass"){
3783      fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3784      fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3785 <    
3785 >
3786      value = (fourVector1 + fourVector2).M();
3787    }
3788 <  
3789 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3788 >  else if(variable == "chargeProduct"){
3789 >    value = object1->charge*object2->charge;
3790 >  }
3791 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3792    value = applyFunction(function, value);
3793    return value;
3794 +
3795   }
3796  
3797 +
3798 + //!muon-track pair valueLookup
3799   double
3800 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function){
3800 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3801    double pionMass = 0.140;
3802    double muonMass = 0.106;
3803    double value = 0.0;
3804    TLorentzVector fourVector1(0, 0, 0, 0);
3805    TLorentzVector fourVector2(0, 0, 0, 0);
3806    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3807 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3808    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3809    else if(variable == "invMass"){
3810      fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
# Line 2624 | Line 3812 | OSUAnalysis::valueLookup (const BNmuon*
3812  
3813      value = (fourVector1 + fourVector2).M();
3814    }
3815 +  else if(variable == "chargeProduct"){
3816 +    value = object1->charge*object2->charge;
3817 +  }
3818  
3819 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3819 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3820    value = applyFunction(function, value);
3821    return value;
3822   }
3823  
3824 <
3824 > //!tau-tau pair valueLookup
3825   double
3826 < OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function){
3826 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3827    double value = 0.0;
3828    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3829 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3830    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3831    else if(variable == "invMass"){
3832 <  TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3833 <  TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3834 <     value = (fourVector1 + fourVector2).M();
3832 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3833 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3834 >    value = (fourVector1 + fourVector2).M();
3835    }
3836  
3837 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3837 >  else if(variable == "chargeProduct"){
3838 >    value = object1->charge*object2->charge;
3839 >  }
3840 >
3841 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3842    value = applyFunction(function, value);
3843    return value;
3844   }
3845  
3846 + //!muon-tau pair valueLookup
3847   double
3848 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function){
3848 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3849    double value = 0.0;
3850    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3851 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3852    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3853    else if(variable == "invMass"){
3854      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2658 | Line 3856 | OSUAnalysis::valueLookup (const BNmuon*
3856      value = (fourVector1 + fourVector2).M();
3857    }
3858  
3859 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3859 >  else if(variable == "chargeProduct"){
3860 >    value = object1->charge*object2->charge;
3861 >  }
3862 >
3863 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3864 >  value = applyFunction(function, value);
3865 >  return value;
3866 > }
3867 >
3868 > //!tau-track pair valueLookup
3869 > double
3870 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3871 >  double value = 0.0;
3872 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3873 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3874 >  else if(variable == "chargeProduct"){
3875 >    value = object1->charge*object2->charge;
3876 >  }
3877 >
3878 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3879 >  value = applyFunction(function, value);
3880 >  return value;
3881 > }
3882 >
3883 >
3884 > //!track-event pair valueLookup
3885 > double
3886 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3887 >
3888 >  double value = 0.0;
3889 >  double pMag = sqrt(object1->pt * object1->pt +
3890 >                     object1->pz * object1->pz);
3891 >
3892 >  if      (variable == "numPV")                      value = object2->numPV;
3893 >  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3894 >  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3895 >  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3896 >  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3897 >
3898 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3899 >
3900    value = applyFunction(function, value);
3901 +
3902    return value;
3903 +
3904   }
3905  
3906 + //!electron-trigobj pair valueLookup
3907 + double
3908 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3909 +
3910 +  double value = 0.0;
3911 +
3912 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3913 +  else if (variable == "match"){
3914 +    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3915 +      stringValue = object2->filter;
3916 +    else
3917 +      stringValue = "none";
3918 +  }
3919 +
3920 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3921 +
3922 +  value = applyFunction(function, value);
3923 +
3924 +  return value;
3925 +
3926 + }
3927 +
3928 + //!muon-trigobj pair valueLookup
3929 + double
3930 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3931 +
3932 +  double value = 0.0;
3933 +
3934 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3935 +
3936 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3937 +
3938 +  value = applyFunction(function, value);
3939 +
3940 +  return value;
3941 +
3942 + }
3943 +
3944 + //!stop valueLookup
3945 + double
3946 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3947 +
3948 +
3949 +  double value = 0.0;
3950 +
3951 +  if(variable == "ctau") value = object->ctau;
3952 +
3953 +  else if (variable == "d0"){
3954 +    double vx = object->vx - chosenVertex ()->x,
3955 +      vy = object->vy - chosenVertex ()->y,
3956 +      px = object->px,
3957 +      py = object->py,
3958 +      pt = object->pt;
3959 +    value = (-vx * py + vy * px) / pt;
3960 +  }
3961 +
3962 +  else if (variable == "dz"){
3963 +    double vx = object->vx - chosenVertex ()->x,
3964 +      vy = object->vy - chosenVertex ()->y,
3965 +      vz = object->vz - chosenVertex ()->z,
3966 +      px = object->px,
3967 +      py = object->py,
3968 +      pz = object->pz,
3969 +      pt = object->pt;
3970 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3971 +  }
3972 +
3973 +  else if (variable == "minD0"){
3974 +    double minD0=999;
3975 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3976 +      double vx = object->vx - vertex->x,
3977 +        vy = object->vy - vertex->y,
3978 +        px = object->px,
3979 +        py = object->py,
3980 +        pt = object->pt;
3981 +      value = (-vx * py + vy * px) / pt;
3982 +      if(abs(value) < abs(minD0)) minD0 = value;
3983 +    }
3984 +    value = minD0;
3985 +  }
3986 +  else if (variable == "minDz"){
3987 +    double minDz=999;
3988 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3989 +      double vx = object->vx - vertex->x,
3990 +        vy = object->vy - vertex->y,
3991 +        vz = object->vz - vertex->z,
3992 +        px = object->px,
3993 +        py = object->py,
3994 +        pz = object->pz,
3995 +        pt = object->pt;
3996 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3997 +      if(abs(value) < abs(minDz)) minDz = value;
3998 +    }
3999 +    value = minDz;
4000 +  }
4001 +  else if(variable == "distToVertex"){
4002 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4003 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4004 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4005 +  }
4006 +  else if (variable == "minDistToVertex"){
4007 +    double minDistToVertex=999;
4008 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4009 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4010 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4011 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
4012 +
4013 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4014 +    }
4015 +    value = minDistToVertex;
4016 +  }
4017 +  else if (variable == "distToVertexDifference"){
4018 +    double minDistToVertex=999;
4019 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4020 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4021 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4022 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
4023 +
4024 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4025 +    }
4026 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4027 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4028 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4029 +
4030 +    value = distToChosenVertex - minDistToVertex;
4031 +  }
4032 +
4033 +  else if (variable == "closestVertexRank"){
4034 +    double minDistToVertex=999;
4035 +    int vertex_rank = 0;
4036 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4037 +      vertex_rank++;
4038 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4039 +                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
4040 +                      (object->vz-vertex->z)*(object->vz-vertex->z));
4041 +
4042 +      if(abs(dist) < abs(minDistToVertex)){
4043 +        value = vertex_rank;
4044 +        minDistToVertex = dist;
4045 +      }
4046 +    }
4047 +  }
4048 +
4049 +  else if (variable == "decaysToTau"){
4050 +    value = abs (object->daughter0Id) == 15 || abs (object->daughter1Id) == 15;
4051 +  }
4052 +
4053 +
4054 +
4055 +
4056 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4057 +
4058 +  value = applyFunction(function, value);
4059 +
4060 +  return value;
4061 +
4062 + } // end stop valueLookup
4063 +
4064 +
4065 +
4066  
4067  
4068   // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
# Line 2678 | Line 4078 | OSUAnalysis::getTrkIsIso (const BNtrack*
4078  
4079   }
4080  
4081 + //calculate the scalar sum of Jet Pt in the event.
4082 + double
4083 + OSUAnalysis::getHt (const BNjetCollection* jetColl){
4084 +  double Ht = 0;
4085 +  for(BNjetCollection::const_iterator jet = jetColl->begin(); jet !=jetColl->end(); jet++){
4086 +    Ht += abs(jet->pt);
4087 +  }
4088 +  return Ht;
4089 + }
4090  
4091   double
4092   OSUAnalysis::getTrkPtRes (const BNtrack* track1){
# Line 2710 | Line 4119 | OSUAnalysis::getTrkPtTrue (const BNtrack
4119  
4120   }
4121  
4122 + double
4123 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
4124 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
4125 +  if (!useTrackCaloRhoCorr_) return -99;
4126 +  // if (!rhokt6CaloJetsHandle_) {
4127 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
4128 +  //   return -99;
4129 +  // }
4130 +  double radDeltaRCone = 0.5;
4131 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
4132 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
4133 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
4134 +  return caloTotRhoCorrCalo;
4135 +
4136 + }
4137 +
4138 +
4139 +
4140 +
4141   //creates a map of the dead Ecal channels in the barrel and endcap
4142   //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
4143   //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
# Line 2718 | Line 4146 | OSUAnalysis::WriteDeadEcal (){
4146    double etaEcal, phiEcal;
4147    ifstream DeadEcalFile(deadEcalFile_);
4148    if(!DeadEcalFile) {
4149 <    cout << "Error: DeadEcalFile has not been found." << endl;
4149 >    clog << "Error: DeadEcalFile has not been found." << endl;
4150      return;
4151    }
4152    if(DeadEcalVec.size()!= 0){
4153 <    cout << "Error: DeadEcalVec has a nonzero size" << endl;
4153 >    clog << "Error: DeadEcalVec has a nonzero size" << endl;
4154      return;
4155    }
4156    while(!DeadEcalFile.eof())
# Line 2733 | Line 4161 | OSUAnalysis::WriteDeadEcal (){
4161        newChan.phiEcal = phiEcal;
4162        DeadEcalVec.push_back(newChan);
4163      }
4164 <  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
4164 >  if(DeadEcalVec.size() == 0) clog << "Warning: No dead Ecal channels have been found." << endl;
4165   }
4166  
4167   //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
# Line 2742 | Line 4170 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
4170    double deltaRLowest = 999;
4171    int value = 0;
4172    if (DeadEcalVec.size() == 0) WriteDeadEcal();
4173 <  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4173 >  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4174      double eta = ecal->etaEcal;
4175      double phi = ecal->phiEcal;
4176 <    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
4176 >    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
4177      if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
4178    }
4179    if (deltaRLowest<0.05) {value = 1;}
# Line 2753 | Line 4181 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
4181    return value;
4182   }
4183  
4184 <
2757 < // Returns the smallest DeltaR between the object and any generated true particle in the event.  
4184 > // Returns the smallest DeltaR between the object and any generated true particle in the event.
4185   template <class InputObject>
4186   double OSUAnalysis::getGenDeltaRLowest(InputObject object){
4187    double genDeltaRLowest = 999.;
4188    for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4189      double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
4190      if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
4191 < }
4191 >  }
4192    return genDeltaRLowest;
4193   }
4194  
2768
4195   double
4196   OSUAnalysis::applyFunction(string function, double value){
4197  
# Line 2775 | Line 4201 | OSUAnalysis::applyFunction(string functi
4201    else if(function == "log") value = log10(value);
4202  
4203    else if(function == "") value = value;
4204 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
4204 >  else{clog << "WARNING: invalid function '" << function << "'\n";}
4205  
4206    return value;
4207  
# Line 2785 | Line 4211 | OSUAnalysis::applyFunction(string functi
4211   template <class InputCollection>
4212   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
4213  
4214 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
4215 +    string obj1, obj2;
4216 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
4217 +    if (inputType==obj1 ||
4218 +        inputType==obj2) {
4219 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
4220 +      // and the inputType is a member of the pair.
4221 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
4222 +      // For example, if currentCut.inputCollection==electron-muon pairs,
4223 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
4224 +      return;
4225 +    }
4226 +  }
4227  
4228    for (uint object = 0; object != inputCollection->size(); object++){
4229  
4230 <
4231 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
2793 <
4230 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4231 >    bool plotDecision = true;
4232  
4233      if(currentCut.inputCollection == inputType){
4234  
4235        vector<bool> subcutDecisions;
4236        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4237 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4238 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4237 >        string stringValue = "";
4238 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4239 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4240 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4241 >
4242        }
4243 <      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4243 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4244        else{
4245          bool tempDecision = true;
4246          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
# Line 2808 | Line 4249 | void OSUAnalysis::setObjectFlags(cut &cu
4249            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4250              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4251          }
4252 <        decision = tempDecision;
4252 >        cutDecision = tempDecision;
4253        }
4254 +      //invert the cut for plotting if this cut is a veto
4255 +      if(currentCut.isVeto) plotDecision = !cutDecision;
4256 +      else plotDecision = cutDecision;
4257      }
2814    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4258  
4259 +    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4260  
4261 <    //set flags for objects that pass each cut AND all the previous cuts
4262 <    bool previousCumulativeFlag = true;
4261 >    //set flags for objects that pass this cut AND all the previous cuts
4262 >    bool previousCumulativeCutFlag = true;
4263      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4264 <      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4265 <      else{ previousCumulativeFlag = false; break;}
4264 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4265 >      else{ previousCumulativeCutFlag = false; break;}
4266      }
4267 <    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4267 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4268 >    bool previousCumulativePlotFlag = true;
4269 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4270 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4271 >      else{ previousCumulativePlotFlag = false; break;}
4272 >    }
4273 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4274  
4275 +    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4276  
4277    }
4278  
# Line 2830 | Line 4281 | void OSUAnalysis::setObjectFlags(cut &cu
4281  
4282   template <class InputCollection1, class InputCollection2>
4283   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
4284 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
4284 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, string inputType){
4285  
4286  
4287    bool sameObjects = false;
4288    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4289  
4290 +  // Get the strings for the two objects that make up the pair.
4291 +  string obj1Type, obj2Type;
4292 +  getTwoObjs(inputType, obj1Type, obj2Type);
4293 +  bool isTwoTypesOfObject = true;
4294 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
4295 +
4296 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
4297 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4298 +  if (currentCut.inputCollection == inputType) {
4299 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4300 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4301 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4302 +    }
4303 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4304 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4305 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4306 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4307 +      }
4308 +    }
4309 +  }
4310  
4311    int counter = 0;
4312 +
4313    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4314      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4315  
4316        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4317  
4318  
4319 <      bool decision = true;//object passes if this cut doesn't cut on that type of object
4319 >      bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4320 >      bool plotDecision = true;
4321  
4322        if(currentCut.inputCollection == inputType){
4323  
4324          vector<bool> subcutDecisions;
4325          for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4326 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4327 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4326 >          string stringValue = "";
4327 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4328 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4329 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4330          }
4331  
4332 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4332 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4333          else{
4334            bool tempDecision = subcutDecisions.at(0);
4335            for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
# Line 2863 | Line 4338 | void OSUAnalysis::setObjectFlags(cut &cu
4338              else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4339                tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4340            }
4341 <          decision = tempDecision;
4341 >          cutDecision = tempDecision;
4342          }
4343 +        //invert the cut for plotting if this cut is a veto
4344 +        if(currentCut.isVeto) plotDecision = !cutDecision;
4345 +        else plotDecision = cutDecision;
4346 +      }
4347 +      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4348 +      if (cutDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4349 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4350 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4351 +      }
4352 +      if (plotDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4353 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4354 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4355 +      }
4356 +
4357 +      //set flags for objects that pass this cut AND all the previous cuts
4358 +      bool previousCumulativeCutFlag = true;
4359 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4360 +        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4361 +        else{ previousCumulativeCutFlag = false; break;}
4362        }
4363 <      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4363 >      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4364  
4365 <      //set flags for objects that pass each cut AND all the previous cuts
2872 <      bool previousCumulativeFlag = true;
4365 >      bool previousCumulativePlotFlag = true;
4366        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4367 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
4368 <        else{ previousCumulativeFlag = false; break;}
4367 >        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4368 >        else{ previousCumulativePlotFlag = false; break;}
4369        }
4370 +      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4371 +      
4372        //apply flags for the components of the composite object as well
4373 <      bool currentCumulativeFlag = true;
4374 <      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
4375 <      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
4376 <      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
4377 <      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
4378 <      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
4373 >      bool currentCumulativeCutFlag = true;
4374 >      bool currentCumulativePlotFlag = true;
4375 >
4376 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4377 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4378 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4379 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4380 >
4381 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4382 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4383 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4384 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4385 >
4386 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));
4387 >
4388 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4389 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4390 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4391 >      }
4392 >
4393 >      if (currentCumulativePlotFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4394 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4395 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4396 >      }
4397  
4398        counter++;
2886    }
4399  
4400 +    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4401 +  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4402 +
4403 + }
4404 +
4405 +
4406 + bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4407 +  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4408 +  // all cuts up to currentCutIndex
4409 +  bool previousCumulativeFlag = true;
4410 +  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4411 +    bool tempFlag = false;
4412 +    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4413 +    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4414 +
4415 +    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4416 +    else {
4417 +      previousCumulativeFlag = false; break;
4418 +    }
4419    }
4420 +  return previousCumulativeFlag;
4421 + }
4422 +
4423  
4424  
4425 +
4426 + template <class InputCollection>
4427 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4428 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4429 +
4430 +  if (BNTreeBranchVals_.count(parameters.name)==0) clog << "Error[assignTreeBranch]:  trying to assign value to " << parameters.name << " that does not have a branch set up.  Will likely seg fault." << endl;
4431 +  for (uint object = 0; object != inputCollection->size(); object++) {
4432 +
4433 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4434 +
4435 +    string inputVariable = parameters.inputVariable;
4436 +    string function = "";
4437 +    string stringValue = "";
4438 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4439 +    BNTreeBranchVals_.at(parameters.name).push_back(value);
4440 +
4441 +  }
4442   }
4443  
4444  
4445   template <class InputCollection>
4446 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4446 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4447 >
4448  
4449    for (uint object = 0; object != inputCollection->size(); object++){
4450  
4451 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4451 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4452  
4453      string currentString = parameters.inputVariables.at(0);
4454      string inputVariable = "";
4455      string function = "";
4456 <    if(currentString.find("(")==std::string::npos){
4456 >    if(currentString.find("(")==string::npos){
4457        inputVariable = currentString;// variable to cut on
4458      }
4459      else{
# Line 2910 | Line 4462 | void OSUAnalysis::fill1DHistogram(TH1* h
4462        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4463      }
4464  
4465 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
4465 >    string stringValue = "";
4466 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4467      histo->Fill(value,scaleFactor);
4468  
4469      if (printEventInfo_) {
4470 <      // Write information about event to screen, for testing purposes.  
4471 <      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;  
4470 >      // Write information about event to screen, for testing purposes.
4471 >      clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
4472      }
4473 <    
4473 >
4474    }
4475   }
4476  
4477   template <class InputCollection1, class InputCollection2>
4478 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4478 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4479  
4480    bool sameObjects = false;
4481    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4482  
4483 <  int pairCounter = 0;
4483 >  int pairCounter = -1;
4484    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4485      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4486  
4487        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4488  
4489 +      pairCounter++;
4490        //only take objects which have passed all cuts and pairs which have passed all cuts
4491 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4492 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4493 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4491 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4492 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4493 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4494  
4495        string currentString = parameters.inputVariables.at(0);
4496        string inputVariable = "";
4497        string function = "";
4498 <      if(currentString.find("(")==std::string::npos){
4498 >      if(currentString.find("(")==string::npos){
4499          inputVariable = currentString;// variable to cut on
4500        }
4501        else{
# Line 2950 | Line 4504 | void OSUAnalysis::fill1DHistogram(TH1* h
4504          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4505        }
4506  
4507 <      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4507 >      string stringValue = "";
4508 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4509        histo->Fill(value,scaleFactor);
4510  
2956      pairCounter++;
4511      }
4512    }
4513  
# Line 2961 | Line 4515 | void OSUAnalysis::fill1DHistogram(TH1* h
4515  
4516  
4517   template <class InputCollection>
4518 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4518 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4519  
4520    for (uint object = 0; object != inputCollection->size(); object++){
4521  
4522 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4522 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4523  
4524 +    string stringValue = "";
4525      string currentString = parameters.inputVariables.at(0);
4526      string inputVariable = "";
4527      string function = "";
4528 <    if(currentString.find("(")==std::string::npos){
4528 >    if(currentString.find("(")==string::npos){
4529        inputVariable = currentString;// variable to cut on
4530      }
4531      else{
# Line 2978 | Line 4533 | void OSUAnalysis::fill2DHistogram(TH2* h
4533        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4534        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4535      }
4536 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
4536 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4537  
4538      currentString = parameters.inputVariables.at(1);
4539      inputVariable = "";
4540      function = "";
4541 <    if(currentString.find("(")==std::string::npos){
4541 >    if(currentString.find("(")==string::npos){
4542        inputVariable = currentString;// variable to cut on
4543      }
4544      else{
# Line 2992 | Line 4547 | void OSUAnalysis::fill2DHistogram(TH2* h
4547        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4548      }
4549  
4550 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
4550 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4551  
4552      histo->Fill(valueX,valueY,scaleFactor);
4553  
# Line 3001 | Line 4556 | void OSUAnalysis::fill2DHistogram(TH2* h
4556   }
4557  
4558   template <class InputCollection1, class InputCollection2>
4559 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4559 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4560  
4561    bool sameObjects = false;
4562    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4563  
4564 <  int pairCounter = 0;
4564 >  int pairCounter = -1;
4565    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4566      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4567  
4568        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4569  
4570 +      pairCounter++;
4571 +
4572        //only take objects which have passed all cuts and pairs which have passed all cuts
4573 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4574 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4575 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4573 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4574 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4575 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4576  
4577 +      string stringValue = "";
4578        string currentString = parameters.inputVariables.at(0);
4579        string inputVariable = "";
4580        string function = "";
4581 <      if(currentString.find("(")==std::string::npos){
4581 >      if(currentString.find("(")==string::npos){
4582          inputVariable = currentString;// variable to cut on
4583        }
4584        else{
# Line 3028 | Line 4586 | void OSUAnalysis::fill2DHistogram(TH2* h
4586          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4587          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4588        }
4589 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4589 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4590  
4591        currentString = parameters.inputVariables.at(1);
4592        inputVariable = "";
4593        function = "";
4594 <      if(currentString.find("(")==std::string::npos){
4594 >      if(currentString.find("(")==string::npos){
4595          inputVariable = currentString;// variable to cut on
4596        }
4597        else{
# Line 3041 | Line 4599 | void OSUAnalysis::fill2DHistogram(TH2* h
4599          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4600          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4601        }
4602 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4602 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4603  
4604  
4605        histo->Fill(valueX,valueY,scaleFactor);
4606  
3049      pairCounter++;
3050
4607      }
4608    }
4609  
# Line 3064 | Line 4620 | int OSUAnalysis::getGenMatchedParticleIn
4620  
4621      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4622      if(currentDeltaR > 0.05) continue;
4623 < //     cout << std::setprecision(3) << std::setw(20)
4624 < //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4625 < //          << std::setw(20)
4626 < //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4627 < //          << std::setw(20)
4628 < //          << "\tdeltaR = " << currentDeltaR
4629 < //          << std::setprecision(1)
4630 < //          << std::setw(20)
4631 < //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4632 < //          << std::setw(20)
4633 < //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4634 < //          << std::setw(20)
4635 < //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4623 >    //     clog << setprecision(3) << setw(20)
4624 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4625 >    //          << setw(20)
4626 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4627 >    //          << setw(20)
4628 >    //          << "\tdeltaR = " << currentDeltaR
4629 >    //          << setprecision(1)
4630 >    //          << setw(20)
4631 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4632 >    //          << setw(20)
4633 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4634 >    //          << setw(20)
4635 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4636      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4637        bestMatchIndex = mcparticle - mcparticles->begin();
4638        bestMatchDeltaR = currentDeltaR;
4639      }
4640  
4641    }
4642 < //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4643 < //   else cout << "no match found..." << endl;
4642 >  //   if(bestMatchDeltaR != 999)  clog << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4643 >  //   else clog << "no match found..." << endl;
4644    return bestMatchIndex;
4645  
4646   }
# Line 3138 | Line 4694 | int OSUAnalysis::findTauMotherIndex(cons
4694   // 20        strange baryon
4695   // 21        charm baryon
4696   // 22        bottom baryon
4697 < // 23        other
4697 > // 23        QCD string
4698 > // 24        other
4699  
4700   int OSUAnalysis::getPdgIdBinValue(int pdgId){
4701  
# Line 3162 | Line 4719 | int OSUAnalysis::getPdgIdBinValue(int pd
4719    else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4720    else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4721    else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4722 +  else if(absPdgId == 92  ) binValue = 23;
4723  
4724 <  else binValue = 23;
4724 >  else binValue = 24;
4725  
4726    return binValue;
4727  
# Line 3173 | Line 4731 | const BNprimaryvertex *
4731   OSUAnalysis::chosenVertex ()
4732   {
4733    const BNprimaryvertex *chosenVertex = 0;
4734 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
4735 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
4736 <                               cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
4734 >  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4735 >    flagPair vertexFlags;
4736 >    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4737 >      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4738 >        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4739 >        break;
4740 >      }
4741 >    }
4742      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4743 <      if(!vertexFlags.at(vertexIndex)) continue;
4743 >      if(!vertexFlags.at(vertexIndex).first) continue;
4744        chosenVertex = & primaryvertexs->at(vertexIndex);
4745        break;
4746      }
4747    }
4748 <  else {
4749 <    chosenVertex = &primaryvertexs->at(0);
3187 <  }
4748 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4749 >    chosenVertex = & primaryvertexs->at (0);
4750  
4751    return chosenVertex;
4752   }
# Line 3193 | Line 4755 | const BNmet *
4755   OSUAnalysis::chosenMET ()
4756   {
4757    const BNmet *chosenMET = 0;
4758 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
4759 <    vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
4760 <                            cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
4758 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4759 >    flagPair metFlags;
4760 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4761 >      if (cumulativeFlags.at("mets").at(i).size()){
4762 >        metFlags = cumulativeFlags.at("mets").at(i);
4763 >        break;
4764 >      }
4765 >    }
4766      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4767 <      if(!metFlags.at(metIndex)) continue;
4767 >      if(!metFlags.at(metIndex).first) continue;
4768        chosenMET = & mets->at(metIndex);
4769        break;
4770      }
4771    }
4772 <  else {
4773 <    chosenMET = &mets->at(0);
3207 <  }
4772 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4773 >    chosenMET = & mets->at (0);
4774  
4775    return chosenMET;
4776   }
# Line 3213 | Line 4779 | const BNelectron *
4779   OSUAnalysis::chosenElectron ()
4780   {
4781    const BNelectron *chosenElectron = 0;
4782 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
4783 <    vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
4784 <                                 cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
4782 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4783 >    flagPair electronFlags;
4784 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4785 >      if (cumulativeFlags.at("electrons").at(i).size()){
4786 >        electronFlags = cumulativeFlags.at("electrons").at(i);
4787 >        break;
4788 >      }
4789 >    }
4790      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4791 <      if(!electronFlags.at(electronIndex)) continue;
4791 >      if(!electronFlags.at(electronIndex).first) continue;
4792        chosenElectron = & electrons->at(electronIndex);
4793        break;
4794      }
4795    }
4796 <  else {
4797 <    chosenElectron = &electrons->at(0);
3227 <  }
4796 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4797 >    chosenElectron = & electrons->at (0);
4798  
4799    return chosenElectron;
4800   }
4801  
4802 +
4803   const BNmuon *
4804   OSUAnalysis::chosenMuon ()
4805   {
4806    const BNmuon *chosenMuon = 0;
4807 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
4808 <    vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
4809 <                             cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
4807 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4808 >    flagPair muonFlags;
4809 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4810 >      if (cumulativeFlags.at("muons").at(i).size()){
4811 >        muonFlags = cumulativeFlags.at("muons").at(i);
4812 >        break;
4813 >      }
4814 >    }
4815      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4816 <      if(!muonFlags.at(muonIndex)) continue;
4816 >      if(!muonFlags.at(muonIndex).first) continue;
4817        chosenMuon = & muons->at(muonIndex);
4818        break;
4819      }
4820    }
4821 <  else {
4822 <    chosenMuon = &muons->at(0);
3247 <  }
4821 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4822 >    chosenMuon = & muons->at (0);
4823  
4824    return chosenMuon;
4825   }
4826  
4827 + double
4828 + OSUAnalysis::chosenHT ()
4829 + {
4830 +  double chosenHT = 0.0;
4831 +  if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
4832 +    flagPair jetFlags;
4833 +    for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
4834 +      if (cumulativeFlags.at("jets").at(i).size()){
4835 +        jetFlags = cumulativeFlags.at("jets").at(i);
4836 +        break;
4837 +      }
4838 +    }
4839 +    for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
4840 +      if(!jetFlags.at(jetIndex).first) continue;
4841 +      chosenHT += jets->at(jetIndex).pt;
4842 +    }
4843 +  }
4844 +
4845 +  return chosenHT;
4846 + }
4847 +
4848 + pair<const BNmuon *, const BNmuon *>
4849 + OSUAnalysis::leadMuonPair ()
4850 + {
4851 +  pair<const BNmuon *, const BNmuon *> leadMuonPair;
4852 +  leadMuonPair.first = leadMuonPair.second = 0;
4853 +
4854 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4855 +    flagPair muonFlags;
4856 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4857 +      if (cumulativeFlags.at("muons").at(i).size()){
4858 +        muonFlags = cumulativeFlags.at("muons").at(i);
4859 +        break;
4860 +      }
4861 +    }
4862 +    for (uint muonIndex0 = 0; muonIndex0 != muonFlags.size(); muonIndex0++){
4863 +      if(!muonFlags.at(muonIndex0).first) continue;
4864 +      for (uint muonIndex1 = muonIndex0 + 1; muonIndex1 < muonFlags.size(); muonIndex1++){
4865 +        if(!muonFlags.at(muonIndex1).first) continue;
4866 +        const BNmuon *mu0 = & muons->at(muonIndex0);
4867 +        const BNmuon *mu1 = & muons->at(muonIndex1);
4868 +        if(leadMuonPair.first == 0 || leadMuonPair.second == 0){
4869 +          leadMuonPair.first = mu0;
4870 +          leadMuonPair.second = mu1;
4871 +        }
4872 +        else{
4873 +          TVector2 newPt0 (mu0->px, mu0->py),
4874 +                   newPt1 (mu1->px, mu1->py),
4875 +                   oldPt0 (leadMuonPair.first->px, leadMuonPair.first->py),
4876 +                   oldPt1 (leadMuonPair.second->px, leadMuonPair.second->py);
4877 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
4878 +            {
4879 +              leadMuonPair.first = mu0;
4880 +              leadMuonPair.second = mu1;
4881 +            }
4882 +        }
4883 +      }
4884 +    }
4885 +  }
4886 +
4887 +  return leadMuonPair;
4888 + }
4889 +
4890 + pair<const BNelectron *, const BNelectron *>
4891 + OSUAnalysis::leadElectronPair ()
4892 + {
4893 +  pair<const BNelectron *, const BNelectron *> leadElectronPair;
4894 +  leadElectronPair.first = leadElectronPair.second = 0;
4895 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4896 +    flagPair electronFlags;
4897 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4898 +      if (cumulativeFlags.at("electrons").at(i).size()){
4899 +        electronFlags = cumulativeFlags.at("electrons").at(i);
4900 +        break;
4901 +      }
4902 +    }
4903 +    for (uint electronIndex0 = 0; electronIndex0 != electronFlags.size(); electronIndex0++){
4904 +      if(!electronFlags.at(electronIndex0).first) continue;
4905 +      for (uint electronIndex1 = electronIndex0 + 1; electronIndex1 < electronFlags.size(); electronIndex1++){
4906 +        if(!electronFlags.at(electronIndex1).first) continue;
4907 +        const BNelectron *el0 = & electrons->at(electronIndex0);
4908 +        const BNelectron *el1 = & electrons->at(electronIndex1);
4909 +        if(leadElectronPair.first == 0 || leadElectronPair.second == 0){
4910 +          leadElectronPair.first = el0;
4911 +          leadElectronPair.second = el1;
4912 +        }
4913 +        else{
4914 +          TVector2 newPt0 (el0->px, el0->py),
4915 +                   newPt1 (el1->px, el1->py),
4916 +                   oldPt0 (leadElectronPair.first->px, leadElectronPair.first->py),
4917 +                   oldPt1 (leadElectronPair.second->px, leadElectronPair.second->py);
4918 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
4919 +            {
4920 +              leadElectronPair.first = el0;
4921 +              leadElectronPair.second = el1;
4922 +            }
4923 +        }
4924 +      }
4925 +    }
4926 +  }
4927 +
4928 +  return leadElectronPair;
4929 + }
4930  
4931   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines