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.8 by ahart, Wed Jan 30 22:29:59 2013 UTC vs.
Revision 1.114 by wulsin, Wed Jul 31 09:38:21 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")),
5    muons_ (cfg.getParameter<edm::InputTag> ("muons")),
6 +  secMuons_ (cfg.getParameter<edm::InputTag> ("secMuons")),
7    electrons_ (cfg.getParameter<edm::InputTag> ("electrons")),
8    events_ (cfg.getParameter<edm::InputTag> ("events")),
9    taus_ (cfg.getParameter<edm::InputTag> ("taus")),
# Line 11 | Line 11 | OSUAnalysis::OSUAnalysis (const edm::Par
11    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
12    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
13    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
14 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
15    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
16    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
17    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
18    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
19    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
20 +  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
21 +  puFile_ (cfg.getParameter<string> ("puFile")),
22 +  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
23 +  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
24 +  dataPU_ (cfg.getParameter<string> ("dataPU")),
25 +  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
26 +  muonSF_ (cfg.getParameter<string> ("muonSF")),
27 +  dataset_ (cfg.getParameter<string> ("dataset")),
28 +  datasetType_ (cfg.getParameter<string> ("datasetType")),
29 +  channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
30 +  histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
31 +  useEDMFormat_   (cfg.getParameter<bool>("useEDMFormat")),
32 +  treeBranchSets_   (cfg.getParameter<vector<edm::ParameterSet> >("treeBranchSets")),
33 +  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
34 +  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
35 +  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
36 +  applyBtagSF_ (cfg.getParameter<bool> ("applyBtagSF")),
37 +  minBtag_ (cfg.getParameter<int> ("minBtag")),
38 +  printEventInfo_      (cfg.getParameter<bool> ("printEventInfo")),
39 +  printAllTriggers_    (cfg.getParameter<bool> ("printAllTriggers")),
40 +  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
41 +  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
42 +  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut")),
43 +  verbose_ (cfg.getParameter<int> ("verbose"))
44 + {
45 +
46 +  if (verbose_) printEventInfo_ = true;  
47 +  if (verbose_) clog << "Beginning OSUAnalysis::OSUAnalysis constructor." << endl;  
48 +
49 +  TH1::SetDefaultSumw2();
50 +
51 +  //create pile-up reweighting object, if necessary
52 +  if(datasetType_ != "data") {
53 +    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
54 +    if (applyLeptonSF_){
55 +      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
56 +      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
57 +    }
58 +    if (applyBtagSF_){
59 +      bTagSFWeight_ = new BtagSFWeight;
60 +    }
61 +  }
62 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
63 +    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at(0), stopCTau_.at(1), stops_);
64  
65  
21  channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels"))
22
23 {
24  TH1::SetDefaultSumw2 ();
25
66    // Construct Cutflow Objects. These store the results of cut decisions and
67    // handle filling cut flow histograms.
68    masterCutFlow_ = new CutFlow (fs_);
69 <  std::vector<TFileDirectory> directories;
69 >
70 >  //always get vertex collection so we can assign the primary vertex in the event
71 >  objectsToGet.push_back("primaryvertexs");
72 >  objectsToPlot.push_back("primaryvertexs");
73 >  objectsToFlag.push_back("primaryvertexs");
74 >
75 >
76 >  //always get the MC particles to do GEN-matching
77 >  objectsToGet.push_back("mcparticles");
78 >
79 >  //always get the event collection to do pile-up reweighting
80 >  objectsToGet.push_back("events");
81 >
82 >
83 >  // Parse the tree variable definitions.
84 >  for (uint iBranchSet = 0; !useEDMFormat_ && iBranchSet<treeBranchSets_.size(); iBranchSet++) {
85 >    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
86 >    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; }
87 >    objectsToGet.push_back(tempInputCollection);
88 >    objectsToFlag.push_back(tempInputCollection);
89 >
90 >    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
91 >
92 >    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
93 >      BranchSpecs br;
94 >      br.inputCollection = tempInputCollection;
95 >      br.inputVariable = branchList.at(iBranch);
96 >      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);
97 >      br.name = string(newName.Data());
98 >      treeBranches_.push_back(br);
99 >      if (verbose_>3) clog << "   Adding branch to BNTree: " << br.name << endl;  
100 >    }
101 >
102 >  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++)
103 >
104 >
105 >  //parse the histogram definitions
106 >  for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
107 >
108 >    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
109 >    if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
110 >    if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
111 >    if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
112 >    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
113 >    if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
114 >    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
115 >    if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
116 >    if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
117 >    if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
118 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
119 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
120 >    if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
121 >    if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
122 >    if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
123 >    if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
124 >    if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
125 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
126 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
127 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
128 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
129 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
130 >        int spaceIndex = tempInputCollection.find(" ");
131 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
132 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
133 >      }
134 >      else{
135 >        objectsToGet.push_back(tempInputCollection);
136 >      }
137 >      objectsToPlot.push_back(tempInputCollection);
138 >      objectsToFlag.push_back(tempInputCollection);
139 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
140 >      string obj1;
141 >      string obj2;
142 >      getTwoObjs(tempInputCollection, obj1, obj2);
143 >      string obj2ToGet = getObjToGet(obj2);
144 >      objectsToFlag.push_back(tempInputCollection);
145 >      objectsToFlag.push_back(obj1);
146 >      objectsToFlag.push_back(obj2);
147 >      objectsToPlot.push_back(tempInputCollection);
148 >      objectsToPlot.push_back(obj1);
149 >      objectsToPlot.push_back(obj2);
150 >      objectsToGet.push_back(tempInputCollection);
151 >      objectsToGet.push_back(obj1);
152 >      objectsToGet.push_back(obj2ToGet);
153 >    } // end else
154 >    if (find(objectsToPlot.begin(), objectsToPlot.end(), "events") != objectsToPlot.end())
155 >      objectsToGet.push_back("jets");
156 >    
157 >    
158 >    vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
159 >
160 >    for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
161 >
162 >      vector<double> defaultValue;
163 >      defaultValue.push_back (-1.0);
164 >
165 >      histogram tempHistogram;
166 >      tempHistogram.inputCollection = tempInputCollection;
167 >      tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
168 >      tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
169 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
170 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
171 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
172 >      tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
173 >
174 >      histograms.push_back(tempHistogram);
175 >
176 >    }
177 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
178 >
179 >  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
180 >  sort( objectsToPlot.begin(), objectsToPlot.end() );
181 >  objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
182 >
183 >
184 >
185 >  //add histograms with the gen-matched id, mother id, and grandmother id
186 >  for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
187 >
188 >    string currentObject = objectsToPlot.at(currentObjectIndex);
189 >    if(currentObject != "muons" &&
190 >       currentObject != "secondary muons" &&
191 >       currentObject != "secondary electrons" &&
192 >       currentObject != "electrons" &&
193 >       currentObject != "taus" &&
194 >       currentObject != "tracks" &&
195 >       currentObject != "photons" &&
196 >       currentObject != "secondary photons"&&
197 >       currentObject != "superclusters")
198 >      continue;
199 >
200 >    histogram tempIdHisto;
201 >    histogram tempMomIdHisto;
202 >    histogram tempGmaIdHisto;
203 >    histogram tempIdVsMomIdHisto;
204 >    histogram tempIdVsGmaIdHisto;
205 >
206 >    tempIdHisto.inputCollection = currentObject;
207 >    tempMomIdHisto.inputCollection = currentObject;
208 >    tempGmaIdHisto.inputCollection = currentObject;
209 >    tempIdVsMomIdHisto.inputCollection = currentObject;
210 >    tempIdVsGmaIdHisto.inputCollection = currentObject;
211 >
212 >    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
213 >    if(currentObject == "secondary photons") currentObject = "secondaryPhotons";
214 >    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
215 >
216 >    currentObject = currentObject.substr(0, currentObject.size()-1);
217 >    tempIdHisto.name = currentObject+"GenMatchId";
218 >    tempMomIdHisto.name = currentObject+"GenMatchMotherId";
219 >    tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
220 >    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
221 >    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
222 >
223 >    currentObject.at(0) = toupper(currentObject.at(0));
224 >    tempIdHisto.title = currentObject+" Gen-matched Particle";
225 >    tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
226 >    tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
227 >    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
228 >    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
229 >
230 >
231 >    int maxNum = 25;
232 >    vector<double> binVector;
233 >    binVector.push_back(maxNum);
234 >    binVector.push_back(0);
235 >    binVector.push_back(maxNum);
236 >
237 >    tempIdHisto.bins = binVector;
238 >    tempIdHisto.inputVariables.push_back("genMatchedId");
239 >    tempMomIdHisto.bins = binVector;
240 >    tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
241 >    tempGmaIdHisto.bins = binVector;
242 >    tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
243 >    binVector.push_back(maxNum);
244 >    binVector.push_back(0);
245 >    binVector.push_back(maxNum);
246 >    tempIdVsMomIdHisto.bins = binVector;
247 >    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
248 >    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
249 >    tempIdVsGmaIdHisto.bins = binVector;
250 >    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
251 >    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
252 >
253 >    histograms.push_back(tempIdHisto);
254 >    histograms.push_back(tempMomIdHisto);
255 >    histograms.push_back(tempGmaIdHisto);
256 >    histograms.push_back(tempIdVsMomIdHisto);
257 >    histograms.push_back(tempIdVsGmaIdHisto);
258 >  }
259  
260  
261    channel tempChannel;
# Line 37 | Line 266 | OSUAnalysis::OSUAnalysis (const edm::Par
266      string channelName  (channels_.at(currentChannel).getParameter<string>("name"));
267      tempChannel.name = channelName;
268      TString channelLabel = channelName;
269 +    if (verbose_) clog << "Processing channel:  " << channelName << endl;  
270  
271      //set triggers for this channel
272      vector<string> triggerNames;
273      triggerNames.clear();
274 +    vector<string> triggerToVetoNames;
275 +    triggerToVetoNames.clear();
276 +
277      tempChannel.triggers.clear();
278 +    tempChannel.triggersToVeto.clear();
279      if(channels_.at(currentChannel).exists("triggers")){
280        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
281        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
282          tempChannel.triggers.push_back(triggerNames.at(trigger));
283 <      allNecessaryObjects.push_back("triggers");
283 >      objectsToGet.push_back("triggers");
284      }
285 +    if(channels_.at(currentChannel).exists("triggersToVeto")){
286 +      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
287 +      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
288 +        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
289 +      objectsToGet.push_back("triggers");
290 +    }
291 +
292  
293  
294      //create cutFlow for this channel
295      cutFlows_.push_back (new CutFlow (fs_, channelName));
296 <
297 <    //book a directory in the output file with the name of the channel
298 <    TFileDirectory subDir = fs_->mkdir( channelName );
58 <    directories.push_back(subDir);
59 <    std::map<std::string, TH1D*> histoMap;
60 <    oneDHists_.push_back(histoMap);
61 <
62 <    //gen histograms
63 <    oneDHists_.at(currentChannel)["genD0"] = directories.at(currentChannel).make<TH1D> ("genD0",channelLabel+" channel: Gen d_{0}; d_{0} [cm] ", 1000, -1, 1);
64 <    oneDHists_.at(currentChannel)["genAbsD0"] = directories.at(currentChannel).make<TH1D> ("genAbsD0",channelLabel+" channel: Gen d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
65 <    oneDHists_.at(currentChannel)["genDZ"] = directories.at(currentChannel).make<TH1D> ("genDZ",channelLabel+" channel: Gen d_{z}; d_{z} [cm] ", 1000, -10, 10);
66 <    oneDHists_.at(currentChannel)["genAbsDZ"] = directories.at(currentChannel).make<TH1D> ("genAbsDZ",channelLabel+" channel: Gen d_{z}; |d_{z}| [cm] ", 1000, 0, 10);
67 <
68 <    //muon histograms
69 <    allNecessaryObjects.push_back("muons");
70 <    oneDHists_.at(currentChannel)["muonPt"]  = directories.at(currentChannel).make<TH1D> ("muonPt",channelLabel+" channel: Muon Transverse Momentum; p_{T} [GeV]", 100, 0, 500);
71 <    oneDHists_.at(currentChannel)["muonEta"] = directories.at(currentChannel).make<TH1D> ("muonEta",channelLabel+" channel: Muon Eta; #eta", 100, -5, 5);
72 <    oneDHists_.at(currentChannel)["muonD0"] = directories.at(currentChannel).make<TH1D> ("muonD0",channelLabel+" channel: Muon d_{0}; d_{0} [cm] ", 1000, -1, 1);
73 <    oneDHists_.at(currentChannel)["muonDz"] = directories.at(currentChannel).make<TH1D> ("muonDz",channelLabel+" channel: Muon d_{z}; d_{z} [cm] ", 1000, -20, 20);
74 <    oneDHists_.at(currentChannel)["muonAbsD0"] = directories.at(currentChannel).make<TH1D> ("muonAbsD0",channelLabel+" channel: Muon d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
75 <    oneDHists_.at(currentChannel)["muonDZ"] = directories.at(currentChannel).make<TH1D> ("muonDZ",channelLabel+" channel: Muon d_{z}; d_{z} [cm] ", 1000, -10, 10);
76 <    oneDHists_.at(currentChannel)["muonAbsDZ"] = directories.at(currentChannel).make<TH1D> ("muonAbsDZ",channelLabel+" channel: Muon d_{z}; |d_{z}| [cm] ", 1000, 0, 10);
77 <    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);
78 <    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);
79 <    oneDHists_.at(currentChannel)["muonIso"] = directories.at(currentChannel).make<TH1D> ("muonIso",channelLabel+" channel: Muon Combined Relative Isolation; rel. iso. ", 1000, 0, 1);
80 <    oneDHists_.at(currentChannel)["numMuons"] = directories.at(currentChannel).make<TH1D> ("numMuons",channelLabel+" channel: Number of Selected Muons; # muons", 10, 0, 10);
81 <
82 <
83 <    //electron histograms
84 <    allNecessaryObjects.push_back("electrons");
85 <    oneDHists_.at(currentChannel)["electronPt"]  = directories.at(currentChannel).make<TH1D> ("electronPt",channelLabel+" channel: Electron Transverse Momentum; p_{T} [GeV]", 100, 0, 500);
86 <    oneDHists_.at(currentChannel)["electronEta"] = directories.at(currentChannel).make<TH1D> ("electronEta",channelLabel+" channel: Electron Eta; #eta", 50, -5, 5);
87 <    oneDHists_.at(currentChannel)["electronD0"] = directories.at(currentChannel).make<TH1D> ("electronD0",channelLabel+" channel: Electron d_{0}; d_{0} [cm] ", 1000, -1, 1);
88 <    oneDHists_.at(currentChannel)["electronDz"] = directories.at(currentChannel).make<TH1D> ("electronDz",channelLabel+" channel: Electron d_{z}; d_{z} [cm] ", 1000, -20, 20);
89 <    oneDHists_.at(currentChannel)["electronAbsD0"] = directories.at(currentChannel).make<TH1D> ("electronAbsD0",channelLabel+" channel: Electron d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
90 <    oneDHists_.at(currentChannel)["electronDZ"] = directories.at(currentChannel).make<TH1D> ("electronDZ",channelLabel+" channel: Electron d_{z}; d_{z} [cm] ", 1000, -10, 10);
91 <    oneDHists_.at(currentChannel)["electronAbsDZ"] = directories.at(currentChannel).make<TH1D> ("electronAbsDZ",channelLabel+" channel: Electron d_{z}; |d_{z}| [cm] ", 1000, 0, 10);
92 <    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);
93 <    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);
94 <    oneDHists_.at(currentChannel)["electronIso"] = directories.at(currentChannel).make<TH1D> ("electronIso",channelLabel+" channel: Electron Combined Relative Isolation; rel. iso. ", 1000, 0, 1);
95 <    oneDHists_.at(currentChannel)["electronFbrem"] = directories.at(currentChannel).make<TH1D> ("electronFbrem",channelLabel+" channel: Electron Brem. Energy Fraction; fbrem", 1000, 0, 2);
96 <    oneDHists_.at(currentChannel)["electronMVATrig"] = directories.at(currentChannel).make<TH1D> ("electronMVATrig",channelLabel+" channel: Electron ID MVA Output", 100, -1, 1);
97 <    oneDHists_.at(currentChannel)["electronMVANonTrig"] = directories.at(currentChannel).make<TH1D> ("electronMVANonTrig",channelLabel+" channel: Electron ID MVA Output", 100, -1, 1);
98 <    oneDHists_.at(currentChannel)["numElectrons"] = directories.at(currentChannel).make<TH1D> ("numElectrons",channelLabel+" channel: Number of Selected Electrons; # electrons", 10, 0, 10);
99 <
100 <
101 <
296 >    vector<TFileDirectory> directories; //vector of directories in the output file.
297 >    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
298 >    vector<string> subSubDirNames;//subdirectories in each channel.
299      //get list of cuts for this channel
300      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
301  
105    vector<string> tempInputCollections;
106
302  
303      //loop over and parse all cuts
304      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
110
305        cut tempCut;
306 <     //store input collection for cut
307 <      string inputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
308 <      tempCut.inputCollection = inputCollection;
306 >      //store input collection for cut
307 >      string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
308 >      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
309 >      if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
310 >      if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
311 >      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
312 >      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
313 >      if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
314 >      if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
315 >      if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
316 >      if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
317 >      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
318 >      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
319 >      if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
320 >      if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
321 >      if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
322 >      if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
323 >      if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
324 >      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
325 >      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
326 >      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
327 >      tempCut.inputCollection = tempInputCollection;
328 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
329 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
330 >          if(tempInputCollection.find("secondary muons")!=string::npos){//treat secondary muons differently; allow for a different input collection
331 >            objectsToGet.push_back("secondary muons");  
332 >          } else {
333 >            int spaceIndex = tempInputCollection.find(" ");
334 >            int secondWordLength = tempInputCollection.size() - spaceIndex;
335 >            objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
336 >          }
337 >        }
338 >        else{
339 >          objectsToGet.push_back(tempInputCollection);
340 >        }
341 >        objectsToCut.push_back(tempInputCollection);
342 >        objectsToFlag.push_back(tempInputCollection);
343 >      }
344 >      else{//pair of objects, need to add them both to objectsToGet
345 >        string obj1;
346 >        string obj2;
347 >        getTwoObjs(tempInputCollection, obj1, obj2);
348 >        string obj2ToGet = getObjToGet(obj2);
349 >        objectsToCut.push_back(tempInputCollection);
350 >        objectsToCut.push_back(obj1);
351 >        objectsToCut.push_back(obj2);
352 >        objectsToFlag.push_back(tempInputCollection);
353 >        objectsToFlag.push_back(obj1);
354 >        objectsToFlag.push_back(obj2);
355 >        objectsToGet.push_back(tempInputCollection);
356 >        objectsToGet.push_back(obj1);
357 >        objectsToGet.push_back(obj2ToGet);
358 >
359 >      }
360 >
361  
116      tempInputCollections.push_back(inputCollection);
117      allNecessaryObjects.push_back(inputCollection);
362  
363        //split cut string into parts and store them
364        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
365 <      std::vector<string> cutStringVector = splitString(cutString);
366 <      tempCut.variable = cutStringVector.at(0);// variable to cut on
367 <      tempCut.comparativeOperator = cutStringVector.at(1);// comparison to make
368 <      tempCut.cutValue = atof(cutStringVector.at(2).c_str());// threshold value to pass cut
365 >      vector<string> cutStringVector = splitString(cutString);
366 >      if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
367 >        clog << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
368 >        exit(0);
369 >      }
370 >      tempCut.numSubcuts = (cutStringVector.size()+1)/4;
371 >      for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
372 >        int indexOffset = 4 * subcutIndex;
373 >        string currentVariableString = cutStringVector.at(indexOffset);
374 >        if(currentVariableString.find("(")==string::npos){
375 >          tempCut.functions.push_back("");//no function was specified
376 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
377 >        }
378 >        else{
379 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
380 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
381 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
382 >        }
383 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
384 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
385 >        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
386 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
387 >      }
388  
389        //get number of objects required to pass cut for event to pass
390        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
391 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
391 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
392 >      if(numberRequiredVector.size()!=2){
393 >        clog << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
394 >        exit(0);
395 >      }
396  
130      // determine number required if comparison contains "="
397        int numberRequiredInt = atoi(numberRequiredVector.at(1).c_str());
132      if(numberRequiredVector.at(0) == ">") numberRequiredInt++;
133      else if(numberRequiredVector.at(0) == "<") numberRequiredInt--;
134
398        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
399        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
400  
401 <      if(cuts_.at(currentCut).exists("function")){
402 <        tempCut.function = cuts_.at(currentCut).getParameter<string> ("function");
140 <      }
141 <      else tempCut.function = "";
401 >      //Set up vectors to store the directories and subDirectories for each channel.
402 >      string subSubDirName;
403        string tempCutName;
404        if(cuts_.at(currentCut).exists("alias")){
405          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
406 +        subSubDirName = "After " + tempCutName + " Cut Applied";
407        }
408        else{
409          //construct string for cutflow table
410          bool plural = numberRequiredInt != 1;
411 <        string collectionString = plural ? inputCollection : inputCollection.substr(0, inputCollection.size()-1);
411 >        string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
412          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
413          tempCutName = cutName;
414 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
415        }
153      tempCut.name = tempCutName;
416  
417 +      tempCut.isVeto = false;
418 +      if(cuts_.at(currentCut).exists("isVeto")){
419 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
420 +        if (isVeto == true) tempCut.isVeto = true;
421 +      }
422 +      subSubDirNames.push_back(subSubDirName);
423 +      tempCut.name = tempCutName;
424 +      if (verbose_) clog << "Setting up cut, index: " << currentCut << ", input collection: " << tempInputCollection<< ", name: " << tempCut.name << endl;  
425  
426        tempChannel.cuts.push_back(tempCut);
427  
428  
429      }//end loop over cuts
430  
431 <    //make unique vector of all objects that this channel cuts on (so we know to set flags for those)
432 <    sort( tempInputCollections.begin(), tempInputCollections.end() );
433 <    tempInputCollections.erase( unique( tempInputCollections.begin(), tempInputCollections.end() ), tempInputCollections.end() );
434 <    tempChannel.inputCollections = tempInputCollections;
431 >    vector<map<string, TH1D*>> oneDHistsTmp;
432 >    vector<map<string, TH2D*>> twoDHistsTmp;
433 >    //book a directory in the output file with the name of the channel
434 >    TFileDirectory subDir = fs_->mkdir( channelName );
435 >    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
436 >    if(GetPlotsAfterEachCut_){
437 >      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
438 >        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
439 >        directories.push_back(subSubDir);
440 >        map<string, TH1D*> oneDhistoMap;
441 >        oneDHistsTmp.push_back(oneDhistoMap);
442 >        map<string, TH2D*> twoDhistoMap;
443 >        twoDHistsTmp.push_back(twoDhistoMap);
444 >      }
445 >      treeDirectories.push_back(subDir);
446 >      oneDHists_.push_back(oneDHistsTmp);
447 >      twoDHists_.push_back(twoDHistsTmp);
448 >    }
449 >    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
450 >    else{
451 >      map<string, TH1D*> oneDhistoMap;
452 >      oneDHistsTmp.push_back(oneDhistoMap);
453 >      map<string, TH2D*> twoDhistoMap;
454 >      twoDHistsTmp.push_back(twoDhistoMap);
455 >      oneDHists_.push_back(oneDHistsTmp);
456 >      twoDHists_.push_back(twoDHistsTmp);
457 >      directories.push_back(subDir);
458 >      treeDirectories.push_back(subDir);
459 >
460 >    }
461 >
462 >    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
463 >      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
464 >      BNTrees_.push_back(newTree);
465 >      BNTrees_.back()->Branch("event_runInt",  &BNTreeBranchVals_runInt_,  "event_runInt/I");      
466 >      BNTrees_.back()->Branch("event_lumiInt", &BNTreeBranchVals_lumiInt_, "event_lumiInt/I");      
467 >      BNTrees_.back()->Branch("event_evtLong", &BNTreeBranchVals_evtLong_, "event_evtLong/L");      
468 >      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
469 >        BranchSpecs currentVar = treeBranches_.at(iBranch);
470 >        vector<float> newVec;
471 >        BNTreeBranchVals_[currentVar.name] = newVec;
472 >        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
473 >      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
474 >    }
475 >
476 >    //book all histograms included in the configuration
477 >    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
478 >
479 >      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
480 >
481 >        histogram currentHistogram = histograms.at(currentHistogramIndex);
482 >        int numBinsElements = currentHistogram.bins.size();
483 >        int numInputVariables = currentHistogram.inputVariables.size();
484 >        int numBinEdgesX = currentHistogram.variableBinsX.size();
485 >        int numBinEdgesY = currentHistogram.variableBinsY.size();
486 >
487 >        if(numBinsElements == 1){
488 >          if(numBinEdgesX > 1){
489 >            if(numBinEdgesY > 1)
490 >              numBinsElements = 6;
491 >            else
492 >              numBinsElements = 3;
493 >          }
494 >        }
495 >        if(numBinsElements != 3 && numBinsElements !=6){
496 >          clog << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
497 >          exit(0);
498 >        }
499 >        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
500 >          clog << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
501 >          exit(0);
502 >        }
503 >        else if(numBinsElements == 3){
504 >          if (currentHistogram.bins.size () == 3)
505 >            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));
506 >          else
507 >            {
508 >              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
509 >            }
510 >        }
511 >        else if(numBinsElements == 6){
512 >          if (currentHistogram.bins.size () == 6)
513 >            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));
514 >          else
515 >            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 ());
516 >        }
517 >
518 >
519 >        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
520  
521 +        // bin      particle type
522 +        // ---      -------------
523 +        //  0        unmatched
524 +        //  1        u
525 +        //  2        d
526 +        //  3        s
527 +        //  4        c
528 +        //  5        b
529 +        //  6        t
530 +        //  7        e
531 +        //  8        mu
532 +        //  9        tau
533 +        // 10        nu
534 +        // 11        g
535 +        // 12        gamma
536 +        // 13        Z
537 +        // 14        W
538 +        // 15        light meson
539 +        // 16        K meson
540 +        // 17        D meson
541 +        // 18        B meson
542 +        // 19        light baryon
543 +        // 20        strange baryon
544 +        // 21        charm baryon
545 +        // 22        bottom baryon
546 +        // 23        QCD string
547 +        // 24        other
548 +
549 +        vector<TString> labelArray;
550 +        labelArray.push_back("unmatched");
551 +        labelArray.push_back("u");
552 +        labelArray.push_back("d");
553 +        labelArray.push_back("s");
554 +        labelArray.push_back("c");
555 +        labelArray.push_back("b");
556 +        labelArray.push_back("t");
557 +        labelArray.push_back("e");
558 +        labelArray.push_back("#mu");
559 +        labelArray.push_back("#tau");
560 +        labelArray.push_back("#nu");
561 +        labelArray.push_back("g");
562 +        labelArray.push_back("#gamma");
563 +        labelArray.push_back("Z");
564 +        labelArray.push_back("W");
565 +        labelArray.push_back("light meson");
566 +        labelArray.push_back("K meson");
567 +        labelArray.push_back("D meson");
568 +        labelArray.push_back("B meson");
569 +        labelArray.push_back("light baryon");
570 +        labelArray.push_back("strange baryon");
571 +        labelArray.push_back("charm baryon");
572 +        labelArray.push_back("bottom baryon");
573 +        labelArray.push_back("QCD string");
574 +        labelArray.push_back("other");
575 +
576 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
577 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
578 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
579 +          }
580 +          else {
581 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
582 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
583 +          }
584 +        }
585 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
586 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
587 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
588 +        }
589 +
590 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
591 +
592 +
593 +      // Book a histogram for the number of each object type to be plotted.
594 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
595 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
596 +        string currentObject = objectsToPlot.at(currentObjectIndex);
597 +        int maxNum = 10;
598 +        if(currentObject == "mcparticles") maxNum = 50;
599 +        else if(currentObject == "primaryvertexs") maxNum = 50;
600 +
601 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
602 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
603 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
604 +        else if(currentObject == "electron-photon pairs")     currentObject = "electronPhotonPairs";
605 +        else if(currentObject == "muon-photon pairs")         currentObject = "muonPhotonPairs";
606 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
607 +        else if(currentObject == "secondary photons")            currentObject = "secondaryPhotons";
608 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
609 +        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
610 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
611 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
612 +        else if(currentObject == "muon-event pairs")            currentObject = "muonEventPairs";
613 +        else if(currentObject == "photon-jet pairs")            currentObject = "photonJetPairs";
614 +        else if(currentObject == "met-jet pairs")             currentObject = "metJetPairs";
615 +        else if(currentObject == "track-jet pairs")           currentObject = "trackJetPairs";
616 +        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
617 +        else if(currentObject == "muon-secondary photon pairs")  currentObject = "muonSecondaryPhotonPairs";
618 +        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
619 +        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
620 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
621 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
622 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
623 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
624 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
625 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
626 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
627 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
628 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
629 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
630 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
631 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
632 +        else if(currentObject == "electron-mcparticle pairs")   currentObject = "electronMCparticlePairs";
633 +
634 +
635 +        currentObject.at(0) = toupper(currentObject.at(0));
636 +        string histoName = "num" + currentObject;
637 +
638 +        if(histoName == "numPrimaryvertexs"){
639 +          string newHistoName = histoName + "BeforePileupCorrection";
640 +          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);
641 +          newHistoName = histoName + "AfterPileupCorrection";
642 +          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);
643 +        }
644 +        else
645 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
646 +      }
647 +
648 +      if (verbose_) {
649 +        clog << "List of 1D histograms booked for channel " << channelName << " and directory " << currentDir << ":" << endl;
650 +        for(map<string, TH1D*>::iterator
651 +              iter = oneDHists_.at(currentChannel).at(currentDir).begin();
652 +            iter  != oneDHists_.at(currentChannel).at(currentDir).end();
653 +            iter++) {
654 +          clog << " " << iter->first
655 +               << ":  name=" << iter->second->GetName()
656 +               << ", title=" << iter->second->GetTitle()
657 +               << ", bins=(" << iter->second->GetNbinsX()
658 +               << "," << iter->second->GetXaxis()->GetXmin()
659 +               << "," << iter->second->GetXaxis()->GetXmax()
660 +               << ")" << endl;
661 +        }  
662 +        clog << "List of 2D histograms booked for channel " << channelName << " and directory " << currentDir << ":" << endl;
663 +        for(map<string, TH2D*>::iterator
664 +              iter = twoDHists_.at(currentChannel).at(currentDir).begin();
665 +            iter  != twoDHists_.at(currentChannel).at(currentDir).end();
666 +            iter++) {
667 +          clog << " " << iter->first
668 +               << ":  name=" << iter->second->GetName()
669 +               << ", title=" << iter->second->GetTitle()
670 +               << ", binsX=(" << iter->second->GetNbinsX()
671 +               << "," << iter->second->GetXaxis()->GetXmin()
672 +               << "," << iter->second->GetXaxis()->GetXmax()
673 +               << ")"
674 +               << ", binsY=(" << iter->second->GetNbinsY()
675 +               << "," << iter->second->GetYaxis()->GetXmin()
676 +               << "," << iter->second->GetYaxis()->GetXmax()
677 +               << ")"
678 +               << endl;
679 +        }  
680 +      }
681 +
682 +    }//end of loop over directories
683      channels.push_back(tempChannel);
684      tempChannel.cuts.clear();
168
685    }//end loop over channels
686  
171  //make unique vector of objects we need to cut on (so we make sure to get them from the event)
172  sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
173  allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
687  
688 +  // Create the cutflow histogram and fill with 0 weight, in case no events are found in the input file.  
689 +  for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
690 +    channel currentChannel = channels.at(currentChannelIndex);
691 +    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
692 +      cutFlows_.at(currentChannelIndex)->at("trigger") = true;  
693 +    }
694 +    for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
695 +      cut currentCut = currentChannel.cuts.at(currentCutIndex);
696 +      cutFlows_.at(currentChannelIndex)->at (currentCut.name) = true;
697 +    }
698 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(0);  // fill cutflow with 0 weight, just to create the cutflow histograms  
699 +  }
700 +
701 +  //make unique vector of objects we need to get from the event
702 +  sort( objectsToGet.begin(), objectsToGet.end() );
703 +  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
704 +  //make unique vector of objects we need to cut on
705 +  sort( objectsToCut.begin(), objectsToCut.end() );
706 +  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
707 +  //make unique vector of objects we need to set flags for
708 +  sort( objectsToFlag.begin(), objectsToFlag.end() );
709 +  objectsToFlag.erase( unique( objectsToFlag.begin(), objectsToFlag.end() ), objectsToFlag.end() );
710 +
711 +  // Move all paired objects to the end of the list, so that the flags for single objects are always set before those of paired objects.  
712 +  for (uint i=0; i<objectsToFlag.size(); i++) {
713 +    if (objectsToFlag.at(i).find("pairs")!=string::npos) { // if it contains "pairs"
714 +      objectsToFlag.push_back(objectsToFlag.at(i));  
715 +      objectsToFlag.erase(objectsToFlag.begin()+i);  
716 +    }
717 +  }
718 +
719 +  if (verbose_) {
720 +    clog << "List of channels:" << endl;
721 +    for (uint i=0; i<channels.size(); i++) {
722 +      clog << " " << channels.at(i).name << endl;
723 +    }
724 +    clog << "List of objects to get:" << endl;
725 +    for (uint i=0; i<objectsToGet.size(); i++) {
726 +      clog << " " << objectsToGet.at(i) << endl;
727 +    }
728 +    clog << "List of objects to plot:" << endl;
729 +    for (uint i=0; i<objectsToPlot.size(); i++) {
730 +      clog << " " << objectsToPlot.at(i) << endl;
731 +    }
732 +    clog << "List of objects to cut:" << endl;
733 +    for (uint i=0; i<objectsToCut.size(); i++) {
734 +      clog << " " << objectsToCut.at(i) << endl;
735 +    }
736 +    clog << "List of objects to flag:" << endl;
737 +    for (uint i=0; i<objectsToFlag.size(); i++) {
738 +      clog << " " << objectsToFlag.at(i) << endl;
739 +    }
740 +  }
741 +
742 +  produces<map<string, bool> > ("channelDecisions");
743 +
744 +  if (printEventInfo_) {
745 +    findEventsLog = new ofstream();  
746 +    findEventsLog->open("findEvents.txt");  
747 +    clog << "Listing run:lumi:event in file findEvents.txt for events that pass full selection (of any channel)." << endl;  
748 +  } else {
749 +    findEventsLog = 0;
750 +  }  
751 +
752 +  isFirstEvent_ = true;  
753 +
754 +  if (verbose_) clog << "Finished OSUAnalysis::OSUAnalysis constructor." << endl;  
755 +
756 +
757 +  } // end constructor OSUAnalysis::OSUAnalysis()
758  
176 }
759  
760   OSUAnalysis::~OSUAnalysis ()
761   {
762 +
763 +  if (verbose_) clog << "Beginning OSUAnalysis::OSUAnalysis destructor." << endl;  
764 +
765    // Destroying the CutFlow objects causes the cut flow numbers and time
766    // information to be printed to standard output.
767    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
768      delete cutFlows_.at(currentChannel);
769    }
770 +
771 +  if (printEventInfo_ && findEventsLog) findEventsLog->close();  
772 +
773 +  clog << "=============================================" << endl;  
774 +  clog << "Successfully completed OSUAnalysis." << endl;  
775 +  clog << "=============================================" << endl;  
776 +
777 +  if (verbose_) clog << "Finished OSUAnalysis::OSUAnalysis destructor." << endl;  
778 +
779   }
780  
781   void
782 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
782 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
783   {
784 +  // Retrieve necessary collections from the event.
785  
786 +  if (verbose_) clog << "Beginning OSUAnalysis::produce." << endl;  
787  
788 <  // Retrieve necessary collections from the event.
193 <  edm::Handle<BNtriggerCollection> triggers;
194 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
788 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end()) {
789      event.getByLabel (triggers_, triggers);
790 +    if (!triggers.product()) cout << "ERROR:  could not get triggers input collection" << endl;  
791 +  }
792  
793 <  edm::Handle<BNjetCollection> jets;
794 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())
793 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end()) {
794 >    event.getByLabel (trigobjs_, trigobjs);
795 >    if (!trigobjs.product()) cout << "ERROR:  could not get trigobjs input collection" << endl;  
796 >  }
797 >
798 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end()) {
799      event.getByLabel (jets_, jets);
800 +    if (!jets.product()) cout << "ERROR:  could not get jets input collection" << endl;  
801 +  }
802  
803 <  edm::Handle<BNmuonCollection> muons;
202 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())
803 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end()) {
804      event.getByLabel (muons_, muons);
805 +    if (!muons.product()) cout << "ERROR:  could not get muons input collection" << endl;  
806 +  }
807  
808 <  edm::Handle<BNelectronCollection> electrons;
809 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())
808 >  if (find(objectsToGet.begin(), objectsToGet.end(), "secondary muons") != objectsToGet.end()) {
809 >    event.getByLabel (secMuons_, secMuons);
810 >    if (!secMuons.product()) cout << "ERROR:  could not get secMuons input collection" << endl;  
811 >  }
812 >
813 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end()) {
814      event.getByLabel (electrons_, electrons);
815 +    if (!electrons.product()) cout << "ERROR:  could not get electrons input collection" << endl;  
816 +  }
817  
818 <  edm::Handle<BNeventCollection> events;
210 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())
818 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end()) {
819      event.getByLabel (events_, events);
820 +    if (!events.product()) cout << "ERROR:  could not get events input collection" << endl;  
821 +  }
822  
823 <  edm::Handle<BNtauCollection> taus;
214 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())
823 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end()) {
824      event.getByLabel (taus_, taus);
825 +    if (!taus.product()) cout << "ERROR:  could not get taus input collection" << endl;  
826 +  }
827  
828 <  edm::Handle<BNmetCollection> mets;
218 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())
828 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end()) {
829      event.getByLabel (mets_, mets);
830 +    if (!mets.product()) cout << "ERROR:  could not get mets input collection" << endl;  
831 +  }
832  
833 <  edm::Handle<BNtrackCollection> tracks;
222 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())
833 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end()) {
834      event.getByLabel (tracks_, tracks);
835 +    if (!tracks.product()) cout << "ERROR:  could not get tracks input collection" << endl;  
836 +  }
837  
838 <  edm::Handle<BNgenjetCollection> genjets;
226 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())
838 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end()) {
839      event.getByLabel (genjets_, genjets);
840 +    if (!genjets.product()) cout << "ERROR:  could not get genjets input collection" << endl;  
841 +  }
842  
843 <  edm::Handle<BNmcparticleCollection> mcparticles;
230 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())
843 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end()) {
844      event.getByLabel (mcparticles_, mcparticles);
845 +    if (!mcparticles.product()) cout << "ERROR:  could not get mcparticles input collection" << endl;  
846 +  }
847  
848 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
234 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())
848 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end()) {
849      event.getByLabel (primaryvertexs_, primaryvertexs);
850 +    if (!primaryvertexs.product()) cout << "ERROR:  could not get primaryvertexs input collection" << endl;  
851 +  }
852  
853 <  edm::Handle<BNbxlumiCollection> bxlumis;
238 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())
853 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end()) {
854      event.getByLabel (bxlumis_, bxlumis);
855 +    if (!bxlumis.product()) cout << "ERROR:  could not get bxlumis input collection" << endl;  
856 +  }
857  
858 <  edm::Handle<BNphotonCollection> photons;
242 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())
858 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end()) {
859      event.getByLabel (photons_, photons);
860 +    if (!photons.product()) cout << "ERROR:  could not get photons input collection" << endl;  
861 +  }
862  
863 <  edm::Handle<BNsuperclusterCollection> superclusters;
246 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())
863 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end()) {
864      event.getByLabel (superclusters_, superclusters);
865 +    if (!superclusters.product()) cout << "ERROR:  could not get superclusters input collection" << endl;  
866 +  }
867  
868 +  if (datasetType_ == "signalMC"){
869 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end()) {
870 +      event.getByLabel (stops_, stops);
871 +      if (!stops.product()) cout << "ERROR:  could not get stops input collection" << endl;  
872 +    }
873 +  }
874 +
875 +  if (useTrackCaloRhoCorr_) {
876 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
877 +    // This rho collection is not available in all BEANs.
878 +    // For description of rho values for different jet reconstruction algorithms, see
879 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
880 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
881 +    if (!rhokt6CaloJetsHandle_.product()) cout << "ERROR:  could not get kt6CaloJets input collection" << endl;  
882 +  }
883 +
884 +  double masterScaleFactor = 1.0;
885 +
886 +  //get pile-up event weight
887 +  if (doPileupReweighting_ && datasetType_ != "data") {
888 +    //for "data" datasets, the numTruePV is always set to -1
889 +    if (events->at(0).numTruePV < 0 && isFirstEvent_) clog << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
890 +    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
891 +  }
892 +
893 +  stopCTauScaleFactor_ = 1.0;
894 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
895 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
896 +  masterScaleFactor *= stopCTauScaleFactor_;
897  
898    //loop over all channels
899  
900 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
901    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
902      channel currentChannel = channels.at(currentChannelIndex);
903 +    if (verbose_>1) clog << " Processing channel " << currentChannel.name << endl;
904  
905      flagMap individualFlags;
256    flagMap cumulativeFlags;
906      counterMap passingCounter;
907 +    cumulativeFlags.clear ();
908 +
909 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
910 +         iter != BNTreeBranchVals_.end(); iter++) {
911 +      iter->second.clear();  // clear array
912 +    }
913  
914      bool triggerDecision = true;
915 <    if(currentChannel.triggers.size() != 0){  //triggers specified
916 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
915 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
916 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
917        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
918      }
919  
920      //loop over all cuts
921      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
922        cut currentCut = currentChannel.cuts.at(currentCutIndex);
923 +      if (verbose_>2) clog << "  Processing cut, index: " << currentCutIndex << ", input collection: " << currentCut.inputCollection << ", name: " << currentCut.name << endl;  
924  
925 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
926 <
271 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
272 <        individualFlags[currentObject].push_back (vector<bool> ());
273 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
274 <
275 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
276 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
277 <        else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
278 <        else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
279 <        else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
280 <        else if(currentObject == "mets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
281 <        else if(currentObject == "tracks") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
282 <        else if(currentObject == "genjets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
283 <        else if(currentObject == "mcparticles") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
284 <        else if(currentObject == "primaryvertexs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
285 <        else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
286 <        else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
287 <        else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
925 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
926 >        string currentObject = objectsToFlag.at(currentObjectIndex);
927  
928 +        //initialize maps to get ready to set cuts
929 +        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
930 +        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
931  
932        }
933  
934 +      //set flags for all relevant objects
935 +      for(int currentObjectIndex = -1; currentObjectIndex != int(objectsToFlag.size()); currentObjectIndex++){
936 +        string currentObject;  
937 +        if (currentObjectIndex < 0) currentObject = currentCut.inputCollection;  // In the first loop, set the flags for the collection that the cut is acting on.  That way other paired collections can access the correct flag for the current cut.  
938 +        else currentObject = objectsToFlag.at(currentObjectIndex);
939 +        if (currentObjectIndex >= 0 && currentObject == currentCut.inputCollection) continue;  // Flags have already been set for the inputCollection object, so should not be set again.  
940 +
941 +        // single object collections
942 +        if     (currentObject == "jets")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
943 +        else if(currentObject == "secondary jets")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
944 +        else if(currentObject == "secondary photons")   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"secondary photons");
945 +        else if(currentObject == "muons")               setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
946 +        else if(currentObject == "secondary muons")     setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,secMuons.product(),"secondary muons");
947 +        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
948 +        else if(currentObject == "electrons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
949 +        else if(currentObject == "events")              setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
950 +        else if(currentObject == "taus")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
951 +        else if(currentObject == "mets")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
952 +        else if(currentObject == "tracks")              setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
953 +        else if(currentObject == "genjets")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
954 +        else if(currentObject == "mcparticles")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
955 +        else if(currentObject == "primaryvertexs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
956 +        else if(currentObject == "bxlumis")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
957 +        else if(currentObject == "photons")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
958 +        else if(currentObject == "superclusters")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
959 +        else if(currentObject == "trigobjs")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
960 +
961 +
962 +        // paired object collections  
963 +        else if(currentObject == "muon-muon pairs")                   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), "muon-muon pairs");
964 +        else if(currentObject == "muon-secondary muon pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),secMuons.product(), "muon-secondary muon pairs");
965 +
966 +        else if(currentObject == "muon-secondary photon pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), "muon-secondary photon pairs");
967 +        else if(currentObject == "muon-secondary jet pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), "muon-secondary jet pairs");
968 +        else if(currentObject == "photon-secondary jet pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), "photon-secondary jet pairs");
969 +        else if(currentObject == "electron-secondary jet pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), "electron-secondary jet pairs");
970 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), "electron-secondary electron pairs");
971 +
972 +        else if(currentObject == "electron-electron pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), "electron-electron pairs");
973 +        else if(currentObject == "electron-muon pairs")     setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), "electron-muon pairs");
974 +        else if(currentObject == "jet-jet pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), "jet-jet pairs");
975 +        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), "jet-secondary jet pairs");
976 +        else if(currentObject == "electron-jet pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), "electron-jet pairs");
977 +        else if(currentObject == "electron-photon pairs")   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), "electron-photon pairs");
978 +        else if(currentObject == "photon-jet pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), "photon-jet pairs");
979 +        else if(currentObject == "muon-jet pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), "muon-jet pairs");
980 +        else if(currentObject == "muon-event pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),events.product(), "muon-event pairs");
981 +        else if(currentObject == "met-jet pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),jets.product(), "met-jet pairs");
982 +        else if(currentObject == "track-jet pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),jets.product(), "track-jet pairs");
983 +        else if(currentObject == "muon-photon pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), "muon-photon pairs");
984 +        else if(currentObject == "track-event pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(), "track-event pairs");
985 +        else if(currentObject == "electron-track pairs")    setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),"electron-track pairs");
986 +        else if(currentObject == "muon-track pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),"muon-track pairs");
987 +        else if(currentObject == "muon-tau pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),"muon-tau pairs");
988 +        else if(currentObject == "tau-tau pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),"tau-tau pairs");
989 +        else if(currentObject == "tau-track pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),"tau-track pairs");
990 +        else if(currentObject == "electron-trigobj pairs")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),"electron-trigobj pairs");
991 +        else if(currentObject == "muon-trigobj pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),"muon-trigobj pairs");
992 +        else if(currentObject == "electron-mcparticle pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),mcparticles.product(),"electron-mcparticle pairs");
993  
994 +        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
995 +      }
996  
997      }//end loop over all cuts
998  
999  
1000  
298
1001      //use cumulative flags to apply cuts at event level
1002 <
1002 >    vector<bool> eventPassedPreviousCuts;    //a vector to store cumulative cut descisions after each cut.
1003      bool eventPassedAllCuts = true;
1004 <
303 <    //apply trigger (true if none were specified)
304 <    eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
305 <
1004 >    eventPassedAllCuts = eventPassedAllCuts && triggerDecision;    //apply trigger (true if none were specified)
1005  
1006      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
1007  
1008        //loop over all objects and count how many passed the cumulative selection up to this point
1009        cut currentCut = currentChannel.cuts.at(currentCutIndex);
1010        int numberPassing = 0;
1011 +      int numberPassingPrev = 0;  // number of objects that pass cuts up to the previous one
1012  
1013 <      for (uint object = 0; object != cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).size() ; object++)
1014 <          if(cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).at(object)) numberPassing++;
1015 <
1013 >      for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
1014 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
1015 >      }
1016 >      bool cutDecision;
1017 >      if (!currentCut.isVeto) {
1018 >        cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
1019 >      } else {
1020 >        int prevCutIndex = currentCutIndex - 1;
1021 >        if (prevCutIndex<0) {
1022 >          numberPassingPrev = cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size();  // count all objects in collection if cut is the first
1023 >        } else {
1024 >          for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(prevCutIndex).size() ; object++){
1025 >            if (cumulativeFlags.at(currentCut.inputCollection).at(prevCutIndex).at(object).first) {
1026 >              numberPassingPrev++;
1027 >              if (verbose_>1) clog << " object passed previous cut" << endl;  
1028 >            }
1029 >          }  
1030 >        }  
1031 >        int numberFailCut = numberPassingPrev - numberPassing;
1032 >        cutDecision = evaluateComparison(numberFailCut,currentCut.eventComparativeOperator,currentCut.numberRequired);  
1033 >      }
1034  
317      bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
1035        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
319
1036        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
1037 +      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
1038 +      if (verbose_>1) clog << " Event passed cuts up to cut index " << currentCutIndex << endl;  
1039 +
1040 +    }
1041 +    //applying all appropriate scale factors
1042 +    double scaleFactor = masterScaleFactor;
1043 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
1044 +
1045 +    if(applyLeptonSF_ && datasetType_ != "data"){
1046 +      //only apply SFs if we've cut on this object
1047 +      if(find(objectsToCut.begin(),objectsToCut.end(),"muons") != objectsToCut.end ()){
1048 +        flagPair muonFlags;
1049 +        //get the last valid flags in the flag map
1050 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
1051 +          if (cumulativeFlags.at("muons").at(i).size()){
1052 +            muonFlags = cumulativeFlags.at("muons").at(i);
1053 +            break;
1054 +          }
1055 +        }
1056 +        //apply the weight for each of those objects
1057 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
1058 +          if(!muonFlags.at(muonIndex).second) continue;
1059 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
1060 +        }
1061 +      }
1062 +      //only apply SFs if we've cut on this object
1063 +      if(find(objectsToCut.begin(),objectsToCut.end(),"electrons") != objectsToCut.end ()){
1064 +        flagPair electronFlags;
1065 +        //get the last valid flags in the flag map
1066 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
1067 +          if (cumulativeFlags.at("electrons").at(i).size()){
1068 +            electronFlags = cumulativeFlags.at("electrons").at(i);
1069 +            break;
1070 +          }
1071 +        }
1072 +        //apply the weight for each of those objects
1073 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
1074 +          if(!electronFlags.at(electronIndex).second) continue;
1075 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
1076 +        }
1077 +      }
1078 +    }
1079 +    if(applyBtagSF_ && datasetType_ != "data"){
1080 +      //only apply SFs if we've cut on this object
1081 +      if(find(objectsToCut.begin(),objectsToCut.end(),"jets") != objectsToCut.end ()){
1082 +        flagPair jetFlags;
1083 +        vector<double> jetSFs;
1084 +        //get the last valid flags in the flag map
1085 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
1086 +          if (cumulativeFlags.at("jets").at(i).size()){
1087 +            jetFlags = cumulativeFlags.at("jets").at(i);
1088 +            break;
1089 +          }
1090 +        }
1091 +        //apply the weight for each of those objects
1092 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
1093 +          if(!jetFlags.at(jetIndex).second) continue;
1094 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour, jets->at(jetIndex).eta);
1095 +          jetSFs.push_back(jetSFTmp);
1096 +        }
1097 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_);
1098 +      }
1099 +    }
1100 +    scaleFactor *= muonScaleFactor_;
1101 +    scaleFactor *= electronScaleFactor_;
1102 +    scaleFactor *= bTagScaleFactor_;
1103 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
1104 +    if (verbose_>1) clog << " Scale factors applied:  "
1105 +                         << " muonScaleFactor_ = " << muonScaleFactor_
1106 +                         << ", electronScaleFactor_ = " << electronScaleFactor_
1107 +                         << ", bTagScaleFactor_ = " << bTagScaleFactor_
1108 +                         << ", total scale factor = " << scaleFactor
1109 +                         << endl;  
1110 +
1111 +
1112 +    if (printEventInfo_ && eventPassedAllCuts) {
1113 +      // Write information about event to screen, for testing purposes.
1114 +      clog << "Event passed all cuts in channel " <<  currentChannel.name
1115 +           << ":  run:lumi:evt=  "  << events->at(0).run
1116 +           << ":" << events->at(0).lumi
1117 +           << ":" << events->at(0).evt
1118 +           << endl;
1119 +      if (findEventsLog) {
1120 +        (*findEventsLog) << events->at(0).run
1121 +                         << ":" << events->at(0).lumi
1122 +                         << ":" << events->at(0).evt << endl;
1123 +      }
1124  
1125      }
1126  
324    cutFlows_.at(currentChannelIndex)->fillCutFlow();
1127  
1128 +    //filling histograms
1129 +    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the cuts in each channel; if GetPlotsAfterEachCut_ is false, only the last cut will be used.
1130  
1131 +      if (verbose_>2) clog << "  Filling histograms for currentcut = " << currentCut << endl;  
1132  
1133 <    if(!eventPassedAllCuts)continue;
1133 >      uint currentDir;
1134 >      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
1135 >      else{
1136 >        currentDir = currentCut;
1137 >      }
1138  
1139  
1140 <    TVector3 vertexPosition;
332 <    vector<bool> vertexFlags = cumulativeFlags["primaryvertexs"].back();
1140 >      if(eventPassedPreviousCuts.at(currentDir)){
1141  
1142 <    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
1143 <      if(!vertexFlags.at(vertexIndex)) continue;
1142 >        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1143 >          histogram currentHistogram = histograms.at(histogramIndex);
1144  
1145 <      vertexPosition.SetXYZ (primaryvertexs->at(vertexIndex).x,primaryvertexs->at(vertexIndex).y,primaryvertexs->at(vertexIndex).z);
338 <      break;
339 <    }
1145 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) clog << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
1146  
1147 <    vector<bool> mcparticleFlags = cumulativeFlags["mcparticles"].back();
1147 >          if (verbose_>1) clog << " Filling histogram " << currentHistogram.name << " for collection " << currentHistogram.inputCollection << endl;  
1148  
1149 <    for (uint mcparticleIndex = 0; mcparticleIndex != mcparticleFlags.size(); mcparticleIndex++){
1150 <      if(!mcparticleFlags.at(mcparticleIndex)) continue;
1149 >          if(currentHistogram.inputVariables.size() == 1){
1150 >            TH1D* histo;
1151 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1152 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1153 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1154 >            else if(currentHistogram.inputCollection == "secondary photons")  fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1155 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1156 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,secMuons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1157 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1158 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1159 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1160 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),secMuons.product(),
1161 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1162 >             else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1163 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1164 >             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1165 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1166 >             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1167 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1168 >             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1169 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1170 >
1171 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1172 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1173 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1174 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1175 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1176 >             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1177 >                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1178 >
1179 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1180 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1181 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(),
1182 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1183 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(),
1184 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1185 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(),
1186 >                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1187 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(),
1188 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1189 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill1DHistogram(histo,currentHistogram, muons.product(),events.product(),
1190 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1191 >            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, mets.product(),jets.product(),
1192 >                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1193 >            else if(currentHistogram.inputCollection == "track-jet pairs")  fill1DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1194 >                                                                                          cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1195 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(),
1196 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1197 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(),
1198 >                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1199 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1200 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1201 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1202 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1203 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1204 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1205 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1206 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1207 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1208 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1209 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1210 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1211 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1212 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1213 >
1214 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1215 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1216 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1217 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1218 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1219 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1220 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1221 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1222 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1223 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1224 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1225 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1226 >          }
1227 >          else if(currentHistogram.inputVariables.size() == 2){
1228 >            TH2D* histo;
1229 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1230 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1231 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1232 >            else if(currentHistogram.inputCollection == "secondary photons")  fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1233 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1234 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,secMuons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1235 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1236 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1237 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),secMuons.product(),
1238 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1239 >            else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1240 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1241 >            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1242 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1243 >            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1244 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1245 >            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1246 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1247 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1248 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1249 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1250 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1251 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1252 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1253 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1254 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1255 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(),
1256 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1257 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1258 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1259 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(),
1260 >                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1261 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1262 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1263 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill2DHistogram(histo,currentHistogram,muons.product(),events.product(),
1264 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1265 >            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,mets.product(),jets.product(),
1266 >                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1267 >            else if(currentHistogram.inputCollection == "track-jet pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1268 >                                                                                         cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1269 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1270 >                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1271 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1272 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1273 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1274 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1275 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1276 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1277 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1278 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1279 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1280 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1281 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1282 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1283 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1284 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1285 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1286 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1287 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1288 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1289 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1290 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1291 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1292 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1293 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1294 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1295 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1296 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1297 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1298 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1299 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1300 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1301 >          }
1302  
1303 <      double vx = mcparticles->at(mcparticleIndex).vx - vertexPosition.X (),
347 <             vy = mcparticles->at(mcparticleIndex).vy - vertexPosition.Y (),
348 <             vz = mcparticles->at(mcparticleIndex).vz - vertexPosition.Z (),
349 <             px = mcparticles->at(mcparticleIndex).px,
350 <             py = mcparticles->at(mcparticleIndex).py,
351 <             pt = mcparticles->at(mcparticleIndex).pt,
352 <             d0;
353 <
354 <      d0 = (-vx * py + vy * px) / pt;
355 <      oneDHists_.at(currentChannelIndex)["genD0"]->Fill (d0);
356 <      oneDHists_.at(currentChannelIndex)["genAbsD0"]->Fill (fabs (d0));
357 <      oneDHists_.at(currentChannelIndex)["genDZ"]->Fill (vz);
358 <      oneDHists_.at(currentChannelIndex)["genAbsDZ"]->Fill (fabs (vz));
359 <    }
1303 >        }
1304  
361    vector<bool> electronFlags = cumulativeFlags["electrons"].back();
362    int electronCounter = 0;
1305  
1306 <    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
1307 <      if(!electronFlags.at(electronIndex)) continue;
1306 >        //fills histograms with the sizes of collections
1307 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1308  
1309 +          string currentObject = objectsToPlot.at(currentObjectIndex);
1310 +          string objectToPlot = "";
1311  
1312 <      electronCounter++;
369 <      oneDHists_.at(currentChannelIndex)["electronPt"]->Fill (electrons->at(electronIndex).pt);
370 <      oneDHists_.at(currentChannelIndex)["electronEta"]->Fill (electrons->at(electronIndex).eta);
371 <      oneDHists_.at(currentChannelIndex)["electronD0"]->Fill (electrons->at(electronIndex).correctedD0Vertex);
372 <      oneDHists_.at(currentChannelIndex)["electronDz"]->Fill (electrons->at(electronIndex).correctedDZ);
373 <      oneDHists_.at(currentChannelIndex)["electronAbsD0"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex));
374 <      oneDHists_.at(currentChannelIndex)["electronDZ"]->Fill (electrons->at(electronIndex).correctedDZ);
375 <      oneDHists_.at(currentChannelIndex)["electronAbsDZ"]->Fill (fabs(electrons->at(electronIndex).correctedDZ));
376 <      oneDHists_.at(currentChannelIndex)["electronD0Sig"]->Fill (electrons->at(electronIndex).correctedD0Vertex / electrons->at(electronIndex).tkD0err);
377 <      oneDHists_.at(currentChannelIndex)["electronAbsD0Sig"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex) / electrons->at(electronIndex).tkD0err);
378 <      oneDHists_.at(currentChannelIndex)["electronIso"]->Fill (electrons->at(electronIndex).puChargedHadronIso / electrons->at(electronIndex).pt);
379 <      oneDHists_.at(currentChannelIndex)["electronFbrem"]->Fill (electrons->at(electronIndex).fbrem);
380 <      oneDHists_.at(currentChannelIndex)["electronMVATrig"]->Fill (electrons->at(electronIndex).mvaTrigV0);
381 <      oneDHists_.at(currentChannelIndex)["electronMVANonTrig"]->Fill (electrons->at(electronIndex).mvaNonTrigV0);
1312 >          if (verbose_) clog << "Filling histogram of number of selected objects in collection: " << currentObject << endl;  
1313  
1314 <    }
1315 <    oneDHists_.at(currentChannelIndex)["numElectrons"]->Fill (electronCounter);
1314 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1315 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1316 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1317 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1318 >          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1319 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1320 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1321 >          else if(currentObject == "muon-event pairs")                   objectToPlot = "muonEventPairs";
1322 >          else if(currentObject == "muon-photon pairs")                  objectToPlot = "muonPhotonPairs";
1323 >          else if(currentObject == "photon-jet pairs")                   objectToPlot = "photonJetPairs";
1324 >          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1325 >          else if(currentObject == "track-jet pairs")                    objectToPlot = "trackJetPairs";
1326 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1327 >          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1328 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1329 >          else if(currentObject == "secondary photons")                  objectToPlot = "secondaryPhotons";
1330 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1331 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1332 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1333 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1334 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1335 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1336 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1337 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1338 >          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1339 >          else if(currentObject == "muon-secondary photon pairs")        objectToPlot = "muonSecondaryJetPairs";
1340 >          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1341 >          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1342 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1343 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1344 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1345 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1346 >          else if(currentObject == "electron-mcparticle pairs")          objectToPlot = "electronMCparticlePairs";
1347 >          else objectToPlot = currentObject;
1348 >
1349 >          string tempCurrentObject = objectToPlot;
1350 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1351 >          string histoName = "num" + tempCurrentObject;
1352 >
1353 >
1354 >          if(find(objectsToPlot.begin(), objectsToPlot.end(), currentObject) != objectsToPlot.end()) {
1355 >            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1356 >            int numToPlot = 0;
1357 >            for (uint iObj = 0; iObj != lastCutFlags.size(); iObj++){  // loop over all the objects  
1358 >              if(lastCutFlags.at(iObj).second) {
1359 >                numToPlot++;  
1360 >                if (verbose_>3) clog << "   Found object " << iObj << " in collection " << currentObject << " to plot." << endl;
1361 >              }
1362 >            }
1363 >
1364 >            if(objectToPlot == "primaryvertexs"){
1365 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1366 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1367 >            }
1368 >            else {
1369 >              if (printEventInfo_) clog << "Number of selected " << objectToPlot << " to plot:  " << numToPlot << endl;  
1370 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1371 >            }
1372 >          }
1373  
1374 +        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1375  
387    vector<bool> muonFlags = cumulativeFlags["muons"].back();
388    int muonCounter = 0;
1376  
1377 +      } // end if(eventPassedPreviousCuts.at(currentDir))
1378 +    } // end loop over cuts
1379  
1380 <    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
1381 <      if(!muonFlags.at(muonIndex)) continue;
1382 <      muonCounter++;
1380 >    if (!useEDMFormat_ && eventPassedAllCuts){
1381 >      // Assign BNTree variables
1382 >      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1383 >        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1384 >        string coll = brSpecs.inputCollection;
1385 >        if (cumulativeFlags.count(coll) == 0) clog << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1386 >
1387 >        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1388 >        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1389 >        else if(coll == "secondary photons")   assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1390 >        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1391 >        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,secMuons.product(),      cumulativeFlags.at(coll).back());
1392 >        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1393 >        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1394 >        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1395 >        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1396 >        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1397 >        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1398 >        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1399 >        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1400 >        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1401 >        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1402 >        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1403 >        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1404 >        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1405 >        else if(coll == "stops"
1406 >                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1407 >      } // end loop over branches
1408 >      // set the evtLong, runInt, and lumiInt variables separately, since they are not type float  
1409 >      BNTreeBranchVals_evtLong_ = events->at(0).evt;
1410 >      BNTreeBranchVals_runInt_  = events->at(0).run;
1411 >      BNTreeBranchVals_lumiInt_ = events->at(0).lumi;
1412  
1413 <      oneDHists_.at(currentChannelIndex)["muonPt"]->Fill (muons->at(muonIndex).pt);
1414 <      oneDHists_.at(currentChannelIndex)["muonEta"]->Fill (muons->at(muonIndex).eta);
397 <      oneDHists_.at(currentChannelIndex)["muonD0"]->Fill (muons->at(muonIndex).correctedD0Vertex);
398 <      oneDHists_.at(currentChannelIndex)["muonDz"]->Fill (muons->at(muonIndex).correctedDZ);
399 <      oneDHists_.at(currentChannelIndex)["muonAbsD0"]->Fill (fabs(muons->at(muonIndex).correctedD0Vertex));
400 <      oneDHists_.at(currentChannelIndex)["muonDZ"]->Fill (muons->at(muonIndex).correctedDZ);
401 <      oneDHists_.at(currentChannelIndex)["muonAbsDZ"]->Fill (fabs(muons->at(muonIndex).correctedDZ));
402 <      oneDHists_.at(currentChannelIndex)["muonD0Sig"]->Fill (muons->at(muonIndex).correctedD0Vertex / muons->at(muonIndex).tkD0err);
403 <      oneDHists_.at(currentChannelIndex)["muonAbsD0Sig"]->Fill (fabs(muons->at(muonIndex).correctedD0Vertex) / muons->at(muonIndex).tkD0err);
404 <      oneDHists_.at(currentChannelIndex)["muonIso"]->Fill (muons->at(muonIndex).puChargedHadronIso / muons->at(muonIndex).pt);
1413 >      if (!BNTrees_.at(currentChannelIndex)) { clog << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1414 >      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1415      }
406    oneDHists_.at(currentChannelIndex)["numMuons"]->Fill (muonCounter);
1416  
1417 +    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1418  
1419 +  } // end loop over channel
1420  
1421 +  masterCutFlow_->fillCutFlow(masterScaleFactor);
1422  
1423 +  event.put (channelDecisions, "channelDecisions");
1424  
1425 <  } //end loop over channel
1425 >  isFirstEvent_ = false;  
1426  
1427 <  masterCutFlow_->fillCutFlow();
1427 >  if (verbose_) clog << "Finished OSUAnalysis::produce." << endl;  
1428  
1429 + } // end void OSUAnalysis::produce (const edm::Event &event, const edm::EventSetup &setup)
1430  
417 }
1431  
1432  
1433   bool
# Line 426 | Line 1439 | OSUAnalysis::evaluateComparison (double
1439    else if(comparison == "<")  return testValue <  cutValue;
1440    else if(comparison == "<=") return testValue <= cutValue;
1441    else if(comparison == "==") return testValue == cutValue;
1442 +  else if(comparison == "=") return testValue == cutValue;
1443    else if(comparison == "!=") return testValue != cutValue;
1444 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1444 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1445  
1446   }
1447  
1448   bool
1449 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1449 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1450 >
1451  
1452 +  if(comparison == ">")       return testValue >  cutValue;
1453 +  else if(comparison == ">=") return testValue >= cutValue;
1454 +  else if(comparison == "<")  return testValue <  cutValue;
1455 +  else if(comparison == "<=") return testValue <= cutValue;
1456 +  else if(comparison == "==") return testValue == cutValue;
1457 +  else if(comparison == "=")  return testValue == cutValue;
1458 +  else if(comparison == "!=") return testValue != cutValue;
1459 +  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1460 +
1461 + }
1462 +
1463 + bool
1464 + OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1465 +
1466 +  //initialize to false until a chosen trigger is passed
1467    bool triggerDecision = false;
1468  
1469 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1470 <    {
1471 <      if(trigger->pass != 1) continue;
1472 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1473 <        {
1474 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1475 <            triggerDecision = true;
1476 <          }
1477 <        }
1469 >  if (printAllTriggers_) clog << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1470 >  //loop over all triggers defined in the event
1471 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1472 >
1473 >    if (printAllTriggers_) clog << "   " << trigger->name << endl;
1474 >
1475 >    //we're only interested in triggers that actually passed
1476 >    if(trigger->pass != 1) continue;
1477 >
1478 >    //if the event passes one of the veto triggers, exit and return false
1479 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1480 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1481      }
1482 <  return triggerDecision;
1482 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1483 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1484 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1485 >    }
1486 >  }
1487  
1488 +  printAllTriggers_ = false;  // only print triggers once, not every event
1489 +
1490 +  //if none of the veto triggers fired:
1491 +  //return the OR of all the chosen triggers
1492 +  if (triggersToTest.size() != 0) return triggerDecision;
1493 +  //or if no triggers were defined return true
1494 +  else return true;
1495   }
1496  
1497 < std::vector<std::string>
1497 >
1498 > vector<string>
1499   OSUAnalysis::splitString (string inputString){
1500  
1501 <  std::stringstream stringStream(inputString);
1502 <  std::istream_iterator<std::string> begin(stringStream);
1503 <  std::istream_iterator<std::string> end;
1504 <  std::vector<std::string> stringVector(begin, end);
1501 >  stringstream stringStream(inputString);
1502 >  istream_iterator<string> begin(stringStream);
1503 >  istream_iterator<string> end;
1504 >  vector<string> stringVector(begin, end);
1505    return stringVector;
1506  
1507   }
1508  
1509 +
1510 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1511 +  // Set two object strings from the tempInputCollection string,
1512 +  // For example, if tempInputCollection is "electron-muon pairs",
1513 +  // then obj1 = "electrons" and obj2 = "muons".
1514 +  // Note that the objects have an "s" appended.
1515 +
1516 +  int dashIndex = tempInputCollection.find("-");
1517 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1518 +  int secondWordLength = spaceIndex - dashIndex;
1519 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1520 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1521 +
1522 + }
1523 +
1524 +
1525 + string OSUAnalysis::getObjToGet(string obj) {
1526 +  // Return the string corresponding to the object to get for the given obj string.
1527 +  // Right now this only handles the case in which obj contains "secondary",
1528 +  // e.g, "secondary muons".
1529 +  // Note that "s" is NOT appended.
1530 +
1531 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1532 +  int firstSpaceIndex = obj.find_first_of(" ");
1533 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1534 +
1535 + }
1536 +
1537 +
1538 + //!jet valueLookup
1539   double
1540 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1540 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1541  
1542    double value = 0.0;
1543    if(variable == "energy") value = object->energy;
# Line 581 | Line 1656 | OSUAnalysis::valueLookup (const BNjet* o
1656    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1657    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1658  
1659 +  //user defined variable
1660 +  else if(variable == "disappTrkLeadingJetID") {
1661 +    value = object->pt > 110
1662 +      && fabs(object->eta) < 2.4
1663 +      && object->chargedHadronEnergyFraction > 0.2
1664 +      && object->neutralHadronEnergyFraction < 0.7
1665 +      && object->chargedEmEnergyFraction < 0.5
1666 +      && object->neutralEmEnergyFraction < 0.7;
1667 +  }
1668 +
1669 +  else if(variable == "disappTrkSubLeadingJetID") {
1670 +    value = object->pt > 30
1671 +      && fabs(object->eta) < 4.5
1672 +      && object->neutralHadronEnergyFraction < 0.7
1673 +      && object->chargedEmEnergyFraction < 0.5;
1674 +  }
1675 +
1676 +  else if(variable == "dPhiMet") {
1677 +    if (const BNmet *met = chosenMET ()) {
1678 +      value = deltaPhi (object->phi, met->phi);
1679 +    } else value = -999;
1680 +  }
1681 +
1682  
1683 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1683 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1684  
1685    value = applyFunction(function, value);
1686  
1687    return value;
1688 < }
591 <
1688 > } // end jet valueLookup
1689  
1690  
1691 + //!muon valueLookup
1692   double
1693 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1693 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1694  
1695    double value = 0.0;
1696    if(variable == "energy") value = object->energy;
# Line 608 | Line 1706 | OSUAnalysis::valueLookup (const BNmuon*
1706    else if(variable == "ecalIso") value = object->ecalIso;
1707    else if(variable == "hcalIso") value = object->hcalIso;
1708    else if(variable == "caloIso") value = object->caloIso;
1709 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
1709 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
1710    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
1711    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
1712    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 684 | Line 1782 | OSUAnalysis::valueLookup (const BNmuon*
1782    else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1783    else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1784    else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1785 +  else if(variable == "chargedHadronIsoDR04") value = object->chargedHadronIsoDR04;
1786 +  else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1787 +  else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1788 +  else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1789    else if(variable == "rhoPrime") value = object->rhoPrime;
1790    else if(variable == "AEffDr03") value = object->AEffDr03;
1791    else if(variable == "AEffDr04") value = object->AEffDr04;
# Line 691 | Line 1793 | OSUAnalysis::valueLookup (const BNmuon*
1793    else if(variable == "pfIsoR03SumNeutralHadronEt") value = object->pfIsoR03SumNeutralHadronEt;
1794    else if(variable == "pfIsoR03SumPhotonEt") value = object->pfIsoR03SumPhotonEt;
1795    else if(variable == "pfIsoR03SumPUPt") value = object->pfIsoR03SumPUPt;
1796 +  else if(variable == "relpfIsoR04SumExceptChargedHad") value = (object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)/ object->pt;
1797 +  else if(variable == "relpfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt/object->pt;
1798 +  else if(variable == "relpfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt/object->pt;
1799 +  else if(variable == "relpfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt/object->pt;
1800 +  else if(variable == "relpfIsoR04SumPUPt") value = object->pfIsoR04SumPUPt/object->pt;
1801    else if(variable == "pfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt;
1802    else if(variable == "pfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt;
1803    else if(variable == "pfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt;
# Line 746 | Line 1853 | OSUAnalysis::valueLookup (const BNmuon*
1853    else if(variable == "numberOfMatchedStations") value = object->numberOfMatchedStations;
1854    else if(variable == "time_ndof") value = object->time_ndof;
1855  
1856 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1856 >  //user-defined variables
1857 >  else if(variable == "looseID") {
1858 >    value = object->pt > 10 &&
1859 >      (object->isGlobalMuon  > 0 ||
1860 >       object->isTrackerMuon > 0);
1861 >  }
1862 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1863 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1864 >  else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1865 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1866 >  else if(variable == "relPFdBetaIsoPseudo") value = (object->pfIsoR04SumChargedHadronPt + object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt) / object->pt;
1867 >  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1868 >  else if(variable == "metMT") {
1869 >    if (const BNmet *met = chosenMET ())
1870 >      {
1871 >        double dPhi = deltaPhi (object->phi, met->phi);
1872 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1873 >      }
1874 >    else
1875 >      value = -999;
1876 >  }
1877 >
1878 >
1879 >
1880 >  else if(variable == "correctedD0VertexInEBPlus"){
1881 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1882 >    else value = -999;
1883 >  }
1884 >  else if(variable == "correctedD0VertexOutEBPlus"){
1885 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1886 >    else value = -999;
1887 >  }
1888 >  else if(variable == "correctedD0VertexEEPlus"){
1889 >    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1890 >    else value = -999;
1891 >  }
1892 >
1893 >  else if(variable == "correctedD0BeamspotInEBPlus"){
1894 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1895 >    else value = -999;
1896 >  }
1897 >  else if(variable == "correctedD0BeamspotOutEBPlus"){
1898 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1899 >    else value = -999;
1900 >  }
1901 >  else if(variable == "correctedD0BeamspotEEPlus"){
1902 >    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1903 >    else value = -999;
1904 >  }
1905 >
1906 >  else if(variable == "correctedD0VertexInEBMinus"){
1907 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1908 >    else value = -999;
1909 >  }
1910 >  else if(variable == "correctedD0VertexOutEBMinus"){
1911 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1912 >    else value = -999;
1913 >  }
1914 >  else if(variable == "correctedD0VertexEEMinus"){
1915 >    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1916 >    else value = -999;
1917 >  }
1918 >
1919 >  else if(variable == "correctedD0BeamspotInEBMinus"){
1920 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1921 >    else value = -999;
1922 >  }
1923 >  else if(variable == "correctedD0BeamspotOutEBMinus"){
1924 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1925 >    else value = -999;
1926 >  }
1927 >  else if(variable == "correctedD0BeamspotEEMinus"){
1928 >    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1929 >    else value = -999;
1930 >  }
1931 >
1932 >
1933 >  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1934 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1935 >    else value = -999;
1936 >  }
1937 >  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1938 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1939 >    else value = -999;
1940 >  }
1941 >  else if(variable == "correctedD0VertexEEPositiveCharge"){
1942 >    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1943 >    else value = -999;
1944 >  }
1945 >
1946 >  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1947 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1948 >    else value = -999;
1949 >  }
1950 >  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1951 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1952 >    else value = -999;
1953 >  }
1954 >  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1955 >    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1956 >    else value = -999;
1957 >  }
1958 >
1959 >  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1960 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1961 >    else value = -999;
1962 >  }
1963 >  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1964 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1965 >    else value = -999;
1966 >  }
1967 >  else if(variable == "correctedD0VertexEENegativeCharge"){
1968 >    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1969 >    else value = -999;
1970 >  }
1971 >
1972 >  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1973 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1974 >    else value = -999;
1975 >  }
1976 >  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1977 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1978 >    else value = -999;
1979 >  }
1980 >  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1981 >    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1982 >    else value = -999;
1983 >  }
1984 >
1985 >
1986 >  else if(variable == "tightID") {
1987 >    value = object->isGlobalMuon > 0                \
1988 >      && object->isPFMuon > 0                        \
1989 >      && object->normalizedChi2 < 10                \
1990 >      && object->numberOfValidMuonHits > 0        \
1991 >      && object->numberOfMatchedStations > 1        \
1992 >      && fabs(object->correctedD0Vertex) < 0.2        \
1993 >      && fabs(object->correctedDZ) < 0.5        \
1994 >      && object->numberOfValidPixelHits > 0                \
1995 >      && object->numberOfLayersWithMeasurement > 5;
1996 >  }
1997 >  else if(variable == "tightIDdisplaced"){
1998 >    value = object->isGlobalMuon > 0                \
1999 >      && object->isPFMuon > 0                        \
2000 >      && object->normalizedChi2 < 10                \
2001 >      && object->numberOfValidMuonHits > 0        \
2002 >      && object->numberOfMatchedStations > 1        \
2003 >      && object->numberOfValidPixelHits > 0        \
2004 >      && object->numberOfLayersWithMeasurement > 5;
2005 >  }
2006 >
2007 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2008 >
2009 >  else if(variable == "genMatchedPdgId"){
2010 >    int index = getGenMatchedParticleIndex(object);
2011 >    if(index == -1) value = 0;
2012 >    else value = mcparticles->at(index).id;
2013 >  }
2014 >
2015 >  else if(variable == "genMatchedId"){
2016 >    int index = getGenMatchedParticleIndex(object);
2017 >    if(index == -1) value = 0;
2018 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2019 >  }
2020 >  else if(variable == "genMatchedMotherId"){
2021 >    int index = getGenMatchedParticleIndex(object);
2022 >    if(index == -1) value = 0;
2023 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2024 >  }
2025 >  else if(variable == "genMatchedMotherIdReverse"){
2026 >    int index = getGenMatchedParticleIndex(object);
2027 >    if(index == -1) value = 24;
2028 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
2029 >  }
2030 >  else if(variable == "genMatchedGrandmotherId"){
2031 >    int index = getGenMatchedParticleIndex(object);
2032 >    if(index == -1) value = 0;
2033 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2034 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2035 >      if(motherIndex == -1) value = 0;
2036 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2037 >    }
2038 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2039 >  }
2040 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2041 >    int index = getGenMatchedParticleIndex(object);
2042 >    if(index == -1) value = 24;
2043 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2044 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2045 >      if(motherIndex == -1) value = 24;
2046 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2047 >    }
2048 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2049 >  }
2050 >  else if(variable == "pfMuonsFromVertex"){
2051 >    double d0Error, dzError;
2052 >
2053 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2054 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2055 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2056 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2057 >      || fabs (object->correctedDZ / dzError) > 99.0;
2058 >    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
2059 >  }
2060 >
2061 >
2062 >
2063 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2064  
2065    value = applyFunction(function, value);
2066  
2067    return value;
2068 < }
2068 > } // end muon valueLookup
2069  
2070  
2071 + //!electron valueLookup
2072   double
2073 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
2073 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
2074  
2075    double value = 0.0;
2076    if(variable == "energy") value = object->energy;
# Line 915 | Line 2230 | OSUAnalysis::valueLookup (const BNelectr
2230    else if(variable == "eidHyperTight4MC") value = object->eidHyperTight4MC;
2231    else if(variable == "passConvVeto") value = object->passConvVeto;
2232  
2233 +  //user-defined variables
2234 +  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2235 +  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2236 +  else if(variable == "detIso") value = (object->trackIso) / object->pt;
2237 +  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2238 +  else if(variable == "relPFrhoIsoEB") value = object->isEB ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2239 +  else if(variable == "relPFrhoIsoEE") value = object->isEE ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2240 +  else if(variable == "metMT") {
2241 +    if (const BNmet *met = chosenMET ())
2242 +      {
2243 +        double dPhi = deltaPhi (object->phi, met->phi);
2244 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2245 +      }
2246 +    else
2247 +      value = -999;
2248 +  }
2249 +
2250 +  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
2251 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
2252 +    else value = -999;
2253 +  }
2254 +  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
2255 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
2256 +    else value = -999;
2257 +  }
2258 +
2259 +  else if(variable == "correctedD0VertexInEBPlus"){
2260 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
2261 +    else value = -999;
2262 +  }
2263 +  else if(variable == "correctedD0VertexOutEBPlus"){
2264 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
2265 +    else value = -999;
2266 +  }
2267 +  else if(variable == "correctedD0VertexEEPlus"){
2268 +    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
2269 +    else value = -999;
2270 +  }
2271 +
2272 +  else if(variable == "correctedD0BeamspotInEBPlus"){
2273 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
2274 +    else value = -999;
2275 +  }
2276 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
2277 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
2278 +    else value = -999;
2279 +  }
2280 +  else if(variable == "correctedD0BeamspotEEPlus"){
2281 +    if(object->isEE && object->eta > 0) value = object->correctedD0;
2282 +    else value = -999;
2283 +  }
2284 +
2285 +  else if(variable == "correctedD0VertexInEBMinus"){
2286 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
2287 +    else value = -999;
2288 +  }
2289 +  else if(variable == "correctedD0VertexOutEBMinus"){
2290 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
2291 +    else value = -999;
2292 +  }
2293 +  else if(variable == "correctedD0VertexEEMinus"){
2294 +    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
2295 +    else value = -999;
2296 +  }
2297 +
2298 +  else if(variable == "correctedD0BeamspotInEBMinus"){
2299 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
2300 +    else value = -999;
2301 +  }
2302 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
2303 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
2304 +    else value = -999;
2305 +  }
2306 +  else if(variable == "correctedD0BeamspotEEMinus"){
2307 +    if(object->isEE && object->eta < 0) value = object->correctedD0;
2308 +    else value = -999;
2309 +  }
2310 +
2311 +  else if(variable == "looseID"){
2312 +    if (object->isEB)
2313 +      {
2314 +        value = fabs(object->delEtaIn) < 0.007 \
2315 +          && fabs (object->delPhiIn) < 0.15 \
2316 +          && object->scSigmaIEtaIEta < 0.01 \
2317 +          && object->hadOverEm < 0.12 \
2318 +          && fabs (object->correctedD0Vertex) < 0.02 \
2319 +          && fabs (object->correctedDZ) < 0.2 \
2320 +          && object->absInvEMinusInvPin < 0.05 \
2321 +          && object->passConvVeto;
2322 +      }
2323 +    else
2324 +      {
2325 +        value = fabs(object->delEtaIn) < 0.009 \
2326 +          && fabs (object->delPhiIn) < 0.10 \
2327 +          && object->scSigmaIEtaIEta < 0.03 \
2328 +          && object->hadOverEm < 0.10 \
2329 +          && fabs (object->correctedD0Vertex) < 0.02 \
2330 +          && fabs (object->correctedDZ) < 0.2 \
2331 +          && object->absInvEMinusInvPin < 0.05 \
2332 +          && object->passConvVeto;
2333 +      }
2334 +  }
2335 +
2336 +  else if(variable == "tightID"){
2337 +    if (object->isEB)
2338 +      {
2339 +        value = fabs(object->delEtaIn) < 0.004 \
2340 +          && fabs (object->delPhiIn) < 0.03 \
2341 +          && object->scSigmaIEtaIEta < 0.01 \
2342 +          && object->hadOverEm < 0.12 \
2343 +          && fabs (object->correctedD0Vertex) < 0.02 \
2344 +          && fabs (object->correctedDZ) < 0.1 \
2345 +          && object->absInvEMinusInvPin < 0.05 \
2346 +          && object->passConvVeto;
2347 +      }
2348 +    else
2349 +      {
2350 +        value = fabs(object->delEtaIn) < 0.005 \
2351 +          && fabs (object->delPhiIn) < 0.02 \
2352 +          && object->scSigmaIEtaIEta < 0.03 \
2353 +          && object->hadOverEm < 0.10 \
2354 +          && fabs (object->correctedD0Vertex) < 0.02 \
2355 +          && fabs (object->correctedDZ) < 0.1 \
2356 +          && object->absInvEMinusInvPin < 0.05 \
2357 +          && object->passConvVeto;
2358 +      }
2359 +  }
2360 +
2361 +  else if(variable == "looseID_MVA"){
2362 +    value = object->pt > 10
2363 +      && object->mvaNonTrigV0 > 0;
2364 +      }
2365 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
2366 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2367 +    else value = -999;
2368 +  }
2369 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
2370 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2371 +    else value = -999;
2372 +  }
2373 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
2374 +    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
2375 +    else value = -999;
2376 +  }
2377 +
2378 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
2379 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
2380 +    else value = -999;
2381 +  }
2382 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
2383 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
2384 +    else value = -999;
2385 +  }
2386 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
2387 +    if(object->isEE && object->charge > 0) value = object->correctedD0;
2388 +    else value = -999;
2389 +  }
2390 +
2391 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
2392 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2393 +    else value = -999;
2394 +  }
2395 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
2396 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2397 +    else value = -999;
2398 +  }
2399 +  else if(variable == "correctedD0VertexEENegativeCharge"){
2400 +    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
2401 +    else value = -999;
2402 +  }
2403 +
2404 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
2405 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
2406 +    else value = -999;
2407 +  }
2408 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
2409 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
2410 +    else value = -999;
2411 +  }
2412 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
2413 +    if(object->isEE && object->charge < 0) value = object->correctedD0;
2414 +    else value = -999;
2415 +  }
2416 +
2417 +
2418 +  else if(variable == "tightIDdisplaced"){
2419 +    if (object->isEB)
2420 +      {
2421 +        value = fabs(object->delEtaIn) < 0.004 \
2422 +          && fabs (object->delPhiIn) < 0.03 \
2423 +          && object->scSigmaIEtaIEta < 0.01 \
2424 +          && object->hadOverEm < 0.12 \
2425 +          && object->absInvEMinusInvPin < 0.05;
2426 +      }
2427 +    else
2428 +      {
2429 +        value = fabs (object->delEtaIn) < 0.005 \
2430 +          && fabs (object->delPhiIn) < 0.02 \
2431 +          && object->scSigmaIEtaIEta < 0.03 \
2432 +          && object->hadOverEm < 0.10 \
2433 +          && object->absInvEMinusInvPin < 0.05;
2434 +      }
2435 +  }
2436 +
2437 +
2438 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2439 +
2440 +  else if(variable == "genMatchedPdgId"){
2441 +    int index = getGenMatchedParticleIndex(object);
2442 +    if(index == -1) value = 0;
2443 +    else value = mcparticles->at(index).id;
2444 +  }
2445 +
2446 +
2447 +  else if(variable == "genMatchedId"){
2448 +    int index = getGenMatchedParticleIndex(object);
2449 +    if(index == -1) value = 0;
2450 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
2451 +  }
2452 +  else if(variable == "genMatchedMotherId"){
2453 +    int index = getGenMatchedParticleIndex(object);
2454 +    if(index == -1) value = 0;
2455 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2456 +  }
2457 +  else if(variable == "genMatchedMotherIdReverse"){
2458 +    int index = getGenMatchedParticleIndex(object);
2459 +    if(index == -1) value = 24;
2460 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2461 +  }
2462 +  else if(variable == "genMatchedGrandmotherId"){
2463 +    int index = getGenMatchedParticleIndex(object);
2464 +    if(index == -1) value = 0;
2465 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2466 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2467 +      if(motherIndex == -1) value = 0;
2468 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2469 +    }
2470 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2471 +  }
2472 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2473 +    int index = getGenMatchedParticleIndex(object);
2474 +    if(index == -1) value = 24;
2475 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2476 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2477 +      if(motherIndex == -1) value = 24;
2478 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2479 +    }
2480 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2481 +  }
2482 +  else if(variable == "pfElectronsFromVertex"){
2483 +    double d0Error, dzError;
2484 +
2485 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2486 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2487 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2488 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2489 +      || fabs (object->correctedDZ / dzError) > 99.0;
2490 +    value = !value;
2491 +  }
2492 +
2493 +
2494  
2495 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2495 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2496  
2497    value = applyFunction(function, value);
2498  
2499    return value;
2500 < }
2500 > } // end electron valueLookup
2501  
2502  
2503 + //!event valueLookup
2504   double
2505 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2505 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2506  
2507    double value = 0.0;
2508  
# Line 993 | Line 2570 | OSUAnalysis::valueLookup (const BNevent*
2570    else if(variable == "id1") value = object->id1;
2571    else if(variable == "id2") value = object->id2;
2572    else if(variable == "evt") value = object->evt;
2573 <
2574 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2573 >  else if(variable == "puScaleFactor"){
2574 >    if(doPileupReweighting_ && datasetType_ != "data")
2575 >      value = puWeight_->at (events->at (0).numTruePV);
2576 >    else
2577 >      value = 1.0;
2578 >  }
2579 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2580 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2581 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2582 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2583 >
2584 >  else if(variable == "unfilteredHt") value = getHt(jets.product());
2585 >  else if(variable == "ht") value = chosenHT ();
2586 >
2587 >  else if(variable == "leadMuPairInvMass"){
2588 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2589 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2590 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2591 >    value = (p0 + p1).M ();
2592 >  }
2593 >  else if(variable == "leadMuPairPt"){
2594 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2595 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2596 >             pt1 (muPair.second->px, muPair.second->py);
2597 >    pt0 += pt1;
2598 >    value = pt0.Mod ();
2599 >  }
2600 >  else if(variable == "leadElPairInvMass"){
2601 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2602 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2603 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2604 >    value = (p0 + p1).M ();
2605 >  }
2606 >  else if(variable == "leadElPairPt"){
2607 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2608 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2609 >             pt1 (muPair.second->px, muPair.second->py);
2610 >    pt0 += pt1;
2611 >    value = pt0.Mod ();
2612 >  }
2613 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2614  
2615    value = applyFunction(function, value);
2616  
2617    return value;
2618 < }
2618 > } // end event valueLookup
2619  
2620 +
2621 + //!tau valueLookup
2622   double
2623 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2623 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2624  
2625    double value = 0.0;
2626  
# Line 1046 | Line 2664 | OSUAnalysis::valueLookup (const BNtau* o
2664    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2665    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2666  
2667 +  else if (variable == "looseHadronicID") {
2668 +    value = object->pt > 10
2669 +      && object->eta < 2.3
2670 +      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2671 +      && object->HPSdecayModeFinding > 0
2672 +      && object->HPSagainstElectronLoose > 0
2673 +      && object->HPSagainstMuonTight > 0;
2674 +  }
2675 +
2676 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2677 +
2678 +  else if(variable == "genMatchedPdgId"){
2679 +    int index = getGenMatchedParticleIndex(object);
2680 +    if(index == -1) value = 0;
2681 +    else value = mcparticles->at(index).id;
2682 +  }
2683 +
2684 +  else if(variable == "genMatchedId"){
2685 +    int index = getGenMatchedParticleIndex(object);
2686 +    if(index == -1) value = 0;
2687 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
2688 +  }
2689 +  else if(variable == "genMatchedMotherId"){
2690 +    int index = getGenMatchedParticleIndex(object);
2691 +    if(index == -1) value = 0;
2692 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2693 +  }
2694 +  else if(variable == "genMatchedMotherIdReverse"){
2695 +    int index = getGenMatchedParticleIndex(object);
2696 +    if(index == -1) value = 24;
2697 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2698 +  }
2699 +  else if(variable == "genMatchedGrandmotherId"){
2700 +    int index = getGenMatchedParticleIndex(object);
2701 +    if(index == -1) value = 0;
2702 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2703 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2704 +      if(motherIndex == -1) value = 0;
2705 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2706 +    }
2707 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2708 +  }
2709 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2710 +    int index = getGenMatchedParticleIndex(object);
2711 +    if(index == -1) value = 24;
2712 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2713 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2714 +      if(motherIndex == -1) value = 24;
2715 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2716 +    }
2717 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2718 +  }
2719 +
2720  
2721 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2721 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2722  
2723    value = applyFunction(function, value);
2724  
2725    return value;
2726 < }
2726 > } // end tau valueLookup
2727  
2728 +
2729 + //!met valueLookup
2730   double
2731 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2731 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2732  
2733    double value = 0.0;
2734  
# Line 1119 | Line 2792 | OSUAnalysis::valueLookup (const BNmet* o
2792    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2793    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2794  
2795 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2795 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2796  
2797    value = applyFunction(function, value);
2798  
2799    return value;
2800 < }
2800 > } // end met valueLookup
2801  
2802 +
2803 + //!track valueLookup
2804   double
2805 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2805 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2806  
2807    double value = 0.0;
2808 +  double pMag = sqrt(object->pt * object->pt +
2809 +                     object->pz * object->pz);
2810  
2811    if(variable == "pt") value = object->pt;
2812    else if(variable == "px") value = object->px;
# Line 1149 | Line 2826 | OSUAnalysis::valueLookup (const BNtrack*
2826    else if(variable == "numValidHits") value = object->numValidHits;
2827    else if(variable == "isHighPurity") value = object->isHighPurity;
2828  
2829 +  //additional BNs info for disappTrks
2830 +  else if(variable == "caloEMDeltaRp3")     value = object->caloEMDeltaRp3;
2831 +  else if(variable == "caloHadDeltaRp3")    value = object->caloHadDeltaRp3;
2832 +  else if(variable == "caloEMDeltaRp4")     value = object->caloEMDeltaRp4;
2833 +  else if(variable == "caloHadDeltaRp4")    value = object->caloHadDeltaRp4;
2834 +  else if(variable == "caloEMDeltaRp5")     value = object->caloEMDeltaRp5;
2835 +  else if(variable == "caloHadDeltaRp5")    value = object->caloHadDeltaRp5;
2836 +  else if(variable == "nHitsMissingOuter")  value = object->nHitsMissingOuter;
2837 +  else if(variable == "nHitsMissingInner")  value = object->nHitsMissingInner;
2838 +  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2839 +  else if(variable == "depTrkRp3")          value = object->depTrkRp3;
2840 +  else if(variable == "trkRelIsoRp3")     { value = (object->depTrkRp3 - object->pt) / object->pt; if (value<0) value = 0; }
2841 +  else if(variable == "trkRelIsoRp5")     { value = (object->depTrkRp5 - object->pt) / object->pt; if (value<0) value = 0; }
2842 +  else if(variable == "depEcalRp3")         value = object->depEcalRp3;
2843 +  else if(variable == "depHcalRp3")         value = object->depHcalRp3;
2844 +  else if(variable == "depHoRp3")           value = object->depHoRp3;
2845 +  else if(variable == "nTracksRp3")         value = object->nTracksRp3;
2846 +  else if(variable == "trackerVetoPtRp3")   value = object->trackerVetoPtRp3;
2847 +  else if(variable == "emVetoEtRp3")        value = object->emVetoEtRp3;
2848 +  else if(variable == "hadVetoEtRp3")       value = object->hadVetoEtRp3;
2849 +  else if(variable == "hoVetoEtRp3")        value = object->hoVetoEtRp3;
2850 +  else if(variable == "depTrkRp5")          value = object->depTrkRp5;
2851 +  else if(variable == "depEcalRp5")         value = object->depEcalRp5;
2852 +  else if(variable == "depHcalRp5")         value = object->depHcalRp5;
2853 +  else if(variable == "depHoRp5")           value = object->depHoRp5;
2854 +  else if(variable == "nTracksRp5")         value = object->nTracksRp5;
2855 +  else if(variable == "trackerVetoPtRp5")   value = object->trackerVetoPtRp5;
2856 +  else if(variable == "emVetoEtRp5")        value = object->emVetoEtRp5;
2857 +  else if(variable == "hadVetoEtRp5")       value = object->hadVetoEtRp5;
2858 +  else if(variable == "hoVetoEtRp5")        value = object->hoVetoEtRp5;
2859 +
2860 +  //user defined variables
2861 +  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;
2862 +  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2863 +  else if(variable == "depTrkRp5MinusPt"){
2864 +    if ( (object->depTrkRp5 - object->pt) < 0 ) {
2865 + //       clog << "Warning:  found track with depTrkRp5 < pt:  depTrkRp5=" << object->depTrkRp5
2866 + //         << "; pt=" << object->pt
2867 + //         << "; object->depTrkRp5 - object->pt = " << object->depTrkRp5 - object->pt
2868 + //         << endl;  
2869 +           value = 0;
2870 +         }
2871 +         else value =  (object->depTrkRp5 - object->pt);
2872 +  }
2873 +  else if(variable == "depTrkRp3MinusPt"){
2874 +    if ( (object->depTrkRp3 - object->pt) < 0 ) {
2875 +      value = 0;
2876 +    }
2877 +    else value =  (object->depTrkRp3 - object->pt);
2878 +  }
2879 +
2880 +  else if(variable == "dPhiMet") {
2881 +    if (const BNmet *met = chosenMET ()) {
2882 +      value = deltaPhi (object->phi, met->phi);
2883 +    } else value = -999;
2884 +  }
2885 +  
2886 +  
2887 +  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2888 +  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2889 +  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2890 +  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2891 +  else if(variable == "depTrkRp5RhoCorr")           value = getTrkDepTrkRp5RhoCorr(object);
2892 +  else if(variable == "depTrkRp3RhoCorr")           value = getTrkDepTrkRp3RhoCorr(object);
2893 +
2894 +  else if(variable == "depTrkRp5MinusPtRhoCorr")    {
2895 +    if ( (getTrkDepTrkRp5RhoCorr(object) - object->pt) < 0 ) value = 0;
2896 +    else {value = (getTrkDepTrkRp5RhoCorr(object) - object->pt );}
2897 +  }
2898 +  
2899 +  else if(variable == "depTrkRp3MinusPtRhoCorr")    
2900 +    {
2901 +      if ( (getTrkDepTrkRp3RhoCorr(object) - object->pt) < 0 ) value = 0;
2902 +      else {value = (getTrkDepTrkRp3RhoCorr(object) - object->pt );}
2903 +    }
2904 +
2905 +  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2906 +  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2907 +  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2908 +  else if(variable == "ptError")                    value = object->ptError;
2909 +  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2910 +  else if (variable == "d0wrtPV"){
2911 +    double vx = object->vx - chosenVertex ()->x,
2912 +      vy = object->vy - chosenVertex ()->y,
2913 +      px = object->px,
2914 +      py = object->py,
2915 +      pt = object->pt;
2916 +    value = (-vx * py + vy * px) / pt;
2917 +  }
2918 +  else if (variable == "dZwrtPV"){
2919 +    double vx = object->vx - chosenVertex ()->x,
2920 +      vy = object->vy - chosenVertex ()->y,
2921 +      vz = object->vz - chosenVertex ()->z,
2922 +      px = object->px,
2923 +      py = object->py,
2924 +      pz = object->pz,
2925 +      pt = object->pt;
2926 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2927 +  }
2928 +
2929 +  else if(variable == "deltaRMinSubLeadJet") {
2930 +    // calculate minimum deltaR between track and any other subleading jet  
2931 +    double trkJetDeltaRMin = 99.;  
2932 +    for (uint ijet = 0; ijet<jets->size(); ijet++) {
2933 +      string empty = "";  
2934 +      double isSubLeadingJet = valueLookup(&jets->at(ijet), "disappTrkSubLeadingJetID", "", empty);  
2935 +      if (!isSubLeadingJet) continue;  // only consider jets that pass the subleading jet ID criteria  
2936 +      double jetEta = valueLookup(&jets->at(ijet), "eta", "", empty);
2937 +      double jetPhi = valueLookup(&jets->at(ijet), "phi", "", empty);
2938 +      double trkJetDeltaR = deltaR(object->eta, object->phi, jetEta, jetPhi);  
2939 +      if (trkJetDeltaR < trkJetDeltaRMin) trkJetDeltaRMin = trkJetDeltaR;
2940 +    }
2941 +    value = trkJetDeltaRMin;  
2942 +  }  
2943 +  
2944 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2945 +
2946 +  else if(variable == "genMatchedPdgId"){
2947 +    int index = getGenMatchedParticleIndex(object);
2948 +    if(index == -1) value = 0;
2949 +    else value = mcparticles->at(index).id;
2950 +  }
2951 +
2952 +
2953 +  else if(variable == "genMatchedId"){
2954 +    int index = getGenMatchedParticleIndex(object);
2955 +    if(index == -1) value = 0;
2956 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
2957 +  }
2958 +  else if(variable == "genMatchedMotherId"){
2959 +    int index = getGenMatchedParticleIndex(object);
2960 +    if(index == -1) value = 0;
2961 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2962 +  }
2963 +  else if(variable == "genMatchedMotherIdReverse"){
2964 +    int index = getGenMatchedParticleIndex(object);
2965 +    if(index == -1) value = 24;
2966 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2967 +  }
2968 +  else if(variable == "genMatchedGrandmotherId"){
2969 +    int index = getGenMatchedParticleIndex(object);
2970 +    if(index == -1) value = 0;
2971 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2972 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2973 +      if(motherIndex == -1) value = 0;
2974 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2975 +    }
2976 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2977 +  }
2978 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2979 +    int index = getGenMatchedParticleIndex(object);
2980 +    if(index == -1) value = 24;
2981 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2982 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2983 +      if(motherIndex == -1) value = 24;
2984 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2985 +    }
2986 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2987 +  }
2988 +
2989 +
2990  
2991 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2991 >  else{clog << "WARNING: invalid variable '" << variable << "' for BNtrack collection.\n"; value = -999;}
2992  
2993    value = applyFunction(function, value);
2994  
2995    return value;
2996 < }
2996 > } // end track valueLookup
2997  
2998 +
2999 + //!genjet valueLookup
3000   double
3001 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
3001 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
3002  
3003    double value = 0.0;
3004  
# Line 1178 | Line 3018 | OSUAnalysis::valueLookup (const BNgenjet
3018    else if(variable == "charge") value = object->charge;
3019  
3020  
3021 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3021 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3022  
3023    value = applyFunction(function, value);
3024  
3025    return value;
3026   }
3027  
3028 + //!mcparticle valueLookup
3029   double
3030 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
3030 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
3031  
3032    double value = 0.0;
3033  
# Line 1275 | Line 3116 | OSUAnalysis::valueLookup (const BNmcpart
3116    else if(variable == "grandMother11Status") value = object->grandMother11Status;
3117    else if(variable == "grandMother11Charge") value = object->grandMother11Charge;
3118  
3119 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3119 >  //user-defined variables
3120 >  else if (variable == "d0"){
3121 >    double vx = object->vx - chosenVertex ()->x,
3122 >      vy = object->vy - chosenVertex ()->y,
3123 >      px = object->px,
3124 >      py = object->py,
3125 >      pt = object->pt;
3126 >    value = (-vx * py + vy * px) / pt;
3127 >  }
3128 >  else if (variable == "dz"){
3129 >    double vx = object->vx - chosenVertex ()->x,
3130 >      vy = object->vy - chosenVertex ()->y,
3131 >      vz = object->vz - chosenVertex ()->z,
3132 >      px = object->px,
3133 >      py = object->py,
3134 >      pz = object->pz,
3135 >      pt = object->pt;
3136 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3137 >  }
3138 >  else if(variable == "v0"){
3139 >    value = sqrt(object->vx*object->vx + object->vy*object->vy);
3140 >  }
3141 >  else if(variable == "deltaV0"){
3142 >    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
3143 >  }
3144 >  else if (variable == "deltaVx"){
3145 >    value = object->vx - chosenVertex ()->x;
3146 >  }
3147 >  else if (variable == "deltaVy"){
3148 >    value = object->vy - chosenVertex ()->y;
3149 >  }
3150 >  else if (variable == "deltaVz"){
3151 >    value = object->vz - chosenVertex ()->z;
3152 >  }
3153 >
3154 >
3155 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3156  
3157    value = applyFunction(function, value);
3158  
3159    return value;
3160 < }
3160 > } // end mcparticle valueLookup
3161 >
3162  
3163 + //!primaryvertex valueLookup
3164   double
3165 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
3165 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
3166  
3167    double value = 0.0;
3168  
# Line 1302 | Line 3181 | OSUAnalysis::valueLookup (const BNprimar
3181    else if(variable == "isGood") value = object->isGood;
3182  
3183  
3184 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3184 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3185  
3186    value = applyFunction(function, value);
3187  
3188    return value;
3189   }
3190  
3191 + //!bxlumi valueLookup
3192   double
3193 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
3193 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
3194  
3195    double value = 0.0;
3196  
# Line 1319 | Line 3199 | OSUAnalysis::valueLookup (const BNbxlumi
3199    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
3200  
3201  
3202 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3202 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3203  
3204    value = applyFunction(function, value);
3205  
3206    return value;
3207   }
3208  
3209 + //!photon valueLookup
3210   double
3211 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
3211 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
3212  
3213    double value = 0.0;
3214  
# Line 1402 | Line 3283 | OSUAnalysis::valueLookup (const BNphoton
3283    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
3284  
3285  
3286 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3286 >
3287 >
3288 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3289 >
3290 >  else if(variable == "genMatchedPdgId"){
3291 >    int index = getGenMatchedParticleIndex(object);
3292 >    if(index == -1) value = 0;
3293 >    else value = mcparticles->at(index).id;
3294 >  }
3295 >
3296 >
3297 >
3298 >  else if(variable == "genMatchedId"){
3299 >    int index = getGenMatchedParticleIndex(object);
3300 >    if(index == -1) value = 0;
3301 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
3302 >  }
3303 >  else if(variable == "genMatchedMotherId"){
3304 >    int index = getGenMatchedParticleIndex(object);
3305 >    if(index == -1) value = 0;
3306 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
3307 >  }
3308 >  else if(variable == "genMatchedMotherIdReverse"){
3309 >    int index = getGenMatchedParticleIndex(object);
3310 >    if(index == -1) value = 24;
3311 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
3312 >  }
3313 >  else if(variable == "genMatchedGrandmotherId"){
3314 >    int index = getGenMatchedParticleIndex(object);
3315 >    if(index == -1) value = 0;
3316 >    else if(fabs(mcparticles->at(index).motherId) == 15){
3317 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3318 >      if(motherIndex == -1) value = 0;
3319 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3320 >    }
3321 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3322 >  }
3323 >  else if(variable == "genMatchedGrandmotherIdReverse"){
3324 >    int index = getGenMatchedParticleIndex(object);
3325 >    if(index == -1) value = 24;
3326 >    else if(fabs(mcparticles->at(index).motherId) == 15){
3327 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3328 >      if(motherIndex == -1) value = 24;
3329 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3330 >    }
3331 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3332 >  }
3333 >
3334 >
3335 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3336  
3337    value = applyFunction(function, value);
3338  
3339    return value;
3340 < }
3340 > } // end photon valueLookup
3341 >
3342  
3343 + //!supercluster valueLookup
3344   double
3345 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
3345 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
3346  
3347    double value = 0.0;
3348  
# Line 1424 | Line 3356 | OSUAnalysis::valueLookup (const BNsuperc
3356    else if(variable == "theta") value = object->theta;
3357  
3358  
3359 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3359 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3360 >
3361 >  value = applyFunction(function, value);
3362 >
3363 >  return value;
3364 > }
3365 >
3366 > //!trigobj valueLookup
3367 > double
3368 > OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3369 >
3370 >  double value = 0.0;
3371 >
3372 >  if(variable == "pt") value = object->pt;
3373 >  else if(variable == "eta") value = object->eta;
3374 >  else if(variable == "phi") value = object->phi;
3375 >  else if(variable == "px") value = object->px;
3376 >  else if(variable == "py") value = object->py;
3377 >  else if(variable == "pz") value = object->pz;
3378 >  else if(variable == "et") value = object->et;
3379 >  else if(variable == "energy") value = object->energy;
3380 >  else if(variable == "etTotal") value = object->etTotal;
3381 >  else if(variable == "id") value = object->id;
3382 >  else if(variable == "charge") value = object->charge;
3383 >  else if(variable == "isIsolated") value = object->isIsolated;
3384 >  else if(variable == "isMip") value = object->isMip;
3385 >  else if(variable == "isForward") value = object->isForward;
3386 >  else if(variable == "isRPC") value = object->isRPC;
3387 >  else if(variable == "bx") value = object->bx;
3388 >  else if(variable == "filter") {
3389 >    if ((stringValue = object->filter) == "")
3390 >      stringValue = "none";  // stringValue should only be empty if value is filled
3391 >  }
3392 >
3393 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3394 >
3395 >  value = applyFunction(function, value);
3396 >
3397 >  return value;
3398 > }
3399 >
3400 > //!muon-muon pair valueLookup
3401 > double
3402 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3403 >
3404 >  double value = 0.0;
3405 >
3406 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3407 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3408 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3409 >  else if(variable == "invMass"){
3410 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3411 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3412 >    value = (fourVector1 + fourVector2).M();
3413 >  }
3414 >  else if(variable == "pt"){
3415 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3416 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3417 >    value = (fourVector1 + fourVector2).Pt();
3418 >  }
3419 >  else if(variable == "threeDAngle")
3420 >    {
3421 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3422 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3423 >      value = (threeVector1.Angle(threeVector2));
3424 >    }
3425 >  else if(variable == "alpha")
3426 >    {
3427 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3428 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3429 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3430 >      value = (pi-threeVector1.Angle(threeVector2));
3431 >    }
3432 >  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3433 >  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3434 >  else if(variable == "d0Sign"){
3435 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3436 >    if(d0Sign < 0) value = -0.5;
3437 >    else if (d0Sign > 0) value = 0.5;
3438 >    else value = -999;
3439 >  }
3440 >  else if(variable == "chargeProduct"){
3441 >    value = object1->charge*object2->charge;
3442 >  }
3443 >  else if(variable == "muon1CorrectedD0Vertex"){
3444 >    value = object1->correctedD0Vertex;
3445 >  }
3446 >  else if(variable == "muon2CorrectedD0Vertex"){
3447 >    value = object2->correctedD0Vertex;
3448 >  }
3449 >  else if(variable == "muon1timeAtIpInOut"){
3450 >    value = object1->timeAtIpInOut;
3451 >  }
3452 >  else if(variable == "muon2timeAtIpInOut"){
3453 >    value = object2->timeAtIpInOut;
3454 >  }
3455 >  else if(variable == "muon1correctedD0")
3456 >    {
3457 >      value = object1->correctedD0;
3458 >    }
3459 >  else if(variable == "muon2correctedD0")
3460 >    {
3461 >      value = object2->correctedD0;
3462 >    }
3463 >
3464 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3465 >
3466 >  value = applyFunction(function, value);
3467 >
3468 >  return value;
3469 > } // end muon-muon pair valueLookup
3470 >
3471 >
3472 > //!muon-photon pair valueLookup
3473 > double
3474 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3475 >
3476 >  double value = 0.0;
3477 >
3478 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3479 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3480 >  else if(variable == "photonEta") value = object2->eta;
3481 >  else if(variable == "photonPt") value = object2->pt;
3482 >  else if(variable == "muonEta") value = object1->eta;
3483 >  else if(variable == "photonPhi") value = object2->phi;
3484 >  else if(variable == "muonPhi") value = object1->phi;
3485 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3486 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3487 >  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3488 >  else if(variable == "invMass"){
3489 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3490 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3491 >    value = (fourVector1 + fourVector2).M();
3492 >  }
3493 >  else if(variable == "pt"){
3494 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3495 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3496 >    value = (fourVector1 + fourVector2).Pt();
3497 >  }
3498 >  else if(variable == "threeDAngle")
3499 >    {
3500 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3501 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3502 >      value = (threeVector1.Angle(threeVector2));
3503 >    }
3504 >  else if(variable == "alpha")
3505 >    {
3506 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3507 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3508 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3509 >      value = (pi-threeVector1.Angle(threeVector2));
3510 >    }
3511 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3512 >
3513 >  value = applyFunction(function, value);
3514 >
3515 >  return value;
3516 > }
3517 >
3518 > //!electron-photon pair valueLookup
3519 > double
3520 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3521 >
3522 >  double value = 0.0;
3523 >
3524 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3525 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3526 >  else if(variable == "photonEta") value = object2->eta;
3527 >  else if(variable == "photonPt") value = object2->pt;
3528 >  else if(variable == "electronEta") value = object1->eta;
3529 >  else if(variable == "photonPhi") value = object2->phi;
3530 >  else if(variable == "electronPhi") value = object1->phi;
3531 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3532 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3533 >  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3534 >  else if(variable == "invMass"){
3535 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3536 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3537 >    value = (fourVector1 + fourVector2).M();
3538 >  }
3539 >  else if(variable == "pt"){
3540 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3541 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3542 >    value = (fourVector1 + fourVector2).Pt();
3543 >  }
3544 >  else if(variable == "threeDAngle")
3545 >    {
3546 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3547 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3548 >      value = (threeVector1.Angle(threeVector2));
3549 >    }
3550 >  else if(variable == "alpha")
3551 >    {
3552 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3553 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3554 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3555 >      value = (pi-threeVector1.Angle(threeVector2));
3556 >    }
3557 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3558 >
3559 >  value = applyFunction(function, value);
3560 >
3561 >  return value;
3562 > }
3563 >
3564 > //!electron-electron pair valueLookup
3565 > double
3566 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3567 >
3568 >  double value = 0.0;
3569 >
3570 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3571 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3572 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3573 >  else if(variable == "invMass"){
3574 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3575 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3576 >    value = (fourVector1 + fourVector2).M();
3577 >  }
3578 >  else if(variable == "pt"){
3579 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3580 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3581 >    value = (fourVector1 + fourVector2).Pt();
3582 >  }
3583 >  else if(variable == "threeDAngle")
3584 >    {
3585 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3586 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3587 >      value = (threeVector1.Angle(threeVector2));
3588 >    }
3589 >  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3590 >  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3591 >  else if(variable == "d0Sign"){
3592 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3593 >    if(d0Sign < 0) value = -0.5;
3594 >    else if (d0Sign > 0) value = 0.5;
3595 >    else value = -999;
3596 >  }
3597 >  else if(variable == "chargeProduct"){
3598 >    value = object1->charge*object2->charge;
3599 >  }
3600 >  else if(variable == "electron1CorrectedD0Vertex"){
3601 >    value = object1->correctedD0Vertex;
3602 >  }
3603 >  else if(variable == "electron2CorrectedD0Vertex"){
3604 >    value = object2->correctedD0Vertex;
3605 >  }
3606 >  else if(variable == "electron1CorrectedD0"){
3607 >    value = object1->correctedD0;
3608 >  }
3609 >  else if(variable == "electron2CorrectedD0"){
3610 >    value = object2->correctedD0;
3611 >  }
3612 >
3613 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3614 >
3615 >  value = applyFunction(function, value);
3616  
3617 +  return value;
3618 + }
3619 +
3620 + //!electron-muon pair valueLookup
3621 + double
3622 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3623 +
3624 +  double value = 0.0;
3625 +
3626 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3627 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3628 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3629 +  else if(variable == "invMass"){
3630 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3631 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3632 +    value = (fourVector1 + fourVector2).M();
3633 +  }
3634 +  else if(variable == "pt"){
3635 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3636 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3637 +    value = (fourVector1 + fourVector2).Pt();
3638 +  }
3639 +  else if(variable == "threeDAngle")
3640 +    {
3641 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3642 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3643 +      value = (threeVector1.Angle(threeVector2));
3644 +    }
3645 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3646 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3647 +  else if(variable == "d0Sign"){
3648 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3649 +    if(d0Sign < 0) value = -0.5;
3650 +    else if (d0Sign > 0) value = 0.5;
3651 +    else value = -999;
3652 +  }
3653 +  else if(variable == "chargeProduct"){
3654 +    value = object1->charge*object2->charge;
3655 +  }
3656 +  else if(variable == "electronCorrectedD0Vertex"){
3657 +    value = object1->correctedD0Vertex;
3658 +  }
3659 +  else if(variable == "muonCorrectedD0Vertex"){
3660 +    value = object2->correctedD0Vertex;
3661 +  }
3662 +  else if(variable == "electronCorrectedD0"){
3663 +    value = object1->correctedD0;
3664 +  }
3665 +  else if(variable == "muonCorrectedD0"){
3666 +    value = object2->correctedD0;
3667 +  }
3668 +  else if(variable == "electronDetIso"){
3669 +    value = (object1->trackIso) / object1->pt;
3670 +  }
3671 +  else if(variable == "muonDetIso"){
3672 +    value = (object2->trackIsoDR03) / object2->pt;
3673 +  }
3674 +  else if(variable == "electronRelPFrhoIso"){
3675 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3676 +  }
3677 +  else if(variable == "muonRelPFdBetaIso"){
3678 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3679 +  }
3680 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3681 +  value = applyFunction(function, value);
3682 +
3683 +  return value;
3684 + } // end electron-muon pair valueLookup
3685 +
3686 +
3687 + //!electron-jet pair valueLookup
3688 + double
3689 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3690 +
3691 +  double value = 0.0;
3692 +
3693 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3694 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3695 +  else if(variable == "jetEta") value = object2->eta;
3696 +  else if(variable == "jetPhi") value = object2->phi;
3697 +  else if(variable == "electronEta") value = object1->eta;
3698 +  else if(variable == "electronPhi") value = object1->phi;
3699 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3700 +  else if(variable == "invMass"){
3701 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3702 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3703 +    value = (fourVector1 + fourVector2).M();
3704 +  }
3705 +  else if(variable == "pt"){
3706 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3707 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3708 +    value = (fourVector1 + fourVector2).Pt();
3709 +  }
3710 +  else if(variable == "threeDAngle")
3711 +    {
3712 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3713 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3714 +      value = (threeVector1.Angle(threeVector2));
3715 +    }
3716 +  else if(variable == "chargeProduct"){
3717 +    value = object1->charge*object2->charge;
3718 +  }
3719 +
3720 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3721    value = applyFunction(function, value);
3722  
3723    return value;
3724   }
3725  
3726 + //!electron-mcparticle pair valueLookup
3727 + double
3728 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmcparticle* object2, string variable, string function, string &stringValue){
3729 +
3730 +  double value = 0.0;
3731 +
3732 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3733 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3734 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3735 +  else if(variable == "threeDAngle")
3736 +    {
3737 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3738 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3739 +      value = (threeVector1.Angle(threeVector2));
3740 +    }
3741 +  else if(variable == "chargeProduct"){
3742 +    value = object1->charge*object2->charge;
3743 +  }
3744 +
3745 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3746 +  value = applyFunction(function, value);
3747 +
3748 +  return value;
3749 + }
3750 +
3751 +
3752 + //!photon-jet pair valueLookup
3753 + double
3754 + OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3755 +
3756 +  double value = 0.0;
3757 +
3758 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3759 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3760 +  else if(variable == "jetEta") value = object2->eta;
3761 +  else if(variable == "jetPhi") value = object2->phi;
3762 +  else if(variable == "photonEta") value = object1->eta;
3763 +  else if(variable == "photonPhi") value = object1->phi;
3764 +  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3765 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3766 +  else if(variable == "invMass"){
3767 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3768 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3769 +    value = (fourVector1 + fourVector2).M();
3770 +  }
3771 +  else if(variable == "pt"){
3772 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3773 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3774 +    value = (fourVector1 + fourVector2).Pt();
3775 +  }
3776 +  else if(variable == "threeDAngle")
3777 +    {
3778 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3779 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3780 +      value = (threeVector1.Angle(threeVector2));
3781 +    }
3782 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3783 +  value = applyFunction(function, value);
3784 +
3785 +  return value;
3786 + }
3787 +
3788 + // track-jet pair valueLookup
3789 + double
3790 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNjet* object2, string variable, string function, string &stringValue){
3791 +
3792 +  double value = 0.0;
3793 +
3794 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3795 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3796 +
3797 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3798 +  value = applyFunction(function, value);
3799 +
3800 +  return value;
3801 +
3802 + }
3803 +
3804 +
3805 +
3806 + // met-jet pair valueLookup
3807 + double
3808 + OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3809 +
3810 +  double value = 0.0;
3811 +
3812 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3813 +
3814 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3815 +  value = applyFunction(function, value);
3816 +
3817 +  return value;
3818 +
3819 + }  
3820 +
3821 +
3822 +
3823 + //!muon-jet pair valueLookup
3824 + double
3825 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3826 +
3827 +  double value = 0.0;
3828 +
3829 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3830 +  else if(variable == "jetEta") value = object2->eta;
3831 +  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3832 +  else if(variable == "jetPt") value = object2->pt;
3833 +  else if(variable == "jetPhi") value = object2->phi;
3834 +  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3835 +  else if(variable == "muonEta") value = object1->eta;
3836 +  else if(variable == "muonPt") value = object1->pt;
3837 +  else if(variable == "muonPhi") value = object1->phi;
3838 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3839 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3840 +  else if(variable == "invMass"){
3841 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3842 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3843 +    value = (fourVector1 + fourVector2).M();
3844 +  }
3845 +  else if(variable == "pt"){
3846 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3847 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3848 +    value = (fourVector1 + fourVector2).Pt();
3849 +  }
3850 +  else if(variable == "threeDAngle")
3851 +    {
3852 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3853 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3854 +      value = (threeVector1.Angle(threeVector2));
3855 +    }
3856 +  else if(variable == "chargeProduct"){
3857 +    value = object1->charge*object2->charge;
3858 +  }
3859 +
3860 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3861 +  value = applyFunction(function, value);
3862 +
3863 +  return value;
3864 + }
3865 +
3866 + //!muon-event valueLookup
3867 + double
3868 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNevent* object2, string variable, string function, string &stringValue){
3869 +
3870 +  double value = 0.0;
3871 +
3872 +  if(variable == "muonEta") value = object1->eta;
3873 +  else if(variable == "muonPt") value = object1->pt;
3874 +  else if(variable == "muonPhi") value = object1->phi;
3875 +  else if(variable == "Ht") value = getHt(jets.product());
3876 +  else if(variable == "pthat")   value = object2->pthat;
3877 +  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3878 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3879 +  value = applyFunction(function, value);
3880 +
3881 +  return value;
3882 + }
3883 + //!jet-jet pair valueLookup
3884 + double
3885 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3886 +
3887 +  double value = 0.0;
3888 +
3889 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3890 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3891 +  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3892 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3893 +  else if(variable == "invMass"){
3894 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3895 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3896 +    value = (fourVector1 + fourVector2).M();
3897 +  }
3898 +  else if(variable == "pt"){
3899 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3900 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3901 +    value = (fourVector1 + fourVector2).Pt();
3902 +  }
3903 +  else if(variable == "threeDAngle")
3904 +    {
3905 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3906 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3907 +      value = (threeVector1.Angle(threeVector2));
3908 +    }
3909 +  else if(variable == "chargeProduct"){
3910 +    value = object1->charge*object2->charge;
3911 +  }
3912 +
3913 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3914 +  value = applyFunction(function, value);
3915 +
3916 +  return value;
3917 + }
3918 +
3919 + //!electron-track pair valueLookup
3920 + double
3921 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3922 +  double electronMass = 0.000511;
3923 +  double value = 0.0;
3924 +  TLorentzVector fourVector1(0, 0, 0, 0);
3925 +  TLorentzVector fourVector2(0, 0, 0, 0);
3926 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3927 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3928 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3929 +  else if(variable == "invMass"){
3930 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3931 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3932 +
3933 +    value = (fourVector1 + fourVector2).M();
3934 +  }
3935 +  else if(variable == "chargeProduct"){
3936 +    value = object1->charge*object2->charge;
3937 +  }
3938 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3939 +  value = applyFunction(function, value);
3940 +  return value;
3941 +
3942 + }
3943 +
3944 +
3945 + //!muon-track pair valueLookup
3946 + double
3947 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3948 +  double pionMass = 0.140;
3949 +  double muonMass = 0.106;
3950 +  double value = 0.0;
3951 +  TLorentzVector fourVector1(0, 0, 0, 0);
3952 +  TLorentzVector fourVector2(0, 0, 0, 0);
3953 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3954 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3955 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3956 +  else if(variable == "invMass"){
3957 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3958 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3959 +
3960 +    value = (fourVector1 + fourVector2).M();
3961 +  }
3962 +  else if(variable == "chargeProduct"){
3963 +    value = object1->charge*object2->charge;
3964 +  }
3965 +
3966 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3967 +  value = applyFunction(function, value);
3968 +  return value;
3969 + }
3970 +
3971 + //!tau-tau pair valueLookup
3972 + double
3973 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3974 +  double value = 0.0;
3975 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3976 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3977 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3978 +  else if(variable == "invMass"){
3979 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3980 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3981 +    value = (fourVector1 + fourVector2).M();
3982 +  }
3983 +
3984 +  else if(variable == "chargeProduct"){
3985 +    value = object1->charge*object2->charge;
3986 +  }
3987 +
3988 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3989 +  value = applyFunction(function, value);
3990 +  return value;
3991 + }
3992 +
3993 + //!muon-tau pair valueLookup
3994 + double
3995 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3996 +  double value = 0.0;
3997 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3998 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3999 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4000 +  else if(variable == "invMass"){
4001 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
4002 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
4003 +    value = (fourVector1 + fourVector2).M();
4004 +  }
4005 +
4006 +  else if(variable == "chargeProduct"){
4007 +    value = object1->charge*object2->charge;
4008 +  }
4009 +
4010 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4011 +  value = applyFunction(function, value);
4012 +  return value;
4013 + }
4014 +
4015 + //!tau-track pair valueLookup
4016 + double
4017 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
4018 +  double value = 0.0;
4019 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
4020 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4021 +  else if(variable == "chargeProduct"){
4022 +    value = object1->charge*object2->charge;
4023 +  }
4024 +
4025 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4026 +  value = applyFunction(function, value);
4027 +  return value;
4028 + }
4029 +
4030 +
4031 + //!track-event pair valueLookup
4032 + double
4033 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
4034 +
4035 +  double value = 0.0;
4036 +  double pMag = sqrt(object1->pt * object1->pt +
4037 +                     object1->pz * object1->pz);
4038 +
4039 +  if      (variable == "numPV")                      value = object2->numPV;
4040 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
4041 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
4042 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
4043 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
4044 +
4045 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4046 +
4047 +  value = applyFunction(function, value);
4048 +
4049 +  return value;
4050 +
4051 + }
4052 +
4053 + //!electron-trigobj pair valueLookup
4054 + double
4055 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
4056 +
4057 +  double value = 0.0;
4058 +
4059 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4060 +  else if (variable == "match"){
4061 +    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
4062 +      stringValue = object2->filter;
4063 +    else
4064 +      stringValue = "none";
4065 +  }
4066 +
4067 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4068 +
4069 +  value = applyFunction(function, value);
4070 +
4071 +  return value;
4072 +
4073 + }
4074 +
4075 + //!muon-trigobj pair valueLookup
4076 + double
4077 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
4078 +
4079 +  double value = 0.0;
4080 +
4081 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4082 +
4083 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4084 +
4085 +  value = applyFunction(function, value);
4086 +
4087 +  return value;
4088 +
4089 + }
4090 +
4091 + //!stop valueLookup
4092 + double
4093 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
4094 +
4095 +
4096 +  double value = 0.0;
4097 +
4098 +  if(variable == "ctau") value = object->ctau;
4099 +
4100 +  else if (variable == "d0"){
4101 +    double vx = object->vx - chosenVertex ()->x,
4102 +      vy = object->vy - chosenVertex ()->y,
4103 +      px = object->px,
4104 +      py = object->py,
4105 +      pt = object->pt;
4106 +    value = (-vx * py + vy * px) / pt;
4107 +  }
4108 +
4109 +  else if (variable == "dz"){
4110 +    double vx = object->vx - chosenVertex ()->x,
4111 +      vy = object->vy - chosenVertex ()->y,
4112 +      vz = object->vz - chosenVertex ()->z,
4113 +      px = object->px,
4114 +      py = object->py,
4115 +      pz = object->pz,
4116 +      pt = object->pt;
4117 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
4118 +  }
4119 +
4120 +  else if (variable == "minD0"){
4121 +    double minD0=999;
4122 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4123 +      double vx = object->vx - vertex->x,
4124 +        vy = object->vy - vertex->y,
4125 +        px = object->px,
4126 +        py = object->py,
4127 +        pt = object->pt;
4128 +      value = (-vx * py + vy * px) / pt;
4129 +      if(abs(value) < abs(minD0)) minD0 = value;
4130 +    }
4131 +    value = minD0;
4132 +  }
4133 +  else if (variable == "minDz"){
4134 +    double minDz=999;
4135 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4136 +      double vx = object->vx - vertex->x,
4137 +        vy = object->vy - vertex->y,
4138 +        vz = object->vz - vertex->z,
4139 +        px = object->px,
4140 +        py = object->py,
4141 +        pz = object->pz,
4142 +        pt = object->pt;
4143 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
4144 +      if(abs(value) < abs(minDz)) minDz = value;
4145 +    }
4146 +    value = minDz;
4147 +  }
4148 +  else if(variable == "distToVertex"){
4149 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4150 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4151 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4152 +  }
4153 +  else if (variable == "minDistToVertex"){
4154 +    double minDistToVertex=999;
4155 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4156 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4157 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4158 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
4159 +
4160 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4161 +    }
4162 +    value = minDistToVertex;
4163 +  }
4164 +  else if (variable == "distToVertexDifference"){
4165 +    double minDistToVertex=999;
4166 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4167 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4168 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4169 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
4170 +
4171 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4172 +    }
4173 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4174 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4175 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4176 +
4177 +    value = distToChosenVertex - minDistToVertex;
4178 +  }
4179 +
4180 +  else if (variable == "closestVertexRank"){
4181 +    double minDistToVertex=999;
4182 +    int vertex_rank = 0;
4183 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4184 +      vertex_rank++;
4185 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4186 +                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
4187 +                      (object->vz-vertex->z)*(object->vz-vertex->z));
4188 +
4189 +      if(abs(dist) < abs(minDistToVertex)){
4190 +        value = vertex_rank;
4191 +        minDistToVertex = dist;
4192 +      }
4193 +    }
4194 +  }
4195 +
4196 +  else if (variable == "decaysToTau"){
4197 +    value = abs (object->daughter0Id) == 15 || abs (object->daughter1Id) == 15;
4198 +  }
4199 +
4200 +
4201 +
4202 +
4203 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4204 +
4205 +  value = applyFunction(function, value);
4206 +
4207 +  return value;
4208 +
4209 + } // end stop valueLookup
4210 +
4211 +
4212 +
4213 +
4214 +
4215 + // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
4216 + // Return true iff no other tracks are found in this cone.
4217 + int
4218 + OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
4219 +  for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
4220 +    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
4221 +    double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
4222 +    if(deltaRtrk < 0.5) return 0;
4223 +  }
4224 +  return 1;
4225 +
4226 + }
4227 +
4228 + //calculate the scalar sum of Jet Pt in the event.
4229 + double
4230 + OSUAnalysis::getHt (const BNjetCollection* jetColl){
4231 +  double Ht = 0;
4232 +  for(BNjetCollection::const_iterator jet = jetColl->begin(); jet !=jetColl->end(); jet++){
4233 +    Ht += abs(jet->pt);
4234 +  }
4235 +  return Ht;
4236 + }
4237 +
4238 + double
4239 + OSUAnalysis::getTrkPtRes (const BNtrack* track1){
4240 +
4241 +  double ptTrue = getTrkPtTrue(track1, mcparticles.product());
4242 +  double PtRes = (track1->pt - ptTrue) / ptTrue;
4243 +
4244 +  return PtRes;
4245 +
4246 + }
4247 +
4248 +
4249 + double
4250 + OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
4251 +  double value = -99;
4252 +  double genDeltaRLowest = 999;
4253 +
4254 +  for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
4255 +    double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
4256 +    if (genDeltaRtemp < genDeltaRLowest) {
4257 +      genDeltaRLowest = genDeltaRtemp;
4258 +      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
4259 +        double ptTrue = genPart->pt;
4260 +        value = ptTrue;
4261 +      }
4262 +    }
4263 +  }
4264 +
4265 +  return value;
4266 +
4267 + }
4268 +
4269 + double
4270 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
4271 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
4272 +  if (!useTrackCaloRhoCorr_) return -99;
4273 +  // if (!rhokt6CaloJetsHandle_) {
4274 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
4275 +  //   return -99;
4276 +  // }
4277 +  double radDeltaRCone = 0.5;
4278 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
4279 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
4280 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
4281 +  return caloTotRhoCorrCalo;
4282 +
4283 + }
4284 +
4285 + double
4286 + OSUAnalysis::getTrkDepTrkRp5RhoCorr(const BNtrack* track) {
4287 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.              
4288 +  if (!useTrackCaloRhoCorr_) return -99;
4289 +  // if (!rhokt6CaloJetsHandle_) {                                                                                                    
4290 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;                        
4291 +  //   return -99;                                                                                                                    
4292 +  // }                                                                                                                                
4293 +  double radDeltaRCone = 0.5;
4294 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.                                                                                                          
4295 +  double rawDepTrkRp5 = track->depTrkRp5;
4296 + double depTrkRp5RhoCorr = TMath::Max(0., rawDepTrkRp5 - rhoCorr_kt6CaloJets);
4297 + return depTrkRp5RhoCorr;
4298 +
4299 + }
4300 +
4301 + double
4302 + OSUAnalysis::getTrkDepTrkRp3RhoCorr(const BNtrack* track) {
4303 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.                                                
4304 +  if (!useTrackCaloRhoCorr_) return -99;
4305 +  // if (!rhokt6CaloJetsHandle_) {                                                                                                                                      
4306 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;                                                          
4307 +  //   return -99;                                                                                                                                                      
4308 +  // }                                                                                                                                                                  
4309 +  double radDeltaRCone = 0.3;
4310 + // Define effective area as pi*r^2, where r is radius of DeltaR cone
4311 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  
4312 +  double rawDepTrkRp3 = track->depTrkRp3;
4313 +  double depTrkRp3RhoCorr = TMath::Max(0., rawDepTrkRp3 - rhoCorr_kt6CaloJets);
4314 +  return depTrkRp3RhoCorr;
4315 +  
4316 + }
4317 +
4318 +
4319 +
4320 +
4321 + //creates a map of the dead Ecal channels in the barrel and endcap
4322 + //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
4323 + //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
4324 + void
4325 + OSUAnalysis::WriteDeadEcal (){
4326 +  double etaEcal, phiEcal;
4327 +  ifstream DeadEcalFile(deadEcalFile_);
4328 +  if(!DeadEcalFile) {
4329 +    clog << "Error: DeadEcalFile has not been found." << endl;
4330 +    return;
4331 +  }
4332 +  if(DeadEcalVec.size()!= 0){
4333 +    clog << "Error: DeadEcalVec has a nonzero size" << endl;
4334 +    return;
4335 +  }
4336 +  while(!DeadEcalFile.eof())
4337 +    {
4338 +      DeadEcalFile >> etaEcal >> phiEcal;
4339 +      DeadEcal newChan;
4340 +      newChan.etaEcal = etaEcal;
4341 +      newChan.phiEcal = phiEcal;
4342 +      DeadEcalVec.push_back(newChan);
4343 +    }
4344 +  if(DeadEcalVec.size() == 0) clog << "Warning: No dead Ecal channels have been found." << endl;
4345 + }
4346 +
4347 + //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
4348 + int
4349 + OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
4350 +  double deltaRLowest = 999;
4351 +  int value = 0;
4352 +  if (DeadEcalVec.size() == 0) WriteDeadEcal();
4353 +  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4354 +    double eta = ecal->etaEcal;
4355 +    double phi = ecal->phiEcal;
4356 +    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
4357 +    if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
4358 +  }
4359 +  if (deltaRLowest<0.05) {value = 1;}
4360 +  else {value = 0;}
4361 +  return value;
4362 + }
4363 +
4364 + // Returns the smallest DeltaR between the object and any generated true particle in the event.
4365 + template <class InputObject>
4366 + double OSUAnalysis::getGenDeltaRLowest(InputObject object){
4367 +  double genDeltaRLowest = 999.;
4368 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4369 +    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
4370 +    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
4371 +  }
4372 +  return genDeltaRLowest;
4373 + }
4374  
4375   double
4376   OSUAnalysis::applyFunction(string function, double value){
4377  
4378 <  if(function == "abs") value = abs(value);
4378 >  if(function == "abs") value = fabs(value);
4379 >  else if(function == "fabs") value = fabs(value);
4380 >  else if(function == "log10") value = log10(value);
4381 >  else if(function == "log") value = log10(value);
4382  
4383 +  else if(function == "") value = value;
4384 +  else{clog << "WARNING: invalid function '" << function << "'\n";}
4385  
4386    return value;
4387  
# Line 1446 | Line 4391 | OSUAnalysis::applyFunction(string functi
4391   template <class InputCollection>
4392   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
4393  
4394 +  if (verbose_>2) clog << "  Beginning setObjectFlags for cut " << currentCutIndex << ": " << currentCut.name
4395 +                       << ", inputType=" << inputType
4396 +                       << endl;  
4397 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
4398 +    string obj1, obj2;
4399 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
4400 +    if (verbose_>2) clog << "  Two object types:  " << obj1 << ", " << obj2 << endl;
4401 +    if (inputType==obj1 ||
4402 +        inputType==obj2) {
4403 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
4404 +      // and the inputType is a member of the pair.
4405 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
4406 +      // For example, if currentCut.inputCollection==electron-muon pairs,
4407 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
4408 +      return;
4409 +    }
4410 +  }
4411 +
4412 +  if (!inputCollection) cout << "ERROR:  invalid input collection for inputType=" << inputType << endl;  
4413 +
4414 +  if (verbose_>3) clog << "   Collection size:  " << inputCollection->size() << endl;
4415  
4416    for (uint object = 0; object != inputCollection->size(); object++){
4417  
4418 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
4418 >    if (verbose_>4) clog << "    Setting flags for object " << object << endl;
4419 >
4420 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4421 >    bool plotDecision = true;
4422  
4423      if(currentCut.inputCollection == inputType){
4424  
4425 <      double value = valueLookup(&inputCollection->at(object), currentCut.variable, currentCut.function);
4425 >      vector<bool> subcutDecisions;
4426 >      for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4427 >        string stringValue = "";
4428 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4429 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4430 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4431  
4432 <      decision = evaluateComparison(value,currentCut.comparativeOperator,currentCut.cutValue);
4432 >      }
4433 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4434 >      else{
4435 >        bool tempDecision = true;
4436 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4437 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4438 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4439 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4440 >            tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4441 >        }
4442 >        cutDecision = tempDecision;
4443 >      }
4444 >      //invert the cut if this cut is a veto
4445 >      if(currentCut.isVeto) cutDecision = !cutDecision;
4446 >      plotDecision = cutDecision;
4447      }
1460    individualFlags[inputType].at(currentCutIndex).push_back(decision);
4448  
4449 +    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4450  
4451 <    //set flags for objects that pass each cut AND all the previous cuts
4452 <    bool previousCumulativeFlag = true;
4451 >    //set flags for objects that pass this cut AND all the previous cuts
4452 >    bool previousCumulativeCutFlag = true;
4453      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4454 <      if(previousCumulativeFlag && individualFlags[inputType].at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4455 <      else{ previousCumulativeFlag = false; break;}
4454 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4455 >      else{ previousCumulativeCutFlag = false; break;}
4456 >    }
4457 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4458 >    bool previousCumulativePlotFlag = true;
4459 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4460 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4461 >      else{ previousCumulativePlotFlag = false; break;}
4462 >    }
4463 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4464 >
4465 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4466 >
4467 >  }  //   for (uint object = 0; object != inputCollection->size(); object++){
4468 >
4469 > } // end void OSUAnalysis::setObjectFlags
4470 >
4471 >
4472 > template <class InputCollection1, class InputCollection2>
4473 > void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags,
4474 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, string inputType){
4475 >  // This function sets the flags for the paired object collection.  
4476 >  // If the cut is applying on the given paired object collection, then the flags for the single object collections are also set.
4477 >  // If not, then the flags for the paired object collection are taken as the AND of the flags for each single object collection.  
4478 >
4479 >  if (verbose_>2) clog << "  Beginning setObjectFlags for cut=" << currentCut.name
4480 >                       << ", inputType=" << inputType
4481 >                       << endl;  
4482 >
4483 >  bool sameObjects = false;
4484 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;  // FIXME:  is sameObjects just the not of isTwoTypesOfObject?  If so, it's redundant.  
4485 >
4486 >  // Get the strings for the two objects that make up the pair.
4487 >  string obj1Type, obj2Type;
4488 >  getTwoObjs(inputType, obj1Type, obj2Type);
4489 >  bool isTwoTypesOfObject = true;
4490 >  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
4491 >
4492 >  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
4493 >  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4494 >  if (currentCut.inputCollection == inputType) {
4495 >    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4496 >      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4497 >      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4498      }
4499 <    cumulativeFlags[inputType].at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4499 >    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4500 >      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4501 >        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4502 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4503 >      }
4504 >    }
4505 >  }
4506 >
4507 >  int counter = 0;
4508 >
4509 >  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4510 >    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4511 >
4512 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4513 >
4514 >
4515 >      bool cutDecision  = true;//object passes if this cut doesn't cut on that type of object
4516 >      bool plotDecision = true;
4517 >
4518 >      // Determine whether each pair passes the cut, only if inputCollection is the same as the inputType.  
4519 >      if(currentCut.inputCollection == inputType){
4520 >
4521 >        vector<bool> subcutDecisions;
4522 >        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4523 >          string stringValue = "";
4524 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4525 >          if (verbose_>1) clog << currentCut.variables.at(subcutIndex) << " = " << value
4526 >                               << endl;  
4527 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4528 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4529 >        }
4530 >
4531 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4532 >        else{
4533 >          bool tempDecision = subcutDecisions.at(0);
4534 >          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
4535 >            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
4536 >              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
4537 >            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4538 >              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4539 >          }
4540 >          cutDecision = tempDecision;
4541 >        }
4542 >        //invert the cut if this cut is a veto
4543 >        if (currentCut.isVeto) cutDecision = !cutDecision;
4544 >        plotDecision = cutDecision;
4545 >
4546 >        if (verbose_>1) clog << " cutDecision = " << cutDecision
4547 >                             << "; for currentCut.inputCollection = " << currentCut.inputCollection
4548 >                             << "; object1 (" << obj1Type << ") = " << object1
4549 >                             << "; object2 (" << obj2Type << ") = " << object2
4550 >                             << endl;  
4551 >        
4552 >        if (cutDecision) {  // only set the flags for the individual objects if the pair object is being cut on
4553 >          individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4554 >          individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4555 >        }
4556 >        if (plotDecision) {  // only set the flags for the individual objects if the pair object is being cut on
4557 >          individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4558 >          individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4559 >        }
4560 >        
4561 >
4562 >      } // if(currentCut.inputCollection == inputType){
4563 >
4564 >      // The individualFlags will be true if the inputCollection is not the same as the inputType.
4565 >      // They are also independent of the previous flags on the single objects.  
4566 >      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));  
4567 >
4568 >
4569 >
4570 >      // ************************************
4571 >      // Determine cumulative flags
4572 >      // ************************************
4573 >      // determine whether this paired object passes this cut AND all previous cuts
4574 >      bool previousCumulativeCutFlag = true;
4575 >      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4576 >        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4577 >        else{ previousCumulativeCutFlag = false; break;}
4578 >      }
4579 >      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4580 >
4581 >      bool previousCumulativePlotFlag = true;
4582 >      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4583 >        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4584 >        else{ previousCumulativePlotFlag = false; break;}
4585 >      }
4586 >      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4587 >      
4588 >      // Get the index for the flags of each of the single objects in the pair.  Usually this is the index of the previous cut, i.e., currentCutIndex-1.    
4589 >      int cutIdxFlagsObj1 = max(int(currentCutIndex-1),0);
4590 >      int cutIdxFlagsObj2 = max(int(currentCutIndex-1),0);
4591 >      // If the inputCollection of the cut is not equal to the inputType but the inputCollection includes objects that are contained in inputType, then use the currentCutIndex for those collections.
4592 >      // For example, if the inputType is jet-jet pairs, and the inputCollection is track-jet pairs, then use currentCutIndex for cutIdxFlagsObj{1,2}, i.e., for both jets.  
4593 >      // For example, if the inputType is jets, and the inputCollection is track-jet pairs, then use currentCutIndex for cutIdxFlagsObj2 (jets) and currentCutIndex-1 for cutIdxFlagsObj1 (tracks).  
4594 >      if (currentCut.inputCollection != inputType) {  
4595 >        if (currentCut.inputCollection.find(obj1Type)!=string::npos) cutIdxFlagsObj1 = currentCutIndex;
4596 >        if (currentCut.inputCollection.find(obj2Type)!=string::npos) cutIdxFlagsObj2 = currentCutIndex;
4597 >      }  
4598 >      flagPair flags1 = cumulativeFlags.at(obj1Type).at(cutIdxFlagsObj1);  // flag for input collection 1
4599 >      flagPair flags2 = cumulativeFlags.at(obj2Type).at(cutIdxFlagsObj2);  // flag for input collection 2
4600 >      
4601 >      // The cumulative flag is only true if the paired object cumulative flag is true, and if the single object cumulative flags are true.  
4602 >      bool currentCumulativeCutFlag = true;
4603 >      bool currentCumulativePlotFlag = true;
4604 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4605 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4606 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4607 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4608 >
4609 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4610 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4611 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4612 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4613 >
4614 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));  // Set the flag for the paired object
4615 >
4616 >
4617 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // Set the flags for the individual objects if the paired object is being cut on.  
4618 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first  = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4619 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first  = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4620 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4621 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4622 >
4623 >        if (verbose_>1) clog << " previousCumulativeCutFlag for object1 = " << getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object1, "cut") << endl;  
4624 >        if (verbose_>1) clog << " previousCumulativeCutFlag for object2 = " << getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut") << endl;  
4625 >
4626 >      }
4627 >
4628 >      counter++;
4629 >
4630 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4631 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4632 >
4633 > } // end void OSUAnalysis::setObjectFlags
4634 >
4635 >
4636 > bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4637 >  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4638 >  // all cuts up to currentCutIndex
4639 >  bool previousCumulativeFlag = true;
4640 >  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4641 >    bool tempFlag = false;
4642 >    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4643 >    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4644 >
4645 >    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4646 >    else {
4647 >      previousCumulativeFlag = false; break;
4648 >    }
4649 >  }
4650 >  return previousCumulativeFlag;
4651 > }
4652 >
4653 >
4654 >
4655 >
4656 > template <class InputCollection>
4657 > void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4658 >  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4659 >
4660 >  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;
4661 >  for (uint object = 0; object != inputCollection->size(); object++) {
4662 >
4663 >    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4664 >
4665 >    string inputVariable = parameters.inputVariable;
4666 >    string function = "";
4667 >    string stringValue = "";
4668 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4669 >    BNTreeBranchVals_.at(parameters.name).push_back(value);
4670  
4671    }
4672 + }
4673 +
4674 +
4675 + template <class InputCollection>
4676 + void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4677 +
4678 +  if (verbose_>2) clog << "  Filling histogram for " << parameters.name << endl;  
4679 +
4680 +  for (uint object = 0; object != inputCollection->size(); object++){
4681 +
4682 +    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4683 +
4684 +    string currentString = parameters.inputVariables.at(0);
4685 +    string inputVariable = "";
4686 +    string function = "";
4687 +    if(currentString.find("(")==string::npos){
4688 +      inputVariable = currentString;// variable to cut on
4689 +    }
4690 +    else{
4691 +      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4692 +      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4693 +      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4694 +    }
4695 +
4696 +    string stringValue = "";
4697 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4698 +    histo->Fill(value,scaleFactor);
4699 +
4700 +    if (printEventInfo_) {
4701 +      // Write information about event to screen, for testing purposes.
4702 +      clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << " (object number " << object << ")" << endl;
4703 +    }
4704 +
4705 +  }
4706 + }
4707 +
4708 + template <class InputCollection1, class InputCollection2>
4709 + void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2,
4710 +                                  flagPair pairFlags, double scaleFactor){
4711 +
4712 +  bool sameObjects = false;
4713 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4714 +
4715 +  int pairCounter = -1;
4716 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4717 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4718 +
4719 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4720 +
4721 +      pairCounter++;
4722 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4723 +
4724 +      string currentString = parameters.inputVariables.at(0);
4725 +      string inputVariable = "";
4726 +      string function = "";
4727 +      if(currentString.find("(")==string::npos){
4728 +        inputVariable = currentString;// variable to cut on
4729 +      }
4730 +      else{
4731 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4732 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4733 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4734 +      }
4735 +
4736 +      string stringValue = "";
4737 +      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4738 +      histo->Fill(value,scaleFactor);
4739 +
4740 +      if (printEventInfo_) {
4741 +        // Write information about event to screen, for testing purposes.
4742 +        clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value
4743 +             << " (object1 number " << object1 << "), "
4744 +             << " (object2 number " << object2 << ")"
4745 +             << endl;
4746 +      }
4747 +      
4748 +    }
4749 +  }
4750  
4751   }
4752  
4753  
4754 + template <class InputCollection>
4755 + void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4756  
4757 +  for (uint object = 0; object != inputCollection->size(); object++){
4758  
4759 +    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4760  
4761 < DEFINE_FWK_MODULE(OSUAnalysis);
4761 >    string stringValue = "";
4762 >    string currentString = parameters.inputVariables.at(0);
4763 >    string inputVariable = "";
4764 >    string function = "";
4765 >    if(currentString.find("(")==string::npos){
4766 >      inputVariable = currentString;// variable to cut on
4767 >    }
4768 >    else{
4769 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4770 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4771 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4772 >    }
4773 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4774 >
4775 >    currentString = parameters.inputVariables.at(1);
4776 >    inputVariable = "";
4777 >    function = "";
4778 >    if(currentString.find("(")==string::npos){
4779 >      inputVariable = currentString;// variable to cut on
4780 >    }
4781 >    else{
4782 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4783 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4784 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4785 >    }
4786 >
4787 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4788 >
4789 >    histo->Fill(valueX,valueY,scaleFactor);
4790 >
4791 >  }
4792 >
4793 > }
4794 >
4795 > template <class InputCollection1, class InputCollection2>
4796 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2,
4797 >                                  flagPair pairFlags, double scaleFactor){
4798 >
4799 >  bool sameObjects = false;
4800 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4801 >
4802 >  int pairCounter = -1;
4803 >  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4804 >    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4805 >
4806 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4807 >
4808 >      pairCounter++;
4809 >
4810 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4811 >
4812 >      string stringValue = "";
4813 >      string currentString = parameters.inputVariables.at(0);
4814 >      string inputVariable = "";
4815 >      string function = "";
4816 >      if(currentString.find("(")==string::npos){
4817 >        inputVariable = currentString;// variable to cut on
4818 >      }
4819 >      else{
4820 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4821 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4822 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4823 >      }
4824 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4825 >
4826 >      currentString = parameters.inputVariables.at(1);
4827 >      inputVariable = "";
4828 >      function = "";
4829 >      if(currentString.find("(")==string::npos){
4830 >        inputVariable = currentString;// variable to cut on
4831 >      }
4832 >      else{
4833 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4834 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4835 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4836 >      }
4837 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4838 >
4839 >
4840 >      histo->Fill(valueX,valueY,scaleFactor);
4841 >
4842 >    }
4843 >  }
4844 >
4845 > }
4846 >
4847 >
4848 > template <class InputObject>
4849 > int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
4850 >
4851 >  int bestMatchIndex = -1;
4852 >  double bestMatchDeltaR = 999;
4853 >
4854 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4855 >
4856 >    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4857 >    if(currentDeltaR > 0.05) continue;
4858 >    //     clog << setprecision(3) << setw(20)
4859 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4860 >    //          << setw(20)
4861 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4862 >    //          << setw(20)
4863 >    //          << "\tdeltaR = " << currentDeltaR
4864 >    //          << setprecision(1)
4865 >    //          << setw(20)
4866 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4867 >    //          << setw(20)
4868 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4869 >    //          << setw(20)
4870 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4871 >    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4872 >      bestMatchIndex = mcparticle - mcparticles->begin();
4873 >      bestMatchDeltaR = currentDeltaR;
4874 >    }
4875 >
4876 >  }
4877 >  //   if(bestMatchDeltaR != 999)  clog << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4878 >  //   else clog << "no match found..." << endl;
4879 >  return bestMatchIndex;
4880 >
4881 > }
4882 >
4883 >
4884 > int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
4885 >
4886 >  int bestMatchIndex = -1;
4887 >  double bestMatchDeltaR = 999;
4888 >
4889 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4890 >
4891 >    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
4892 >
4893 >    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
4894 >    if(currentDeltaR > 0.05) continue;
4895 >
4896 >    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4897 >      bestMatchIndex = mcparticle - mcparticles->begin();
4898 >      bestMatchDeltaR = currentDeltaR;
4899 >    }
4900 >
4901 >  }
4902 >
4903 >  return bestMatchIndex;
4904 > }
4905 >
4906 >
4907 > // bin      particle type
4908 > // ---      -------------
4909 > //  0        unmatched
4910 > //  1        u
4911 > //  2        d
4912 > //  3        s
4913 > //  4        c
4914 > //  5        b
4915 > //  6        t
4916 > //  7        e
4917 > //  8        mu
4918 > //  9        tau
4919 > // 10        nu
4920 > // 11        g
4921 > // 12        gamma
4922 > // 13        Z
4923 > // 14        W
4924 > // 15        light meson
4925 > // 16        K meson
4926 > // 17        D meson
4927 > // 18        B meson
4928 > // 19        light baryon
4929 > // 20        strange baryon
4930 > // 21        charm baryon
4931 > // 22        bottom baryon
4932 > // 23        QCD string
4933 > // 24        other
4934 >
4935 > int OSUAnalysis::getPdgIdBinValue(int pdgId){
4936 >
4937 >  int binValue = -999;
4938 >  int absPdgId = fabs(pdgId);
4939 >  if(pdgId == -1) binValue = 0;
4940 >  else if(absPdgId <= 6 ) binValue = absPdgId;
4941 >  else if(absPdgId == 11 ) binValue = 7;
4942 >  else if(absPdgId == 13 ) binValue = 8;
4943 >  else if(absPdgId == 15 ) binValue = 9;
4944 >  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
4945 >  else if(absPdgId == 21 ) binValue = 11;
4946 >  else if(absPdgId == 22 ) binValue = 12;
4947 >  else if(absPdgId == 23 ) binValue = 13;
4948 >  else if(absPdgId == 24 ) binValue = 14;
4949 >  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
4950 >  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
4951 >  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
4952 >  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
4953 >  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
4954 >  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4955 >  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4956 >  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4957 >  else if(absPdgId == 92  ) binValue = 23;
4958 >
4959 >  else binValue = 24;
4960 >
4961 >  return binValue;
4962 >
4963 > }
4964 >
4965 > const BNprimaryvertex *
4966 > OSUAnalysis::chosenVertex ()
4967 > {
4968 >  const BNprimaryvertex *chosenVertex = 0;
4969 >  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4970 >    flagPair vertexFlags;
4971 >    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4972 >      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4973 >        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4974 >        break;
4975 >      }
4976 >    }
4977 >    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4978 >      if(!vertexFlags.at(vertexIndex).first) continue;
4979 >      chosenVertex = & primaryvertexs->at(vertexIndex);
4980 >      break;
4981 >    }
4982 >  }
4983 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4984 >    chosenVertex = & primaryvertexs->at (0);
4985 >
4986 >  return chosenVertex;
4987 > }
4988 >
4989 > const BNmet *
4990 > OSUAnalysis::chosenMET ()
4991 > {
4992 >  const BNmet *chosenMET = 0;
4993 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4994 >    flagPair metFlags;
4995 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4996 >      if (cumulativeFlags.at("mets").at(i).size()){
4997 >        metFlags = cumulativeFlags.at("mets").at(i);
4998 >        break;
4999 >      }
5000 >    }
5001 >    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
5002 >      if(!metFlags.at(metIndex).first) continue;
5003 >      chosenMET = & mets->at(metIndex);
5004 >      break;
5005 >    }
5006 >  }
5007 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
5008 >    chosenMET = & mets->at (0);
5009 >
5010 >  return chosenMET;
5011 > }
5012 >
5013 > const BNelectron *
5014 > OSUAnalysis::chosenElectron ()
5015 > {
5016 >  const BNelectron *chosenElectron = 0;
5017 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
5018 >    flagPair electronFlags;
5019 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
5020 >      if (cumulativeFlags.at("electrons").at(i).size()){
5021 >        electronFlags = cumulativeFlags.at("electrons").at(i);
5022 >        break;
5023 >      }
5024 >    }
5025 >    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
5026 >      if(!electronFlags.at(electronIndex).first) continue;
5027 >      chosenElectron = & electrons->at(electronIndex);
5028 >      break;
5029 >    }
5030 >  }
5031 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
5032 >    chosenElectron = & electrons->at (0);
5033 >
5034 >  return chosenElectron;
5035 > }
5036 >
5037 >
5038 > const BNmuon *
5039 > OSUAnalysis::chosenMuon ()
5040 > {
5041 >  const BNmuon *chosenMuon = 0;
5042 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
5043 >    flagPair muonFlags;
5044 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
5045 >      if (cumulativeFlags.at("muons").at(i).size()){
5046 >        muonFlags = cumulativeFlags.at("muons").at(i);
5047 >        break;
5048 >      }
5049 >    }
5050 >    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
5051 >      if(!muonFlags.at(muonIndex).first) continue;
5052 >      chosenMuon = & muons->at(muonIndex);
5053 >      break;
5054 >    }
5055 >  }
5056 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
5057 >    chosenMuon = & muons->at (0);
5058 >
5059 >  return chosenMuon;
5060 > }
5061  
5062 + double
5063 + OSUAnalysis::chosenHT ()
5064 + {
5065 +  double chosenHT = 0.0;
5066 +  if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
5067 +    flagPair jetFlags;
5068 +    for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
5069 +      if (cumulativeFlags.at("jets").at(i).size()){
5070 +        jetFlags = cumulativeFlags.at("jets").at(i);
5071 +        break;
5072 +      }
5073 +    }
5074 +    for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
5075 +      if(!jetFlags.at(jetIndex).first) continue;
5076 +      chosenHT += jets->at(jetIndex).pt;
5077 +    }
5078 +  }
5079 +
5080 +  return chosenHT;
5081 + }
5082  
5083 + pair<const BNmuon *, const BNmuon *>
5084 + OSUAnalysis::leadMuonPair ()
5085 + {
5086 +  pair<const BNmuon *, const BNmuon *> leadMuonPair;
5087 +  leadMuonPair.first = leadMuonPair.second = 0;
5088 +
5089 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
5090 +    flagPair muonFlags;
5091 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
5092 +      if (cumulativeFlags.at("muons").at(i).size()){
5093 +        muonFlags = cumulativeFlags.at("muons").at(i);
5094 +        break;
5095 +      }
5096 +    }
5097 +    for (uint muonIndex0 = 0; muonIndex0 != muonFlags.size(); muonIndex0++){
5098 +      if(!muonFlags.at(muonIndex0).first) continue;
5099 +      for (uint muonIndex1 = muonIndex0 + 1; muonIndex1 < muonFlags.size(); muonIndex1++){
5100 +        if(!muonFlags.at(muonIndex1).first) continue;
5101 +        const BNmuon *mu0 = & muons->at(muonIndex0);
5102 +        const BNmuon *mu1 = & muons->at(muonIndex1);
5103 +        if(leadMuonPair.first == 0 || leadMuonPair.second == 0){
5104 +          leadMuonPair.first = mu0;
5105 +          leadMuonPair.second = mu1;
5106 +        }
5107 +        else{
5108 +          TVector2 newPt0 (mu0->px, mu0->py),
5109 +                   newPt1 (mu1->px, mu1->py),
5110 +                   oldPt0 (leadMuonPair.first->px, leadMuonPair.first->py),
5111 +                   oldPt1 (leadMuonPair.second->px, leadMuonPair.second->py);
5112 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
5113 +            {
5114 +              leadMuonPair.first = mu0;
5115 +              leadMuonPair.second = mu1;
5116 +            }
5117 +        }
5118 +      }
5119 +    }
5120 +  }
5121 +
5122 +  return leadMuonPair;
5123 + }
5124 +
5125 + pair<const BNelectron *, const BNelectron *>
5126 + OSUAnalysis::leadElectronPair ()
5127 + {
5128 +  pair<const BNelectron *, const BNelectron *> leadElectronPair;
5129 +  leadElectronPair.first = leadElectronPair.second = 0;
5130 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
5131 +    flagPair electronFlags;
5132 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
5133 +      if (cumulativeFlags.at("electrons").at(i).size()){
5134 +        electronFlags = cumulativeFlags.at("electrons").at(i);
5135 +        break;
5136 +      }
5137 +    }
5138 +    for (uint electronIndex0 = 0; electronIndex0 != electronFlags.size(); electronIndex0++){
5139 +      if(!electronFlags.at(electronIndex0).first) continue;
5140 +      for (uint electronIndex1 = electronIndex0 + 1; electronIndex1 < electronFlags.size(); electronIndex1++){
5141 +        if(!electronFlags.at(electronIndex1).first) continue;
5142 +        const BNelectron *el0 = & electrons->at(electronIndex0);
5143 +        const BNelectron *el1 = & electrons->at(electronIndex1);
5144 +        if(leadElectronPair.first == 0 || leadElectronPair.second == 0){
5145 +          leadElectronPair.first = el0;
5146 +          leadElectronPair.second = el1;
5147 +        }
5148 +        else{
5149 +          TVector2 newPt0 (el0->px, el0->py),
5150 +                   newPt1 (el1->px, el1->py),
5151 +                   oldPt0 (leadElectronPair.first->px, leadElectronPair.first->py),
5152 +                   oldPt1 (leadElectronPair.second->px, leadElectronPair.second->py);
5153 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
5154 +            {
5155 +              leadElectronPair.first = el0;
5156 +              leadElectronPair.second = el1;
5157 +            }
5158 +        }
5159 +      }
5160 +    }
5161 +  }
5162 +
5163 +  return leadElectronPair;
5164 + }
5165 +
5166 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines