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.42 by wulsin, Wed Mar 27 22:38:08 2013 UTC vs.
Revision 1.89 by wulsin, Tue Jun 25 09:35:49 2013 UTC

# Line 11 | Line 11 | OSUAnalysis::OSUAnalysis (const edm::Par
11    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
12    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
13    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
14 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
15    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
16    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
17    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
18    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
19    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
20 <  puFile_ (cfg.getParameter<std::string> ("puFile")),
21 <  deadEcalFile_ (cfg.getParameter<std::string> ("deadEcalFile")),
22 <  muonSFFile_ (cfg.getParameter<std::string> ("muonSFFile")),
23 <  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
24 <  electronSFID_ (cfg.getParameter<std::string> ("electronSFID")),
25 <  muonSF_ (cfg.getParameter<std::string> ("muonSF")),
26 <  dataset_ (cfg.getParameter<std::string> ("dataset")),
27 <  datasetType_ (cfg.getParameter<std::string> ("datasetType")),
20 >  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
21 >  puFile_ (cfg.getParameter<string> ("puFile")),
22 >  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
23 >  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
24 >  dataPU_ (cfg.getParameter<string> ("dataPU")),
25 >  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
26 >  muonSF_ (cfg.getParameter<string> ("muonSF")),
27 >  dataset_ (cfg.getParameter<string> ("dataset")),
28 >  datasetType_ (cfg.getParameter<string> ("datasetType")),
29    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
30    histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
31 +  useEDMFormat_   (cfg.getParameter<bool>("useEDMFormat")),
32 +  treeBranchSets_   (cfg.getParameter<vector<edm::ParameterSet> >("treeBranchSets")),
33    plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
34    doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
35 <  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
36 <  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr"))
37 <
38 < {
35 >  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
36 >  applyBtagSF_ (cfg.getParameter<bool> ("applyBtagSF")),
37 >  minBtag_ (cfg.getParameter<int> ("minBtag")),
38 >  maxBtag_ (cfg.getParameter<int> ("maxBtag")),
39 >  printEventInfo_      (cfg.getParameter<bool> ("printEventInfo")),
40 >  printAllTriggers_    (cfg.getParameter<bool> ("printAllTriggers")),
41 >  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
42 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
43 >  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
44 > {
45  
46    TH1::SetDefaultSumw2 ();
47  
48    //create pile-up reweighting object, if necessary
49    if(datasetType_ != "data") {
50      if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
51 <    //    muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
52 <    //    electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
51 >    if (applyLeptonSF_){
52 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
53 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
54 >    }
55 >    if (applyBtagSF_){
56 >      bTagSFWeight_ = new BtagSFWeight;
57 >    }
58    }
59 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
60 +    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
61  
62  
63    // Construct Cutflow Objects. These store the results of cut decisions and
64    // handle filling cut flow histograms.
65    masterCutFlow_ = new CutFlow (fs_);
49  std::vector<TFileDirectory> directories;
66  
67    //always get vertex collection so we can assign the primary vertex in the event
68    objectsToGet.push_back("primaryvertexs");
53
54  //always make the plot of number of primary verticex (to check pile-up reweighting)
69    objectsToPlot.push_back("primaryvertexs");
70 +  objectsToCut.push_back("primaryvertexs");
71 +
72  
73    //always get the MC particles to do GEN-matching
74    objectsToGet.push_back("mcparticles");
# Line 60 | Line 76 | OSUAnalysis::OSUAnalysis (const edm::Par
76    //always get the event collection to do pile-up reweighting
77    objectsToGet.push_back("events");
78  
79 +
80 +  // Parse the tree variable definitions.
81 +  for (uint iBranchSet = 0; !useEDMFormat_ && iBranchSet<treeBranchSets_.size(); iBranchSet++) {
82 +    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
83 +    if(tempInputCollection.find("pairs")!=string::npos) { cout << "Warning:  tree filling is not configured for pairs of objects, so will not work for collection: " << tempInputCollection << endl; }
84 +    objectsToGet.push_back(tempInputCollection);
85 +    objectsToCut.push_back(tempInputCollection);
86 +
87 +    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
88 +
89 +    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
90 +      BranchSpecs br;
91 +      br.inputCollection = tempInputCollection;
92 +      br.inputVariable = branchList.at(iBranch);
93 +      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);
94 +      br.name = string(newName.Data());
95 +      treeBranches_.push_back(br);
96 +    }
97 +
98 +  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++)
99 +
100 +
101    //parse the histogram definitions
102    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
103  
104      string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
105      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
106 +    if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
107 +    if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
108 +    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
109 +    if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
110 +    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
111 +    if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
112      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
113 <    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
114 <      objectsToGet.push_back(tempInputCollection);
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 jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
116 >    if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
117 >    if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
118 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
119 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
120 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
121 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
122 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
123 >        int spaceIndex = tempInputCollection.find(" ");
124 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
125 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
126 >      }
127 >      else{
128 >        objectsToGet.push_back(tempInputCollection);
129 >      }
130        objectsToPlot.push_back(tempInputCollection);
131        objectsToCut.push_back(tempInputCollection);
132 <    }
133 <    else{//pair of objects, need to add them both to the things to objectsToGet
134 <      int dashIndex = tempInputCollection.find("-");
135 <      int spaceIndex = tempInputCollection.find(" ");
136 <      int secondWordLength = spaceIndex - dashIndex;
78 <      objectsToGet.push_back(tempInputCollection);
79 <      objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
80 <      objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
81 <      objectsToPlot.push_back(tempInputCollection);
82 <      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
83 <      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
132 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
133 >      string obj1;
134 >      string obj2;
135 >      getTwoObjs(tempInputCollection, obj1, obj2);
136 >      string obj2ToGet = getObjToGet(obj2);
137        objectsToCut.push_back(tempInputCollection);
138 <      objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
139 <      objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
138 >      objectsToCut.push_back(obj1);
139 >      objectsToCut.push_back(obj2);
140 >      objectsToPlot.push_back(tempInputCollection);
141 >      objectsToPlot.push_back(obj1);
142 >      objectsToPlot.push_back(obj2);
143 >      objectsToGet.push_back(tempInputCollection);
144 >      objectsToGet.push_back(obj1);
145 >      objectsToGet.push_back(obj2ToGet);
146 >    } // end else
147 >
148  
88      }
149  
150      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
151  
152      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
153  
154 +      vector<double> defaultValue;
155 +      defaultValue.push_back (-1.0);
156 +
157        histogram tempHistogram;
158        tempHistogram.inputCollection = tempInputCollection;
159        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
160        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
161 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
161 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
162 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
163 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
164        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
165  
166        histograms.push_back(tempHistogram);
167  
168      }
169 <  }
169 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
170 >
171    //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
172    sort( objectsToPlot.begin(), objectsToPlot.end() );
173    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
# Line 112 | Line 178 | OSUAnalysis::OSUAnalysis (const edm::Par
178    for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
179  
180      string currentObject = objectsToPlot.at(currentObjectIndex);
181 <    if(currentObject != "muons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
181 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
182  
183      histogram tempIdHisto;
184      histogram tempMomIdHisto;
185      histogram tempGmaIdHisto;
186      histogram tempIdVsMomIdHisto;
187 +    histogram tempIdVsGmaIdHisto;
188  
189      tempIdHisto.inputCollection = currentObject;
190      tempMomIdHisto.inputCollection = currentObject;
191      tempGmaIdHisto.inputCollection = currentObject;
192      tempIdVsMomIdHisto.inputCollection = currentObject;
193 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
194 +
195 +    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
196 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
197  
198      currentObject = currentObject.substr(0, currentObject.size()-1);
199      tempIdHisto.name = currentObject+"GenMatchId";
200      tempMomIdHisto.name = currentObject+"GenMatchMotherId";
201      tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
202      tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
203 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
204  
205      currentObject.at(0) = toupper(currentObject.at(0));
206      tempIdHisto.title = currentObject+" Gen-matched Particle";
207      tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
208      tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
209      tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
210 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
211 +
212  
213 <    int maxNum = 24;
213 >    int maxNum = 25;
214      vector<double> binVector;
215      binVector.push_back(maxNum);
216      binVector.push_back(0);
# Line 154 | Line 228 | OSUAnalysis::OSUAnalysis (const edm::Par
228      tempIdVsMomIdHisto.bins = binVector;
229      tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
230      tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
231 +    tempIdVsGmaIdHisto.bins = binVector;
232 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
233 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
234  
235      histograms.push_back(tempIdHisto);
236      histograms.push_back(tempMomIdHisto);
237      histograms.push_back(tempGmaIdHisto);
238      histograms.push_back(tempIdVsMomIdHisto);
239 +    histograms.push_back(tempIdVsGmaIdHisto);
240    }
241  
242  
# Line 174 | Line 252 | OSUAnalysis::OSUAnalysis (const edm::Par
252      //set triggers for this channel
253      vector<string> triggerNames;
254      triggerNames.clear();
255 +    vector<string> triggerToVetoNames;
256 +    triggerToVetoNames.clear();
257 +
258      tempChannel.triggers.clear();
259 +    tempChannel.triggersToVeto.clear();
260      if(channels_.at(currentChannel).exists("triggers")){
261        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
262        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
263          tempChannel.triggers.push_back(triggerNames.at(trigger));
264        objectsToGet.push_back("triggers");
265      }
266 <
266 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
267 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
268 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
269 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
270 >      objectsToGet.push_back("triggers");
271 >    }
272  
273  
274  
275      //create cutFlow for this channel
276      cutFlows_.push_back (new CutFlow (fs_, channelName));
277 <
278 <    //book a directory in the output file with the name of the channel
279 <    TFileDirectory subDir = fs_->mkdir( channelName );
193 <    directories.push_back(subDir);
194 <
195 <    std::map<std::string, TH1D*> oneDhistoMap;
196 <    oneDHists_.push_back(oneDhistoMap);
197 <    std::map<std::string, TH2D*> twoDhistoMap;
198 <    twoDHists_.push_back(twoDhistoMap);
199 <
200 <
201 <
202 <    //book all histograms included in the configuration
203 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
204 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
205 <      int numBinsElements = currentHistogram.bins.size();
206 <      int numInputVariables = currentHistogram.inputVariables.size();
207 <
208 <      if(numBinsElements != 3 && numBinsElements !=6) {
209 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
210 <        exit(0);
211 <      }
212 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
213 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
214 <        exit(0);
215 <      }
216 <      else if(numBinsElements == 3){
217 <        oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
218 <      }
219 <      else if(numBinsElements == 6){
220 <        twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2),currentHistogram.bins.at(3),currentHistogram.bins.at(4),currentHistogram.bins.at(5));
221 <
222 <      }
223 <
224 <
225 <      if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
226 <
227 < // bin      particle type
228 < // ---      -------------
229 < //  0        unmatched
230 < //  1        u
231 < //  2        d
232 < //  3        s
233 < //  4        c
234 < //  5        b
235 < //  6        t
236 < //  7        e
237 < //  8        mu
238 < //  9        tau
239 < // 10        nu
240 < // 11        g
241 < // 12        gamma
242 < // 13        Z
243 < // 14        W
244 < // 15        light meson
245 < // 16        K meson
246 < // 17        D meson
247 < // 18        B meson
248 < // 19        light baryon
249 < // 20        strange baryon
250 < // 21        charm baryon
251 < // 22        bottom baryon
252 < // 23        other
253 <
254 <      vector<TString> labelArray;
255 <      labelArray.push_back("unmatched");
256 <      labelArray.push_back("u");
257 <      labelArray.push_back("d");
258 <      labelArray.push_back("s");
259 <      labelArray.push_back("c");
260 <      labelArray.push_back("b");
261 <      labelArray.push_back("t");
262 <      labelArray.push_back("e");
263 <      labelArray.push_back("#mu");
264 <      labelArray.push_back("#tau");
265 <      labelArray.push_back("#nu");
266 <      labelArray.push_back("g");
267 <      labelArray.push_back("#gamma");
268 <      labelArray.push_back("Z");
269 <      labelArray.push_back("W");
270 <      labelArray.push_back("light meson");
271 <      labelArray.push_back("K meson");
272 <      labelArray.push_back("D meson");
273 <      labelArray.push_back("B meson");
274 <      labelArray.push_back("light baryon");
275 <      labelArray.push_back("strange baryon");
276 <      labelArray.push_back("charm baryon");
277 <      labelArray.push_back("bottom baryon");
278 <      labelArray.push_back("other");
279 <
280 <      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
281 <        if(currentHistogram.name.find("GenMatchIdVsMotherId")==std::string::npos) {
282 <          oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
283 <        }
284 <        else {
285 <          twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
286 <          twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
287 <        }
288 <      }
289 <      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=std::string::npos) {
290 <        twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->CenterTitle();
291 <        twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->CenterTitle();
292 <      }
293 <
294 <    }
295 <
296 <    // Book a histogram for the number of each object type to be plotted.  
297 <    // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().  
298 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
299 <      string currentObject = objectsToPlot.at(currentObjectIndex);
300 <      int maxNum = 10;
301 <      if(currentObject == "mcparticles") maxNum = 50;
302 <      else if(currentObject == "primaryvertexs") maxNum = 50;
303 <      else if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
304 <      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
305 <      else if(currentObject == "electron-muon pairs")     currentObject = "electronMuonPairs";
306 <      else if(currentObject == "track-event pairs")       currentObject = "trackEventPairs";
307 <
308 <      currentObject.at(0) = toupper(currentObject.at(0));
309 <      string histoName = "num" + currentObject;
310 <
311 <      if(histoName == "numPrimaryvertexs"){
312 <        string newHistoName = histoName + "BeforePileupCorrection";
313 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
314 <        newHistoName = histoName + "AfterPileupCorrection";
315 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
316 <      }
317 <      else
318 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
319 <    }
320 <
321 <
322 <
323 <
277 >    vector<TFileDirectory> directories; //vector of directories in the output file.
278 >    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
279 >    vector<string> subSubDirNames;//subdirectories in each channel.
280      //get list of cuts for this channel
281      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
282  
283 +
284      //loop over and parse all cuts
285      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
286        cut tempCut;
287        //store input collection for cut
288        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
289 +      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
290 +      if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
291 +      if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
292 +      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
293 +      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
294 +      if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
295 +      if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
296 +      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
297 +      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
298 +      if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
299 +      if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
300 +      if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
301 +      if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
302 +      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
303 +      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
304 +      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
305        tempCut.inputCollection = tempInputCollection;
306 <      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
307 <        objectsToGet.push_back(tempInputCollection);
306 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
307 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
308 >          int spaceIndex = tempInputCollection.find(" ");
309 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
310 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
311 >        }
312 >        else{
313 >          objectsToGet.push_back(tempInputCollection);
314 >        }
315          objectsToCut.push_back(tempInputCollection);
316        }
317 <      else{//pair of objects, need to add them both to the things to objectsToGet
318 <        int dashIndex = tempInputCollection.find("-");
319 <        int spaceIndex = tempInputCollection.find(" ");
320 <        int secondWordLength = spaceIndex - dashIndex;
321 <        objectsToGet.push_back(tempInputCollection);
342 <        objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
343 <        objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
317 >      else{//pair of objects, need to add them both to objectsToGet
318 >        string obj1;
319 >        string obj2;
320 >        getTwoObjs(tempInputCollection, obj1, obj2);
321 >        string obj2ToGet = getObjToGet(obj2);
322          objectsToCut.push_back(tempInputCollection);
323 <        objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
324 <        objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
323 >        objectsToCut.push_back(obj1);
324 >        objectsToCut.push_back(obj2);
325 >        objectsToGet.push_back(tempInputCollection);
326 >        objectsToGet.push_back(obj1);
327 >        objectsToGet.push_back(obj2ToGet);
328  
329        }
330  
# Line 351 | Line 332 | OSUAnalysis::OSUAnalysis (const edm::Par
332  
333        //split cut string into parts and store them
334        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
335 <      std::vector<string> cutStringVector = splitString(cutString);
335 >      vector<string> cutStringVector = splitString(cutString);
336        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
337 <        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
337 >        cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
338          exit(0);
339        }
340        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
341        for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
342          int indexOffset = 4 * subcutIndex;
343          string currentVariableString = cutStringVector.at(indexOffset);
344 <        if(currentVariableString.find("(")==std::string::npos){
344 >        if(currentVariableString.find("(")==string::npos){
345            tempCut.functions.push_back("");//no function was specified
346            tempCut.variables.push_back(currentVariableString);// variable to cut on
347          }
# Line 371 | Line 352 | OSUAnalysis::OSUAnalysis (const edm::Par
352          }
353          tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
354          tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
355 +        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
356          if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
357        }
358  
359        //get number of objects required to pass cut for event to pass
360        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
361 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
361 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
362        if(numberRequiredVector.size()!=2){
363 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
363 >        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
364          exit(0);
365        }
366  
# Line 386 | Line 368 | OSUAnalysis::OSUAnalysis (const edm::Par
368        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
369        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
370  
371 <
371 >      //Set up vectors to store the directories and subDirectories for each channel.
372 >      string subSubDirName;
373        string tempCutName;
374        if(cuts_.at(currentCut).exists("alias")){
375          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
376 +        subSubDirName = "After " + tempCutName + " Cut Applied";
377        }
378        else{
379          //construct string for cutflow table
# Line 397 | Line 381 | OSUAnalysis::OSUAnalysis (const edm::Par
381          string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
382          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
383          tempCutName = cutName;
384 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
385        }
401      tempCut.name = tempCutName;
386  
387 +      tempCut.isVeto = false;
388 +      if(cuts_.at(currentCut).exists("isVeto")){
389 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
390 +        if (isVeto == true) tempCut.isVeto = true;
391 +      }
392 +      subSubDirNames.push_back(subSubDirName);
393 +      tempCut.name = tempCutName;
394  
395        tempChannel.cuts.push_back(tempCut);
396  
397  
407
398      }//end loop over cuts
399  
400 +    vector<map<string, TH1D*>> oneDHistsTmp;
401 +    vector<map<string, TH2D*>> twoDHistsTmp;
402 +    //book a directory in the output file with the name of the channel
403 +    TFileDirectory subDir = fs_->mkdir( channelName );
404 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
405 +    if(GetPlotsAfterEachCut_){
406 +      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
407 +        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
408 +        directories.push_back(subSubDir);
409 +        map<string, TH1D*> oneDhistoMap;
410 +        oneDHistsTmp.push_back(oneDhistoMap);
411 +        map<string, TH2D*> twoDhistoMap;
412 +        twoDHistsTmp.push_back(twoDhistoMap);
413 +      }
414 +      treeDirectories.push_back(subDir);
415 +      oneDHists_.push_back(oneDHistsTmp);
416 +      twoDHists_.push_back(twoDHistsTmp);
417 +    }
418 +    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
419 +    else{
420 +      map<string, TH1D*> oneDhistoMap;
421 +      oneDHistsTmp.push_back(oneDhistoMap);
422 +      map<string, TH2D*> twoDhistoMap;
423 +      twoDHistsTmp.push_back(twoDhistoMap);
424 +      oneDHists_.push_back(oneDHistsTmp);
425 +      twoDHists_.push_back(twoDHistsTmp);
426 +      directories.push_back(subDir);
427 +      treeDirectories.push_back(subDir);
428 +
429 +    }
430 +
431 +    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
432 +      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
433 +      BNTrees_.push_back(newTree);
434 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
435 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
436 +        vector<float> newVec;
437 +        BNTreeBranchVals_[currentVar.name] = newVec;
438 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
439 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
440 +    }
441 +
442 +    //book all histograms included in the configuration
443 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
444 +
445 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
446 +
447 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
448 +        int numBinsElements = currentHistogram.bins.size();
449 +        int numInputVariables = currentHistogram.inputVariables.size();
450 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
451 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
452 +
453 +        if(numBinsElements == 1){
454 +          if(numBinEdgesX > 1){
455 +            if(numBinEdgesY > 1)
456 +              numBinsElements = 6;
457 +            else
458 +              numBinsElements = 3;
459 +          }
460 +        }
461 +        if(numBinsElements != 3 && numBinsElements !=6){
462 +          cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
463 +          exit(0);
464 +        }
465 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
466 +          cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
467 +          exit(0);
468 +        }
469 +        else if(numBinsElements == 3){
470 +          if (currentHistogram.bins.size () == 3)
471 +            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));
472 +          else
473 +            {
474 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
475 +            }
476 +        }
477 +        else if(numBinsElements == 6){
478 +          if (currentHistogram.bins.size () == 6)
479 +            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));
480 +          else
481 +            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 ());
482 +        }
483 +
484 +
485 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
486 +
487 +        // bin      particle type
488 +        // ---      -------------
489 +        //  0        unmatched
490 +        //  1        u
491 +        //  2        d
492 +        //  3        s
493 +        //  4        c
494 +        //  5        b
495 +        //  6        t
496 +        //  7        e
497 +        //  8        mu
498 +        //  9        tau
499 +        // 10        nu
500 +        // 11        g
501 +        // 12        gamma
502 +        // 13        Z
503 +        // 14        W
504 +        // 15        light meson
505 +        // 16        K meson
506 +        // 17        D meson
507 +        // 18        B meson
508 +        // 19        light baryon
509 +        // 20        strange baryon
510 +        // 21        charm baryon
511 +        // 22        bottom baryon
512 +        // 23        QCD string
513 +        // 24        other
514 +
515 +        vector<TString> labelArray;
516 +        labelArray.push_back("unmatched");
517 +        labelArray.push_back("u");
518 +        labelArray.push_back("d");
519 +        labelArray.push_back("s");
520 +        labelArray.push_back("c");
521 +        labelArray.push_back("b");
522 +        labelArray.push_back("t");
523 +        labelArray.push_back("e");
524 +        labelArray.push_back("#mu");
525 +        labelArray.push_back("#tau");
526 +        labelArray.push_back("#nu");
527 +        labelArray.push_back("g");
528 +        labelArray.push_back("#gamma");
529 +        labelArray.push_back("Z");
530 +        labelArray.push_back("W");
531 +        labelArray.push_back("light meson");
532 +        labelArray.push_back("K meson");
533 +        labelArray.push_back("D meson");
534 +        labelArray.push_back("B meson");
535 +        labelArray.push_back("light baryon");
536 +        labelArray.push_back("strange baryon");
537 +        labelArray.push_back("charm baryon");
538 +        labelArray.push_back("bottom baryon");
539 +        labelArray.push_back("QCD string");
540 +        labelArray.push_back("other");
541 +
542 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
543 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
544 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
545 +          }
546 +          else {
547 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
548 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
549 +          }
550 +        }
551 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
552 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
553 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
554 +        }
555 +
556 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
557 +
558 +
559 +      // Book a histogram for the number of each object type to be plotted.
560 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
561 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
562 +        string currentObject = objectsToPlot.at(currentObjectIndex);
563 +        int maxNum = 10;
564 +        if(currentObject == "mcparticles") maxNum = 50;
565 +        else if(currentObject == "primaryvertexs") maxNum = 50;
566 +
567 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
568 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
569 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
570 +        else if(currentObject == "electron-photon pairs")     currentObject = "electronPhotonPairs";
571 +        else if(currentObject == "muon-photon pairs")         currentObject = "muonPhotonPairs";
572 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
573 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
574 +        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
575 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
576 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
577 +        else if(currentObject == "photon-jet pairs")          currentObject = "photonJetPairs";
578 +        else if(currentObject == "met-jet pairs")             currentObject = "metJetPairs";
579 +        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
580 +        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
581 +        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
582 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
583 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
584 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
585 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
586 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
587 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
588 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
589 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
590 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
591 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
592 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
593 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
594 +
595 +        currentObject.at(0) = toupper(currentObject.at(0));
596 +        string histoName = "num" + currentObject;
597 +
598 +        if(histoName == "numPrimaryvertexs"){
599 +          string newHistoName = histoName + "BeforePileupCorrection";
600 +          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);
601 +          newHistoName = histoName + "AfterPileupCorrection";
602 +          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);
603 +        }
604 +        else
605 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
606 +      }
607 +    }//end of loop over directories
608      channels.push_back(tempChannel);
609      tempChannel.cuts.clear();
412
610    }//end loop over channels
611  
612  
# Line 420 | Line 617 | OSUAnalysis::OSUAnalysis (const edm::Par
617    sort( objectsToCut.begin(), objectsToCut.end() );
618    objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
619  
620 +  produces<map<string, bool> > ("channelDecisions");
621 +
622 + } // end constructor OSUAnalysis::OSUAnalysis()
623  
424 }
624  
625   OSUAnalysis::~OSUAnalysis ()
626   {
627 +
628    // Destroying the CutFlow objects causes the cut flow numbers and time
629    // information to be printed to standard output.
630    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
# Line 433 | Line 633 | OSUAnalysis::~OSUAnalysis ()
633   }
634  
635   void
636 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
636 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
637   {
638 <
638 >  //cout << "**********************\n\n\n";
639    // Retrieve necessary collections from the event.
640  
641 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
641 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
642      event.getByLabel (triggers_, triggers);
643  
644 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
644 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
645 >    event.getByLabel (trigobjs_, trigobjs);
646 >
647 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
648      event.getByLabel (jets_, jets);
649  
650 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
650 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
651      event.getByLabel (muons_, muons);
652  
653 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
653 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
654      event.getByLabel (electrons_, electrons);
655  
656 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
656 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
657      event.getByLabel (events_, events);
658  
659 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
659 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
660      event.getByLabel (taus_, taus);
661  
662 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
662 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
663      event.getByLabel (mets_, mets);
664  
665 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
665 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
666      event.getByLabel (tracks_, tracks);
667  
668 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
668 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
669      event.getByLabel (genjets_, genjets);
670  
671 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
671 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
672      event.getByLabel (mcparticles_, mcparticles);
673  
674 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
674 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
675      event.getByLabel (primaryvertexs_, primaryvertexs);
676  
677 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
677 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
678      event.getByLabel (bxlumis_, bxlumis);
679  
680 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
680 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
681      event.getByLabel (photons_, photons);
682  
683 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
683 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
684      event.getByLabel (superclusters_, superclusters);
685  
686 <  if (useTrackCaloRhoCorr_) {  
687 <    // Used only for pile-up correction of by-hand calculation of isolation energy.  
688 <    // This rho collection is not available in all BEANs.  
686 >  if (datasetType_ == "signalMC"){
687 >    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
688 >      event.getByLabel (stops_, stops);
689 >  }
690 >
691 >  if (useTrackCaloRhoCorr_) {
692 >    // Used only for pile-up correction of by-hand calculation of isolation energy.
693 >    // This rho collection is not available in all BEANs.
694      // For description of rho values for different jet reconstruction algorithms, see
695 <    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms  
696 <    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
695 >    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
696 >    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
697    }
698  
699 +  double masterScaleFactor = 1.0;
700  
701    //get pile-up event weight
702 <  double scaleFactor = 1.00;
703 <  if(doPileupReweighting_ && datasetType_ != "data")
704 <    scaleFactor = puWeight_->at (events->at (0).numTruePV);
702 >  if (doPileupReweighting_ && datasetType_ != "data") {
703 >    //for "data" datasets, the numTruePV is always set to -1
704 >    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
705 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
706 >  }
707  
708 +  stopCTauScaleFactor_ = 1.0;
709 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
710 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
711 +  masterScaleFactor *= stopCTauScaleFactor_;
712  
713    //loop over all channels
714  
715 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
716    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
717      channel currentChannel = channels.at(currentChannelIndex);
718  
# Line 504 | Line 720 | OSUAnalysis::analyze (const edm::Event &
720      counterMap passingCounter;
721      cumulativeFlags.clear ();
722  
723 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
724 +         iter != BNTreeBranchVals_.end(); iter++) {
725 +      iter->second.clear();  // clear array
726 +    }
727 +
728      bool triggerDecision = true;
729 <    if(currentChannel.triggers.size() != 0){  //triggers specified
730 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
729 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
730 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
731        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
732      }
733  
734      //loop over all cuts
514
515
516
735      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
736        cut currentCut = currentChannel.cuts.at(currentCutIndex);
519
737        for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
738          string currentObject = objectsToCut.at(currentObjectIndex);
739  
740          //initialize maps to get ready to set cuts
741 <        individualFlags[currentObject].push_back (vector<bool> ());
742 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
741 >        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
742 >        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
743  
744        }
745        for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
# Line 531 | Line 748 | OSUAnalysis::analyze (const edm::Event &
748          int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
749  
750  
751 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
752 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
751 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
752 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
753 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
754 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
755 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
756          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
757          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
758          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 544 | Line 764 | OSUAnalysis::analyze (const edm::Event &
764          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
765          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
766          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
767 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
768 +
769  
770  
771          else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
772                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
773                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
774                                                                     "muon-muon pairs");
775 +
776 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
777 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
778 +                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
779 +                                                                             "muon-secondary muon pairs");
780 +
781 +        else if(currentObject == "muon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
782 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
783 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
784 +                                                                             "muon-secondary jet pairs");
785 +        else if(currentObject == "photon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
786 +                                                                             cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
787 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
788 +                                                                             "photon-secondary jet pairs");
789 +
790 +        else if(currentObject == "electron-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
791 +                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
792 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
793 +                                                                             "electron-secondary jet pairs");
794 +
795 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
796 +                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
797 +                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
798 +                                                                                     "electron-secondary electron pairs");
799 +
800          else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
801                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
802                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
# Line 558 | Line 805 | OSUAnalysis::analyze (const edm::Event &
805                                                                         cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
806                                                                         cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
807                                                                         "electron-muon pairs");
808 <        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
809 <                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
810 <                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
811 <                                                                     "track-event pairs");
812 <        
808 >        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
809 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
810 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
811 >                                                                 "jet-jet pairs");
812 >        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
813 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
814 >                                                                 cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex),\
815 >                                                                 "jet-secondary jet pairs");
816 >        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
817 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
818 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
819 >                                                                      "electron-jet pairs");
820 >        else if(currentObject == "electron-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), \
821 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
822 >                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
823 >                                                                      "electron-photon pairs");
824 >        else if(currentObject == "photon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
825 >                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
826 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
827 >                                                                      "photon-jet pairs");
828 >        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
829 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
830 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
831 >                                                                  "muon-jet pairs");
832 >        else if(currentObject == "met-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
833 >                                                                  cumulativeFlags.at("mets").at(flagsForPairCutsIndex), \
834 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
835 >                                                                  "met-jet pairs");
836 >        else if(currentObject == "muon-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
837 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
838 >                                                                  cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
839 >                                                                  "muon-photon pairs");
840 >        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
841 >                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
842 >                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
843 >                                                                     "track-event pairs");
844 >        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
845 >                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
846 >                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
847 >                                                                        "electron-track pairs");
848 >        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
849 >                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
850 >                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
851 >                                                                    "muon-track pairs");
852 >        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
853 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
854 >                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
855 >                                                                  "muon-tau pairs");
856 >        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
857 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
858 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
859 >                                                                 "tau-tau pairs");
860 >        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
861 >                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
862 >                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
863 >                                                                   "tau-track pairs");
864 >        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
865 >                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
866 >                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
867 >                                                                          "electron-trigobj pairs");
868 >        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
869 >                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
870 >                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
871 >                                                                      "muon-trigobj pairs");
872  
873 +        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
874        }
875  
876  
877  
878      }//end loop over all cuts
572
573
879      //use cumulative flags to apply cuts at event level
880  
881 +    //a vector to store cumulative cut descisions after each cut.
882 +    vector<bool> eventPassedPreviousCuts;
883      bool eventPassedAllCuts = true;
577
884      //apply trigger (true if none were specified)
885      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
886  
581
582
887      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
888  
889        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 587 | Line 891 | OSUAnalysis::analyze (const edm::Event &
891        int numberPassing = 0;
892  
893        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
894 <          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
894 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
895        }
592
896        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
897        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
595
898        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
899 <
899 >      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
900      }
901 +    double scaleFactor = masterScaleFactor;
902  
903 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
904 +    if(applyLeptonSF_ && datasetType_ != "data"){
905 +      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
906 +        flagPair muonFlags;
907 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
908 +          if (cumulativeFlags.at("muons").at(i).size()){
909 +            muonFlags = cumulativeFlags.at("muons").at(i);
910 +            break;
911 +          }
912 +        }
913 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
914 +          if(!muonFlags.at(muonIndex).second) continue;
915 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
916 +        }
917 +      }
918 +      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
919 +        flagPair electronFlags;
920 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
921 +          if (cumulativeFlags.at("electrons").at(i).size()){
922 +            electronFlags = cumulativeFlags.at("electrons").at(i);
923 +            break;
924 +          }
925 +        }
926 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
927 +          if(!electronFlags.at(electronIndex).second) continue;
928 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
929 +        }
930 +      }
931 +    }
932 +    if(applyBtagSF_ && datasetType_ != "data"){
933 +     if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
934 +       flagPair jetFlags;
935 +        vector<double> jetSFs;
936 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
937 +          if (cumulativeFlags.at("jets").at(i).size()){
938 +            jetFlags = cumulativeFlags.at("jets").at(i);
939 +            break;
940 +          }
941 +        }
942 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
943 +          if(!jetFlags.at(jetIndex).second) continue;
944 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour);
945 +          jetSFs.push_back(jetSFTmp);
946 +        }
947 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_, maxBtag_ );
948 +      }
949 +    }
950 +    scaleFactor *= muonScaleFactor_;
951 +    scaleFactor *= electronScaleFactor_;
952 +    scaleFactor *= bTagScaleFactor_;
953      cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
954  
955 +    if (printEventInfo_) {
956 +      // Write information about event to screen, for testing purposes.
957 +      cout << "Event passed all cuts in channel " <<  currentChannel.name
958 +           << ": run="  << events->at(0).run
959 +           << "  lumi=" << events->at(0).lumi
960 +           << "  event=" << events->at(0).evt
961 +           << endl;
962 +    }
963  
964  
965 <    if(!eventPassedAllCuts)continue;
965 >    //filling histograms
966 >    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
967 >      uint currentDir;
968 >      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
969 >      else{
970 >        currentDir = currentCut;
971 >      }
972  
606    if (printEventInfo_) {
607      // Write information about event to screen, for testing purposes.  
608      cout << "Event passed all cuts in channel " <<  currentChannel.name
609           << ": run="  << events->at(0).run
610           << "  lumi=" << events->at(0).lumi
611           << "  event=" << events->at(0).evt
612           << endl;  
613    }
973  
974 +      if(eventPassedPreviousCuts.at(currentDir)){
975  
976 < //     if(datasetType_ != "data") {
977 < //       scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
618 < //       scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
619 < //     }
976 >        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
977 >          histogram currentHistogram = histograms.at(histogramIndex);
978  
979 <    //filling histograms
980 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
981 <      histogram currentHistogram = histograms.at(histogramIndex);
979 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) cout << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
980 >
981 >          if(currentHistogram.inputVariables.size() == 1){
982 >            TH1D* histo;
983 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
984 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
985 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
986 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
987 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
988 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
989 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
990 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
991 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
992 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
993 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
994 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
995 >             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
996 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
997 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
998 >             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
999 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1000 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1001 >             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1002 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1003 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1004 >
1005 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1006 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
1007 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
1008 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1009 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
1010 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
1011 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1012 >             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1013 >                                                                                                     cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1014 >                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1015 >
1016 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1017 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1018 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1019 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
1020 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
1021 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1022 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
1023 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1024 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1025 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(), \
1026 >                                                                                              cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1027 >                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1028 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
1029 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1030 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1031 >            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
1032 >                                                                                          cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1033 >                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1034 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(), \
1035 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1036 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1037 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(), \
1038 >                                                                                          cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1039 >                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1040 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1041 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1042 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1043 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1044 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1045 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1046 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1047 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1048 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1049 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1050 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1051 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1052 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1053 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1054 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1055 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1056 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1057 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1058 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1059 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1060 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1061 >
1062 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1063 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1064 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1065 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1066 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1067 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1068 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1069 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1070 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1071 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1072 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1073 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1074 >          }
1075 >          else if(currentHistogram.inputVariables.size() == 2){
1076 >            TH2D* histo;
1077 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1078 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1079 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1080 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1081 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1082 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1083 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1084 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1085 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1086 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1087 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1088 >            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1089 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1090 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1091 >            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1092 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1093 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1094 >            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1095 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1096 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1097 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1098 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1099 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1100 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1101 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1102 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1103 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1104 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1105 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1106 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1107 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1108 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1109 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1110 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1111 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1112 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1113 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1114 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(), \
1115 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1116 >                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1117 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1118 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1119 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1120 >            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1121 >                                                                                         cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1122 >                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1123 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1124 >                                                                                          cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1125 >                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1126 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1127 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1128 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1129 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1130 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1131 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1132 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1133 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1134 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1135 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1136 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1137 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1138 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1139 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1140 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1141 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1142 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1143 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1144 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1145 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1146 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1147 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1148 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1149 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1150 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1151 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1152 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1153 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1154 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1155 >                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1156 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1157 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1158 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1159 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1160 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1161 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1162 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1163 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1164 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1165 >          }
1166 >
1167 >        }
1168 >
1169 >
1170 >        //fills histograms with the sizes of collections
1171 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1172 >
1173 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1174 >          string objectToPlot = "";
1175 >
1176 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1177 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1178 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1179 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1180 >          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1181 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1182 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1183 >          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1184 >          else if(currentObject == "muon-photon pairs")                  objectToPlot = "muonPhotonPairs";
1185 >          else if(currentObject == "photon-jet pairs")                   objectToPlot = "photonJetPairs";
1186 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1187 >          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1188 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1189 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1190 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1191 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1192 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1193 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1194 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1195 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1196 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1197 >          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1198 >          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1199 >          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1200 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1201 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1202 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1203 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1204 >          else objectToPlot = currentObject;
1205 >
1206 >          string tempCurrentObject = objectToPlot;
1207 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1208 >          string histoName = "num" + tempCurrentObject;
1209 >
1210 >
1211 >          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1212 >            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1213 >            int numToPlot = 0;
1214 >            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1215 >              if(lastCutFlags.at(currentFlag).second) numToPlot++;
1216 >            }
1217 >
1218 >            if(objectToPlot == "primaryvertexs"){
1219 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1220 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1221 >            }
1222 >            else {
1223 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1224 >            }
1225 >          }
1226 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1227 >
1228 >
1229 >      } // end if(eventPassedPreviousCuts.at(currentDir))
1230 >    } // end loop over cuts
1231 >
1232 >    if (!useEDMFormat_ && eventPassedAllCuts){
1233 >      // Assign BNTree variables
1234 >      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1235 >        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1236 >        string coll = brSpecs.inputCollection;
1237 >        if (cumulativeFlags.count(coll) == 0) cout << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1238 >
1239 >        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1240 >        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1241 >        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1242 >        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1243 >        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1244 >        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1245 >        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1246 >        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1247 >        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1248 >        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1249 >        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1250 >        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1251 >        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1252 >        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1253 >        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1254 >        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1255 >        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1256 >        else if(coll == "stops"
1257 >                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1258 >      } // end loop over branches
1259 >
1260 >      if (!BNTrees_.at(currentChannelIndex)) { cout << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1261 >      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1262 >    }
1263  
1264 <      if(currentHistogram.inputVariables.size() == 1){
626 <        TH1D* histo;
627 <        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
628 <
629 <
630 <
631 <        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
632 <         else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
633 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
634 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
635 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
636 <        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
637 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
638 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
639 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
640 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
641 <                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
642 <                                                                                              cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
643 <        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
644 <        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
645 <        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
646 <        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
647 <        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
648 <        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
649 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
650 <        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
651 <        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
652 <        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
653 <      }
654 <      else if(currentHistogram.inputVariables.size() == 2){
655 <        TH2D* histo;
656 <        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
657 <
658 <
659 <
660 <        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
661 <        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
662 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
663 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
664 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
665 <        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
666 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
667 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
668 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
669 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
670 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
671 <                                                                                               cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
672 <        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
673 <        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
674 <        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
675 <        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
676 <        else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
677 <                                                                                         cumulativeFlags.at("tracks").back(),cumulativeFlags.at("events").back(),
678 <                                                                                         cumulativeFlags.at("track-event pairs").back(),scaleFactor);  
679 <        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
680 <        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
681 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
682 <        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
683 <        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
684 <        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
685 <      }
686 <    }
687 <
688 <    //fills histograms with the sizes of collections
689 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
690 <
691 <      string currentObject = objectsToPlot.at(currentObjectIndex);
692 <
693 <      string objectToPlot = "";  
694 <
695 <      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().  
696 <      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
697 <      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
698 <      else if(currentObject == "electron-muon pairs")     objectToPlot = "electronMuonPairs";
699 <      else if(currentObject == "track-event pairs")       objectToPlot = "trackEventPairs";  
700 <      else objectToPlot = currentObject;
701 <      string tempCurrentObject = objectToPlot;
702 <      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));  // Capitalize the first letter.  
703 <      string histoName = "num" + tempCurrentObject;
704 <
705 <
706 <      //set position of primary vertex in event, in order to calculate quantities relative to it
707 <      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
708 <        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
709 <        int numToPlot = 0;
710 <        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
711 <          if(lastCutFlags.at(currentFlag)) numToPlot++;
712 <        }
713 <        if(objectToPlot == "primaryvertexs"){
714 <          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
715 <          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
716 <        }
717 <        else {
718 <          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
719 <        }
720 <      }
721 <      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
722 <      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
723 <      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
724 <      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
725 <      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
726 <      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
727 <      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
728 <      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
729 <      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
730 <      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
731 <      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
732 <      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
733 <      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
734 <      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
735 <      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
736 <      else if(objectToPlot == "primaryvertexs"){
737 <        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
738 <        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
739 <      }
1264 >    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1265  
1266 <    } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1266 >  } // end loop over channel
1267  
1268 <  } //end loop over channel
1268 >  masterCutFlow_->fillCutFlow(masterScaleFactor);
1269  
1270 <  masterCutFlow_->fillCutFlow(scaleFactor);
1270 >  event.put (channelDecisions, "channelDecisions");
1271  
1272   } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1273  
# Line 759 | Line 1284 | OSUAnalysis::evaluateComparison (double
1284    else if(comparison == "==") return testValue == cutValue;
1285    else if(comparison == "=") return testValue == cutValue;
1286    else if(comparison == "!=") return testValue != cutValue;
1287 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1287 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1288  
1289   }
1290  
1291   bool
1292 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1292 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1293  
1294 +
1295 +  if(comparison == ">")       return testValue >  cutValue;
1296 +  else if(comparison == ">=") return testValue >= cutValue;
1297 +  else if(comparison == "<")  return testValue <  cutValue;
1298 +  else if(comparison == "<=") return testValue <= cutValue;
1299 +  else if(comparison == "==") return testValue == cutValue;
1300 +  else if(comparison == "=") return testValue == cutValue;
1301 +  else if(comparison == "!=") return testValue != cutValue;
1302 +  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1303 +
1304 + }
1305 +
1306 + bool
1307 + OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1308 +
1309 +  //initialize to false until a chosen trigger is passed
1310    bool triggerDecision = false;
1311  
1312 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1313 <    {
1314 <      if(trigger->pass != 1) continue;
1315 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1316 <        {
1317 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1318 <            triggerDecision = true;
1319 <          }
1320 <        }
1312 >  if (printAllTriggers_) cout << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1313 >  //loop over all triggers defined in the event
1314 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1315 >
1316 >    if (printAllTriggers_) cout << "   " << trigger->name << endl;
1317 >
1318 >    //we're only interested in triggers that actually passed
1319 >    if(trigger->pass != 1) continue;
1320 >
1321 >    //if the event passes one of the veto triggers, exit and return false
1322 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1323 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1324 >    }
1325 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1326 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1327 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1328      }
1329 <  return triggerDecision;
1329 >  }
1330  
1331 +  printAllTriggers_ = false;  // only print triggers once, not every event
1332 +
1333 +  //if none of the veto triggers fired:
1334 +  //return the OR of all the chosen triggers
1335 +  if (triggersToTest.size() != 0) return triggerDecision;
1336 +  //or if no triggers were defined return true
1337 +  else return true;
1338   }
1339  
1340 < std::vector<std::string>
1340 >
1341 > vector<string>
1342   OSUAnalysis::splitString (string inputString){
1343  
1344 <  std::stringstream stringStream(inputString);
1345 <  std::istream_iterator<std::string> begin(stringStream);
1346 <  std::istream_iterator<std::string> end;
1347 <  std::vector<std::string> stringVector(begin, end);
1344 >  stringstream stringStream(inputString);
1345 >  istream_iterator<string> begin(stringStream);
1346 >  istream_iterator<string> end;
1347 >  vector<string> stringVector(begin, end);
1348    return stringVector;
1349  
1350   }
1351  
1352 +
1353 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1354 +  // Set two object strings from the tempInputCollection string,
1355 +  // For example, if tempInputCollection is "electron-muon pairs",
1356 +  // then obj1 = "electrons" and obj2 = "muons".
1357 +  // Note that the objects have an "s" appended.
1358 +
1359 +  int dashIndex = tempInputCollection.find("-");
1360 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1361 +  int secondWordLength = spaceIndex - dashIndex;
1362 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1363 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1364 +
1365 + }
1366 +
1367 +
1368 + string OSUAnalysis::getObjToGet(string obj) {
1369 +  // Return the string corresponding to the object to get for the given obj string.
1370 +  // Right now this only handles the case in which obj contains "secondary",
1371 +  // e.g, "secondary muons".
1372 +  // Note that "s" is NOT appended.
1373 +
1374 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1375 +  int firstSpaceIndex = obj.find_first_of(" ");
1376 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1377 +
1378 + }
1379 +
1380 +
1381 + //!jet valueLookup
1382   double
1383 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1383 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1384  
1385    double value = 0.0;
1386    if(variable == "energy") value = object->energy;
# Line 913 | Line 1499 | OSUAnalysis::valueLookup (const BNjet* o
1499    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1500    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1501  
1502 +  //user defined variable
1503 +  else if(variable == "disappTrkLeadingJetID") {
1504 +    value = object->pt > 110
1505 +      && fabs(object->eta) < 2.4
1506 +      && object->chargedHadronEnergyFraction > 0.2
1507 +      && object->neutralHadronEnergyFraction < 0.7
1508 +      && object->chargedEmEnergyFraction < 0.5
1509 +      && object->neutralEmEnergyFraction < 0.7;
1510 +  }
1511  
1512 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1512 >  else if(variable == "disappTrkSubLeadingJetID") {
1513 >    value = object->pt > 30
1514 >      && fabs(object->eta) < 4.5
1515 >      && object->neutralHadronEnergyFraction < 0.7
1516 >      && object->chargedEmEnergyFraction < 0.5;
1517 >  }
1518 >
1519 >  else if(variable == "dPhiMet") {
1520 >    if (const BNmet *met = chosenMET ()) {
1521 >      value = deltaPhi (object->phi, met->phi);
1522 >    } else value = -999;
1523 >  }
1524 >
1525 >
1526 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1527  
1528    value = applyFunction(function, value);
1529  
# Line 922 | Line 1531 | OSUAnalysis::valueLookup (const BNjet* o
1531   }
1532  
1533  
1534 <
1534 > //!muon valueLookup
1535   double
1536 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1536 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1537  
1538    double value = 0.0;
1539    if(variable == "energy") value = object->energy;
# Line 1079 | Line 1688 | OSUAnalysis::valueLookup (const BNmuon*
1688    else if(variable == "time_ndof") value = object->time_ndof;
1689  
1690    //user-defined variables
1691 +  else if(variable == "looseID") {
1692 +    value = object->pt > 10
1693 +      && object->isGlobalMuon > 0
1694 +      && object->isTrackerMuon > 0;
1695 +      }
1696    else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1697    else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1698    else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1699    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1700    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1701    else if(variable == "metMT") {
1702 <    const BNmet *met = chosenMET ();
1089 <    if (met)
1702 >    if (const BNmet *met = chosenMET ())
1703        {
1704 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1705 <                       p2 (met->px, met->py, 0.0, met->pt);
1093 <
1094 <        value = (p1 + p2).Mt ();
1704 >        double dPhi = deltaPhi (object->phi, met->phi);
1705 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1706        }
1707      else
1708        value = -999;
# Line 1218 | Line 1829 | OSUAnalysis::valueLookup (const BNmuon*
1829    }
1830    else if(variable == "tightIDdisplaced"){
1831      value = object->isGlobalMuon > 0                \
1832 +      && object->isPFMuon > 0                        \
1833        && object->normalizedChi2 < 10                \
1834        && object->numberOfValidMuonHits > 0        \
1835        && object->numberOfMatchedStations > 1        \
# Line 1225 | Line 1837 | OSUAnalysis::valueLookup (const BNmuon*
1837        && object->numberOfLayersWithMeasurement > 5;
1838    }
1839  
1840 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1840 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1841  
1842    else if(variable == "genMatchedPdgId"){
1843      int index = getGenMatchedParticleIndex(object);
# Line 1245 | Line 1857 | OSUAnalysis::valueLookup (const BNmuon*
1857    }
1858    else if(variable == "genMatchedMotherIdReverse"){
1859      int index = getGenMatchedParticleIndex(object);
1860 <    if(index == -1) value = 23;
1861 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1860 >    if(index == -1) value = 24;
1861 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1862    }
1863    else if(variable == "genMatchedGrandmotherId"){
1864      int index = getGenMatchedParticleIndex(object);
# Line 1258 | Line 1870 | OSUAnalysis::valueLookup (const BNmuon*
1870      }
1871      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1872    }
1873 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1874 +    int index = getGenMatchedParticleIndex(object);
1875 +    if(index == -1) value = 24;
1876 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1877 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1878 +      if(motherIndex == -1) value = 24;
1879 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1880 +    }
1881 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1882 +  }
1883 +  else if(variable == "pfMuonsFromVertex"){
1884 +    double d0Error, dzError;
1885  
1886 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1887 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1888 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1889 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1890 +      || fabs (object->correctedDZ / dzError) > 99.0;
1891 +    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1892 +  }
1893  
1894  
1895 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1895 >
1896 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1897  
1898    value = applyFunction(function, value);
1899  
1900    return value;
1901   }
1902  
1903 <
1903 > //!electron valueLookup
1904   double
1905 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1905 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1906  
1907    double value = 0.0;
1908    if(variable == "energy") value = object->energy;
# Line 1436 | Line 2068 | OSUAnalysis::valueLookup (const BNelectr
2068    else if(variable == "detIso") value = (object->trackIso) / object->pt;
2069    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2070    else if(variable == "metMT") {
2071 <    const BNmet *met = chosenMET ();
1440 <    if (met)
2071 >    if (const BNmet *met = chosenMET ())
2072        {
2073 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
2074 <                       p2 (met->px, met->py, 0.0, met->pt);
1444 <
1445 <        value = (p1 + p2).Mt ();
2073 >        double dPhi = deltaPhi (object->phi, met->phi);
2074 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2075        }
2076      else
2077        value = -999;
# Line 1534 | Line 2163 | OSUAnalysis::valueLookup (const BNelectr
2163        }
2164    }
2165  
2166 +  else if(variable == "looseID"){
2167 +    value = object->pt > 10
2168 +      && object->mvaNonTrigV0 > 0;
2169 +      }
2170    else if(variable == "correctedD0VertexInEBPositiveCharge"){
2171      if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2172      else value = -999;
# Line 1607 | Line 2240 | OSUAnalysis::valueLookup (const BNelectr
2240    }
2241  
2242  
2243 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2243 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2244  
2245    else if(variable == "genMatchedPdgId"){
2246      int index = getGenMatchedParticleIndex(object);
# Line 1628 | Line 2261 | OSUAnalysis::valueLookup (const BNelectr
2261    }
2262    else if(variable == "genMatchedMotherIdReverse"){
2263      int index = getGenMatchedParticleIndex(object);
2264 <    if(index == -1) value = 23;
2265 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2264 >    if(index == -1) value = 24;
2265 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2266    }
2267    else if(variable == "genMatchedGrandmotherId"){
2268      int index = getGenMatchedParticleIndex(object);
# Line 1641 | Line 2274 | OSUAnalysis::valueLookup (const BNelectr
2274      }
2275      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2276    }
2277 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2278 +    int index = getGenMatchedParticleIndex(object);
2279 +    if(index == -1) value = 24;
2280 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2281 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2282 +      if(motherIndex == -1) value = 24;
2283 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2284 +    }
2285 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2286 +  }
2287 +  else if(variable == "pfElectronsFromVertex"){
2288 +    double d0Error, dzError;
2289  
2290 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2291 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2292 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2293 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2294 +      || fabs (object->correctedDZ / dzError) > 99.0;
2295 +    value = !value;
2296 +  }
2297  
2298  
2299 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2299 >
2300 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2301  
2302    value = applyFunction(function, value);
2303  
2304    return value;
2305   }
2306  
2307 <
2307 > //!event valueLookup
2308   double
2309 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2309 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2310  
2311    double value = 0.0;
2312  
# Line 1722 | Line 2375 | OSUAnalysis::valueLookup (const BNevent*
2375    else if(variable == "id2") value = object->id2;
2376    else if(variable == "evt") value = object->evt;
2377    else if(variable == "puScaleFactor"){
2378 <    if(datasetType_ != "data")
2378 >    if(doPileupReweighting_ && datasetType_ != "data")
2379        value = puWeight_->at (events->at (0).numTruePV);
2380      else
2381        value = 1.0;
2382    }
2383 <  else if(variable == "muonScaleFactor"){
2384 <    if(datasetType_ != "data")
2385 <      //      value = muonSFWeight_->at (chosenMuon ()->eta);
2386 <    value = 1.0;
2387 <    else
1735 <      value = 1.0;
1736 <  }
1737 <  else if(variable == "electronScaleFactor"){
1738 <    if(datasetType_ != "data")
1739 <      //      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1740 <    value = 1.0;
1741 <    else
1742 <      value = 1.0;
1743 <  }
1744 <
1745 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2383 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2384 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2385 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2386 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2387 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2388  
2389    value = applyFunction(function, value);
2390  
2391    return value;
2392   }
2393  
2394 + //!tau valueLookup
2395   double
2396 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2396 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2397  
2398    double value = 0.0;
2399  
# Line 1794 | Line 2437 | OSUAnalysis::valueLookup (const BNtau* o
2437    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2438    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2439  
2440 +  else if (variable == "looseHadronicID") {
2441 +    value = object->pt > 10
2442 +      && object->eta < 2.3
2443 +      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2444 +      && object->HPSdecayModeFinding > 0
2445 +      && object->HPSagainstElectronLoose > 0
2446 +      && object->HPSagainstMuonTight > 0;
2447 +  }
2448  
2449 <
1799 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2449 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2450  
2451    else if(variable == "genMatchedPdgId"){
2452      int index = getGenMatchedParticleIndex(object);
# Line 1816 | Line 2466 | OSUAnalysis::valueLookup (const BNtau* o
2466    }
2467    else if(variable == "genMatchedMotherIdReverse"){
2468      int index = getGenMatchedParticleIndex(object);
2469 <    if(index == -1) value = 23;
2470 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2469 >    if(index == -1) value = 24;
2470 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2471    }
2472    else if(variable == "genMatchedGrandmotherId"){
2473      int index = getGenMatchedParticleIndex(object);
# Line 1829 | Line 2479 | OSUAnalysis::valueLookup (const BNtau* o
2479      }
2480      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2481    }
2482 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2483 +    int index = getGenMatchedParticleIndex(object);
2484 +    if(index == -1) value = 24;
2485 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2486 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2487 +      if(motherIndex == -1) value = 24;
2488 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2489 +    }
2490 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2491 +  }
2492  
2493  
2494 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2494 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2495  
2496    value = applyFunction(function, value);
2497  
2498    return value;
2499   }
2500  
2501 + //!met valueLookup
2502   double
2503 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2503 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2504  
2505    double value = 0.0;
2506  
# Line 1903 | Line 2564 | OSUAnalysis::valueLookup (const BNmet* o
2564    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2565    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2566  
2567 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2567 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2568  
2569    value = applyFunction(function, value);
2570  
2571    return value;
2572   }
2573  
2574 + //!track valueLookup
2575   double
2576 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2576 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2577  
2578    double value = 0.0;
2579    double pMag = sqrt(object->pt * object->pt +
2580 <                     object->pz * object->pz);
2581 <  
2580 >                     object->pz * object->pz);
2581 >
2582    if(variable == "pt") value = object->pt;
2583    else if(variable == "px") value = object->px;
2584    else if(variable == "py") value = object->py;
# Line 1937 | Line 2599 | OSUAnalysis::valueLookup (const BNtrack*
2599  
2600  
2601    //additional BNs info for disappTrks
1940  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2602    else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2603    else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2604    else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2605    else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2606    else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2607    else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2608 +  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2609    else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2610    else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2611    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2612 <  
2612 >  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2613  
2614    //user defined variables
2615    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;
2616    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2617 +  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2618    else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2619    else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2620 <  else if(variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object);  
2621 <  else if(variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object) / pMag;  
2620 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2621 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2622    else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2623    else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2624    else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2625    else if(variable == "ptError")                    value = object->ptError;
2626    else if(variable == "ptRes")                      value = getTrkPtRes(object);
2627 +  else if (variable == "d0wrtPV"){
2628 +    double vx = object->vx - chosenVertex ()->x,
2629 +      vy = object->vy - chosenVertex ()->y,
2630 +      px = object->px,
2631 +      py = object->py,
2632 +      pt = object->pt;
2633 +    value = (-vx * py + vy * px) / pt;
2634 +  }
2635 +  else if (variable == "dZwrtPV"){
2636 +    double vx = object->vx - chosenVertex ()->x,
2637 +      vy = object->vy - chosenVertex ()->y,
2638 +      vz = object->vz - chosenVertex ()->z,
2639 +      px = object->px,
2640 +      py = object->py,
2641 +      pz = object->pz,
2642 +      pt = object->pt;
2643 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2644 +  }
2645 +
2646  
2647 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2647 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2648  
2649    else if(variable == "genMatchedPdgId"){
2650      int index = getGenMatchedParticleIndex(object);
# Line 1983 | Line 2665 | OSUAnalysis::valueLookup (const BNtrack*
2665    }
2666    else if(variable == "genMatchedMotherIdReverse"){
2667      int index = getGenMatchedParticleIndex(object);
2668 <    if(index == -1) value = 23;
2669 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2668 >    if(index == -1) value = 24;
2669 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2670    }
2671    else if(variable == "genMatchedGrandmotherId"){
2672      int index = getGenMatchedParticleIndex(object);
# Line 1996 | Line 2678 | OSUAnalysis::valueLookup (const BNtrack*
2678      }
2679      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2680    }
2681 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2682 +    int index = getGenMatchedParticleIndex(object);
2683 +    if(index == -1) value = 24;
2684 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2685 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2686 +      if(motherIndex == -1) value = 24;
2687 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2688 +    }
2689 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2690 +  }
2691  
2692  
2693  
2694 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2694 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2695  
2696    value = applyFunction(function, value);
2697  
2698    return value;
2699   }
2700  
2701 + //!genjet valueLookup
2702   double
2703 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2703 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2704  
2705    double value = 0.0;
2706  
# Line 2027 | Line 2720 | OSUAnalysis::valueLookup (const BNgenjet
2720    else if(variable == "charge") value = object->charge;
2721  
2722  
2723 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2723 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2724  
2725    value = applyFunction(function, value);
2726  
2727    return value;
2728   }
2729  
2730 + //!mcparticle valueLookup
2731   double
2732 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2732 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2733  
2734    double value = 0.0;
2735  
# Line 2160 | Line 2854 | OSUAnalysis::valueLookup (const BNmcpart
2854    }
2855  
2856  
2857 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2857 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2858  
2859    value = applyFunction(function, value);
2860  
2861    return value;
2862   }
2863  
2864 + //!primaryvertex valueLookup
2865   double
2866 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2866 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2867  
2868    double value = 0.0;
2869  
# Line 2187 | Line 2882 | OSUAnalysis::valueLookup (const BNprimar
2882    else if(variable == "isGood") value = object->isGood;
2883  
2884  
2885 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2885 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2886  
2887    value = applyFunction(function, value);
2888  
2889    return value;
2890   }
2891  
2892 + //!bxlumi valueLookup
2893   double
2894 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2894 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2895  
2896    double value = 0.0;
2897  
# Line 2204 | Line 2900 | OSUAnalysis::valueLookup (const BNbxlumi
2900    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2901  
2902  
2903 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2903 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2904  
2905    value = applyFunction(function, value);
2906  
2907    return value;
2908   }
2909  
2910 + //!photon valueLookup
2911   double
2912 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2912 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2913  
2914    double value = 0.0;
2915  
# Line 2287 | Line 2984 | OSUAnalysis::valueLookup (const BNphoton
2984    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2985  
2986  
2290
2987  
2988 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2988 >
2989 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2990  
2991    else if(variable == "genMatchedPdgId"){
2992      int index = getGenMatchedParticleIndex(object);
# Line 2311 | Line 3008 | OSUAnalysis::valueLookup (const BNphoton
3008    }
3009    else if(variable == "genMatchedMotherIdReverse"){
3010      int index = getGenMatchedParticleIndex(object);
3011 <    if(index == -1) value = 23;
3012 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
3011 >    if(index == -1) value = 24;
3012 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
3013    }
3014    else if(variable == "genMatchedGrandmotherId"){
3015      int index = getGenMatchedParticleIndex(object);
# Line 2324 | Line 3021 | OSUAnalysis::valueLookup (const BNphoton
3021      }
3022      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3023    }
3024 +  else if(variable == "genMatchedGrandmotherIdReverse"){
3025 +    int index = getGenMatchedParticleIndex(object);
3026 +    if(index == -1) value = 24;
3027 +    else if(fabs(mcparticles->at(index).motherId) == 15){
3028 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3029 +      if(motherIndex == -1) value = 24;
3030 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3031 +    }
3032 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3033 +  }
3034  
3035  
3036 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3036 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3037  
3038    value = applyFunction(function, value);
3039  
3040    return value;
3041   }
3042  
3043 + //!supercluster valueLookup
3044   double
3045 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
3045 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
3046  
3047    double value = 0.0;
3048  
# Line 2348 | Line 3056 | OSUAnalysis::valueLookup (const BNsuperc
3056    else if(variable == "theta") value = object->theta;
3057  
3058  
3059 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3059 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3060  
3061    value = applyFunction(function, value);
3062  
3063    return value;
3064   }
3065  
3066 + //!trigobj valueLookup
3067 + double
3068 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3069 +
3070 +  double value = 0.0;
3071 +
3072 +  if(variable == "pt") value = object->pt;
3073 +  else if(variable == "eta") value = object->eta;
3074 +  else if(variable == "phi") value = object->phi;
3075 +  else if(variable == "px") value = object->px;
3076 +  else if(variable == "py") value = object->py;
3077 +  else if(variable == "pz") value = object->pz;
3078 +  else if(variable == "et") value = object->et;
3079 +  else if(variable == "energy") value = object->energy;
3080 +  else if(variable == "etTotal") value = object->etTotal;
3081 +  else if(variable == "id") value = object->id;
3082 +  else if(variable == "charge") value = object->charge;
3083 +  else if(variable == "isIsolated") value = object->isIsolated;
3084 +  else if(variable == "isMip") value = object->isMip;
3085 +  else if(variable == "isForward") value = object->isForward;
3086 +  else if(variable == "isRPC") value = object->isRPC;
3087 +  else if(variable == "bx") value = object->bx;
3088 +  else if(variable == "filter") {
3089 +    if ((stringValue = object->filter) == "")
3090 +      stringValue = "none";  // stringValue should only be empty if value is filled
3091 +  }
3092 +
3093 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3094  
3095 +  value = applyFunction(function, value);
3096 +
3097 +  return value;
3098 + }
3099 +
3100 + //!muon-muon pair valueLookup
3101   double
3102 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
3102 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3103  
3104    double value = 0.0;
3105  
3106    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3107 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3108    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3109    else if(variable == "invMass"){
3110      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2403 | Line 3146 | OSUAnalysis::valueLookup (const BNmuon*
3146    else if(variable == "muon2CorrectedD0Vertex"){
3147      value = object2->correctedD0Vertex;
3148    }
3149 < else if(variable == "muon1timeAtIpInOut"){
3149 >  else if(variable == "muon1timeAtIpInOut"){
3150      value = object1->timeAtIpInOut;
3151    }
3152 < else if(variable == "muon2timeAtIpInOut"){
3152 >  else if(variable == "muon2timeAtIpInOut"){
3153      value = object2->timeAtIpInOut;
3154    }
3155 < else if(variable == "muon1correctedD0")
3156 <   {
3157 <     value = object1->correctedD0;
3158 <   }
3159 < else if(variable == "muon2correctedD0")
3160 <   {
3161 <     value = object2->correctedD0;
3162 <   }
3155 >  else if(variable == "muon1correctedD0")
3156 >    {
3157 >      value = object1->correctedD0;
3158 >    }
3159 >  else if(variable == "muon2correctedD0")
3160 >    {
3161 >      value = object2->correctedD0;
3162 >    }
3163  
3164 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3164 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3165  
3166    value = applyFunction(function, value);
3167  
3168    return value;
3169   }
3170  
3171 + //!muon-photon pair valueLookup
3172   double
3173 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
3173 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3174  
3175    double value = 0.0;
3176  
3177    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3178 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3179 +  else if(variable == "photonEta") value = object2->eta;
3180 +  else if(variable == "muonEta") value = object1->eta;
3181 +  else if(variable == "photonPhi") value = object2->phi;
3182 +  else if(variable == "muonPhi") value = object1->phi;
3183 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3184 +  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3185 +  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3186 +  else if(variable == "invMass"){
3187 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3188 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3189 +    value = (fourVector1 + fourVector2).M();
3190 +  }
3191 +  else if(variable == "pt"){
3192 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3193 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3194 +    value = (fourVector1 + fourVector2).Pt();
3195 +  }
3196 +  else if(variable == "threeDAngle")
3197 +    {
3198 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3199 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3200 +      value = (threeVector1.Angle(threeVector2));
3201 +    }
3202 +  else if(variable == "alpha")
3203 +    {
3204 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3205 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3206 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3207 +      value = (pi-threeVector1.Angle(threeVector2));
3208 +    }
3209 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3210 +
3211 +  value = applyFunction(function, value);
3212 +
3213 +  return value;
3214 + }
3215 +
3216 + //!electron-photon pair valueLookup
3217 + double
3218 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3219 +
3220 +  double value = 0.0;
3221 +
3222 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3223 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3224 +  else if(variable == "photonEta") value = object2->eta;
3225 +  else if(variable == "electronEta") value = object1->eta;
3226 +  else if(variable == "photonPhi") value = object2->phi;
3227 +  else if(variable == "electronPhi") value = object1->phi;
3228 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3229 +  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3230 +  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3231 +  else if(variable == "invMass"){
3232 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3233 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3234 +    value = (fourVector1 + fourVector2).M();
3235 +  }
3236 +  else if(variable == "pt"){
3237 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3238 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3239 +    value = (fourVector1 + fourVector2).Pt();
3240 +  }
3241 +  else if(variable == "threeDAngle")
3242 +    {
3243 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3244 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3245 +      value = (threeVector1.Angle(threeVector2));
3246 +    }
3247 +  else if(variable == "alpha")
3248 +    {
3249 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3250 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3251 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3252 +      value = (pi-threeVector1.Angle(threeVector2));
3253 +    }
3254 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3255 +
3256 +  value = applyFunction(function, value);
3257 +
3258 +  return value;
3259 + }
3260 +
3261 + //!electron-electron pair valueLookup
3262 + double
3263 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3264 +
3265 +  double value = 0.0;
3266 +
3267 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3268 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3269    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3270    else if(variable == "invMass"){
3271      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2472 | Line 3307 | OSUAnalysis::valueLookup (const BNelectr
3307      value = object2->correctedD0;
3308    }
3309  
3310 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3310 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3311  
3312    value = applyFunction(function, value);
3313  
3314    return value;
3315   }
3316 <
3316 > //!electron-muon pair valueLookup
3317   double
3318 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3318 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3319  
3320    double value = 0.0;
3321  
3322    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3323 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3324    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3325    else if(variable == "invMass"){
3326      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2531 | Line 3367 | OSUAnalysis::valueLookup (const BNelectr
3367    else if(variable == "muonDetIso"){
3368      value = (object2->trackIsoDR03) / object2->pt;
3369    }
3370 +  else if(variable == "electronRelPFrhoIso"){
3371 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3372 +  }
3373 +  else if(variable == "muonRelPFdBetaIso"){
3374 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3375 +  }
3376 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3377 +  value = applyFunction(function, value);
3378 +
3379 +  return value;
3380 + }
3381 +
3382 + //!electron-jet pair valueLookup
3383 + double
3384 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3385 +
3386 +  double value = 0.0;
3387 +
3388 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3389 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3390 +  else if(variable == "jetEta") value = object2->eta;
3391 +  else if(variable == "jetPhi") value = object2->phi;
3392 +  else if(variable == "electronEta") value = object1->eta;
3393 +  else if(variable == "electronPhi") value = object1->phi;
3394 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3395 +  else if(variable == "invMass"){
3396 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3397 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3398 +    value = (fourVector1 + fourVector2).M();
3399 +  }
3400 +  else if(variable == "pt"){
3401 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3402 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3403 +    value = (fourVector1 + fourVector2).Pt();
3404 +  }
3405 +  else if(variable == "threeDAngle")
3406 +    {
3407 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3408 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3409 +      value = (threeVector1.Angle(threeVector2));
3410 +    }
3411 +  else if(variable == "chargeProduct"){
3412 +    value = object1->charge*object2->charge;
3413 +  }
3414 +
3415 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3416 +  value = applyFunction(function, value);
3417 +
3418 +  return value;
3419 + }
3420 +
3421 + //!photon-jet pair valueLookup
3422 + double
3423 + OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3424 +
3425 +  double value = 0.0;
3426 +
3427 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3428 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3429 +  else if(variable == "jetEta") value = object2->eta;
3430 +  else if(variable == "jetPhi") value = object2->phi;
3431 +  else if(variable == "photonEta") value = object1->eta;
3432 +  else if(variable == "photonPhi") value = object1->phi;
3433 +  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3434 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3435 +  else if(variable == "invMass"){
3436 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3437 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3438 +    value = (fourVector1 + fourVector2).M();
3439 +  }
3440 +  else if(variable == "pt"){
3441 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3442 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3443 +    value = (fourVector1 + fourVector2).Pt();
3444 +  }
3445 +  else if(variable == "threeDAngle")
3446 +    {
3447 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3448 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3449 +      value = (threeVector1.Angle(threeVector2));
3450 +    }
3451 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3452 +  value = applyFunction(function, value);
3453 +
3454 +  return value;
3455 + }
3456 +
3457 + // met-jet pair valueLookup
3458 + double
3459 + OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3460 +
3461 +  double value = 0.0;
3462 +
3463 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3464 +
3465 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3466 +  value = applyFunction(function, value);
3467 +
3468 +  return value;
3469 +
3470 + }  
3471 +
3472 +
3473 +
3474 + //!muon-jet pair valueLookup
3475 + double
3476 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3477 +
3478 +  double value = 0.0;
3479 +
3480 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3481 +  else if(variable == "jetEta") value = object2->eta;
3482 +  else if(variable == "jetPhi") value = object2->phi;
3483 +  else if(variable == "muonEta") value = object1->eta;
3484 +  else if(variable == "muonPhi") value = object1->phi;
3485 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3486 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3487 +  else if(variable == "invMass"){
3488 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3489 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3490 +    value = (fourVector1 + fourVector2).M();
3491 +  }
3492 +  else if(variable == "pt"){
3493 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3494 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3495 +    value = (fourVector1 + fourVector2).Pt();
3496 +  }
3497 +  else if(variable == "threeDAngle")
3498 +    {
3499 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3500 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3501 +      value = (threeVector1.Angle(threeVector2));
3502 +    }
3503 +  else if(variable == "chargeProduct"){
3504 +    value = object1->charge*object2->charge;
3505 +  }
3506 +
3507 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3508 +  value = applyFunction(function, value);
3509 +
3510 +  return value;
3511 + }
3512 + //!jet-jet pair valueLookup
3513 + double
3514 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3515 +
3516 +  double value = 0.0;
3517  
3518 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3519 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3520 +  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3521 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3522 +  else if(variable == "invMass"){
3523 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3524 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3525 +    value = (fourVector1 + fourVector2).M();
3526 +  }
3527 +  else if(variable == "pt"){
3528 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3529 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3530 +    value = (fourVector1 + fourVector2).Pt();
3531 +  }
3532 +  else if(variable == "threeDAngle")
3533 +    {
3534 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3535 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3536 +      value = (threeVector1.Angle(threeVector2));
3537 +    }
3538 +  else if(variable == "chargeProduct"){
3539 +    value = object1->charge*object2->charge;
3540 +  }
3541 +
3542 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3543 +  value = applyFunction(function, value);
3544 +
3545 +  return value;
3546 + }
3547 + //!electron-track pair valueLookup
3548 + double
3549 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3550 +  double electronMass = 0.000511;
3551 +  double value = 0.0;
3552 +  TLorentzVector fourVector1(0, 0, 0, 0);
3553 +  TLorentzVector fourVector2(0, 0, 0, 0);
3554 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3555 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3556 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3557 +  else if(variable == "invMass"){
3558 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3559 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3560 +
3561 +    value = (fourVector1 + fourVector2).M();
3562 +  }
3563 +  else if(variable == "chargeProduct"){
3564 +    value = object1->charge*object2->charge;
3565 +  }
3566 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3567 +  value = applyFunction(function, value);
3568 +  return value;
3569 +
3570 + }
3571 +
3572 +
3573 + //!muon-track pair valueLookup
3574 + double
3575 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3576 +  double pionMass = 0.140;
3577 +  double muonMass = 0.106;
3578 +  double value = 0.0;
3579 +  TLorentzVector fourVector1(0, 0, 0, 0);
3580 +  TLorentzVector fourVector2(0, 0, 0, 0);
3581 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3582 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3583 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3584 +  else if(variable == "invMass"){
3585 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3586 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3587 +
3588 +    value = (fourVector1 + fourVector2).M();
3589 +  }
3590 +  else if(variable == "chargeProduct"){
3591 +    value = object1->charge*object2->charge;
3592 +  }
3593  
3594    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3595 +  value = applyFunction(function, value);
3596 +  return value;
3597 + }
3598 +
3599 + //!tau-tau pair valueLookup
3600 + double
3601 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3602 +  double value = 0.0;
3603 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3604 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3605 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3606 +  else if(variable == "invMass"){
3607 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3608 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3609 +    value = (fourVector1 + fourVector2).M();
3610 +  }
3611 +
3612 +  else if(variable == "chargeProduct"){
3613 +    value = object1->charge*object2->charge;
3614 +  }
3615  
3616 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3617    value = applyFunction(function, value);
3618 +  return value;
3619 + }
3620 +
3621 + //!muon-tau pair valueLookup
3622 + double
3623 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3624 +  double value = 0.0;
3625 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3626 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3627 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3628 +  else if(variable == "invMass"){
3629 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3630 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3631 +    value = (fourVector1 + fourVector2).M();
3632 +  }
3633  
3634 +  else if(variable == "chargeProduct"){
3635 +    value = object1->charge*object2->charge;
3636 +  }
3637 +
3638 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3639 +  value = applyFunction(function, value);
3640    return value;
3641   }
3642  
3643 + //!tau-track pair valueLookup
3644 + double
3645 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3646 +  double value = 0.0;
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 +  else if(variable == "chargeProduct"){
3650 +    value = object1->charge*object2->charge;
3651 +  }
3652  
3653 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3654 +  value = applyFunction(function, value);
3655 +  return value;
3656 + }
3657  
3658  
3659 + //!track-event pair valueLookup
3660   double
3661 < OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function){
3661 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3662  
3663    double value = 0.0;
3664    double pMag = sqrt(object1->pt * object1->pt +
3665 <                     object1->pz * object1->pz);  
3665 >                     object1->pz * object1->pz);
3666  
3667    if      (variable == "numPV")                      value = object2->numPV;
3668    else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3669    else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3670 <  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);  
3671 <  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;  
3670 >  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3671 >  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3672  
3673 <  else { std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3673 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3674  
3675    value = applyFunction(function, value);
3676  
3677    return value;
3678  
3679 < }  
3679 > }
3680 >
3681 > //!electron-trigobj pair valueLookup
3682 > double
3683 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3684 >
3685 >  double value = 0.0;
3686 >
3687 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3688 >  else if (variable == "match"){
3689 >    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3690 >      stringValue = object2->filter;
3691 >    else
3692 >      stringValue = "none";
3693 >  }
3694 >
3695 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3696 >
3697 >  value = applyFunction(function, value);
3698 >
3699 >  return value;
3700 >
3701 > }
3702 >
3703 > //!muon-trigobj pair valueLookup
3704 > double
3705 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3706 >
3707 >  double value = 0.0;
3708 >
3709 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3710 >
3711 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3712 >
3713 >  value = applyFunction(function, value);
3714 >
3715 >  return value;
3716 >
3717 > }
3718 >
3719 > //!stop valueLookup
3720 > double
3721 > OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3722 >
3723 >
3724 >  double value = 0.0;
3725 >
3726 >  if(variable == "ctau") value = object->ctau;
3727 >
3728 >  else if (variable == "d0"){
3729 >    double vx = object->vx - chosenVertex ()->x,
3730 >      vy = object->vy - chosenVertex ()->y,
3731 >      px = object->px,
3732 >      py = object->py,
3733 >      pt = object->pt;
3734 >    value = (-vx * py + vy * px) / pt;
3735 >  }
3736 >
3737 >  else if (variable == "dz"){
3738 >    double vx = object->vx - chosenVertex ()->x,
3739 >      vy = object->vy - chosenVertex ()->y,
3740 >      vz = object->vz - chosenVertex ()->z,
3741 >      px = object->px,
3742 >      py = object->py,
3743 >      pz = object->pz,
3744 >      pt = object->pt;
3745 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3746 >  }
3747 >
3748 >  else if (variable == "minD0"){
3749 >    double minD0=999;
3750 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3751 >      double vx = object->vx - vertex->x,
3752 >        vy = object->vy - vertex->y,
3753 >        px = object->px,
3754 >        py = object->py,
3755 >        pt = object->pt;
3756 >      value = (-vx * py + vy * px) / pt;
3757 >      if(abs(value) < abs(minD0)) minD0 = value;
3758 >    }
3759 >    value = minD0;
3760 >  }
3761 >  else if (variable == "minDz"){
3762 >    double minDz=999;
3763 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3764 >      double vx = object->vx - vertex->x,
3765 >        vy = object->vy - vertex->y,
3766 >        vz = object->vz - vertex->z,
3767 >        px = object->px,
3768 >        py = object->py,
3769 >        pz = object->pz,
3770 >        pt = object->pt;
3771 >      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3772 >      if(abs(value) < abs(minDz)) minDz = value;
3773 >    }
3774 >    value = minDz;
3775 >  }
3776 >  else if(variable == "distToVertex"){
3777 >    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3778 >                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3779 >                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3780 >  }
3781 >  else if (variable == "minDistToVertex"){
3782 >    double minDistToVertex=999;
3783 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3784 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3785 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3786 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
3787 >
3788 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3789 >    }
3790 >    value = minDistToVertex;
3791 >  }
3792 >  else if (variable == "distToVertexDifference"){
3793 >    double minDistToVertex=999;
3794 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3795 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3796 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3797 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
3798 >
3799 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3800 >    }
3801 >    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3802 >                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3803 >                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3804 >
3805 >    value = distToChosenVertex - minDistToVertex;
3806 >  }
3807 >
3808 >  else if (variable == "closestVertexRank"){
3809 >    double minDistToVertex=999;
3810 >    int vertex_rank = 0;
3811 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3812 >      vertex_rank++;
3813 >      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3814 >                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
3815 >                      (object->vz-vertex->z)*(object->vz-vertex->z));
3816 >
3817 >      if(abs(dist) < abs(minDistToVertex)){
3818 >        value = vertex_rank;
3819 >        minDistToVertex = dist;
3820 >      }
3821 >    }
3822 >  }
3823 >
3824 >
3825 >
3826 >
3827 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3828 >
3829 >  value = applyFunction(function, value);
3830 >
3831 >  return value;
3832 >
3833 > }
3834 >
3835 >
3836 >
3837  
3838   // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3839   // Return true iff no other tracks are found in this cone.
# Line 2611 | Line 3882 | OSUAnalysis::getTrkPtTrue (const BNtrack
3882  
3883   double
3884   OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3885 <  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.  
3886 <  if (!useTrackCaloRhoCorr_) return -99;  
3887 <  // if (!rhokt6CaloJetsHandle_) {
3888 <  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;  
3889 <  //   return -99;  
3885 >  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3886 >  if (!useTrackCaloRhoCorr_) return -99;
3887 >  // if (!rhokt6CaloJetsHandle_) {
3888 >  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3889 >  //   return -99;
3890    // }
3891 <  double radDeltaRCone = 0.5;  
3892 <  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.  
3893 <  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;  
3894 <  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);  
3895 <  return caloTotRhoCorrCalo;  
3896 <
3891 >  double radDeltaRCone = 0.5;
3892 >  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3893 >  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3894 >  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3895 >  return caloTotRhoCorrCalo;
3896 >
3897   }
3898  
3899  
# Line 2660 | Line 3931 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3931    double deltaRLowest = 999;
3932    int value = 0;
3933    if (DeadEcalVec.size() == 0) WriteDeadEcal();
3934 <  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3934 >  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3935      double eta = ecal->etaEcal;
3936      double phi = ecal->phiEcal;
3937 <    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
3937 >    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
3938      if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3939    }
3940    if (deltaRLowest<0.05) {value = 1;}
# Line 2671 | Line 3942 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3942    return value;
3943   }
3944  
3945 < // Returns the smallest DeltaR between the object and any generated true particle in the event.  
3945 > // Returns the smallest DeltaR between the object and any generated true particle in the event.
3946   template <class InputObject>
3947   double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3948    double genDeltaRLowest = 999.;
3949    for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3950      double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
3951      if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
3952 < }
3952 >  }
3953    return genDeltaRLowest;
3954   }
3955  
# Line 2691 | Line 3962 | OSUAnalysis::applyFunction(string functi
3962    else if(function == "log") value = log10(value);
3963  
3964    else if(function == "") value = value;
3965 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
3965 >  else{cout << "WARNING: invalid function '" << function << "'\n";}
3966  
3967    return value;
3968  
# Line 2701 | Line 3972 | OSUAnalysis::applyFunction(string functi
3972   template <class InputCollection>
3973   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
3974  
3975 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
3976 +    string obj1, obj2;
3977 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
3978 +    if (inputType==obj1 ||
3979 +        inputType==obj2) {
3980 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
3981 +      // and the inputType is a member of the pair.
3982 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
3983 +      // For example, if currentCut.inputCollection==electron-muon pairs,
3984 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
3985 +      return;
3986 +    }
3987 +  }
3988  
3989    for (uint object = 0; object != inputCollection->size(); object++){
3990  
3991 <
3992 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
2709 <
3991 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
3992 >    bool plotDecision = true;
3993  
3994      if(currentCut.inputCollection == inputType){
3995  
3996        vector<bool> subcutDecisions;
3997        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3998 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3999 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3998 >        string stringValue = "";
3999 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4000 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4001 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4002 >
4003        }
4004 <      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4004 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4005        else{
4006          bool tempDecision = true;
4007          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
# Line 2724 | Line 4010 | void OSUAnalysis::setObjectFlags(cut &cu
4010            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4011              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4012          }
4013 <        decision = tempDecision;
4013 >        cutDecision = tempDecision;
4014        }
4015 +      //invert the cut for plotting if this cut is a veto
4016 +      if(currentCut.isVeto) plotDecision = !cutDecision;
4017 +      else plotDecision = cutDecision;
4018      }
2730    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4019  
4020 +    //if(cutDecision != plotDecision && currentCut.variables.at(0) == "pt") cout << "---------------\n" << cutDecision << " " << plotDecision << endl;
4021 +    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4022  
4023 <    //set flags for objects that pass each cut AND all the previous cuts
4024 <    bool previousCumulativeFlag = true;
4023 >    //set flags for objects that pass this cut AND all the previous cuts
4024 >    bool previousCumulativeCutFlag = true;
4025      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4026 <      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4027 <      else{ previousCumulativeFlag = false; break;}
4026 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4027 >      else{ previousCumulativeCutFlag = false; break;}
4028      }
4029 <    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4029 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4030 >    bool previousCumulativePlotFlag = true;
4031 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4032 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4033 >      else{ previousCumulativePlotFlag = false; break;}
4034 >    }
4035 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4036  
4037 +    //if(inputType == "muons") cout << previousCumulativeCutFlag << " " << previousCumulativePlotFlag << " " << currentCut.variables.at(0) << "\n---------------\n\n";
4038 +    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4039  
4040    }
4041  
# Line 2746 | Line 4044 | void OSUAnalysis::setObjectFlags(cut &cu
4044  
4045   template <class InputCollection1, class InputCollection2>
4046   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
4047 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
4047 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, string inputType){
4048  
4049  
4050    bool sameObjects = false;
4051    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4052  
4053 +  // Get the strings for the two objects that make up the pair.
4054 +  string obj1Type, obj2Type;
4055 +  getTwoObjs(inputType, obj1Type, obj2Type);
4056 +  bool isTwoTypesOfObject = true;
4057 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
4058 +
4059 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
4060 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4061 +  if (currentCut.inputCollection == inputType) {
4062 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4063 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4064 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4065 +    }
4066 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4067 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4068 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4069 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4070 +      }
4071 +    }
4072 +  }
4073  
4074    int counter = 0;
4075 +
4076    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4077      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4078  
4079        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4080  
4081  
4082 <      bool decision = true;//object passes if this cut doesn't cut on that type of object
4082 >      bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4083 >      bool plotDecision = true;
4084  
4085        if(currentCut.inputCollection == inputType){
4086  
4087          vector<bool> subcutDecisions;
4088          for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4089 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4090 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4089 >          string stringValue = "";
4090 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4091 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4092 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4093          }
4094  
4095 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4095 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4096          else{
4097            bool tempDecision = subcutDecisions.at(0);
4098            for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
# Line 2779 | Line 4101 | void OSUAnalysis::setObjectFlags(cut &cu
4101              else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4102                tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4103            }
4104 <          decision = tempDecision;
4104 >          cutDecision = tempDecision;
4105          }
4106 +        //invert the cut for plotting if this cut is a veto
4107 +        if(currentCut.isVeto) plotDecision = !cutDecision;
4108 +        else plotDecision = cutDecision;
4109 +      }
4110 +      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4111 +      if (cutDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4112 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4113 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4114 +      }
4115 +      if (plotDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4116 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4117 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4118        }
2785      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4119  
4120 <      //set flags for objects that pass each cut AND all the previous cuts
4121 <      bool previousCumulativeFlag = true;
4120 >      //set flags for objects that pass this cut AND all the previous cuts
4121 >      bool previousCumulativeCutFlag = true;
4122        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4123 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
4124 <        else{ previousCumulativeFlag = false; break;}
4123 >        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4124 >        else{ previousCumulativeCutFlag = false; break;}
4125        }
4126 +      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4127 +
4128 +      bool previousCumulativePlotFlag = true;
4129 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4130 +        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4131 +        else{ previousCumulativePlotFlag = false; break;}
4132 +      }
4133 +      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4134 +      
4135        //apply flags for the components of the composite object as well
4136 <      bool currentCumulativeFlag = true;
4137 <      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
4138 <      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
4139 <      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
4140 <      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
4141 <      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
4136 >      bool currentCumulativeCutFlag = true;
4137 >      bool currentCumulativePlotFlag = true;
4138 >
4139 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4140 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4141 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4142 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4143 >
4144 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4145 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4146 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4147 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4148 >
4149 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));
4150 >
4151 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4152 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4153 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4154 >      }
4155 >
4156 >      if (currentCumulativePlotFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4157 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4158 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4159 >      }
4160  
4161        counter++;
2802    }
4162  
4163 +    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4164 +  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4165 +
4166 + }
4167 +
4168 +
4169 + bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4170 +  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4171 +  // all cuts up to currentCutIndex
4172 +  bool previousCumulativeFlag = true;
4173 +  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4174 +    bool tempFlag = false;
4175 +    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4176 +    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4177 +
4178 +    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4179 +    else {
4180 +      previousCumulativeFlag = false; break;
4181 +    }
4182    }
4183 +  return previousCumulativeFlag;
4184 + }
4185 +
4186 +
4187 +
4188  
4189 + template <class InputCollection>
4190 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4191 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4192 +
4193 +  if (BNTreeBranchVals_.count(parameters.name)==0) cout << "Error[assignTreeBranch]:  trying to assign value to " << parameters.name << " that does not have a branch set up.  Will likely seg fault." << endl;
4194 +  for (uint object = 0; object != inputCollection->size(); object++) {
4195 +
4196 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4197  
4198 +    string inputVariable = parameters.inputVariable;
4199 +    string function = "";
4200 +    string stringValue = "";
4201 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4202 +    BNTreeBranchVals_.at(parameters.name).push_back(value);
4203 +
4204 +  }
4205   }
4206  
4207  
4208   template <class InputCollection>
4209 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4209 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4210 >
4211  
4212    for (uint object = 0; object != inputCollection->size(); object++){
4213  
4214 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4214 >    //cout << "flags.at(object).second: " << flags.at(object).second << endl;
4215 >
4216 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4217  
4218      string currentString = parameters.inputVariables.at(0);
4219      string inputVariable = "";
4220      string function = "";
4221 <    if(currentString.find("(")==std::string::npos){
4221 >    if(currentString.find("(")==string::npos){
4222        inputVariable = currentString;// variable to cut on
4223      }
4224      else{
# Line 2826 | Line 4227 | void OSUAnalysis::fill1DHistogram(TH1* h
4227        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4228      }
4229  
4230 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
4230 >    string stringValue = "";
4231 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4232      histo->Fill(value,scaleFactor);
4233  
4234      if (printEventInfo_) {
4235 <      // Write information about event to screen, for testing purposes.  
4236 <      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;  
4235 >      // Write information about event to screen, for testing purposes.
4236 >      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
4237      }
4238 <    
4238 >
4239    }
4240   }
4241  
4242   template <class InputCollection1, class InputCollection2>
4243 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4243 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4244  
4245    bool sameObjects = false;
4246    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4247  
4248 <  int pairCounter = 0;
4248 >  int pairCounter = -1;
4249    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4250      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4251  
4252        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4253  
4254 +      pairCounter++;
4255        //only take objects which have passed all cuts and pairs which have passed all cuts
4256 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4257 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4258 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4256 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4257 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4258 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4259  
4260        string currentString = parameters.inputVariables.at(0);
4261        string inputVariable = "";
4262        string function = "";
4263 <      if(currentString.find("(")==std::string::npos){
4263 >      if(currentString.find("(")==string::npos){
4264          inputVariable = currentString;// variable to cut on
4265        }
4266        else{
# Line 2866 | Line 4269 | void OSUAnalysis::fill1DHistogram(TH1* h
4269          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4270        }
4271  
4272 <      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4272 >      string stringValue = "";
4273 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4274        histo->Fill(value,scaleFactor);
4275  
2872      pairCounter++;
4276      }
4277    }
4278  
# Line 2877 | Line 4280 | void OSUAnalysis::fill1DHistogram(TH1* h
4280  
4281  
4282   template <class InputCollection>
4283 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4283 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4284  
4285    for (uint object = 0; object != inputCollection->size(); object++){
4286  
4287 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4287 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4288  
4289 +    string stringValue = "";
4290      string currentString = parameters.inputVariables.at(0);
4291      string inputVariable = "";
4292      string function = "";
4293 <    if(currentString.find("(")==std::string::npos){
4293 >    if(currentString.find("(")==string::npos){
4294        inputVariable = currentString;// variable to cut on
4295      }
4296      else{
# Line 2894 | Line 4298 | void OSUAnalysis::fill2DHistogram(TH2* h
4298        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4299        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4300      }
4301 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
4301 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4302  
4303      currentString = parameters.inputVariables.at(1);
4304      inputVariable = "";
4305      function = "";
4306 <    if(currentString.find("(")==std::string::npos){
4306 >    if(currentString.find("(")==string::npos){
4307        inputVariable = currentString;// variable to cut on
4308      }
4309      else{
# Line 2908 | Line 4312 | void OSUAnalysis::fill2DHistogram(TH2* h
4312        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4313      }
4314  
4315 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
4315 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4316  
4317      histo->Fill(valueX,valueY,scaleFactor);
4318  
# Line 2917 | Line 4321 | void OSUAnalysis::fill2DHistogram(TH2* h
4321   }
4322  
4323   template <class InputCollection1, class InputCollection2>
4324 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4324 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4325  
4326    bool sameObjects = false;
4327    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4328  
4329 <  int pairCounter = 0;
4329 >  int pairCounter = -1;
4330    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4331      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4332  
4333        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4334  
4335 +      pairCounter++;
4336 +
4337        //only take objects which have passed all cuts and pairs which have passed all cuts
4338 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4339 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4340 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4338 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4339 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4340 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4341  
4342 +      string stringValue = "";
4343        string currentString = parameters.inputVariables.at(0);
4344        string inputVariable = "";
4345        string function = "";
4346 <      if(currentString.find("(")==std::string::npos){
4346 >      if(currentString.find("(")==string::npos){
4347          inputVariable = currentString;// variable to cut on
4348        }
4349        else{
# Line 2944 | Line 4351 | void OSUAnalysis::fill2DHistogram(TH2* h
4351          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4352          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4353        }
4354 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4354 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4355  
4356        currentString = parameters.inputVariables.at(1);
4357        inputVariable = "";
4358        function = "";
4359 <      if(currentString.find("(")==std::string::npos){
4359 >      if(currentString.find("(")==string::npos){
4360          inputVariable = currentString;// variable to cut on
4361        }
4362        else{
# Line 2957 | Line 4364 | void OSUAnalysis::fill2DHistogram(TH2* h
4364          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4365          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4366        }
4367 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4367 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4368  
4369  
4370        histo->Fill(valueX,valueY,scaleFactor);
4371  
2965      pairCounter++;
2966
4372      }
4373    }
4374  
# Line 2980 | Line 4385 | int OSUAnalysis::getGenMatchedParticleIn
4385  
4386      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4387      if(currentDeltaR > 0.05) continue;
4388 < //     cout << std::setprecision(3) << std::setw(20)
4389 < //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4390 < //          << std::setw(20)
4391 < //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4392 < //          << std::setw(20)
4393 < //          << "\tdeltaR = " << currentDeltaR
4394 < //          << std::setprecision(1)
4395 < //          << std::setw(20)
4396 < //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4397 < //          << std::setw(20)
4398 < //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4399 < //          << std::setw(20)
4400 < //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4388 >    //     cout << setprecision(3) << setw(20)
4389 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4390 >    //          << setw(20)
4391 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4392 >    //          << setw(20)
4393 >    //          << "\tdeltaR = " << currentDeltaR
4394 >    //          << setprecision(1)
4395 >    //          << setw(20)
4396 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4397 >    //          << setw(20)
4398 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4399 >    //          << setw(20)
4400 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4401      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4402        bestMatchIndex = mcparticle - mcparticles->begin();
4403        bestMatchDeltaR = currentDeltaR;
4404      }
4405  
4406    }
4407 < //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4408 < //   else cout << "no match found..." << endl;
4407 >  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4408 >  //   else cout << "no match found..." << endl;
4409    return bestMatchIndex;
4410  
4411   }
# Line 3054 | Line 4459 | int OSUAnalysis::findTauMotherIndex(cons
4459   // 20        strange baryon
4460   // 21        charm baryon
4461   // 22        bottom baryon
4462 < // 23        other
4462 > // 23        QCD string
4463 > // 24        other
4464  
4465   int OSUAnalysis::getPdgIdBinValue(int pdgId){
4466  
# Line 3078 | Line 4484 | int OSUAnalysis::getPdgIdBinValue(int pd
4484    else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4485    else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4486    else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4487 +  else if(absPdgId == 92  ) binValue = 23;
4488  
4489 <  else binValue = 23;
4489 >  else binValue = 24;
4490  
4491    return binValue;
4492  
# Line 3089 | Line 4496 | const BNprimaryvertex *
4496   OSUAnalysis::chosenVertex ()
4497   {
4498    const BNprimaryvertex *chosenVertex = 0;
4499 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
4500 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
4501 <                               cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
4499 >  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4500 >    flagPair vertexFlags;
4501 >    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4502 >      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4503 >        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4504 >        break;
4505 >      }
4506 >    }
4507      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4508 <      if(!vertexFlags.at(vertexIndex)) continue;
4508 >      if(!vertexFlags.at(vertexIndex).first) continue;
4509        chosenVertex = & primaryvertexs->at(vertexIndex);
4510        break;
4511      }
4512    }
4513 <  else {
4514 <    chosenVertex = &primaryvertexs->at(0);
3103 <  }
4513 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4514 >    chosenVertex = & primaryvertexs->at (0);
4515  
4516    return chosenVertex;
4517   }
# Line 3109 | Line 4520 | const BNmet *
4520   OSUAnalysis::chosenMET ()
4521   {
4522    const BNmet *chosenMET = 0;
4523 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
4524 <    vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
4525 <                            cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
4523 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4524 >    flagPair metFlags;
4525 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4526 >      if (cumulativeFlags.at("mets").at(i).size()){
4527 >        metFlags = cumulativeFlags.at("mets").at(i);
4528 >        break;
4529 >      }
4530 >    }
4531      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4532 <      if(!metFlags.at(metIndex)) continue;
4532 >      if(!metFlags.at(metIndex).first) continue;
4533        chosenMET = & mets->at(metIndex);
4534        break;
4535      }
4536    }
4537 <  else {
4538 <    chosenMET = &mets->at(0);
3123 <  }
4537 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4538 >    chosenMET = & mets->at (0);
4539  
4540    return chosenMET;
4541   }
# Line 3129 | Line 4544 | const BNelectron *
4544   OSUAnalysis::chosenElectron ()
4545   {
4546    const BNelectron *chosenElectron = 0;
4547 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
4548 <    vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
4549 <                                 cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
4547 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4548 >    flagPair electronFlags;
4549 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4550 >      if (cumulativeFlags.at("electrons").at(i).size()){
4551 >        electronFlags = cumulativeFlags.at("electrons").at(i);
4552 >        break;
4553 >      }
4554 >    }
4555      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4556 <      if(!electronFlags.at(electronIndex)) continue;
4556 >      if(!electronFlags.at(electronIndex).first) continue;
4557        chosenElectron = & electrons->at(electronIndex);
4558        break;
4559      }
4560    }
4561 <  else {
4562 <    chosenElectron = &electrons->at(0);
3143 <  }
4561 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4562 >    chosenElectron = & electrons->at (0);
4563  
4564    return chosenElectron;
4565   }
4566  
4567 +
4568   const BNmuon *
4569   OSUAnalysis::chosenMuon ()
4570   {
4571    const BNmuon *chosenMuon = 0;
4572 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
4573 <    vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
4574 <                             cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
4572 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4573 >    flagPair muonFlags;
4574 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4575 >      if (cumulativeFlags.at("muons").at(i).size()){
4576 >        muonFlags = cumulativeFlags.at("muons").at(i);
4577 >        break;
4578 >      }
4579 >    }
4580      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4581 <      if(!muonFlags.at(muonIndex)) continue;
4581 >      if(!muonFlags.at(muonIndex).first) continue;
4582        chosenMuon = & muons->at(muonIndex);
4583        break;
4584      }
4585    }
4586 <  else {
4587 <    chosenMuon = &muons->at(0);
3163 <  }
4586 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4587 >    chosenMuon = & muons->at (0);
4588  
4589    return chosenMuon;
4590   }
4591  
3168
4592   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines