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.84 by ahart, Thu Jun 6 11:44:32 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines