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.3 by lantonel, Mon Jan 28 13:30:45 2013 UTC vs.
Revision 1.105 by wulsin, Mon Jul 22 16:33:25 2013 UTC

# Line 1 | Line 1
1   #include "OSUT3Analysis/AnaTools/plugins/OSUAnalysis.h"
2
2   OSUAnalysis::OSUAnalysis (const edm::ParameterSet &cfg) :
3    // Retrieve parameters from the configuration file.
4    jets_ (cfg.getParameter<edm::InputTag> ("jets")),
# Line 11 | Line 10 | OSUAnalysis::OSUAnalysis (const edm::Par
10    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
11    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
12    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
13 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
14    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
15    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
16    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
17    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
18    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
19 +  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
20 +  puFile_ (cfg.getParameter<string> ("puFile")),
21 +  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
22 +  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
23 +  dataPU_ (cfg.getParameter<string> ("dataPU")),
24 +  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
25 +  muonSF_ (cfg.getParameter<string> ("muonSF")),
26 +  dataset_ (cfg.getParameter<string> ("dataset")),
27 +  datasetType_ (cfg.getParameter<string> ("datasetType")),
28 +  channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
29 +  histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
30 +  useEDMFormat_   (cfg.getParameter<bool>("useEDMFormat")),
31 +  treeBranchSets_   (cfg.getParameter<vector<edm::ParameterSet> >("treeBranchSets")),
32 +  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
33 +  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
34 +  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
35 +  applyBtagSF_ (cfg.getParameter<bool> ("applyBtagSF")),
36 +  minBtag_ (cfg.getParameter<int> ("minBtag")),
37 +  printEventInfo_      (cfg.getParameter<bool> ("printEventInfo")),
38 +  printAllTriggers_    (cfg.getParameter<bool> ("printAllTriggers")),
39 +  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
40 +  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
41 +  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
42 + {
43  
44 +  TH1::SetDefaultSumw2 ();
45  
46 <  channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels"))
46 >  //create pile-up reweighting object, if necessary
47 >  if(datasetType_ != "data") {
48 >    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
49 >    if (applyLeptonSF_){
50 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
51 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
52 >    }
53 >    if (applyBtagSF_){
54 >      bTagSFWeight_ = new BtagSFWeight;
55 >    }
56 >  }
57 >  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
58 >    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
59  
23 {
24  TH1::SetDefaultSumw2 ();
60  
61    // Construct Cutflow Objects. These store the results of cut decisions and
62    // handle filling cut flow histograms.
63    masterCutFlow_ = new CutFlow (fs_);
64 <  std::vector<TFileDirectory> directories;
64 >
65 >  //always get vertex collection so we can assign the primary vertex in the event
66 >  objectsToGet.push_back("primaryvertexs");
67 >  objectsToPlot.push_back("primaryvertexs");
68 >  objectsToFlag.push_back("primaryvertexs");
69 >
70 >
71 >  //always get the MC particles to do GEN-matching
72 >  objectsToGet.push_back("mcparticles");
73 >
74 >  //always get the event collection to do pile-up reweighting
75 >  objectsToGet.push_back("events");
76 >
77 >
78 >  // Parse the tree variable definitions.
79 >  for (uint iBranchSet = 0; !useEDMFormat_ && iBranchSet<treeBranchSets_.size(); iBranchSet++) {
80 >    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
81 >    if(tempInputCollection.find("pairs")!=string::npos) { clog << "Warning:  tree filling is not configured for pairs of objects, so will not work for collection: " << tempInputCollection << endl; }
82 >    objectsToGet.push_back(tempInputCollection);
83 >    objectsToFlag.push_back(tempInputCollection);
84 >
85 >    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
86 >
87 >    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
88 >      BranchSpecs br;
89 >      br.inputCollection = tempInputCollection;
90 >      br.inputVariable = branchList.at(iBranch);
91 >      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);
92 >      br.name = string(newName.Data());
93 >      treeBranches_.push_back(br);
94 >    }
95 >
96 >  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++)
97 >
98 >
99 >  //parse the histogram definitions
100 >  for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
101 >
102 >    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
103 >    if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
104 >    if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
105 >    if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
106 >    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
107 >    if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
108 >    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
109 >    if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
110 >    if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
111 >    if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
112 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
113 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
114 >    if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
115 >    if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
116 >    if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
117 >    if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
118 >    if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
119 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
120 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
121 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
122 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
123 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
124 >        int spaceIndex = tempInputCollection.find(" ");
125 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
126 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
127 >      }
128 >      else{
129 >        objectsToGet.push_back(tempInputCollection);
130 >      }
131 >      objectsToPlot.push_back(tempInputCollection);
132 >      objectsToFlag.push_back(tempInputCollection);
133 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
134 >      string obj1;
135 >      string obj2;
136 >      getTwoObjs(tempInputCollection, obj1, obj2);
137 >      string obj2ToGet = getObjToGet(obj2);
138 >      objectsToFlag.push_back(tempInputCollection);
139 >      objectsToFlag.push_back(obj1);
140 >      objectsToFlag.push_back(obj2);
141 >      objectsToPlot.push_back(tempInputCollection);
142 >      objectsToPlot.push_back(obj1);
143 >      objectsToPlot.push_back(obj2);
144 >      objectsToGet.push_back(tempInputCollection);
145 >      objectsToGet.push_back(obj1);
146 >      objectsToGet.push_back(obj2ToGet);
147 >    } // end else
148 >      if (find(objectsToPlot.begin(), objectsToPlot.end(), "events") != objectsToPlot.end())
149 >        objectsToGet.push_back("jets");
150 >
151 >
152 >    vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
153 >
154 >    for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
155 >
156 >      vector<double> defaultValue;
157 >      defaultValue.push_back (-1.0);
158 >
159 >      histogram tempHistogram;
160 >      tempHistogram.inputCollection = tempInputCollection;
161 >      tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
162 >      tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
163 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
164 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
165 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
166 >      tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
167 >
168 >      histograms.push_back(tempHistogram);
169 >
170 >    }
171 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
172 >
173 >  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
174 >  sort( objectsToPlot.begin(), objectsToPlot.end() );
175 >  objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
176 >
177 >
178 >
179 >  //add histograms with the gen-matched id, mother id, and grandmother id
180 >  for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
181 >
182 >    string currentObject = objectsToPlot.at(currentObjectIndex);
183 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "secondary photons"&& currentObject != "superclusters") continue;
184 >
185 >    histogram tempIdHisto;
186 >    histogram tempMomIdHisto;
187 >    histogram tempGmaIdHisto;
188 >    histogram tempIdVsMomIdHisto;
189 >    histogram tempIdVsGmaIdHisto;
190 >
191 >    tempIdHisto.inputCollection = currentObject;
192 >    tempMomIdHisto.inputCollection = currentObject;
193 >    tempGmaIdHisto.inputCollection = currentObject;
194 >    tempIdVsMomIdHisto.inputCollection = currentObject;
195 >    tempIdVsGmaIdHisto.inputCollection = currentObject;
196 >
197 >    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
198 >    if(currentObject == "secondary photons") currentObject = "secondaryPhotons";
199 >    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
200 >
201 >    currentObject = currentObject.substr(0, currentObject.size()-1);
202 >    tempIdHisto.name = currentObject+"GenMatchId";
203 >    tempMomIdHisto.name = currentObject+"GenMatchMotherId";
204 >    tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
205 >    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
206 >    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
207 >
208 >    currentObject.at(0) = toupper(currentObject.at(0));
209 >    tempIdHisto.title = currentObject+" Gen-matched Particle";
210 >    tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
211 >    tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
212 >    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
213 >    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
214 >
215 >
216 >    int maxNum = 25;
217 >    vector<double> binVector;
218 >    binVector.push_back(maxNum);
219 >    binVector.push_back(0);
220 >    binVector.push_back(maxNum);
221 >
222 >    tempIdHisto.bins = binVector;
223 >    tempIdHisto.inputVariables.push_back("genMatchedId");
224 >    tempMomIdHisto.bins = binVector;
225 >    tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
226 >    tempGmaIdHisto.bins = binVector;
227 >    tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
228 >    binVector.push_back(maxNum);
229 >    binVector.push_back(0);
230 >    binVector.push_back(maxNum);
231 >    tempIdVsMomIdHisto.bins = binVector;
232 >    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
233 >    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
234 >    tempIdVsGmaIdHisto.bins = binVector;
235 >    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
236 >    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
237 >
238 >    histograms.push_back(tempIdHisto);
239 >    histograms.push_back(tempMomIdHisto);
240 >    histograms.push_back(tempGmaIdHisto);
241 >    histograms.push_back(tempIdVsMomIdHisto);
242 >    histograms.push_back(tempIdVsGmaIdHisto);
243 >  }
244  
245  
246    channel tempChannel;
247    //loop over all channels (event selections)
248    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
249 <    
249 >
250      //get name of channel
251      string channelName  (channels_.at(currentChannel).getParameter<string>("name"));
252      tempChannel.name = channelName;
# Line 41 | Line 255 | OSUAnalysis::OSUAnalysis (const edm::Par
255      //set triggers for this channel
256      vector<string> triggerNames;
257      triggerNames.clear();
258 +    vector<string> triggerToVetoNames;
259 +    triggerToVetoNames.clear();
260 +
261      tempChannel.triggers.clear();
262 +    tempChannel.triggersToVeto.clear();
263      if(channels_.at(currentChannel).exists("triggers")){
264        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
265        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
266 <        tempChannel.triggers.push_back(triggerNames.at(trigger));
267 <      allNecessaryObjects.push_back("triggers");
266 >        tempChannel.triggers.push_back(triggerNames.at(trigger));
267 >      objectsToGet.push_back("triggers");
268 >    }
269 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
270 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
271 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
272 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
273 >      objectsToGet.push_back("triggers");
274      }
275  
276  
277 +
278      //create cutFlow for this channel
279      cutFlows_.push_back (new CutFlow (fs_, channelName));
280 <
281 <    //book a directory in the output file with the name of the channel
282 <    TFileDirectory subDir = fs_->mkdir( channelName );
58 <    directories.push_back(subDir);
59 <    std::map<std::string, TH1D*> histoMap;
60 <    oneDHists_.push_back(histoMap);
61 <
62 <
63 <    //muon histograms
64 <    allNecessaryObjects.push_back("muons");
65 <    oneDHists_.at(currentChannel)["muonPt"]  = directories.at(currentChannel).make<TH1D> ("muonPt",channelLabel+" channel: Muon Transverse Momentum; p_{T} [GeV]", 100, 0, 500);
66 <    oneDHists_.at(currentChannel)["muonEta"] = directories.at(currentChannel).make<TH1D> ("muonEta",channelLabel+" channel: Muon Eta; #eta", 100, -5, 5);
67 <    oneDHists_.at(currentChannel)["muonD0"] = directories.at(currentChannel).make<TH1D> ("muonD0",channelLabel+" channel: Muon d_{0}; d_{0} [cm] ", 1000, -1, 1);
68 <    oneDHists_.at(currentChannel)["muonAbsD0"] = directories.at(currentChannel).make<TH1D> ("muonAbsD0",channelLabel+" channel: Muon d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
69 <    oneDHists_.at(currentChannel)["muonD0Sig"] = directories.at(currentChannel).make<TH1D> ("muonD0Sig",channelLabel+" channel: Muon d_{0} Significance; d_{0} / #sigma_{d_{0}} ", 1000, -10.0, 10.0);
70 <    oneDHists_.at(currentChannel)["muonAbsD0Sig"] = directories.at(currentChannel).make<TH1D> ("muonAbsD0Sig",channelLabel+" channel: Muon d_{0} Significance; |d_{0}| / #sigma_{d_{0}} ", 1000, 0, 10.0);
71 <    oneDHists_.at(currentChannel)["muonIso"] = directories.at(currentChannel).make<TH1D> ("muonIso",channelLabel+" channel: Muon Combined Relative Isolation; rel. iso. ", 1000, 0, 1);
72 <    oneDHists_.at(currentChannel)["numMuons"] = directories.at(currentChannel).make<TH1D> ("numMuons",channelLabel+" channel: Number of Selected Muons; # muons", 10, 0, 10);
73 <
74 <
75 <    //electron histograms
76 <    allNecessaryObjects.push_back("electrons");
77 <    oneDHists_.at(currentChannel)["electronPt"]  = directories.at(currentChannel).make<TH1D> ("electronPt",channelLabel+" channel: Electron Transverse Momentum; p_{T} [GeV]", 100, 0, 500);
78 <    oneDHists_.at(currentChannel)["electronEta"] = directories.at(currentChannel).make<TH1D> ("electronEta",channelLabel+" channel: Electron Eta; #eta", 50, -5, 5);
79 <    oneDHists_.at(currentChannel)["electronD0"] = directories.at(currentChannel).make<TH1D> ("electronD0",channelLabel+" channel: Electron d_{0}; d_{0} [cm] ", 1000, -1, 1);
80 <    oneDHists_.at(currentChannel)["electronAbsD0"] = directories.at(currentChannel).make<TH1D> ("electronAbsD0",channelLabel+" channel: Electron d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
81 <    oneDHists_.at(currentChannel)["electronD0Sig"] = directories.at(currentChannel).make<TH1D> ("electronD0Sig",channelLabel+" channel: Electron d_{0} Significance; d_{0} / #sigma_{d_{0}} ", 1000, -10.0, 10.0);
82 <    oneDHists_.at(currentChannel)["electronAbsD0Sig"] = directories.at(currentChannel).make<TH1D> ("electronAbsD0Sig",channelLabel+" channel: Electron d_{0} Significance; |d_{0}| / #sigma_{d_{0}} ", 1000, 0, 10.0);
83 <    oneDHists_.at(currentChannel)["electronIso"] = directories.at(currentChannel).make<TH1D> ("electronIso",channelLabel+" channel: Electron Combined Relative Isolation; rel. iso. ", 1000, 0, 1);
84 <    oneDHists_.at(currentChannel)["electronFbrem"] = directories.at(currentChannel).make<TH1D> ("electronFbrem",channelLabel+" channel: Electron Brem. Energy Fraction; fbrem", 1000, 0, 2);
85 <    oneDHists_.at(currentChannel)["numElectrons"] = directories.at(currentChannel).make<TH1D> ("numElectrons",channelLabel+" channel: Number of Selected Electrons; # electrons", 10, 0, 10);
86 <
87 <
88 <
280 >    vector<TFileDirectory> directories; //vector of directories in the output file.
281 >    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
282 >    vector<string> subSubDirNames;//subdirectories in each channel.
283      //get list of cuts for this channel
284      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
285  
92    vector<string> tempInputCollections;
93
286  
287      //loop over and parse all cuts
288      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
97
289        cut tempCut;
290 <     //store input collection for cut
291 <      string inputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
292 <      tempCut.inputCollection = inputCollection;
293 <      
294 <      tempInputCollections.push_back(inputCollection);
295 <      allNecessaryObjects.push_back(inputCollection);
290 >      //store input collection for cut
291 >      string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
292 >      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
293 >      if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
294 >      if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
295 >      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
296 >      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
297 >      if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
298 >      if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
299 >      if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
300 >      if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
301 >      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
302 >      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
303 >      if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
304 >      if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
305 >      if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
306 >      if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
307 >      if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
308 >      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
309 >      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
310 >      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
311 >      tempCut.inputCollection = tempInputCollection;
312 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
313 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
314 >          int spaceIndex = tempInputCollection.find(" ");
315 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
316 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
317 >        }
318 >        else{
319 >          objectsToGet.push_back(tempInputCollection);
320 >        }
321 >        objectsToCut.push_back(tempInputCollection);
322 >        objectsToFlag.push_back(tempInputCollection);
323 >      }
324 >      else{//pair of objects, need to add them both to objectsToGet
325 >        string obj1;
326 >        string obj2;
327 >        getTwoObjs(tempInputCollection, obj1, obj2);
328 >        string obj2ToGet = getObjToGet(obj2);
329 >        objectsToCut.push_back(tempInputCollection);
330 >        objectsToCut.push_back(obj1);
331 >        objectsToCut.push_back(obj2);
332 >        objectsToFlag.push_back(tempInputCollection);
333 >        objectsToFlag.push_back(obj1);
334 >        objectsToFlag.push_back(obj2);
335 >        objectsToGet.push_back(tempInputCollection);
336 >        objectsToGet.push_back(obj1);
337 >        objectsToGet.push_back(obj2ToGet);
338 >
339 >      }
340 >
341 >
342  
343        //split cut string into parts and store them
344        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
345 <      std::vector<string> cutStringVector = splitString(cutString);
346 <      tempCut.variable = cutStringVector.at(0);// variable to cut on
347 <      tempCut.comparativeOperator = cutStringVector.at(1);// comparison to make
348 <      tempCut.cutValue = atof(cutStringVector.at(2).c_str());// threshold value to pass cut
345 >      vector<string> cutStringVector = splitString(cutString);
346 >      if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
347 >        clog << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
348 >        exit(0);
349 >      }
350 >      tempCut.numSubcuts = (cutStringVector.size()+1)/4;
351 >      for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
352 >        int indexOffset = 4 * subcutIndex;
353 >        string currentVariableString = cutStringVector.at(indexOffset);
354 >        if(currentVariableString.find("(")==string::npos){
355 >          tempCut.functions.push_back("");//no function was specified
356 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
357 >        }
358 >        else{
359 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
360 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
361 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
362 >        }
363 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
364 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
365 >        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
366 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
367 >      }
368  
369        //get number of objects required to pass cut for event to pass
370        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
371 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
372 <
373 <      // determine number required if comparison contains "="
374 <      int numberRequiredInt = atoi(numberRequiredVector.at(1).c_str());
375 <      if(numberRequiredVector.at(0) == ">") numberRequiredInt++;
120 <      else if(numberRequiredVector.at(0) == "<") numberRequiredInt--;
371 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
372 >      if(numberRequiredVector.size()!=2){
373 >        clog << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
374 >        exit(0);
375 >      }
376  
377 +      int numberRequiredInt = atoi(numberRequiredVector.at(1).c_str());
378        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
379        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
380 <      
381 <      if(cuts_.at(currentCut).exists("function")){
382 <        tempCut.function = cuts_.at(currentCut).getParameter<string> ("function");
127 <      }
128 <      else tempCut.function = "";
380 >
381 >      //Set up vectors to store the directories and subDirectories for each channel.
382 >      string subSubDirName;
383        string tempCutName;
384        if(cuts_.at(currentCut).exists("alias")){
385 <        tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
385 >        tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
386 >        subSubDirName = "After " + tempCutName + " Cut Applied";
387        }
388        else{
389 <        //construct string for cutflow table
390 <        bool plural = numberRequiredInt != 1;
391 <        string collectionString = plural ? inputCollection : inputCollection.substr(0, inputCollection.size()-1);
392 <        string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
393 <        tempCutName = cutName;
389 >        //construct string for cutflow table
390 >        bool plural = numberRequiredInt != 1;
391 >        string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
392 >        string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
393 >        tempCutName = cutName;
394 >        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
395        }
140      tempCut.name = tempCutName;
396  
397 +      tempCut.isVeto = false;
398 +      if(cuts_.at(currentCut).exists("isVeto")){
399 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
400 +        if (isVeto == true) tempCut.isVeto = true;
401 +      }
402 +      subSubDirNames.push_back(subSubDirName);
403 +      tempCut.name = tempCutName;
404  
405        tempChannel.cuts.push_back(tempCut);
406  
407  
408      }//end loop over cuts
409  
410 <    //make unique vector of all objects that this channel cuts on (so we know to set flags for those)
411 <    sort( tempInputCollections.begin(), tempInputCollections.end() );
412 <    tempInputCollections.erase( unique( tempInputCollections.begin(), tempInputCollections.end() ), tempInputCollections.end() );
413 <    tempChannel.inputCollections = tempInputCollections;    
410 >    vector<map<string, TH1D*>> oneDHistsTmp;
411 >    vector<map<string, TH2D*>> twoDHistsTmp;
412 >    //book a directory in the output file with the name of the channel
413 >    TFileDirectory subDir = fs_->mkdir( channelName );
414 >    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
415 >    if(GetPlotsAfterEachCut_){
416 >      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
417 >        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
418 >        directories.push_back(subSubDir);
419 >        map<string, TH1D*> oneDhistoMap;
420 >        oneDHistsTmp.push_back(oneDhistoMap);
421 >        map<string, TH2D*> twoDhistoMap;
422 >        twoDHistsTmp.push_back(twoDhistoMap);
423 >      }
424 >      treeDirectories.push_back(subDir);
425 >      oneDHists_.push_back(oneDHistsTmp);
426 >      twoDHists_.push_back(twoDHistsTmp);
427 >    }
428 >    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
429 >    else{
430 >      map<string, TH1D*> oneDhistoMap;
431 >      oneDHistsTmp.push_back(oneDhistoMap);
432 >      map<string, TH2D*> twoDhistoMap;
433 >      twoDHistsTmp.push_back(twoDhistoMap);
434 >      oneDHists_.push_back(oneDHistsTmp);
435 >      twoDHists_.push_back(twoDHistsTmp);
436 >      directories.push_back(subDir);
437 >      treeDirectories.push_back(subDir);
438 >
439 >    }
440 >
441 >    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
442 >      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
443 >      BNTrees_.push_back(newTree);
444 >      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
445 >        BranchSpecs currentVar = treeBranches_.at(iBranch);
446 >        vector<float> newVec;
447 >        BNTreeBranchVals_[currentVar.name] = newVec;
448 >        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
449 >      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
450 >    }
451 >
452 >    //book all histograms included in the configuration
453 >    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
454 >
455 >      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
456 >
457 >        histogram currentHistogram = histograms.at(currentHistogramIndex);
458 >        int numBinsElements = currentHistogram.bins.size();
459 >        int numInputVariables = currentHistogram.inputVariables.size();
460 >        int numBinEdgesX = currentHistogram.variableBinsX.size();
461 >        int numBinEdgesY = currentHistogram.variableBinsY.size();
462 >
463 >        if(numBinsElements == 1){
464 >          if(numBinEdgesX > 1){
465 >            if(numBinEdgesY > 1)
466 >              numBinsElements = 6;
467 >            else
468 >              numBinsElements = 3;
469 >          }
470 >        }
471 >        if(numBinsElements != 3 && numBinsElements !=6){
472 >          clog << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
473 >          exit(0);
474 >        }
475 >        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
476 >          clog << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
477 >          exit(0);
478 >        }
479 >        else if(numBinsElements == 3){
480 >          if (currentHistogram.bins.size () == 3)
481 >            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
482 >          else
483 >            {
484 >              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
485 >            }
486 >        }
487 >        else if(numBinsElements == 6){
488 >          if (currentHistogram.bins.size () == 6)
489 >            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2),currentHistogram.bins.at(3),currentHistogram.bins.at(4),currentHistogram.bins.at(5));
490 >          else
491 >            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data (), numBinEdgesY - 1, currentHistogram.variableBinsY.data ());
492 >        }
493 >
494 >
495 >        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
496  
497 +        // bin      particle type
498 +        // ---      -------------
499 +        //  0        unmatched
500 +        //  1        u
501 +        //  2        d
502 +        //  3        s
503 +        //  4        c
504 +        //  5        b
505 +        //  6        t
506 +        //  7        e
507 +        //  8        mu
508 +        //  9        tau
509 +        // 10        nu
510 +        // 11        g
511 +        // 12        gamma
512 +        // 13        Z
513 +        // 14        W
514 +        // 15        light meson
515 +        // 16        K meson
516 +        // 17        D meson
517 +        // 18        B meson
518 +        // 19        light baryon
519 +        // 20        strange baryon
520 +        // 21        charm baryon
521 +        // 22        bottom baryon
522 +        // 23        QCD string
523 +        // 24        other
524 +
525 +        vector<TString> labelArray;
526 +        labelArray.push_back("unmatched");
527 +        labelArray.push_back("u");
528 +        labelArray.push_back("d");
529 +        labelArray.push_back("s");
530 +        labelArray.push_back("c");
531 +        labelArray.push_back("b");
532 +        labelArray.push_back("t");
533 +        labelArray.push_back("e");
534 +        labelArray.push_back("#mu");
535 +        labelArray.push_back("#tau");
536 +        labelArray.push_back("#nu");
537 +        labelArray.push_back("g");
538 +        labelArray.push_back("#gamma");
539 +        labelArray.push_back("Z");
540 +        labelArray.push_back("W");
541 +        labelArray.push_back("light meson");
542 +        labelArray.push_back("K meson");
543 +        labelArray.push_back("D meson");
544 +        labelArray.push_back("B meson");
545 +        labelArray.push_back("light baryon");
546 +        labelArray.push_back("strange baryon");
547 +        labelArray.push_back("charm baryon");
548 +        labelArray.push_back("bottom baryon");
549 +        labelArray.push_back("QCD string");
550 +        labelArray.push_back("other");
551 +
552 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
553 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
554 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
555 +          }
556 +          else {
557 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
558 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
559 +          }
560 +        }
561 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
562 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
563 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
564 +        }
565 +
566 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
567 +
568 +
569 +      // Book a histogram for the number of each object type to be plotted.
570 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
571 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
572 +        string currentObject = objectsToPlot.at(currentObjectIndex);
573 +        int maxNum = 10;
574 +        if(currentObject == "mcparticles") maxNum = 50;
575 +        else if(currentObject == "primaryvertexs") maxNum = 50;
576 +
577 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
578 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
579 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
580 +        else if(currentObject == "electron-photon pairs")     currentObject = "electronPhotonPairs";
581 +        else if(currentObject == "muon-photon pairs")         currentObject = "muonPhotonPairs";
582 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
583 +        else if(currentObject == "secondary photons")            currentObject = "secondaryPhotons";
584 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
585 +        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
586 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
587 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
588 +        else if(currentObject == "muon-event pairs")            currentObject = "muonEventPairs";
589 +        else if(currentObject == "photon-jet pairs")            currentObject = "photonJetPairs";
590 +        else if(currentObject == "met-jet pairs")             currentObject = "metJetPairs";
591 +        else if(currentObject == "track-jet pairs")           currentObject = "trackJetPairs";
592 +        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
593 +        else if(currentObject == "muon-secondary photon pairs")  currentObject = "muonSecondaryPhotonPairs";
594 +        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
595 +        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
596 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
597 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
598 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
599 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
600 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
601 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
602 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
603 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
604 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
605 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
606 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
607 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
608 +
609 +        currentObject.at(0) = toupper(currentObject.at(0));
610 +        string histoName = "num" + currentObject;
611 +
612 +        if(histoName == "numPrimaryvertexs"){
613 +          string newHistoName = histoName + "BeforePileupCorrection";
614 +          oneDHists_.at(currentChannel).at(currentDir)[newHistoName] = directories.at(currentDir).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
615 +          newHistoName = histoName + "AfterPileupCorrection";
616 +          oneDHists_.at(currentChannel).at(currentDir)[newHistoName] = directories.at(currentDir).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
617 +        }
618 +        else
619 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
620 +      }
621 +    }//end of loop over directories
622      channels.push_back(tempChannel);
623      tempChannel.cuts.clear();
155
624    }//end loop over channels
625  
158  //make unique vector of objects we need to cut on (so we make sure to get them from the event)
159  sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
160  allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
626  
627 +  //make unique vector of objects we need to get from the event
628 +  sort( objectsToGet.begin(), objectsToGet.end() );
629 +  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
630 +  //make unique vector of objects we need to cut on
631 +  sort( objectsToCut.begin(), objectsToCut.end() );
632 +  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
633 +  //make unique vector of objects we need to set flags for
634 +  sort( objectsToFlag.begin(), objectsToFlag.end() );
635 +  objectsToFlag.erase( unique( objectsToFlag.begin(), objectsToFlag.end() ), objectsToFlag.end() );
636 +
637 +  produces<map<string, bool> > ("channelDecisions");
638 +
639 +  if (printEventInfo_) {
640 +    findEventsLog = new ofstream();  
641 +    findEventsLog->open("findEvents.txt");  
642 +    clog << "Listing run:lumi:event in file findEvents.txt for events that pass full selection (of any channel)." << endl;  
643 +  }
644 +
645 +  isFirstEvent_ = true;  
646 +
647 + } // end constructor OSUAnalysis::OSUAnalysis()
648  
163 }
649  
650   OSUAnalysis::~OSUAnalysis ()
651   {
652 +
653    // Destroying the CutFlow objects causes the cut flow numbers and time
654    // information to be printed to standard output.
655    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
656      delete cutFlows_.at(currentChannel);
657    }
658 +
659 +  if (printEventInfo_ && findEventsLog) findEventsLog->close();  
660 +
661 +  clog << "=============================================" << endl;  
662 +  clog << "Successfully completed OSUAnalysis." << endl;  
663 +  clog << "=============================================" << endl;  
664 +
665   }
666  
667   void
668 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
668 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
669   {
177
178
670    // Retrieve necessary collections from the event.
671 <  edm::Handle<BNtriggerCollection> triggers;
672 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
671 >
672 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
673      event.getByLabel (triggers_, triggers);
674  
675 <  edm::Handle<BNjetCollection> jets;
676 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())  
675 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
676 >    event.getByLabel (trigobjs_, trigobjs);
677 >
678 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
679      event.getByLabel (jets_, jets);
680  
681 <  edm::Handle<BNmuonCollection> muons;
189 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())  
681 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
682      event.getByLabel (muons_, muons);
683  
684 <  edm::Handle<BNelectronCollection> electrons;
193 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())  
684 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
685      event.getByLabel (electrons_, electrons);
686  
687 <  edm::Handle<BNeventCollection> events;
197 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())  
687 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
688      event.getByLabel (events_, events);
689  
690 <  edm::Handle<BNtauCollection> taus;
201 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())  
690 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
691      event.getByLabel (taus_, taus);
692  
693 <  edm::Handle<BNmetCollection> mets;
205 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())  
693 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
694      event.getByLabel (mets_, mets);
695  
696 <  edm::Handle<BNtrackCollection> tracks;
209 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())  
696 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
697      event.getByLabel (tracks_, tracks);
698  
699 <  edm::Handle<BNgenjetCollection> genjets;
213 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())  
699 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
700      event.getByLabel (genjets_, genjets);
701  
702 <  edm::Handle<BNmcparticleCollection> mcparticles;
217 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())  
702 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
703      event.getByLabel (mcparticles_, mcparticles);
704  
705 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
221 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())  
705 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
706      event.getByLabel (primaryvertexs_, primaryvertexs);
707  
708 <  edm::Handle<BNbxlumiCollection> bxlumis;
225 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())  
708 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
709      event.getByLabel (bxlumis_, bxlumis);
710  
711 <  edm::Handle<BNphotonCollection> photons;
229 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())  
711 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
712      event.getByLabel (photons_, photons);
713  
714 <  edm::Handle<BNsuperclusterCollection> superclusters;
233 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())  
714 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
715      event.getByLabel (superclusters_, superclusters);
716  
717 +  if (datasetType_ == "signalMC"){
718 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
719 +      event.getByLabel (stops_, stops);
720 +  }
721 +
722 +  if (useTrackCaloRhoCorr_) {
723 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
724 +    // This rho collection is not available in all BEANs.
725 +    // For description of rho values for different jet reconstruction algorithms, see
726 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
727 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
728 +  }
729 +
730 +  double masterScaleFactor = 1.0;
731 +
732 +  //get pile-up event weight
733 +  if (doPileupReweighting_ && datasetType_ != "data") {
734 +    //for "data" datasets, the numTruePV is always set to -1
735 +    if (events->at(0).numTruePV < 0 && isFirstEvent_) clog << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
736 +    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
737 +  }
738 +
739 +  stopCTauScaleFactor_ = 1.0;
740 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
741 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
742 +  masterScaleFactor *= stopCTauScaleFactor_;
743  
744    //loop over all channels
745  
746 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
747    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
748      channel currentChannel = channels.at(currentChannelIndex);
241    
242    flagMap individualFlags;  
243    flagMap cumulativeFlags;  
244    counterMap passingCounter;
749  
750 <    if(currentChannel.triggers.size() != 0){  //triggers specified
751 <      bool triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
750 >    flagMap individualFlags;
751 >    counterMap passingCounter;
752 >    cumulativeFlags.clear ();
753 >
754 >    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
755 >         iter != BNTreeBranchVals_.end(); iter++) {
756 >      iter->second.clear();  // clear array
757 >    }
758 >
759 >    bool triggerDecision = true;
760 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
761 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
762        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
763      }
764  
# Line 252 | Line 766 | OSUAnalysis::analyze (const edm::Event &
766      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
767        cut currentCut = currentChannel.cuts.at(currentCutIndex);
768  
769 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
770 <
257 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
258 <        individualFlags[currentObject].push_back (vector<bool> ());
259 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
260 <
261 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
262 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
263 <        else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
264 <        else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
265 <        else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
266 <        else if(currentObject == "mets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
267 <        else if(currentObject == "tracks") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
268 <        else if(currentObject == "genjets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
269 <        else if(currentObject == "mcparticles") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
270 <        else if(currentObject == "primaryvertexs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
271 <        else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
272 <        else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
273 <        else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
769 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
770 >        string currentObject = objectsToFlag.at(currentObjectIndex);
771  
772 +        //initialize maps to get ready to set cuts
773 +        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
774 +        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
775  
776        }
777  
778 +      //set flags for all relevant objects
779 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
780 +        string currentObject = objectsToFlag.at(currentObjectIndex);
781 +
782 +        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
783 +
784 +
785 +        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
786 +        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
787 +        else if(currentObject == "secondary photons")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"secondary photons");
788 +        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
789 +        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
790 +        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
791 +        else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
792 +        else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
793 +        else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
794 +        else if(currentObject == "mets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
795 +        else if(currentObject == "tracks") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
796 +        else if(currentObject == "genjets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
797 +        else if(currentObject == "mcparticles") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
798 +        else if(currentObject == "primaryvertexs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
799 +        else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
800 +        else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
801 +        else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
802 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
803 +
804 +
805 +
806 +        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
807 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
808 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
809 +                                                                   "muon-muon pairs");
810 +
811 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
812 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
813 +                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
814 +                                                                             "muon-secondary muon pairs");
815 +
816 +        else if(currentObject == "muon-secondary photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
817 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
818 +                                                                             cumulativeFlags.at("secondary photons").at(flagsForPairCutsIndex), \
819 +                                                                             "muon-secondary photon pairs");
820 +        else if(currentObject == "muon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
821 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
822 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
823 +                                                                             "muon-secondary jet pairs");
824 +        else if(currentObject == "photon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
825 +                                                                             cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
826 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
827 +                                                                             "photon-secondary jet pairs");
828 +
829 +        else if(currentObject == "electron-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
830 +                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
831 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
832 +                                                                             "electron-secondary jet pairs");
833 +
834 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
835 +                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
836 +                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
837 +                                                                                     "electron-secondary electron pairs");
838 +
839 +        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
840 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
841 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
842 +                                                                           "electron-electron pairs");
843 +        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
844 +                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
845 +                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
846 +                                                                       "electron-muon pairs");
847 +        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
848 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
849 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
850 +                                                                 "jet-jet pairs");
851 +        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
852 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
853 +                                                                 cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex),\
854 +                                                                 "jet-secondary jet pairs");
855 +        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
856 +                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
857 +                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
858 +                                                                      "electron-jet pairs");
859 +        else if(currentObject == "electron-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), \
860 +                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
861 +                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
862 +                                                                      "electron-photon pairs");
863 +        else if(currentObject == "photon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
864 +                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
865 +                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
866 +                                                                      "photon-jet pairs");
867 +        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
868 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
869 +                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
870 +                                                                  "muon-jet pairs");
871 +        else if(currentObject == "muon-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),events.product(), \
872 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
873 +                                                                  cumulativeFlags.at("events").at(flagsForPairCutsIndex), \
874 +                                                                  "muon-event pairs");
875 +        else if(currentObject == "met-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),jets.product(), \
876 +                                                                  cumulativeFlags.at("mets").at(flagsForPairCutsIndex), \
877 +                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
878 +                                                                  "met-jet pairs");
879 +        else if(currentObject == "track-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),jets.product(), \
880 +                                                                 cumulativeFlags.at("tracks").at(flagsForPairCutsIndex), \
881 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
882 +                                                                 "track-jet pairs");
883 +        else if(currentObject == "muon-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
884 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
885 +                                                                  cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
886 +                                                                  "muon-photon pairs");
887 +        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
888 +                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
889 +                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
890 +                                                                     "track-event pairs");
891 +        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
892 +                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
893 +                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
894 +                                                                        "electron-track pairs");
895 +        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
896 +                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
897 +                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
898 +                                                                    "muon-track pairs");
899 +        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
900 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
901 +                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
902 +                                                                  "muon-tau pairs");
903 +        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
904 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
905 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
906 +                                                                 "tau-tau pairs");
907 +        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
908 +                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
909 +                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
910 +                                                                   "tau-track pairs");
911 +        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
912 +                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
913 +                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
914 +                                                                          "electron-trigobj pairs");
915 +        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
916 +                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
917 +                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
918 +                                                                      "muon-trigobj pairs");
919  
920 <
921 <    }//end loop over all cuts
281 <    
920 >        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
921 >      }
922  
923  
924  
925 +    }//end loop over all cuts
926      //use cumulative flags to apply cuts at event level
927  
928 +    //a vector to store cumulative cut descisions after each cut.
929 +    vector<bool> eventPassedPreviousCuts;
930      bool eventPassedAllCuts = true;
931 +    //apply trigger (true if none were specified)
932 +    eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
933  
934      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
935  
# Line 292 | Line 937 | OSUAnalysis::analyze (const edm::Event &
937        cut currentCut = currentChannel.cuts.at(currentCutIndex);
938        int numberPassing = 0;
939  
940 <      for (uint object = 0; object != cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).size() ; object++)
941 <          if(cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).at(object)) numberPassing++;
942 <
298 <
940 >      for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
941 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
942 >      }
943        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
944        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
301
945        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
946 +      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
947 +    }
948 +    //applying all appropriate scale factors
949 +    double scaleFactor = masterScaleFactor;
950 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
951 +
952 +    if(applyLeptonSF_ && datasetType_ != "data"){
953 +      //only apply SFs if we've cut on this object
954 +      if(find(objectsToCut.begin(),objectsToCut.end(),"muons") != objectsToCut.end ()){
955 +        flagPair muonFlags;
956 +        //get the last valid flags in the flag map
957 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
958 +          if (cumulativeFlags.at("muons").at(i).size()){
959 +            muonFlags = cumulativeFlags.at("muons").at(i);
960 +            break;
961 +          }
962 +        }
963 +        //apply the weight for each of those objects
964 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
965 +          if(!muonFlags.at(muonIndex).second) continue;
966 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
967 +        }
968 +      }
969 +      //only apply SFs if we've cut on this object
970 +      if(find(objectsToCut.begin(),objectsToCut.end(),"electrons") != objectsToCut.end ()){
971 +        flagPair electronFlags;
972 +        //get the last valid flags in the flag map
973 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
974 +          if (cumulativeFlags.at("electrons").at(i).size()){
975 +            electronFlags = cumulativeFlags.at("electrons").at(i);
976 +            break;
977 +          }
978 +        }
979 +        //apply the weight for each of those objects
980 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
981 +          if(!electronFlags.at(electronIndex).second) continue;
982 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
983 +        }
984 +      }
985 +    }
986 +    if(applyBtagSF_ && datasetType_ != "data"){
987 +      //only apply SFs if we've cut on this object
988 +      if(find(objectsToCut.begin(),objectsToCut.end(),"jets") != objectsToCut.end ()){
989 +        flagPair jetFlags;
990 +        vector<double> jetSFs;
991 +        //get the last valid flags in the flag map
992 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
993 +          if (cumulativeFlags.at("jets").at(i).size()){
994 +            jetFlags = cumulativeFlags.at("jets").at(i);
995 +            break;
996 +          }
997 +        }
998 +        //apply the weight for each of those objects
999 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
1000 +          if(!jetFlags.at(jetIndex).second) continue;
1001 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour, jets->at(jetIndex).eta);
1002 +          jetSFs.push_back(jetSFTmp);
1003 +        }
1004 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_);
1005 +      }
1006 +    }
1007 +    scaleFactor *= muonScaleFactor_;
1008 +    scaleFactor *= electronScaleFactor_;
1009 +    scaleFactor *= bTagScaleFactor_;
1010 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
1011 +
1012 +    if (printEventInfo_ && eventPassedAllCuts) {
1013 +      // Write information about event to screen, for testing purposes.
1014 +      clog << "Event passed all cuts in channel " <<  currentChannel.name
1015 +           << ":  run:lumi:evt=  "  << events->at(0).run
1016 +           << ":" << events->at(0).lumi
1017 +           << ":" << events->at(0).evt
1018 +           << endl;
1019 +      if (findEventsLog) {
1020 +        (*findEventsLog) << events->at(0).run
1021 +                         << ":" << events->at(0).lumi
1022 +                         << ":" << events->at(0).evt << endl;
1023 +      }
1024  
1025      }
1026  
1027 <    cutFlows_.at(currentChannelIndex)->fillCutFlow();  
1028 <  
1027 >
1028 >    //filling histograms
1029 >    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
1030 >      uint currentDir;
1031 >      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
1032 >      else{
1033 >        currentDir = currentCut;
1034 >      }
1035  
1036  
1037 <    if(!eventPassedAllCuts)continue;
1037 >      if(eventPassedPreviousCuts.at(currentDir)){
1038  
1039 +        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1040 +          histogram currentHistogram = histograms.at(histogramIndex);
1041  
1042 +          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) clog << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
1043  
1044 <    vector<bool> electronFlags = cumulativeFlags["electrons"].back();
1045 <    int electronCounter = 0;
1044 >          if(currentHistogram.inputVariables.size() == 1){
1045 >            TH1D* histo;
1046 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1047 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1048 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1049 >            else if(currentHistogram.inputCollection == "secondary photons")  fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1050 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1051 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1052 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1053 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1054 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1055 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1056 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1057 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1058 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1059 >             else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1060 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary photons").at(currentDir), \
1061 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1062 >             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1063 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1064 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1065 >             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1066 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1067 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1068 >             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1069 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1070 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1071 >
1072 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1073 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
1074 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
1075 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1076 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
1077 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
1078 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1079 >             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1080 >                                                                                                     cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1081 >                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1082 >
1083 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1084 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1085 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1086 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
1087 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
1088 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1089 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
1090 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1091 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1092 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(), \
1093 >                                                                                              cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1094 >                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1095 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
1096 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1097 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1098 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill1DHistogram(histo,currentHistogram, muons.product(),events.product(), \
1099 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1100 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1101 >            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, mets.product(),jets.product(), \
1102 >                                                                                          cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1103 >                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1104 >            else if(currentHistogram.inputCollection == "track-jet pairs")  fill1DHistogram(histo,currentHistogram,tracks.product(),jets.product(), \
1105 >                                                                                          cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1106 >                                                                                          cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1107 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(), \
1108 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1109 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1110 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(), \
1111 >                                                                                          cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1112 >                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1113 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1114 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1115 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1116 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1117 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1118 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1119 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1120 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1121 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1122 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1123 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1124 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1125 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1126 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1127 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1128 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1129 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1130 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1131 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1132 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1133 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1134 >
1135 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1136 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1137 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1138 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1139 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1140 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1141 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1142 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1143 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1144 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1145 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1146 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1147 >          }
1148 >          else if(currentHistogram.inputVariables.size() == 2){
1149 >            TH2D* histo;
1150 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1151 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1152 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1153 >            else if(currentHistogram.inputCollection == "secondary photons")  fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1154 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1155 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1156 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1157 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1158 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1159 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1160 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1161 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1162 >            else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1163 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary photons").at(currentDir), \
1164 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1165 >            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1166 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1167 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1168 >            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1169 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1170 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1171 >            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1172 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1173 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1174 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1175 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1176 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1177 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1178 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1179 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1180 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1181 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1182 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1183 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1184 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1185 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1186 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1187 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1188 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1189 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1190 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1191 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(), \
1192 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1193 >                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1194 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1195 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1196 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1197 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill2DHistogram(histo,currentHistogram,muons.product(),events.product(), \
1198 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("events").at(currentDir), \
1199 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1200 >            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,mets.product(),jets.product(), \
1201 >                                                                                         cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1202 >                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1203 >            else if(currentHistogram.inputCollection == "track-jet pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1204 >                                                                                         cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1205 >                                                                                         cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1206 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1207 >                                                                                          cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1208 >                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1209 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1210 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1211 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1212 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1213 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1214 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1215 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1216 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1217 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1218 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1219 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1220 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1221 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1222 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1223 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1224 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1225 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1226 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1227 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1228 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1229 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1230 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1231 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1232 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1233 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1234 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1235 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1236 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1237 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1238 >                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1239 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1240 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1241 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1242 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1243 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1244 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1245 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1246 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1247 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1248 >          }
1249  
1250 <    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
318 <      if(!electronFlags.at(electronIndex)) continue;
1250 >        }
1251  
1252  
1253 <      electronCounter++;
1254 <      oneDHists_.at(currentChannelIndex)["electronPt"]->Fill (electrons->at(electronIndex).pt);
323 <      oneDHists_.at(currentChannelIndex)["electronEta"]->Fill (electrons->at(electronIndex).eta);
324 <      oneDHists_.at(currentChannelIndex)["electronD0"]->Fill (electrons->at(electronIndex).correctedD0Vertex);
325 <      oneDHists_.at(currentChannelIndex)["electronAbsD0"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex));
326 <      oneDHists_.at(currentChannelIndex)["electronD0Sig"]->Fill (electrons->at(electronIndex).correctedD0Vertex / electrons->at(electronIndex).tkD0err);
327 <      oneDHists_.at(currentChannelIndex)["electronAbsD0Sig"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex) / electrons->at(electronIndex).tkD0err);
328 <      oneDHists_.at(currentChannelIndex)["electronIso"]->Fill (((electrons->at(electronIndex).trackIso + electrons->at(electronIndex).caloIso) / electrons->at(electronIndex).pt));
329 <      oneDHists_.at(currentChannelIndex)["electronFbrem"]->Fill (electrons->at(electronIndex).fbrem);
330 <    }
331 <    oneDHists_.at(currentChannelIndex)["numElectrons"]->Fill (electronCounter);
332 <
333 <    
334 <    vector<bool> muonFlags = cumulativeFlags["muons"].back();
335 <    int muonCounter = 0;
1253 >        //fills histograms with the sizes of collections
1254 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1255  
1256 +          string currentObject = objectsToPlot.at(currentObjectIndex);
1257 +          string objectToPlot = "";
1258  
1259 <    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
1260 <      if(!muonFlags.at(muonIndex)) continue;
1261 <      muonCounter++;
1259 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1260 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1261 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1262 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1263 >          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1264 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1265 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1266 >          else if(currentObject == "muon-event pairs")                     objectToPlot = "muonEventPairs";
1267 >          else if(currentObject == "muon-photon pairs")                     objectToPlot = "muonPhotonPairs";
1268 >          else if(currentObject == "photon-jet pairs")                     objectToPlot = "photonJetPairs";
1269 >          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1270 >          else if(currentObject == "track-jet pairs")                    objectToPlot = "trackJetPairs";
1271 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1272 >          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1273 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1274 >          else if(currentObject == "secondary photons")                     objectToPlot = "secondaryPhotons";
1275 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1276 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1277 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1278 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1279 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1280 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1281 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1282 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1283 >          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1284 >          else if(currentObject == "muon-secondary photon pairs")           objectToPlot = "muonSecondaryJetPairs";
1285 >          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1286 >          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1287 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1288 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1289 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1290 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1291 >          else objectToPlot = currentObject;
1292 >
1293 >          string tempCurrentObject = objectToPlot;
1294 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1295 >          string histoName = "num" + tempCurrentObject;
1296 >
1297 >
1298 >          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1299 >            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1300 >            int numToPlot = 0;
1301 >            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1302 >              if(lastCutFlags.at(currentFlag).second) numToPlot++;
1303 >            }
1304 >
1305 >            if(objectToPlot == "primaryvertexs"){
1306 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1307 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1308 >            }
1309 >            else {
1310 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1311 >            }
1312 >          }
1313 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1314  
342      oneDHists_.at(currentChannelIndex)["muonPt"]->Fill (muons->at(muonIndex).pt);
343      oneDHists_.at(currentChannelIndex)["muonEta"]->Fill (muons->at(muonIndex).eta);
344      oneDHists_.at(currentChannelIndex)["muonD0"]->Fill (muons->at(muonIndex).correctedD0Vertex);
345      oneDHists_.at(currentChannelIndex)["muonAbsD0"]->Fill (fabs(muons->at(muonIndex).correctedD0Vertex));
346      oneDHists_.at(currentChannelIndex)["muonD0Sig"]->Fill (muons->at(muonIndex).correctedD0Vertex / muons->at(muonIndex).tkD0err);
347      oneDHists_.at(currentChannelIndex)["muonAbsD0Sig"]->Fill (fabs(muons->at(muonIndex).correctedD0Vertex) / muons->at(muonIndex).tkD0err);
348      oneDHists_.at(currentChannelIndex)["muonIso"]->Fill (((muons->at(muonIndex).trackIso + muons->at(muonIndex).caloIso) / muons->at(muonIndex).pt));
349    }
350    oneDHists_.at(currentChannelIndex)["numMuons"]->Fill (muonCounter);
1315  
1316 +      } // end if(eventPassedPreviousCuts.at(currentDir))
1317 +    } // end loop over cuts
1318  
1319 +    if (!useEDMFormat_ && eventPassedAllCuts){
1320 +      // Assign BNTree variables
1321 +      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1322 +        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1323 +        string coll = brSpecs.inputCollection;
1324 +        if (cumulativeFlags.count(coll) == 0) clog << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1325 +
1326 +        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1327 +        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1328 +        else if(coll == "secondary photons")      assignTreeBranch(brSpecs,photons.product(),          cumulativeFlags.at(coll).back());
1329 +        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1330 +        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1331 +        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1332 +        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1333 +        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1334 +        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1335 +        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1336 +        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1337 +        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1338 +        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1339 +        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1340 +        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1341 +        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1342 +        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1343 +        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1344 +        else if(coll == "stops"
1345 +                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1346 +      } // end loop over branches
1347  
1348 +      if (!BNTrees_.at(currentChannelIndex)) { clog << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1349 +      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1350 +    }
1351  
1352 +    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1353  
1354 <  } //end loop over channel
1354 >  } // end loop over channel
1355  
1356 <  masterCutFlow_->fillCutFlow();    
1356 >  masterCutFlow_->fillCutFlow(masterScaleFactor);
1357  
1358 +  event.put (channelDecisions, "channelDecisions");
1359 +
1360 +  isFirstEvent_ = false;  
1361 +
1362 + } // end void OSUAnalysis::produce (const edm::Event &event, const edm::EventSetup &setup)
1363  
361 }
1364  
1365  
1366 < bool
1366 > bool
1367   OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
1368  
1369  
# Line 369 | Line 1371 | OSUAnalysis::evaluateComparison (double
1371    else if(comparison == ">=") return testValue >= cutValue;
1372    else if(comparison == "<")  return testValue <  cutValue;
1373    else if(comparison == "<=") return testValue <= cutValue;
1374 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1374 >  else if(comparison == "==") return testValue == cutValue;
1375 >  else if(comparison == "=") return testValue == cutValue;
1376 >  else if(comparison == "!=") return testValue != cutValue;
1377 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1378 >
1379 > }
1380 >
1381 > bool
1382 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1383 >
1384 >
1385 >  if(comparison == ">")       return testValue >  cutValue;
1386 >  else if(comparison == ">=") return testValue >= cutValue;
1387 >  else if(comparison == "<")  return testValue <  cutValue;
1388 >  else if(comparison == "<=") return testValue <= cutValue;
1389 >  else if(comparison == "==") return testValue == cutValue;
1390 >  else if(comparison == "=") return testValue == cutValue;
1391 >  else if(comparison == "!=") return testValue != cutValue;
1392 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1393  
1394   }
1395  
1396   bool
1397 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1397 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1398  
1399 +  //initialize to false until a chosen trigger is passed
1400    bool triggerDecision = false;
1401  
1402 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1403 <    {
1404 <      if(trigger->pass != 1) continue;
1405 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1406 <        {
1407 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1408 <            triggerDecision = true;
1409 <          }
1410 <        }
1402 >  if (printAllTriggers_) clog << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1403 >  //loop over all triggers defined in the event
1404 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1405 >
1406 >    if (printAllTriggers_) clog << "   " << trigger->name << endl;
1407 >
1408 >    //we're only interested in triggers that actually passed
1409 >    if(trigger->pass != 1) continue;
1410 >
1411 >    //if the event passes one of the veto triggers, exit and return false
1412 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1413 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1414      }
1415 <  return triggerDecision;
1415 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1416 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1417 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1418 >    }
1419 >  }
1420  
1421 +  printAllTriggers_ = false;  // only print triggers once, not every event
1422 +
1423 +  //if none of the veto triggers fired:
1424 +  //return the OR of all the chosen triggers
1425 +  if (triggersToTest.size() != 0) return triggerDecision;
1426 +  //or if no triggers were defined return true
1427 +  else return true;
1428   }
1429  
1430 < std::vector<std::string>
1430 >
1431 > vector<string>
1432   OSUAnalysis::splitString (string inputString){
1433  
1434 <  std::stringstream stringStream(inputString);
1435 <  std::istream_iterator<std::string> begin(stringStream);
1436 <  std::istream_iterator<std::string> end;
1437 <  std::vector<std::string> stringVector(begin, end);
1434 >  stringstream stringStream(inputString);
1435 >  istream_iterator<string> begin(stringStream);
1436 >  istream_iterator<string> end;
1437 >  vector<string> stringVector(begin, end);
1438    return stringVector;
1439  
1440   }
1441  
1442 +
1443 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1444 +  // Set two object strings from the tempInputCollection string,
1445 +  // For example, if tempInputCollection is "electron-muon pairs",
1446 +  // then obj1 = "electrons" and obj2 = "muons".
1447 +  // Note that the objects have an "s" appended.
1448 +
1449 +  int dashIndex = tempInputCollection.find("-");
1450 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1451 +  int secondWordLength = spaceIndex - dashIndex;
1452 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1453 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1454 +
1455 + }
1456 +
1457 +
1458 + string OSUAnalysis::getObjToGet(string obj) {
1459 +  // Return the string corresponding to the object to get for the given obj string.
1460 +  // Right now this only handles the case in which obj contains "secondary",
1461 +  // e.g, "secondary muons".
1462 +  // Note that "s" is NOT appended.
1463 +
1464 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1465 +  int firstSpaceIndex = obj.find_first_of(" ");
1466 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1467 +
1468 + }
1469 +
1470 +
1471 + //!jet valueLookup
1472   double
1473 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1473 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1474  
1475    double value = 0.0;
1476    if(variable == "energy") value = object->energy;
# Line 522 | Line 1588 | OSUAnalysis::valueLookup (const BNjet* o
1588    else if(variable == "puJetId_loose_full") value = object->puJetId_loose_full;
1589    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1590    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
525  
526  
527  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
528  
529  if(function == "abs") value = abs(value);
1591  
1592 <  return value;
1593 < }
1592 >  //user defined variable
1593 >  else if(variable == "disappTrkLeadingJetID") {
1594 >    value = object->pt > 110
1595 >      && fabs(object->eta) < 2.4
1596 >      && object->chargedHadronEnergyFraction > 0.2
1597 >      && object->neutralHadronEnergyFraction < 0.7
1598 >      && object->chargedEmEnergyFraction < 0.5
1599 >      && object->neutralEmEnergyFraction < 0.7;
1600 >  }
1601 >
1602 >  else if(variable == "disappTrkSubLeadingJetID") {
1603 >    value = object->pt > 30
1604 >      && fabs(object->eta) < 4.5
1605 >      && object->neutralHadronEnergyFraction < 0.7
1606 >      && object->chargedEmEnergyFraction < 0.5;
1607 >  }
1608 >
1609 >  else if(variable == "dPhiMet") {
1610 >    if (const BNmet *met = chosenMET ()) {
1611 >      value = deltaPhi (object->phi, met->phi);
1612 >    } else value = -999;
1613 >  }
1614 >
1615  
1616 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1617  
1618 +  value = applyFunction(function, value);
1619 +
1620 +  return value;
1621 + } // end jet valueLookup
1622  
1623 +
1624 + //!muon valueLookup
1625   double
1626 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1626 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1627  
1628    double value = 0.0;
1629    if(variable == "energy") value = object->energy;
# Line 550 | Line 1639 | OSUAnalysis::valueLookup (const BNmuon*
1639    else if(variable == "ecalIso") value = object->ecalIso;
1640    else if(variable == "hcalIso") value = object->hcalIso;
1641    else if(variable == "caloIso") value = object->caloIso;
1642 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
1642 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
1643    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
1644    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
1645    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 626 | Line 1715 | OSUAnalysis::valueLookup (const BNmuon*
1715    else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1716    else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1717    else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1718 +  else if(variable == "chargedHadronIsoDR04") value = object->chargedHadronIsoDR04;
1719 +  else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1720 +  else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1721 +  else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1722    else if(variable == "rhoPrime") value = object->rhoPrime;
1723    else if(variable == "AEffDr03") value = object->AEffDr03;
1724    else if(variable == "AEffDr04") value = object->AEffDr04;
# Line 633 | Line 1726 | OSUAnalysis::valueLookup (const BNmuon*
1726    else if(variable == "pfIsoR03SumNeutralHadronEt") value = object->pfIsoR03SumNeutralHadronEt;
1727    else if(variable == "pfIsoR03SumPhotonEt") value = object->pfIsoR03SumPhotonEt;
1728    else if(variable == "pfIsoR03SumPUPt") value = object->pfIsoR03SumPUPt;
1729 +  else if(variable == "relpfIsoR04SumExceptChargedHad") value = (object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)/ object->pt;
1730 +  else if(variable == "relpfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt/object->pt;
1731 +  else if(variable == "relpfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt/object->pt;
1732 +  else if(variable == "relpfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt/object->pt;
1733 +  else if(variable == "relpfIsoR04SumPUPt") value = object->pfIsoR04SumPUPt/object->pt;
1734    else if(variable == "pfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt;
1735    else if(variable == "pfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt;
1736    else if(variable == "pfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt;
# Line 688 | Line 1786 | OSUAnalysis::valueLookup (const BNmuon*
1786    else if(variable == "numberOfMatchedStations") value = object->numberOfMatchedStations;
1787    else if(variable == "time_ndof") value = object->time_ndof;
1788  
1789 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1790 <  
1789 >  //user-defined variables
1790 >  else if(variable == "looseID") {
1791 >    value = object->pt > 10 &&
1792 >      (object->isGlobalMuon  > 0 ||
1793 >       object->isTrackerMuon > 0);
1794 >  }
1795 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1796 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1797 >  else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1798 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1799 >  else if(variable == "relPFdBetaIsoPseudo") value = (object->pfIsoR04SumChargedHadronPt + object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt) / object->pt;
1800 >  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1801 >  else if(variable == "metMT") {
1802 >    if (const BNmet *met = chosenMET ())
1803 >      {
1804 >        double dPhi = deltaPhi (object->phi, met->phi);
1805 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1806 >      }
1807 >    else
1808 >      value = -999;
1809 >  }
1810 >
1811 >
1812 >
1813 >  else if(variable == "correctedD0VertexInEBPlus"){
1814 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1815 >    else value = -999;
1816 >  }
1817 >  else if(variable == "correctedD0VertexOutEBPlus"){
1818 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1819 >    else value = -999;
1820 >  }
1821 >  else if(variable == "correctedD0VertexEEPlus"){
1822 >    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1823 >    else value = -999;
1824 >  }
1825 >
1826 >  else if(variable == "correctedD0BeamspotInEBPlus"){
1827 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1828 >    else value = -999;
1829 >  }
1830 >  else if(variable == "correctedD0BeamspotOutEBPlus"){
1831 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1832 >    else value = -999;
1833 >  }
1834 >  else if(variable == "correctedD0BeamspotEEPlus"){
1835 >    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1836 >    else value = -999;
1837 >  }
1838 >
1839 >  else if(variable == "correctedD0VertexInEBMinus"){
1840 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1841 >    else value = -999;
1842 >  }
1843 >  else if(variable == "correctedD0VertexOutEBMinus"){
1844 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1845 >    else value = -999;
1846 >  }
1847 >  else if(variable == "correctedD0VertexEEMinus"){
1848 >    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1849 >    else value = -999;
1850 >  }
1851 >
1852 >  else if(variable == "correctedD0BeamspotInEBMinus"){
1853 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1854 >    else value = -999;
1855 >  }
1856 >  else if(variable == "correctedD0BeamspotOutEBMinus"){
1857 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1858 >    else value = -999;
1859 >  }
1860 >  else if(variable == "correctedD0BeamspotEEMinus"){
1861 >    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1862 >    else value = -999;
1863 >  }
1864 >
1865 >
1866 >  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1867 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1868 >    else value = -999;
1869 >  }
1870 >  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1871 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1872 >    else value = -999;
1873 >  }
1874 >  else if(variable == "correctedD0VertexEEPositiveCharge"){
1875 >    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1876 >    else value = -999;
1877 >  }
1878 >
1879 >  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1880 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1881 >    else value = -999;
1882 >  }
1883 >  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1884 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1885 >    else value = -999;
1886 >  }
1887 >  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1888 >    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1889 >    else value = -999;
1890 >  }
1891 >
1892 >  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1893 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1894 >    else value = -999;
1895 >  }
1896 >  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1897 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1898 >    else value = -999;
1899 >  }
1900 >  else if(variable == "correctedD0VertexEENegativeCharge"){
1901 >    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1902 >    else value = -999;
1903 >  }
1904 >
1905 >  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1906 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1907 >    else value = -999;
1908 >  }
1909 >  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1910 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1911 >    else value = -999;
1912 >  }
1913 >  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1914 >    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1915 >    else value = -999;
1916 >  }
1917 >
1918 >
1919 >  else if(variable == "tightID") {
1920 >    value = object->isGlobalMuon > 0                \
1921 >      && object->isPFMuon > 0                        \
1922 >      && object->normalizedChi2 < 10                \
1923 >      && object->numberOfValidMuonHits > 0        \
1924 >      && object->numberOfMatchedStations > 1        \
1925 >      && fabs(object->correctedD0Vertex) < 0.2        \
1926 >      && fabs(object->correctedDZ) < 0.5        \
1927 >      && object->numberOfValidPixelHits > 0                \
1928 >      && object->numberOfLayersWithMeasurement > 5;
1929 >  }
1930 >  else if(variable == "tightIDdisplaced"){
1931 >    value = object->isGlobalMuon > 0                \
1932 >      && object->isPFMuon > 0                        \
1933 >      && object->normalizedChi2 < 10                \
1934 >      && object->numberOfValidMuonHits > 0        \
1935 >      && object->numberOfMatchedStations > 1        \
1936 >      && object->numberOfValidPixelHits > 0        \
1937 >      && object->numberOfLayersWithMeasurement > 5;
1938 >  }
1939 >
1940 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1941 >
1942 >  else if(variable == "genMatchedPdgId"){
1943 >    int index = getGenMatchedParticleIndex(object);
1944 >    if(index == -1) value = 0;
1945 >    else value = mcparticles->at(index).id;
1946 >  }
1947 >
1948 >  else if(variable == "genMatchedId"){
1949 >    int index = getGenMatchedParticleIndex(object);
1950 >    if(index == -1) value = 0;
1951 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
1952 >  }
1953 >  else if(variable == "genMatchedMotherId"){
1954 >    int index = getGenMatchedParticleIndex(object);
1955 >    if(index == -1) value = 0;
1956 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1957 >  }
1958 >  else if(variable == "genMatchedMotherIdReverse"){
1959 >    int index = getGenMatchedParticleIndex(object);
1960 >    if(index == -1) value = 24;
1961 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1962 >  }
1963 >  else if(variable == "genMatchedGrandmotherId"){
1964 >    int index = getGenMatchedParticleIndex(object);
1965 >    if(index == -1) value = 0;
1966 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1967 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1968 >      if(motherIndex == -1) value = 0;
1969 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1970 >    }
1971 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1972 >  }
1973 >  else if(variable == "genMatchedGrandmotherIdReverse"){
1974 >    int index = getGenMatchedParticleIndex(object);
1975 >    if(index == -1) value = 24;
1976 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1977 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1978 >      if(motherIndex == -1) value = 24;
1979 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1980 >    }
1981 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1982 >  }
1983 >  else if(variable == "pfMuonsFromVertex"){
1984 >    double d0Error, dzError;
1985 >
1986 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1987 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1988 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1989 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1990 >      || fabs (object->correctedDZ / dzError) > 99.0;
1991 >    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1992 >  }
1993 >
1994 >
1995 >
1996 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1997 >
1998 >  value = applyFunction(function, value);
1999  
2000    return value;
2001 < }
2001 > } // end muon valueLookup
2002  
2003  
2004 + //!electron valueLookup
2005   double
2006 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
2006 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
2007  
2008    double value = 0.0;
2009    if(variable == "energy") value = object->energy;
# Line 856 | Line 2163 | OSUAnalysis::valueLookup (const BNelectr
2163    else if(variable == "eidHyperTight4MC") value = object->eidHyperTight4MC;
2164    else if(variable == "passConvVeto") value = object->passConvVeto;
2165  
2166 +  //user-defined variables
2167 +  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2168 +  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2169 +  else if(variable == "detIso") value = (object->trackIso) / object->pt;
2170 +  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2171 +  else if(variable == "relPFrhoIsoEB") value = object->isEB ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2172 +  else if(variable == "relPFrhoIsoEE") value = object->isEE ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2173 +  else if(variable == "metMT") {
2174 +    if (const BNmet *met = chosenMET ())
2175 +      {
2176 +        double dPhi = deltaPhi (object->phi, met->phi);
2177 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2178 +      }
2179 +    else
2180 +      value = -999;
2181 +  }
2182 +
2183 +  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
2184 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
2185 +    else value = -999;
2186 +  }
2187 +  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
2188 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
2189 +    else value = -999;
2190 +  }
2191  
2192 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2193 <  
2192 >  else if(variable == "correctedD0VertexInEBPlus"){
2193 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
2194 >    else value = -999;
2195 >  }
2196 >  else if(variable == "correctedD0VertexOutEBPlus"){
2197 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
2198 >    else value = -999;
2199 >  }
2200 >  else if(variable == "correctedD0VertexEEPlus"){
2201 >    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
2202 >    else value = -999;
2203 >  }
2204 >
2205 >  else if(variable == "correctedD0BeamspotInEBPlus"){
2206 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
2207 >    else value = -999;
2208 >  }
2209 >  else if(variable == "correctedD0BeamspotOutEBPlus"){
2210 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
2211 >    else value = -999;
2212 >  }
2213 >  else if(variable == "correctedD0BeamspotEEPlus"){
2214 >    if(object->isEE && object->eta > 0) value = object->correctedD0;
2215 >    else value = -999;
2216 >  }
2217 >
2218 >  else if(variable == "correctedD0VertexInEBMinus"){
2219 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
2220 >    else value = -999;
2221 >  }
2222 >  else if(variable == "correctedD0VertexOutEBMinus"){
2223 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
2224 >    else value = -999;
2225 >  }
2226 >  else if(variable == "correctedD0VertexEEMinus"){
2227 >    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
2228 >    else value = -999;
2229 >  }
2230 >
2231 >  else if(variable == "correctedD0BeamspotInEBMinus"){
2232 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
2233 >    else value = -999;
2234 >  }
2235 >  else if(variable == "correctedD0BeamspotOutEBMinus"){
2236 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
2237 >    else value = -999;
2238 >  }
2239 >  else if(variable == "correctedD0BeamspotEEMinus"){
2240 >    if(object->isEE && object->eta < 0) value = object->correctedD0;
2241 >    else value = -999;
2242 >  }
2243 >
2244 >  else if(variable == "looseID"){
2245 >    if (object->isEB)
2246 >      {
2247 >        value = fabs(object->delEtaIn) < 0.007 \
2248 >          && fabs (object->delPhiIn) < 0.15 \
2249 >          && object->scSigmaIEtaIEta < 0.01 \
2250 >          && object->hadOverEm < 0.12 \
2251 >          && fabs (object->correctedD0Vertex) < 0.02 \
2252 >          && fabs (object->correctedDZ) < 0.2 \
2253 >          && object->absInvEMinusInvPin < 0.05 \
2254 >          && object->passConvVeto;
2255 >      }
2256 >    else
2257 >      {
2258 >        value = fabs(object->delEtaIn) < 0.009 \
2259 >          && fabs (object->delPhiIn) < 0.10 \
2260 >          && object->scSigmaIEtaIEta < 0.03 \
2261 >          && object->hadOverEm < 0.10 \
2262 >          && fabs (object->correctedD0Vertex) < 0.02 \
2263 >          && fabs (object->correctedDZ) < 0.2 \
2264 >          && object->absInvEMinusInvPin < 0.05 \
2265 >          && object->passConvVeto;
2266 >      }
2267 >  }
2268 >
2269 >  else if(variable == "tightID"){
2270 >    if (object->isEB)
2271 >      {
2272 >        value = fabs(object->delEtaIn) < 0.004 \
2273 >          && fabs (object->delPhiIn) < 0.03 \
2274 >          && object->scSigmaIEtaIEta < 0.01 \
2275 >          && object->hadOverEm < 0.12 \
2276 >          && fabs (object->correctedD0Vertex) < 0.02 \
2277 >          && fabs (object->correctedDZ) < 0.1 \
2278 >          && object->absInvEMinusInvPin < 0.05 \
2279 >          && object->passConvVeto;
2280 >      }
2281 >    else
2282 >      {
2283 >        value = fabs(object->delEtaIn) < 0.005 \
2284 >          && fabs (object->delPhiIn) < 0.02 \
2285 >          && object->scSigmaIEtaIEta < 0.03 \
2286 >          && object->hadOverEm < 0.10 \
2287 >          && fabs (object->correctedD0Vertex) < 0.02 \
2288 >          && fabs (object->correctedDZ) < 0.1 \
2289 >          && object->absInvEMinusInvPin < 0.05 \
2290 >          && object->passConvVeto;
2291 >      }
2292 >  }
2293 >
2294 >  else if(variable == "looseID_MVA"){
2295 >    value = object->pt > 10
2296 >      && object->mvaNonTrigV0 > 0;
2297 >      }
2298 >  else if(variable == "correctedD0VertexInEBPositiveCharge"){
2299 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2300 >    else value = -999;
2301 >  }
2302 >  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
2303 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2304 >    else value = -999;
2305 >  }
2306 >  else if(variable == "correctedD0VertexEEPositiveCharge"){
2307 >    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
2308 >    else value = -999;
2309 >  }
2310 >
2311 >  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
2312 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
2313 >    else value = -999;
2314 >  }
2315 >  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
2316 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
2317 >    else value = -999;
2318 >  }
2319 >  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
2320 >    if(object->isEE && object->charge > 0) value = object->correctedD0;
2321 >    else value = -999;
2322 >  }
2323 >
2324 >  else if(variable == "correctedD0VertexInEBNegativeCharge"){
2325 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2326 >    else value = -999;
2327 >  }
2328 >  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
2329 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2330 >    else value = -999;
2331 >  }
2332 >  else if(variable == "correctedD0VertexEENegativeCharge"){
2333 >    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
2334 >    else value = -999;
2335 >  }
2336 >
2337 >  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
2338 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
2339 >    else value = -999;
2340 >  }
2341 >  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
2342 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
2343 >    else value = -999;
2344 >  }
2345 >  else if(variable == "correctedD0BeamspotEENegativeCharge"){
2346 >    if(object->isEE && object->charge < 0) value = object->correctedD0;
2347 >    else value = -999;
2348 >  }
2349 >
2350 >
2351 >  else if(variable == "tightIDdisplaced"){
2352 >    if (object->isEB)
2353 >      {
2354 >        value = fabs(object->delEtaIn) < 0.004 \
2355 >          && fabs (object->delPhiIn) < 0.03 \
2356 >          && object->scSigmaIEtaIEta < 0.01 \
2357 >          && object->hadOverEm < 0.12 \
2358 >          && object->absInvEMinusInvPin < 0.05;
2359 >      }
2360 >    else
2361 >      {
2362 >        value = fabs (object->delEtaIn) < 0.005 \
2363 >          && fabs (object->delPhiIn) < 0.02 \
2364 >          && object->scSigmaIEtaIEta < 0.03 \
2365 >          && object->hadOverEm < 0.10 \
2366 >          && object->absInvEMinusInvPin < 0.05;
2367 >      }
2368 >  }
2369 >
2370 >
2371 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2372 >
2373 >  else if(variable == "genMatchedPdgId"){
2374 >    int index = getGenMatchedParticleIndex(object);
2375 >    if(index == -1) value = 0;
2376 >    else value = mcparticles->at(index).id;
2377 >  }
2378 >
2379 >
2380 >  else if(variable == "genMatchedId"){
2381 >    int index = getGenMatchedParticleIndex(object);
2382 >    if(index == -1) value = 0;
2383 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2384 >  }
2385 >  else if(variable == "genMatchedMotherId"){
2386 >    int index = getGenMatchedParticleIndex(object);
2387 >    if(index == -1) value = 0;
2388 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2389 >  }
2390 >  else if(variable == "genMatchedMotherIdReverse"){
2391 >    int index = getGenMatchedParticleIndex(object);
2392 >    if(index == -1) value = 24;
2393 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2394 >  }
2395 >  else if(variable == "genMatchedGrandmotherId"){
2396 >    int index = getGenMatchedParticleIndex(object);
2397 >    if(index == -1) value = 0;
2398 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2399 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2400 >      if(motherIndex == -1) value = 0;
2401 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2402 >    }
2403 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2404 >  }
2405 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2406 >    int index = getGenMatchedParticleIndex(object);
2407 >    if(index == -1) value = 24;
2408 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2409 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2410 >      if(motherIndex == -1) value = 24;
2411 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2412 >    }
2413 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2414 >  }
2415 >  else if(variable == "pfElectronsFromVertex"){
2416 >    double d0Error, dzError;
2417 >
2418 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2419 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2420 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2421 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2422 >      || fabs (object->correctedDZ / dzError) > 99.0;
2423 >    value = !value;
2424 >  }
2425 >
2426 >
2427 >
2428 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2429 >
2430 >  value = applyFunction(function, value);
2431  
2432    return value;
2433 < }
2433 > } // end electron valueLookup
2434  
2435  
2436 + //!event valueLookup
2437   double
2438 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2438 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2439  
2440    double value = 0.0;
2441  
# Line 873 | Line 2443 | OSUAnalysis::valueLookup (const BNevent*
2443    else if(variable == "pthat") value = object->pthat;
2444    else if(variable == "qScale") value = object->qScale;
2445    else if(variable == "alphaQCD") value = object->alphaQCD;
2446 +  else if(variable == "Ht") value = getHt(jets.product());
2447    else if(variable == "alphaQED") value = object->alphaQED;
2448    else if(variable == "scalePDF") value = object->scalePDF;
2449    else if(variable == "x1") value = object->x1;
# Line 933 | Line 2504 | OSUAnalysis::valueLookup (const BNevent*
2504    else if(variable == "id1") value = object->id1;
2505    else if(variable == "id2") value = object->id2;
2506    else if(variable == "evt") value = object->evt;
2507 +  else if(variable == "puScaleFactor"){
2508 +    if(doPileupReweighting_ && datasetType_ != "data")
2509 +      value = puWeight_->at (events->at (0).numTruePV);
2510 +    else
2511 +      value = 1.0;
2512 +  }
2513 +  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2514 +  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2515 +  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2516 +  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2517 +  else if(variable == "ht") value = chosenHT ();
2518 +  else if(variable == "leadMuPairInvMass"){
2519 +    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2520 +    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2521 +                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2522 +    value = (p0 + p1).M ();
2523 +  }
2524 +  else if(variable == "leadMuPairPt"){
2525 +    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2526 +    TVector2 pt0 (muPair.first->px, muPair.first->py),
2527 +             pt1 (muPair.second->px, muPair.second->py);
2528 +    pt0 += pt1;
2529 +    value = pt0.Mod ();
2530 +  }
2531 +  else if(variable == "leadElPairInvMass"){
2532 +    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2533 +    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2534 +                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2535 +    value = (p0 + p1).M ();
2536 +  }
2537 +  else if(variable == "leadElPairPt"){
2538 +    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2539 +    TVector2 pt0 (muPair.first->px, muPair.first->py),
2540 +             pt1 (muPair.second->px, muPair.second->py);
2541 +    pt0 += pt1;
2542 +    value = pt0.Mod ();
2543 +  }
2544 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2545  
2546 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
938 <  
2546 >  value = applyFunction(function, value);
2547  
2548    return value;
2549 < }
2549 > } // end event valueLookup
2550 >
2551  
2552 + //!tau valueLookup
2553   double
2554 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2554 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2555  
2556    double value = 0.0;
2557  
# Line 985 | Line 2595 | OSUAnalysis::valueLookup (const BNtau* o
2595    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2596    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2597  
2598 +  else if (variable == "looseHadronicID") {
2599 +    value = object->pt > 10
2600 +      && object->eta < 2.3
2601 +      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2602 +      && object->HPSdecayModeFinding > 0
2603 +      && object->HPSagainstElectronLoose > 0
2604 +      && object->HPSagainstMuonTight > 0;
2605 +  }
2606  
2607 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2608 <  
2607 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2608 >
2609 >  else if(variable == "genMatchedPdgId"){
2610 >    int index = getGenMatchedParticleIndex(object);
2611 >    if(index == -1) value = 0;
2612 >    else value = mcparticles->at(index).id;
2613 >  }
2614 >
2615 >  else if(variable == "genMatchedId"){
2616 >    int index = getGenMatchedParticleIndex(object);
2617 >    if(index == -1) value = 0;
2618 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2619 >  }
2620 >  else if(variable == "genMatchedMotherId"){
2621 >    int index = getGenMatchedParticleIndex(object);
2622 >    if(index == -1) value = 0;
2623 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2624 >  }
2625 >  else if(variable == "genMatchedMotherIdReverse"){
2626 >    int index = getGenMatchedParticleIndex(object);
2627 >    if(index == -1) value = 24;
2628 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2629 >  }
2630 >  else if(variable == "genMatchedGrandmotherId"){
2631 >    int index = getGenMatchedParticleIndex(object);
2632 >    if(index == -1) value = 0;
2633 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2634 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2635 >      if(motherIndex == -1) value = 0;
2636 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2637 >    }
2638 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2639 >  }
2640 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2641 >    int index = getGenMatchedParticleIndex(object);
2642 >    if(index == -1) value = 24;
2643 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2644 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2645 >      if(motherIndex == -1) value = 24;
2646 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2647 >    }
2648 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2649 >  }
2650 >
2651 >
2652 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2653 >
2654 >  value = applyFunction(function, value);
2655  
2656    return value;
2657 < }
2657 > } // end tau valueLookup
2658  
2659 +
2660 + //!met valueLookup
2661   double
2662 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2662 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2663  
2664    double value = 0.0;
2665  
# Line 1057 | Line 2723 | OSUAnalysis::valueLookup (const BNmet* o
2723    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2724    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2725  
2726 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2727 <  
2726 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2727 >
2728 >  value = applyFunction(function, value);
2729  
2730    return value;
2731 < }
2731 > } // end met valueLookup
2732  
2733 +
2734 + //!track valueLookup
2735   double
2736 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2736 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2737  
2738    double value = 0.0;
2739 +  double pMag = sqrt(object->pt * object->pt +
2740 +                     object->pz * object->pz);
2741  
2742    if(variable == "pt") value = object->pt;
2743    else if(variable == "px") value = object->px;
# Line 1086 | Line 2757 | OSUAnalysis::valueLookup (const BNtrack*
2757    else if(variable == "numValidHits") value = object->numValidHits;
2758    else if(variable == "isHighPurity") value = object->isHighPurity;
2759  
2760 +  //additional BNs info for disappTrks
2761 +  else if(variable == "caloEMDeltaRp3")     value = object->caloEMDeltaRp3;
2762 +  else if(variable == "caloHadDeltaRp3")    value = object->caloHadDeltaRp3;
2763 +  else if(variable == "caloEMDeltaRp4")     value = object->caloEMDeltaRp4;
2764 +  else if(variable == "caloHadDeltaRp4")    value = object->caloHadDeltaRp4;
2765 +  else if(variable == "caloEMDeltaRp5")     value = object->caloEMDeltaRp5;
2766 +  else if(variable == "caloHadDeltaRp5")    value = object->caloHadDeltaRp5;
2767 +  else if(variable == "nHitsMissingOuter")  value = object->nHitsMissingOuter;
2768 +  else if(variable == "nHitsMissingInner")  value = object->nHitsMissingInner;
2769 +  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2770 +  else if(variable == "depTrkRp3")          value = object->depTrkRp3;
2771 +  else if(variable == "trkRelIsoRp3")       value = (object->depTrkRp3 - object->pt) / object->pt;
2772 +  else if(variable == "trkRelIsoRp5")       value = (object->depTrkRp5 - object->pt) / object->pt;
2773 +  else if(variable == "depEcalRp3")         value = object->depEcalRp3;
2774 +  else if(variable == "depHcalRp3")         value = object->depHcalRp3;
2775 +  else if(variable == "depHoRp3")           value = object->depHoRp3;
2776 +  else if(variable == "nTracksRp3")         value = object->nTracksRp3;
2777 +  else if(variable == "trackerVetoPtRp3")   value = object->trackerVetoPtRp3;
2778 +  else if(variable == "emVetoEtRp3")        value = object->emVetoEtRp3;
2779 +  else if(variable == "hadVetoEtRp3")       value = object->hadVetoEtRp3;
2780 +  else if(variable == "hoVetoEtRp3")        value = object->hoVetoEtRp3;
2781 +  else if(variable == "depTrkRp5")          value = object->depTrkRp5;
2782 +  else if(variable == "depEcalRp5")         value = object->depEcalRp5;
2783 +  else if(variable == "depHcalRp5")         value = object->depHcalRp5;
2784 +  else if(variable == "depHoRp5")           value = object->depHoRp5;
2785 +  else if(variable == "nTracksRp5")         value = object->nTracksRp5;
2786 +  else if(variable == "trackerVetoPtRp5")   value = object->trackerVetoPtRp5;
2787 +  else if(variable == "emVetoEtRp5")        value = object->emVetoEtRp5;
2788 +  else if(variable == "hadVetoEtRp5")       value = object->hadVetoEtRp5;
2789 +  else if(variable == "hoVetoEtRp5")        value = object->hoVetoEtRp5;
2790 +
2791 +  //user defined variables
2792 +  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;
2793 +  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2794 +  else if(variable == "depTrkRp5MinusPt"){
2795 +    if ( (object->depTrkRp5 - object->pt) < 0 ) {
2796 + //       cout << "Warning:  found track with depTrkRp5 < pt:  depTrkRp5=" << object->depTrkRp5
2797 + //         << "; pt=" << object->pt
2798 + //         << "; object->depTrkRp5 - object->pt = " << object->depTrkRp5 - object->pt
2799 + //         << endl;  
2800 +           value = 0;
2801 +         }
2802 +         else value =  (object->depTrkRp5 - object->pt);
2803 +  }
2804 +  else if(variable == "depTrkRp3MinusPt"){
2805 +    if ( (object->depTrkRp3 - object->pt) < 0 ) {
2806 +      value = 0;
2807 +    }
2808 +    else value =  (object->depTrkRp3 - object->pt);
2809 +  }
2810  
2811 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2811 >  else if(variable == "dPhiMet") {
2812 >    if (const BNmet *met = chosenMET ()) {
2813 >      value = deltaPhi (object->phi, met->phi);
2814 >    } else value = -999;
2815 >  }
2816 >  
2817    
2818 +  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2819 +  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2820 +  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2821 +  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2822 +  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2823 +  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2824 +  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2825 +  else if(variable == "ptError")                    value = object->ptError;
2826 +  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2827 +  else if (variable == "d0wrtPV"){
2828 +    double vx = object->vx - chosenVertex ()->x,
2829 +      vy = object->vy - chosenVertex ()->y,
2830 +      px = object->px,
2831 +      py = object->py,
2832 +      pt = object->pt;
2833 +    value = (-vx * py + vy * px) / pt;
2834 +  }
2835 +  else if (variable == "dZwrtPV"){
2836 +    double vx = object->vx - chosenVertex ()->x,
2837 +      vy = object->vy - chosenVertex ()->y,
2838 +      vz = object->vz - chosenVertex ()->z,
2839 +      px = object->px,
2840 +      py = object->py,
2841 +      pz = object->pz,
2842 +      pt = object->pt;
2843 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2844 +  }
2845 +
2846 +
2847 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2848 +
2849 +  else if(variable == "genMatchedPdgId"){
2850 +    int index = getGenMatchedParticleIndex(object);
2851 +    if(index == -1) value = 0;
2852 +    else value = mcparticles->at(index).id;
2853 +  }
2854 +
2855 +
2856 +  else if(variable == "genMatchedId"){
2857 +    int index = getGenMatchedParticleIndex(object);
2858 +    if(index == -1) value = 0;
2859 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
2860 +  }
2861 +  else if(variable == "genMatchedMotherId"){
2862 +    int index = getGenMatchedParticleIndex(object);
2863 +    if(index == -1) value = 0;
2864 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2865 +  }
2866 +  else if(variable == "genMatchedMotherIdReverse"){
2867 +    int index = getGenMatchedParticleIndex(object);
2868 +    if(index == -1) value = 24;
2869 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2870 +  }
2871 +  else if(variable == "genMatchedGrandmotherId"){
2872 +    int index = getGenMatchedParticleIndex(object);
2873 +    if(index == -1) value = 0;
2874 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2875 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2876 +      if(motherIndex == -1) value = 0;
2877 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2878 +    }
2879 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2880 +  }
2881 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2882 +    int index = getGenMatchedParticleIndex(object);
2883 +    if(index == -1) value = 24;
2884 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2885 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2886 +      if(motherIndex == -1) value = 24;
2887 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2888 +    }
2889 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2890 +  }
2891 +
2892 +
2893 +
2894 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2895 +
2896 +  value = applyFunction(function, value);
2897  
2898    return value;
2899 < }
2899 > } // end track valueLookup
2900  
2901 +
2902 + //!genjet valueLookup
2903   double
2904 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2904 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2905  
2906    double value = 0.0;
2907  
# Line 1114 | Line 2921 | OSUAnalysis::valueLookup (const BNgenjet
2921    else if(variable == "charge") value = object->charge;
2922  
2923  
2924 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2925 <  
2924 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2925 >
2926 >  value = applyFunction(function, value);
2927  
2928    return value;
2929   }
2930  
2931 + //!mcparticle valueLookup
2932   double
2933 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2933 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2934  
2935    double value = 0.0;
2936  
# Line 1210 | Line 3019 | OSUAnalysis::valueLookup (const BNmcpart
3019    else if(variable == "grandMother11Status") value = object->grandMother11Status;
3020    else if(variable == "grandMother11Charge") value = object->grandMother11Charge;
3021  
3022 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3023 <  
3022 >  //user-defined variables
3023 >  else if (variable == "d0"){
3024 >    double vx = object->vx - chosenVertex ()->x,
3025 >      vy = object->vy - chosenVertex ()->y,
3026 >      px = object->px,
3027 >      py = object->py,
3028 >      pt = object->pt;
3029 >    value = (-vx * py + vy * px) / pt;
3030 >  }
3031 >  else if (variable == "dz"){
3032 >    double vx = object->vx - chosenVertex ()->x,
3033 >      vy = object->vy - chosenVertex ()->y,
3034 >      vz = object->vz - chosenVertex ()->z,
3035 >      px = object->px,
3036 >      py = object->py,
3037 >      pz = object->pz,
3038 >      pt = object->pt;
3039 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3040 >  }
3041 >  else if(variable == "v0"){
3042 >    value = sqrt(object->vx*object->vx + object->vy*object->vy);
3043 >  }
3044 >  else if(variable == "deltaV0"){
3045 >    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
3046 >  }
3047 >  else if (variable == "deltaVx"){
3048 >    value = object->vx - chosenVertex ()->x;
3049 >  }
3050 >  else if (variable == "deltaVy"){
3051 >    value = object->vy - chosenVertex ()->y;
3052 >  }
3053 >  else if (variable == "deltaVz"){
3054 >    value = object->vz - chosenVertex ()->z;
3055 >  }
3056 >
3057 >
3058 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3059 >
3060 >  value = applyFunction(function, value);
3061  
3062    return value;
3063 < }
3063 > } // end mcparticle valueLookup
3064  
3065 +
3066 + //!primaryvertex valueLookup
3067   double
3068 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
3068 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
3069  
3070    double value = 0.0;
3071  
# Line 1236 | Line 3084 | OSUAnalysis::valueLookup (const BNprimar
3084    else if(variable == "isGood") value = object->isGood;
3085  
3086  
3087 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3088 <  
3087 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3088 >
3089 >  value = applyFunction(function, value);
3090  
3091    return value;
3092   }
3093  
3094 + //!bxlumi valueLookup
3095   double
3096 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
3096 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
3097  
3098    double value = 0.0;
3099  
# Line 1252 | Line 3102 | OSUAnalysis::valueLookup (const BNbxlumi
3102    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
3103  
3104  
3105 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3106 <  
3105 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3106 >
3107 >  value = applyFunction(function, value);
3108  
3109    return value;
3110   }
3111  
3112 + //!photon valueLookup
3113   double
3114 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
3114 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
3115  
3116    double value = 0.0;
3117  
# Line 1334 | Line 3186 | OSUAnalysis::valueLookup (const BNphoton
3186    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
3187  
3188  
3189 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3190 <  
3189 >
3190 >
3191 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3192 >
3193 >  else if(variable == "genMatchedPdgId"){
3194 >    int index = getGenMatchedParticleIndex(object);
3195 >    if(index == -1) value = 0;
3196 >    else value = mcparticles->at(index).id;
3197 >  }
3198 >
3199 >
3200 >
3201 >  else if(variable == "genMatchedId"){
3202 >    int index = getGenMatchedParticleIndex(object);
3203 >    if(index == -1) value = 0;
3204 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
3205 >  }
3206 >  else if(variable == "genMatchedMotherId"){
3207 >    int index = getGenMatchedParticleIndex(object);
3208 >    if(index == -1) value = 0;
3209 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
3210 >  }
3211 >  else if(variable == "genMatchedMotherIdReverse"){
3212 >    int index = getGenMatchedParticleIndex(object);
3213 >    if(index == -1) value = 24;
3214 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
3215 >  }
3216 >  else if(variable == "genMatchedGrandmotherId"){
3217 >    int index = getGenMatchedParticleIndex(object);
3218 >    if(index == -1) value = 0;
3219 >    else if(fabs(mcparticles->at(index).motherId) == 15){
3220 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3221 >      if(motherIndex == -1) value = 0;
3222 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3223 >    }
3224 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3225 >  }
3226 >  else if(variable == "genMatchedGrandmotherIdReverse"){
3227 >    int index = getGenMatchedParticleIndex(object);
3228 >    if(index == -1) value = 24;
3229 >    else if(fabs(mcparticles->at(index).motherId) == 15){
3230 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3231 >      if(motherIndex == -1) value = 24;
3232 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3233 >    }
3234 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3235 >  }
3236 >
3237 >
3238 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3239 >
3240 >  value = applyFunction(function, value);
3241  
3242    return value;
3243 < }
3243 > } // end photon valueLookup
3244  
3245 +
3246 + //!supercluster valueLookup
3247   double
3248 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
3248 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
3249  
3250    double value = 0.0;
3251  
# Line 1355 | Line 3259 | OSUAnalysis::valueLookup (const BNsuperc
3259    else if(variable == "theta") value = object->theta;
3260  
3261  
3262 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3263 <  
3262 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3263 >
3264 >  value = applyFunction(function, value);
3265 >
3266 >  return value;
3267 > }
3268 >
3269 > //!trigobj valueLookup
3270 > double
3271 > OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3272 >
3273 >  double value = 0.0;
3274 >
3275 >  if(variable == "pt") value = object->pt;
3276 >  else if(variable == "eta") value = object->eta;
3277 >  else if(variable == "phi") value = object->phi;
3278 >  else if(variable == "px") value = object->px;
3279 >  else if(variable == "py") value = object->py;
3280 >  else if(variable == "pz") value = object->pz;
3281 >  else if(variable == "et") value = object->et;
3282 >  else if(variable == "energy") value = object->energy;
3283 >  else if(variable == "etTotal") value = object->etTotal;
3284 >  else if(variable == "id") value = object->id;
3285 >  else if(variable == "charge") value = object->charge;
3286 >  else if(variable == "isIsolated") value = object->isIsolated;
3287 >  else if(variable == "isMip") value = object->isMip;
3288 >  else if(variable == "isForward") value = object->isForward;
3289 >  else if(variable == "isRPC") value = object->isRPC;
3290 >  else if(variable == "bx") value = object->bx;
3291 >  else if(variable == "filter") {
3292 >    if ((stringValue = object->filter) == "")
3293 >      stringValue = "none";  // stringValue should only be empty if value is filled
3294 >  }
3295 >
3296 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3297 >
3298 >  value = applyFunction(function, value);
3299 >
3300 >  return value;
3301 > }
3302 >
3303 > //!muon-muon pair valueLookup
3304 > double
3305 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3306 >
3307 >  double value = 0.0;
3308 >
3309 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3310 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3311 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3312 >  else if(variable == "invMass"){
3313 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3314 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3315 >    value = (fourVector1 + fourVector2).M();
3316 >  }
3317 >  else if(variable == "pt"){
3318 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3319 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3320 >    value = (fourVector1 + fourVector2).Pt();
3321 >  }
3322 >  else if(variable == "threeDAngle")
3323 >    {
3324 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3325 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3326 >      value = (threeVector1.Angle(threeVector2));
3327 >    }
3328 >  else if(variable == "alpha")
3329 >    {
3330 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3331 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3332 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3333 >      value = (pi-threeVector1.Angle(threeVector2));
3334 >    }
3335 >  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3336 >  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3337 >  else if(variable == "d0Sign"){
3338 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3339 >    if(d0Sign < 0) value = -0.5;
3340 >    else if (d0Sign > 0) value = 0.5;
3341 >    else value = -999;
3342 >  }
3343 >  else if(variable == "chargeProduct"){
3344 >    value = object1->charge*object2->charge;
3345 >  }
3346 >  else if(variable == "muon1CorrectedD0Vertex"){
3347 >    value = object1->correctedD0Vertex;
3348 >  }
3349 >  else if(variable == "muon2CorrectedD0Vertex"){
3350 >    value = object2->correctedD0Vertex;
3351 >  }
3352 >  else if(variable == "muon1timeAtIpInOut"){
3353 >    value = object1->timeAtIpInOut;
3354 >  }
3355 >  else if(variable == "muon2timeAtIpInOut"){
3356 >    value = object2->timeAtIpInOut;
3357 >  }
3358 >  else if(variable == "muon1correctedD0")
3359 >    {
3360 >      value = object1->correctedD0;
3361 >    }
3362 >  else if(variable == "muon2correctedD0")
3363 >    {
3364 >      value = object2->correctedD0;
3365 >    }
3366 >
3367 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3368 >
3369 >  value = applyFunction(function, value);
3370 >
3371 >  return value;
3372 > } // end muon-muon pair valueLookup
3373 >
3374 >
3375 > //!muon-photon pair valueLookup
3376 > double
3377 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3378 >
3379 >  double value = 0.0;
3380 >
3381 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3382 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3383 >  else if(variable == "photonEta") value = object2->eta;
3384 >  else if(variable == "photonPt") value = object2->pt;
3385 >  else if(variable == "muonEta") value = object1->eta;
3386 >  else if(variable == "photonPhi") value = object2->phi;
3387 >  else if(variable == "muonPhi") value = object1->phi;
3388 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3389 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3390 >  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3391 >  else if(variable == "invMass"){
3392 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3393 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3394 >    value = (fourVector1 + fourVector2).M();
3395 >  }
3396 >  else if(variable == "pt"){
3397 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3398 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3399 >    value = (fourVector1 + fourVector2).Pt();
3400 >  }
3401 >  else if(variable == "threeDAngle")
3402 >    {
3403 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3404 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3405 >      value = (threeVector1.Angle(threeVector2));
3406 >    }
3407 >  else if(variable == "alpha")
3408 >    {
3409 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3410 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3411 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3412 >      value = (pi-threeVector1.Angle(threeVector2));
3413 >    }
3414 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3415 >
3416 >  value = applyFunction(function, value);
3417 >
3418 >  return value;
3419 > }
3420 >
3421 > //!electron-photon pair valueLookup
3422 > double
3423 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3424 >
3425 >  double value = 0.0;
3426 >
3427 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3428 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3429 >  else if(variable == "photonEta") value = object2->eta;
3430 >  else if(variable == "photonPt") value = object2->pt;
3431 >  else if(variable == "electronEta") value = object1->eta;
3432 >  else if(variable == "photonPhi") value = object2->phi;
3433 >  else if(variable == "electronPhi") value = object1->phi;
3434 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3435 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3436 >  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3437 >  else if(variable == "invMass"){
3438 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3439 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3440 >    value = (fourVector1 + fourVector2).M();
3441 >  }
3442 >  else if(variable == "pt"){
3443 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3444 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3445 >    value = (fourVector1 + fourVector2).Pt();
3446 >  }
3447 >  else if(variable == "threeDAngle")
3448 >    {
3449 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3450 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3451 >      value = (threeVector1.Angle(threeVector2));
3452 >    }
3453 >  else if(variable == "alpha")
3454 >    {
3455 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3456 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3457 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3458 >      value = (pi-threeVector1.Angle(threeVector2));
3459 >    }
3460 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3461 >
3462 >  value = applyFunction(function, value);
3463 >
3464 >  return value;
3465 > }
3466 >
3467 > //!electron-electron pair valueLookup
3468 > double
3469 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3470 >
3471 >  double value = 0.0;
3472 >
3473 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3474 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3475 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3476 >  else if(variable == "invMass"){
3477 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3478 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3479 >    value = (fourVector1 + fourVector2).M();
3480 >  }
3481 >  else if(variable == "pt"){
3482 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3483 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3484 >    value = (fourVector1 + fourVector2).Pt();
3485 >  }
3486 >  else if(variable == "threeDAngle")
3487 >    {
3488 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3489 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3490 >      value = (threeVector1.Angle(threeVector2));
3491 >    }
3492 >  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3493 >  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3494 >  else if(variable == "d0Sign"){
3495 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3496 >    if(d0Sign < 0) value = -0.5;
3497 >    else if (d0Sign > 0) value = 0.5;
3498 >    else value = -999;
3499 >  }
3500 >  else if(variable == "chargeProduct"){
3501 >    value = object1->charge*object2->charge;
3502 >  }
3503 >  else if(variable == "electron1CorrectedD0Vertex"){
3504 >    value = object1->correctedD0Vertex;
3505 >  }
3506 >  else if(variable == "electron2CorrectedD0Vertex"){
3507 >    value = object2->correctedD0Vertex;
3508 >  }
3509 >  else if(variable == "electron1CorrectedD0"){
3510 >    value = object1->correctedD0;
3511 >  }
3512 >  else if(variable == "electron2CorrectedD0"){
3513 >    value = object2->correctedD0;
3514 >  }
3515 >
3516 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3517 >
3518 >  value = applyFunction(function, value);
3519 >
3520 >  return value;
3521 > }
3522 >
3523 > //!electron-muon pair valueLookup
3524 > double
3525 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3526 >
3527 >  double value = 0.0;
3528 >
3529 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3530 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3531 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3532 >  else if(variable == "invMass"){
3533 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3534 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3535 >    value = (fourVector1 + fourVector2).M();
3536 >  }
3537 >  else if(variable == "pt"){
3538 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3539 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3540 >    value = (fourVector1 + fourVector2).Pt();
3541 >  }
3542 >  else if(variable == "threeDAngle")
3543 >    {
3544 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3545 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3546 >      value = (threeVector1.Angle(threeVector2));
3547 >    }
3548 >  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3549 >  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3550 >  else if(variable == "d0Sign"){
3551 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3552 >    if(d0Sign < 0) value = -0.5;
3553 >    else if (d0Sign > 0) value = 0.5;
3554 >    else value = -999;
3555 >  }
3556 >  else if(variable == "chargeProduct"){
3557 >    value = object1->charge*object2->charge;
3558 >  }
3559 >  else if(variable == "electronCorrectedD0Vertex"){
3560 >    value = object1->correctedD0Vertex;
3561 >  }
3562 >  else if(variable == "muonCorrectedD0Vertex"){
3563 >    value = object2->correctedD0Vertex;
3564 >  }
3565 >  else if(variable == "electronCorrectedD0"){
3566 >    value = object1->correctedD0;
3567 >  }
3568 >  else if(variable == "muonCorrectedD0"){
3569 >    value = object2->correctedD0;
3570 >  }
3571 >  else if(variable == "electronDetIso"){
3572 >    value = (object1->trackIso) / object1->pt;
3573 >  }
3574 >  else if(variable == "muonDetIso"){
3575 >    value = (object2->trackIsoDR03) / object2->pt;
3576 >  }
3577 >  else if(variable == "electronRelPFrhoIso"){
3578 >    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3579 >  }
3580 >  else if(variable == "muonRelPFdBetaIso"){
3581 >    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3582 >  }
3583 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3584 >  value = applyFunction(function, value);
3585 >
3586 >  return value;
3587 > } // end electron-muon pair valueLookup
3588 >
3589 >
3590 > //!electron-jet pair valueLookup
3591 > double
3592 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3593 >
3594 >  double value = 0.0;
3595 >
3596 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3597 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3598 >  else if(variable == "jetEta") value = object2->eta;
3599 >  else if(variable == "jetPhi") value = object2->phi;
3600 >  else if(variable == "electronEta") value = object1->eta;
3601 >  else if(variable == "electronPhi") value = object1->phi;
3602 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3603 >  else if(variable == "invMass"){
3604 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3605 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3606 >    value = (fourVector1 + fourVector2).M();
3607 >  }
3608 >  else if(variable == "pt"){
3609 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3610 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3611 >    value = (fourVector1 + fourVector2).Pt();
3612 >  }
3613 >  else if(variable == "threeDAngle")
3614 >    {
3615 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3616 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3617 >      value = (threeVector1.Angle(threeVector2));
3618 >    }
3619 >  else if(variable == "chargeProduct"){
3620 >    value = object1->charge*object2->charge;
3621 >  }
3622 >
3623 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3624 >  value = applyFunction(function, value);
3625 >
3626 >  return value;
3627 > }
3628 >
3629 > //!photon-jet pair valueLookup
3630 > double
3631 > OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3632 >
3633 >  double value = 0.0;
3634 >
3635 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3636 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3637 >  else if(variable == "jetEta") value = object2->eta;
3638 >  else if(variable == "jetPhi") value = object2->phi;
3639 >  else if(variable == "photonEta") value = object1->eta;
3640 >  else if(variable == "photonPhi") value = object1->phi;
3641 >  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3642 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3643 >  else if(variable == "invMass"){
3644 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3645 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3646 >    value = (fourVector1 + fourVector2).M();
3647 >  }
3648 >  else if(variable == "pt"){
3649 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3650 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3651 >    value = (fourVector1 + fourVector2).Pt();
3652 >  }
3653 >  else if(variable == "threeDAngle")
3654 >    {
3655 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3656 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3657 >      value = (threeVector1.Angle(threeVector2));
3658 >    }
3659 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3660 >  value = applyFunction(function, value);
3661 >
3662 >  return value;
3663 > }
3664 >
3665 > // track-jet pair valueLookup
3666 > double
3667 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNjet* object2, string variable, string function, string &stringValue){
3668 >
3669 >  double value = 0.0;
3670 >
3671 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3672 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3673 >
3674 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3675 >  value = applyFunction(function, value);
3676 >
3677 >  return value;
3678 >
3679 > }
3680 >
3681 >
3682 >
3683 > // met-jet pair valueLookup
3684 > double
3685 > OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3686 >
3687 >  double value = 0.0;
3688 >
3689 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3690 >
3691 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3692 >  value = applyFunction(function, value);
3693 >
3694 >  return value;
3695 >
3696 > }  
3697 >
3698 >
3699 >
3700 > //!muon-jet pair valueLookup
3701 > double
3702 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3703 >
3704 >  double value = 0.0;
3705 >
3706 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3707 >  else if(variable == "jetEta") value = object2->eta;
3708 >  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3709 >  else if(variable == "jetPt") value = object2->pt;
3710 >  else if(variable == "jetPhi") value = object2->phi;
3711 >  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3712 >  else if(variable == "muonEta") value = object1->eta;
3713 >  else if(variable == "muonPt") value = object1->pt;
3714 >  else if(variable == "muonPhi") value = object1->phi;
3715 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3716 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3717 >  else if(variable == "invMass"){
3718 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3719 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3720 >    value = (fourVector1 + fourVector2).M();
3721 >  }
3722 >  else if(variable == "pt"){
3723 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3724 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3725 >    value = (fourVector1 + fourVector2).Pt();
3726 >  }
3727 >  else if(variable == "threeDAngle")
3728 >    {
3729 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3730 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3731 >      value = (threeVector1.Angle(threeVector2));
3732 >    }
3733 >  else if(variable == "chargeProduct"){
3734 >    value = object1->charge*object2->charge;
3735 >  }
3736 >
3737 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3738 >  value = applyFunction(function, value);
3739 >
3740 >  return value;
3741 > }
3742 >
3743 > //!muon-event valueLookup
3744 > double
3745 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNevent* object2, string variable, string function, string &stringValue){
3746 >
3747 >  double value = 0.0;
3748 >
3749 >  if(variable == "muonEta") value = object1->eta;
3750 >  else if(variable == "muonPt") value = object1->pt;
3751 >  else if(variable == "muonPhi") value = object1->phi;
3752 >  else if(variable == "Ht") value = getHt(jets.product());
3753 >  else if(variable == "pthat")   value = object2->pthat;
3754 >  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3755 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3756 >  value = applyFunction(function, value);
3757 >
3758 >  return value;
3759 > }
3760 > //!jet-jet pair valueLookup
3761 > double
3762 > OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3763 >
3764 >  double value = 0.0;
3765 >
3766 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3767 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3768 >  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3769 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3770 >  else if(variable == "invMass"){
3771 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3772 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3773 >    value = (fourVector1 + fourVector2).M();
3774 >  }
3775 >  else if(variable == "pt"){
3776 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3777 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3778 >    value = (fourVector1 + fourVector2).Pt();
3779 >  }
3780 >  else if(variable == "threeDAngle")
3781 >    {
3782 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3783 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3784 >      value = (threeVector1.Angle(threeVector2));
3785 >    }
3786 >  else if(variable == "chargeProduct"){
3787 >    value = object1->charge*object2->charge;
3788 >  }
3789 >
3790 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3791 >  value = applyFunction(function, value);
3792 >
3793 >  return value;
3794 > }
3795 >
3796 > //!electron-track pair valueLookup
3797 > double
3798 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3799 >  double electronMass = 0.000511;
3800 >  double value = 0.0;
3801 >  TLorentzVector fourVector1(0, 0, 0, 0);
3802 >  TLorentzVector fourVector2(0, 0, 0, 0);
3803 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3804 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3805 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3806 >  else if(variable == "invMass"){
3807 >    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3808 >    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3809 >
3810 >    value = (fourVector1 + fourVector2).M();
3811 >  }
3812 >  else if(variable == "chargeProduct"){
3813 >    value = object1->charge*object2->charge;
3814 >  }
3815 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3816 >  value = applyFunction(function, value);
3817 >  return value;
3818 >
3819 > }
3820 >
3821 >
3822 > //!muon-track pair valueLookup
3823 > double
3824 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3825 >  double pionMass = 0.140;
3826 >  double muonMass = 0.106;
3827 >  double value = 0.0;
3828 >  TLorentzVector fourVector1(0, 0, 0, 0);
3829 >  TLorentzVector fourVector2(0, 0, 0, 0);
3830 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3831 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3832 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3833 >  else if(variable == "invMass"){
3834 >    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3835 >    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3836 >
3837 >    value = (fourVector1 + fourVector2).M();
3838 >  }
3839 >  else if(variable == "chargeProduct"){
3840 >    value = object1->charge*object2->charge;
3841 >  }
3842 >
3843 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3844 >  value = applyFunction(function, value);
3845 >  return value;
3846 > }
3847 >
3848 > //!tau-tau pair valueLookup
3849 > double
3850 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3851 >  double value = 0.0;
3852 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3853 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3854 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3855 >  else if(variable == "invMass"){
3856 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3857 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3858 >    value = (fourVector1 + fourVector2).M();
3859 >  }
3860 >
3861 >  else if(variable == "chargeProduct"){
3862 >    value = object1->charge*object2->charge;
3863 >  }
3864 >
3865 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3866 >  value = applyFunction(function, value);
3867 >  return value;
3868 > }
3869 >
3870 > //!muon-tau pair valueLookup
3871 > double
3872 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3873 >  double value = 0.0;
3874 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3875 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3876 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3877 >  else if(variable == "invMass"){
3878 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3879 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3880 >    value = (fourVector1 + fourVector2).M();
3881 >  }
3882 >
3883 >  else if(variable == "chargeProduct"){
3884 >    value = object1->charge*object2->charge;
3885 >  }
3886 >
3887 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3888 >  value = applyFunction(function, value);
3889 >  return value;
3890 > }
3891 >
3892 > //!tau-track pair valueLookup
3893 > double
3894 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3895 >  double value = 0.0;
3896 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3897 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3898 >  else if(variable == "chargeProduct"){
3899 >    value = object1->charge*object2->charge;
3900 >  }
3901 >
3902 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3903 >  value = applyFunction(function, value);
3904 >  return value;
3905 > }
3906 >
3907 >
3908 > //!track-event pair valueLookup
3909 > double
3910 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3911 >
3912 >  double value = 0.0;
3913 >  double pMag = sqrt(object1->pt * object1->pt +
3914 >                     object1->pz * object1->pz);
3915 >
3916 >  if      (variable == "numPV")                      value = object2->numPV;
3917 >  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3918 >  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3919 >  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3920 >  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3921 >
3922 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3923 >
3924 >  value = applyFunction(function, value);
3925 >
3926 >  return value;
3927 >
3928 > }
3929 >
3930 > //!electron-trigobj pair valueLookup
3931 > double
3932 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3933 >
3934 >  double value = 0.0;
3935 >
3936 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3937 >  else if (variable == "match"){
3938 >    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3939 >      stringValue = object2->filter;
3940 >    else
3941 >      stringValue = "none";
3942 >  }
3943 >
3944 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3945 >
3946 >  value = applyFunction(function, value);
3947 >
3948 >  return value;
3949 >
3950 > }
3951 >
3952 > //!muon-trigobj pair valueLookup
3953 > double
3954 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3955 >
3956 >  double value = 0.0;
3957 >
3958 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3959 >
3960 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3961 >
3962 >  value = applyFunction(function, value);
3963 >
3964 >  return value;
3965 >
3966 > }
3967 >
3968 > //!stop valueLookup
3969 > double
3970 > OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3971 >
3972 >
3973 >  double value = 0.0;
3974 >
3975 >  if(variable == "ctau") value = object->ctau;
3976 >
3977 >  else if (variable == "d0"){
3978 >    double vx = object->vx - chosenVertex ()->x,
3979 >      vy = object->vy - chosenVertex ()->y,
3980 >      px = object->px,
3981 >      py = object->py,
3982 >      pt = object->pt;
3983 >    value = (-vx * py + vy * px) / pt;
3984 >  }
3985 >
3986 >  else if (variable == "dz"){
3987 >    double vx = object->vx - chosenVertex ()->x,
3988 >      vy = object->vy - chosenVertex ()->y,
3989 >      vz = object->vz - chosenVertex ()->z,
3990 >      px = object->px,
3991 >      py = object->py,
3992 >      pz = object->pz,
3993 >      pt = object->pt;
3994 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3995 >  }
3996 >
3997 >  else if (variable == "minD0"){
3998 >    double minD0=999;
3999 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4000 >      double vx = object->vx - vertex->x,
4001 >        vy = object->vy - vertex->y,
4002 >        px = object->px,
4003 >        py = object->py,
4004 >        pt = object->pt;
4005 >      value = (-vx * py + vy * px) / pt;
4006 >      if(abs(value) < abs(minD0)) minD0 = value;
4007 >    }
4008 >    value = minD0;
4009 >  }
4010 >  else if (variable == "minDz"){
4011 >    double minDz=999;
4012 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4013 >      double vx = object->vx - vertex->x,
4014 >        vy = object->vy - vertex->y,
4015 >        vz = object->vz - vertex->z,
4016 >        px = object->px,
4017 >        py = object->py,
4018 >        pz = object->pz,
4019 >        pt = object->pt;
4020 >      value = vz - (vx * px + vy * py)/pt * (pz/pt);
4021 >      if(abs(value) < abs(minDz)) minDz = value;
4022 >    }
4023 >    value = minDz;
4024 >  }
4025 >  else if(variable == "distToVertex"){
4026 >    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4027 >                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4028 >                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4029 >  }
4030 >  else if (variable == "minDistToVertex"){
4031 >    double minDistToVertex=999;
4032 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4033 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4034 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4035 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
4036 >
4037 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4038 >    }
4039 >    value = minDistToVertex;
4040 >  }
4041 >  else if (variable == "distToVertexDifference"){
4042 >    double minDistToVertex=999;
4043 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4044 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4045 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4046 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
4047 >
4048 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4049 >    }
4050 >    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4051 >                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4052 >                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4053 >
4054 >    value = distToChosenVertex - minDistToVertex;
4055 >  }
4056 >
4057 >  else if (variable == "closestVertexRank"){
4058 >    double minDistToVertex=999;
4059 >    int vertex_rank = 0;
4060 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4061 >      vertex_rank++;
4062 >      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4063 >                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
4064 >                      (object->vz-vertex->z)*(object->vz-vertex->z));
4065 >
4066 >      if(abs(dist) < abs(minDistToVertex)){
4067 >        value = vertex_rank;
4068 >        minDistToVertex = dist;
4069 >      }
4070 >    }
4071 >  }
4072 >
4073 >  else if (variable == "decaysToTau"){
4074 >    value = abs (object->daughter0Id) == 15 || abs (object->daughter1Id) == 15;
4075 >  }
4076 >
4077 >
4078 >
4079 >
4080 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4081 >
4082 >  value = applyFunction(function, value);
4083 >
4084 >  return value;
4085 >
4086 > } // end stop valueLookup
4087 >
4088 >
4089 >
4090 >
4091 >
4092 > // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
4093 > // Return true iff no other tracks are found in this cone.
4094 > int
4095 > OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
4096 >  for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
4097 >    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
4098 >    double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
4099 >    if(deltaRtrk < 0.5) return 0;
4100 >  }
4101 >  return 1;
4102 >
4103 > }
4104 >
4105 > //calculate the scalar sum of Jet Pt in the event.
4106 > double
4107 > OSUAnalysis::getHt (const BNjetCollection* jetColl){
4108 >  double Ht = 0;
4109 >  for(BNjetCollection::const_iterator jet = jetColl->begin(); jet !=jetColl->end(); jet++){
4110 >    Ht += abs(jet->pt);
4111 >  }
4112 >  return Ht;
4113 > }
4114 >
4115 > double
4116 > OSUAnalysis::getTrkPtRes (const BNtrack* track1){
4117 >
4118 >  double ptTrue = getTrkPtTrue(track1, mcparticles.product());
4119 >  double PtRes = (track1->pt - ptTrue) / ptTrue;
4120  
4121 +  return PtRes;
4122 +
4123 + }
4124 +
4125 +
4126 + double
4127 + OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
4128 +  double value = -99;
4129 +  double genDeltaRLowest = 999;
4130 +
4131 +  for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
4132 +    double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
4133 +    if (genDeltaRtemp < genDeltaRLowest) {
4134 +      genDeltaRLowest = genDeltaRtemp;
4135 +      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
4136 +        double ptTrue = genPart->pt;
4137 +        value = ptTrue;
4138 +      }
4139 +    }
4140 +  }
4141 +
4142 +  return value;
4143 +
4144 + }
4145 +
4146 + double
4147 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
4148 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
4149 +  if (!useTrackCaloRhoCorr_) return -99;
4150 +  // if (!rhokt6CaloJetsHandle_) {
4151 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
4152 +  //   return -99;
4153 +  // }
4154 +  double radDeltaRCone = 0.5;
4155 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
4156 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
4157 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
4158 +  return caloTotRhoCorrCalo;
4159 +
4160 + }
4161 +
4162 +
4163 +
4164 +
4165 + //creates a map of the dead Ecal channels in the barrel and endcap
4166 + //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
4167 + //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
4168 + void
4169 + OSUAnalysis::WriteDeadEcal (){
4170 +  double etaEcal, phiEcal;
4171 +  ifstream DeadEcalFile(deadEcalFile_);
4172 +  if(!DeadEcalFile) {
4173 +    clog << "Error: DeadEcalFile has not been found." << endl;
4174 +    return;
4175 +  }
4176 +  if(DeadEcalVec.size()!= 0){
4177 +    clog << "Error: DeadEcalVec has a nonzero size" << endl;
4178 +    return;
4179 +  }
4180 +  while(!DeadEcalFile.eof())
4181 +    {
4182 +      DeadEcalFile >> etaEcal >> phiEcal;
4183 +      DeadEcal newChan;
4184 +      newChan.etaEcal = etaEcal;
4185 +      newChan.phiEcal = phiEcal;
4186 +      DeadEcalVec.push_back(newChan);
4187 +    }
4188 +  if(DeadEcalVec.size() == 0) clog << "Warning: No dead Ecal channels have been found." << endl;
4189 + }
4190 +
4191 + //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
4192 + int
4193 + OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
4194 +  double deltaRLowest = 999;
4195 +  int value = 0;
4196 +  if (DeadEcalVec.size() == 0) WriteDeadEcal();
4197 +  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4198 +    double eta = ecal->etaEcal;
4199 +    double phi = ecal->phiEcal;
4200 +    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
4201 +    if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
4202 +  }
4203 +  if (deltaRLowest<0.05) {value = 1;}
4204 +  else {value = 0;}
4205    return value;
4206   }
4207  
4208 + // Returns the smallest DeltaR between the object and any generated true particle in the event.
4209 + template <class InputObject>
4210 + double OSUAnalysis::getGenDeltaRLowest(InputObject object){
4211 +  double genDeltaRLowest = 999.;
4212 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4213 +    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
4214 +    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
4215 +  }
4216 +  return genDeltaRLowest;
4217 + }
4218 +
4219 + double
4220 + OSUAnalysis::applyFunction(string function, double value){
4221  
4222 < template <class InputCollection>
4222 >  if(function == "abs") value = fabs(value);
4223 >  else if(function == "fabs") value = fabs(value);
4224 >  else if(function == "log10") value = log10(value);
4225 >  else if(function == "log") value = log10(value);
4226 >
4227 >  else if(function == "") value = value;
4228 >  else{clog << "WARNING: invalid function '" << function << "'\n";}
4229 >
4230 >  return value;
4231 >
4232 > }
4233 >
4234 >
4235 > template <class InputCollection>
4236   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
4237  
4238 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
4239 +    string obj1, obj2;
4240 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
4241 +    if (inputType==obj1 ||
4242 +        inputType==obj2) {
4243 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
4244 +      // and the inputType is a member of the pair.
4245 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
4246 +      // For example, if currentCut.inputCollection==electron-muon pairs,
4247 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
4248 +      return;
4249 +    }
4250 +  }
4251  
4252    for (uint object = 0; object != inputCollection->size(); object++){
1370    
1371    bool decision = true;//object passes if this cut doesn't cut on that type of object
1372    
1373    if(currentCut.inputCollection == inputType){
1374      
1375      double value = valueLookup(&inputCollection->at(object), currentCut.variable, currentCut.function);
4253  
4254 <      decision = evaluateComparison(value,currentCut.comparativeOperator,currentCut.cutValue);
4254 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4255 >    bool plotDecision = true;
4256 >
4257 >    if(currentCut.inputCollection == inputType){
4258 >
4259 >      vector<bool> subcutDecisions;
4260 >      for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4261 >        string stringValue = "";
4262 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4263 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4264 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4265 >
4266 >      }
4267 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4268 >      else{
4269 >        bool tempDecision = true;
4270 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4271 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4272 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4273 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4274 >            tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4275 >        }
4276 >        cutDecision = tempDecision;
4277 >      }
4278 >      //invert the cut for plotting if this cut is a veto
4279 >      if(currentCut.isVeto) plotDecision = !cutDecision;
4280 >      else plotDecision = cutDecision;
4281      }
1379    individualFlags[inputType].at(currentCutIndex).push_back(decision);
1380    
4282  
4283 <    //set flags for objects that pass each cut AND all the previous cuts
4284 <    bool previousCumulativeFlag = true;
4283 >    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4284 >
4285 >    //set flags for objects that pass this cut AND all the previous cuts
4286 >    bool previousCumulativeCutFlag = true;
4287 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4288 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4289 >      else{ previousCumulativeCutFlag = false; break;}
4290 >    }
4291 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4292 >    bool previousCumulativePlotFlag = true;
4293      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4294 <      if(previousCumulativeFlag && individualFlags[inputType].at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4295 <      else{ previousCumulativeFlag = false; break;}
4294 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4295 >      else{ previousCumulativePlotFlag = false; break;}
4296      }
4297 <    cumulativeFlags[inputType].at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4298 <    
4297 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4298 >
4299 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4300 >
4301    }
4302 <  
4302 >
4303   }
4304  
4305  
4306 + template <class InputCollection1, class InputCollection2>
4307 + void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
4308 +                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, string inputType){
4309 +
4310 +
4311 +  bool sameObjects = false;
4312 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4313 +
4314 +  // Get the strings for the two objects that make up the pair.
4315 +  string obj1Type, obj2Type;
4316 +  getTwoObjs(inputType, obj1Type, obj2Type);
4317 +  bool isTwoTypesOfObject = true;
4318 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
4319 +
4320 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
4321 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4322 +  if (currentCut.inputCollection == inputType) {
4323 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4324 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4325 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4326 +    }
4327 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4328 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4329 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4330 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4331 +      }
4332 +    }
4333 +  }
4334  
4335 +  int counter = 0;
4336  
4337 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4338 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4339  
4340 < DEFINE_FWK_MODULE(OSUAnalysis);
4340 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4341 >
4342 >
4343 >      bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4344 >      bool plotDecision = true;
4345 >
4346 >      if(currentCut.inputCollection == inputType){
4347 >
4348 >        vector<bool> subcutDecisions;
4349 >        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4350 >          string stringValue = "";
4351 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4352 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4353 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4354 >        }
4355 >
4356 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4357 >        else{
4358 >          bool tempDecision = subcutDecisions.at(0);
4359 >          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
4360 >            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
4361 >              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
4362 >            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4363 >              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4364 >          }
4365 >          cutDecision = tempDecision;
4366 >        }
4367 >        //invert the cut for plotting if this cut is a veto
4368 >        if(currentCut.isVeto) plotDecision = !cutDecision;
4369 >        else plotDecision = cutDecision;
4370 >      }
4371 >      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4372 >      if (cutDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4373 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4374 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4375 >      }
4376 >      if (plotDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4377 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4378 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4379 >      }
4380 >
4381 >      //set flags for objects that pass this cut AND all the previous cuts
4382 >      bool previousCumulativeCutFlag = true;
4383 >      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4384 >        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4385 >        else{ previousCumulativeCutFlag = false; break;}
4386 >      }
4387 >      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4388 >
4389 >      bool previousCumulativePlotFlag = true;
4390 >      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4391 >        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4392 >        else{ previousCumulativePlotFlag = false; break;}
4393 >      }
4394 >      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4395 >      
4396 >      //apply flags for the components of the composite object as well
4397 >      bool currentCumulativeCutFlag = true;
4398 >      bool currentCumulativePlotFlag = true;
4399 >
4400 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4401 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4402 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4403 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4404 >
4405 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4406 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4407 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4408 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4409 >
4410 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));
4411 >
4412 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4413 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4414 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4415 >      }
4416 >
4417 >      if (currentCumulativePlotFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4418 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4419 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4420 >      }
4421 >
4422 >      counter++;
4423 >
4424 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4425 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4426 >
4427 > }
4428 >
4429 >
4430 > bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4431 >  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4432 >  // all cuts up to currentCutIndex
4433 >  bool previousCumulativeFlag = true;
4434 >  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4435 >    bool tempFlag = false;
4436 >    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4437 >    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4438 >
4439 >    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4440 >    else {
4441 >      previousCumulativeFlag = false; break;
4442 >    }
4443 >  }
4444 >  return previousCumulativeFlag;
4445 > }
4446 >
4447 >
4448 >
4449 >
4450 > template <class InputCollection>
4451 > void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4452 >  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4453 >
4454 >  if (BNTreeBranchVals_.count(parameters.name)==0) clog << "Error[assignTreeBranch]:  trying to assign value to " << parameters.name << " that does not have a branch set up.  Will likely seg fault." << endl;
4455 >  for (uint object = 0; object != inputCollection->size(); object++) {
4456 >
4457 >    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4458 >
4459 >    string inputVariable = parameters.inputVariable;
4460 >    string function = "";
4461 >    string stringValue = "";
4462 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4463 >    BNTreeBranchVals_.at(parameters.name).push_back(value);
4464 >
4465 >  }
4466 > }
4467 >
4468 >
4469 > template <class InputCollection>
4470 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4471 >
4472 >
4473 >  for (uint object = 0; object != inputCollection->size(); object++){
4474 >
4475 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4476 >
4477 >    string currentString = parameters.inputVariables.at(0);
4478 >    string inputVariable = "";
4479 >    string function = "";
4480 >    if(currentString.find("(")==string::npos){
4481 >      inputVariable = currentString;// variable to cut on
4482 >    }
4483 >    else{
4484 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4485 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4486 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4487 >    }
4488 >
4489 >    string stringValue = "";
4490 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4491 >    histo->Fill(value,scaleFactor);
4492 >
4493 >    if (printEventInfo_) {
4494 >      // Write information about event to screen, for testing purposes.
4495 >      clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
4496 >    }
4497 >
4498 >  }
4499 > }
4500 >
4501 > template <class InputCollection1, class InputCollection2>
4502 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4503 >
4504 >  bool sameObjects = false;
4505 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4506 >
4507 >  int pairCounter = -1;
4508 >  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4509 >    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4510 >
4511 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4512 >
4513 >      pairCounter++;
4514 >      //only take objects which have passed all cuts and pairs which have passed all cuts
4515 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4516 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4517 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4518 >
4519 >      string currentString = parameters.inputVariables.at(0);
4520 >      string inputVariable = "";
4521 >      string function = "";
4522 >      if(currentString.find("(")==string::npos){
4523 >        inputVariable = currentString;// variable to cut on
4524 >      }
4525 >      else{
4526 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4527 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4528 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4529 >      }
4530 >
4531 >      string stringValue = "";
4532 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4533 >      histo->Fill(value,scaleFactor);
4534 >
4535 >    }
4536 >  }
4537 >
4538 > }
4539 >
4540 >
4541 > template <class InputCollection>
4542 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4543 >
4544 >  for (uint object = 0; object != inputCollection->size(); object++){
4545  
4546 +    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4547  
4548 +    string stringValue = "";
4549 +    string currentString = parameters.inputVariables.at(0);
4550 +    string inputVariable = "";
4551 +    string function = "";
4552 +    if(currentString.find("(")==string::npos){
4553 +      inputVariable = currentString;// variable to cut on
4554 +    }
4555 +    else{
4556 +      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4557 +      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4558 +      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4559 +    }
4560 +    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4561 +
4562 +    currentString = parameters.inputVariables.at(1);
4563 +    inputVariable = "";
4564 +    function = "";
4565 +    if(currentString.find("(")==string::npos){
4566 +      inputVariable = currentString;// variable to cut on
4567 +    }
4568 +    else{
4569 +      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4570 +      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4571 +      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4572 +    }
4573 +
4574 +    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4575 +
4576 +    histo->Fill(valueX,valueY,scaleFactor);
4577 +
4578 +  }
4579 +
4580 + }
4581 +
4582 + template <class InputCollection1, class InputCollection2>
4583 + void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4584 +
4585 +  bool sameObjects = false;
4586 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4587 +
4588 +  int pairCounter = -1;
4589 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4590 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4591 +
4592 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4593 +
4594 +      pairCounter++;
4595 +
4596 +      //only take objects which have passed all cuts and pairs which have passed all cuts
4597 +      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4598 +      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4599 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4600 +
4601 +      string stringValue = "";
4602 +      string currentString = parameters.inputVariables.at(0);
4603 +      string inputVariable = "";
4604 +      string function = "";
4605 +      if(currentString.find("(")==string::npos){
4606 +        inputVariable = currentString;// variable to cut on
4607 +      }
4608 +      else{
4609 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4610 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4611 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4612 +      }
4613 +      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4614 +
4615 +      currentString = parameters.inputVariables.at(1);
4616 +      inputVariable = "";
4617 +      function = "";
4618 +      if(currentString.find("(")==string::npos){
4619 +        inputVariable = currentString;// variable to cut on
4620 +      }
4621 +      else{
4622 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4623 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4624 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4625 +      }
4626 +      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4627 +
4628 +
4629 +      histo->Fill(valueX,valueY,scaleFactor);
4630 +
4631 +    }
4632 +  }
4633 +
4634 + }
4635 +
4636 +
4637 + template <class InputObject>
4638 + int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
4639 +
4640 +  int bestMatchIndex = -1;
4641 +  double bestMatchDeltaR = 999;
4642 +
4643 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4644 +
4645 +    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4646 +    if(currentDeltaR > 0.05) continue;
4647 +    //     clog << setprecision(3) << setw(20)
4648 +    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4649 +    //          << setw(20)
4650 +    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4651 +    //          << setw(20)
4652 +    //          << "\tdeltaR = " << currentDeltaR
4653 +    //          << setprecision(1)
4654 +    //          << setw(20)
4655 +    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4656 +    //          << setw(20)
4657 +    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4658 +    //          << setw(20)
4659 +    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4660 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4661 +      bestMatchIndex = mcparticle - mcparticles->begin();
4662 +      bestMatchDeltaR = currentDeltaR;
4663 +    }
4664 +
4665 +  }
4666 +  //   if(bestMatchDeltaR != 999)  clog << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4667 +  //   else clog << "no match found..." << endl;
4668 +  return bestMatchIndex;
4669 +
4670 + }
4671 +
4672 +
4673 + int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
4674 +
4675 +  int bestMatchIndex = -1;
4676 +  double bestMatchDeltaR = 999;
4677 +
4678 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4679 +
4680 +    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
4681 +
4682 +    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
4683 +    if(currentDeltaR > 0.05) continue;
4684 +
4685 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4686 +      bestMatchIndex = mcparticle - mcparticles->begin();
4687 +      bestMatchDeltaR = currentDeltaR;
4688 +    }
4689 +
4690 +  }
4691 +
4692 +  return bestMatchIndex;
4693 + }
4694 +
4695 +
4696 + // bin      particle type
4697 + // ---      -------------
4698 + //  0        unmatched
4699 + //  1        u
4700 + //  2        d
4701 + //  3        s
4702 + //  4        c
4703 + //  5        b
4704 + //  6        t
4705 + //  7        e
4706 + //  8        mu
4707 + //  9        tau
4708 + // 10        nu
4709 + // 11        g
4710 + // 12        gamma
4711 + // 13        Z
4712 + // 14        W
4713 + // 15        light meson
4714 + // 16        K meson
4715 + // 17        D meson
4716 + // 18        B meson
4717 + // 19        light baryon
4718 + // 20        strange baryon
4719 + // 21        charm baryon
4720 + // 22        bottom baryon
4721 + // 23        QCD string
4722 + // 24        other
4723 +
4724 + int OSUAnalysis::getPdgIdBinValue(int pdgId){
4725 +
4726 +  int binValue = -999;
4727 +  int absPdgId = fabs(pdgId);
4728 +  if(pdgId == -1) binValue = 0;
4729 +  else if(absPdgId <= 6 ) binValue = absPdgId;
4730 +  else if(absPdgId == 11 ) binValue = 7;
4731 +  else if(absPdgId == 13 ) binValue = 8;
4732 +  else if(absPdgId == 15 ) binValue = 9;
4733 +  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
4734 +  else if(absPdgId == 21 ) binValue = 11;
4735 +  else if(absPdgId == 22 ) binValue = 12;
4736 +  else if(absPdgId == 23 ) binValue = 13;
4737 +  else if(absPdgId == 24 ) binValue = 14;
4738 +  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
4739 +  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
4740 +  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
4741 +  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
4742 +  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
4743 +  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4744 +  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4745 +  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4746 +  else if(absPdgId == 92  ) binValue = 23;
4747 +
4748 +  else binValue = 24;
4749 +
4750 +  return binValue;
4751 +
4752 + }
4753 +
4754 + const BNprimaryvertex *
4755 + OSUAnalysis::chosenVertex ()
4756 + {
4757 +  const BNprimaryvertex *chosenVertex = 0;
4758 +  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4759 +    flagPair vertexFlags;
4760 +    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4761 +      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4762 +        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4763 +        break;
4764 +      }
4765 +    }
4766 +    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4767 +      if(!vertexFlags.at(vertexIndex).first) continue;
4768 +      chosenVertex = & primaryvertexs->at(vertexIndex);
4769 +      break;
4770 +    }
4771 +  }
4772 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4773 +    chosenVertex = & primaryvertexs->at (0);
4774 +
4775 +  return chosenVertex;
4776 + }
4777 +
4778 + const BNmet *
4779 + OSUAnalysis::chosenMET ()
4780 + {
4781 +  const BNmet *chosenMET = 0;
4782 +  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4783 +    flagPair metFlags;
4784 +    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4785 +      if (cumulativeFlags.at("mets").at(i).size()){
4786 +        metFlags = cumulativeFlags.at("mets").at(i);
4787 +        break;
4788 +      }
4789 +    }
4790 +    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4791 +      if(!metFlags.at(metIndex).first) continue;
4792 +      chosenMET = & mets->at(metIndex);
4793 +      break;
4794 +    }
4795 +  }
4796 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4797 +    chosenMET = & mets->at (0);
4798 +
4799 +  return chosenMET;
4800 + }
4801 +
4802 + const BNelectron *
4803 + OSUAnalysis::chosenElectron ()
4804 + {
4805 +  const BNelectron *chosenElectron = 0;
4806 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4807 +    flagPair electronFlags;
4808 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4809 +      if (cumulativeFlags.at("electrons").at(i).size()){
4810 +        electronFlags = cumulativeFlags.at("electrons").at(i);
4811 +        break;
4812 +      }
4813 +    }
4814 +    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4815 +      if(!electronFlags.at(electronIndex).first) continue;
4816 +      chosenElectron = & electrons->at(electronIndex);
4817 +      break;
4818 +    }
4819 +  }
4820 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4821 +    chosenElectron = & electrons->at (0);
4822 +
4823 +  return chosenElectron;
4824 + }
4825 +
4826 +
4827 + const BNmuon *
4828 + OSUAnalysis::chosenMuon ()
4829 + {
4830 +  const BNmuon *chosenMuon = 0;
4831 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4832 +    flagPair muonFlags;
4833 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4834 +      if (cumulativeFlags.at("muons").at(i).size()){
4835 +        muonFlags = cumulativeFlags.at("muons").at(i);
4836 +        break;
4837 +      }
4838 +    }
4839 +    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4840 +      if(!muonFlags.at(muonIndex).first) continue;
4841 +      chosenMuon = & muons->at(muonIndex);
4842 +      break;
4843 +    }
4844 +  }
4845 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4846 +    chosenMuon = & muons->at (0);
4847 +
4848 +  return chosenMuon;
4849 + }
4850 +
4851 + double
4852 + OSUAnalysis::chosenHT ()
4853 + {
4854 +  double chosenHT = 0.0;
4855 +  if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
4856 +    flagPair jetFlags;
4857 +    for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
4858 +      if (cumulativeFlags.at("jets").at(i).size()){
4859 +        jetFlags = cumulativeFlags.at("jets").at(i);
4860 +        break;
4861 +      }
4862 +    }
4863 +    for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
4864 +      if(!jetFlags.at(jetIndex).first) continue;
4865 +      chosenHT += jets->at(jetIndex).pt;
4866 +    }
4867 +  }
4868 +
4869 +  return chosenHT;
4870 + }
4871 +
4872 + pair<const BNmuon *, const BNmuon *>
4873 + OSUAnalysis::leadMuonPair ()
4874 + {
4875 +  pair<const BNmuon *, const BNmuon *> leadMuonPair;
4876 +  leadMuonPair.first = leadMuonPair.second = 0;
4877 +
4878 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4879 +    flagPair muonFlags;
4880 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4881 +      if (cumulativeFlags.at("muons").at(i).size()){
4882 +        muonFlags = cumulativeFlags.at("muons").at(i);
4883 +        break;
4884 +      }
4885 +    }
4886 +    for (uint muonIndex0 = 0; muonIndex0 != muonFlags.size(); muonIndex0++){
4887 +      if(!muonFlags.at(muonIndex0).first) continue;
4888 +      for (uint muonIndex1 = muonIndex0 + 1; muonIndex1 < muonFlags.size(); muonIndex1++){
4889 +        if(!muonFlags.at(muonIndex1).first) continue;
4890 +        const BNmuon *mu0 = & muons->at(muonIndex0);
4891 +        const BNmuon *mu1 = & muons->at(muonIndex1);
4892 +        if(leadMuonPair.first == 0 || leadMuonPair.second == 0){
4893 +          leadMuonPair.first = mu0;
4894 +          leadMuonPair.second = mu1;
4895 +        }
4896 +        else{
4897 +          TVector2 newPt0 (mu0->px, mu0->py),
4898 +                   newPt1 (mu1->px, mu1->py),
4899 +                   oldPt0 (leadMuonPair.first->px, leadMuonPair.first->py),
4900 +                   oldPt1 (leadMuonPair.second->px, leadMuonPair.second->py);
4901 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
4902 +            {
4903 +              leadMuonPair.first = mu0;
4904 +              leadMuonPair.second = mu1;
4905 +            }
4906 +        }
4907 +      }
4908 +    }
4909 +  }
4910 +
4911 +  return leadMuonPair;
4912 + }
4913 +
4914 + pair<const BNelectron *, const BNelectron *>
4915 + OSUAnalysis::leadElectronPair ()
4916 + {
4917 +  pair<const BNelectron *, const BNelectron *> leadElectronPair;
4918 +  leadElectronPair.first = leadElectronPair.second = 0;
4919 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4920 +    flagPair electronFlags;
4921 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4922 +      if (cumulativeFlags.at("electrons").at(i).size()){
4923 +        electronFlags = cumulativeFlags.at("electrons").at(i);
4924 +        break;
4925 +      }
4926 +    }
4927 +    for (uint electronIndex0 = 0; electronIndex0 != electronFlags.size(); electronIndex0++){
4928 +      if(!electronFlags.at(electronIndex0).first) continue;
4929 +      for (uint electronIndex1 = electronIndex0 + 1; electronIndex1 < electronFlags.size(); electronIndex1++){
4930 +        if(!electronFlags.at(electronIndex1).first) continue;
4931 +        const BNelectron *el0 = & electrons->at(electronIndex0);
4932 +        const BNelectron *el1 = & electrons->at(electronIndex1);
4933 +        if(leadElectronPair.first == 0 || leadElectronPair.second == 0){
4934 +          leadElectronPair.first = el0;
4935 +          leadElectronPair.second = el1;
4936 +        }
4937 +        else{
4938 +          TVector2 newPt0 (el0->px, el0->py),
4939 +                   newPt1 (el1->px, el1->py),
4940 +                   oldPt0 (leadElectronPair.first->px, leadElectronPair.first->py),
4941 +                   oldPt1 (leadElectronPair.second->px, leadElectronPair.second->py);
4942 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
4943 +            {
4944 +              leadElectronPair.first = el0;
4945 +              leadElectronPair.second = el1;
4946 +            }
4947 +        }
4948 +      }
4949 +    }
4950 +  }
4951 +
4952 +  return leadElectronPair;
4953 + }
4954 +
4955 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines