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.76 by wulsin, Fri May 31 09:42:10 2013 UTC

# Line 11 | Line 11 | OSUAnalysis::OSUAnalysis (const edm::Par
11    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
12    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
13    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
14 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
15    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
16    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
17    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
18    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
19    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
20 +  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 +  treeBranchSets_   (cfg.getParameter<vector<edm::ParameterSet> >("treeBranchSets")),
32 +  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
33 +  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
34 +  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
35 +  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
36 +  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
37 +  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
38 +  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
39 + {
40  
41 +  TH1::SetDefaultSumw2 ();
42  
43 <  channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels"))
43 >  //create pile-up reweighting object, if necessary
44 >  if(datasetType_ != "data") {
45 >    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
46 >    if (applyLeptonSF_){
47 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
48 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
49 >    }
50 >  }
51 >  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
52 >    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
53  
23 {
24  TH1::SetDefaultSumw2 ();
54  
55    // Construct Cutflow Objects. These store the results of cut decisions and
56    // handle filling cut flow histograms.
57    masterCutFlow_ = new CutFlow (fs_);
58 <  std::vector<TFileDirectory> directories;
58 >
59 >  //always get vertex collection so we can assign the primary vertex in the event
60 >  objectsToGet.push_back("primaryvertexs");
61 >  objectsToPlot.push_back("primaryvertexs");
62 >  objectsToCut.push_back("primaryvertexs");
63 >
64 >
65 >  //always get the MC particles to do GEN-matching
66 >  objectsToGet.push_back("mcparticles");
67 >
68 >  //always get the event collection to do pile-up reweighting
69 >  objectsToGet.push_back("events");
70 >
71 >
72 >  // Parse the tree variable definitions.    
73 >  for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++) {
74 >    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
75 >    if(tempInputCollection.find("pairs")!=string::npos) { cout << "Warning:  tree filling is not configured for pairs of objects, so will not work for collection: " << tempInputCollection << endl; }  
76 >    objectsToGet.push_back(tempInputCollection);
77 >    objectsToCut.push_back(tempInputCollection);
78 >
79 >    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
80 >
81 >    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
82 >      BranchSpecs br;
83 >      br.inputCollection = tempInputCollection;
84 >      br.inputVariable = branchList.at(iBranch);  
85 >      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);  
86 >      br.name = string(newName.Data());  
87 >      treeBranches_.push_back(br);
88 >    }  
89 >
90 >  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++) {
91 >
92 >
93 >  //parse the histogram definitions
94 >  for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
95 >
96 >    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
97 >    if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
98 >    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
99 >    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
100 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
101 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
102 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
103 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
104 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
105 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
106 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
107 >        int spaceIndex = tempInputCollection.find(" ");
108 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
109 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
110 >      }
111 >      else{
112 >        objectsToGet.push_back(tempInputCollection);
113 >      }
114 >      objectsToPlot.push_back(tempInputCollection);
115 >      objectsToCut.push_back(tempInputCollection);
116 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
117 >      string obj1;
118 >      string obj2;
119 >      getTwoObjs(tempInputCollection, obj1, obj2);
120 >      string obj2ToGet = getObjToGet(obj2);
121 >      objectsToCut.push_back(tempInputCollection);
122 >      objectsToCut.push_back(obj1);
123 >      objectsToCut.push_back(obj2);
124 >      objectsToPlot.push_back(tempInputCollection);
125 >      objectsToPlot.push_back(obj1);
126 >      objectsToPlot.push_back(obj2);
127 >      objectsToGet.push_back(tempInputCollection);
128 >      objectsToGet.push_back(obj1);
129 >      objectsToGet.push_back(obj2ToGet);
130 >    } // end else
131 >
132 >
133 >
134 >    vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
135 >
136 >    for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
137 >
138 >      vector<double> defaultValue;
139 >      defaultValue.push_back (-1.0);
140 >
141 >      histogram tempHistogram;
142 >      tempHistogram.inputCollection = tempInputCollection;
143 >      tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
144 >      tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
145 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
146 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
147 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
148 >      tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
149 >
150 >      histograms.push_back(tempHistogram);
151 >
152 >    }
153 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
154 >
155 >  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
156 >  sort( objectsToPlot.begin(), objectsToPlot.end() );
157 >  objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
158 >
159 >
160 >
161 >  //add histograms with the gen-matched id, mother id, and grandmother id
162 >  for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
163 >
164 >    string currentObject = objectsToPlot.at(currentObjectIndex);
165 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
166 >
167 >    histogram tempIdHisto;
168 >    histogram tempMomIdHisto;
169 >    histogram tempGmaIdHisto;
170 >    histogram tempIdVsMomIdHisto;
171 >    histogram tempIdVsGmaIdHisto;
172 >
173 >    tempIdHisto.inputCollection = currentObject;
174 >    tempMomIdHisto.inputCollection = currentObject;
175 >    tempGmaIdHisto.inputCollection = currentObject;
176 >    tempIdVsMomIdHisto.inputCollection = currentObject;
177 >    tempIdVsGmaIdHisto.inputCollection = currentObject;
178 >
179 >    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
180 >    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
181 >
182 >    currentObject = currentObject.substr(0, currentObject.size()-1);
183 >    tempIdHisto.name = currentObject+"GenMatchId";
184 >    tempMomIdHisto.name = currentObject+"GenMatchMotherId";
185 >    tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
186 >    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
187 >    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
188 >
189 >    currentObject.at(0) = toupper(currentObject.at(0));
190 >    tempIdHisto.title = currentObject+" Gen-matched Particle";
191 >    tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
192 >    tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
193 >    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
194 >    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
195 >
196 >
197 >    int maxNum = 25;
198 >    vector<double> binVector;
199 >    binVector.push_back(maxNum);
200 >    binVector.push_back(0);
201 >    binVector.push_back(maxNum);
202 >
203 >    tempIdHisto.bins = binVector;
204 >    tempIdHisto.inputVariables.push_back("genMatchedId");
205 >    tempMomIdHisto.bins = binVector;
206 >    tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
207 >    tempGmaIdHisto.bins = binVector;
208 >    tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
209 >    binVector.push_back(maxNum);
210 >    binVector.push_back(0);
211 >    binVector.push_back(maxNum);
212 >    tempIdVsMomIdHisto.bins = binVector;
213 >    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
214 >    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
215 >    tempIdVsGmaIdHisto.bins = binVector;
216 >    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
217 >    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
218 >
219 >    histograms.push_back(tempIdHisto);
220 >    histograms.push_back(tempMomIdHisto);
221 >    histograms.push_back(tempGmaIdHisto);
222 >    histograms.push_back(tempIdVsMomIdHisto);
223 >    histograms.push_back(tempIdVsGmaIdHisto);
224 >  }
225  
226  
227    channel tempChannel;
# Line 41 | Line 236 | OSUAnalysis::OSUAnalysis (const edm::Par
236      //set triggers for this channel
237      vector<string> triggerNames;
238      triggerNames.clear();
239 +    vector<string> triggerToVetoNames;
240 +    triggerToVetoNames.clear();
241 +
242      tempChannel.triggers.clear();
243 +    tempChannel.triggersToVeto.clear();
244      if(channels_.at(currentChannel).exists("triggers")){
245        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
246        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
247          tempChannel.triggers.push_back(triggerNames.at(trigger));
248 <      allNecessaryObjects.push_back("triggers");
248 >      objectsToGet.push_back("triggers");
249 >    }
250 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
251 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
252 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
253 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
254 >      objectsToGet.push_back("triggers");
255      }
256  
257  
258 +
259      //create cutFlow for this channel
260      cutFlows_.push_back (new CutFlow (fs_, channelName));
261 <
262 <    //book a directory in the output file with the name of the channel
57 <    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 <
261 >    vector<TFileDirectory> directories; //vector of directories in the output file.
262 >    vector<string> subSubDirNames;//subdirectories in each channel.
263      //get list of cuts for this channel
264      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
265  
105    vector<string> tempInputCollections;
106
266  
267      //loop over and parse all cuts
268      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
110
269        cut tempCut;
270 <     //store input collection for cut
271 <      string inputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
272 <      tempCut.inputCollection = inputCollection;
270 >      //store input collection for cut
271 >      string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
272 >      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
273 >      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
274 >      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
275 >      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
276 >      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
277 >      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
278 >      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
279 >      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
280 >      tempCut.inputCollection = tempInputCollection;
281 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
282 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
283 >          int spaceIndex = tempInputCollection.find(" ");
284 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
285 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
286 >        }
287 >        else{
288 >          objectsToGet.push_back(tempInputCollection);
289 >        }
290 >        objectsToCut.push_back(tempInputCollection);
291 >      }
292 >      else{//pair of objects, need to add them both to objectsToGet
293 >        string obj1;
294 >        string obj2;
295 >        getTwoObjs(tempInputCollection, obj1, obj2);
296 >        string obj2ToGet = getObjToGet(obj2);
297 >        objectsToCut.push_back(tempInputCollection);
298 >        objectsToCut.push_back(obj1);
299 >        objectsToCut.push_back(obj2);
300 >        objectsToGet.push_back(tempInputCollection);
301 >        objectsToGet.push_back(obj1);
302 >        objectsToGet.push_back(obj2ToGet);
303 >
304 >      }
305 >
306  
116      tempInputCollections.push_back(inputCollection);
117      allNecessaryObjects.push_back(inputCollection);
307  
308        //split cut string into parts and store them
309        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
310 <      std::vector<string> cutStringVector = splitString(cutString);
311 <      tempCut.variable = cutStringVector.at(0);// variable to cut on
312 <      tempCut.comparativeOperator = cutStringVector.at(1);// comparison to make
313 <      tempCut.cutValue = atof(cutStringVector.at(2).c_str());// threshold value to pass cut
310 >      vector<string> cutStringVector = splitString(cutString);
311 >      if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
312 >        cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
313 >        exit(0);
314 >      }
315 >      tempCut.numSubcuts = (cutStringVector.size()+1)/4;
316 >      for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
317 >        int indexOffset = 4 * subcutIndex;
318 >        string currentVariableString = cutStringVector.at(indexOffset);
319 >        if(currentVariableString.find("(")==string::npos){
320 >          tempCut.functions.push_back("");//no function was specified
321 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
322 >        }
323 >        else{
324 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
325 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
326 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
327 >        }
328 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
329 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
330 >        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
331 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
332 >      }
333  
334        //get number of objects required to pass cut for event to pass
335        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
336 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
336 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
337 >      if(numberRequiredVector.size()!=2){
338 >        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
339 >        exit(0);
340 >      }
341  
130      // determine number required if comparison contains "="
342        int numberRequiredInt = atoi(numberRequiredVector.at(1).c_str());
132      if(numberRequiredVector.at(0) == ">") numberRequiredInt++;
133      else if(numberRequiredVector.at(0) == "<") numberRequiredInt--;
134
343        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
344        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
345  
346 <      if(cuts_.at(currentCut).exists("function")){
347 <        tempCut.function = cuts_.at(currentCut).getParameter<string> ("function");
140 <      }
141 <      else tempCut.function = "";
346 >      //Set up vectors to store the directories and subDIrectories for each channel.
347 >      string subSubDirName;
348        string tempCutName;
349        if(cuts_.at(currentCut).exists("alias")){
350          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
351 +        subSubDirName = "After " + cuts_.at(currentCut).getParameter<string> ("alias") + " Cut Applied";
352        }
353        else{
354          //construct string for cutflow table
355          bool plural = numberRequiredInt != 1;
356 <        string collectionString = plural ? inputCollection : inputCollection.substr(0, inputCollection.size()-1);
356 >        string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
357          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
358          tempCutName = cutName;
359 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
360        }
153      tempCut.name = tempCutName;
361  
362 +      subSubDirNames.push_back(subSubDirName);
363 +      tempCut.name = tempCutName;
364  
365        tempChannel.cuts.push_back(tempCut);
366  
367  
368      }//end loop over cuts
369  
370 <    //make unique vector of all objects that this channel cuts on (so we know to set flags for those)
371 <    sort( tempInputCollections.begin(), tempInputCollections.end() );
372 <    tempInputCollections.erase( unique( tempInputCollections.begin(), tempInputCollections.end() ), tempInputCollections.end() );
373 <    tempChannel.inputCollections = tempInputCollections;
370 >    vector<map<string, TH1D*>> oneDHistsTmp;
371 >    vector<map<string, TH2D*>> twoDHistsTmp;
372 >    //book a directory in the output file with the name of the channel
373 >    TFileDirectory subDir = fs_->mkdir( channelName );
374 >    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
375 >    if(GetPlotsAfterEachCut_){
376 >      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
377 >        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
378 >        directories.push_back(subSubDir);
379 >        map<string, TH1D*> oneDhistoMap;
380 >        oneDHistsTmp.push_back(oneDhistoMap);
381 >        map<string, TH2D*> twoDhistoMap;
382 >        twoDHistsTmp.push_back(twoDhistoMap);
383 >      }
384 >      oneDHists_.push_back(oneDHistsTmp);
385 >      twoDHists_.push_back(twoDHistsTmp);
386 >    }
387 >    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
388 >    else{
389 >      map<string, TH1D*> oneDhistoMap;
390 >      oneDHistsTmp.push_back(oneDhistoMap);
391 >      map<string, TH2D*> twoDhistoMap;
392 >      twoDHistsTmp.push_back(twoDhistoMap);
393 >      oneDHists_.push_back(oneDHistsTmp);
394 >      twoDHists_.push_back(twoDHistsTmp);
395 >      directories.push_back(subDir);
396 >
397 >    }
398 >
399  
400 +    //book all histograms included in the configuration
401 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
402 +
403 +      TTree* newTree = directories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));  
404 +      BNTrees_.push_back(newTree);  
405 +      
406 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
407 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
408 +        vector<float> newVec;  
409 +        BNTreeBranchVals_[currentVar.name] = newVec;  
410 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
411 +
412 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
413 +
414 +
415 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
416 +
417 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
418 +        int numBinsElements = currentHistogram.bins.size();
419 +        int numInputVariables = currentHistogram.inputVariables.size();
420 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
421 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
422 +        
423 +        if(numBinsElements == 1){
424 +          if(numBinEdgesX > 1){
425 +            if(numBinEdgesY > 1)
426 +              numBinsElements = 6;
427 +            else
428 +              numBinsElements = 3;
429 +          }
430 +        }
431 +        if(numBinsElements != 3 && numBinsElements !=6){
432 +          cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
433 +          exit(0);
434 +        }
435 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
436 +          cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
437 +          exit(0);
438 +        }
439 +        else if(numBinsElements == 3){
440 +          if (currentHistogram.bins.size () == 3)
441 +            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));
442 +          else
443 +            {
444 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
445 +            }
446 +        }
447 +        else if(numBinsElements == 6){
448 +          if (currentHistogram.bins.size () == 6)
449 +            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));
450 +          else
451 +            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 ());
452 +        }
453 +
454 +
455 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
456 +
457 +        // bin      particle type
458 +        // ---      -------------
459 +        //  0        unmatched
460 +        //  1        u
461 +        //  2        d
462 +        //  3        s
463 +        //  4        c
464 +        //  5        b
465 +        //  6        t
466 +        //  7        e
467 +        //  8        mu
468 +        //  9        tau
469 +        // 10        nu
470 +        // 11        g
471 +        // 12        gamma
472 +        // 13        Z
473 +        // 14        W
474 +        // 15        light meson
475 +        // 16        K meson
476 +        // 17        D meson
477 +        // 18        B meson
478 +        // 19        light baryon
479 +        // 20        strange baryon
480 +        // 21        charm baryon
481 +        // 22        bottom baryon
482 +        // 23        QCD string
483 +        // 24        other
484 +
485 +        vector<TString> labelArray;
486 +        labelArray.push_back("unmatched");
487 +        labelArray.push_back("u");
488 +        labelArray.push_back("d");
489 +        labelArray.push_back("s");
490 +        labelArray.push_back("c");
491 +        labelArray.push_back("b");
492 +        labelArray.push_back("t");
493 +        labelArray.push_back("e");
494 +        labelArray.push_back("#mu");
495 +        labelArray.push_back("#tau");
496 +        labelArray.push_back("#nu");
497 +        labelArray.push_back("g");
498 +        labelArray.push_back("#gamma");
499 +        labelArray.push_back("Z");
500 +        labelArray.push_back("W");
501 +        labelArray.push_back("light meson");
502 +        labelArray.push_back("K meson");
503 +        labelArray.push_back("D meson");
504 +        labelArray.push_back("B meson");
505 +        labelArray.push_back("light baryon");
506 +        labelArray.push_back("strange baryon");
507 +        labelArray.push_back("charm baryon");
508 +        labelArray.push_back("bottom baryon");
509 +        labelArray.push_back("QCD string");
510 +        labelArray.push_back("other");
511 +
512 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
513 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
514 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
515 +          }
516 +          else {
517 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
518 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
519 +          }
520 +        }
521 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
522 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
523 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
524 +        }
525 +
526 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
527 +
528 +
529 +      // Book a histogram for the number of each object type to be plotted.
530 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
531 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
532 +        string currentObject = objectsToPlot.at(currentObjectIndex);
533 +        int maxNum = 10;
534 +        if(currentObject == "mcparticles") maxNum = 50;
535 +        else if(currentObject == "primaryvertexs") maxNum = 50;
536 +
537 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
538 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
539 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
540 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
541 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
542 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
543 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
544 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
545 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
546 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
547 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
548 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
549 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
550 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
551 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
552 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
553 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
554 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
555 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
556 +
557 +        currentObject.at(0) = toupper(currentObject.at(0));
558 +        string histoName = "num" + currentObject;
559 +
560 +        if(histoName == "numPrimaryvertexs"){
561 +          string newHistoName = histoName + "BeforePileupCorrection";
562 +          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);
563 +          newHistoName = histoName + "AfterPileupCorrection";
564 +          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);
565 +        }
566 +        else
567 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
568 +      }
569 +    }//end of loop over directories
570      channels.push_back(tempChannel);
571      tempChannel.cuts.clear();
168
572    }//end loop over channels
573  
574 <  //make unique vector of objects we need to cut on (so we make sure to get them from the event)
575 <  sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
576 <  allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
574 >
575 >  //make unique vector of objects we need to get from the event
576 >  sort( objectsToGet.begin(), objectsToGet.end() );
577 >  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
578 >  //make unique vector of objects we need to cut on
579 >  sort( objectsToCut.begin(), objectsToCut.end() );
580 >  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
581  
582  
583   }
# Line 188 | Line 595 | void
595   OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
596   {
597  
191
598    // Retrieve necessary collections from the event.
599 <  edm::Handle<BNtriggerCollection> triggers;
600 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
599 >
600 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
601      event.getByLabel (triggers_, triggers);
602  
603 <  edm::Handle<BNjetCollection> jets;
604 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())
603 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
604 >    event.getByLabel (trigobjs_, trigobjs);
605 >
606 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
607      event.getByLabel (jets_, jets);
608  
609 <  edm::Handle<BNmuonCollection> muons;
202 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())
609 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
610      event.getByLabel (muons_, muons);
611  
612 <  edm::Handle<BNelectronCollection> electrons;
206 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())
612 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
613      event.getByLabel (electrons_, electrons);
614  
615 <  edm::Handle<BNeventCollection> events;
210 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())
615 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
616      event.getByLabel (events_, events);
617  
618 <  edm::Handle<BNtauCollection> taus;
214 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())
618 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
619      event.getByLabel (taus_, taus);
620  
621 <  edm::Handle<BNmetCollection> mets;
218 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())
621 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
622      event.getByLabel (mets_, mets);
623  
624 <  edm::Handle<BNtrackCollection> tracks;
222 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())
624 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
625      event.getByLabel (tracks_, tracks);
626  
627 <  edm::Handle<BNgenjetCollection> genjets;
226 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())
627 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
628      event.getByLabel (genjets_, genjets);
629  
630 <  edm::Handle<BNmcparticleCollection> mcparticles;
230 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())
630 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
631      event.getByLabel (mcparticles_, mcparticles);
632  
633 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
234 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())
633 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
634      event.getByLabel (primaryvertexs_, primaryvertexs);
635  
636 <  edm::Handle<BNbxlumiCollection> bxlumis;
238 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())
636 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
637      event.getByLabel (bxlumis_, bxlumis);
638  
639 <  edm::Handle<BNphotonCollection> photons;
242 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())
639 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
640      event.getByLabel (photons_, photons);
641  
642 <  edm::Handle<BNsuperclusterCollection> superclusters;
246 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())
642 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
643      event.getByLabel (superclusters_, superclusters);
644  
645 +  if (datasetType_ == "signalMC"){
646 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
647 +      event.getByLabel (stops_, stops);
648 +  }
649 +
650 +  if (useTrackCaloRhoCorr_) {
651 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
652 +    // This rho collection is not available in all BEANs.
653 +    // For description of rho values for different jet reconstruction algorithms, see
654 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
655 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
656 +  }
657 +
658 +  double masterScaleFactor = 1.0;
659 +
660 +  //get pile-up event weight
661 +  if (doPileupReweighting_ && datasetType_ != "data") {
662 +    //for "data" datasets, the numTruePV is always set to -1
663 +    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;  
664 +    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);  
665 +  }
666 +
667 +  stopCTauScaleFactor_ = 1.0;
668 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
669 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
670 +  masterScaleFactor *= stopCTauScaleFactor_;
671  
672    //loop over all channels
673  
# Line 253 | Line 675 | OSUAnalysis::analyze (const edm::Event &
675      channel currentChannel = channels.at(currentChannelIndex);
676  
677      flagMap individualFlags;
256    flagMap cumulativeFlags;
678      counterMap passingCounter;
679 +    cumulativeFlags.clear ();
680 +
681 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
682 +         iter != BNTreeBranchVals_.end(); iter++) {
683 +      iter->second.clear();  // clear array
684 +    }
685 +
686  
687      bool triggerDecision = true;
688 <    if(currentChannel.triggers.size() != 0){  //triggers specified
689 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
688 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
689 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
690        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
691      }
692  
693      //loop over all cuts
694      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
695        cut currentCut = currentChannel.cuts.at(currentCutIndex);
696 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
697 +        string currentObject = objectsToCut.at(currentObjectIndex);
698  
699 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
270 <
271 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
699 >        //initialize maps to get ready to set cuts
700          individualFlags[currentObject].push_back (vector<bool> ());
701          cumulativeFlags[currentObject].push_back (vector<bool> ());
702  
703 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
704 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
703 >      }
704 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
705 >        string currentObject = objectsToCut.at(currentObjectIndex);
706 >
707 >        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
708 >
709 >
710 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
711 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
712 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
713 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
714 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
715          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
716          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
717          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 285 | Line 723 | OSUAnalysis::analyze (const edm::Event &
723          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
724          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
725          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
726 <
289 <
290 <      }
726 >        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
727  
728  
729  
730 <    }//end loop over all cuts
730 >        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
731 >                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
732 >                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
733 >                                                                   "muon-muon pairs");
734 >
735 >        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
736 >                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
737 >                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
738 >                                                                             "muon-secondary muon pairs");
739 >
740 >        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
741 >                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
742 >                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
743 >                                                                                     "electron-secondary electron pairs");
744 >
745 >        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
746 >                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
747 >                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
748 >                                                                           "electron-electron pairs");
749 >        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
750 >                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
751 >                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
752 >                                                                       "electron-muon pairs");
753 >        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
754 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
755 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
756 >                                                                 "jet-jet pairs");
757 >        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
758 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
759 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
760 >                                                                      "electron-jet pairs");
761 >        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
762 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
763 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
764 >                                                                  "muon-jet pairs");
765 >        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
766 >                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
767 >                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
768 >                                                                     "track-event pairs");
769 >        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
770 >                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
771 >                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
772 >                                                                        "electron-track pairs");
773 >        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
774 >                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
775 >                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
776 >                                                                    "muon-track pairs");
777 >        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
778 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
779 >                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
780 >                                                                  "muon-tau pairs");
781 >        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
782 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
783 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
784 >                                                                 "tau-tau pairs");
785 >        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
786 >                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
787 >                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
788 >                                                                   "tau-track pairs");
789 >        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
790 >                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
791 >                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
792 >                                                                          "electron-trigobj pairs");
793 >        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
794 >                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
795 >                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
796 >                                                                      "muon-trigobj pairs");
797  
798 +        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
799 +      }
800  
801  
802  
803 +    }//end loop over all cuts
804      //use cumulative flags to apply cuts at event level
805  
806      bool eventPassedAllCuts = true;
807 <
807 >    //a vector to store cumulative cut descisions after each cut.
808 >    vector<bool> eventPassedPreviousCuts;
809      //apply trigger (true if none were specified)
810      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
811  
306
812      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
813  
814        //loop over all objects and count how many passed the cumulative selection up to this point
815        cut currentCut = currentChannel.cuts.at(currentCutIndex);
816        int numberPassing = 0;
817  
818 <      for (uint object = 0; object != cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).size() ; object++)
819 <          if(cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).at(object)) numberPassing++;
820 <
316 <
818 >      for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
819 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
820 >      }
821        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
822        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
319
823        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
824 <
824 >      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
825      }
826 +    double scaleFactor = masterScaleFactor;
827  
828 <    cutFlows_.at(currentChannelIndex)->fillCutFlow();
829 <
830 <
831 <
832 <    if(!eventPassedAllCuts)continue;
833 <
834 <
835 <    TVector3 vertexPosition;
836 <    vector<bool> vertexFlags = cumulativeFlags["primaryvertexs"].back();
837 <
838 <    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
839 <      if(!vertexFlags.at(vertexIndex)) continue;
840 <
841 <      vertexPosition.SetXYZ (primaryvertexs->at(vertexIndex).x,primaryvertexs->at(vertexIndex).y,primaryvertexs->at(vertexIndex).z);
842 <      break;
828 >    muonScaleFactor_ = electronScaleFactor_ = 1.0;
829 >    if(applyLeptonSF_ && datasetType_ != "data"){
830 >      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
831 >        vector<bool> muonFlags;
832 >        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
833 >          if (cumulativeFlags.at("muons").at(i).size()){
834 >            muonFlags = cumulativeFlags.at("muons").at(i);
835 >            break;
836 >          }
837 >        }
838 >        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
839 >          if(!muonFlags.at(muonIndex)) continue;
840 >          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
841 >        }
842 >      }
843 >      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
844 >        vector<bool> electronFlags;
845 >        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
846 >          if (cumulativeFlags.at("electrons").at(i).size()){
847 >            electronFlags = cumulativeFlags.at("electrons").at(i);
848 >            break;
849 >          }
850 >        }
851 >        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
852 >          if(!electronFlags.at(electronIndex)) continue;
853 >          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
854 >        }
855 >      }
856      }
857 +    scaleFactor *= muonScaleFactor_;
858 +    scaleFactor *= electronScaleFactor_;
859  
860 <    vector<bool> mcparticleFlags = cumulativeFlags["mcparticles"].back();
860 >    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
861  
862 <    for (uint mcparticleIndex = 0; mcparticleIndex != mcparticleFlags.size(); mcparticleIndex++){
863 <      if(!mcparticleFlags.at(mcparticleIndex)) continue;
864 <
865 <      double vx = mcparticles->at(mcparticleIndex).vx - vertexPosition.X (),
866 <             vy = mcparticles->at(mcparticleIndex).vy - vertexPosition.Y (),
867 <             vz = mcparticles->at(mcparticleIndex).vz - vertexPosition.Z (),
868 <             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));
862 >    if (printEventInfo_) {
863 >      // Write information about event to screen, for testing purposes.
864 >      cout << "Event passed all cuts in channel " <<  currentChannel.name
865 >           << ": run="  << events->at(0).run
866 >           << "  lumi=" << events->at(0).lumi
867 >           << "  event=" << events->at(0).evt
868 >           << endl;
869      }
870  
361    vector<bool> electronFlags = cumulativeFlags["electrons"].back();
362    int electronCounter = 0;
363
364    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
365      if(!electronFlags.at(electronIndex)) continue;
366
367
368      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);
382
383    }
384    oneDHists_.at(currentChannelIndex)["numElectrons"]->Fill (electronCounter);
871  
872 +    //filling histograms
873 +    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
874 +      uint currentDir;
875 +      if(!GetPlotsAfterEachCut_){ currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size();}//if GetPlotsAfterEachCut_ is true, set currentDir point to the lat cut.
876 +      else{
877 +        currentDir = currentCut;
878 +      }
879 +      if(eventPassedPreviousCuts.at(currentDir)){
880  
881 <    vector<bool> muonFlags = cumulativeFlags["muons"].back();
882 <    int muonCounter = 0;
881 >        // Assign BNTree variables
882 >        for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
883 >          BranchSpecs brSpecs = treeBranches_.at(iBranch);  
884 >          string coll = brSpecs.inputCollection;  
885 >          if (cumulativeFlags.count(coll) == 0) cout << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
886 >
887 >          if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).at(currentDir));            
888 >          else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).at(currentDir));
889 >          else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).at(currentDir));        
890 >          else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).at(currentDir));
891 >          else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).at(currentDir));
892 >          else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).at(currentDir));
893 >          else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).at(currentDir));
894 >          else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).at(currentDir));
895 >          else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).at(currentDir));
896 >          else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).at(currentDir));
897 >          else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).at(currentDir));
898 >          else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).at(currentDir));
899 >          else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).at(currentDir));
900 >          else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).at(currentDir));
901 >          else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).at(currentDir));
902 >          else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).at(currentDir));
903 >          else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).at(currentDir));
904 >          else if(coll == "stops"
905 >                  && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).at(currentDir));
906 >        } // end loop over histograms  
907 >                                                                                          
908 >
909 >        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
910 >          histogram currentHistogram = histograms.at(histogramIndex);
911 >
912 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) cout << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
913 >
914 >          if(currentHistogram.inputVariables.size() == 1){
915 >            TH1D* histo;  
916 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
917 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
918 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
919 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
920 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
921 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
922 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
923 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
924 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
925 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
926 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
927 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
928 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
929 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
930 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
931 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
932 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
933 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
934 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
935 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
936 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
937 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
938 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
939 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
940 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
941 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
942 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
943 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
944 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
945 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
946 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
947 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
948 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
949 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
950 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
951 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
952 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
953 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
954 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
955 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
956 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
957 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
958 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
959 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
960 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
961 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
962 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
963 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
964 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
965 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
966 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
967 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
968 >
969 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
970 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
971 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
972 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
973 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
974 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
975 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
976 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
977 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
978 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
979 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
980 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
981 >          }
982 >          else if(currentHistogram.inputVariables.size() == 2){
983 >            TH2D* histo;
984 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
985 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
986 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
987 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
988 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
989 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
990 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
991 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
992 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
993 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
994 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
995 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
996 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
997 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
998 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
999 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1000 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1001 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1002 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1003 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1004 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1005 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1006 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1007 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1008 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1009 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1010 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1011 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1012 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1013 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1014 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1015 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1016 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1017 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1018 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1019 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1020 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1021 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1022 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1023 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1024 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1025 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1026 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1027 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1028 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1029 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1030 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1031 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1032 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1033 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1034 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1035 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1036 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1037 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1038 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1039 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1040 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1041 >                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1042 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1043 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1044 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1045 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1046 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1047 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1048 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1049 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1050 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1051 >          }
1052 >          
1053 >        }
1054 >
1055 >
1056 >        //fills histograms with the sizes of collections
1057 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1058 >
1059 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1060 >          string objectToPlot = "";
1061 >
1062 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1063 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1064 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1065 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1066 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1067 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1068 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1069 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1070 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1071 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1072 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1073 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1074 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1075 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1076 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1077 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1078 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1079 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1080 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1081 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1082 >          else objectToPlot = currentObject;
1083 >
1084 >          string tempCurrentObject = objectToPlot;
1085 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1086 >          string histoName = "num" + tempCurrentObject;
1087 >
1088 >          //set position of primary vertex in event, in order to calculate quantities relative to it
1089 >          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1090 >            vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1091 >            int numToPlot = 0;
1092 >            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1093 >              if(lastCutFlags.at(currentFlag)) numToPlot++;
1094 >            }
1095 >            if(objectToPlot == "primaryvertexs"){
1096 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1097 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1098 >            }
1099 >            else {
1100 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1101 >            }
1102 >          }
1103 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1104 >      } // end if(eventPassedPreviousCuts.at(currentDir)){
1105 >    } // end loop over cuts
1106  
1107 +    BNTrees_.at(currentChannelIndex)->Fill();  
1108  
1109 <    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
392 <      if(!muonFlags.at(muonIndex)) continue;
393 <      muonCounter++;
1109 >  } // end loop over channel
1110  
1111 <      oneDHists_.at(currentChannelIndex)["muonPt"]->Fill (muons->at(muonIndex).pt);
396 <      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);
405 <    }
406 <    oneDHists_.at(currentChannelIndex)["numMuons"]->Fill (muonCounter);
1111 >  masterCutFlow_->fillCutFlow(masterScaleFactor);
1112  
1113  
1114 + } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1115  
1116  
1117  
1118 <  } //end loop over channel
1118 > bool
1119 > OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
1120  
414  masterCutFlow_->fillCutFlow();
1121  
1122 +  if(comparison == ">")       return testValue >  cutValue;
1123 +  else if(comparison == ">=") return testValue >= cutValue;
1124 +  else if(comparison == "<")  return testValue <  cutValue;
1125 +  else if(comparison == "<=") return testValue <= cutValue;
1126 +  else if(comparison == "==") return testValue == cutValue;
1127 +  else if(comparison == "=") return testValue == cutValue;
1128 +  else if(comparison == "!=") return testValue != cutValue;
1129 +  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1130  
1131   }
1132  
419
1133   bool
1134 < OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
1134 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1135  
1136  
1137    if(comparison == ">")       return testValue >  cutValue;
# Line 426 | Line 1139 | OSUAnalysis::evaluateComparison (double
1139    else if(comparison == "<")  return testValue <  cutValue;
1140    else if(comparison == "<=") return testValue <= cutValue;
1141    else if(comparison == "==") return testValue == cutValue;
1142 +  else if(comparison == "=") return testValue == cutValue;
1143    else if(comparison == "!=") return testValue != cutValue;
1144 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1144 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1145  
1146   }
1147  
1148   bool
1149 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1149 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1150  
1151 +  //initialize to false until a chosen trigger is passed
1152    bool triggerDecision = false;
1153  
1154 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1155 <    {
1156 <      if(trigger->pass != 1) continue;
1157 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1158 <        {
444 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
445 <            triggerDecision = true;
446 <          }
447 <        }
448 <    }
449 <  return triggerDecision;
1154 >  //loop over all triggers defined in the event
1155 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1156 >
1157 >    //we're only interested in triggers that actually passed
1158 >    if(trigger->pass != 1) continue;
1159  
1160 +    //if the event passes one of the veto triggers, exit and return false
1161 +    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1162 +      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1163 +    }
1164 +    //if the event passes one of the chosen triggers, set triggerDecision to true
1165 +    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1166 +      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1167 +    }  
1168 +  }
1169 +  //if none of the veto triggers fired:
1170 +  //return the OR of all the chosen triggers
1171 +  if (triggersToTest.size() != 0) return triggerDecision;
1172 +  //or if no triggers were defined return true
1173 +  else return true;
1174   }
1175  
1176 < std::vector<std::string>
1176 >
1177 > vector<string>
1178   OSUAnalysis::splitString (string inputString){
1179  
1180 <  std::stringstream stringStream(inputString);
1181 <  std::istream_iterator<std::string> begin(stringStream);
1182 <  std::istream_iterator<std::string> end;
1183 <  std::vector<std::string> stringVector(begin, end);
1180 >  stringstream stringStream(inputString);
1181 >  istream_iterator<string> begin(stringStream);
1182 >  istream_iterator<string> end;
1183 >  vector<string> stringVector(begin, end);
1184    return stringVector;
1185  
1186   }
1187  
1188 +
1189 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1190 +  // Set two object strings from the tempInputCollection string,
1191 +  // For example, if tempInputCollection is "electron-muon pairs",
1192 +  // then obj1 = "electrons" and obj2 = "muons".
1193 +  // Note that the objects have an "s" appended.
1194 +
1195 +  int dashIndex = tempInputCollection.find("-");
1196 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1197 +  int secondWordLength = spaceIndex - dashIndex;
1198 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1199 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1200 +
1201 + }
1202 +
1203 +
1204 + string OSUAnalysis::getObjToGet(string obj) {
1205 +  // Return the string corresponding to the object to get for the given obj string.
1206 +  // Right now this only handles the case in which obj contains "secondary",
1207 +  // e.g, "secondary muons".
1208 +  // Note that "s" is NOT appended.
1209 +
1210 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1211 +  int firstSpaceIndex = obj.find_first_of(" ");
1212 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1213 +
1214 + }
1215 +
1216 +
1217 + //!jet valueLookup
1218   double
1219 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1219 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1220  
1221    double value = 0.0;
1222    if(variable == "energy") value = object->energy;
# Line 582 | Line 1336 | OSUAnalysis::valueLookup (const BNjet* o
1336    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1337  
1338  
1339 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1339 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1340  
1341    value = applyFunction(function, value);
1342  
# Line 590 | Line 1344 | OSUAnalysis::valueLookup (const BNjet* o
1344   }
1345  
1346  
1347 <
1347 > //!muon valueLookup
1348   double
1349 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1349 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1350  
1351    double value = 0.0;
1352    if(variable == "energy") value = object->energy;
# Line 608 | Line 1362 | OSUAnalysis::valueLookup (const BNmuon*
1362    else if(variable == "ecalIso") value = object->ecalIso;
1363    else if(variable == "hcalIso") value = object->hcalIso;
1364    else if(variable == "caloIso") value = object->caloIso;
1365 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
1365 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
1366    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
1367    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
1368    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 746 | Line 1500 | OSUAnalysis::valueLookup (const BNmuon*
1500    else if(variable == "numberOfMatchedStations") value = object->numberOfMatchedStations;
1501    else if(variable == "time_ndof") value = object->time_ndof;
1502  
1503 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1503 >  //user-defined variables
1504 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1505 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1506 >  else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1507 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1508 >  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1509 >  else if(variable == "metMT") {
1510 >    if (const BNmet *met = chosenMET ())
1511 >      {
1512 >        double dPhi = deltaPhi (object->phi, met->phi);
1513 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1514 >      }
1515 >    else
1516 >      value = -999;
1517 >  }
1518 >
1519 >
1520 >
1521 >  else if(variable == "correctedD0VertexInEBPlus"){
1522 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1523 >    else value = -999;
1524 >  }
1525 >  else if(variable == "correctedD0VertexOutEBPlus"){
1526 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1527 >    else value = -999;
1528 >  }
1529 >  else if(variable == "correctedD0VertexEEPlus"){
1530 >    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1531 >    else value = -999;
1532 >  }
1533 >
1534 >  else if(variable == "correctedD0BeamspotInEBPlus"){
1535 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1536 >    else value = -999;
1537 >  }
1538 >  else if(variable == "correctedD0BeamspotOutEBPlus"){
1539 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1540 >    else value = -999;
1541 >  }
1542 >  else if(variable == "correctedD0BeamspotEEPlus"){
1543 >    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1544 >    else value = -999;
1545 >  }
1546 >
1547 >  else if(variable == "correctedD0VertexInEBMinus"){
1548 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1549 >    else value = -999;
1550 >  }
1551 >  else if(variable == "correctedD0VertexOutEBMinus"){
1552 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1553 >    else value = -999;
1554 >  }
1555 >  else if(variable == "correctedD0VertexEEMinus"){
1556 >    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1557 >    else value = -999;
1558 >  }
1559 >
1560 >  else if(variable == "correctedD0BeamspotInEBMinus"){
1561 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1562 >    else value = -999;
1563 >  }
1564 >  else if(variable == "correctedD0BeamspotOutEBMinus"){
1565 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1566 >    else value = -999;
1567 >  }
1568 >  else if(variable == "correctedD0BeamspotEEMinus"){
1569 >    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1570 >    else value = -999;
1571 >  }
1572 >
1573 >
1574 >  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1575 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1576 >    else value = -999;
1577 >  }
1578 >  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1579 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1580 >    else value = -999;
1581 >  }
1582 >  else if(variable == "correctedD0VertexEEPositiveCharge"){
1583 >    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1584 >    else value = -999;
1585 >  }
1586 >
1587 >  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1588 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1589 >    else value = -999;
1590 >  }
1591 >  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1592 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1593 >    else value = -999;
1594 >  }
1595 >  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1596 >    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1597 >    else value = -999;
1598 >  }
1599 >
1600 >  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1601 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1602 >    else value = -999;
1603 >  }
1604 >  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1605 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1606 >    else value = -999;
1607 >  }
1608 >  else if(variable == "correctedD0VertexEENegativeCharge"){
1609 >    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1610 >    else value = -999;
1611 >  }
1612 >
1613 >  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1614 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1615 >    else value = -999;
1616 >  }
1617 >  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1618 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1619 >    else value = -999;
1620 >  }
1621 >  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1622 >    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1623 >    else value = -999;
1624 >  }
1625 >
1626 >
1627 >  else if(variable == "tightID") {
1628 >    value = object->isGlobalMuon > 0                \
1629 >      && object->isPFMuon > 0                        \
1630 >      && object->normalizedChi2 < 10                \
1631 >      && object->numberOfValidMuonHits > 0        \
1632 >      && object->numberOfMatchedStations > 1        \
1633 >      && fabs(object->correctedD0Vertex) < 0.2        \
1634 >      && fabs(object->correctedDZ) < 0.5        \
1635 >      && object->numberOfValidPixelHits > 0                \
1636 >      && object->numberOfLayersWithMeasurement > 5;
1637 >  }
1638 >  else if(variable == "tightIDdisplaced"){
1639 >    value = object->isGlobalMuon > 0                \
1640 >      && object->isPFMuon > 0                        \
1641 >      && object->normalizedChi2 < 10                \
1642 >      && object->numberOfValidMuonHits > 0        \
1643 >      && object->numberOfMatchedStations > 1        \
1644 >      && object->numberOfValidPixelHits > 0        \
1645 >      && object->numberOfLayersWithMeasurement > 5;
1646 >  }
1647 >
1648 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1649 >
1650 >  else if(variable == "genMatchedPdgId"){
1651 >    int index = getGenMatchedParticleIndex(object);
1652 >    if(index == -1) value = 0;
1653 >    else value = mcparticles->at(index).id;
1654 >  }
1655 >
1656 >  else if(variable == "genMatchedId"){
1657 >    int index = getGenMatchedParticleIndex(object);
1658 >    if(index == -1) value = 0;
1659 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
1660 >  }
1661 >  else if(variable == "genMatchedMotherId"){
1662 >    int index = getGenMatchedParticleIndex(object);
1663 >    if(index == -1) value = 0;
1664 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1665 >  }
1666 >  else if(variable == "genMatchedMotherIdReverse"){
1667 >    int index = getGenMatchedParticleIndex(object);
1668 >    if(index == -1) value = 24;
1669 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1670 >  }
1671 >  else if(variable == "genMatchedGrandmotherId"){
1672 >    int index = getGenMatchedParticleIndex(object);
1673 >    if(index == -1) value = 0;
1674 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1675 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1676 >      if(motherIndex == -1) value = 0;
1677 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1678 >    }
1679 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1680 >  }
1681 >  else if(variable == "genMatchedGrandmotherIdReverse"){
1682 >    int index = getGenMatchedParticleIndex(object);
1683 >    if(index == -1) value = 24;
1684 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1685 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1686 >      if(motherIndex == -1) value = 24;
1687 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1688 >    }
1689 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1690 >  }
1691 >  else if(variable == "pfMuonsFromVertex"){
1692 >    double d0Error, dzError;
1693 >
1694 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1695 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1696 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1697 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1698 >      || fabs (object->correctedDZ / dzError) > 99.0;
1699 >    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1700 >  }
1701 >
1702 >
1703 >
1704 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1705  
1706    value = applyFunction(function, value);
1707  
1708    return value;
1709   }
1710  
1711 <
1711 > //!electron valueLookup
1712   double
1713 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1713 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1714  
1715    double value = 0.0;
1716    if(variable == "energy") value = object->energy;
# Line 915 | Line 1870 | OSUAnalysis::valueLookup (const BNelectr
1870    else if(variable == "eidHyperTight4MC") value = object->eidHyperTight4MC;
1871    else if(variable == "passConvVeto") value = object->passConvVeto;
1872  
1873 +  //user-defined variables
1874 +  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1875 +  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1876 +  else if(variable == "detIso") value = (object->trackIso) / object->pt;
1877 +  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1878 +  else if(variable == "metMT") {
1879 +    if (const BNmet *met = chosenMET ())
1880 +      {
1881 +        double dPhi = deltaPhi (object->phi, met->phi);
1882 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1883 +      }
1884 +    else
1885 +      value = -999;
1886 +  }
1887 +
1888 +  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
1889 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
1890 +    else value = -999;
1891 +  }
1892 +  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
1893 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
1894 +    else value = -999;
1895 +  }
1896 +
1897 +  else if(variable == "correctedD0VertexInEBPlus"){
1898 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1899 +    else value = -999;
1900 +  }
1901 +  else if(variable == "correctedD0VertexOutEBPlus"){
1902 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1903 +    else value = -999;
1904 +  }
1905 +  else if(variable == "correctedD0VertexEEPlus"){
1906 +    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
1907 +    else value = -999;
1908 +  }
1909 +
1910 +  else if(variable == "correctedD0BeamspotInEBPlus"){
1911 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1912 +    else value = -999;
1913 +  }
1914 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
1915 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1916 +    else value = -999;
1917 +  }
1918 +  else if(variable == "correctedD0BeamspotEEPlus"){
1919 +    if(object->isEE && object->eta > 0) value = object->correctedD0;
1920 +    else value = -999;
1921 +  }
1922 +
1923 +  else if(variable == "correctedD0VertexInEBMinus"){
1924 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1925 +    else value = -999;
1926 +  }
1927 +  else if(variable == "correctedD0VertexOutEBMinus"){
1928 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1929 +    else value = -999;
1930 +  }
1931 +  else if(variable == "correctedD0VertexEEMinus"){
1932 +    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
1933 +    else value = -999;
1934 +  }
1935 +
1936 +  else if(variable == "correctedD0BeamspotInEBMinus"){
1937 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1938 +    else value = -999;
1939 +  }
1940 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
1941 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1942 +    else value = -999;
1943 +  }
1944 +  else if(variable == "correctedD0BeamspotEEMinus"){
1945 +    if(object->isEE && object->eta < 0) value = object->correctedD0;
1946 +    else value = -999;
1947 +  }
1948 +
1949 +  else if(variable == "tightID"){
1950 +    if (object->isEB)
1951 +      {
1952 +        value = fabs(object->delEtaIn) < 0.004 \
1953 +          && fabs (object->delPhiIn) < 0.03 \
1954 +          && object->scSigmaIEtaIEta < 0.01 \
1955 +          && object->hadOverEm < 0.12 \
1956 +          && fabs (object->correctedD0Vertex) < 0.02 \
1957 +          && fabs (object->correctedDZ) < 0.1 \
1958 +          && object->absInvEMinusInvPin < 0.05 \
1959 +          && object->passConvVeto;
1960 +      }
1961 +    else
1962 +      {
1963 +        value = fabs(object->delEtaIn) < 0.005 \
1964 +          && fabs (object->delPhiIn) < 0.02 \
1965 +          && object->scSigmaIEtaIEta < 0.03 \
1966 +          && object->hadOverEm < 0.10 \
1967 +          && fabs (object->correctedD0Vertex) < 0.02 \
1968 +          && fabs (object->correctedDZ) < 0.1 \
1969 +          && object->absInvEMinusInvPin < 0.05 \
1970 +          && object->passConvVeto;
1971 +      }
1972 +  }
1973 +
1974 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1975 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1976 +    else value = -999;
1977 +  }
1978 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1979 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1980 +    else value = -999;
1981 +  }
1982 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
1983 +    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
1984 +    else value = -999;
1985 +  }
1986 +
1987 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1988 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1989 +    else value = -999;
1990 +  }
1991 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1992 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1993 +    else value = -999;
1994 +  }
1995 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1996 +    if(object->isEE && object->charge > 0) value = object->correctedD0;
1997 +    else value = -999;
1998 +  }
1999 +
2000 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
2001 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2002 +    else value = -999;
2003 +  }
2004 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
2005 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2006 +    else value = -999;
2007 +  }
2008 +  else if(variable == "correctedD0VertexEENegativeCharge"){
2009 +    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
2010 +    else value = -999;
2011 +  }
2012 +
2013 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
2014 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
2015 +    else value = -999;
2016 +  }
2017 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
2018 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
2019 +    else value = -999;
2020 +  }
2021 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
2022 +    if(object->isEE && object->charge < 0) value = object->correctedD0;
2023 +    else value = -999;
2024 +  }
2025 +
2026 +
2027 +  else if(variable == "tightIDdisplaced"){
2028 +    if (object->isEB)
2029 +      {
2030 +        value = fabs(object->delEtaIn) < 0.004 \
2031 +          && fabs (object->delPhiIn) < 0.03 \
2032 +          && object->scSigmaIEtaIEta < 0.01 \
2033 +          && object->hadOverEm < 0.12 \
2034 +          && object->absInvEMinusInvPin < 0.05;
2035 +      }
2036 +    else
2037 +      {
2038 +        value = fabs (object->delEtaIn) < 0.005 \
2039 +          && fabs (object->delPhiIn) < 0.02 \
2040 +          && object->scSigmaIEtaIEta < 0.03 \
2041 +          && object->hadOverEm < 0.10 \
2042 +          && object->absInvEMinusInvPin < 0.05;
2043 +      }
2044 +  }
2045 +
2046 +
2047 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2048 +
2049 +  else if(variable == "genMatchedPdgId"){
2050 +    int index = getGenMatchedParticleIndex(object);
2051 +    if(index == -1) value = 0;
2052 +    else value = mcparticles->at(index).id;
2053 +  }
2054 +
2055 +
2056 +  else if(variable == "genMatchedId"){
2057 +    int index = getGenMatchedParticleIndex(object);
2058 +    if(index == -1) value = 0;
2059 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
2060 +  }
2061 +  else if(variable == "genMatchedMotherId"){
2062 +    int index = getGenMatchedParticleIndex(object);
2063 +    if(index == -1) value = 0;
2064 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2065 +  }
2066 +  else if(variable == "genMatchedMotherIdReverse"){
2067 +    int index = getGenMatchedParticleIndex(object);
2068 +    if(index == -1) value = 24;
2069 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2070 +  }
2071 +  else if(variable == "genMatchedGrandmotherId"){
2072 +    int index = getGenMatchedParticleIndex(object);
2073 +    if(index == -1) value = 0;
2074 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2075 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2076 +      if(motherIndex == -1) value = 0;
2077 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2078 +    }
2079 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2080 +  }
2081 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2082 +    int index = getGenMatchedParticleIndex(object);
2083 +    if(index == -1) value = 24;
2084 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2085 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2086 +      if(motherIndex == -1) value = 24;
2087 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2088 +    }
2089 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2090 +  }
2091 +  else if(variable == "pfElectronsFromVertex"){
2092 +    double d0Error, dzError;
2093 +
2094 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2095 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2096 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2097 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2098 +      || fabs (object->correctedDZ / dzError) > 99.0;
2099 +    value = !value;
2100 +  }
2101  
2102 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2102 >
2103 >
2104 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2105  
2106    value = applyFunction(function, value);
2107  
2108    return value;
2109   }
2110  
2111 <
2111 > //!event valueLookup
2112   double
2113 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2113 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2114  
2115    double value = 0.0;
2116  
# Line 993 | Line 2178 | OSUAnalysis::valueLookup (const BNevent*
2178    else if(variable == "id1") value = object->id1;
2179    else if(variable == "id2") value = object->id2;
2180    else if(variable == "evt") value = object->evt;
2181 +  else if(variable == "puScaleFactor"){
2182 +    if(doPileupReweighting_ && datasetType_ != "data")
2183 +      value = puWeight_->at (events->at (0).numTruePV);
2184 +    else
2185 +      value = 1.0;
2186 +  }
2187 +  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2188 +  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2189 +  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2190  
2191 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2191 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2192  
2193    value = applyFunction(function, value);
2194  
2195    return value;
2196   }
2197  
2198 + //!tau valueLookup
2199   double
2200 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2200 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2201  
2202    double value = 0.0;
2203  
# Line 1047 | Line 2242 | OSUAnalysis::valueLookup (const BNtau* o
2242    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2243  
2244  
2245 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2245 >
2246 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2247 >
2248 >  else if(variable == "genMatchedPdgId"){
2249 >    int index = getGenMatchedParticleIndex(object);
2250 >    if(index == -1) value = 0;
2251 >    else value = mcparticles->at(index).id;
2252 >  }
2253 >
2254 >  else if(variable == "genMatchedId"){
2255 >    int index = getGenMatchedParticleIndex(object);
2256 >    if(index == -1) value = 0;
2257 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2258 >  }
2259 >  else if(variable == "genMatchedMotherId"){
2260 >    int index = getGenMatchedParticleIndex(object);
2261 >    if(index == -1) value = 0;
2262 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2263 >  }
2264 >  else if(variable == "genMatchedMotherIdReverse"){
2265 >    int index = getGenMatchedParticleIndex(object);
2266 >    if(index == -1) value = 24;
2267 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2268 >  }
2269 >  else if(variable == "genMatchedGrandmotherId"){
2270 >    int index = getGenMatchedParticleIndex(object);
2271 >    if(index == -1) value = 0;
2272 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2273 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2274 >      if(motherIndex == -1) value = 0;
2275 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2276 >    }
2277 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2278 >  }
2279 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2280 >    int index = getGenMatchedParticleIndex(object);
2281 >    if(index == -1) value = 24;
2282 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2283 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2284 >      if(motherIndex == -1) value = 24;
2285 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2286 >    }
2287 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2288 >  }
2289 >
2290 >
2291 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2292  
2293    value = applyFunction(function, value);
2294  
2295    return value;
2296   }
2297  
2298 + //!met valueLookup
2299   double
2300 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2300 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2301  
2302    double value = 0.0;
2303  
# Line 1119 | Line 2361 | OSUAnalysis::valueLookup (const BNmet* o
2361    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2362    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2363  
2364 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2364 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2365  
2366    value = applyFunction(function, value);
2367  
2368    return value;
2369   }
2370  
2371 + //!track valueLookup
2372   double
2373 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2373 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2374  
2375    double value = 0.0;
2376 +  double pMag = sqrt(object->pt * object->pt +
2377 +                     object->pz * object->pz);
2378  
2379    if(variable == "pt") value = object->pt;
2380    else if(variable == "px") value = object->px;
# Line 1150 | Line 2395 | OSUAnalysis::valueLookup (const BNtrack*
2395    else if(variable == "isHighPurity") value = object->isHighPurity;
2396  
2397  
2398 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2398 >  //additional BNs info for disappTrks
2399 >  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2400 >  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2401 >  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2402 >  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2403 >  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2404 >  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2405 >  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2406 >  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2407 >  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2408 >  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2409 >  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2410 >
2411 >  //user defined variables
2412 >  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;
2413 >  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2414 >  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2415 >  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2416 >  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2417 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2418 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2419 >  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2420 >  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2421 >  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2422 >  else if(variable == "ptError")                    value = object->ptError;
2423 >  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2424 >  else if (variable == "d0wrtPV"){
2425 >    double vx = object->vx - chosenVertex ()->x,
2426 >      vy = object->vy - chosenVertex ()->y,
2427 >      px = object->px,
2428 >      py = object->py,
2429 >      pt = object->pt;
2430 >    value = (-vx * py + vy * px) / pt;
2431 >  }
2432 >  else if (variable == "dZwrtPV"){
2433 >    double vx = object->vx - chosenVertex ()->x,
2434 >      vy = object->vy - chosenVertex ()->y,
2435 >      vz = object->vz - chosenVertex ()->z,
2436 >      px = object->px,
2437 >      py = object->py,
2438 >      pz = object->pz,
2439 >      pt = object->pt;
2440 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2441 >  }
2442 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2443 >
2444 >  else if(variable == "genMatchedPdgId"){
2445 >    int index = getGenMatchedParticleIndex(object);
2446 >    if(index == -1) value = 0;
2447 >    else value = mcparticles->at(index).id;
2448 >  }
2449 >
2450 >
2451 >  else if(variable == "genMatchedId"){
2452 >    int index = getGenMatchedParticleIndex(object);
2453 >    if(index == -1) value = 0;
2454 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2455 >  }
2456 >  else if(variable == "genMatchedMotherId"){
2457 >    int index = getGenMatchedParticleIndex(object);
2458 >    if(index == -1) value = 0;
2459 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2460 >  }
2461 >  else if(variable == "genMatchedMotherIdReverse"){
2462 >    int index = getGenMatchedParticleIndex(object);
2463 >    if(index == -1) value = 24;
2464 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2465 >  }
2466 >  else if(variable == "genMatchedGrandmotherId"){
2467 >    int index = getGenMatchedParticleIndex(object);
2468 >    if(index == -1) value = 0;
2469 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2470 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2471 >      if(motherIndex == -1) value = 0;
2472 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2473 >    }
2474 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2475 >  }
2476 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2477 >    int index = getGenMatchedParticleIndex(object);
2478 >    if(index == -1) value = 24;
2479 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2480 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2481 >      if(motherIndex == -1) value = 24;
2482 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2483 >    }
2484 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2485 >  }
2486 >
2487 >
2488 >
2489 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2490  
2491    value = applyFunction(function, value);
2492  
2493    return value;
2494   }
2495  
2496 + //!genjet valueLookup
2497   double
2498 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2498 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2499  
2500    double value = 0.0;
2501  
# Line 1178 | Line 2515 | OSUAnalysis::valueLookup (const BNgenjet
2515    else if(variable == "charge") value = object->charge;
2516  
2517  
2518 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2518 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2519  
2520    value = applyFunction(function, value);
2521  
2522    return value;
2523   }
2524  
2525 + //!mcparticle valueLookup
2526   double
2527 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2527 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2528  
2529    double value = 0.0;
2530  
# Line 1275 | Line 2613 | OSUAnalysis::valueLookup (const BNmcpart
2613    else if(variable == "grandMother11Status") value = object->grandMother11Status;
2614    else if(variable == "grandMother11Charge") value = object->grandMother11Charge;
2615  
2616 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2616 >  //user-defined variables
2617 >  else if (variable == "d0"){
2618 >    double vx = object->vx - chosenVertex ()->x,
2619 >      vy = object->vy - chosenVertex ()->y,
2620 >      px = object->px,
2621 >      py = object->py,
2622 >      pt = object->pt;
2623 >    value = (-vx * py + vy * px) / pt;
2624 >  }
2625 >  else if (variable == "dz"){
2626 >    double vx = object->vx - chosenVertex ()->x,
2627 >      vy = object->vy - chosenVertex ()->y,
2628 >      vz = object->vz - chosenVertex ()->z,
2629 >      px = object->px,
2630 >      py = object->py,
2631 >      pz = object->pz,
2632 >      pt = object->pt;
2633 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2634 >  }
2635 >  else if(variable == "v0"){
2636 >    value = sqrt(object->vx*object->vx + object->vy*object->vy);
2637 >  }
2638 >  else if(variable == "deltaV0"){
2639 >    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
2640 >  }
2641 >  else if (variable == "deltaVx"){
2642 >    value = object->vx - chosenVertex ()->x;
2643 >  }
2644 >  else if (variable == "deltaVy"){
2645 >    value = object->vy - chosenVertex ()->y;
2646 >  }
2647 >  else if (variable == "deltaVz"){
2648 >    value = object->vz - chosenVertex ()->z;
2649 >  }
2650 >
2651 >
2652 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2653  
2654    value = applyFunction(function, value);
2655  
2656    return value;
2657   }
2658  
2659 + //!primaryvertex valueLookup
2660   double
2661 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2661 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2662  
2663    double value = 0.0;
2664  
# Line 1302 | Line 2677 | OSUAnalysis::valueLookup (const BNprimar
2677    else if(variable == "isGood") value = object->isGood;
2678  
2679  
2680 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2680 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2681  
2682    value = applyFunction(function, value);
2683  
2684    return value;
2685   }
2686  
2687 + //!bxlumi valueLookup
2688   double
2689 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2689 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2690  
2691    double value = 0.0;
2692  
# Line 1319 | Line 2695 | OSUAnalysis::valueLookup (const BNbxlumi
2695    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2696  
2697  
2698 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2698 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2699  
2700    value = applyFunction(function, value);
2701  
2702    return value;
2703   }
2704  
2705 + //!photon valueLookup
2706   double
2707 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2707 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2708  
2709    double value = 0.0;
2710  
# Line 1402 | Line 2779 | OSUAnalysis::valueLookup (const BNphoton
2779    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2780  
2781  
2782 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2782 >
2783 >
2784 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2785 >
2786 >  else if(variable == "genMatchedPdgId"){
2787 >    int index = getGenMatchedParticleIndex(object);
2788 >    if(index == -1) value = 0;
2789 >    else value = mcparticles->at(index).id;
2790 >  }
2791 >
2792 >
2793 >
2794 >  else if(variable == "genMatchedId"){
2795 >    int index = getGenMatchedParticleIndex(object);
2796 >    if(index == -1) value = 0;
2797 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2798 >  }
2799 >  else if(variable == "genMatchedMotherId"){
2800 >    int index = getGenMatchedParticleIndex(object);
2801 >    if(index == -1) value = 0;
2802 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2803 >  }
2804 >  else if(variable == "genMatchedMotherIdReverse"){
2805 >    int index = getGenMatchedParticleIndex(object);
2806 >    if(index == -1) value = 24;
2807 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2808 >  }
2809 >  else if(variable == "genMatchedGrandmotherId"){
2810 >    int index = getGenMatchedParticleIndex(object);
2811 >    if(index == -1) value = 0;
2812 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2813 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2814 >      if(motherIndex == -1) value = 0;
2815 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2816 >    }
2817 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2818 >  }
2819 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2820 >    int index = getGenMatchedParticleIndex(object);
2821 >    if(index == -1) value = 24;
2822 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2823 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2824 >      if(motherIndex == -1) value = 24;
2825 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2826 >    }
2827 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2828 >  }
2829 >
2830 >
2831 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2832  
2833    value = applyFunction(function, value);
2834  
2835    return value;
2836   }
2837  
2838 + //!supercluster valueLookup
2839   double
2840 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
2840 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
2841  
2842    double value = 0.0;
2843  
# Line 1424 | Line 2851 | OSUAnalysis::valueLookup (const BNsuperc
2851    else if(variable == "theta") value = object->theta;
2852  
2853  
2854 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2855 +
2856 +  value = applyFunction(function, value);
2857 +
2858 +  return value;
2859 + }
2860 +
2861 + //!trigobj valueLookup
2862 + double
2863 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
2864 +
2865 +  double value = 0.0;
2866 +
2867 +  if(variable == "pt") value = object->pt;
2868 +  else if(variable == "eta") value = object->eta;
2869 +  else if(variable == "phi") value = object->phi;
2870 +  else if(variable == "px") value = object->px;
2871 +  else if(variable == "py") value = object->py;
2872 +  else if(variable == "pz") value = object->pz;
2873 +  else if(variable == "et") value = object->et;
2874 +  else if(variable == "energy") value = object->energy;
2875 +  else if(variable == "etTotal") value = object->etTotal;
2876 +  else if(variable == "id") value = object->id;
2877 +  else if(variable == "charge") value = object->charge;
2878 +  else if(variable == "isIsolated") value = object->isIsolated;
2879 +  else if(variable == "isMip") value = object->isMip;
2880 +  else if(variable == "isForward") value = object->isForward;
2881 +  else if(variable == "isRPC") value = object->isRPC;
2882 +  else if(variable == "bx") value = object->bx;
2883 +  else if(variable == "filter") {
2884 +    if ((stringValue = object->filter) == "")
2885 +      stringValue = "none";  // stringValue should only be empty if value is filled
2886 +  }
2887 +
2888 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2889 +
2890 +  value = applyFunction(function, value);
2891 +
2892 +  return value;
2893 + }
2894 +
2895 + //!muon-muon pair valueLookup
2896 + double
2897 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
2898 +
2899 +  double value = 0.0;
2900 +
2901 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2902 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2903 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2904 +  else if(variable == "invMass"){
2905 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2906 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2907 +    value = (fourVector1 + fourVector2).M();
2908 +  }
2909 +  else if(variable == "pt"){
2910 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2911 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2912 +    value = (fourVector1 + fourVector2).Pt();
2913 +  }
2914 +  else if(variable == "threeDAngle")
2915 +    {
2916 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2917 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2918 +      value = (threeVector1.Angle(threeVector2));
2919 +    }
2920 +  else if(variable == "alpha")
2921 +    {
2922 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
2923 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2924 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2925 +      value = (pi-threeVector1.Angle(threeVector2));
2926 +    }
2927 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2928 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2929 +  else if(variable == "d0Sign"){
2930 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2931 +    if(d0Sign < 0) value = -0.5;
2932 +    else if (d0Sign > 0) value = 0.5;
2933 +    else value = -999;
2934 +  }
2935 +  else if(variable == "chargeProduct"){
2936 +    value = object1->charge*object2->charge;
2937 +  }
2938 +  else if(variable == "muon1CorrectedD0Vertex"){
2939 +    value = object1->correctedD0Vertex;
2940 +  }
2941 +  else if(variable == "muon2CorrectedD0Vertex"){
2942 +    value = object2->correctedD0Vertex;
2943 +  }
2944 +  else if(variable == "muon1timeAtIpInOut"){
2945 +    value = object1->timeAtIpInOut;
2946 +  }
2947 +  else if(variable == "muon2timeAtIpInOut"){
2948 +    value = object2->timeAtIpInOut;
2949 +  }
2950 +  else if(variable == "muon1correctedD0")
2951 +    {
2952 +      value = object1->correctedD0;
2953 +    }
2954 +  else if(variable == "muon2correctedD0")
2955 +    {
2956 +      value = object2->correctedD0;
2957 +    }
2958 +
2959 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2960 +
2961 +  value = applyFunction(function, value);
2962 +
2963 +  return value;
2964 + }
2965 +
2966 + //!electron-electron pair valueLookup
2967 + double
2968 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
2969 +
2970 +  double value = 0.0;
2971 +
2972 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2973 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2974 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2975 +  else if(variable == "invMass"){
2976 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2977 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2978 +    value = (fourVector1 + fourVector2).M();
2979 +  }
2980 +  else if(variable == "pt"){
2981 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2982 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2983 +    value = (fourVector1 + fourVector2).Pt();
2984 +  }
2985 +  else if(variable == "threeDAngle")
2986 +    {
2987 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2988 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2989 +      value = (threeVector1.Angle(threeVector2));
2990 +    }
2991 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2992 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2993 +  else if(variable == "d0Sign"){
2994 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2995 +    if(d0Sign < 0) value = -0.5;
2996 +    else if (d0Sign > 0) value = 0.5;
2997 +    else value = -999;
2998 +  }
2999 +  else if(variable == "chargeProduct"){
3000 +    value = object1->charge*object2->charge;
3001 +  }
3002 +  else if(variable == "electron1CorrectedD0Vertex"){
3003 +    value = object1->correctedD0Vertex;
3004 +  }
3005 +  else if(variable == "electron2CorrectedD0Vertex"){
3006 +    value = object2->correctedD0Vertex;
3007 +  }
3008 +  else if(variable == "electron1CorrectedD0"){
3009 +    value = object1->correctedD0;
3010 +  }
3011 +  else if(variable == "electron2CorrectedD0"){
3012 +    value = object2->correctedD0;
3013 +  }
3014 +
3015 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3016 +
3017 +  value = applyFunction(function, value);
3018 +
3019 +  return value;
3020 + }
3021 + //!electron-muon pair valueLookup
3022 + double
3023 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3024 +
3025 +  double value = 0.0;
3026 +
3027 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3028 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3029 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3030 +  else if(variable == "invMass"){
3031 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3032 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3033 +    value = (fourVector1 + fourVector2).M();
3034 +  }
3035 +  else if(variable == "pt"){
3036 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3037 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3038 +    value = (fourVector1 + fourVector2).Pt();
3039 +  }
3040 +  else if(variable == "threeDAngle")
3041 +    {
3042 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3043 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3044 +      value = (threeVector1.Angle(threeVector2));
3045 +    }
3046 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3047 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3048 +  else if(variable == "d0Sign"){
3049 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3050 +    if(d0Sign < 0) value = -0.5;
3051 +    else if (d0Sign > 0) value = 0.5;
3052 +    else value = -999;
3053 +  }
3054 +  else if(variable == "chargeProduct"){
3055 +    value = object1->charge*object2->charge;
3056 +  }
3057 +  else if(variable == "electronCorrectedD0Vertex"){
3058 +    value = object1->correctedD0Vertex;
3059 +  }
3060 +  else if(variable == "muonCorrectedD0Vertex"){
3061 +    value = object2->correctedD0Vertex;
3062 +  }
3063 +  else if(variable == "electronCorrectedD0"){
3064 +    value = object1->correctedD0;
3065 +  }
3066 +  else if(variable == "muonCorrectedD0"){
3067 +    value = object2->correctedD0;
3068 +  }
3069 +  else if(variable == "electronDetIso"){
3070 +    value = (object1->trackIso) / object1->pt;
3071 +  }
3072 +  else if(variable == "muonDetIso"){
3073 +    value = (object2->trackIsoDR03) / object2->pt;
3074 +  }
3075 +  else if(variable == "electronRelPFrhoIso"){
3076 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3077 +  }
3078 +  else if(variable == "muonRelPFdBetaIso"){
3079 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3080 +  }
3081 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3082 +  value = applyFunction(function, value);
3083 +
3084 +  return value;
3085 + }
3086 +
3087 + //!electron-jet pair valueLookup
3088 + double
3089 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3090 +
3091 +  double value = 0.0;
3092 +
3093 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3094 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3095 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3096 +  else if(variable == "invMass"){
3097 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3098 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3099 +    value = (fourVector1 + fourVector2).M();
3100 +  }
3101 +  else if(variable == "pt"){
3102 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3103 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3104 +    value = (fourVector1 + fourVector2).Pt();
3105 +  }
3106 +  else if(variable == "threeDAngle")
3107 +    {
3108 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3109 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3110 +      value = (threeVector1.Angle(threeVector2));
3111 +    }
3112 +  else if(variable == "chargeProduct"){
3113 +    value = object1->charge*object2->charge;
3114 +  }
3115 +
3116 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3117 +  value = applyFunction(function, value);
3118 +
3119 +  return value;
3120 + }
3121 +
3122 + //!muon-jet pair valueLookup
3123 + double
3124 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3125 +
3126 +  double value = 0.0;
3127 +
3128 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3129 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3130 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3131 +  else if(variable == "invMass"){
3132 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3133 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3134 +    value = (fourVector1 + fourVector2).M();
3135 +  }
3136 +  else if(variable == "pt"){
3137 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3138 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3139 +    value = (fourVector1 + fourVector2).Pt();
3140 +  }
3141 +  else if(variable == "threeDAngle")
3142 +    {
3143 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3144 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3145 +      value = (threeVector1.Angle(threeVector2));
3146 +    }
3147 +  else if(variable == "chargeProduct"){
3148 +    value = object1->charge*object2->charge;
3149 +  }
3150 +
3151 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3152 +  value = applyFunction(function, value);
3153 +
3154 +  return value;
3155 + }
3156 +
3157 + //!jet-jet pair valueLookup
3158 + double
3159 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3160 +
3161 +  double value = 0.0;
3162 +
3163 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3164 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3165 +  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3166 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3167 +  else if(variable == "invMass"){
3168 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3169 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3170 +    value = (fourVector1 + fourVector2).M();
3171 +  }
3172 +  else if(variable == "pt"){
3173 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3174 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3175 +    value = (fourVector1 + fourVector2).Pt();
3176 +  }
3177 +  else if(variable == "threeDAngle")
3178 +    {
3179 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3180 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3181 +      value = (threeVector1.Angle(threeVector2));
3182 +    }
3183 +  else if(variable == "chargeProduct"){
3184 +    value = object1->charge*object2->charge;
3185 +  }
3186 +
3187 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3188 +  value = applyFunction(function, value);
3189 +
3190 +  return value;
3191 + }
3192 + //!electron-track pair valueLookup
3193 + double
3194 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3195 +  double electronMass = 0.000511;
3196 +  double value = 0.0;
3197 +  TLorentzVector fourVector1(0, 0, 0, 0);
3198 +  TLorentzVector fourVector2(0, 0, 0, 0);
3199 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3200 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3201 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3202 +  else if(variable == "invMass"){
3203 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3204 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3205 +
3206 +    value = (fourVector1 + fourVector2).M();
3207 +  }
3208 +  else if(variable == "chargeProduct"){
3209 +    value = object1->charge*object2->charge;
3210 +  }
3211 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3212 +  value = applyFunction(function, value);
3213 +  return value;
3214 +
3215 + }
3216 +
3217 +
3218 + //!muon-track pair valueLookup
3219 + double
3220 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3221 +  double pionMass = 0.140;
3222 +  double muonMass = 0.106;
3223 +  double value = 0.0;
3224 +  TLorentzVector fourVector1(0, 0, 0, 0);
3225 +  TLorentzVector fourVector2(0, 0, 0, 0);
3226 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3227 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3228 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3229 +  else if(variable == "invMass"){
3230 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3231 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3232 +
3233 +    value = (fourVector1 + fourVector2).M();
3234 +  }
3235 +  else if(variable == "chargeProduct"){
3236 +    value = object1->charge*object2->charge;
3237 +  }
3238 +
3239 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3240 +  value = applyFunction(function, value);
3241 +  return value;
3242 + }
3243 +
3244 + //!tau-tau pair valueLookup
3245 + double
3246 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3247 +  double value = 0.0;
3248 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3249 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3250 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3251 +  else if(variable == "invMass"){
3252 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3253 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3254 +    value = (fourVector1 + fourVector2).M();
3255 +  }
3256 +
3257 +  else if(variable == "chargeProduct"){
3258 +    value = object1->charge*object2->charge;
3259 +  }
3260 +
3261 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3262 +  value = applyFunction(function, value);
3263 +  return value;
3264 + }
3265 +
3266 + //!muon-tau pair valueLookup
3267 + double
3268 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3269 +  double value = 0.0;
3270 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3271 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3272 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3273 +  else if(variable == "invMass"){
3274 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3275 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3276 +    value = (fourVector1 + fourVector2).M();
3277 +  }
3278 +
3279 +  else if(variable == "chargeProduct"){
3280 +    value = object1->charge*object2->charge;
3281 +  }
3282 +
3283 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3284 +  value = applyFunction(function, value);
3285 +  return value;
3286 + }
3287 +
3288 + //!tau-track pair valueLookup
3289 + double
3290 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3291 +  double value = 0.0;
3292 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3293 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3294 +  else if(variable == "chargeProduct"){
3295 +    value = object1->charge*object2->charge;
3296 +  }
3297 +
3298    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3299 +  value = applyFunction(function, value);
3300 +  return value;
3301 + }
3302 +
3303 +
3304 + //!track-event pair valueLookup
3305 + double
3306 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3307 +
3308 +  double value = 0.0;
3309 +  double pMag = sqrt(object1->pt * object1->pt +
3310 +                     object1->pz * object1->pz);
3311 +
3312 +  if      (variable == "numPV")                      value = object2->numPV;
3313 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3314 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3315 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3316 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3317 +
3318 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3319 +
3320 +  value = applyFunction(function, value);
3321 +
3322 +  return value;
3323 +
3324 + }
3325 +
3326 + //!electron-trigobj pair valueLookup
3327 + double
3328 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3329 +
3330 +  double value = 0.0;
3331 +
3332 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3333 +  else if (variable == "match"){
3334 +    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3335 +      stringValue = object2->filter;
3336 +    else
3337 +      stringValue = "none";
3338 +  }
3339 +
3340 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3341 +
3342 +  value = applyFunction(function, value);
3343 +
3344 +  return value;
3345 +
3346 + }
3347 +
3348 + //!muon-trigobj pair valueLookup
3349 + double
3350 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3351 +
3352 +  double value = 0.0;
3353 +
3354 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3355 +
3356 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3357  
3358    value = applyFunction(function, value);
3359  
3360    return value;
3361 +
3362 + }
3363 +
3364 + //!stop valueLookup
3365 + double
3366 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3367 +
3368 +
3369 +  double value = 0.0;
3370 +
3371 +  if(variable == "ctau") value = object->ctau;
3372 +
3373 +  else if (variable == "d0"){
3374 +    double vx = object->vx - chosenVertex ()->x,
3375 +      vy = object->vy - chosenVertex ()->y,
3376 +      px = object->px,
3377 +      py = object->py,
3378 +      pt = object->pt;
3379 +    value = (-vx * py + vy * px) / pt;
3380 +  }
3381 +
3382 +  else if (variable == "dz"){
3383 +    double vx = object->vx - chosenVertex ()->x,
3384 +      vy = object->vy - chosenVertex ()->y,
3385 +      vz = object->vz - chosenVertex ()->z,
3386 +      px = object->px,
3387 +      py = object->py,
3388 +      pz = object->pz,
3389 +      pt = object->pt;
3390 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3391 +  }
3392 +
3393 +  else if (variable == "minD0"){
3394 +    double minD0=999;
3395 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3396 +      double vx = object->vx - vertex->x,
3397 +        vy = object->vy - vertex->y,
3398 +        px = object->px,
3399 +        py = object->py,
3400 +        pt = object->pt;
3401 +      value = (-vx * py + vy * px) / pt;
3402 +      if(abs(value) < abs(minD0)) minD0 = value;
3403 +    }
3404 +    value = minD0;
3405 +  }
3406 +  else if (variable == "minDz"){
3407 +    double minDz=999;
3408 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3409 +      double vx = object->vx - vertex->x,
3410 +        vy = object->vy - vertex->y,
3411 +        vz = object->vz - vertex->z,
3412 +        px = object->px,
3413 +        py = object->py,
3414 +        pz = object->pz,
3415 +        pt = object->pt;
3416 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3417 +      if(abs(value) < abs(minDz)) minDz = value;
3418 +    }
3419 +    value = minDz;
3420 +  }
3421 +  else if(variable == "distToVertex"){
3422 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3423 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3424 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3425 +  }
3426 +  else if (variable == "minDistToVertex"){
3427 +    double minDistToVertex=999;
3428 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3429 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3430 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3431 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3432 +
3433 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3434 +    }
3435 +    value = minDistToVertex;
3436 +  }
3437 +  else if (variable == "distToVertexDifference"){
3438 +    double minDistToVertex=999;
3439 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3440 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3441 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3442 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3443 +
3444 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3445 +    }
3446 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3447 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3448 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3449 +
3450 +    value = distToChosenVertex - minDistToVertex;
3451 +  }
3452 +
3453 +  else if (variable == "closestVertexRank"){
3454 +    double minDistToVertex=999;
3455 +    int vertex_rank = 0;
3456 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3457 +      vertex_rank++;
3458 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3459 +                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
3460 +                      (object->vz-vertex->z)*(object->vz-vertex->z));
3461 +
3462 +      if(abs(dist) < abs(minDistToVertex)){
3463 +        value = vertex_rank;
3464 +        minDistToVertex = dist;
3465 +      }
3466 +    }
3467 +  }
3468 +
3469 +
3470 +
3471 +
3472 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3473 +
3474 +  value = applyFunction(function, value);
3475 +
3476 +  return value;
3477 +
3478 + }
3479 +
3480 +
3481 +
3482 +
3483 + // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3484 + // Return true iff no other tracks are found in this cone.
3485 + int
3486 + OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
3487 +  for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
3488 +    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
3489 +    double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
3490 +    if(deltaRtrk < 0.5) return 0;
3491 +  }
3492 +  return 1;
3493 +
3494   }
3495  
3496  
3497   double
3498 + OSUAnalysis::getTrkPtRes (const BNtrack* track1){
3499 +
3500 +  double ptTrue = getTrkPtTrue(track1, mcparticles.product());
3501 +  double PtRes = (track1->pt - ptTrue) / ptTrue;
3502 +
3503 +  return PtRes;
3504 +
3505 + }
3506 +
3507 +
3508 + double
3509 + OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
3510 +  double value = -99;
3511 +  double genDeltaRLowest = 999;
3512 +
3513 +  for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
3514 +    double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
3515 +    if (genDeltaRtemp < genDeltaRLowest) {
3516 +      genDeltaRLowest = genDeltaRtemp;
3517 +      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
3518 +        double ptTrue = genPart->pt;
3519 +        value = ptTrue;
3520 +      }
3521 +    }
3522 +  }
3523 +
3524 +  return value;
3525 +
3526 + }
3527 +
3528 + double
3529 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3530 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3531 +  if (!useTrackCaloRhoCorr_) return -99;
3532 +  // if (!rhokt6CaloJetsHandle_) {
3533 +  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3534 +  //   return -99;
3535 +  // }
3536 +  double radDeltaRCone = 0.5;
3537 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3538 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3539 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3540 +  return caloTotRhoCorrCalo;
3541 +
3542 + }
3543 +
3544 +
3545 +
3546 +
3547 + //creates a map of the dead Ecal channels in the barrel and endcap
3548 + //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
3549 + //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
3550 + void
3551 + OSUAnalysis::WriteDeadEcal (){
3552 +  double etaEcal, phiEcal;
3553 +  ifstream DeadEcalFile(deadEcalFile_);
3554 +  if(!DeadEcalFile) {
3555 +    cout << "Error: DeadEcalFile has not been found." << endl;
3556 +    return;
3557 +  }
3558 +  if(DeadEcalVec.size()!= 0){
3559 +    cout << "Error: DeadEcalVec has a nonzero size" << endl;
3560 +    return;
3561 +  }
3562 +  while(!DeadEcalFile.eof())
3563 +    {
3564 +      DeadEcalFile >> etaEcal >> phiEcal;
3565 +      DeadEcal newChan;
3566 +      newChan.etaEcal = etaEcal;
3567 +      newChan.phiEcal = phiEcal;
3568 +      DeadEcalVec.push_back(newChan);
3569 +    }
3570 +  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
3571 + }
3572 +
3573 + //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
3574 + int
3575 + OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
3576 +  double deltaRLowest = 999;
3577 +  int value = 0;
3578 +  if (DeadEcalVec.size() == 0) WriteDeadEcal();
3579 +  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3580 +    double eta = ecal->etaEcal;
3581 +    double phi = ecal->phiEcal;
3582 +    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
3583 +    if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3584 +  }
3585 +  if (deltaRLowest<0.05) {value = 1;}
3586 +  else {value = 0;}
3587 +  return value;
3588 + }
3589 +
3590 + // Returns the smallest DeltaR between the object and any generated true particle in the event.
3591 + template <class InputObject>
3592 + double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3593 +  double genDeltaRLowest = 999.;
3594 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3595 +    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
3596 +    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
3597 +  }
3598 +  return genDeltaRLowest;
3599 + }
3600 +
3601 + double
3602   OSUAnalysis::applyFunction(string function, double value){
3603  
3604 <  if(function == "abs") value = abs(value);
3604 >  if(function == "abs") value = fabs(value);
3605 >  else if(function == "fabs") value = fabs(value);
3606 >  else if(function == "log10") value = log10(value);
3607 >  else if(function == "log") value = log10(value);
3608  
3609 +  else if(function == "") value = value;
3610 +  else{cout << "WARNING: invalid function '" << function << "'\n";}
3611  
3612    return value;
3613  
# Line 1446 | Line 3617 | OSUAnalysis::applyFunction(string functi
3617   template <class InputCollection>
3618   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
3619  
3620 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
3621 +    string obj1, obj2;
3622 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
3623 +    if (inputType==obj1 ||
3624 +        inputType==obj2) {
3625 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
3626 +      // and the inputType is a member of the pair.
3627 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
3628 +      // For example, if currentCut.inputCollection==electron-muon pairs,
3629 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
3630 +      return;
3631 +    }
3632 +  }
3633  
3634    for (uint object = 0; object != inputCollection->size(); object++){
3635  
# Line 1453 | Line 3637 | void OSUAnalysis::setObjectFlags(cut &cu
3637  
3638      if(currentCut.inputCollection == inputType){
3639  
3640 <      double value = valueLookup(&inputCollection->at(object), currentCut.variable, currentCut.function);
3640 >      vector<bool> subcutDecisions;
3641 >      for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3642 >        string stringValue = "";
3643 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3644 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3645 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3646  
3647 <      decision = evaluateComparison(value,currentCut.comparativeOperator,currentCut.cutValue);
3647 >      }
3648 >      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3649 >      else{
3650 >        bool tempDecision = true;
3651 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
3652 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
3653 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
3654 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
3655 >            tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
3656 >        }
3657 >        decision = tempDecision;
3658 >      }
3659      }
1460    individualFlags[inputType].at(currentCutIndex).push_back(decision);
3660  
3661 +    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3662  
3663      //set flags for objects that pass each cut AND all the previous cuts
3664      bool previousCumulativeFlag = true;
3665      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3666 <      if(previousCumulativeFlag && individualFlags[inputType].at(previousCutIndex).at(object)) previousCumulativeFlag = true;
3666 >      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
3667        else{ previousCumulativeFlag = false; break;}
3668      }
3669 <    cumulativeFlags[inputType].at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3669 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3670  
3671    }
3672  
3673   }
3674  
3675  
3676 + template <class InputCollection1, class InputCollection2>
3677 + void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
3678 +                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
3679 +
3680 +
3681 +  bool sameObjects = false;
3682 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3683 +
3684 +  // Get the strings for the two objects that make up the pair.
3685 +  string obj1Type, obj2Type;
3686 +  getTwoObjs(inputType, obj1Type, obj2Type);
3687 +  bool isTwoTypesOfObject = true;
3688 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
3689 +
3690 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
3691 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
3692 +  if (currentCut.inputCollection == inputType) {
3693 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
3694 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3695 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3696 +    }
3697 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
3698 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
3699 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3700 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3701 +      }
3702 +    }
3703 +  }
3704  
3705 +  int counter = 0;
3706  
3707 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3708 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3709  
3710 < DEFINE_FWK_MODULE(OSUAnalysis);
3710 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3711 >
3712 >
3713 >      bool decision = true;//object passes if this cut doesn't cut on that type of object
3714 >
3715 >      if(currentCut.inputCollection == inputType){
3716 >
3717 >        vector<bool> subcutDecisions;
3718 >        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3719 >          string stringValue = "";
3720 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3721 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3722 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3723 >        }
3724 >
3725 >        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3726 >        else{
3727 >          bool tempDecision = subcutDecisions.at(0);
3728 >          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
3729 >            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
3730 >              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
3731 >            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
3732 >              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
3733 >          }
3734 >          decision = tempDecision;
3735 >        }
3736 >      }
3737 >      // if (decision) isPassObj1.at(object1) = true;
3738 >      // if (decision) isPassObj2.at(object2) = true;
3739 >      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3740 >      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3741 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;
3742 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;
3743 >      }
3744 >
3745 >      //set flags for objects that pass each cut AND all the previous cuts
3746 >      bool previousCumulativeFlag = true;
3747 >      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3748 >        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
3749 >        else{ previousCumulativeFlag = false; break;}
3750 >      }
3751 >      //apply flags for the components of the composite object as well
3752 >      bool currentCumulativeFlag = true;
3753 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
3754 >      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
3755 >      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
3756 >      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
3757 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
3758 >      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3759 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);
3760 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);
3761 >      }
3762 >      counter++;
3763 >
3764 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
3765 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
3766 >
3767 > }
3768 >
3769 >
3770 > bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
3771 >  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
3772 >  // all cuts up to currentCutIndex
3773 >  bool previousCumulativeFlag = true;
3774 >  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
3775 >    if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
3776 >    else {
3777 >      previousCumulativeFlag = false; break;
3778 >    }
3779 >  }
3780 >  return previousCumulativeFlag;
3781 > }
3782 >
3783 >
3784 >
3785 > template <class InputCollection>
3786 > void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, vector<bool> flags){
3787 >  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree  
3788 >
3789 >  for (uint object = 0; object != inputCollection->size(); object++){
3790 >
3791 >    if (!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3792 >
3793 >    string inputVariable = parameters.inputVariable;
3794 >    string function = "";
3795 >    string stringValue = "";  
3796 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);  
3797 >    BNTreeBranchVals_.at(parameters.name).push_back(value);  
3798 >
3799 >  }
3800 > }
3801 >
3802 >
3803 > template <class InputCollection>
3804 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3805  
3806 +  for (uint object = 0; object != inputCollection->size(); object++){
3807 +
3808 +    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3809 +
3810 +    string currentString = parameters.inputVariables.at(0);
3811 +    string inputVariable = "";
3812 +    string function = "";
3813 +    if(currentString.find("(")==string::npos){
3814 +      inputVariable = currentString;// variable to cut on
3815 +    }
3816 +    else{
3817 +      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3818 +      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3819 +      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3820 +    }  
3821 +
3822 +    string stringValue = "";  
3823 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);  
3824 +    histo->Fill(value,scaleFactor);  
3825 +
3826 +    if (printEventInfo_) {
3827 +      // Write information about event to screen, for testing purposes.
3828 +      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
3829 +    }
3830 +
3831 +  }
3832 + }
3833 +
3834 + template <class InputCollection1, class InputCollection2>
3835 + void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3836 +
3837 +  bool sameObjects = false;
3838 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3839 +
3840 +  int pairCounter = -1;
3841 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3842 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3843 +
3844 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3845 +
3846 +      pairCounter++;
3847 +      //only take objects which have passed all cuts and pairs which have passed all cuts
3848 +      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3849 +      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3850 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3851 +
3852 +      string currentString = parameters.inputVariables.at(0);
3853 +      string inputVariable = "";
3854 +      string function = "";
3855 +      if(currentString.find("(")==string::npos){
3856 +        inputVariable = currentString;// variable to cut on
3857 +      }
3858 +      else{
3859 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3860 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3861 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3862 +      }
3863 +
3864 +      string stringValue = "";
3865 +      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3866 +      histo->Fill(value,scaleFactor);
3867 +
3868 +    }
3869 +  }
3870 +
3871 + }
3872 +
3873 +
3874 + template <class InputCollection>
3875 + void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3876 +
3877 +  for (uint object = 0; object != inputCollection->size(); object++){
3878  
3879 +    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3880 +
3881 +    string stringValue = "";
3882 +    string currentString = parameters.inputVariables.at(0);
3883 +    string inputVariable = "";
3884 +    string function = "";
3885 +    if(currentString.find("(")==string::npos){
3886 +      inputVariable = currentString;// variable to cut on
3887 +    }
3888 +    else{
3889 +      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3890 +      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3891 +      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3892 +    }
3893 +    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3894 +
3895 +    currentString = parameters.inputVariables.at(1);
3896 +    inputVariable = "";
3897 +    function = "";
3898 +    if(currentString.find("(")==string::npos){
3899 +      inputVariable = currentString;// variable to cut on
3900 +    }
3901 +    else{
3902 +      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3903 +      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3904 +      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3905 +    }
3906 +
3907 +    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3908 +
3909 +    histo->Fill(valueX,valueY,scaleFactor);
3910 +
3911 +  }
3912 +
3913 + }
3914 +
3915 + template <class InputCollection1, class InputCollection2>
3916 + void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3917 +
3918 +  bool sameObjects = false;
3919 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3920 +
3921 +  int pairCounter = -1;
3922 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3923 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3924 +
3925 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3926 +
3927 +      pairCounter++;
3928 +
3929 +      //only take objects which have passed all cuts and pairs which have passed all cuts
3930 +      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3931 +      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3932 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3933 +
3934 +      string stringValue = "";
3935 +      string currentString = parameters.inputVariables.at(0);
3936 +      string inputVariable = "";
3937 +      string function = "";
3938 +      if(currentString.find("(")==string::npos){
3939 +        inputVariable = currentString;// variable to cut on
3940 +      }
3941 +      else{
3942 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3943 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3944 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3945 +      }
3946 +      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3947 +
3948 +      currentString = parameters.inputVariables.at(1);
3949 +      inputVariable = "";
3950 +      function = "";
3951 +      if(currentString.find("(")==string::npos){
3952 +        inputVariable = currentString;// variable to cut on
3953 +      }
3954 +      else{
3955 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3956 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3957 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3958 +      }
3959 +      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3960 +
3961 +
3962 +      histo->Fill(valueX,valueY,scaleFactor);
3963 +
3964 +    }
3965 +  }
3966 +
3967 + }
3968 +
3969 +
3970 + template <class InputObject>
3971 + int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
3972 +
3973 +  int bestMatchIndex = -1;
3974 +  double bestMatchDeltaR = 999;
3975 +
3976 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3977 +
3978 +    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
3979 +    if(currentDeltaR > 0.05) continue;
3980 +    //     cout << setprecision(3) << setw(20)
3981 +    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
3982 +    //          << setw(20)
3983 +    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
3984 +    //          << setw(20)
3985 +    //          << "\tdeltaR = " << currentDeltaR
3986 +    //          << setprecision(1)
3987 +    //          << setw(20)
3988 +    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
3989 +    //          << setw(20)
3990 +    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
3991 +    //          << setw(20)
3992 +    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
3993 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
3994 +      bestMatchIndex = mcparticle - mcparticles->begin();
3995 +      bestMatchDeltaR = currentDeltaR;
3996 +    }
3997 +
3998 +  }
3999 +  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4000 +  //   else cout << "no match found..." << endl;
4001 +  return bestMatchIndex;
4002 +
4003 + }
4004 +
4005 +
4006 + int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
4007 +
4008 +  int bestMatchIndex = -1;
4009 +  double bestMatchDeltaR = 999;
4010 +
4011 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4012 +
4013 +    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
4014 +
4015 +    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
4016 +    if(currentDeltaR > 0.05) continue;
4017 +
4018 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4019 +      bestMatchIndex = mcparticle - mcparticles->begin();
4020 +      bestMatchDeltaR = currentDeltaR;
4021 +    }
4022 +
4023 +  }
4024 +
4025 +  return bestMatchIndex;
4026 + }
4027 +
4028 +
4029 + // bin      particle type
4030 + // ---      -------------
4031 + //  0        unmatched
4032 + //  1        u
4033 + //  2        d
4034 + //  3        s
4035 + //  4        c
4036 + //  5        b
4037 + //  6        t
4038 + //  7        e
4039 + //  8        mu
4040 + //  9        tau
4041 + // 10        nu
4042 + // 11        g
4043 + // 12        gamma
4044 + // 13        Z
4045 + // 14        W
4046 + // 15        light meson
4047 + // 16        K meson
4048 + // 17        D meson
4049 + // 18        B meson
4050 + // 19        light baryon
4051 + // 20        strange baryon
4052 + // 21        charm baryon
4053 + // 22        bottom baryon
4054 + // 23        QCD string
4055 + // 24        other
4056 +
4057 + int OSUAnalysis::getPdgIdBinValue(int pdgId){
4058 +
4059 +  int binValue = -999;
4060 +  int absPdgId = fabs(pdgId);
4061 +  if(pdgId == -1) binValue = 0;
4062 +  else if(absPdgId <= 6 ) binValue = absPdgId;
4063 +  else if(absPdgId == 11 ) binValue = 7;
4064 +  else if(absPdgId == 13 ) binValue = 8;
4065 +  else if(absPdgId == 15 ) binValue = 9;
4066 +  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
4067 +  else if(absPdgId == 21 ) binValue = 11;
4068 +  else if(absPdgId == 22 ) binValue = 12;
4069 +  else if(absPdgId == 23 ) binValue = 13;
4070 +  else if(absPdgId == 24 ) binValue = 14;
4071 +  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
4072 +  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
4073 +  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
4074 +  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
4075 +  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
4076 +  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4077 +  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4078 +  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4079 +  else if(absPdgId == 92  ) binValue = 23;
4080 +
4081 +  else binValue = 24;
4082 +
4083 +  return binValue;
4084 +
4085 + }
4086 +
4087 + const BNprimaryvertex *
4088 + OSUAnalysis::chosenVertex ()
4089 + {
4090 +  const BNprimaryvertex *chosenVertex = 0;
4091 +  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4092 +    vector<bool> vertexFlags;
4093 +    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4094 +      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4095 +        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4096 +        break;
4097 +      }
4098 +    }
4099 +    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4100 +      if(!vertexFlags.at(vertexIndex)) continue;
4101 +      chosenVertex = & primaryvertexs->at(vertexIndex);
4102 +      break;
4103 +    }
4104 +  }
4105 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4106 +    chosenVertex = & primaryvertexs->at (0);
4107 +
4108 +  return chosenVertex;
4109 + }
4110 +
4111 + const BNmet *
4112 + OSUAnalysis::chosenMET ()
4113 + {
4114 +  const BNmet *chosenMET = 0;
4115 +  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4116 +    vector<bool> metFlags;
4117 +    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4118 +      if (cumulativeFlags.at("mets").at(i).size()){
4119 +        metFlags = cumulativeFlags.at("mets").at(i);
4120 +        break;
4121 +      }
4122 +    }
4123 +    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4124 +      if(!metFlags.at(metIndex)) continue;
4125 +      chosenMET = & mets->at(metIndex);
4126 +      break;
4127 +    }
4128 +  }
4129 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4130 +    chosenMET = & mets->at (0);
4131 +
4132 +  return chosenMET;
4133 + }
4134 +
4135 + const BNelectron *
4136 + OSUAnalysis::chosenElectron ()
4137 + {
4138 +  const BNelectron *chosenElectron = 0;
4139 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4140 +    vector<bool> electronFlags;
4141 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4142 +      if (cumulativeFlags.at("electrons").at(i).size()){
4143 +        electronFlags = cumulativeFlags.at("electrons").at(i);
4144 +        break;
4145 +      }
4146 +    }
4147 +    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4148 +      if(!electronFlags.at(electronIndex)) continue;
4149 +      chosenElectron = & electrons->at(electronIndex);
4150 +      break;
4151 +    }
4152 +  }
4153 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4154 +    chosenElectron = & electrons->at (0);
4155 +
4156 +  return chosenElectron;
4157 + }
4158 +
4159 + const BNmuon *
4160 + OSUAnalysis::chosenMuon ()
4161 + {
4162 +  const BNmuon *chosenMuon = 0;
4163 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4164 +    vector<bool> muonFlags;
4165 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4166 +      if (cumulativeFlags.at("muons").at(i).size()){
4167 +        muonFlags = cumulativeFlags.at("muons").at(i);
4168 +        break;
4169 +      }
4170 +    }
4171 +    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4172 +      if(!muonFlags.at(muonIndex)) continue;
4173 +      chosenMuon = & muons->at(muonIndex);
4174 +      break;
4175 +    }
4176 +  }
4177 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4178 +    chosenMuon = & muons->at (0);
4179 +
4180 +  return chosenMuon;
4181 + }
4182 +
4183 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines