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.85 by ahart, Tue Jun 11 00:36:10 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines