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

Comparing UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc (file contents):
Revision 1.39 by jbrinson, Wed Mar 27 16:52:25 2013 UTC vs.
Revision 1.87 by biliu, Thu Jun 20 16:20:24 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 <  
23 < muonSFFile_ (cfg.getParameter<std::string> ("muonSFFile")),
24 <  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
25 <  electronSFID_ (cfg.getParameter<std::string> ("electronSFID")),
26 <  muonSF_ (cfg.getParameter<std::string> ("muonSF")),
27 <  dataset_ (cfg.getParameter<std::string> ("dataset")),
28 <  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 < {
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_);
48  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");
52
53  //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 59 | Line 76 | muonSFFile_ (cfg.getParameter<std::strin
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.find("pairs")==std::string::npos){ //just a single object
107 <      objectsToGet.push_back(tempInputCollection);
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 == "event-track pairs")   tempInputCollection = "track-event pairs";
112 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
113 >    if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
114 >    if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
115 >    if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
116 >    if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
117 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
118 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
119 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
120 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
121 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
122 >        int spaceIndex = tempInputCollection.find(" ");
123 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
124 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
125 >      }
126 >      else{
127 >        objectsToGet.push_back(tempInputCollection);
128 >      }
129        objectsToPlot.push_back(tempInputCollection);
130        objectsToCut.push_back(tempInputCollection);
131 <    }
132 <    else{//pair of objects, need to add them both to the things to objectsToGet
133 <      int dashIndex = tempInputCollection.find("-");
134 <      int spaceIndex = tempInputCollection.find(" ");
135 <      int secondWordLength = spaceIndex - dashIndex;
76 <      objectsToGet.push_back(tempInputCollection);
77 <      objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
78 <      objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
79 <      objectsToPlot.push_back(tempInputCollection);
80 <      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
81 <      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
131 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
132 >      string obj1;
133 >      string obj2;
134 >      getTwoObjs(tempInputCollection, obj1, obj2);
135 >      string obj2ToGet = getObjToGet(obj2);
136        objectsToCut.push_back(tempInputCollection);
137 <      objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
138 <      objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
137 >      objectsToCut.push_back(obj1);
138 >      objectsToCut.push_back(obj2);
139 >      objectsToPlot.push_back(tempInputCollection);
140 >      objectsToPlot.push_back(obj1);
141 >      objectsToPlot.push_back(obj2);
142 >      objectsToGet.push_back(tempInputCollection);
143 >      objectsToGet.push_back(obj1);
144 >      objectsToGet.push_back(obj2ToGet);
145 >    } // end else
146 >
147  
86      }
148  
149      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
150  
151      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
152  
153 +      vector<double> defaultValue;
154 +      defaultValue.push_back (-1.0);
155 +
156        histogram tempHistogram;
157        tempHistogram.inputCollection = tempInputCollection;
158        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
159        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
160 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
160 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
161 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
162 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
163        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
164  
165        histograms.push_back(tempHistogram);
166  
167      }
168 <  }
168 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
169 >
170    //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
171    sort( objectsToPlot.begin(), objectsToPlot.end() );
172    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
# Line 110 | Line 177 | muonSFFile_ (cfg.getParameter<std::strin
177    for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
178  
179      string currentObject = objectsToPlot.at(currentObjectIndex);
180 <    if(currentObject != "muons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
180 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
181  
182      histogram tempIdHisto;
183      histogram tempMomIdHisto;
184      histogram tempGmaIdHisto;
185      histogram tempIdVsMomIdHisto;
186 +    histogram tempIdVsGmaIdHisto;
187  
188      tempIdHisto.inputCollection = currentObject;
189      tempMomIdHisto.inputCollection = currentObject;
190      tempGmaIdHisto.inputCollection = currentObject;
191      tempIdVsMomIdHisto.inputCollection = currentObject;
192 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
193 +
194 +    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
195 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
196  
197      currentObject = currentObject.substr(0, currentObject.size()-1);
198      tempIdHisto.name = currentObject+"GenMatchId";
199      tempMomIdHisto.name = currentObject+"GenMatchMotherId";
200      tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
201      tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
202 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
203  
204      currentObject.at(0) = toupper(currentObject.at(0));
205      tempIdHisto.title = currentObject+" Gen-matched Particle";
206      tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
207      tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
208      tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
209 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
210 +
211  
212 <    int maxNum = 24;
212 >    int maxNum = 25;
213      vector<double> binVector;
214      binVector.push_back(maxNum);
215      binVector.push_back(0);
# Line 152 | Line 227 | muonSFFile_ (cfg.getParameter<std::strin
227      tempIdVsMomIdHisto.bins = binVector;
228      tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
229      tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
230 +    tempIdVsGmaIdHisto.bins = binVector;
231 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
232 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
233  
234      histograms.push_back(tempIdHisto);
235      histograms.push_back(tempMomIdHisto);
236      histograms.push_back(tempGmaIdHisto);
237      histograms.push_back(tempIdVsMomIdHisto);
238 +    histograms.push_back(tempIdVsGmaIdHisto);
239    }
240  
241  
# Line 172 | Line 251 | muonSFFile_ (cfg.getParameter<std::strin
251      //set triggers for this channel
252      vector<string> triggerNames;
253      triggerNames.clear();
254 +    vector<string> triggerToVetoNames;
255 +    triggerToVetoNames.clear();
256 +
257      tempChannel.triggers.clear();
258 +    tempChannel.triggersToVeto.clear();
259      if(channels_.at(currentChannel).exists("triggers")){
260        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
261        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
262          tempChannel.triggers.push_back(triggerNames.at(trigger));
263        objectsToGet.push_back("triggers");
264      }
265 <
265 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
266 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
267 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
268 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
269 >      objectsToGet.push_back("triggers");
270 >    }
271  
272  
273  
274      //create cutFlow for this channel
275      cutFlows_.push_back (new CutFlow (fs_, channelName));
276 <
277 <    //book a directory in the output file with the name of the channel
278 <    TFileDirectory subDir = fs_->mkdir( channelName );
191 <    directories.push_back(subDir);
192 <
193 <    std::map<std::string, TH1D*> oneDhistoMap;
194 <    oneDHists_.push_back(oneDhistoMap);
195 <    std::map<std::string, TH2D*> twoDhistoMap;
196 <    twoDHists_.push_back(twoDhistoMap);
197 <
198 <
199 <
200 <    //book all histograms included in the configuration
201 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
202 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
203 <      int numBinsElements = currentHistogram.bins.size();
204 <      int numInputVariables = currentHistogram.inputVariables.size();
205 <
206 <      if(numBinsElements != 3 && numBinsElements !=6) {
207 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
208 <        exit(0);
209 <      }
210 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
211 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
212 <        exit(0);
213 <      }
214 <      else if(numBinsElements == 3){
215 <        oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
216 <      }
217 <      else if(numBinsElements == 6){
218 <        twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2),currentHistogram.bins.at(3),currentHistogram.bins.at(4),currentHistogram.bins.at(5));
219 <
220 <      }
221 <
222 <
223 <      if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
224 <
225 < // bin      particle type
226 < // ---      -------------
227 < //  0        unmatched
228 < //  1        u
229 < //  2        d
230 < //  3        s
231 < //  4        c
232 < //  5        b
233 < //  6        t
234 < //  7        e
235 < //  8        mu
236 < //  9        tau
237 < // 10        nu
238 < // 11        g
239 < // 12        gamma
240 < // 13        Z
241 < // 14        W
242 < // 15        light meson
243 < // 16        K meson
244 < // 17        D meson
245 < // 18        B meson
246 < // 19        light baryon
247 < // 20        strange baryon
248 < // 21        charm baryon
249 < // 22        bottom baryon
250 < // 23        other
251 <
252 <      vector<TString> labelArray;
253 <      labelArray.push_back("unmatched");
254 <      labelArray.push_back("u");
255 <      labelArray.push_back("d");
256 <      labelArray.push_back("s");
257 <      labelArray.push_back("c");
258 <      labelArray.push_back("b");
259 <      labelArray.push_back("t");
260 <      labelArray.push_back("e");
261 <      labelArray.push_back("#mu");
262 <      labelArray.push_back("#tau");
263 <      labelArray.push_back("#nu");
264 <      labelArray.push_back("g");
265 <      labelArray.push_back("#gamma");
266 <      labelArray.push_back("Z");
267 <      labelArray.push_back("W");
268 <      labelArray.push_back("light meson");
269 <      labelArray.push_back("K meson");
270 <      labelArray.push_back("D meson");
271 <      labelArray.push_back("B meson");
272 <      labelArray.push_back("light baryon");
273 <      labelArray.push_back("strange baryon");
274 <      labelArray.push_back("charm baryon");
275 <      labelArray.push_back("bottom baryon");
276 <      labelArray.push_back("other");
277 <
278 <      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
279 <        if(currentHistogram.name.find("GenMatchIdVsMotherId")==std::string::npos) {
280 <          oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
281 <        }
282 <        else {
283 <          twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
284 <          twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
285 <        }
286 <      }
287 <      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=std::string::npos) {
288 <        twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->CenterTitle();
289 <        twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->CenterTitle();
290 <      }
291 <
292 <    }
293 <
294 <    //book a histogram for the number of each object type to be plotted
295 <
296 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
297 <      string currentObject = objectsToPlot.at(currentObjectIndex);
298 <      int maxNum = 10;
299 <      if(currentObject == "mcparticles") maxNum = 50;
300 <      else if(currentObject == "primaryvertexs") maxNum = 50;
301 <      else if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
302 <      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
303 <      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
304 <
305 <      else if(currentObject == "electron-track pairs") currentObject = "electronTrackPairs";
306 <      else if(currentObject == "muon-track pairs") currentObject = "muonTrackPairs";
307 <      else if(currentObject == "muon-tau pairs") currentObject = "muonTauPairs";
308 <      else if(currentObject == "tau-tau pairs") currentObject = "ditauPairs";
309 <
310 <      currentObject.at(0) = toupper(currentObject.at(0));
311 <      string histoName = "num" + currentObject;
312 <
313 <      if(histoName == "numPrimaryvertexs"){
314 <        string newHistoName = histoName + "BeforePileupCorrection";
315 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
316 <        newHistoName = histoName + "AfterPileupCorrection";
317 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
318 <      }
319 <      else
320 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
321 <    }
322 <
323 <
324 <
325 <
276 >    vector<TFileDirectory> directories; //vector of directories in the output file.
277 >    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
278 >    vector<string> subSubDirNames;//subdirectories in each channel.
279      //get list of cuts for this channel
280      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
281  
282 +
283      //loop over and parse all cuts
284      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
285        cut tempCut;
286        //store input collection for cut
287        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
288 +      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
289 +      if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
290 +      if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
291 +      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
292 +      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
293 +      if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
294 +      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
295 +      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
296 +      if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
297 +      if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
298 +      if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
299 +      if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
300 +      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
301 +      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
302 +      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
303        tempCut.inputCollection = tempInputCollection;
304 <      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
305 <        objectsToGet.push_back(tempInputCollection);
304 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
305 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
306 >          int spaceIndex = tempInputCollection.find(" ");
307 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
308 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
309 >        }
310 >        else{
311 >          objectsToGet.push_back(tempInputCollection);
312 >        }
313          objectsToCut.push_back(tempInputCollection);
314        }
315 <      else{//pair of objects, need to add them both to the things to objectsToGet
316 <        int dashIndex = tempInputCollection.find("-");
317 <        int spaceIndex = tempInputCollection.find(" ");
318 <        int secondWordLength = spaceIndex - dashIndex;
319 <        objectsToGet.push_back(tempInputCollection);
344 <        objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
345 <        objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
315 >      else{//pair of objects, need to add them both to objectsToGet
316 >        string obj1;
317 >        string obj2;
318 >        getTwoObjs(tempInputCollection, obj1, obj2);
319 >        string obj2ToGet = getObjToGet(obj2);
320          objectsToCut.push_back(tempInputCollection);
321 <        objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
322 <        objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
321 >        objectsToCut.push_back(obj1);
322 >        objectsToCut.push_back(obj2);
323 >        objectsToGet.push_back(tempInputCollection);
324 >        objectsToGet.push_back(obj1);
325 >        objectsToGet.push_back(obj2ToGet);
326  
327        }
328  
# Line 353 | Line 330 | muonSFFile_ (cfg.getParameter<std::strin
330  
331        //split cut string into parts and store them
332        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
333 <      std::vector<string> cutStringVector = splitString(cutString);
333 >      vector<string> cutStringVector = splitString(cutString);
334        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
335 <        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
335 >        cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
336          exit(0);
337        }
338        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
339        for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
340          int indexOffset = 4 * subcutIndex;
341          string currentVariableString = cutStringVector.at(indexOffset);
342 <        if(currentVariableString.find("(")==std::string::npos){
342 >        if(currentVariableString.find("(")==string::npos){
343            tempCut.functions.push_back("");//no function was specified
344            tempCut.variables.push_back(currentVariableString);// variable to cut on
345          }
# Line 373 | Line 350 | muonSFFile_ (cfg.getParameter<std::strin
350          }
351          tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
352          tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
353 +        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
354          if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
355        }
356  
357        //get number of objects required to pass cut for event to pass
358        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
359 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
359 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
360        if(numberRequiredVector.size()!=2){
361 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
361 >        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
362          exit(0);
363        }
364  
# Line 388 | Line 366 | muonSFFile_ (cfg.getParameter<std::strin
366        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
367        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
368  
369 <
369 >      //Set up vectors to store the directories and subDirectories for each channel.
370 >      string subSubDirName;
371        string tempCutName;
372        if(cuts_.at(currentCut).exists("alias")){
373          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
374 +        subSubDirName = "After " + tempCutName + " Cut Applied";
375        }
376        else{
377          //construct string for cutflow table
# Line 399 | Line 379 | muonSFFile_ (cfg.getParameter<std::strin
379          string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
380          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
381          tempCutName = cutName;
382 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
383        }
403      tempCut.name = tempCutName;
384  
385 +      tempCut.isVeto = false;
386 +      if(cuts_.at(currentCut).exists("isVeto")){
387 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
388 +        if (isVeto == true) tempCut.isVeto = true;
389 +      }
390 +      subSubDirNames.push_back(subSubDirName);
391 +      tempCut.name = tempCutName;
392  
393        tempChannel.cuts.push_back(tempCut);
394  
395  
409
396      }//end loop over cuts
397  
398 +    vector<map<string, TH1D*>> oneDHistsTmp;
399 +    vector<map<string, TH2D*>> twoDHistsTmp;
400 +    //book a directory in the output file with the name of the channel
401 +    TFileDirectory subDir = fs_->mkdir( channelName );
402 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
403 +    if(GetPlotsAfterEachCut_){
404 +      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
405 +        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
406 +        directories.push_back(subSubDir);
407 +        map<string, TH1D*> oneDhistoMap;
408 +        oneDHistsTmp.push_back(oneDhistoMap);
409 +        map<string, TH2D*> twoDhistoMap;
410 +        twoDHistsTmp.push_back(twoDhistoMap);
411 +      }
412 +      treeDirectories.push_back(subDir);
413 +      oneDHists_.push_back(oneDHistsTmp);
414 +      twoDHists_.push_back(twoDHistsTmp);
415 +    }
416 +    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
417 +    else{
418 +      map<string, TH1D*> oneDhistoMap;
419 +      oneDHistsTmp.push_back(oneDhistoMap);
420 +      map<string, TH2D*> twoDhistoMap;
421 +      twoDHistsTmp.push_back(twoDhistoMap);
422 +      oneDHists_.push_back(oneDHistsTmp);
423 +      twoDHists_.push_back(twoDHistsTmp);
424 +      directories.push_back(subDir);
425 +      treeDirectories.push_back(subDir);
426 +
427 +    }
428 +
429 +    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
430 +      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
431 +      BNTrees_.push_back(newTree);
432 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
433 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
434 +        vector<float> newVec;
435 +        BNTreeBranchVals_[currentVar.name] = newVec;
436 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
437 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
438 +    }
439 +
440 +    //book all histograms included in the configuration
441 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
442 +
443 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
444 +
445 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
446 +        int numBinsElements = currentHistogram.bins.size();
447 +        int numInputVariables = currentHistogram.inputVariables.size();
448 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
449 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
450 +
451 +        if(numBinsElements == 1){
452 +          if(numBinEdgesX > 1){
453 +            if(numBinEdgesY > 1)
454 +              numBinsElements = 6;
455 +            else
456 +              numBinsElements = 3;
457 +          }
458 +        }
459 +        if(numBinsElements != 3 && numBinsElements !=6){
460 +          cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
461 +          exit(0);
462 +        }
463 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
464 +          cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
465 +          exit(0);
466 +        }
467 +        else if(numBinsElements == 3){
468 +          if (currentHistogram.bins.size () == 3)
469 +            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));
470 +          else
471 +            {
472 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
473 +            }
474 +        }
475 +        else if(numBinsElements == 6){
476 +          if (currentHistogram.bins.size () == 6)
477 +            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));
478 +          else
479 +            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 ());
480 +        }
481 +
482 +
483 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
484 +
485 +        // bin      particle type
486 +        // ---      -------------
487 +        //  0        unmatched
488 +        //  1        u
489 +        //  2        d
490 +        //  3        s
491 +        //  4        c
492 +        //  5        b
493 +        //  6        t
494 +        //  7        e
495 +        //  8        mu
496 +        //  9        tau
497 +        // 10        nu
498 +        // 11        g
499 +        // 12        gamma
500 +        // 13        Z
501 +        // 14        W
502 +        // 15        light meson
503 +        // 16        K meson
504 +        // 17        D meson
505 +        // 18        B meson
506 +        // 19        light baryon
507 +        // 20        strange baryon
508 +        // 21        charm baryon
509 +        // 22        bottom baryon
510 +        // 23        QCD string
511 +        // 24        other
512 +
513 +        vector<TString> labelArray;
514 +        labelArray.push_back("unmatched");
515 +        labelArray.push_back("u");
516 +        labelArray.push_back("d");
517 +        labelArray.push_back("s");
518 +        labelArray.push_back("c");
519 +        labelArray.push_back("b");
520 +        labelArray.push_back("t");
521 +        labelArray.push_back("e");
522 +        labelArray.push_back("#mu");
523 +        labelArray.push_back("#tau");
524 +        labelArray.push_back("#nu");
525 +        labelArray.push_back("g");
526 +        labelArray.push_back("#gamma");
527 +        labelArray.push_back("Z");
528 +        labelArray.push_back("W");
529 +        labelArray.push_back("light meson");
530 +        labelArray.push_back("K meson");
531 +        labelArray.push_back("D meson");
532 +        labelArray.push_back("B meson");
533 +        labelArray.push_back("light baryon");
534 +        labelArray.push_back("strange baryon");
535 +        labelArray.push_back("charm baryon");
536 +        labelArray.push_back("bottom baryon");
537 +        labelArray.push_back("QCD string");
538 +        labelArray.push_back("other");
539 +
540 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
541 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
542 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
543 +          }
544 +          else {
545 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
546 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
547 +          }
548 +        }
549 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
550 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
551 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
552 +        }
553 +
554 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
555 +
556 +
557 +      // Book a histogram for the number of each object type to be plotted.
558 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
559 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
560 +        string currentObject = objectsToPlot.at(currentObjectIndex);
561 +        int maxNum = 10;
562 +        if(currentObject == "mcparticles") maxNum = 50;
563 +        else if(currentObject == "primaryvertexs") maxNum = 50;
564 +
565 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
566 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
567 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
568 +        else if(currentObject == "electron-photon pairs")       currentObject = "electronPhotonPairs";
569 +        else if(currentObject == "muon-photon pairs")       currentObject = "muonPhotonPairs";
570 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
571 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
572 +        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
573 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
574 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
575 +        else if(currentObject == "photon-jet pairs")            currentObject = "photonJetPairs";
576 +        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
577 +        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
578 +        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
579 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
580 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
581 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
582 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
583 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
584 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
585 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
586 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
587 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
588 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
589 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
590 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
591 +
592 +        currentObject.at(0) = toupper(currentObject.at(0));
593 +        string histoName = "num" + currentObject;
594 +
595 +        if(histoName == "numPrimaryvertexs"){
596 +          string newHistoName = histoName + "BeforePileupCorrection";
597 +          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);
598 +          newHistoName = histoName + "AfterPileupCorrection";
599 +          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);
600 +        }
601 +        else
602 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
603 +      }
604 +    }//end of loop over directories
605      channels.push_back(tempChannel);
606      tempChannel.cuts.clear();
414
607    }//end loop over channels
608  
609  
# Line 422 | Line 614 | muonSFFile_ (cfg.getParameter<std::strin
614    sort( objectsToCut.begin(), objectsToCut.end() );
615    objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
616  
617 +  produces<map<string, bool> > ("channelDecisions");
618 +
619 + } // end constructor OSUAnalysis::OSUAnalysis()
620  
426 }
621  
622   OSUAnalysis::~OSUAnalysis ()
623   {
624 +
625    // Destroying the CutFlow objects causes the cut flow numbers and time
626    // information to be printed to standard output.
627    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
# Line 435 | Line 630 | OSUAnalysis::~OSUAnalysis ()
630   }
631  
632   void
633 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
633 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
634   {
635 <
635 >  //cout << "**********************\n\n\n";
636    // Retrieve necessary collections from the event.
637  
638 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
638 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
639      event.getByLabel (triggers_, triggers);
640  
641 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
641 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
642 >    event.getByLabel (trigobjs_, trigobjs);
643 >
644 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
645      event.getByLabel (jets_, jets);
646  
647 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
647 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
648      event.getByLabel (muons_, muons);
649  
650 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
650 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
651      event.getByLabel (electrons_, electrons);
652  
653 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
653 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
654      event.getByLabel (events_, events);
655  
656 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
656 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
657      event.getByLabel (taus_, taus);
658  
659 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
659 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
660      event.getByLabel (mets_, mets);
661  
662 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
662 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
663      event.getByLabel (tracks_, tracks);
664  
665 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
665 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
666      event.getByLabel (genjets_, genjets);
667  
668 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
668 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
669      event.getByLabel (mcparticles_, mcparticles);
670  
671 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
671 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
672      event.getByLabel (primaryvertexs_, primaryvertexs);
673  
674 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
674 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
675      event.getByLabel (bxlumis_, bxlumis);
676  
677 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
677 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
678      event.getByLabel (photons_, photons);
679  
680 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
680 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
681      event.getByLabel (superclusters_, superclusters);
682  
683 +  if (datasetType_ == "signalMC"){
684 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
685 +      event.getByLabel (stops_, stops);
686 +  }
687 +
688 +  if (useTrackCaloRhoCorr_) {
689 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
690 +    // This rho collection is not available in all BEANs.
691 +    // For description of rho values for different jet reconstruction algorithms, see
692 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
693 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
694 +  }
695 +
696 +  double masterScaleFactor = 1.0;
697 +
698    //get pile-up event weight
699 <  double scaleFactor = 1.00;
700 <  if(doPileupReweighting_ && datasetType_ != "data")
701 <    scaleFactor = puWeight_->at (events->at (0).numTruePV);
699 >  if (doPileupReweighting_ && datasetType_ != "data") {
700 >    //for "data" datasets, the numTruePV is always set to -1
701 >    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
702 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
703 >  }
704  
705 +  stopCTauScaleFactor_ = 1.0;
706 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
707 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
708 +  masterScaleFactor *= stopCTauScaleFactor_;
709  
710    //loop over all channels
711  
712 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
713    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
714      channel currentChannel = channels.at(currentChannelIndex);
715  
# Line 497 | Line 717 | OSUAnalysis::analyze (const edm::Event &
717      counterMap passingCounter;
718      cumulativeFlags.clear ();
719  
720 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
721 +         iter != BNTreeBranchVals_.end(); iter++) {
722 +      iter->second.clear();  // clear array
723 +    }
724 +
725      bool triggerDecision = true;
726 <    if(currentChannel.triggers.size() != 0){  //triggers specified
727 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
726 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
727 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
728        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
729      }
730  
731      //loop over all cuts
507
508
509
732      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
733        cut currentCut = currentChannel.cuts.at(currentCutIndex);
512
734        for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
735          string currentObject = objectsToCut.at(currentObjectIndex);
736  
737          //initialize maps to get ready to set cuts
738 <        individualFlags[currentObject].push_back (vector<bool> ());
739 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
738 >        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
739 >        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
740  
741        }
742        for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
# Line 524 | Line 745 | OSUAnalysis::analyze (const edm::Event &
745          int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
746  
747  
748 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
749 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
748 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
749 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
750 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
751 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
752 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
753          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
754          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
755          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 537 | Line 761 | OSUAnalysis::analyze (const edm::Event &
761          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
762          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
763          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
764 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
765 +
766  
767  
768          else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
769                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
770                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
771                                                                     "muon-muon pairs");
772 +
773 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
774 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
775 +                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
776 +                                                                             "muon-secondary muon pairs");
777 +
778 +        else if(currentObject == "muon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
779 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
780 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
781 +                                                                             "muon-secondary jet pairs");
782 +        else if(currentObject == "photon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
783 +                                                                             cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
784 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
785 +                                                                             "photon-secondary jet pairs");
786 +
787 +        else if(currentObject == "electron-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
788 +                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
789 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
790 +                                                                             "electron-secondary jet pairs");
791 +
792 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
793 +                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
794 +                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
795 +                                                                                     "electron-secondary electron pairs");
796 +
797          else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
798                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
799                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
# Line 551 | Line 802 | OSUAnalysis::analyze (const edm::Event &
802                                                                         cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
803                                                                         cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
804                                                                         "electron-muon pairs");
805 <        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(), \
806 <                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
807 <                                                                       cumulativeFlags.at("tracks").at(flagsForPairCutsIndex), \
808 <                                                                       "electron-track pairs");
809 <        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(), \
810 <                                                                        cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
811 <                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex), \
812 <                                                                        "muon-track pairs");
813 <        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(), \
814 <                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
815 <                                                                    cumulativeFlags.at("taus").at(flagsForPairCutsIndex), \
816 <                                                                    "muon-tau pairs");
817 <
818 <        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),taus.product(), \
819 <                                                                        cumulativeFlags.at("taus").at(flagsForPairCutsIndex), \
820 <                                                                        cumulativeFlags.at("taus").at(flagsForPairCutsIndex), \
821 <                                                                        "tau-tau pairs");
822 <
805 >        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
806 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
807 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
808 >                                                                 "jet-jet pairs");
809 >        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
810 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
811 >                                                                 cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex),\
812 >                                                                 "jet-secondary jet pairs");
813 >        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
814 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
815 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
816 >                                                                      "electron-jet pairs");
817 >        else if(currentObject == "electron-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), \
818 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
819 >                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
820 >                                                                      "electron-photon pairs");
821 >        else if(currentObject == "photon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
822 >                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
823 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
824 >                                                                      "photon-jet pairs");
825 >        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
826 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
827 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
828 >                                                                  "muon-jet pairs");
829 >        else if(currentObject == "muon-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
830 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
831 >                                                                  cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
832 >                                                                  "muon-photon pairs");
833 >        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
834 >                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
835 >                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
836 >                                                                     "track-event pairs");
837 >        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
838 >                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
839 >                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
840 >                                                                        "electron-track pairs");
841 >        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
842 >                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
843 >                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
844 >                                                                    "muon-track pairs");
845 >        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
846 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
847 >                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
848 >                                                                  "muon-tau pairs");
849 >        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
850 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
851 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
852 >                                                                 "tau-tau pairs");
853 >        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
854 >                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
855 >                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
856 >                                                                   "tau-track pairs");
857 >        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
858 >                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
859 >                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
860 >                                                                          "electron-trigobj pairs");
861 >        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
862 >                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
863 >                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
864 >                                                                      "muon-trigobj pairs");
865  
866 +        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
867        }
868  
869  
870  
871      }//end loop over all cuts
578
579
872      //use cumulative flags to apply cuts at event level
873  
874 +    //a vector to store cumulative cut descisions after each cut.
875 +    vector<bool> eventPassedPreviousCuts;
876      bool eventPassedAllCuts = true;
583
877      //apply trigger (true if none were specified)
878      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
879  
587
588
880      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
881  
882        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 593 | Line 884 | OSUAnalysis::analyze (const edm::Event &
884        int numberPassing = 0;
885  
886        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
887 <          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
887 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
888        }
598
889        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
890        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
601
891        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
892 <
892 >      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
893      }
894 +    double scaleFactor = masterScaleFactor;
895  
896 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
897 +    if(applyLeptonSF_ && datasetType_ != "data"){
898 +      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
899 +        flagPair muonFlags;
900 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
901 +          if (cumulativeFlags.at("muons").at(i).size()){
902 +            muonFlags = cumulativeFlags.at("muons").at(i);
903 +            break;
904 +          }
905 +        }
906 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
907 +          if(!muonFlags.at(muonIndex).second) continue;
908 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
909 +        }
910 +      }
911 +      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
912 +        flagPair electronFlags;
913 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
914 +          if (cumulativeFlags.at("electrons").at(i).size()){
915 +            electronFlags = cumulativeFlags.at("electrons").at(i);
916 +            break;
917 +          }
918 +        }
919 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
920 +          if(!electronFlags.at(electronIndex).second) continue;
921 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
922 +        }
923 +      }
924 +    }
925 +    if(applyBtagSF_ && datasetType_ != "data"){
926 +     if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
927 +       flagPair jetFlags;
928 +        vector<double> jetSFs;
929 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
930 +          if (cumulativeFlags.at("jets").at(i).size()){
931 +            jetFlags = cumulativeFlags.at("jets").at(i);
932 +            break;
933 +          }
934 +        }
935 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
936 +          if(!jetFlags.at(jetIndex).second) continue;
937 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour);
938 +          jetSFs.push_back(jetSFTmp);
939 +        }
940 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_, maxBtag_ );
941 +      }
942 +    }
943 +    scaleFactor *= muonScaleFactor_;
944 +    scaleFactor *= electronScaleFactor_;
945 +    scaleFactor *= bTagScaleFactor_;
946      cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
947  
948 +    if (printEventInfo_) {
949 +      // Write information about event to screen, for testing purposes.
950 +      cout << "Event passed all cuts in channel " <<  currentChannel.name
951 +           << ": run="  << events->at(0).run
952 +           << "  lumi=" << events->at(0).lumi
953 +           << "  event=" << events->at(0).evt
954 +           << endl;
955 +    }
956  
957  
958 <    if(!eventPassedAllCuts)continue;
958 >    //filling histograms
959 >    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
960 >      uint currentDir;
961 >      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
962 >      else{
963 >        currentDir = currentCut;
964 >      }
965  
612    if (printEventInfo_) {
613      // Write information about event to screen, for testing purposes.  
614      cout << "Event passed all cuts in channel " <<  currentChannel.name
615           << ": run="  << events->at(0).run
616           << "  lumi=" << events->at(0).lumi
617           << "  event=" << events->at(0).evt
618           << endl;  
619    }
966  
967 +      if(eventPassedPreviousCuts.at(currentDir)){
968  
969 < //     if(datasetType_ != "data") {
970 < //       scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
624 < //       scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
625 < //     }
969 >        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
970 >          histogram currentHistogram = histograms.at(histogramIndex);
971  
972 <    //filling histograms
973 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
974 <      histogram currentHistogram = histograms.at(histogramIndex);
972 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) cout << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
973 >
974 >          if(currentHistogram.inputVariables.size() == 1){
975 >            TH1D* histo;
976 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
977 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
978 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
979 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
980 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
981 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
982 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
983 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
984 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
985 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
986 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
987 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
988 >             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
989 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
990 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
991 >             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
992 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
993 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
994 >             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
995 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
996 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
997 >
998 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
999 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
1000 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
1001 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1002 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
1003 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
1004 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1005 >             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1006 >                                                                                                     cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1007 >                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1008 >
1009 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1010 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1011 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1012 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
1013 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
1014 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1015 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
1016 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1017 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1018 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(), \
1019 >                                                                                              cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1020 >                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1021 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
1022 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1023 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1024 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(), \
1025 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1026 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1027 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(), \
1028 >                                                                                          cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1029 >                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1030 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1031 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1032 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1033 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1034 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1035 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1036 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1037 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1038 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1039 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1040 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1041 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1042 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1043 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1044 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1045 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1046 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1047 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1048 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1049 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1050 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1051 >
1052 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1053 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1054 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1055 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1056 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1057 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1058 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1059 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1060 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1061 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1062 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1063 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1064 >          }
1065 >          else if(currentHistogram.inputVariables.size() == 2){
1066 >            TH2D* histo;
1067 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1068 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1069 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1070 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1071 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1072 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1073 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1074 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1075 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1076 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1077 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1078 >            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1079 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1080 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1081 >            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1082 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1083 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1084 >            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1085 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1086 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1087 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1088 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1089 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1090 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1091 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1092 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1093 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1094 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1095 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1096 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1097 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1098 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1099 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1100 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1101 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1102 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1103 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1104 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(), \
1105 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1106 >                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1107 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1108 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1109 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1110 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1111 >                                                                                          cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1112 >                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1113 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1114 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1115 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1116 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1117 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1118 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1119 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1120 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1121 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1122 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1123 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1124 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1125 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1126 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1127 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1128 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1129 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1130 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1131 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1132 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1133 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1134 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1135 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1136 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1137 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1138 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1139 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1140 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1141 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1142 >                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1143 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1144 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1145 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1146 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1147 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1148 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1149 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1150 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1151 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1152 >          }
1153  
631      if(currentHistogram.inputVariables.size() == 1){
632        TH1D* histo;
633        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
634
635
636
637        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
638         else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
639        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
640                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
641                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
642        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
643        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
644                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
645                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
646        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
647                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
648                                                                                              cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
649        else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(), \
650                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),
651                                                                                           cumulativeFlags.at("electron-track pairs").back(),scaleFactor);
652        else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(), \
653                                                                                            cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),
654                                                                                            cumulativeFlags.at("muon-track pairs").back(),scaleFactor);
655        else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(), \
656                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),
657                                                                                        cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);
658
659        else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(), \
660                                                                                            cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),
661                                                                                            cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);
662        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
663        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
664        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
665        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
666        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
667        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
668        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
669        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
670        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
671        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
672      }
673      else if(currentHistogram.inputVariables.size() == 2){
674        TH2D* histo;
675        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
676
677
678
679        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
680        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
681        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
682                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
683                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
684        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
685        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
686                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
687                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
688        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
689                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
690                                                                                               cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
691        else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(), \
692                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(), \
693                                                                                           cumulativeFlags.at("electron-track pairs").back(),scaleFactor);
694        else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(), \
695                                                                                            cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(), \
696                                                                                            cumulativeFlags.at("muon-track pairs").back(),scaleFactor);
697        else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(), \
698                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(), \
699                                                                                        cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);
700        else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(), \
701                                                                                            cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(), \
702                                                                                            cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);
703        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
704        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
705        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
706        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
707        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
708        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
709        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
710        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
711        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
712        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
713      }
714    }
715
716    //fills histograms with the sizes of collections
717    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
718      string currentObject = objectsToPlot.at(currentObjectIndex);
719
720      string objectToPlot = "";
721
722      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
723      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
724      else if(currentObject == "electron-muon pairs") objectToPlot = "electronMuonPairs";
725      else if(currentObject == "electron-track pairs") objectToPlot = "electronTrackPairs";
726      else if(currentObject == "muon-track pairs") objectToPlot = "muonTrackPairs";
727      else if(currentObject == "muon-tau pairs") objectToPlot = "muonTauPairs";
728      else if(currentObject == "tau-tau pairs") objectToPlot = "ditauPairs";
729      else objectToPlot = currentObject;
730      string tempCurrentObject = objectToPlot;
731      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
732      string histoName = "num" + tempCurrentObject;
733
734
735
736
737      //set position of primary vertex in event, in order to calculate quantities relative to it
738      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
739        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
740        int numToPlot = 0;
741        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
742          if(lastCutFlags.at(currentFlag)) numToPlot++;
743        }
744        if(objectToPlot == "primaryvertexs"){
745          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
746          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1154          }
748        else
749          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
750      }
751      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
752      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
753      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
754      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
755      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
756      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
757      else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
758      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
759      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
760      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
761      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
762      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
763      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
764      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
765      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
766      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
767      else if(objectToPlot == "primaryvertexs"){
768        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
769        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
770      }
1155  
772    }
1156  
1157 +        //fills histograms with the sizes of collections
1158 +        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1159 +
1160 +          string currentObject = objectsToPlot.at(currentObjectIndex);
1161 +          string objectToPlot = "";
1162  
1163 +          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1164 +          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1165 +          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1166 +          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1167 +          else if(currentObject == "electron-photon pairs")                objectToPlot = "electronPhotonPairs";
1168 +          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1169 +          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1170 +          else if(currentObject == "muon-photon pairs")                     objectToPlot = "muonPhotonPairs";
1171 +          else if(currentObject == "photon-jet pairs")                     objectToPlot = "photonJetPairs";
1172 +          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1173 +          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1174 +          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1175 +          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1176 +          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1177 +          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1178 +          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1179 +          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1180 +          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1181 +          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1182 +          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1183 +          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1184 +          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1185 +          else if(currentObject == "photon-secondary jet pairs")       objectToPlot = "photonSecondaryJetPairs";
1186 +          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1187 +          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1188 +          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1189 +          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1190 +          else objectToPlot = currentObject;
1191 +
1192 +          string tempCurrentObject = objectToPlot;
1193 +          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1194 +          string histoName = "num" + tempCurrentObject;
1195 +
1196 +
1197 +          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1198 +            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1199 +            int numToPlot = 0;
1200 +            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1201 +              if(lastCutFlags.at(currentFlag).second) numToPlot++;
1202 +            }
1203 +
1204 +            if(objectToPlot == "primaryvertexs"){
1205 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1206 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1207 +            }
1208 +            else {
1209 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1210 +            }
1211 +          }
1212 +        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1213  
1214  
1215 <  } //end loop over channel
1215 >      } // end if(eventPassedPreviousCuts.at(currentDir))
1216 >    } // end loop over cuts
1217  
1218 <  masterCutFlow_->fillCutFlow(scaleFactor);
1218 >    if (!useEDMFormat_ && eventPassedAllCuts){
1219 >      // Assign BNTree variables
1220 >      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1221 >        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1222 >        string coll = brSpecs.inputCollection;
1223 >        if (cumulativeFlags.count(coll) == 0) cout << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1224 >
1225 >        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1226 >        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1227 >        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1228 >        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1229 >        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1230 >        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1231 >        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1232 >        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1233 >        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1234 >        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1235 >        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1236 >        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1237 >        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1238 >        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1239 >        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1240 >        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1241 >        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1242 >        else if(coll == "stops"
1243 >                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1244 >      } // end loop over branches
1245  
1246 +      if (!BNTrees_.at(currentChannelIndex)) { cout << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1247 +      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1248 +    }
1249  
1250 +    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1251 +
1252 +  } // end loop over channel
1253 +
1254 +  masterCutFlow_->fillCutFlow(masterScaleFactor);
1255 +
1256 +  event.put (channelDecisions, "channelDecisions");
1257 +
1258 + } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1259  
783 }
1260  
1261  
1262   bool
# Line 794 | Line 1270 | OSUAnalysis::evaluateComparison (double
1270    else if(comparison == "==") return testValue == cutValue;
1271    else if(comparison == "=") return testValue == cutValue;
1272    else if(comparison == "!=") return testValue != cutValue;
1273 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1273 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1274 >
1275 > }
1276 >
1277 > bool
1278 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1279 >
1280 >
1281 >  if(comparison == ">")       return testValue >  cutValue;
1282 >  else if(comparison == ">=") return testValue >= cutValue;
1283 >  else if(comparison == "<")  return testValue <  cutValue;
1284 >  else if(comparison == "<=") return testValue <= cutValue;
1285 >  else if(comparison == "==") return testValue == cutValue;
1286 >  else if(comparison == "=") return testValue == cutValue;
1287 >  else if(comparison == "!=") return testValue != cutValue;
1288 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1289  
1290   }
1291  
1292   bool
1293 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1293 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1294  
1295 +  //initialize to false until a chosen trigger is passed
1296    bool triggerDecision = false;
1297  
1298 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1299 <    {
1300 <      if(trigger->pass != 1) continue;
1301 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1302 <        {
1303 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1304 <            triggerDecision = true;
1305 <          }
1306 <        }
1298 >  if (printAllTriggers_) cout << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1299 >  //loop over all triggers defined in the event
1300 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1301 >
1302 >    if (printAllTriggers_) cout << "   " << trigger->name << endl;
1303 >
1304 >    //we're only interested in triggers that actually passed
1305 >    if(trigger->pass != 1) continue;
1306 >
1307 >    //if the event passes one of the veto triggers, exit and return false
1308 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1309 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1310 >    }
1311 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1312 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1313 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1314      }
1315 <  return triggerDecision;
1315 >  }
1316  
1317 +  printAllTriggers_ = false;  // only print triggers once, not every event
1318 +
1319 +  //if none of the veto triggers fired:
1320 +  //return the OR of all the chosen triggers
1321 +  if (triggersToTest.size() != 0) return triggerDecision;
1322 +  //or if no triggers were defined return true
1323 +  else return true;
1324   }
1325  
1326 < std::vector<std::string>
1326 >
1327 > vector<string>
1328   OSUAnalysis::splitString (string inputString){
1329  
1330 <  std::stringstream stringStream(inputString);
1331 <  std::istream_iterator<std::string> begin(stringStream);
1332 <  std::istream_iterator<std::string> end;
1333 <  std::vector<std::string> stringVector(begin, end);
1330 >  stringstream stringStream(inputString);
1331 >  istream_iterator<string> begin(stringStream);
1332 >  istream_iterator<string> end;
1333 >  vector<string> stringVector(begin, end);
1334    return stringVector;
1335  
1336   }
1337  
1338 +
1339 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1340 +  // Set two object strings from the tempInputCollection string,
1341 +  // For example, if tempInputCollection is "electron-muon pairs",
1342 +  // then obj1 = "electrons" and obj2 = "muons".
1343 +  // Note that the objects have an "s" appended.
1344 +
1345 +  int dashIndex = tempInputCollection.find("-");
1346 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1347 +  int secondWordLength = spaceIndex - dashIndex;
1348 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1349 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1350 +
1351 + }
1352 +
1353 +
1354 + string OSUAnalysis::getObjToGet(string obj) {
1355 +  // Return the string corresponding to the object to get for the given obj string.
1356 +  // Right now this only handles the case in which obj contains "secondary",
1357 +  // e.g, "secondary muons".
1358 +  // Note that "s" is NOT appended.
1359 +
1360 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1361 +  int firstSpaceIndex = obj.find_first_of(" ");
1362 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1363 +
1364 + }
1365 +
1366 +
1367 + //!jet valueLookup
1368   double
1369 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1369 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1370  
1371    double value = 0.0;
1372    if(variable == "energy") value = object->energy;
# Line 949 | Line 1486 | OSUAnalysis::valueLookup (const BNjet* o
1486    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1487  
1488  
1489 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1489 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1490  
1491    value = applyFunction(function, value);
1492  
# Line 957 | Line 1494 | OSUAnalysis::valueLookup (const BNjet* o
1494   }
1495  
1496  
1497 <
1497 > //!muon valueLookup
1498   double
1499 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1499 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1500  
1501    double value = 0.0;
1502    if(variable == "energy") value = object->energy;
# Line 1120 | Line 1657 | OSUAnalysis::valueLookup (const BNmuon*
1657    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1658    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1659    else if(variable == "metMT") {
1660 <    const BNmet *met = chosenMET ();
1124 <    if (met)
1660 >    if (const BNmet *met = chosenMET ())
1661        {
1662 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1663 <                       p2 (met->px, met->py, 0.0, met->pt);
1128 <
1129 <        value = (p1 + p2).Mt ();
1662 >        double dPhi = deltaPhi (object->phi, met->phi);
1663 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1664        }
1665      else
1666        value = -999;
# Line 1253 | Line 1787 | OSUAnalysis::valueLookup (const BNmuon*
1787    }
1788    else if(variable == "tightIDdisplaced"){
1789      value = object->isGlobalMuon > 0                \
1790 +      && object->isPFMuon > 0                        \
1791        && object->normalizedChi2 < 10                \
1792        && object->numberOfValidMuonHits > 0        \
1793        && object->numberOfMatchedStations > 1        \
# Line 1260 | Line 1795 | OSUAnalysis::valueLookup (const BNmuon*
1795        && object->numberOfLayersWithMeasurement > 5;
1796    }
1797  
1798 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1798 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1799  
1800    else if(variable == "genMatchedPdgId"){
1801      int index = getGenMatchedParticleIndex(object);
# Line 1280 | Line 1815 | OSUAnalysis::valueLookup (const BNmuon*
1815    }
1816    else if(variable == "genMatchedMotherIdReverse"){
1817      int index = getGenMatchedParticleIndex(object);
1818 <    if(index == -1) value = 23;
1819 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1818 >    if(index == -1) value = 24;
1819 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1820    }
1821    else if(variable == "genMatchedGrandmotherId"){
1822      int index = getGenMatchedParticleIndex(object);
# Line 1293 | Line 1828 | OSUAnalysis::valueLookup (const BNmuon*
1828      }
1829      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1830    }
1831 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1832 +    int index = getGenMatchedParticleIndex(object);
1833 +    if(index == -1) value = 24;
1834 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1835 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1836 +      if(motherIndex == -1) value = 24;
1837 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1838 +    }
1839 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1840 +  }
1841 +  else if(variable == "pfMuonsFromVertex"){
1842 +    double d0Error, dzError;
1843  
1844 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1845 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1846 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1847 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1848 +      || fabs (object->correctedDZ / dzError) > 99.0;
1849 +    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1850 +  }
1851  
1852  
1853 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1853 >
1854 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1855  
1856    value = applyFunction(function, value);
1857  
1858    return value;
1859   }
1860  
1861 <
1861 > //!electron valueLookup
1862   double
1863 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1863 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1864  
1865    double value = 0.0;
1866    if(variable == "energy") value = object->energy;
# Line 1471 | Line 2026 | OSUAnalysis::valueLookup (const BNelectr
2026    else if(variable == "detIso") value = (object->trackIso) / object->pt;
2027    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2028    else if(variable == "metMT") {
2029 <    const BNmet *met = chosenMET ();
1475 <    if (met)
2029 >    if (const BNmet *met = chosenMET ())
2030        {
2031 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
2032 <                       p2 (met->px, met->py, 0.0, met->pt);
1479 <
1480 <        value = (p1 + p2).Mt ();
2031 >        double dPhi = deltaPhi (object->phi, met->phi);
2032 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2033        }
2034      else
2035        value = -999;
# Line 1642 | Line 2194 | OSUAnalysis::valueLookup (const BNelectr
2194    }
2195  
2196  
2197 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2197 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2198  
2199    else if(variable == "genMatchedPdgId"){
2200      int index = getGenMatchedParticleIndex(object);
# Line 1663 | Line 2215 | OSUAnalysis::valueLookup (const BNelectr
2215    }
2216    else if(variable == "genMatchedMotherIdReverse"){
2217      int index = getGenMatchedParticleIndex(object);
2218 <    if(index == -1) value = 23;
2219 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2218 >    if(index == -1) value = 24;
2219 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2220    }
2221    else if(variable == "genMatchedGrandmotherId"){
2222      int index = getGenMatchedParticleIndex(object);
# Line 1676 | Line 2228 | OSUAnalysis::valueLookup (const BNelectr
2228      }
2229      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2230    }
2231 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2232 +    int index = getGenMatchedParticleIndex(object);
2233 +    if(index == -1) value = 24;
2234 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2235 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2236 +      if(motherIndex == -1) value = 24;
2237 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2238 +    }
2239 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2240 +  }
2241 +  else if(variable == "pfElectronsFromVertex"){
2242 +    double d0Error, dzError;
2243  
2244 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2245 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2246 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2247 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2248 +      || fabs (object->correctedDZ / dzError) > 99.0;
2249 +    value = !value;
2250 +  }
2251  
2252  
2253 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2253 >
2254 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2255  
2256    value = applyFunction(function, value);
2257  
2258    return value;
2259   }
2260  
2261 <
2261 > //!event valueLookup
2262   double
2263 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2263 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2264  
2265    double value = 0.0;
2266  
# Line 1757 | Line 2329 | OSUAnalysis::valueLookup (const BNevent*
2329    else if(variable == "id2") value = object->id2;
2330    else if(variable == "evt") value = object->evt;
2331    else if(variable == "puScaleFactor"){
2332 <    if(datasetType_ != "data")
2332 >    if(doPileupReweighting_ && datasetType_ != "data")
2333        value = puWeight_->at (events->at (0).numTruePV);
2334      else
2335        value = 1.0;
2336    }
2337 <  else if(variable == "muonScaleFactor"){
2338 <    if(datasetType_ != "data")
2339 <      //      value = muonSFWeight_->at (chosenMuon ()->eta);
2340 <    value = 1.0;
2341 <    else
1770 <      value = 1.0;
1771 <  }
1772 <  else if(variable == "electronScaleFactor"){
1773 <    if(datasetType_ != "data")
1774 <      //      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1775 <    value = 1.0;
1776 <    else
1777 <      value = 1.0;
1778 <  }
1779 <
1780 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2337 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2338 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2339 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2340 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2341 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2342  
2343    value = applyFunction(function, value);
2344  
2345    return value;
2346   }
2347  
2348 + //!tau valueLookup
2349   double
2350 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2350 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2351  
2352    double value = 0.0;
2353  
# Line 1831 | Line 2393 | OSUAnalysis::valueLookup (const BNtau* o
2393  
2394  
2395  
2396 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2396 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2397  
2398    else if(variable == "genMatchedPdgId"){
2399      int index = getGenMatchedParticleIndex(object);
# Line 1851 | Line 2413 | OSUAnalysis::valueLookup (const BNtau* o
2413    }
2414    else if(variable == "genMatchedMotherIdReverse"){
2415      int index = getGenMatchedParticleIndex(object);
2416 <    if(index == -1) value = 23;
2417 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2416 >    if(index == -1) value = 24;
2417 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2418    }
2419    else if(variable == "genMatchedGrandmotherId"){
2420      int index = getGenMatchedParticleIndex(object);
# Line 1864 | Line 2426 | OSUAnalysis::valueLookup (const BNtau* o
2426      }
2427      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2428    }
2429 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2430 +    int index = getGenMatchedParticleIndex(object);
2431 +    if(index == -1) value = 24;
2432 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2433 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2434 +      if(motherIndex == -1) value = 24;
2435 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2436 +    }
2437 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2438 +  }
2439  
2440  
2441 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2441 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2442  
2443    value = applyFunction(function, value);
2444  
2445    return value;
2446   }
2447  
2448 + //!met valueLookup
2449   double
2450 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2450 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2451  
2452    double value = 0.0;
2453  
# Line 1938 | Line 2511 | OSUAnalysis::valueLookup (const BNmet* o
2511    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2512    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2513  
2514 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2514 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2515  
2516    value = applyFunction(function, value);
2517  
2518    return value;
2519   }
2520  
2521 + //!track valueLookup
2522   double
2523 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2523 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2524  
2525    double value = 0.0;
2526    double pMag = sqrt(object->pt * object->pt +
2527 <                         object->pz * object->pz);
2527 >                     object->pz * object->pz);
2528  
2529    if(variable == "pt") value = object->pt;
2530    else if(variable == "px") value = object->px;
# Line 1972 | Line 2546 | OSUAnalysis::valueLookup (const BNtrack*
2546  
2547  
2548    //additional BNs info for disappTrks
1975  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2549    else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2550    else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2551    else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2552    else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2553    else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2554    else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2555 +  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2556    else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2557    else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2558    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2559 <  
2559 >  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2560  
2561    //user defined variables
2562    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;
2563    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2564 <  else if(variable == "caloTotDeltaRp5") value =(object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2565 <  else if(variable == "caloTotDeltaRp5ByP") value =( (object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2566 <  else if(variable == "isIso") value = getTrkIsIso(object, tracks.product());
2567 <  else if(variable == "isMatchedDeadEcal") value = getTrkIsMatchedDeadEcal(object);
2568 <  else if(variable == "ptErrorByPt") value = (object->ptError/object->pt);
2569 <  else if(variable == "ptError") value = object->ptError;
2570 <  else if(variable == "ptRes") value = getTrkPtRes(object);
2571 <
2564 >  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2565 >  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2566 >  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2567 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2568 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2569 >  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2570 >  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2571 >  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2572 >  else if(variable == "ptError")                    value = object->ptError;
2573 >  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2574    else if (variable == "d0wrtPV"){
2575      double vx = object->vx - chosenVertex ()->x,
2576        vy = object->vy - chosenVertex ()->y,
# Line 2013 | Line 2589 | OSUAnalysis::valueLookup (const BNtrack*
2589        pt = object->pt;
2590      value = vz - (vx * px + vy * py)/pt * (pz/pt);
2591    }
2592 <
2017 <
2018 <
2019 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2592 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2593  
2594    else if(variable == "genMatchedPdgId"){
2595      int index = getGenMatchedParticleIndex(object);
# Line 2024 | Line 2597 | OSUAnalysis::valueLookup (const BNtrack*
2597      else value = mcparticles->at(index).id;
2598    }
2599  
2600 +
2601    else if(variable == "genMatchedId"){
2602      int index = getGenMatchedParticleIndex(object);
2603      if(index == -1) value = 0;
# Line 2036 | Line 2610 | OSUAnalysis::valueLookup (const BNtrack*
2610    }
2611    else if(variable == "genMatchedMotherIdReverse"){
2612      int index = getGenMatchedParticleIndex(object);
2613 <    if(index == -1) value = 23;
2614 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2613 >    if(index == -1) value = 24;
2614 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2615    }
2616    else if(variable == "genMatchedGrandmotherId"){
2617      int index = getGenMatchedParticleIndex(object);
# Line 2049 | Line 2623 | OSUAnalysis::valueLookup (const BNtrack*
2623      }
2624      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2625    }
2626 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2627 +    int index = getGenMatchedParticleIndex(object);
2628 +    if(index == -1) value = 24;
2629 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2630 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2631 +      if(motherIndex == -1) value = 24;
2632 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2633 +    }
2634 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2635 +  }
2636  
2637  
2638  
2639 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2639 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2640  
2641    value = applyFunction(function, value);
2642  
2643    return value;
2644   }
2645  
2646 + //!genjet valueLookup
2647   double
2648 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2648 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2649  
2650    double value = 0.0;
2651  
# Line 2080 | Line 2665 | OSUAnalysis::valueLookup (const BNgenjet
2665    else if(variable == "charge") value = object->charge;
2666  
2667  
2668 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2668 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2669  
2670    value = applyFunction(function, value);
2671  
2672    return value;
2673   }
2674  
2675 + //!mcparticle valueLookup
2676   double
2677 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2677 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2678  
2679    double value = 0.0;
2680  
# Line 2213 | Line 2799 | OSUAnalysis::valueLookup (const BNmcpart
2799    }
2800  
2801  
2802 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2802 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2803  
2804    value = applyFunction(function, value);
2805  
2806    return value;
2807   }
2808  
2809 + //!primaryvertex valueLookup
2810   double
2811 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2811 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2812  
2813    double value = 0.0;
2814  
# Line 2240 | Line 2827 | OSUAnalysis::valueLookup (const BNprimar
2827    else if(variable == "isGood") value = object->isGood;
2828  
2829  
2830 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2830 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2831  
2832    value = applyFunction(function, value);
2833  
2834    return value;
2835   }
2836  
2837 + //!bxlumi valueLookup
2838   double
2839 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2839 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2840  
2841    double value = 0.0;
2842  
# Line 2257 | Line 2845 | OSUAnalysis::valueLookup (const BNbxlumi
2845    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2846  
2847  
2848 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2848 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2849  
2850    value = applyFunction(function, value);
2851  
2852    return value;
2853   }
2854  
2855 + //!photon valueLookup
2856   double
2857 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2857 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2858  
2859    double value = 0.0;
2860  
# Line 2338 | Line 2927 | OSUAnalysis::valueLookup (const BNphoton
2927    else if(variable == "isEEGap") value = object->isEEGap;
2928    else if(variable == "hasPixelSeed") value = object->hasPixelSeed;
2929    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2341
2930  
2931 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2931 >
2932 >
2933 >
2934 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2935  
2936    else if(variable == "genMatchedPdgId"){
2937      int index = getGenMatchedParticleIndex(object);
2938      if(index == -1) value = 0;
2939      else value = mcparticles->at(index).id;
2940    }
2941 +
2942 +
2943 +
2944    else if(variable == "genMatchedId"){
2945      int index = getGenMatchedParticleIndex(object);
2946      if(index == -1) value = 0;
# Line 2359 | Line 2953 | OSUAnalysis::valueLookup (const BNphoton
2953    }
2954    else if(variable == "genMatchedMotherIdReverse"){
2955      int index = getGenMatchedParticleIndex(object);
2956 <    if(index == -1) value = 23;
2957 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2956 >    if(index == -1) value = 24;
2957 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2958    }
2959    else if(variable == "genMatchedGrandmotherId"){
2960      int index = getGenMatchedParticleIndex(object);
# Line 2372 | Line 2966 | OSUAnalysis::valueLookup (const BNphoton
2966      }
2967      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2968    }
2969 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2970 +    int index = getGenMatchedParticleIndex(object);
2971 +    if(index == -1) value = 24;
2972 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2973 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2974 +      if(motherIndex == -1) value = 24;
2975 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2976 +    }
2977 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2978 +  }
2979  
2980  
2981 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2981 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2982  
2983    value = applyFunction(function, value);
2984  
2985    return value;
2986   }
2987  
2988 + //!supercluster valueLookup
2989   double
2990 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
2990 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
2991  
2992    double value = 0.0;
2993  
# Line 2396 | Line 3001 | OSUAnalysis::valueLookup (const BNsuperc
3001    else if(variable == "theta") value = object->theta;
3002  
3003  
3004 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3004 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3005  
3006    value = applyFunction(function, value);
3007  
3008    return value;
3009   }
3010  
3011 + //!trigobj valueLookup
3012 + double
3013 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3014 +
3015 +  double value = 0.0;
3016  
3017 +  if(variable == "pt") value = object->pt;
3018 +  else if(variable == "eta") value = object->eta;
3019 +  else if(variable == "phi") value = object->phi;
3020 +  else if(variable == "px") value = object->px;
3021 +  else if(variable == "py") value = object->py;
3022 +  else if(variable == "pz") value = object->pz;
3023 +  else if(variable == "et") value = object->et;
3024 +  else if(variable == "energy") value = object->energy;
3025 +  else if(variable == "etTotal") value = object->etTotal;
3026 +  else if(variable == "id") value = object->id;
3027 +  else if(variable == "charge") value = object->charge;
3028 +  else if(variable == "isIsolated") value = object->isIsolated;
3029 +  else if(variable == "isMip") value = object->isMip;
3030 +  else if(variable == "isForward") value = object->isForward;
3031 +  else if(variable == "isRPC") value = object->isRPC;
3032 +  else if(variable == "bx") value = object->bx;
3033 +  else if(variable == "filter") {
3034 +    if ((stringValue = object->filter) == "")
3035 +      stringValue = "none";  // stringValue should only be empty if value is filled
3036 +  }
3037 +
3038 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3039 +
3040 +  value = applyFunction(function, value);
3041 +
3042 +  return value;
3043 + }
3044 +
3045 + //!muon-muon pair valueLookup
3046   double
3047 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
3047 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3048  
3049    double value = 0.0;
3050  
3051    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3052 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3053    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3054    else if(variable == "invMass"){
3055      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2419 | Line 3059 | OSUAnalysis::valueLookup (const BNmuon*
3059    else if(variable == "pt"){
3060      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3061      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3062 <    value = (fourVector1 + fourVector2).Et();
3062 >    value = (fourVector1 + fourVector2).Pt();
3063    }
3064    else if(variable == "threeDAngle")
3065      {
# Line 2451 | Line 3091 | OSUAnalysis::valueLookup (const BNmuon*
3091    else if(variable == "muon2CorrectedD0Vertex"){
3092      value = object2->correctedD0Vertex;
3093    }
3094 < else if(variable == "muon1timeAtIpInOut"){
3094 >  else if(variable == "muon1timeAtIpInOut"){
3095      value = object1->timeAtIpInOut;
3096    }
3097 < else if(variable == "muon2timeAtIpInOut"){
3097 >  else if(variable == "muon2timeAtIpInOut"){
3098      value = object2->timeAtIpInOut;
3099    }
3100 < else if(variable == "muon1correctedD0")
3101 <   {
3102 <     value = object1->correctedD0;
3103 <   }
3104 < else if(variable == "muon2correctedD0")
3105 <   {
3106 <     value = object2->correctedD0;
3107 <   }
3100 >  else if(variable == "muon1correctedD0")
3101 >    {
3102 >      value = object1->correctedD0;
3103 >    }
3104 >  else if(variable == "muon2correctedD0")
3105 >    {
3106 >      value = object2->correctedD0;
3107 >    }
3108  
3109 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3109 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3110 >
3111 >  value = applyFunction(function, value);
3112 >
3113 >  return value;
3114 > }
3115 >
3116 > //!muon-photon pair valueLookup
3117 > double
3118 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3119 >
3120 >  double value = 0.0;
3121 >
3122 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3123 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3124 >  else if(variable == "photonEta") value = object2->eta;
3125 >  else if(variable == "muonEta") value = object1->eta;
3126 >  else if(variable == "photonPhi") value = object2->phi;
3127 >  else if(variable == "muonPhi") value = object1->phi;
3128 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3129 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3130 >  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3131 >  else if(variable == "invMass"){
3132 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3133 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3134 >    value = (fourVector1 + fourVector2).M();
3135 >  }
3136 >  else if(variable == "pt"){
3137 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3138 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3139 >    value = (fourVector1 + fourVector2).Pt();
3140 >  }
3141 >  else if(variable == "threeDAngle")
3142 >    {
3143 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3144 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3145 >      value = (threeVector1.Angle(threeVector2));
3146 >    }
3147 >  else if(variable == "alpha")
3148 >    {
3149 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3150 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3151 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3152 >      value = (pi-threeVector1.Angle(threeVector2));
3153 >    }
3154 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3155 >
3156 >  value = applyFunction(function, value);
3157 >
3158 >  return value;
3159 > }
3160 >
3161 > //!electron-photon pair valueLookup
3162 > double
3163 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3164 >
3165 >  double value = 0.0;
3166 >
3167 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3168 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3169 >  else if(variable == "photonEta") value = object2->eta;
3170 >  else if(variable == "electronEta") value = object1->eta;
3171 >  else if(variable == "photonPhi") value = object2->phi;
3172 >  else if(variable == "electronPhi") value = object1->phi;
3173 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3174 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3175 >  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3176 >  else if(variable == "invMass"){
3177 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3178 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3179 >    value = (fourVector1 + fourVector2).M();
3180 >  }
3181 >  else if(variable == "pt"){
3182 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3183 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3184 >    value = (fourVector1 + fourVector2).Pt();
3185 >  }
3186 >  else if(variable == "threeDAngle")
3187 >    {
3188 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3189 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3190 >      value = (threeVector1.Angle(threeVector2));
3191 >    }
3192 >  else if(variable == "alpha")
3193 >    {
3194 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3195 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3196 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3197 >      value = (pi-threeVector1.Angle(threeVector2));
3198 >    }
3199 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3200  
3201    value = applyFunction(function, value);
3202  
3203    return value;
3204   }
3205  
3206 + //!electron-electron pair valueLookup
3207   double
3208 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
3208 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3209  
3210    double value = 0.0;
3211  
3212    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3213 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3214    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3215    else if(variable == "invMass"){
3216      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2488 | Line 3220 | OSUAnalysis::valueLookup (const BNelectr
3220    else if(variable == "pt"){
3221      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3222      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3223 <    value = (fourVector1 + fourVector2).Et();
3223 >    value = (fourVector1 + fourVector2).Pt();
3224    }
3225    else if(variable == "threeDAngle")
3226      {
# Line 2520 | Line 3252 | OSUAnalysis::valueLookup (const BNelectr
3252      value = object2->correctedD0;
3253    }
3254  
3255 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3255 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3256  
3257    value = applyFunction(function, value);
3258  
3259    return value;
3260   }
3261 <
3261 > //!electron-muon pair valueLookup
3262   double
3263 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3263 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* 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 2542 | Line 3275 | OSUAnalysis::valueLookup (const BNelectr
3275    else if(variable == "pt"){
3276      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3277      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3278 <    value = (fourVector1 + fourVector2).Et();
3278 >    value = (fourVector1 + fourVector2).Pt();
3279    }
3280    else if(variable == "threeDAngle")
3281      {
# Line 2579 | Line 3312 | OSUAnalysis::valueLookup (const BNelectr
3312    else if(variable == "muonDetIso"){
3313      value = (object2->trackIsoDR03) / object2->pt;
3314    }
3315 +  else if(variable == "electronRelPFrhoIso"){
3316 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3317 +  }
3318 +  else if(variable == "muonRelPFdBetaIso"){
3319 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3320 +  }
3321 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3322 +  value = applyFunction(function, value);
3323 +
3324 +  return value;
3325 + }
3326 +
3327 + //!electron-jet pair valueLookup
3328 + double
3329 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3330  
3331 +  double value = 0.0;
3332  
3333 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3333 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3334 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3335 >  else if(variable == "jetEta") value = object2->eta;
3336 >  else if(variable == "jetPhi") value = object2->phi;
3337 >  else if(variable == "electronEta") value = object1->eta;
3338 >  else if(variable == "electronPhi") value = object1->phi;
3339 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3340 >  else if(variable == "invMass"){
3341 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3342 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3343 >    value = (fourVector1 + fourVector2).M();
3344 >  }
3345 >  else if(variable == "pt"){
3346 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3347 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3348 >    value = (fourVector1 + fourVector2).Pt();
3349 >  }
3350 >  else if(variable == "threeDAngle")
3351 >    {
3352 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3353 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3354 >      value = (threeVector1.Angle(threeVector2));
3355 >    }
3356 >  else if(variable == "chargeProduct"){
3357 >    value = object1->charge*object2->charge;
3358 >  }
3359  
3360 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3361    value = applyFunction(function, value);
3362  
3363    return value;
3364   }
3365  
3366 + //!photon-jet pair valueLookup
3367 + double
3368 + OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3369  
3370 +  double value = 0.0;
3371 +
3372 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3373 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3374 +  else if(variable == "jetEta") value = object2->eta;
3375 +  else if(variable == "jetPhi") value = object2->phi;
3376 +  else if(variable == "photonEta") value = object1->eta;
3377 +  else if(variable == "photonPhi") value = object1->phi;
3378 +  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3379 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3380 +  else if(variable == "invMass"){
3381 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3382 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3383 +    value = (fourVector1 + fourVector2).M();
3384 +  }
3385 +  else if(variable == "pt"){
3386 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3387 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3388 +    value = (fourVector1 + fourVector2).Pt();
3389 +  }
3390 +  else if(variable == "threeDAngle")
3391 +    {
3392 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3393 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3394 +      value = (threeVector1.Angle(threeVector2));
3395 +    }
3396 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3397 +  value = applyFunction(function, value);
3398 +
3399 +  return value;
3400 + }
3401 +
3402 + //!muon-jet pair valueLookup
3403 + double
3404 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3405 +
3406 +  double value = 0.0;
3407 +
3408 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3409 +  else if(variable == "jetEta") value = object2->eta;
3410 +  else if(variable == "jetPhi") value = object2->phi;
3411 +  else if(variable == "muonEta") value = object1->eta;
3412 +  else if(variable == "muonPhi") value = object1->phi;
3413 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3414 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3415 +  else if(variable == "invMass"){
3416 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3417 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3418 +    value = (fourVector1 + fourVector2).M();
3419 +  }
3420 +  else if(variable == "pt"){
3421 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3422 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3423 +    value = (fourVector1 + fourVector2).Pt();
3424 +  }
3425 +  else if(variable == "threeDAngle")
3426 +    {
3427 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3428 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3429 +      value = (threeVector1.Angle(threeVector2));
3430 +    }
3431 +  else if(variable == "chargeProduct"){
3432 +    value = object1->charge*object2->charge;
3433 +  }
3434 +
3435 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3436 +  value = applyFunction(function, value);
3437 +
3438 +  return value;
3439 + }
3440 + //!jet-jet pair valueLookup
3441   double
3442 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function){
3442 > OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3443 >
3444 >  double value = 0.0;
3445 >
3446 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3447 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3448 >  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3449 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3450 >  else if(variable == "invMass"){
3451 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3452 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3453 >    value = (fourVector1 + fourVector2).M();
3454 >  }
3455 >  else if(variable == "pt"){
3456 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3457 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3458 >    value = (fourVector1 + fourVector2).Pt();
3459 >  }
3460 >  else if(variable == "threeDAngle")
3461 >    {
3462 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3463 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3464 >      value = (threeVector1.Angle(threeVector2));
3465 >    }
3466 >  else if(variable == "chargeProduct"){
3467 >    value = object1->charge*object2->charge;
3468 >  }
3469 >
3470 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3471 >  value = applyFunction(function, value);
3472 >
3473 >  return value;
3474 > }
3475 > //!electron-track pair valueLookup
3476 > double
3477 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3478    double electronMass = 0.000511;
3479    double value = 0.0;
3480 <  TLorentzVector fourVector1(0, 0, 0, 0);  
3481 <  TLorentzVector fourVector2(0, 0, 0, 0);  
3480 >  TLorentzVector fourVector1(0, 0, 0, 0);
3481 >  TLorentzVector fourVector2(0, 0, 0, 0);
3482    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3483 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3484    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3485    else if(variable == "invMass"){
3486      fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3487      fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3488 <    
3488 >
3489      value = (fourVector1 + fourVector2).M();
3490    }
3491 <  
3491 >  else if(variable == "chargeProduct"){
3492 >    value = object1->charge*object2->charge;
3493 >  }
3494    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3495    value = applyFunction(function, value);
3496    return value;
3497 +
3498   }
3499  
3500 +
3501 + //!muon-track pair valueLookup
3502   double
3503 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function){
3503 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3504    double pionMass = 0.140;
3505    double muonMass = 0.106;
3506    double value = 0.0;
3507    TLorentzVector fourVector1(0, 0, 0, 0);
3508    TLorentzVector fourVector2(0, 0, 0, 0);
3509    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3510 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3511    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3512    else if(variable == "invMass"){
3513      fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
# Line 2624 | Line 3515 | OSUAnalysis::valueLookup (const BNmuon*
3515  
3516      value = (fourVector1 + fourVector2).M();
3517    }
3518 +  else if(variable == "chargeProduct"){
3519 +    value = object1->charge*object2->charge;
3520 +  }
3521  
3522    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3523    value = applyFunction(function, value);
3524    return value;
3525   }
3526  
3527 <
3527 > //!tau-tau pair valueLookup
3528   double
3529 < OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function){
3529 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3530    double value = 0.0;
3531    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3532 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3533    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3534    else if(variable == "invMass"){
3535 <  TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3536 <  TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3537 <     value = (fourVector1 + fourVector2).M();
3535 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3536 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3537 >    value = (fourVector1 + fourVector2).M();
3538 >  }
3539 >
3540 >  else if(variable == "chargeProduct"){
3541 >    value = object1->charge*object2->charge;
3542    }
3543  
3544    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
# Line 2647 | Line 3546 | OSUAnalysis::valueLookup (const BNtau* o
3546    return value;
3547   }
3548  
3549 + //!muon-tau pair valueLookup
3550   double
3551 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function){
3551 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3552    double value = 0.0;
3553    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3554 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3555    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3556    else if(variable == "invMass"){
3557      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2658 | Line 3559 | OSUAnalysis::valueLookup (const BNmuon*
3559      value = (fourVector1 + fourVector2).M();
3560    }
3561  
3562 +  else if(variable == "chargeProduct"){
3563 +    value = object1->charge*object2->charge;
3564 +  }
3565 +
3566 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3567 +  value = applyFunction(function, value);
3568 +  return value;
3569 + }
3570 +
3571 + //!tau-track pair valueLookup
3572 + double
3573 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3574 +  double value = 0.0;
3575 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3576 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3577 +  else if(variable == "chargeProduct"){
3578 +    value = object1->charge*object2->charge;
3579 +  }
3580 +
3581    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3582    value = applyFunction(function, value);
3583    return value;
3584   }
3585  
3586  
3587 + //!track-event pair valueLookup
3588 + double
3589 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3590 +
3591 +  double value = 0.0;
3592 +  double pMag = sqrt(object1->pt * object1->pt +
3593 +                     object1->pz * object1->pz);
3594 +
3595 +  if      (variable == "numPV")                      value = object2->numPV;
3596 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3597 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3598 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3599 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3600 +
3601 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3602 +
3603 +  value = applyFunction(function, value);
3604 +
3605 +  return value;
3606 +
3607 + }
3608 +
3609 + //!electron-trigobj pair valueLookup
3610 + double
3611 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3612 +
3613 +  double value = 0.0;
3614 +
3615 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3616 +  else if (variable == "match"){
3617 +    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3618 +      stringValue = object2->filter;
3619 +    else
3620 +      stringValue = "none";
3621 +  }
3622 +
3623 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3624 +
3625 +  value = applyFunction(function, value);
3626 +
3627 +  return value;
3628 +
3629 + }
3630 +
3631 + //!muon-trigobj pair valueLookup
3632 + double
3633 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3634 +
3635 +  double value = 0.0;
3636 +
3637 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3638 +
3639 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3640 +
3641 +  value = applyFunction(function, value);
3642 +
3643 +  return value;
3644 +
3645 + }
3646 +
3647 + //!stop valueLookup
3648 + double
3649 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3650 +
3651 +
3652 +  double value = 0.0;
3653 +
3654 +  if(variable == "ctau") value = object->ctau;
3655 +
3656 +  else if (variable == "d0"){
3657 +    double vx = object->vx - chosenVertex ()->x,
3658 +      vy = object->vy - chosenVertex ()->y,
3659 +      px = object->px,
3660 +      py = object->py,
3661 +      pt = object->pt;
3662 +    value = (-vx * py + vy * px) / pt;
3663 +  }
3664 +
3665 +  else if (variable == "dz"){
3666 +    double vx = object->vx - chosenVertex ()->x,
3667 +      vy = object->vy - chosenVertex ()->y,
3668 +      vz = object->vz - chosenVertex ()->z,
3669 +      px = object->px,
3670 +      py = object->py,
3671 +      pz = object->pz,
3672 +      pt = object->pt;
3673 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3674 +  }
3675 +
3676 +  else if (variable == "minD0"){
3677 +    double minD0=999;
3678 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3679 +      double vx = object->vx - vertex->x,
3680 +        vy = object->vy - vertex->y,
3681 +        px = object->px,
3682 +        py = object->py,
3683 +        pt = object->pt;
3684 +      value = (-vx * py + vy * px) / pt;
3685 +      if(abs(value) < abs(minD0)) minD0 = value;
3686 +    }
3687 +    value = minD0;
3688 +  }
3689 +  else if (variable == "minDz"){
3690 +    double minDz=999;
3691 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3692 +      double vx = object->vx - vertex->x,
3693 +        vy = object->vy - vertex->y,
3694 +        vz = object->vz - vertex->z,
3695 +        px = object->px,
3696 +        py = object->py,
3697 +        pz = object->pz,
3698 +        pt = object->pt;
3699 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3700 +      if(abs(value) < abs(minDz)) minDz = value;
3701 +    }
3702 +    value = minDz;
3703 +  }
3704 +  else if(variable == "distToVertex"){
3705 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3706 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3707 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3708 +  }
3709 +  else if (variable == "minDistToVertex"){
3710 +    double minDistToVertex=999;
3711 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3712 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3713 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3714 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3715 +
3716 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3717 +    }
3718 +    value = minDistToVertex;
3719 +  }
3720 +  else if (variable == "distToVertexDifference"){
3721 +    double minDistToVertex=999;
3722 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3723 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3724 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3725 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3726 +
3727 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3728 +    }
3729 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3730 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3731 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3732 +
3733 +    value = distToChosenVertex - minDistToVertex;
3734 +  }
3735 +
3736 +  else if (variable == "closestVertexRank"){
3737 +    double minDistToVertex=999;
3738 +    int vertex_rank = 0;
3739 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3740 +      vertex_rank++;
3741 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3742 +                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
3743 +                      (object->vz-vertex->z)*(object->vz-vertex->z));
3744 +
3745 +      if(abs(dist) < abs(minDistToVertex)){
3746 +        value = vertex_rank;
3747 +        minDistToVertex = dist;
3748 +      }
3749 +    }
3750 +  }
3751 +
3752 +
3753 +
3754 +
3755 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3756 +
3757 +  value = applyFunction(function, value);
3758 +
3759 +  return value;
3760 +
3761 + }
3762 +
3763 +
3764 +
3765  
3766   // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3767   // Return true iff no other tracks are found in this cone.
# Line 2710 | Line 3808 | OSUAnalysis::getTrkPtTrue (const BNtrack
3808  
3809   }
3810  
3811 + double
3812 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3813 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3814 +  if (!useTrackCaloRhoCorr_) return -99;
3815 +  // if (!rhokt6CaloJetsHandle_) {
3816 +  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3817 +  //   return -99;
3818 +  // }
3819 +  double radDeltaRCone = 0.5;
3820 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3821 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3822 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3823 +  return caloTotRhoCorrCalo;
3824 +
3825 + }
3826 +
3827 +
3828 +
3829 +
3830   //creates a map of the dead Ecal channels in the barrel and endcap
3831   //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
3832   //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
# Line 2742 | Line 3859 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3859    double deltaRLowest = 999;
3860    int value = 0;
3861    if (DeadEcalVec.size() == 0) WriteDeadEcal();
3862 <  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3862 >  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3863      double eta = ecal->etaEcal;
3864      double phi = ecal->phiEcal;
3865 <    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
3865 >    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
3866      if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3867    }
3868    if (deltaRLowest<0.05) {value = 1;}
# Line 2753 | Line 3870 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3870    return value;
3871   }
3872  
3873 <
2757 < // Returns the smallest DeltaR between the object and any generated true particle in the event.  
3873 > // Returns the smallest DeltaR between the object and any generated true particle in the event.
3874   template <class InputObject>
3875   double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3876    double genDeltaRLowest = 999.;
3877    for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3878      double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
3879      if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
3880 < }
3880 >  }
3881    return genDeltaRLowest;
3882   }
3883  
2768
3884   double
3885   OSUAnalysis::applyFunction(string function, double value){
3886  
# Line 2775 | Line 3890 | OSUAnalysis::applyFunction(string functi
3890    else if(function == "log") value = log10(value);
3891  
3892    else if(function == "") value = value;
3893 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
3893 >  else{cout << "WARNING: invalid function '" << function << "'\n";}
3894  
3895    return value;
3896  
# Line 2785 | Line 3900 | OSUAnalysis::applyFunction(string functi
3900   template <class InputCollection>
3901   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
3902  
3903 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
3904 +    string obj1, obj2;
3905 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
3906 +    if (inputType==obj1 ||
3907 +        inputType==obj2) {
3908 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
3909 +      // and the inputType is a member of the pair.
3910 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
3911 +      // For example, if currentCut.inputCollection==electron-muon pairs,
3912 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
3913 +      return;
3914 +    }
3915 +  }
3916  
3917    for (uint object = 0; object != inputCollection->size(); object++){
3918  
3919 <
3920 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
2793 <
3919 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
3920 >    bool plotDecision = true;
3921  
3922      if(currentCut.inputCollection == inputType){
3923  
3924        vector<bool> subcutDecisions;
3925        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3926 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3927 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3926 >        string stringValue = "";
3927 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3928 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3929 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3930 >
3931        }
3932 <      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3932 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
3933        else{
3934          bool tempDecision = true;
3935          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
# Line 2808 | Line 3938 | void OSUAnalysis::setObjectFlags(cut &cu
3938            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
3939              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
3940          }
3941 <        decision = tempDecision;
3941 >        cutDecision = tempDecision;
3942        }
3943 +      //invert the cut for plotting if this cut is a veto
3944 +      if(currentCut.isVeto) plotDecision = !cutDecision;
3945 +      else plotDecision = cutDecision;
3946      }
2814    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3947  
3948 +    //if(cutDecision != plotDecision && currentCut.variables.at(0) == "pt") cout << "---------------\n" << cutDecision << " " << plotDecision << endl;
3949 +    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
3950  
3951 <    //set flags for objects that pass each cut AND all the previous cuts
3952 <    bool previousCumulativeFlag = true;
3951 >    //set flags for objects that pass this cut AND all the previous cuts
3952 >    bool previousCumulativeCutFlag = true;
3953 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3954 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
3955 >      else{ previousCumulativeCutFlag = false; break;}
3956 >    }
3957 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
3958 >    bool previousCumulativePlotFlag = true;
3959      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3960 <      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
3961 <      else{ previousCumulativeFlag = false; break;}
3960 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
3961 >      else{ previousCumulativePlotFlag = false; break;}
3962      }
3963 <    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3963 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
3964  
3965 +    //if(inputType == "muons") cout << previousCumulativeCutFlag << " " << previousCumulativePlotFlag << " " << currentCut.variables.at(0) << "\n---------------\n\n";
3966 +    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
3967  
3968    }
3969  
# Line 2830 | Line 3972 | void OSUAnalysis::setObjectFlags(cut &cu
3972  
3973   template <class InputCollection1, class InputCollection2>
3974   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
3975 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
3975 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, string inputType){
3976  
3977  
3978    bool sameObjects = false;
3979    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3980  
3981 +  // Get the strings for the two objects that make up the pair.
3982 +  string obj1Type, obj2Type;
3983 +  getTwoObjs(inputType, obj1Type, obj2Type);
3984 +  bool isTwoTypesOfObject = true;
3985 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
3986 +
3987 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
3988 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
3989 +  if (currentCut.inputCollection == inputType) {
3990 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
3991 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
3992 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
3993 +    }
3994 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
3995 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
3996 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
3997 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
3998 +      }
3999 +    }
4000 +  }
4001  
4002    int counter = 0;
4003 +
4004    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4005      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4006  
4007        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4008  
4009  
4010 <      bool decision = true;//object passes if this cut doesn't cut on that type of object
4010 >      bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4011 >      bool plotDecision = true;
4012  
4013        if(currentCut.inputCollection == inputType){
4014  
4015          vector<bool> subcutDecisions;
4016          for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4017 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4018 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4017 >          string stringValue = "";
4018 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4019 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4020 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4021          }
4022  
4023 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4023 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4024          else{
4025            bool tempDecision = subcutDecisions.at(0);
4026            for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
# Line 2863 | Line 4029 | void OSUAnalysis::setObjectFlags(cut &cu
4029              else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4030                tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4031            }
4032 <          decision = tempDecision;
4032 >          cutDecision = tempDecision;
4033          }
4034 +        //invert the cut for plotting if this cut is a veto
4035 +        if(currentCut.isVeto) plotDecision = !cutDecision;
4036 +        else plotDecision = cutDecision;
4037 +      }
4038 +      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4039 +      if (cutDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4040 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4041 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4042 +      }
4043 +      if (plotDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4044 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4045 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4046        }
2869      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4047  
4048 <      //set flags for objects that pass each cut AND all the previous cuts
4049 <      bool previousCumulativeFlag = true;
4048 >      //set flags for objects that pass this cut AND all the previous cuts
4049 >      bool previousCumulativeCutFlag = true;
4050        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4051 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
4052 <        else{ previousCumulativeFlag = false; break;}
4051 >        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4052 >        else{ previousCumulativeCutFlag = false; break;}
4053        }
4054 +      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4055 +
4056 +      bool previousCumulativePlotFlag = true;
4057 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4058 +        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4059 +        else{ previousCumulativePlotFlag = false; break;}
4060 +      }
4061 +      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4062 +      
4063        //apply flags for the components of the composite object as well
4064 <      bool currentCumulativeFlag = true;
4065 <      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
4066 <      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
4067 <      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
4068 <      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
4069 <      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
4064 >      bool currentCumulativeCutFlag = true;
4065 >      bool currentCumulativePlotFlag = true;
4066 >
4067 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4068 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4069 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4070 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4071 >
4072 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4073 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4074 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4075 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4076 >
4077 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));
4078 >
4079 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4080 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4081 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4082 >      }
4083 >
4084 >      if (currentCumulativePlotFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4085 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4086 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4087 >      }
4088  
4089        counter++;
2886    }
4090  
4091 +    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4092 +  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4093 +
4094 + }
4095 +
4096 +
4097 + bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4098 +  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4099 +  // all cuts up to currentCutIndex
4100 +  bool previousCumulativeFlag = true;
4101 +  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4102 +    bool tempFlag = false;
4103 +    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4104 +    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4105 +
4106 +    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4107 +    else {
4108 +      previousCumulativeFlag = false; break;
4109 +    }
4110    }
4111 +  return previousCumulativeFlag;
4112 + }
4113  
4114  
4115 +
4116 +
4117 + template <class InputCollection>
4118 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4119 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4120 +
4121 +  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;
4122 +  for (uint object = 0; object != inputCollection->size(); object++) {
4123 +
4124 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4125 +
4126 +    string inputVariable = parameters.inputVariable;
4127 +    string function = "";
4128 +    string stringValue = "";
4129 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4130 +    BNTreeBranchVals_.at(parameters.name).push_back(value);
4131 +
4132 +  }
4133   }
4134  
4135  
4136   template <class InputCollection>
4137 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4137 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4138 >
4139  
4140    for (uint object = 0; object != inputCollection->size(); object++){
4141  
4142 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4142 >    //cout << "flags.at(object).second: " << flags.at(object).second << endl;
4143 >
4144 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4145  
4146      string currentString = parameters.inputVariables.at(0);
4147      string inputVariable = "";
4148      string function = "";
4149 <    if(currentString.find("(")==std::string::npos){
4149 >    if(currentString.find("(")==string::npos){
4150        inputVariable = currentString;// variable to cut on
4151      }
4152      else{
# Line 2910 | Line 4155 | void OSUAnalysis::fill1DHistogram(TH1* h
4155        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4156      }
4157  
4158 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
4158 >    string stringValue = "";
4159 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4160      histo->Fill(value,scaleFactor);
4161  
4162      if (printEventInfo_) {
4163 <      // Write information about event to screen, for testing purposes.  
4164 <      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;  
4163 >      // Write information about event to screen, for testing purposes.
4164 >      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
4165      }
4166 <    
4166 >
4167    }
4168   }
4169  
4170   template <class InputCollection1, class InputCollection2>
4171 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4171 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4172  
4173    bool sameObjects = false;
4174    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4175  
4176 <  int pairCounter = 0;
4176 >  int pairCounter = -1;
4177    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4178      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4179  
4180        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4181  
4182 +      pairCounter++;
4183        //only take objects which have passed all cuts and pairs which have passed all cuts
4184 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4185 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4186 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4184 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4185 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4186 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4187  
4188        string currentString = parameters.inputVariables.at(0);
4189        string inputVariable = "";
4190        string function = "";
4191 <      if(currentString.find("(")==std::string::npos){
4191 >      if(currentString.find("(")==string::npos){
4192          inputVariable = currentString;// variable to cut on
4193        }
4194        else{
# Line 2950 | Line 4197 | void OSUAnalysis::fill1DHistogram(TH1* h
4197          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4198        }
4199  
4200 <      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4200 >      string stringValue = "";
4201 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4202        histo->Fill(value,scaleFactor);
4203  
2956      pairCounter++;
4204      }
4205    }
4206  
# Line 2961 | Line 4208 | void OSUAnalysis::fill1DHistogram(TH1* h
4208  
4209  
4210   template <class InputCollection>
4211 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4211 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4212  
4213    for (uint object = 0; object != inputCollection->size(); object++){
4214  
4215 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4215 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4216  
4217 +    string stringValue = "";
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 2978 | Line 4226 | void OSUAnalysis::fill2DHistogram(TH2* h
4226        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4227        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4228      }
4229 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
4229 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4230  
4231      currentString = parameters.inputVariables.at(1);
4232      inputVariable = "";
4233      function = "";
4234 <    if(currentString.find("(")==std::string::npos){
4234 >    if(currentString.find("(")==string::npos){
4235        inputVariable = currentString;// variable to cut on
4236      }
4237      else{
# Line 2992 | Line 4240 | void OSUAnalysis::fill2DHistogram(TH2* h
4240        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4241      }
4242  
4243 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
4243 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4244  
4245      histo->Fill(valueX,valueY,scaleFactor);
4246  
# Line 3001 | Line 4249 | void OSUAnalysis::fill2DHistogram(TH2* h
4249   }
4250  
4251   template <class InputCollection1, class InputCollection2>
4252 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4252 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4253  
4254    bool sameObjects = false;
4255    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4256  
4257 <  int pairCounter = 0;
4257 >  int pairCounter = -1;
4258    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4259      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4260  
4261        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4262  
4263 +      pairCounter++;
4264 +
4265        //only take objects which have passed all cuts and pairs which have passed all cuts
4266 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4267 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4268 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4266 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4267 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4268 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4269  
4270 +      string stringValue = "";
4271        string currentString = parameters.inputVariables.at(0);
4272        string inputVariable = "";
4273        string function = "";
4274 <      if(currentString.find("(")==std::string::npos){
4274 >      if(currentString.find("(")==string::npos){
4275          inputVariable = currentString;// variable to cut on
4276        }
4277        else{
# Line 3028 | Line 4279 | void OSUAnalysis::fill2DHistogram(TH2* h
4279          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4280          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4281        }
4282 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4282 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4283  
4284        currentString = parameters.inputVariables.at(1);
4285        inputVariable = "";
4286        function = "";
4287 <      if(currentString.find("(")==std::string::npos){
4287 >      if(currentString.find("(")==string::npos){
4288          inputVariable = currentString;// variable to cut on
4289        }
4290        else{
# Line 3041 | Line 4292 | void OSUAnalysis::fill2DHistogram(TH2* h
4292          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4293          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4294        }
4295 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4295 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4296  
4297  
4298        histo->Fill(valueX,valueY,scaleFactor);
4299  
3049      pairCounter++;
3050
4300      }
4301    }
4302  
# Line 3064 | Line 4313 | int OSUAnalysis::getGenMatchedParticleIn
4313  
4314      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4315      if(currentDeltaR > 0.05) continue;
4316 < //     cout << std::setprecision(3) << std::setw(20)
4317 < //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4318 < //          << std::setw(20)
4319 < //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4320 < //          << std::setw(20)
4321 < //          << "\tdeltaR = " << currentDeltaR
4322 < //          << std::setprecision(1)
4323 < //          << std::setw(20)
4324 < //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4325 < //          << std::setw(20)
4326 < //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4327 < //          << std::setw(20)
4328 < //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4316 >    //     cout << setprecision(3) << setw(20)
4317 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4318 >    //          << setw(20)
4319 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4320 >    //          << setw(20)
4321 >    //          << "\tdeltaR = " << currentDeltaR
4322 >    //          << setprecision(1)
4323 >    //          << setw(20)
4324 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4325 >    //          << setw(20)
4326 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4327 >    //          << setw(20)
4328 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4329      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4330        bestMatchIndex = mcparticle - mcparticles->begin();
4331        bestMatchDeltaR = currentDeltaR;
4332      }
4333  
4334    }
4335 < //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4336 < //   else cout << "no match found..." << endl;
4335 >  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4336 >  //   else cout << "no match found..." << endl;
4337    return bestMatchIndex;
4338  
4339   }
# Line 3138 | Line 4387 | int OSUAnalysis::findTauMotherIndex(cons
4387   // 20        strange baryon
4388   // 21        charm baryon
4389   // 22        bottom baryon
4390 < // 23        other
4390 > // 23        QCD string
4391 > // 24        other
4392  
4393   int OSUAnalysis::getPdgIdBinValue(int pdgId){
4394  
# Line 3162 | Line 4412 | int OSUAnalysis::getPdgIdBinValue(int pd
4412    else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4413    else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4414    else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4415 +  else if(absPdgId == 92  ) binValue = 23;
4416  
4417 <  else binValue = 23;
4417 >  else binValue = 24;
4418  
4419    return binValue;
4420  
# Line 3173 | Line 4424 | const BNprimaryvertex *
4424   OSUAnalysis::chosenVertex ()
4425   {
4426    const BNprimaryvertex *chosenVertex = 0;
4427 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
4428 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
4429 <                               cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
4427 >  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4428 >    flagPair vertexFlags;
4429 >    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4430 >      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4431 >        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4432 >        break;
4433 >      }
4434 >    }
4435      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4436 <      if(!vertexFlags.at(vertexIndex)) continue;
4436 >      if(!vertexFlags.at(vertexIndex).first) continue;
4437        chosenVertex = & primaryvertexs->at(vertexIndex);
4438        break;
4439      }
4440    }
4441 <  else {
4442 <    chosenVertex = &primaryvertexs->at(0);
3187 <  }
4441 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4442 >    chosenVertex = & primaryvertexs->at (0);
4443  
4444    return chosenVertex;
4445   }
# Line 3193 | Line 4448 | const BNmet *
4448   OSUAnalysis::chosenMET ()
4449   {
4450    const BNmet *chosenMET = 0;
4451 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
4452 <    vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
4453 <                            cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
4451 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4452 >    flagPair metFlags;
4453 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4454 >      if (cumulativeFlags.at("mets").at(i).size()){
4455 >        metFlags = cumulativeFlags.at("mets").at(i);
4456 >        break;
4457 >      }
4458 >    }
4459      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4460 <      if(!metFlags.at(metIndex)) continue;
4460 >      if(!metFlags.at(metIndex).first) continue;
4461        chosenMET = & mets->at(metIndex);
4462        break;
4463      }
4464    }
4465 <  else {
4466 <    chosenMET = &mets->at(0);
3207 <  }
4465 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4466 >    chosenMET = & mets->at (0);
4467  
4468    return chosenMET;
4469   }
# Line 3213 | Line 4472 | const BNelectron *
4472   OSUAnalysis::chosenElectron ()
4473   {
4474    const BNelectron *chosenElectron = 0;
4475 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
4476 <    vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
4477 <                                 cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
4475 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4476 >    flagPair electronFlags;
4477 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4478 >      if (cumulativeFlags.at("electrons").at(i).size()){
4479 >        electronFlags = cumulativeFlags.at("electrons").at(i);
4480 >        break;
4481 >      }
4482 >    }
4483      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4484 <      if(!electronFlags.at(electronIndex)) continue;
4484 >      if(!electronFlags.at(electronIndex).first) continue;
4485        chosenElectron = & electrons->at(electronIndex);
4486        break;
4487      }
4488    }
4489 <  else {
4490 <    chosenElectron = &electrons->at(0);
3227 <  }
4489 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4490 >    chosenElectron = & electrons->at (0);
4491  
4492    return chosenElectron;
4493   }
4494  
4495 +
4496   const BNmuon *
4497   OSUAnalysis::chosenMuon ()
4498   {
4499    const BNmuon *chosenMuon = 0;
4500 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
4501 <    vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
4502 <                             cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
4500 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4501 >    flagPair muonFlags;
4502 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4503 >      if (cumulativeFlags.at("muons").at(i).size()){
4504 >        muonFlags = cumulativeFlags.at("muons").at(i);
4505 >        break;
4506 >      }
4507 >    }
4508      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4509 <      if(!muonFlags.at(muonIndex)) continue;
4509 >      if(!muonFlags.at(muonIndex).first) continue;
4510        chosenMuon = & muons->at(muonIndex);
4511        break;
4512      }
4513    }
4514 <  else {
4515 <    chosenMuon = &muons->at(0);
3247 <  }
4514 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4515 >    chosenMuon = & muons->at (0);
4516  
4517    return chosenMuon;
4518   }
4519  
3252
4520   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines