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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines