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.99 by biliu, Thu Jul 11 16:40:01 2013 UTC

# Line 1 | Line 1
1   #include "OSUT3Analysis/AnaTools/plugins/OSUAnalysis.h"
2
2   OSUAnalysis::OSUAnalysis (const edm::ParameterSet &cfg) :
3    // Retrieve parameters from the configuration file.
4    jets_ (cfg.getParameter<edm::InputTag> ("jets")),
# Line 11 | Line 10 | OSUAnalysis::OSUAnalysis (const edm::Par
10    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
11    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
12    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
13 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
14    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
15    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
16    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
17    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
18    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
19 +  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
20 +  puFile_ (cfg.getParameter<string> ("puFile")),
21 +  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
22 +  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
23 +  dataPU_ (cfg.getParameter<string> ("dataPU")),
24 +  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
25 +  muonSF_ (cfg.getParameter<string> ("muonSF")),
26 +  dataset_ (cfg.getParameter<string> ("dataset")),
27 +  datasetType_ (cfg.getParameter<string> ("datasetType")),
28 +  channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
29 +  histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
30 +  useEDMFormat_   (cfg.getParameter<bool>("useEDMFormat")),
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 +  printEventInfo_      (cfg.getParameter<bool> ("printEventInfo")),
38 +  printAllTriggers_    (cfg.getParameter<bool> ("printAllTriggers")),
39 +  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
40 +  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
41 +  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
42 + {
43  
44 +  TH1::SetDefaultSumw2 ();
45  
46 <  channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels"))
46 >  //create pile-up reweighting object, if necessary
47 >  if(datasetType_ != "data") {
48 >    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
49 >    if (applyLeptonSF_){
50 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
51 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
52 >    }
53 >    if (applyBtagSF_){
54 >      bTagSFWeight_ = new BtagSFWeight;
55 >    }
56 >  }
57 >  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
58 >    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
59  
23 {
24  TH1::SetDefaultSumw2 ();
60  
61    // Construct Cutflow Objects. These store the results of cut decisions and
62    // handle filling cut flow histograms.
63    masterCutFlow_ = new CutFlow (fs_);
64 <  std::vector<TFileDirectory> directories;
64 >
65 >  //always get vertex collection so we can assign the primary vertex in the event
66 >  objectsToGet.push_back("primaryvertexs");
67 >  objectsToPlot.push_back("primaryvertexs");
68 >  objectsToFlag.push_back("primaryvertexs");
69 >
70 >
71 >  //always get the MC particles to do GEN-matching
72 >  objectsToGet.push_back("mcparticles");
73 >
74 >  //always get the event collection to do pile-up reweighting
75 >  objectsToGet.push_back("events");
76 >
77 >
78 >  // Parse the tree variable definitions.
79 >  for (uint iBranchSet = 0; !useEDMFormat_ && iBranchSet<treeBranchSets_.size(); iBranchSet++) {
80 >    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
81 >    if(tempInputCollection.find("pairs")!=string::npos) { clog << "Warning:  tree filling is not configured for pairs of objects, so will not work for collection: " << tempInputCollection << endl; }
82 >    objectsToGet.push_back(tempInputCollection);
83 >    objectsToFlag.push_back(tempInputCollection);
84 >
85 >    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
86 >
87 >    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
88 >      BranchSpecs br;
89 >      br.inputCollection = tempInputCollection;
90 >      br.inputVariable = branchList.at(iBranch);
91 >      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);
92 >      br.name = string(newName.Data());
93 >      treeBranches_.push_back(br);
94 >    }
95 >
96 >  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++)
97 >
98 >
99 >  //parse the histogram definitions
100 >  for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
101 >
102 >    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
103 >    if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
104 >    if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
105 >    if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
106 >    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
107 >    if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
108 >    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
109 >    if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
110 >    if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
111 >    if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
112 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
113 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
114 >    if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
115 >    if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
116 >    if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
117 >    if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
118 >    if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
119 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
120 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
121 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
122 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
123 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
124 >        int spaceIndex = tempInputCollection.find(" ");
125 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
126 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
127 >      }
128 >      else{
129 >        objectsToGet.push_back(tempInputCollection);
130 >      }
131 >      objectsToPlot.push_back(tempInputCollection);
132 >      objectsToFlag.push_back(tempInputCollection);
133 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
134 >      string obj1;
135 >      string obj2;
136 >      getTwoObjs(tempInputCollection, obj1, obj2);
137 >      string obj2ToGet = getObjToGet(obj2);
138 >      objectsToFlag.push_back(tempInputCollection);
139 >      objectsToFlag.push_back(obj1);
140 >      objectsToFlag.push_back(obj2);
141 >      objectsToPlot.push_back(tempInputCollection);
142 >      objectsToPlot.push_back(obj1);
143 >      objectsToPlot.push_back(obj2);
144 >      objectsToGet.push_back(tempInputCollection);
145 >      objectsToGet.push_back(obj1);
146 >      objectsToGet.push_back(obj2ToGet);
147 >    } // end else
148 >      if (find(objectsToPlot.begin(), objectsToPlot.end(), "events") != objectsToPlot.end())
149 >        objectsToGet.push_back("jets");
150 >
151 >
152 >    vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
153 >
154 >    for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
155 >
156 >      vector<double> defaultValue;
157 >      defaultValue.push_back (-1.0);
158 >
159 >      histogram tempHistogram;
160 >      tempHistogram.inputCollection = tempInputCollection;
161 >      tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
162 >      tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
163 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
164 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
165 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
166 >      tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
167 >
168 >      histograms.push_back(tempHistogram);
169 >
170 >    }
171 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
172 >
173 >  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
174 >  sort( objectsToPlot.begin(), objectsToPlot.end() );
175 >  objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
176 >
177 >
178 >
179 >  //add histograms with the gen-matched id, mother id, and grandmother id
180 >  for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
181 >
182 >    string currentObject = objectsToPlot.at(currentObjectIndex);
183 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "secondary photons"&& currentObject != "superclusters") continue;
184 >
185 >    histogram tempIdHisto;
186 >    histogram tempMomIdHisto;
187 >    histogram tempGmaIdHisto;
188 >    histogram tempIdVsMomIdHisto;
189 >    histogram tempIdVsGmaIdHisto;
190 >
191 >    tempIdHisto.inputCollection = currentObject;
192 >    tempMomIdHisto.inputCollection = currentObject;
193 >    tempGmaIdHisto.inputCollection = currentObject;
194 >    tempIdVsMomIdHisto.inputCollection = currentObject;
195 >    tempIdVsGmaIdHisto.inputCollection = currentObject;
196 >
197 >    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
198 >    if(currentObject == "secondary photons") currentObject = "secondaryPhotons";
199 >    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
200 >
201 >    currentObject = currentObject.substr(0, currentObject.size()-1);
202 >    tempIdHisto.name = currentObject+"GenMatchId";
203 >    tempMomIdHisto.name = currentObject+"GenMatchMotherId";
204 >    tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
205 >    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
206 >    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
207 >
208 >    currentObject.at(0) = toupper(currentObject.at(0));
209 >    tempIdHisto.title = currentObject+" Gen-matched Particle";
210 >    tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
211 >    tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
212 >    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
213 >    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
214 >
215 >
216 >    int maxNum = 25;
217 >    vector<double> binVector;
218 >    binVector.push_back(maxNum);
219 >    binVector.push_back(0);
220 >    binVector.push_back(maxNum);
221 >
222 >    tempIdHisto.bins = binVector;
223 >    tempIdHisto.inputVariables.push_back("genMatchedId");
224 >    tempMomIdHisto.bins = binVector;
225 >    tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
226 >    tempGmaIdHisto.bins = binVector;
227 >    tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
228 >    binVector.push_back(maxNum);
229 >    binVector.push_back(0);
230 >    binVector.push_back(maxNum);
231 >    tempIdVsMomIdHisto.bins = binVector;
232 >    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
233 >    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
234 >    tempIdVsGmaIdHisto.bins = binVector;
235 >    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
236 >    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
237 >
238 >    histograms.push_back(tempIdHisto);
239 >    histograms.push_back(tempMomIdHisto);
240 >    histograms.push_back(tempGmaIdHisto);
241 >    histograms.push_back(tempIdVsMomIdHisto);
242 >    histograms.push_back(tempIdVsGmaIdHisto);
243 >  }
244  
245  
246    channel tempChannel;
# Line 41 | Line 255 | OSUAnalysis::OSUAnalysis (const edm::Par
255      //set triggers for this channel
256      vector<string> triggerNames;
257      triggerNames.clear();
258 +    vector<string> triggerToVetoNames;
259 +    triggerToVetoNames.clear();
260 +
261      tempChannel.triggers.clear();
262 +    tempChannel.triggersToVeto.clear();
263      if(channels_.at(currentChannel).exists("triggers")){
264        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
265        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
266          tempChannel.triggers.push_back(triggerNames.at(trigger));
267 <      allNecessaryObjects.push_back("triggers");
267 >      objectsToGet.push_back("triggers");
268      }
269 +    if(channels_.at(currentChannel).exists("triggersToVeto")){
270 +      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
271 +      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
272 +        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
273 +      objectsToGet.push_back("triggers");
274 +    }
275 +
276  
277  
278      //create cutFlow for this channel
279      cutFlows_.push_back (new CutFlow (fs_, channelName));
280 <
281 <    //book a directory in the output file with the name of the channel
282 <    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 <
280 >    vector<TFileDirectory> directories; //vector of directories in the output file.
281 >    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
282 >    vector<string> subSubDirNames;//subdirectories in each channel.
283      //get list of cuts for this channel
284      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
285  
105    vector<string> tempInputCollections;
106
286  
287      //loop over and parse all cuts
288      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
110
289        cut tempCut;
290 <     //store input collection for cut
291 <      string inputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
292 <      tempCut.inputCollection = inputCollection;
290 >      //store input collection for cut
291 >      string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
292 >      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
293 >      if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
294 >      if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
295 >      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
296 >      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
297 >      if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
298 >      if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
299 >      if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
300 >      if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
301 >      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
302 >      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
303 >      if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
304 >      if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
305 >      if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
306 >      if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
307 >      if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
308 >      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
309 >      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
310 >      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
311 >      tempCut.inputCollection = tempInputCollection;
312 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
313 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
314 >          int spaceIndex = tempInputCollection.find(" ");
315 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
316 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
317 >        }
318 >        else{
319 >          objectsToGet.push_back(tempInputCollection);
320 >        }
321 >        objectsToCut.push_back(tempInputCollection);
322 >        objectsToFlag.push_back(tempInputCollection);
323 >      }
324 >      else{//pair of objects, need to add them both to objectsToGet
325 >        string obj1;
326 >        string obj2;
327 >        getTwoObjs(tempInputCollection, obj1, obj2);
328 >        string obj2ToGet = getObjToGet(obj2);
329 >        objectsToCut.push_back(tempInputCollection);
330 >        objectsToCut.push_back(obj1);
331 >        objectsToCut.push_back(obj2);
332 >        objectsToFlag.push_back(tempInputCollection);
333 >        objectsToFlag.push_back(obj1);
334 >        objectsToFlag.push_back(obj2);
335 >        objectsToGet.push_back(tempInputCollection);
336 >        objectsToGet.push_back(obj1);
337 >        objectsToGet.push_back(obj2ToGet);
338 >
339 >      }
340 >
341  
116      tempInputCollections.push_back(inputCollection);
117      allNecessaryObjects.push_back(inputCollection);
342  
343        //split cut string into parts and store them
344        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
345 <      std::vector<string> cutStringVector = splitString(cutString);
346 <      tempCut.variable = cutStringVector.at(0);// variable to cut on
347 <      tempCut.comparativeOperator = cutStringVector.at(1);// comparison to make
348 <      tempCut.cutValue = atof(cutStringVector.at(2).c_str());// threshold value to pass cut
345 >      vector<string> cutStringVector = splitString(cutString);
346 >      if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
347 >        clog << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
348 >        exit(0);
349 >      }
350 >      tempCut.numSubcuts = (cutStringVector.size()+1)/4;
351 >      for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
352 >        int indexOffset = 4 * subcutIndex;
353 >        string currentVariableString = cutStringVector.at(indexOffset);
354 >        if(currentVariableString.find("(")==string::npos){
355 >          tempCut.functions.push_back("");//no function was specified
356 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
357 >        }
358 >        else{
359 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
360 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
361 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
362 >        }
363 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
364 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
365 >        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
366 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
367 >      }
368  
369        //get number of objects required to pass cut for event to pass
370        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
371 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
371 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
372 >      if(numberRequiredVector.size()!=2){
373 >        clog << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
374 >        exit(0);
375 >      }
376  
130      // determine number required if comparison contains "="
377        int numberRequiredInt = atoi(numberRequiredVector.at(1).c_str());
132      if(numberRequiredVector.at(0) == ">") numberRequiredInt++;
133      else if(numberRequiredVector.at(0) == "<") numberRequiredInt--;
134
378        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
379        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
380  
381 <      if(cuts_.at(currentCut).exists("function")){
382 <        tempCut.function = cuts_.at(currentCut).getParameter<string> ("function");
140 <      }
141 <      else tempCut.function = "";
381 >      //Set up vectors to store the directories and subDirectories for each channel.
382 >      string subSubDirName;
383        string tempCutName;
384        if(cuts_.at(currentCut).exists("alias")){
385          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
386 +        subSubDirName = "After " + tempCutName + " Cut Applied";
387        }
388        else{
389          //construct string for cutflow table
390          bool plural = numberRequiredInt != 1;
391 <        string collectionString = plural ? inputCollection : inputCollection.substr(0, inputCollection.size()-1);
391 >        string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
392          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
393          tempCutName = cutName;
394 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
395        }
153      tempCut.name = tempCutName;
396  
397 +      tempCut.isVeto = false;
398 +      if(cuts_.at(currentCut).exists("isVeto")){
399 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
400 +        if (isVeto == true) tempCut.isVeto = true;
401 +      }
402 +      subSubDirNames.push_back(subSubDirName);
403 +      tempCut.name = tempCutName;
404  
405        tempChannel.cuts.push_back(tempCut);
406  
407  
408      }//end loop over cuts
409  
410 <    //make unique vector of all objects that this channel cuts on (so we know to set flags for those)
411 <    sort( tempInputCollections.begin(), tempInputCollections.end() );
412 <    tempInputCollections.erase( unique( tempInputCollections.begin(), tempInputCollections.end() ), tempInputCollections.end() );
413 <    tempChannel.inputCollections = tempInputCollections;
410 >    vector<map<string, TH1D*>> oneDHistsTmp;
411 >    vector<map<string, TH2D*>> twoDHistsTmp;
412 >    //book a directory in the output file with the name of the channel
413 >    TFileDirectory subDir = fs_->mkdir( channelName );
414 >    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
415 >    if(GetPlotsAfterEachCut_){
416 >      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
417 >        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
418 >        directories.push_back(subSubDir);
419 >        map<string, TH1D*> oneDhistoMap;
420 >        oneDHistsTmp.push_back(oneDhistoMap);
421 >        map<string, TH2D*> twoDhistoMap;
422 >        twoDHistsTmp.push_back(twoDhistoMap);
423 >      }
424 >      treeDirectories.push_back(subDir);
425 >      oneDHists_.push_back(oneDHistsTmp);
426 >      twoDHists_.push_back(twoDHistsTmp);
427 >    }
428 >    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
429 >    else{
430 >      map<string, TH1D*> oneDhistoMap;
431 >      oneDHistsTmp.push_back(oneDhistoMap);
432 >      map<string, TH2D*> twoDhistoMap;
433 >      twoDHistsTmp.push_back(twoDhistoMap);
434 >      oneDHists_.push_back(oneDHistsTmp);
435 >      twoDHists_.push_back(twoDHistsTmp);
436 >      directories.push_back(subDir);
437 >      treeDirectories.push_back(subDir);
438 >
439 >    }
440 >
441 >    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
442 >      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
443 >      BNTrees_.push_back(newTree);
444 >      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
445 >        BranchSpecs currentVar = treeBranches_.at(iBranch);
446 >        vector<float> newVec;
447 >        BNTreeBranchVals_[currentVar.name] = newVec;
448 >        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
449 >      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
450 >    }
451 >
452 >    //book all histograms included in the configuration
453 >    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
454 >
455 >      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
456 >
457 >        histogram currentHistogram = histograms.at(currentHistogramIndex);
458 >        int numBinsElements = currentHistogram.bins.size();
459 >        int numInputVariables = currentHistogram.inputVariables.size();
460 >        int numBinEdgesX = currentHistogram.variableBinsX.size();
461 >        int numBinEdgesY = currentHistogram.variableBinsY.size();
462 >
463 >        if(numBinsElements == 1){
464 >          if(numBinEdgesX > 1){
465 >            if(numBinEdgesY > 1)
466 >              numBinsElements = 6;
467 >            else
468 >              numBinsElements = 3;
469 >          }
470 >        }
471 >        if(numBinsElements != 3 && numBinsElements !=6){
472 >          clog << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
473 >          exit(0);
474 >        }
475 >        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
476 >          clog << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
477 >          exit(0);
478 >        }
479 >        else if(numBinsElements == 3){
480 >          if (currentHistogram.bins.size () == 3)
481 >            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));
482 >          else
483 >            {
484 >              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
485 >            }
486 >        }
487 >        else if(numBinsElements == 6){
488 >          if (currentHistogram.bins.size () == 6)
489 >            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));
490 >          else
491 >            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 ());
492 >        }
493 >
494 >
495 >        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
496 >
497 >        // bin      particle type
498 >        // ---      -------------
499 >        //  0        unmatched
500 >        //  1        u
501 >        //  2        d
502 >        //  3        s
503 >        //  4        c
504 >        //  5        b
505 >        //  6        t
506 >        //  7        e
507 >        //  8        mu
508 >        //  9        tau
509 >        // 10        nu
510 >        // 11        g
511 >        // 12        gamma
512 >        // 13        Z
513 >        // 14        W
514 >        // 15        light meson
515 >        // 16        K meson
516 >        // 17        D meson
517 >        // 18        B meson
518 >        // 19        light baryon
519 >        // 20        strange baryon
520 >        // 21        charm baryon
521 >        // 22        bottom baryon
522 >        // 23        QCD string
523 >        // 24        other
524 >
525 >        vector<TString> labelArray;
526 >        labelArray.push_back("unmatched");
527 >        labelArray.push_back("u");
528 >        labelArray.push_back("d");
529 >        labelArray.push_back("s");
530 >        labelArray.push_back("c");
531 >        labelArray.push_back("b");
532 >        labelArray.push_back("t");
533 >        labelArray.push_back("e");
534 >        labelArray.push_back("#mu");
535 >        labelArray.push_back("#tau");
536 >        labelArray.push_back("#nu");
537 >        labelArray.push_back("g");
538 >        labelArray.push_back("#gamma");
539 >        labelArray.push_back("Z");
540 >        labelArray.push_back("W");
541 >        labelArray.push_back("light meson");
542 >        labelArray.push_back("K meson");
543 >        labelArray.push_back("D meson");
544 >        labelArray.push_back("B meson");
545 >        labelArray.push_back("light baryon");
546 >        labelArray.push_back("strange baryon");
547 >        labelArray.push_back("charm baryon");
548 >        labelArray.push_back("bottom baryon");
549 >        labelArray.push_back("QCD string");
550 >        labelArray.push_back("other");
551 >
552 >        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
553 >          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
554 >            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
555 >          }
556 >          else {
557 >            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
558 >            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
559 >          }
560 >        }
561 >        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
562 >          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
563 >          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
564 >        }
565 >
566 >      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
567 >
568  
569 +      // Book a histogram for the number of each object type to be plotted.
570 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
571 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
572 +        string currentObject = objectsToPlot.at(currentObjectIndex);
573 +        int maxNum = 10;
574 +        if(currentObject == "mcparticles") maxNum = 50;
575 +        else if(currentObject == "primaryvertexs") maxNum = 50;
576 +
577 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
578 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
579 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
580 +        else if(currentObject == "electron-photon pairs")     currentObject = "electronPhotonPairs";
581 +        else if(currentObject == "muon-photon pairs")         currentObject = "muonPhotonPairs";
582 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
583 +        else if(currentObject == "secondary photons")            currentObject = "secondaryPhotons";
584 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
585 +        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
586 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
587 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
588 +        else if(currentObject == "muon-event pairs")            currentObject = "muonEventPairs";
589 +        else if(currentObject == "photon-jet pairs")            currentObject = "photonJetPairs";
590 +        else if(currentObject == "met-jet pairs")             currentObject = "metJetPairs";
591 +        else if(currentObject == "track-jet pairs")           currentObject = "trackJetPairs";
592 +        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
593 +        else if(currentObject == "muon-secondary photon pairs")  currentObject = "muonSecondaryPhotonPairs";
594 +        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
595 +        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
596 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
597 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
598 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
599 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
600 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
601 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
602 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
603 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
604 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
605 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
606 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
607 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
608 +
609 +        currentObject.at(0) = toupper(currentObject.at(0));
610 +        string histoName = "num" + currentObject;
611 +
612 +        if(histoName == "numPrimaryvertexs"){
613 +          string newHistoName = histoName + "BeforePileupCorrection";
614 +          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);
615 +          newHistoName = histoName + "AfterPileupCorrection";
616 +          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);
617 +        }
618 +        else
619 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
620 +      }
621 +    }//end of loop over directories
622      channels.push_back(tempChannel);
623      tempChannel.cuts.clear();
168
624    }//end loop over channels
625  
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() );
626  
627 +  //make unique vector of objects we need to get from the event
628 +  sort( objectsToGet.begin(), objectsToGet.end() );
629 +  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
630 +  //make unique vector of objects we need to cut on
631 +  sort( objectsToCut.begin(), objectsToCut.end() );
632 +  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
633 +  //make unique vector of objects we need to set flags for
634 +  sort( objectsToFlag.begin(), objectsToFlag.end() );
635 +  objectsToFlag.erase( unique( objectsToFlag.begin(), objectsToFlag.end() ), objectsToFlag.end() );
636 +
637 +  produces<map<string, bool> > ("channelDecisions");
638 +
639 + } // end constructor OSUAnalysis::OSUAnalysis()
640  
176 }
641  
642   OSUAnalysis::~OSUAnalysis ()
643   {
644 +
645    // Destroying the CutFlow objects causes the cut flow numbers and time
646    // information to be printed to standard output.
647    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
648      delete cutFlows_.at(currentChannel);
649    }
650 +
651 +  clog << "=============================================" << endl;  
652 +  clog << "Successfully completed OSUAnalysis." << endl;  
653 +  clog << "=============================================" << endl;  
654 +
655   }
656  
657   void
658 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
658 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
659   {
190
191
660    // Retrieve necessary collections from the event.
661 <  edm::Handle<BNtriggerCollection> triggers;
662 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
661 >
662 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
663      event.getByLabel (triggers_, triggers);
664  
665 <  edm::Handle<BNjetCollection> jets;
666 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())
665 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
666 >    event.getByLabel (trigobjs_, trigobjs);
667 >
668 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
669      event.getByLabel (jets_, jets);
670  
671 <  edm::Handle<BNmuonCollection> muons;
202 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())
671 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
672      event.getByLabel (muons_, muons);
673  
674 <  edm::Handle<BNelectronCollection> electrons;
206 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())
674 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
675      event.getByLabel (electrons_, electrons);
676  
677 <  edm::Handle<BNeventCollection> events;
210 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())
677 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
678      event.getByLabel (events_, events);
679  
680 <  edm::Handle<BNtauCollection> taus;
214 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())
680 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
681      event.getByLabel (taus_, taus);
682  
683 <  edm::Handle<BNmetCollection> mets;
218 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())
683 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
684      event.getByLabel (mets_, mets);
685  
686 <  edm::Handle<BNtrackCollection> tracks;
222 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())
686 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
687      event.getByLabel (tracks_, tracks);
688  
689 <  edm::Handle<BNgenjetCollection> genjets;
226 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())
689 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
690      event.getByLabel (genjets_, genjets);
691  
692 <  edm::Handle<BNmcparticleCollection> mcparticles;
230 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())
692 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
693      event.getByLabel (mcparticles_, mcparticles);
694  
695 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
234 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())
695 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
696      event.getByLabel (primaryvertexs_, primaryvertexs);
697  
698 <  edm::Handle<BNbxlumiCollection> bxlumis;
238 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())
698 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
699      event.getByLabel (bxlumis_, bxlumis);
700  
701 <  edm::Handle<BNphotonCollection> photons;
242 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())
701 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
702      event.getByLabel (photons_, photons);
703  
704 <  edm::Handle<BNsuperclusterCollection> superclusters;
246 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())
704 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
705      event.getByLabel (superclusters_, superclusters);
706  
707 +  if (datasetType_ == "signalMC"){
708 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
709 +      event.getByLabel (stops_, stops);
710 +  }
711 +
712 +  if (useTrackCaloRhoCorr_) {
713 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
714 +    // This rho collection is not available in all BEANs.
715 +    // For description of rho values for different jet reconstruction algorithms, see
716 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
717 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
718 +  }
719 +
720 +  double masterScaleFactor = 1.0;
721 +
722 +  //get pile-up event weight
723 +  if (doPileupReweighting_ && datasetType_ != "data") {
724 +    //for "data" datasets, the numTruePV is always set to -1
725 +    if (events->at(0).numTruePV < 0) clog << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
726 +    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
727 +  }
728 +
729 +  stopCTauScaleFactor_ = 1.0;
730 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
731 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
732 +  masterScaleFactor *= stopCTauScaleFactor_;
733  
734    //loop over all channels
735  
736 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
737    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
738      channel currentChannel = channels.at(currentChannelIndex);
739  
740      flagMap individualFlags;
256    flagMap cumulativeFlags;
741      counterMap passingCounter;
742 +    cumulativeFlags.clear ();
743 +
744 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
745 +         iter != BNTreeBranchVals_.end(); iter++) {
746 +      iter->second.clear();  // clear array
747 +    }
748  
749      bool triggerDecision = true;
750 <    if(currentChannel.triggers.size() != 0){  //triggers specified
751 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
750 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
751 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
752        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
753      }
754  
# Line 266 | Line 756 | OSUAnalysis::analyze (const edm::Event &
756      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
757        cut currentCut = currentChannel.cuts.at(currentCutIndex);
758  
759 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
759 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
760 >        string currentObject = objectsToFlag.at(currentObjectIndex);
761 >
762 >        //initialize maps to get ready to set cuts
763 >        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
764 >        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
765  
766 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
767 <        individualFlags[currentObject].push_back (vector<bool> ());
768 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
766 >      }
767 >
768 >      //set flags for all relevant objects
769 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
770 >        string currentObject = objectsToFlag.at(currentObjectIndex);
771 >
772 >        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
773  
774 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
775 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
774 >
775 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
776 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
777 >        else if(currentObject == "secondary photons")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"secondary photons");
778 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
779 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
780 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
781          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
782          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
783          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 285 | Line 789 | OSUAnalysis::analyze (const edm::Event &
789          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
790          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
791          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
792 <
289 <
290 <      }
792 >        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
793  
794  
795  
796 <    }//end loop over all cuts
796 >        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
797 >                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
798 >                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
799 >                                                                   "muon-muon pairs");
800 >
801 >        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
802 >                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
803 >                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
804 >                                                                             "muon-secondary muon pairs");
805 >
806 >        else if(currentObject == "muon-secondary photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
807 >                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
808 >                                                                             cumulativeFlags.at("secondary photons").at(flagsForPairCutsIndex), \
809 >                                                                             "muon-secondary photon pairs");
810 >        else if(currentObject == "muon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
811 >                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
812 >                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
813 >                                                                             "muon-secondary jet pairs");
814 >        else if(currentObject == "photon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
815 >                                                                             cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
816 >                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
817 >                                                                             "photon-secondary jet pairs");
818 >
819 >        else if(currentObject == "electron-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
820 >                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
821 >                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
822 >                                                                             "electron-secondary jet pairs");
823 >
824 >        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
825 >                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
826 >                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
827 >                                                                                     "electron-secondary electron pairs");
828 >
829 >        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
830 >                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
831 >                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
832 >                                                                           "electron-electron pairs");
833 >        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
834 >                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
835 >                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
836 >                                                                       "electron-muon pairs");
837 >        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
838 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
839 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
840 >                                                                 "jet-jet pairs");
841 >        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
842 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
843 >                                                                 cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex),\
844 >                                                                 "jet-secondary jet pairs");
845 >        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
846 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
847 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
848 >                                                                      "electron-jet pairs");
849 >        else if(currentObject == "electron-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), \
850 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
851 >                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
852 >                                                                      "electron-photon pairs");
853 >        else if(currentObject == "photon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
854 >                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
855 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
856 >                                                                      "photon-jet pairs");
857 >        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
858 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
859 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
860 >                                                                  "muon-jet pairs");
861 >        else if(currentObject == "muon-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),events.product(), \
862 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
863 >                                                                  cumulativeFlags.at("events").at(flagsForPairCutsIndex), \
864 >                                                                  "muon-event pairs");
865 >        else if(currentObject == "met-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),jets.product(), \
866 >                                                                  cumulativeFlags.at("mets").at(flagsForPairCutsIndex), \
867 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
868 >                                                                  "met-jet pairs");
869 >        else if(currentObject == "track-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),jets.product(), \
870 >                                                                 cumulativeFlags.at("tracks").at(flagsForPairCutsIndex), \
871 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
872 >                                                                 "track-jet pairs");
873 >        else if(currentObject == "muon-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
874 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
875 >                                                                  cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
876 >                                                                  "muon-photon pairs");
877 >        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
878 >                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
879 >                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
880 >                                                                     "track-event pairs");
881 >        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
882 >                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
883 >                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
884 >                                                                        "electron-track pairs");
885 >        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
886 >                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
887 >                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
888 >                                                                    "muon-track pairs");
889 >        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
890 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
891 >                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
892 >                                                                  "muon-tau pairs");
893 >        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
894 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
895 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
896 >                                                                 "tau-tau pairs");
897 >        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
898 >                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
899 >                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
900 >                                                                   "tau-track pairs");
901 >        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
902 >                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
903 >                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
904 >                                                                          "electron-trigobj pairs");
905 >        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
906 >                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
907 >                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
908 >                                                                      "muon-trigobj pairs");
909  
910 +        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
911 +      }
912  
913  
914  
915 +    }//end loop over all cuts
916      //use cumulative flags to apply cuts at event level
917  
918 +    //a vector to store cumulative cut descisions after each cut.
919 +    vector<bool> eventPassedPreviousCuts;
920      bool eventPassedAllCuts = true;
302
921      //apply trigger (true if none were specified)
922      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
923  
306
924      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
925  
926        //loop over all objects and count how many passed the cumulative selection up to this point
927        cut currentCut = currentChannel.cuts.at(currentCutIndex);
928        int numberPassing = 0;
929  
930 <      for (uint object = 0; object != cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).size() ; object++)
931 <          if(cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).at(object)) numberPassing++;
932 <
316 <
930 >      for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
931 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
932 >      }
933        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
934        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
319
935        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
936 <
936 >      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
937 >    }
938 >    //applying all appropriate scale factors
939 >    double scaleFactor = masterScaleFactor;
940 >    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
941 >
942 >    if(applyLeptonSF_ && datasetType_ != "data"){
943 >      //only apply SFs if we've cut on this object
944 >      if(find(objectsToCut.begin(),objectsToCut.end(),"muons") != objectsToCut.end ()){
945 >        flagPair muonFlags;
946 >        //get the last valid flags in the flag map
947 >        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
948 >          if (cumulativeFlags.at("muons").at(i).size()){
949 >            muonFlags = cumulativeFlags.at("muons").at(i);
950 >            break;
951 >          }
952 >        }
953 >        //apply the weight for each of those objects
954 >        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
955 >          if(!muonFlags.at(muonIndex).second) continue;
956 >          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
957 >        }
958 >      }
959 >      //only apply SFs if we've cut on this object
960 >      if(find(objectsToCut.begin(),objectsToCut.end(),"electrons") != objectsToCut.end ()){
961 >        flagPair electronFlags;
962 >        //get the last valid flags in the flag map
963 >        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
964 >          if (cumulativeFlags.at("electrons").at(i).size()){
965 >            electronFlags = cumulativeFlags.at("electrons").at(i);
966 >            break;
967 >          }
968 >        }
969 >        //apply the weight for each of those objects
970 >        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
971 >          if(!electronFlags.at(electronIndex).second) continue;
972 >          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
973 >        }
974 >      }
975 >    }
976 >    if(applyBtagSF_ && datasetType_ != "data"){
977 >      //only apply SFs if we've cut on this object
978 >      if(find(objectsToCut.begin(),objectsToCut.end(),"jets") != objectsToCut.end ()){
979 >        flagPair jetFlags;
980 >        vector<double> jetSFs;
981 >        //get the last valid flags in the flag map
982 >        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
983 >          if (cumulativeFlags.at("jets").at(i).size()){
984 >            jetFlags = cumulativeFlags.at("jets").at(i);
985 >            break;
986 >          }
987 >        }
988 >        //apply the weight for each of those objects
989 >        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
990 >          if(!jetFlags.at(jetIndex).second) continue;
991 >          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour, jets->at(jetIndex).eta);
992 >          jetSFs.push_back(jetSFTmp);
993 >        }
994 >        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_);
995 >      }
996 >    }
997 >    scaleFactor *= muonScaleFactor_;
998 >    scaleFactor *= electronScaleFactor_;
999 >    scaleFactor *= bTagScaleFactor_;
1000 >    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
1001 >
1002 >    if (printEventInfo_) {
1003 >      // Write information about event to screen, for testing purposes.
1004 >      clog << "Event passed all cuts in channel " <<  currentChannel.name
1005 >           << ": run="  << events->at(0).run
1006 >           << "  lumi=" << events->at(0).lumi
1007 >           << "  event=" << events->at(0).evt
1008 >           << endl;
1009      }
1010  
324    cutFlows_.at(currentChannelIndex)->fillCutFlow();
1011  
1012 +    //filling histograms
1013 +    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
1014 +      uint currentDir;
1015 +      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
1016 +      else{
1017 +        currentDir = currentCut;
1018 +      }
1019  
1020  
1021 <    if(!eventPassedAllCuts)continue;
1021 >      if(eventPassedPreviousCuts.at(currentDir)){
1022  
1023 +        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1024 +          histogram currentHistogram = histograms.at(histogramIndex);
1025  
1026 <    TVector3 vertexPosition;
332 <    vector<bool> vertexFlags = cumulativeFlags["primaryvertexs"].back();
1026 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) clog << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
1027  
1028 <    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
1029 <      if(!vertexFlags.at(vertexIndex)) continue;
1028 >          if(currentHistogram.inputVariables.size() == 1){
1029 >            TH1D* histo;
1030 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1031 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1032 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1033 >            else if(currentHistogram.inputCollection == "secondary photons")  fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1034 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1035 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1036 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1037 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1038 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1039 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1040 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1041 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1042 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1043 >             else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1044 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary photons").at(currentDir), \
1045 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1046 >             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1047 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1048 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1049 >             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1050 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1051 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1052 >             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1053 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1054 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1055 >
1056 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1057 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
1058 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
1059 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1060 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
1061 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
1062 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1063 >             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1064 >                                                                                                     cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1065 >                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1066 >
1067 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1068 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1069 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1070 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
1071 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
1072 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1073 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
1074 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1075 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1076 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(), \
1077 >                                                                                              cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1078 >                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1079 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
1080 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1081 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1082 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill1DHistogram(histo,currentHistogram, muons.product(),events.product(), \
1083 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1084 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1085 >            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, mets.product(),jets.product(), \
1086 >                                                                                          cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1087 >                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1088 >            else if(currentHistogram.inputCollection == "track-jet pairs")  fill1DHistogram(histo,currentHistogram,tracks.product(),jets.product(), \
1089 >                                                                                          cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1090 >                                                                                          cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1091 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(), \
1092 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1093 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1094 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(), \
1095 >                                                                                          cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1096 >                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1097 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1098 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1099 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1100 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1101 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1102 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1103 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1104 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1105 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1106 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1107 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1108 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1109 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1110 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1111 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1112 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1113 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1114 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1115 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1116 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1117 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1118 >
1119 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1120 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1121 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1122 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1123 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1124 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1125 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1126 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1127 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1128 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1129 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1130 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1131 >          }
1132 >          else if(currentHistogram.inputVariables.size() == 2){
1133 >            TH2D* histo;
1134 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1135 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1136 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1137 >            else if(currentHistogram.inputCollection == "secondary photons")  fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1138 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1139 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1140 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1141 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1142 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1143 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1144 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1145 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1146 >            else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1147 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary photons").at(currentDir), \
1148 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1149 >            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1150 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1151 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1152 >            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1153 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1154 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1155 >            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1156 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1157 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1158 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1159 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1160 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1161 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1162 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1163 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1164 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1165 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1166 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1167 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1168 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1169 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1170 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1171 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1172 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1173 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1174 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1175 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(), \
1176 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1177 >                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1178 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1179 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1180 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1181 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill2DHistogram(histo,currentHistogram,muons.product(),events.product(), \
1182 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("events").at(currentDir), \
1183 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1184 >            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,mets.product(),jets.product(), \
1185 >                                                                                         cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1186 >                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1187 >            else if(currentHistogram.inputCollection == "track-jet pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1188 >                                                                                         cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1189 >                                                                                         cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1190 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1191 >                                                                                          cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1192 >                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1193 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1194 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1195 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1196 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1197 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1198 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1199 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1200 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1201 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1202 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1203 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1204 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1205 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1206 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1207 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1208 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1209 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1210 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1211 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1212 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1213 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1214 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1215 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1216 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1217 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1218 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1219 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1220 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1221 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1222 >                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1223 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1224 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1225 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1226 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1227 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1228 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1229 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1230 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1231 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1232 >          }
1233  
1234 <      vertexPosition.SetXYZ (primaryvertexs->at(vertexIndex).x,primaryvertexs->at(vertexIndex).y,primaryvertexs->at(vertexIndex).z);
338 <      break;
339 <    }
1234 >        }
1235  
341    vector<bool> mcparticleFlags = cumulativeFlags["mcparticles"].back();
1236  
1237 <    for (uint mcparticleIndex = 0; mcparticleIndex != mcparticleFlags.size(); mcparticleIndex++){
1238 <      if(!mcparticleFlags.at(mcparticleIndex)) continue;
1237 >        //fills histograms with the sizes of collections
1238 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1239  
1240 <      double vx = mcparticles->at(mcparticleIndex).vx - vertexPosition.X (),
1241 <             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 <    }
1240 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1241 >          string objectToPlot = "";
1242  
1243 <    vector<bool> electronFlags = cumulativeFlags["electrons"].back();
1244 <    int electronCounter = 0;
1243 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1244 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1245 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1246 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1247 >          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1248 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1249 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1250 >          else if(currentObject == "muon-event pairs")                     objectToPlot = "muonEventPairs";
1251 >          else if(currentObject == "muon-photon pairs")                     objectToPlot = "muonPhotonPairs";
1252 >          else if(currentObject == "photon-jet pairs")                     objectToPlot = "photonJetPairs";
1253 >          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1254 >          else if(currentObject == "track-jet pairs")                    objectToPlot = "trackJetPairs";
1255 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1256 >          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1257 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1258 >          else if(currentObject == "secondary photons")                     objectToPlot = "secondaryPhotons";
1259 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1260 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1261 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1262 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1263 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1264 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1265 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1266 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1267 >          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1268 >          else if(currentObject == "muon-secondary photon pairs")           objectToPlot = "muonSecondaryJetPairs";
1269 >          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1270 >          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1271 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1272 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1273 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1274 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1275 >          else objectToPlot = currentObject;
1276 >
1277 >          string tempCurrentObject = objectToPlot;
1278 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1279 >          string histoName = "num" + tempCurrentObject;
1280 >
1281 >
1282 >          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1283 >            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1284 >            int numToPlot = 0;
1285 >            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1286 >              if(lastCutFlags.at(currentFlag).second) numToPlot++;
1287 >            }
1288 >
1289 >            if(objectToPlot == "primaryvertexs"){
1290 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1291 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1292 >            }
1293 >            else {
1294 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1295 >            }
1296 >          }
1297 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1298  
364    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
365      if(!electronFlags.at(electronIndex)) continue;
1299  
1300 +      } // end if(eventPassedPreviousCuts.at(currentDir))
1301 +    } // end loop over cuts
1302  
1303 <      electronCounter++;
1304 <      oneDHists_.at(currentChannelIndex)["electronPt"]->Fill (electrons->at(electronIndex).pt);
1305 <      oneDHists_.at(currentChannelIndex)["electronEta"]->Fill (electrons->at(electronIndex).eta);
1306 <      oneDHists_.at(currentChannelIndex)["electronD0"]->Fill (electrons->at(electronIndex).correctedD0Vertex);
1307 <      oneDHists_.at(currentChannelIndex)["electronDz"]->Fill (electrons->at(electronIndex).correctedDZ);
1308 <      oneDHists_.at(currentChannelIndex)["electronAbsD0"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex));
1309 <      oneDHists_.at(currentChannelIndex)["electronDZ"]->Fill (electrons->at(electronIndex).correctedDZ);
1310 <      oneDHists_.at(currentChannelIndex)["electronAbsDZ"]->Fill (fabs(electrons->at(electronIndex).correctedDZ));
1311 <      oneDHists_.at(currentChannelIndex)["electronD0Sig"]->Fill (electrons->at(electronIndex).correctedD0Vertex / electrons->at(electronIndex).tkD0err);
1312 <      oneDHists_.at(currentChannelIndex)["electronAbsD0Sig"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex) / electrons->at(electronIndex).tkD0err);
1313 <      oneDHists_.at(currentChannelIndex)["electronIso"]->Fill (electrons->at(electronIndex).puChargedHadronIso / electrons->at(electronIndex).pt);
1314 <      oneDHists_.at(currentChannelIndex)["electronFbrem"]->Fill (electrons->at(electronIndex).fbrem);
1315 <      oneDHists_.at(currentChannelIndex)["electronMVATrig"]->Fill (electrons->at(electronIndex).mvaTrigV0);
1316 <      oneDHists_.at(currentChannelIndex)["electronMVANonTrig"]->Fill (electrons->at(electronIndex).mvaNonTrigV0);
1303 >    if (!useEDMFormat_ && eventPassedAllCuts){
1304 >      // Assign BNTree variables
1305 >      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1306 >        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1307 >        string coll = brSpecs.inputCollection;
1308 >        if (cumulativeFlags.count(coll) == 0) clog << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1309 >
1310 >        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1311 >        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1312 >        else if(coll == "secondary photons")      assignTreeBranch(brSpecs,photons.product(),          cumulativeFlags.at(coll).back());
1313 >        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1314 >        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1315 >        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1316 >        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1317 >        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1318 >        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1319 >        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1320 >        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1321 >        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1322 >        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1323 >        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1324 >        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1325 >        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1326 >        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1327 >        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1328 >        else if(coll == "stops"
1329 >                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1330 >      } // end loop over branches
1331  
1332 +      if (!BNTrees_.at(currentChannelIndex)) { clog << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1333 +      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1334      }
384    oneDHists_.at(currentChannelIndex)["numElectrons"]->Fill (electronCounter);
1335  
1336 +    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1337  
1338 <    vector<bool> muonFlags = cumulativeFlags["muons"].back();
388 <    int muonCounter = 0;
1338 >  } // end loop over channel
1339  
1340 +  masterCutFlow_->fillCutFlow(masterScaleFactor);
1341  
1342 <    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);
1342 >  event.put (channelDecisions, "channelDecisions");
1343  
1344 + } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1345  
1346  
1347  
1348 + bool
1349 + OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
1350  
412  } //end loop over channel
413
414  masterCutFlow_->fillCutFlow();
1351  
1352 +  if(comparison == ">")       return testValue >  cutValue;
1353 +  else if(comparison == ">=") return testValue >= cutValue;
1354 +  else if(comparison == "<")  return testValue <  cutValue;
1355 +  else if(comparison == "<=") return testValue <= cutValue;
1356 +  else if(comparison == "==") return testValue == cutValue;
1357 +  else if(comparison == "=") return testValue == cutValue;
1358 +  else if(comparison == "!=") return testValue != cutValue;
1359 +  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1360  
1361   }
1362  
419
1363   bool
1364 < OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
1364 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1365  
1366  
1367    if(comparison == ">")       return testValue >  cutValue;
# Line 426 | Line 1369 | OSUAnalysis::evaluateComparison (double
1369    else if(comparison == "<")  return testValue <  cutValue;
1370    else if(comparison == "<=") return testValue <= cutValue;
1371    else if(comparison == "==") return testValue == cutValue;
1372 +  else if(comparison == "=") return testValue == cutValue;
1373    else if(comparison == "!=") return testValue != cutValue;
1374 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1374 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1375  
1376   }
1377  
1378   bool
1379 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1379 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1380  
1381 +  //initialize to false until a chosen trigger is passed
1382    bool triggerDecision = false;
1383  
1384 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1385 <    {
1386 <      if(trigger->pass != 1) continue;
1387 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1388 <        {
1389 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1390 <            triggerDecision = true;
1391 <          }
1392 <        }
1384 >  if (printAllTriggers_) clog << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1385 >  //loop over all triggers defined in the event
1386 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1387 >
1388 >    if (printAllTriggers_) clog << "   " << trigger->name << endl;
1389 >
1390 >    //we're only interested in triggers that actually passed
1391 >    if(trigger->pass != 1) continue;
1392 >
1393 >    //if the event passes one of the veto triggers, exit and return false
1394 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1395 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1396 >    }
1397 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1398 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1399 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1400      }
1401 <  return triggerDecision;
1401 >  }
1402 >
1403 >  printAllTriggers_ = false;  // only print triggers once, not every event
1404  
1405 +  //if none of the veto triggers fired:
1406 +  //return the OR of all the chosen triggers
1407 +  if (triggersToTest.size() != 0) return triggerDecision;
1408 +  //or if no triggers were defined return true
1409 +  else return true;
1410   }
1411  
1412 < std::vector<std::string>
1412 >
1413 > vector<string>
1414   OSUAnalysis::splitString (string inputString){
1415  
1416 <  std::stringstream stringStream(inputString);
1417 <  std::istream_iterator<std::string> begin(stringStream);
1418 <  std::istream_iterator<std::string> end;
1419 <  std::vector<std::string> stringVector(begin, end);
1416 >  stringstream stringStream(inputString);
1417 >  istream_iterator<string> begin(stringStream);
1418 >  istream_iterator<string> end;
1419 >  vector<string> stringVector(begin, end);
1420    return stringVector;
1421  
1422   }
1423  
1424 +
1425 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1426 +  // Set two object strings from the tempInputCollection string,
1427 +  // For example, if tempInputCollection is "electron-muon pairs",
1428 +  // then obj1 = "electrons" and obj2 = "muons".
1429 +  // Note that the objects have an "s" appended.
1430 +
1431 +  int dashIndex = tempInputCollection.find("-");
1432 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1433 +  int secondWordLength = spaceIndex - dashIndex;
1434 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1435 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1436 +
1437 + }
1438 +
1439 +
1440 + string OSUAnalysis::getObjToGet(string obj) {
1441 +  // Return the string corresponding to the object to get for the given obj string.
1442 +  // Right now this only handles the case in which obj contains "secondary",
1443 +  // e.g, "secondary muons".
1444 +  // Note that "s" is NOT appended.
1445 +
1446 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1447 +  int firstSpaceIndex = obj.find_first_of(" ");
1448 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1449 +
1450 + }
1451 +
1452 +
1453 + //!jet valueLookup
1454   double
1455 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1455 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1456  
1457    double value = 0.0;
1458    if(variable == "energy") value = object->energy;
# Line 581 | Line 1571 | OSUAnalysis::valueLookup (const BNjet* o
1571    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1572    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1573  
1574 +  //user defined variable
1575 +  else if(variable == "disappTrkLeadingJetID") {
1576 +    value = object->pt > 110
1577 +      && fabs(object->eta) < 2.4
1578 +      && object->chargedHadronEnergyFraction > 0.2
1579 +      && object->neutralHadronEnergyFraction < 0.7
1580 +      && object->chargedEmEnergyFraction < 0.5
1581 +      && object->neutralEmEnergyFraction < 0.7;
1582 +  }
1583  
1584 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1584 >  else if(variable == "disappTrkSubLeadingJetID") {
1585 >    value = object->pt > 30
1586 >      && fabs(object->eta) < 4.5
1587 >      && object->neutralHadronEnergyFraction < 0.7
1588 >      && object->chargedEmEnergyFraction < 0.5;
1589 >  }
1590 >
1591 >  else if(variable == "dPhiMet") {
1592 >    if (const BNmet *met = chosenMET ()) {
1593 >      value = deltaPhi (object->phi, met->phi);
1594 >    } else value = -999;
1595 >  }
1596 >
1597 >
1598 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1599  
1600    value = applyFunction(function, value);
1601  
1602    return value;
1603 < }
591 <
1603 > } // end jet valueLookup
1604  
1605  
1606 + //!muon valueLookup
1607   double
1608 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1608 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1609  
1610    double value = 0.0;
1611    if(variable == "energy") value = object->energy;
# Line 608 | Line 1621 | OSUAnalysis::valueLookup (const BNmuon*
1621    else if(variable == "ecalIso") value = object->ecalIso;
1622    else if(variable == "hcalIso") value = object->hcalIso;
1623    else if(variable == "caloIso") value = object->caloIso;
1624 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
1624 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
1625    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
1626    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
1627    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 684 | Line 1697 | OSUAnalysis::valueLookup (const BNmuon*
1697    else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1698    else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1699    else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1700 +  else if(variable == "chargedHadronIsoDR04") value = object->chargedHadronIsoDR04;
1701 +  else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1702 +  else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1703 +  else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1704    else if(variable == "rhoPrime") value = object->rhoPrime;
1705    else if(variable == "AEffDr03") value = object->AEffDr03;
1706    else if(variable == "AEffDr04") value = object->AEffDr04;
# Line 691 | Line 1708 | OSUAnalysis::valueLookup (const BNmuon*
1708    else if(variable == "pfIsoR03SumNeutralHadronEt") value = object->pfIsoR03SumNeutralHadronEt;
1709    else if(variable == "pfIsoR03SumPhotonEt") value = object->pfIsoR03SumPhotonEt;
1710    else if(variable == "pfIsoR03SumPUPt") value = object->pfIsoR03SumPUPt;
1711 +  else if(variable == "relpfIsoR04SumExceptChargedHad") value = (object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)/ object->pt;
1712 +  else if(variable == "relpfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt/object->pt;
1713 +  else if(variable == "relpfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt/object->pt;
1714 +  else if(variable == "relpfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt/object->pt;
1715 +  else if(variable == "relpfIsoR04SumPUPt") value = object->pfIsoR04SumPUPt/object->pt;
1716    else if(variable == "pfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt;
1717    else if(variable == "pfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt;
1718    else if(variable == "pfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt;
# Line 746 | Line 1768 | OSUAnalysis::valueLookup (const BNmuon*
1768    else if(variable == "numberOfMatchedStations") value = object->numberOfMatchedStations;
1769    else if(variable == "time_ndof") value = object->time_ndof;
1770  
1771 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1771 >  //user-defined variables
1772 >  else if(variable == "looseID") {
1773 >    value = object->pt > 10 &&
1774 >      (object->isGlobalMuon  > 0 ||
1775 >       object->isTrackerMuon > 0);
1776 >  }
1777 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1778 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1779 >  else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1780 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1781 >  else if(variable == "relPFdBetaIsoPseudo") value = (object->pfIsoR04SumChargedHadronPt + object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt) / object->pt;
1782 >  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1783 >  else if(variable == "metMT") {
1784 >    if (const BNmet *met = chosenMET ())
1785 >      {
1786 >        double dPhi = deltaPhi (object->phi, met->phi);
1787 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1788 >      }
1789 >    else
1790 >      value = -999;
1791 >  }
1792 >
1793 >
1794 >
1795 >  else if(variable == "correctedD0VertexInEBPlus"){
1796 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1797 >    else value = -999;
1798 >  }
1799 >  else if(variable == "correctedD0VertexOutEBPlus"){
1800 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1801 >    else value = -999;
1802 >  }
1803 >  else if(variable == "correctedD0VertexEEPlus"){
1804 >    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1805 >    else value = -999;
1806 >  }
1807 >
1808 >  else if(variable == "correctedD0BeamspotInEBPlus"){
1809 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1810 >    else value = -999;
1811 >  }
1812 >  else if(variable == "correctedD0BeamspotOutEBPlus"){
1813 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1814 >    else value = -999;
1815 >  }
1816 >  else if(variable == "correctedD0BeamspotEEPlus"){
1817 >    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1818 >    else value = -999;
1819 >  }
1820 >
1821 >  else if(variable == "correctedD0VertexInEBMinus"){
1822 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1823 >    else value = -999;
1824 >  }
1825 >  else if(variable == "correctedD0VertexOutEBMinus"){
1826 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1827 >    else value = -999;
1828 >  }
1829 >  else if(variable == "correctedD0VertexEEMinus"){
1830 >    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1831 >    else value = -999;
1832 >  }
1833 >
1834 >  else if(variable == "correctedD0BeamspotInEBMinus"){
1835 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1836 >    else value = -999;
1837 >  }
1838 >  else if(variable == "correctedD0BeamspotOutEBMinus"){
1839 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1840 >    else value = -999;
1841 >  }
1842 >  else if(variable == "correctedD0BeamspotEEMinus"){
1843 >    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1844 >    else value = -999;
1845 >  }
1846 >
1847 >
1848 >  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1849 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1850 >    else value = -999;
1851 >  }
1852 >  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1853 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1854 >    else value = -999;
1855 >  }
1856 >  else if(variable == "correctedD0VertexEEPositiveCharge"){
1857 >    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1858 >    else value = -999;
1859 >  }
1860 >
1861 >  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1862 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1863 >    else value = -999;
1864 >  }
1865 >  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1866 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1867 >    else value = -999;
1868 >  }
1869 >  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1870 >    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1871 >    else value = -999;
1872 >  }
1873 >
1874 >  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1875 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1876 >    else value = -999;
1877 >  }
1878 >  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1879 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1880 >    else value = -999;
1881 >  }
1882 >  else if(variable == "correctedD0VertexEENegativeCharge"){
1883 >    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1884 >    else value = -999;
1885 >  }
1886 >
1887 >  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1888 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1889 >    else value = -999;
1890 >  }
1891 >  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1892 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1893 >    else value = -999;
1894 >  }
1895 >  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1896 >    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1897 >    else value = -999;
1898 >  }
1899 >
1900 >
1901 >  else if(variable == "tightID") {
1902 >    value = object->isGlobalMuon > 0                \
1903 >      && object->isPFMuon > 0                        \
1904 >      && object->normalizedChi2 < 10                \
1905 >      && object->numberOfValidMuonHits > 0        \
1906 >      && object->numberOfMatchedStations > 1        \
1907 >      && fabs(object->correctedD0Vertex) < 0.2        \
1908 >      && fabs(object->correctedDZ) < 0.5        \
1909 >      && object->numberOfValidPixelHits > 0                \
1910 >      && object->numberOfLayersWithMeasurement > 5;
1911 >  }
1912 >  else if(variable == "tightIDdisplaced"){
1913 >    value = object->isGlobalMuon > 0                \
1914 >      && object->isPFMuon > 0                        \
1915 >      && object->normalizedChi2 < 10                \
1916 >      && object->numberOfValidMuonHits > 0        \
1917 >      && object->numberOfMatchedStations > 1        \
1918 >      && object->numberOfValidPixelHits > 0        \
1919 >      && object->numberOfLayersWithMeasurement > 5;
1920 >  }
1921 >
1922 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1923 >
1924 >  else if(variable == "genMatchedPdgId"){
1925 >    int index = getGenMatchedParticleIndex(object);
1926 >    if(index == -1) value = 0;
1927 >    else value = mcparticles->at(index).id;
1928 >  }
1929 >
1930 >  else if(variable == "genMatchedId"){
1931 >    int index = getGenMatchedParticleIndex(object);
1932 >    if(index == -1) value = 0;
1933 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
1934 >  }
1935 >  else if(variable == "genMatchedMotherId"){
1936 >    int index = getGenMatchedParticleIndex(object);
1937 >    if(index == -1) value = 0;
1938 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1939 >  }
1940 >  else if(variable == "genMatchedMotherIdReverse"){
1941 >    int index = getGenMatchedParticleIndex(object);
1942 >    if(index == -1) value = 24;
1943 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1944 >  }
1945 >  else if(variable == "genMatchedGrandmotherId"){
1946 >    int index = getGenMatchedParticleIndex(object);
1947 >    if(index == -1) value = 0;
1948 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1949 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1950 >      if(motherIndex == -1) value = 0;
1951 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1952 >    }
1953 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1954 >  }
1955 >  else if(variable == "genMatchedGrandmotherIdReverse"){
1956 >    int index = getGenMatchedParticleIndex(object);
1957 >    if(index == -1) value = 24;
1958 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1959 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1960 >      if(motherIndex == -1) value = 24;
1961 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1962 >    }
1963 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1964 >  }
1965 >  else if(variable == "pfMuonsFromVertex"){
1966 >    double d0Error, dzError;
1967 >
1968 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1969 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1970 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1971 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1972 >      || fabs (object->correctedDZ / dzError) > 99.0;
1973 >    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1974 >  }
1975 >
1976 >
1977 >
1978 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1979  
1980    value = applyFunction(function, value);
1981  
1982    return value;
1983 < }
1983 > } // end muon valueLookup
1984  
1985  
1986 + //!electron valueLookup
1987   double
1988 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1988 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1989  
1990    double value = 0.0;
1991    if(variable == "energy") value = object->energy;
# Line 915 | Line 2145 | OSUAnalysis::valueLookup (const BNelectr
2145    else if(variable == "eidHyperTight4MC") value = object->eidHyperTight4MC;
2146    else if(variable == "passConvVeto") value = object->passConvVeto;
2147  
2148 +  //user-defined variables
2149 +  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2150 +  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2151 +  else if(variable == "detIso") value = (object->trackIso) / object->pt;
2152 +  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2153 +  else if(variable == "relPFrhoIsoEB") value = object->isEB ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2154 +  else if(variable == "relPFrhoIsoEE") value = object->isEE ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2155 +  else if(variable == "metMT") {
2156 +    if (const BNmet *met = chosenMET ())
2157 +      {
2158 +        double dPhi = deltaPhi (object->phi, met->phi);
2159 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2160 +      }
2161 +    else
2162 +      value = -999;
2163 +  }
2164  
2165 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2165 >  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
2166 >    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
2167 >    else value = -999;
2168 >  }
2169 >  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
2170 >    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
2171 >    else value = -999;
2172 >  }
2173 >
2174 >  else if(variable == "correctedD0VertexInEBPlus"){
2175 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
2176 >    else value = -999;
2177 >  }
2178 >  else if(variable == "correctedD0VertexOutEBPlus"){
2179 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
2180 >    else value = -999;
2181 >  }
2182 >  else if(variable == "correctedD0VertexEEPlus"){
2183 >    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
2184 >    else value = -999;
2185 >  }
2186 >
2187 >  else if(variable == "correctedD0BeamspotInEBPlus"){
2188 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
2189 >    else value = -999;
2190 >  }
2191 >  else if(variable == "correctedD0BeamspotOutEBPlus"){
2192 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
2193 >    else value = -999;
2194 >  }
2195 >  else if(variable == "correctedD0BeamspotEEPlus"){
2196 >    if(object->isEE && object->eta > 0) value = object->correctedD0;
2197 >    else value = -999;
2198 >  }
2199 >
2200 >  else if(variable == "correctedD0VertexInEBMinus"){
2201 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
2202 >    else value = -999;
2203 >  }
2204 >  else if(variable == "correctedD0VertexOutEBMinus"){
2205 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
2206 >    else value = -999;
2207 >  }
2208 >  else if(variable == "correctedD0VertexEEMinus"){
2209 >    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
2210 >    else value = -999;
2211 >  }
2212 >
2213 >  else if(variable == "correctedD0BeamspotInEBMinus"){
2214 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
2215 >    else value = -999;
2216 >  }
2217 >  else if(variable == "correctedD0BeamspotOutEBMinus"){
2218 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
2219 >    else value = -999;
2220 >  }
2221 >  else if(variable == "correctedD0BeamspotEEMinus"){
2222 >    if(object->isEE && object->eta < 0) value = object->correctedD0;
2223 >    else value = -999;
2224 >  }
2225 >
2226 >  else if(variable == "looseID"){
2227 >    if (object->isEB)
2228 >      {
2229 >        value = fabs(object->delEtaIn) < 0.007 \
2230 >          && fabs (object->delPhiIn) < 0.15 \
2231 >          && object->scSigmaIEtaIEta < 0.01 \
2232 >          && object->hadOverEm < 0.12 \
2233 >          && fabs (object->correctedD0Vertex) < 0.02 \
2234 >          && fabs (object->correctedDZ) < 0.2 \
2235 >          && object->absInvEMinusInvPin < 0.05 \
2236 >          && object->passConvVeto;
2237 >      }
2238 >    else
2239 >      {
2240 >        value = fabs(object->delEtaIn) < 0.009 \
2241 >          && fabs (object->delPhiIn) < 0.10 \
2242 >          && object->scSigmaIEtaIEta < 0.03 \
2243 >          && object->hadOverEm < 0.10 \
2244 >          && fabs (object->correctedD0Vertex) < 0.02 \
2245 >          && fabs (object->correctedDZ) < 0.2 \
2246 >          && object->absInvEMinusInvPin < 0.05 \
2247 >          && object->passConvVeto;
2248 >      }
2249 >  }
2250 >
2251 >  else if(variable == "tightID"){
2252 >    if (object->isEB)
2253 >      {
2254 >        value = fabs(object->delEtaIn) < 0.004 \
2255 >          && fabs (object->delPhiIn) < 0.03 \
2256 >          && object->scSigmaIEtaIEta < 0.01 \
2257 >          && object->hadOverEm < 0.12 \
2258 >          && fabs (object->correctedD0Vertex) < 0.02 \
2259 >          && fabs (object->correctedDZ) < 0.1 \
2260 >          && object->absInvEMinusInvPin < 0.05 \
2261 >          && object->passConvVeto;
2262 >      }
2263 >    else
2264 >      {
2265 >        value = fabs(object->delEtaIn) < 0.005 \
2266 >          && fabs (object->delPhiIn) < 0.02 \
2267 >          && object->scSigmaIEtaIEta < 0.03 \
2268 >          && object->hadOverEm < 0.10 \
2269 >          && fabs (object->correctedD0Vertex) < 0.02 \
2270 >          && fabs (object->correctedDZ) < 0.1 \
2271 >          && object->absInvEMinusInvPin < 0.05 \
2272 >          && object->passConvVeto;
2273 >      }
2274 >  }
2275 >
2276 >  else if(variable == "looseID"){
2277 >    value = object->pt > 10
2278 >      && object->mvaNonTrigV0 > 0;
2279 >      }
2280 >  else if(variable == "correctedD0VertexInEBPositiveCharge"){
2281 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2282 >    else value = -999;
2283 >  }
2284 >  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
2285 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2286 >    else value = -999;
2287 >  }
2288 >  else if(variable == "correctedD0VertexEEPositiveCharge"){
2289 >    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
2290 >    else value = -999;
2291 >  }
2292 >
2293 >  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
2294 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
2295 >    else value = -999;
2296 >  }
2297 >  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
2298 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
2299 >    else value = -999;
2300 >  }
2301 >  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
2302 >    if(object->isEE && object->charge > 0) value = object->correctedD0;
2303 >    else value = -999;
2304 >  }
2305 >
2306 >  else if(variable == "correctedD0VertexInEBNegativeCharge"){
2307 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2308 >    else value = -999;
2309 >  }
2310 >  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
2311 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2312 >    else value = -999;
2313 >  }
2314 >  else if(variable == "correctedD0VertexEENegativeCharge"){
2315 >    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
2316 >    else value = -999;
2317 >  }
2318 >
2319 >  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
2320 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
2321 >    else value = -999;
2322 >  }
2323 >  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
2324 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
2325 >    else value = -999;
2326 >  }
2327 >  else if(variable == "correctedD0BeamspotEENegativeCharge"){
2328 >    if(object->isEE && object->charge < 0) value = object->correctedD0;
2329 >    else value = -999;
2330 >  }
2331 >
2332 >
2333 >  else if(variable == "tightIDdisplaced"){
2334 >    if (object->isEB)
2335 >      {
2336 >        value = fabs(object->delEtaIn) < 0.004 \
2337 >          && fabs (object->delPhiIn) < 0.03 \
2338 >          && object->scSigmaIEtaIEta < 0.01 \
2339 >          && object->hadOverEm < 0.12 \
2340 >          && object->absInvEMinusInvPin < 0.05;
2341 >      }
2342 >    else
2343 >      {
2344 >        value = fabs (object->delEtaIn) < 0.005 \
2345 >          && fabs (object->delPhiIn) < 0.02 \
2346 >          && object->scSigmaIEtaIEta < 0.03 \
2347 >          && object->hadOverEm < 0.10 \
2348 >          && object->absInvEMinusInvPin < 0.05;
2349 >      }
2350 >  }
2351 >
2352 >
2353 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2354 >
2355 >  else if(variable == "genMatchedPdgId"){
2356 >    int index = getGenMatchedParticleIndex(object);
2357 >    if(index == -1) value = 0;
2358 >    else value = mcparticles->at(index).id;
2359 >  }
2360 >
2361 >
2362 >  else if(variable == "genMatchedId"){
2363 >    int index = getGenMatchedParticleIndex(object);
2364 >    if(index == -1) value = 0;
2365 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2366 >  }
2367 >  else if(variable == "genMatchedMotherId"){
2368 >    int index = getGenMatchedParticleIndex(object);
2369 >    if(index == -1) value = 0;
2370 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2371 >  }
2372 >  else if(variable == "genMatchedMotherIdReverse"){
2373 >    int index = getGenMatchedParticleIndex(object);
2374 >    if(index == -1) value = 24;
2375 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2376 >  }
2377 >  else if(variable == "genMatchedGrandmotherId"){
2378 >    int index = getGenMatchedParticleIndex(object);
2379 >    if(index == -1) value = 0;
2380 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2381 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2382 >      if(motherIndex == -1) value = 0;
2383 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2384 >    }
2385 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2386 >  }
2387 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2388 >    int index = getGenMatchedParticleIndex(object);
2389 >    if(index == -1) value = 24;
2390 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2391 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2392 >      if(motherIndex == -1) value = 24;
2393 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2394 >    }
2395 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2396 >  }
2397 >  else if(variable == "pfElectronsFromVertex"){
2398 >    double d0Error, dzError;
2399 >
2400 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2401 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2402 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2403 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2404 >      || fabs (object->correctedDZ / dzError) > 99.0;
2405 >    value = !value;
2406 >  }
2407 >
2408 >
2409 >
2410 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2411  
2412    value = applyFunction(function, value);
2413  
2414    return value;
2415 < }
2415 > } // end electron valueLookup
2416  
2417  
2418 + //!event valueLookup
2419   double
2420 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2420 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2421  
2422    double value = 0.0;
2423  
# Line 933 | Line 2425 | OSUAnalysis::valueLookup (const BNevent*
2425    else if(variable == "pthat") value = object->pthat;
2426    else if(variable == "qScale") value = object->qScale;
2427    else if(variable == "alphaQCD") value = object->alphaQCD;
2428 +  else if(variable == "Ht") value = getHt(jets.product());
2429    else if(variable == "alphaQED") value = object->alphaQED;
2430    else if(variable == "scalePDF") value = object->scalePDF;
2431    else if(variable == "x1") value = object->x1;
# Line 993 | Line 2486 | OSUAnalysis::valueLookup (const BNevent*
2486    else if(variable == "id1") value = object->id1;
2487    else if(variable == "id2") value = object->id2;
2488    else if(variable == "evt") value = object->evt;
2489 <
2490 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2489 >  else if(variable == "puScaleFactor"){
2490 >    if(doPileupReweighting_ && datasetType_ != "data")
2491 >      value = puWeight_->at (events->at (0).numTruePV);
2492 >    else
2493 >      value = 1.0;
2494 >  }
2495 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2496 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2497 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2498 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2499 >  else if(variable == "ht") value = chosenHT ();
2500 >  else if(variable == "leadMuPairInvMass"){
2501 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2502 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2503 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2504 >    value = (p0 + p1).M ();
2505 >  }
2506 >  else if(variable == "leadMuPairPt"){
2507 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2508 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2509 >             pt1 (muPair.second->px, muPair.second->py);
2510 >    pt0 += pt1;
2511 >    value = pt0.Mod ();
2512 >  }
2513 >  else if(variable == "leadElPairInvMass"){
2514 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2515 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2516 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2517 >    value = (p0 + p1).M ();
2518 >  }
2519 >  else if(variable == "leadElPairPt"){
2520 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2521 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2522 >             pt1 (muPair.second->px, muPair.second->py);
2523 >    pt0 += pt1;
2524 >    value = pt0.Mod ();
2525 >  }
2526 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2527  
2528    value = applyFunction(function, value);
2529  
2530    return value;
2531 < }
2531 > } // end event valueLookup
2532 >
2533  
2534 + //!tau valueLookup
2535   double
2536 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2536 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2537  
2538    double value = 0.0;
2539  
# Line 1046 | Line 2577 | OSUAnalysis::valueLookup (const BNtau* o
2577    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2578    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2579  
2580 +  else if (variable == "looseHadronicID") {
2581 +    value = object->pt > 10
2582 +      && object->eta < 2.3
2583 +      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2584 +      && object->HPSdecayModeFinding > 0
2585 +      && object->HPSagainstElectronLoose > 0
2586 +      && object->HPSagainstMuonTight > 0;
2587 +  }
2588 +
2589 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2590  
2591 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2591 >  else if(variable == "genMatchedPdgId"){
2592 >    int index = getGenMatchedParticleIndex(object);
2593 >    if(index == -1) value = 0;
2594 >    else value = mcparticles->at(index).id;
2595 >  }
2596 >
2597 >  else if(variable == "genMatchedId"){
2598 >    int index = getGenMatchedParticleIndex(object);
2599 >    if(index == -1) value = 0;
2600 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2601 >  }
2602 >  else if(variable == "genMatchedMotherId"){
2603 >    int index = getGenMatchedParticleIndex(object);
2604 >    if(index == -1) value = 0;
2605 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2606 >  }
2607 >  else if(variable == "genMatchedMotherIdReverse"){
2608 >    int index = getGenMatchedParticleIndex(object);
2609 >    if(index == -1) value = 24;
2610 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2611 >  }
2612 >  else if(variable == "genMatchedGrandmotherId"){
2613 >    int index = getGenMatchedParticleIndex(object);
2614 >    if(index == -1) value = 0;
2615 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2616 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2617 >      if(motherIndex == -1) value = 0;
2618 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2619 >    }
2620 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2621 >  }
2622 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2623 >    int index = getGenMatchedParticleIndex(object);
2624 >    if(index == -1) value = 24;
2625 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2626 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2627 >      if(motherIndex == -1) value = 24;
2628 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2629 >    }
2630 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2631 >  }
2632 >
2633 >
2634 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2635  
2636    value = applyFunction(function, value);
2637  
2638    return value;
2639 < }
2639 > } // end tau valueLookup
2640  
2641 +
2642 + //!met valueLookup
2643   double
2644 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2644 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2645  
2646    double value = 0.0;
2647  
# Line 1119 | Line 2705 | OSUAnalysis::valueLookup (const BNmet* o
2705    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2706    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2707  
2708 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2708 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2709  
2710    value = applyFunction(function, value);
2711  
2712    return value;
2713 < }
2713 > } // end met valueLookup
2714  
2715 +
2716 + //!track valueLookup
2717   double
2718 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2718 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2719  
2720    double value = 0.0;
2721 +  double pMag = sqrt(object->pt * object->pt +
2722 +                     object->pz * object->pz);
2723  
2724    if(variable == "pt") value = object->pt;
2725    else if(variable == "px") value = object->px;
# Line 1149 | Line 2739 | OSUAnalysis::valueLookup (const BNtrack*
2739    else if(variable == "numValidHits") value = object->numValidHits;
2740    else if(variable == "isHighPurity") value = object->isHighPurity;
2741  
2742 +  //additional BNs info for disappTrks
2743 +  else if(variable == "caloEMDeltaRp3")     value = object->caloEMDeltaRp3;
2744 +  else if(variable == "caloHadDeltaRp3")    value = object->caloHadDeltaRp3;
2745 +  else if(variable == "caloEMDeltaRp4")     value = object->caloEMDeltaRp4;
2746 +  else if(variable == "caloHadDeltaRp4")    value = object->caloHadDeltaRp4;
2747 +  else if(variable == "caloEMDeltaRp5")     value = object->caloEMDeltaRp5;
2748 +  else if(variable == "caloHadDeltaRp5")    value = object->caloHadDeltaRp5;
2749 +  else if(variable == "nHitsMissingOuter")  value = object->nHitsMissingOuter;
2750 +  else if(variable == "nHitsMissingInner")  value = object->nHitsMissingInner;
2751 +  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2752 +  else if(variable == "depTrkRp3")          value = object->depTrkRp3;
2753 +  else if(variable == "depEcalRp3")         value = object->depEcalRp3;
2754 +  else if(variable == "depHcalRp3")         value = object->depHcalRp3;
2755 +  else if(variable == "depHoRp3")           value = object->depHoRp3;
2756 +  else if(variable == "nTracksRp3")         value = object->nTracksRp3;
2757 +  else if(variable == "trackerVetoPtRp3")   value = object->trackerVetoPtRp3;
2758 +  else if(variable == "emVetoEtRp3")        value = object->emVetoEtRp3;
2759 +  else if(variable == "hadVetoEtRp3")       value = object->hadVetoEtRp3;
2760 +  else if(variable == "hoVetoEtRp3")        value = object->hoVetoEtRp3;
2761 +  else if(variable == "depTrkRp5")          value = object->depTrkRp5;
2762 +  else if(variable == "depEcalRp5")         value = object->depEcalRp5;
2763 +  else if(variable == "depHcalRp5")         value = object->depHcalRp5;
2764 +  else if(variable == "depHoRp5")           value = object->depHoRp5;
2765 +  else if(variable == "nTracksRp5")         value = object->nTracksRp5;
2766 +  else if(variable == "trackerVetoPtRp5")   value = object->trackerVetoPtRp5;
2767 +  else if(variable == "emVetoEtRp5")        value = object->emVetoEtRp5;
2768 +  else if(variable == "hadVetoEtRp5")       value = object->hadVetoEtRp5;
2769 +  else if(variable == "hoVetoEtRp5")        value = object->hoVetoEtRp5;
2770 +
2771 +  //user defined variables
2772 +  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;
2773 +  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2774 +  else if(variable == "depTrkRp5MinusPt"){
2775 +    if ( (object->depTrkRp5 - object->pt) < 0 ) {
2776 +           value = 0;
2777 +         }
2778 +         else value =  (object->depTrkRp5 - object->pt);
2779 +  }
2780 +  else if(variable == "depTrkRp3MinusPt"){
2781 +    if ( (object->depTrkRp3 - object->pt) < 0 ) {
2782 +      value = 0;
2783 +    }
2784 +    else value =  (object->depTrkRp3 - object->pt);
2785 +  }
2786 +
2787 +  else if(variable == "dPhiMet") {
2788 +    if (const BNmet *met = chosenMET ()) {
2789 +      value = deltaPhi (object->phi, met->phi);
2790 +    } else value = -999;
2791 +  }
2792 +  
2793 +  
2794 +  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2795 +  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2796 +  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2797 +  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2798 +  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2799 +  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2800 +  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2801 +  else if(variable == "ptError")                    value = object->ptError;
2802 +  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2803 +  else if (variable == "d0wrtPV"){
2804 +    double vx = object->vx - chosenVertex ()->x,
2805 +      vy = object->vy - chosenVertex ()->y,
2806 +      px = object->px,
2807 +      py = object->py,
2808 +      pt = object->pt;
2809 +    value = (-vx * py + vy * px) / pt;
2810 +  }
2811 +  else if (variable == "dZwrtPV"){
2812 +    double vx = object->vx - chosenVertex ()->x,
2813 +      vy = object->vy - chosenVertex ()->y,
2814 +      vz = object->vz - chosenVertex ()->z,
2815 +      px = object->px,
2816 +      py = object->py,
2817 +      pz = object->pz,
2818 +      pt = object->pt;
2819 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2820 +  }
2821 +
2822 +
2823 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2824 +
2825 +  else if(variable == "genMatchedPdgId"){
2826 +    int index = getGenMatchedParticleIndex(object);
2827 +    if(index == -1) value = 0;
2828 +    else value = mcparticles->at(index).id;
2829 +  }
2830 +
2831 +
2832 +  else if(variable == "genMatchedId"){
2833 +    int index = getGenMatchedParticleIndex(object);
2834 +    if(index == -1) value = 0;
2835 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
2836 +  }
2837 +  else if(variable == "genMatchedMotherId"){
2838 +    int index = getGenMatchedParticleIndex(object);
2839 +    if(index == -1) value = 0;
2840 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2841 +  }
2842 +  else if(variable == "genMatchedMotherIdReverse"){
2843 +    int index = getGenMatchedParticleIndex(object);
2844 +    if(index == -1) value = 24;
2845 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2846 +  }
2847 +  else if(variable == "genMatchedGrandmotherId"){
2848 +    int index = getGenMatchedParticleIndex(object);
2849 +    if(index == -1) value = 0;
2850 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2851 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2852 +      if(motherIndex == -1) value = 0;
2853 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2854 +    }
2855 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2856 +  }
2857 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2858 +    int index = getGenMatchedParticleIndex(object);
2859 +    if(index == -1) value = 24;
2860 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2861 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2862 +      if(motherIndex == -1) value = 24;
2863 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2864 +    }
2865 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2866 +  }
2867 +
2868 +
2869  
2870 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2870 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2871  
2872    value = applyFunction(function, value);
2873  
2874    return value;
2875 < }
2875 > } // end track valueLookup
2876 >
2877  
2878 + //!genjet valueLookup
2879   double
2880 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2880 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2881  
2882    double value = 0.0;
2883  
# Line 1178 | Line 2897 | OSUAnalysis::valueLookup (const BNgenjet
2897    else if(variable == "charge") value = object->charge;
2898  
2899  
2900 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2900 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2901  
2902    value = applyFunction(function, value);
2903  
2904    return value;
2905   }
2906  
2907 + //!mcparticle valueLookup
2908   double
2909 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2909 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2910  
2911    double value = 0.0;
2912  
# Line 1275 | Line 2995 | OSUAnalysis::valueLookup (const BNmcpart
2995    else if(variable == "grandMother11Status") value = object->grandMother11Status;
2996    else if(variable == "grandMother11Charge") value = object->grandMother11Charge;
2997  
2998 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2998 >  //user-defined variables
2999 >  else if (variable == "d0"){
3000 >    double vx = object->vx - chosenVertex ()->x,
3001 >      vy = object->vy - chosenVertex ()->y,
3002 >      px = object->px,
3003 >      py = object->py,
3004 >      pt = object->pt;
3005 >    value = (-vx * py + vy * px) / pt;
3006 >  }
3007 >  else if (variable == "dz"){
3008 >    double vx = object->vx - chosenVertex ()->x,
3009 >      vy = object->vy - chosenVertex ()->y,
3010 >      vz = object->vz - chosenVertex ()->z,
3011 >      px = object->px,
3012 >      py = object->py,
3013 >      pz = object->pz,
3014 >      pt = object->pt;
3015 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3016 >  }
3017 >  else if(variable == "v0"){
3018 >    value = sqrt(object->vx*object->vx + object->vy*object->vy);
3019 >  }
3020 >  else if(variable == "deltaV0"){
3021 >    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
3022 >  }
3023 >  else if (variable == "deltaVx"){
3024 >    value = object->vx - chosenVertex ()->x;
3025 >  }
3026 >  else if (variable == "deltaVy"){
3027 >    value = object->vy - chosenVertex ()->y;
3028 >  }
3029 >  else if (variable == "deltaVz"){
3030 >    value = object->vz - chosenVertex ()->z;
3031 >  }
3032 >
3033 >
3034 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3035  
3036    value = applyFunction(function, value);
3037  
3038    return value;
3039 < }
3039 > } // end mcparticle valueLookup
3040  
3041 +
3042 + //!primaryvertex valueLookup
3043   double
3044 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
3044 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
3045  
3046    double value = 0.0;
3047  
# Line 1302 | Line 3060 | OSUAnalysis::valueLookup (const BNprimar
3060    else if(variable == "isGood") value = object->isGood;
3061  
3062  
3063 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3063 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3064  
3065    value = applyFunction(function, value);
3066  
3067    return value;
3068   }
3069  
3070 + //!bxlumi valueLookup
3071   double
3072 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
3072 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
3073  
3074    double value = 0.0;
3075  
# Line 1319 | Line 3078 | OSUAnalysis::valueLookup (const BNbxlumi
3078    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
3079  
3080  
3081 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3081 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3082  
3083    value = applyFunction(function, value);
3084  
3085    return value;
3086   }
3087  
3088 + //!photon valueLookup
3089   double
3090 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
3090 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
3091  
3092    double value = 0.0;
3093  
# Line 1402 | Line 3162 | OSUAnalysis::valueLookup (const BNphoton
3162    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
3163  
3164  
3165 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3165 >
3166 >
3167 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3168 >
3169 >  else if(variable == "genMatchedPdgId"){
3170 >    int index = getGenMatchedParticleIndex(object);
3171 >    if(index == -1) value = 0;
3172 >    else value = mcparticles->at(index).id;
3173 >  }
3174 >
3175 >
3176 >
3177 >  else if(variable == "genMatchedId"){
3178 >    int index = getGenMatchedParticleIndex(object);
3179 >    if(index == -1) value = 0;
3180 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
3181 >  }
3182 >  else if(variable == "genMatchedMotherId"){
3183 >    int index = getGenMatchedParticleIndex(object);
3184 >    if(index == -1) value = 0;
3185 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
3186 >  }
3187 >  else if(variable == "genMatchedMotherIdReverse"){
3188 >    int index = getGenMatchedParticleIndex(object);
3189 >    if(index == -1) value = 24;
3190 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
3191 >  }
3192 >  else if(variable == "genMatchedGrandmotherId"){
3193 >    int index = getGenMatchedParticleIndex(object);
3194 >    if(index == -1) value = 0;
3195 >    else if(fabs(mcparticles->at(index).motherId) == 15){
3196 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3197 >      if(motherIndex == -1) value = 0;
3198 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3199 >    }
3200 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3201 >  }
3202 >  else if(variable == "genMatchedGrandmotherIdReverse"){
3203 >    int index = getGenMatchedParticleIndex(object);
3204 >    if(index == -1) value = 24;
3205 >    else if(fabs(mcparticles->at(index).motherId) == 15){
3206 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3207 >      if(motherIndex == -1) value = 24;
3208 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3209 >    }
3210 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3211 >  }
3212 >
3213 >
3214 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3215  
3216    value = applyFunction(function, value);
3217  
3218    return value;
3219 < }
3219 > } // end photon valueLookup
3220 >
3221  
3222 + //!supercluster valueLookup
3223   double
3224 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
3224 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
3225  
3226    double value = 0.0;
3227  
# Line 1424 | Line 3235 | OSUAnalysis::valueLookup (const BNsuperc
3235    else if(variable == "theta") value = object->theta;
3236  
3237  
3238 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3238 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3239  
3240    value = applyFunction(function, value);
3241  
3242    return value;
3243   }
3244  
3245 + //!trigobj valueLookup
3246 + double
3247 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3248 +
3249 +  double value = 0.0;
3250 +
3251 +  if(variable == "pt") value = object->pt;
3252 +  else if(variable == "eta") value = object->eta;
3253 +  else if(variable == "phi") value = object->phi;
3254 +  else if(variable == "px") value = object->px;
3255 +  else if(variable == "py") value = object->py;
3256 +  else if(variable == "pz") value = object->pz;
3257 +  else if(variable == "et") value = object->et;
3258 +  else if(variable == "energy") value = object->energy;
3259 +  else if(variable == "etTotal") value = object->etTotal;
3260 +  else if(variable == "id") value = object->id;
3261 +  else if(variable == "charge") value = object->charge;
3262 +  else if(variable == "isIsolated") value = object->isIsolated;
3263 +  else if(variable == "isMip") value = object->isMip;
3264 +  else if(variable == "isForward") value = object->isForward;
3265 +  else if(variable == "isRPC") value = object->isRPC;
3266 +  else if(variable == "bx") value = object->bx;
3267 +  else if(variable == "filter") {
3268 +    if ((stringValue = object->filter) == "")
3269 +      stringValue = "none";  // stringValue should only be empty if value is filled
3270 +  }
3271 +
3272 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3273 +
3274 +  value = applyFunction(function, value);
3275 +
3276 +  return value;
3277 + }
3278 +
3279 + //!muon-muon pair valueLookup
3280 + double
3281 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3282 +
3283 +  double value = 0.0;
3284 +
3285 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3286 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3287 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3288 +  else if(variable == "invMass"){
3289 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3290 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3291 +    value = (fourVector1 + fourVector2).M();
3292 +  }
3293 +  else if(variable == "pt"){
3294 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3295 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3296 +    value = (fourVector1 + fourVector2).Pt();
3297 +  }
3298 +  else if(variable == "threeDAngle")
3299 +    {
3300 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3301 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3302 +      value = (threeVector1.Angle(threeVector2));
3303 +    }
3304 +  else if(variable == "alpha")
3305 +    {
3306 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3307 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3308 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3309 +      value = (pi-threeVector1.Angle(threeVector2));
3310 +    }
3311 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3312 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3313 +  else if(variable == "d0Sign"){
3314 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3315 +    if(d0Sign < 0) value = -0.5;
3316 +    else if (d0Sign > 0) value = 0.5;
3317 +    else value = -999;
3318 +  }
3319 +  else if(variable == "chargeProduct"){
3320 +    value = object1->charge*object2->charge;
3321 +  }
3322 +  else if(variable == "muon1CorrectedD0Vertex"){
3323 +    value = object1->correctedD0Vertex;
3324 +  }
3325 +  else if(variable == "muon2CorrectedD0Vertex"){
3326 +    value = object2->correctedD0Vertex;
3327 +  }
3328 +  else if(variable == "muon1timeAtIpInOut"){
3329 +    value = object1->timeAtIpInOut;
3330 +  }
3331 +  else if(variable == "muon2timeAtIpInOut"){
3332 +    value = object2->timeAtIpInOut;
3333 +  }
3334 +  else if(variable == "muon1correctedD0")
3335 +    {
3336 +      value = object1->correctedD0;
3337 +    }
3338 +  else if(variable == "muon2correctedD0")
3339 +    {
3340 +      value = object2->correctedD0;
3341 +    }
3342 +
3343 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3344 +
3345 +  value = applyFunction(function, value);
3346 +
3347 +  return value;
3348 + } // end muon-muon pair valueLookup
3349 +
3350 +
3351 + //!muon-photon pair valueLookup
3352 + double
3353 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3354 +
3355 +  double value = 0.0;
3356 +
3357 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3358 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3359 +  else if(variable == "photonEta") value = object2->eta;
3360 +  else if(variable == "photonPt") value = object2->pt;
3361 +  else if(variable == "muonEta") value = object1->eta;
3362 +  else if(variable == "photonPhi") value = object2->phi;
3363 +  else if(variable == "muonPhi") value = object1->phi;
3364 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3365 +  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3366 +  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3367 +  else if(variable == "invMass"){
3368 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3369 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3370 +    value = (fourVector1 + fourVector2).M();
3371 +  }
3372 +  else if(variable == "pt"){
3373 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3374 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3375 +    value = (fourVector1 + fourVector2).Pt();
3376 +  }
3377 +  else if(variable == "threeDAngle")
3378 +    {
3379 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3380 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3381 +      value = (threeVector1.Angle(threeVector2));
3382 +    }
3383 +  else if(variable == "alpha")
3384 +    {
3385 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3386 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3387 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3388 +      value = (pi-threeVector1.Angle(threeVector2));
3389 +    }
3390 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3391 +
3392 +  value = applyFunction(function, value);
3393 +
3394 +  return value;
3395 + }
3396 +
3397 + //!electron-photon pair valueLookup
3398 + double
3399 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3400 +
3401 +  double value = 0.0;
3402 +
3403 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3404 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3405 +  else if(variable == "photonEta") value = object2->eta;
3406 +  else if(variable == "photonPt") value = object2->pt;
3407 +  else if(variable == "electronEta") value = object1->eta;
3408 +  else if(variable == "photonPhi") value = object2->phi;
3409 +  else if(variable == "electronPhi") value = object1->phi;
3410 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3411 +  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3412 +  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3413 +  else if(variable == "invMass"){
3414 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3415 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3416 +    value = (fourVector1 + fourVector2).M();
3417 +  }
3418 +  else if(variable == "pt"){
3419 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3420 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3421 +    value = (fourVector1 + fourVector2).Pt();
3422 +  }
3423 +  else if(variable == "threeDAngle")
3424 +    {
3425 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3426 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3427 +      value = (threeVector1.Angle(threeVector2));
3428 +    }
3429 +  else if(variable == "alpha")
3430 +    {
3431 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3432 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3433 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3434 +      value = (pi-threeVector1.Angle(threeVector2));
3435 +    }
3436 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3437 +
3438 +  value = applyFunction(function, value);
3439 +
3440 +  return value;
3441 + }
3442 +
3443 + //!electron-electron pair valueLookup
3444 + double
3445 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3446 +
3447 +  double value = 0.0;
3448 +
3449 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3450 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3451 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3452 +  else if(variable == "invMass"){
3453 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3454 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3455 +    value = (fourVector1 + fourVector2).M();
3456 +  }
3457 +  else if(variable == "pt"){
3458 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3459 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3460 +    value = (fourVector1 + fourVector2).Pt();
3461 +  }
3462 +  else if(variable == "threeDAngle")
3463 +    {
3464 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3465 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3466 +      value = (threeVector1.Angle(threeVector2));
3467 +    }
3468 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3469 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3470 +  else if(variable == "d0Sign"){
3471 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3472 +    if(d0Sign < 0) value = -0.5;
3473 +    else if (d0Sign > 0) value = 0.5;
3474 +    else value = -999;
3475 +  }
3476 +  else if(variable == "chargeProduct"){
3477 +    value = object1->charge*object2->charge;
3478 +  }
3479 +  else if(variable == "electron1CorrectedD0Vertex"){
3480 +    value = object1->correctedD0Vertex;
3481 +  }
3482 +  else if(variable == "electron2CorrectedD0Vertex"){
3483 +    value = object2->correctedD0Vertex;
3484 +  }
3485 +  else if(variable == "electron1CorrectedD0"){
3486 +    value = object1->correctedD0;
3487 +  }
3488 +  else if(variable == "electron2CorrectedD0"){
3489 +    value = object2->correctedD0;
3490 +  }
3491 +
3492 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3493 +
3494 +  value = applyFunction(function, value);
3495 +
3496 +  return value;
3497 + }
3498 +
3499 + //!electron-muon pair valueLookup
3500 + double
3501 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3502 +
3503 +  double value = 0.0;
3504 +
3505 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3506 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3507 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3508 +  else if(variable == "invMass"){
3509 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3510 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3511 +    value = (fourVector1 + fourVector2).M();
3512 +  }
3513 +  else if(variable == "pt"){
3514 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3515 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3516 +    value = (fourVector1 + fourVector2).Pt();
3517 +  }
3518 +  else if(variable == "threeDAngle")
3519 +    {
3520 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3521 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3522 +      value = (threeVector1.Angle(threeVector2));
3523 +    }
3524 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3525 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3526 +  else if(variable == "d0Sign"){
3527 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3528 +    if(d0Sign < 0) value = -0.5;
3529 +    else if (d0Sign > 0) value = 0.5;
3530 +    else value = -999;
3531 +  }
3532 +  else if(variable == "chargeProduct"){
3533 +    value = object1->charge*object2->charge;
3534 +  }
3535 +  else if(variable == "electronCorrectedD0Vertex"){
3536 +    value = object1->correctedD0Vertex;
3537 +  }
3538 +  else if(variable == "muonCorrectedD0Vertex"){
3539 +    value = object2->correctedD0Vertex;
3540 +  }
3541 +  else if(variable == "electronCorrectedD0"){
3542 +    value = object1->correctedD0;
3543 +  }
3544 +  else if(variable == "muonCorrectedD0"){
3545 +    value = object2->correctedD0;
3546 +  }
3547 +  else if(variable == "electronDetIso"){
3548 +    value = (object1->trackIso) / object1->pt;
3549 +  }
3550 +  else if(variable == "muonDetIso"){
3551 +    value = (object2->trackIsoDR03) / object2->pt;
3552 +  }
3553 +  else if(variable == "electronRelPFrhoIso"){
3554 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3555 +  }
3556 +  else if(variable == "muonRelPFdBetaIso"){
3557 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3558 +  }
3559 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3560 +  value = applyFunction(function, value);
3561 +
3562 +  return value;
3563 + } // end electron-muon pair valueLookup
3564 +
3565 +
3566 + //!electron-jet pair valueLookup
3567 + double
3568 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3569 +
3570 +  double value = 0.0;
3571 +
3572 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3573 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3574 +  else if(variable == "jetEta") value = object2->eta;
3575 +  else if(variable == "jetPhi") value = object2->phi;
3576 +  else if(variable == "electronEta") value = object1->eta;
3577 +  else if(variable == "electronPhi") value = object1->phi;
3578 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3579 +  else if(variable == "invMass"){
3580 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3581 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3582 +    value = (fourVector1 + fourVector2).M();
3583 +  }
3584 +  else if(variable == "pt"){
3585 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3586 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3587 +    value = (fourVector1 + fourVector2).Pt();
3588 +  }
3589 +  else if(variable == "threeDAngle")
3590 +    {
3591 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3592 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3593 +      value = (threeVector1.Angle(threeVector2));
3594 +    }
3595 +  else if(variable == "chargeProduct"){
3596 +    value = object1->charge*object2->charge;
3597 +  }
3598 +
3599 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3600 +  value = applyFunction(function, value);
3601 +
3602 +  return value;
3603 + }
3604 +
3605 + //!photon-jet pair valueLookup
3606 + double
3607 + OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3608 +
3609 +  double value = 0.0;
3610 +
3611 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3612 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3613 +  else if(variable == "jetEta") value = object2->eta;
3614 +  else if(variable == "jetPhi") value = object2->phi;
3615 +  else if(variable == "photonEta") value = object1->eta;
3616 +  else if(variable == "photonPhi") value = object1->phi;
3617 +  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3618 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3619 +  else if(variable == "invMass"){
3620 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3621 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3622 +    value = (fourVector1 + fourVector2).M();
3623 +  }
3624 +  else if(variable == "pt"){
3625 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3626 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3627 +    value = (fourVector1 + fourVector2).Pt();
3628 +  }
3629 +  else if(variable == "threeDAngle")
3630 +    {
3631 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3632 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3633 +      value = (threeVector1.Angle(threeVector2));
3634 +    }
3635 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3636 +  value = applyFunction(function, value);
3637 +
3638 +  return value;
3639 + }
3640 +
3641 + // track-jet pair valueLookup
3642 + double
3643 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNjet* object2, string variable, string function, string &stringValue){
3644 +
3645 +  double value = 0.0;
3646 +
3647 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3648 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3649 +
3650 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3651 +  value = applyFunction(function, value);
3652 +
3653 +  return value;
3654 +
3655 + }
3656 +
3657 +
3658 +
3659 + // met-jet pair valueLookup
3660 + double
3661 + OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3662 +
3663 +  double value = 0.0;
3664 +
3665 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3666 +
3667 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3668 +  value = applyFunction(function, value);
3669 +
3670 +  return value;
3671 +
3672 + }  
3673 +
3674 +
3675 +
3676 + //!muon-jet pair valueLookup
3677 + double
3678 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3679 +
3680 +  double value = 0.0;
3681 +
3682 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3683 +  else if(variable == "jetEta") value = object2->eta;
3684 +  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3685 +  else if(variable == "jetPt") value = object2->pt;
3686 +  else if(variable == "jetPhi") value = object2->phi;
3687 +  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3688 +  else if(variable == "muonEta") value = object1->eta;
3689 +  else if(variable == "muonPt") value = object1->pt;
3690 +  else if(variable == "muonPhi") value = object1->phi;
3691 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3692 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3693 +  else if(variable == "invMass"){
3694 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3695 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3696 +    value = (fourVector1 + fourVector2).M();
3697 +  }
3698 +  else if(variable == "pt"){
3699 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3700 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3701 +    value = (fourVector1 + fourVector2).Pt();
3702 +  }
3703 +  else if(variable == "threeDAngle")
3704 +    {
3705 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3706 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3707 +      value = (threeVector1.Angle(threeVector2));
3708 +    }
3709 +  else if(variable == "chargeProduct"){
3710 +    value = object1->charge*object2->charge;
3711 +  }
3712 +
3713 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3714 +  value = applyFunction(function, value);
3715 +
3716 +  return value;
3717 + }
3718 +
3719 + //!muon-event valueLookup
3720 + double
3721 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNevent* object2, string variable, string function, string &stringValue){
3722 +
3723 +  double value = 0.0;
3724 +
3725 +  if(variable == "muonEta") value = object1->eta;
3726 +  else if(variable == "muonPt") value = object1->pt;
3727 +  else if(variable == "muonPhi") value = object1->phi;
3728 +  else if(variable == "Ht") value = getHt(jets.product());
3729 +  else if(variable == "pthat")   value = object2->pthat;
3730 +  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3731 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3732 +  value = applyFunction(function, value);
3733 +
3734 +  return value;
3735 + }
3736 + //!jet-jet pair valueLookup
3737 + double
3738 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3739 +
3740 +  double value = 0.0;
3741 +
3742 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3743 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3744 +  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3745 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3746 +  else if(variable == "invMass"){
3747 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3748 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3749 +    value = (fourVector1 + fourVector2).M();
3750 +  }
3751 +  else if(variable == "pt"){
3752 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3753 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3754 +    value = (fourVector1 + fourVector2).Pt();
3755 +  }
3756 +  else if(variable == "threeDAngle")
3757 +    {
3758 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3759 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3760 +      value = (threeVector1.Angle(threeVector2));
3761 +    }
3762 +  else if(variable == "chargeProduct"){
3763 +    value = object1->charge*object2->charge;
3764 +  }
3765 +
3766 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3767 +  value = applyFunction(function, value);
3768 +
3769 +  return value;
3770 + }
3771 +
3772 + //!electron-track pair valueLookup
3773 + double
3774 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3775 +  double electronMass = 0.000511;
3776 +  double value = 0.0;
3777 +  TLorentzVector fourVector1(0, 0, 0, 0);
3778 +  TLorentzVector fourVector2(0, 0, 0, 0);
3779 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3780 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3781 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3782 +  else if(variable == "invMass"){
3783 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3784 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3785 +
3786 +    value = (fourVector1 + fourVector2).M();
3787 +  }
3788 +  else if(variable == "chargeProduct"){
3789 +    value = object1->charge*object2->charge;
3790 +  }
3791 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3792 +  value = applyFunction(function, value);
3793 +  return value;
3794 +
3795 + }
3796 +
3797 +
3798 + //!muon-track pair valueLookup
3799 + double
3800 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3801 +  double pionMass = 0.140;
3802 +  double muonMass = 0.106;
3803 +  double value = 0.0;
3804 +  TLorentzVector fourVector1(0, 0, 0, 0);
3805 +  TLorentzVector fourVector2(0, 0, 0, 0);
3806 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3807 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3808 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3809 +  else if(variable == "invMass"){
3810 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3811 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3812 +
3813 +    value = (fourVector1 + fourVector2).M();
3814 +  }
3815 +  else if(variable == "chargeProduct"){
3816 +    value = object1->charge*object2->charge;
3817 +  }
3818 +
3819 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3820 +  value = applyFunction(function, value);
3821 +  return value;
3822 + }
3823 +
3824 + //!tau-tau pair valueLookup
3825 + double
3826 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3827 +  double value = 0.0;
3828 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3829 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3830 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3831 +  else if(variable == "invMass"){
3832 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3833 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3834 +    value = (fourVector1 + fourVector2).M();
3835 +  }
3836 +
3837 +  else if(variable == "chargeProduct"){
3838 +    value = object1->charge*object2->charge;
3839 +  }
3840 +
3841 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3842 +  value = applyFunction(function, value);
3843 +  return value;
3844 + }
3845 +
3846 + //!muon-tau pair valueLookup
3847 + double
3848 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3849 +  double value = 0.0;
3850 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3851 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3852 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3853 +  else if(variable == "invMass"){
3854 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3855 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3856 +    value = (fourVector1 + fourVector2).M();
3857 +  }
3858 +
3859 +  else if(variable == "chargeProduct"){
3860 +    value = object1->charge*object2->charge;
3861 +  }
3862 +
3863 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3864 +  value = applyFunction(function, value);
3865 +  return value;
3866 + }
3867 +
3868 + //!tau-track pair valueLookup
3869 + double
3870 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3871 +  double value = 0.0;
3872 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3873 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3874 +  else if(variable == "chargeProduct"){
3875 +    value = object1->charge*object2->charge;
3876 +  }
3877 +
3878 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3879 +  value = applyFunction(function, value);
3880 +  return value;
3881 + }
3882 +
3883 +
3884 + //!track-event pair valueLookup
3885 + double
3886 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3887 +
3888 +  double value = 0.0;
3889 +  double pMag = sqrt(object1->pt * object1->pt +
3890 +                     object1->pz * object1->pz);
3891 +
3892 +  if      (variable == "numPV")                      value = object2->numPV;
3893 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3894 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3895 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3896 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3897 +
3898 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3899 +
3900 +  value = applyFunction(function, value);
3901 +
3902 +  return value;
3903 +
3904 + }
3905 +
3906 + //!electron-trigobj pair valueLookup
3907 + double
3908 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3909 +
3910 +  double value = 0.0;
3911 +
3912 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3913 +  else if (variable == "match"){
3914 +    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3915 +      stringValue = object2->filter;
3916 +    else
3917 +      stringValue = "none";
3918 +  }
3919 +
3920 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3921 +
3922 +  value = applyFunction(function, value);
3923 +
3924 +  return value;
3925 +
3926 + }
3927 +
3928 + //!muon-trigobj pair valueLookup
3929 + double
3930 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3931 +
3932 +  double value = 0.0;
3933 +
3934 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3935 +
3936 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3937 +
3938 +  value = applyFunction(function, value);
3939 +
3940 +  return value;
3941 +
3942 + }
3943 +
3944 + //!stop valueLookup
3945 + double
3946 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3947 +
3948 +
3949 +  double value = 0.0;
3950 +
3951 +  if(variable == "ctau") value = object->ctau;
3952 +
3953 +  else if (variable == "d0"){
3954 +    double vx = object->vx - chosenVertex ()->x,
3955 +      vy = object->vy - chosenVertex ()->y,
3956 +      px = object->px,
3957 +      py = object->py,
3958 +      pt = object->pt;
3959 +    value = (-vx * py + vy * px) / pt;
3960 +  }
3961 +
3962 +  else if (variable == "dz"){
3963 +    double vx = object->vx - chosenVertex ()->x,
3964 +      vy = object->vy - chosenVertex ()->y,
3965 +      vz = object->vz - chosenVertex ()->z,
3966 +      px = object->px,
3967 +      py = object->py,
3968 +      pz = object->pz,
3969 +      pt = object->pt;
3970 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3971 +  }
3972 +
3973 +  else if (variable == "minD0"){
3974 +    double minD0=999;
3975 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3976 +      double vx = object->vx - vertex->x,
3977 +        vy = object->vy - vertex->y,
3978 +        px = object->px,
3979 +        py = object->py,
3980 +        pt = object->pt;
3981 +      value = (-vx * py + vy * px) / pt;
3982 +      if(abs(value) < abs(minD0)) minD0 = value;
3983 +    }
3984 +    value = minD0;
3985 +  }
3986 +  else if (variable == "minDz"){
3987 +    double minDz=999;
3988 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3989 +      double vx = object->vx - vertex->x,
3990 +        vy = object->vy - vertex->y,
3991 +        vz = object->vz - vertex->z,
3992 +        px = object->px,
3993 +        py = object->py,
3994 +        pz = object->pz,
3995 +        pt = object->pt;
3996 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3997 +      if(abs(value) < abs(minDz)) minDz = value;
3998 +    }
3999 +    value = minDz;
4000 +  }
4001 +  else if(variable == "distToVertex"){
4002 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4003 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4004 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4005 +  }
4006 +  else if (variable == "minDistToVertex"){
4007 +    double minDistToVertex=999;
4008 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4009 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4010 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4011 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
4012 +
4013 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4014 +    }
4015 +    value = minDistToVertex;
4016 +  }
4017 +  else if (variable == "distToVertexDifference"){
4018 +    double minDistToVertex=999;
4019 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4020 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4021 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4022 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
4023 +
4024 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4025 +    }
4026 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4027 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4028 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4029 +
4030 +    value = distToChosenVertex - minDistToVertex;
4031 +  }
4032 +
4033 +  else if (variable == "closestVertexRank"){
4034 +    double minDistToVertex=999;
4035 +    int vertex_rank = 0;
4036 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4037 +      vertex_rank++;
4038 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4039 +                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
4040 +                      (object->vz-vertex->z)*(object->vz-vertex->z));
4041 +
4042 +      if(abs(dist) < abs(minDistToVertex)){
4043 +        value = vertex_rank;
4044 +        minDistToVertex = dist;
4045 +      }
4046 +    }
4047 +  }
4048 +
4049 +
4050 +
4051 +
4052 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4053 +
4054 +  value = applyFunction(function, value);
4055 +
4056 +  return value;
4057 +
4058 + } // end stop valueLookup
4059 +
4060 +
4061 +
4062 +
4063 +
4064 + // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
4065 + // Return true iff no other tracks are found in this cone.
4066 + int
4067 + OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
4068 +  for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
4069 +    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
4070 +    double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
4071 +    if(deltaRtrk < 0.5) return 0;
4072 +  }
4073 +  return 1;
4074 +
4075 + }
4076 +
4077 + //calculate the scalar sum of Jet Pt in the event.
4078 + double
4079 + OSUAnalysis::getHt (const BNjetCollection* jetColl){
4080 +  double Ht = 0;
4081 +  for(BNjetCollection::const_iterator jet = jetColl->begin(); jet !=jetColl->end(); jet++){
4082 +    Ht += abs(jet->pt);
4083 +  }
4084 +  return Ht;
4085 + }
4086 +
4087 + double
4088 + OSUAnalysis::getTrkPtRes (const BNtrack* track1){
4089 +
4090 +  double ptTrue = getTrkPtTrue(track1, mcparticles.product());
4091 +  double PtRes = (track1->pt - ptTrue) / ptTrue;
4092 +
4093 +  return PtRes;
4094 +
4095 + }
4096 +
4097 +
4098 + double
4099 + OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
4100 +  double value = -99;
4101 +  double genDeltaRLowest = 999;
4102 +
4103 +  for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
4104 +    double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
4105 +    if (genDeltaRtemp < genDeltaRLowest) {
4106 +      genDeltaRLowest = genDeltaRtemp;
4107 +      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
4108 +        double ptTrue = genPart->pt;
4109 +        value = ptTrue;
4110 +      }
4111 +    }
4112 +  }
4113 +
4114 +  return value;
4115 +
4116 + }
4117 +
4118 + double
4119 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
4120 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
4121 +  if (!useTrackCaloRhoCorr_) return -99;
4122 +  // if (!rhokt6CaloJetsHandle_) {
4123 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
4124 +  //   return -99;
4125 +  // }
4126 +  double radDeltaRCone = 0.5;
4127 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
4128 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
4129 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
4130 +  return caloTotRhoCorrCalo;
4131 +
4132 + }
4133 +
4134 +
4135 +
4136 +
4137 + //creates a map of the dead Ecal channels in the barrel and endcap
4138 + //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
4139 + //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
4140 + void
4141 + OSUAnalysis::WriteDeadEcal (){
4142 +  double etaEcal, phiEcal;
4143 +  ifstream DeadEcalFile(deadEcalFile_);
4144 +  if(!DeadEcalFile) {
4145 +    clog << "Error: DeadEcalFile has not been found." << endl;
4146 +    return;
4147 +  }
4148 +  if(DeadEcalVec.size()!= 0){
4149 +    clog << "Error: DeadEcalVec has a nonzero size" << endl;
4150 +    return;
4151 +  }
4152 +  while(!DeadEcalFile.eof())
4153 +    {
4154 +      DeadEcalFile >> etaEcal >> phiEcal;
4155 +      DeadEcal newChan;
4156 +      newChan.etaEcal = etaEcal;
4157 +      newChan.phiEcal = phiEcal;
4158 +      DeadEcalVec.push_back(newChan);
4159 +    }
4160 +  if(DeadEcalVec.size() == 0) clog << "Warning: No dead Ecal channels have been found." << endl;
4161 + }
4162 +
4163 + //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
4164 + int
4165 + OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
4166 +  double deltaRLowest = 999;
4167 +  int value = 0;
4168 +  if (DeadEcalVec.size() == 0) WriteDeadEcal();
4169 +  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4170 +    double eta = ecal->etaEcal;
4171 +    double phi = ecal->phiEcal;
4172 +    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
4173 +    if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
4174 +  }
4175 +  if (deltaRLowest<0.05) {value = 1;}
4176 +  else {value = 0;}
4177 +  return value;
4178 + }
4179 +
4180 + // Returns the smallest DeltaR between the object and any generated true particle in the event.
4181 + template <class InputObject>
4182 + double OSUAnalysis::getGenDeltaRLowest(InputObject object){
4183 +  double genDeltaRLowest = 999.;
4184 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4185 +    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
4186 +    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
4187 +  }
4188 +  return genDeltaRLowest;
4189 + }
4190  
4191   double
4192   OSUAnalysis::applyFunction(string function, double value){
4193  
4194 <  if(function == "abs") value = abs(value);
4194 >  if(function == "abs") value = fabs(value);
4195 >  else if(function == "fabs") value = fabs(value);
4196 >  else if(function == "log10") value = log10(value);
4197 >  else if(function == "log") value = log10(value);
4198  
4199 +  else if(function == "") value = value;
4200 +  else{clog << "WARNING: invalid function '" << function << "'\n";}
4201  
4202    return value;
4203  
# Line 1446 | Line 4207 | OSUAnalysis::applyFunction(string functi
4207   template <class InputCollection>
4208   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
4209  
4210 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
4211 +    string obj1, obj2;
4212 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
4213 +    if (inputType==obj1 ||
4214 +        inputType==obj2) {
4215 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
4216 +      // and the inputType is a member of the pair.
4217 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
4218 +      // For example, if currentCut.inputCollection==electron-muon pairs,
4219 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
4220 +      return;
4221 +    }
4222 +  }
4223  
4224    for (uint object = 0; object != inputCollection->size(); object++){
4225  
4226 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
4226 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4227 >    bool plotDecision = true;
4228  
4229      if(currentCut.inputCollection == inputType){
4230  
4231 <      double value = valueLookup(&inputCollection->at(object), currentCut.variable, currentCut.function);
4231 >      vector<bool> subcutDecisions;
4232 >      for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4233 >        string stringValue = "";
4234 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4235 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4236 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4237  
4238 <      decision = evaluateComparison(value,currentCut.comparativeOperator,currentCut.cutValue);
4238 >      }
4239 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4240 >      else{
4241 >        bool tempDecision = true;
4242 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4243 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4244 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4245 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4246 >            tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4247 >        }
4248 >        cutDecision = tempDecision;
4249 >      }
4250 >      //invert the cut for plotting if this cut is a veto
4251 >      if(currentCut.isVeto) plotDecision = !cutDecision;
4252 >      else plotDecision = cutDecision;
4253      }
1460    individualFlags[inputType].at(currentCutIndex).push_back(decision);
4254  
4255 +    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4256  
4257 <    //set flags for objects that pass each cut AND all the previous cuts
4258 <    bool previousCumulativeFlag = true;
4257 >    //set flags for objects that pass this cut AND all the previous cuts
4258 >    bool previousCumulativeCutFlag = true;
4259      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4260 <      if(previousCumulativeFlag && individualFlags[inputType].at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4261 <      else{ previousCumulativeFlag = false; break;}
4260 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4261 >      else{ previousCumulativeCutFlag = false; break;}
4262      }
4263 <    cumulativeFlags[inputType].at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4263 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4264 >    bool previousCumulativePlotFlag = true;
4265 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4266 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4267 >      else{ previousCumulativePlotFlag = false; break;}
4268 >    }
4269 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4270 >
4271 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4272  
4273    }
4274  
4275   }
4276  
4277  
4278 + template <class InputCollection1, class InputCollection2>
4279 + void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
4280 +                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, string inputType){
4281 +
4282 +
4283 +  bool sameObjects = false;
4284 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4285 +
4286 +  // Get the strings for the two objects that make up the pair.
4287 +  string obj1Type, obj2Type;
4288 +  getTwoObjs(inputType, obj1Type, obj2Type);
4289 +  bool isTwoTypesOfObject = true;
4290 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
4291 +
4292 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
4293 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4294 +  if (currentCut.inputCollection == inputType) {
4295 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4296 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4297 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4298 +    }
4299 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4300 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4301 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4302 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4303 +      }
4304 +    }
4305 +  }
4306  
4307 +  int counter = 0;
4308  
4309 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4310 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4311  
4312 < DEFINE_FWK_MODULE(OSUAnalysis);
4312 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4313 >
4314 >
4315 >      bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4316 >      bool plotDecision = true;
4317 >
4318 >      if(currentCut.inputCollection == inputType){
4319 >
4320 >        vector<bool> subcutDecisions;
4321 >        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4322 >          string stringValue = "";
4323 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4324 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4325 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4326 >        }
4327 >
4328 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4329 >        else{
4330 >          bool tempDecision = subcutDecisions.at(0);
4331 >          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
4332 >            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
4333 >              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
4334 >            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4335 >              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4336 >          }
4337 >          cutDecision = tempDecision;
4338 >        }
4339 >        //invert the cut for plotting if this cut is a veto
4340 >        if(currentCut.isVeto) plotDecision = !cutDecision;
4341 >        else plotDecision = cutDecision;
4342 >      }
4343 >      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4344 >      if (cutDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4345 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4346 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4347 >      }
4348 >      if (plotDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4349 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4350 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4351 >      }
4352 >
4353 >      //set flags for objects that pass this cut AND all the previous cuts
4354 >      bool previousCumulativeCutFlag = true;
4355 >      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4356 >        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4357 >        else{ previousCumulativeCutFlag = false; break;}
4358 >      }
4359 >      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4360 >
4361 >      bool previousCumulativePlotFlag = true;
4362 >      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4363 >        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4364 >        else{ previousCumulativePlotFlag = false; break;}
4365 >      }
4366 >      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4367 >      
4368 >      //apply flags for the components of the composite object as well
4369 >      bool currentCumulativeCutFlag = true;
4370 >      bool currentCumulativePlotFlag = true;
4371 >
4372 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4373 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4374 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4375 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4376 >
4377 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4378 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4379 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4380 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4381 >
4382 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));
4383 >
4384 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4385 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4386 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4387 >      }
4388 >
4389 >      if (currentCumulativePlotFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4390 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4391 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4392 >      }
4393 >
4394 >      counter++;
4395 >
4396 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4397 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4398 >
4399 > }
4400 >
4401 >
4402 > bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4403 >  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4404 >  // all cuts up to currentCutIndex
4405 >  bool previousCumulativeFlag = true;
4406 >  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4407 >    bool tempFlag = false;
4408 >    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4409 >    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4410 >
4411 >    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4412 >    else {
4413 >      previousCumulativeFlag = false; break;
4414 >    }
4415 >  }
4416 >  return previousCumulativeFlag;
4417 > }
4418 >
4419 >
4420 >
4421 >
4422 > template <class InputCollection>
4423 > void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4424 >  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4425 >
4426 >  if (BNTreeBranchVals_.count(parameters.name)==0) clog << "Error[assignTreeBranch]:  trying to assign value to " << parameters.name << " that does not have a branch set up.  Will likely seg fault." << endl;
4427 >  for (uint object = 0; object != inputCollection->size(); object++) {
4428 >
4429 >    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4430 >
4431 >    string inputVariable = parameters.inputVariable;
4432 >    string function = "";
4433 >    string stringValue = "";
4434 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4435 >    BNTreeBranchVals_.at(parameters.name).push_back(value);
4436 >
4437 >  }
4438 > }
4439 >
4440 >
4441 > template <class InputCollection>
4442 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4443 >
4444 >
4445 >  for (uint object = 0; object != inputCollection->size(); object++){
4446 >
4447 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4448 >
4449 >    string currentString = parameters.inputVariables.at(0);
4450 >    string inputVariable = "";
4451 >    string function = "";
4452 >    if(currentString.find("(")==string::npos){
4453 >      inputVariable = currentString;// variable to cut on
4454 >    }
4455 >    else{
4456 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4457 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4458 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4459 >    }
4460 >
4461 >    string stringValue = "";
4462 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4463 >    histo->Fill(value,scaleFactor);
4464 >
4465 >    if (printEventInfo_) {
4466 >      // Write information about event to screen, for testing purposes.
4467 >      clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
4468 >    }
4469 >
4470 >  }
4471 > }
4472 >
4473 > template <class InputCollection1, class InputCollection2>
4474 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4475 >
4476 >  bool sameObjects = false;
4477 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4478 >
4479 >  int pairCounter = -1;
4480 >  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4481 >    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4482 >
4483 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4484 >
4485 >      pairCounter++;
4486 >      //only take objects which have passed all cuts and pairs which have passed all cuts
4487 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4488 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4489 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4490 >
4491 >      string currentString = parameters.inputVariables.at(0);
4492 >      string inputVariable = "";
4493 >      string function = "";
4494 >      if(currentString.find("(")==string::npos){
4495 >        inputVariable = currentString;// variable to cut on
4496 >      }
4497 >      else{
4498 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4499 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4500 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4501 >      }
4502 >
4503 >      string stringValue = "";
4504 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4505 >      histo->Fill(value,scaleFactor);
4506 >
4507 >    }
4508 >  }
4509 >
4510 > }
4511 >
4512 >
4513 > template <class InputCollection>
4514 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4515 >
4516 >  for (uint object = 0; object != inputCollection->size(); object++){
4517 >
4518 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4519 >
4520 >    string stringValue = "";
4521 >    string currentString = parameters.inputVariables.at(0);
4522 >    string inputVariable = "";
4523 >    string function = "";
4524 >    if(currentString.find("(")==string::npos){
4525 >      inputVariable = currentString;// variable to cut on
4526 >    }
4527 >    else{
4528 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4529 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4530 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4531 >    }
4532 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4533 >
4534 >    currentString = parameters.inputVariables.at(1);
4535 >    inputVariable = "";
4536 >    function = "";
4537 >    if(currentString.find("(")==string::npos){
4538 >      inputVariable = currentString;// variable to cut on
4539 >    }
4540 >    else{
4541 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4542 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4543 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4544 >    }
4545  
4546 +    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4547  
4548 +    histo->Fill(valueX,valueY,scaleFactor);
4549 +
4550 +  }
4551 +
4552 + }
4553 +
4554 + template <class InputCollection1, class InputCollection2>
4555 + void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4556 +
4557 +  bool sameObjects = false;
4558 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4559 +
4560 +  int pairCounter = -1;
4561 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4562 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4563 +
4564 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4565 +
4566 +      pairCounter++;
4567 +
4568 +      //only take objects which have passed all cuts and pairs which have passed all cuts
4569 +      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4570 +      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4571 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4572 +
4573 +      string stringValue = "";
4574 +      string currentString = parameters.inputVariables.at(0);
4575 +      string inputVariable = "";
4576 +      string function = "";
4577 +      if(currentString.find("(")==string::npos){
4578 +        inputVariable = currentString;// variable to cut on
4579 +      }
4580 +      else{
4581 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4582 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4583 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4584 +      }
4585 +      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4586 +
4587 +      currentString = parameters.inputVariables.at(1);
4588 +      inputVariable = "";
4589 +      function = "";
4590 +      if(currentString.find("(")==string::npos){
4591 +        inputVariable = currentString;// variable to cut on
4592 +      }
4593 +      else{
4594 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4595 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4596 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4597 +      }
4598 +      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4599 +
4600 +
4601 +      histo->Fill(valueX,valueY,scaleFactor);
4602 +
4603 +    }
4604 +  }
4605 +
4606 + }
4607 +
4608 +
4609 + template <class InputObject>
4610 + int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
4611 +
4612 +  int bestMatchIndex = -1;
4613 +  double bestMatchDeltaR = 999;
4614 +
4615 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4616 +
4617 +    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4618 +    if(currentDeltaR > 0.05) continue;
4619 +    //     clog << setprecision(3) << setw(20)
4620 +    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4621 +    //          << setw(20)
4622 +    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4623 +    //          << setw(20)
4624 +    //          << "\tdeltaR = " << currentDeltaR
4625 +    //          << setprecision(1)
4626 +    //          << setw(20)
4627 +    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4628 +    //          << setw(20)
4629 +    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4630 +    //          << setw(20)
4631 +    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4632 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4633 +      bestMatchIndex = mcparticle - mcparticles->begin();
4634 +      bestMatchDeltaR = currentDeltaR;
4635 +    }
4636 +
4637 +  }
4638 +  //   if(bestMatchDeltaR != 999)  clog << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4639 +  //   else clog << "no match found..." << endl;
4640 +  return bestMatchIndex;
4641 +
4642 + }
4643 +
4644 +
4645 + int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
4646 +
4647 +  int bestMatchIndex = -1;
4648 +  double bestMatchDeltaR = 999;
4649 +
4650 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4651 +
4652 +    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
4653 +
4654 +    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
4655 +    if(currentDeltaR > 0.05) continue;
4656 +
4657 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4658 +      bestMatchIndex = mcparticle - mcparticles->begin();
4659 +      bestMatchDeltaR = currentDeltaR;
4660 +    }
4661 +
4662 +  }
4663 +
4664 +  return bestMatchIndex;
4665 + }
4666 +
4667 +
4668 + // bin      particle type
4669 + // ---      -------------
4670 + //  0        unmatched
4671 + //  1        u
4672 + //  2        d
4673 + //  3        s
4674 + //  4        c
4675 + //  5        b
4676 + //  6        t
4677 + //  7        e
4678 + //  8        mu
4679 + //  9        tau
4680 + // 10        nu
4681 + // 11        g
4682 + // 12        gamma
4683 + // 13        Z
4684 + // 14        W
4685 + // 15        light meson
4686 + // 16        K meson
4687 + // 17        D meson
4688 + // 18        B meson
4689 + // 19        light baryon
4690 + // 20        strange baryon
4691 + // 21        charm baryon
4692 + // 22        bottom baryon
4693 + // 23        QCD string
4694 + // 24        other
4695 +
4696 + int OSUAnalysis::getPdgIdBinValue(int pdgId){
4697 +
4698 +  int binValue = -999;
4699 +  int absPdgId = fabs(pdgId);
4700 +  if(pdgId == -1) binValue = 0;
4701 +  else if(absPdgId <= 6 ) binValue = absPdgId;
4702 +  else if(absPdgId == 11 ) binValue = 7;
4703 +  else if(absPdgId == 13 ) binValue = 8;
4704 +  else if(absPdgId == 15 ) binValue = 9;
4705 +  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
4706 +  else if(absPdgId == 21 ) binValue = 11;
4707 +  else if(absPdgId == 22 ) binValue = 12;
4708 +  else if(absPdgId == 23 ) binValue = 13;
4709 +  else if(absPdgId == 24 ) binValue = 14;
4710 +  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
4711 +  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
4712 +  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
4713 +  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
4714 +  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
4715 +  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4716 +  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4717 +  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4718 +  else if(absPdgId == 92  ) binValue = 23;
4719 +
4720 +  else binValue = 24;
4721 +
4722 +  return binValue;
4723 +
4724 + }
4725 +
4726 + const BNprimaryvertex *
4727 + OSUAnalysis::chosenVertex ()
4728 + {
4729 +  const BNprimaryvertex *chosenVertex = 0;
4730 +  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4731 +    flagPair vertexFlags;
4732 +    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4733 +      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4734 +        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4735 +        break;
4736 +      }
4737 +    }
4738 +    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4739 +      if(!vertexFlags.at(vertexIndex).first) continue;
4740 +      chosenVertex = & primaryvertexs->at(vertexIndex);
4741 +      break;
4742 +    }
4743 +  }
4744 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4745 +    chosenVertex = & primaryvertexs->at (0);
4746 +
4747 +  return chosenVertex;
4748 + }
4749 +
4750 + const BNmet *
4751 + OSUAnalysis::chosenMET ()
4752 + {
4753 +  const BNmet *chosenMET = 0;
4754 +  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4755 +    flagPair metFlags;
4756 +    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4757 +      if (cumulativeFlags.at("mets").at(i).size()){
4758 +        metFlags = cumulativeFlags.at("mets").at(i);
4759 +        break;
4760 +      }
4761 +    }
4762 +    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4763 +      if(!metFlags.at(metIndex).first) continue;
4764 +      chosenMET = & mets->at(metIndex);
4765 +      break;
4766 +    }
4767 +  }
4768 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4769 +    chosenMET = & mets->at (0);
4770 +
4771 +  return chosenMET;
4772 + }
4773 +
4774 + const BNelectron *
4775 + OSUAnalysis::chosenElectron ()
4776 + {
4777 +  const BNelectron *chosenElectron = 0;
4778 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4779 +    flagPair electronFlags;
4780 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4781 +      if (cumulativeFlags.at("electrons").at(i).size()){
4782 +        electronFlags = cumulativeFlags.at("electrons").at(i);
4783 +        break;
4784 +      }
4785 +    }
4786 +    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4787 +      if(!electronFlags.at(electronIndex).first) continue;
4788 +      chosenElectron = & electrons->at(electronIndex);
4789 +      break;
4790 +    }
4791 +  }
4792 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4793 +    chosenElectron = & electrons->at (0);
4794 +
4795 +  return chosenElectron;
4796 + }
4797 +
4798 +
4799 + const BNmuon *
4800 + OSUAnalysis::chosenMuon ()
4801 + {
4802 +  const BNmuon *chosenMuon = 0;
4803 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4804 +    flagPair muonFlags;
4805 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4806 +      if (cumulativeFlags.at("muons").at(i).size()){
4807 +        muonFlags = cumulativeFlags.at("muons").at(i);
4808 +        break;
4809 +      }
4810 +    }
4811 +    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4812 +      if(!muonFlags.at(muonIndex).first) continue;
4813 +      chosenMuon = & muons->at(muonIndex);
4814 +      break;
4815 +    }
4816 +  }
4817 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4818 +    chosenMuon = & muons->at (0);
4819 +
4820 +  return chosenMuon;
4821 + }
4822 +
4823 + double
4824 + OSUAnalysis::chosenHT ()
4825 + {
4826 +  double chosenHT = 0.0;
4827 +  if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
4828 +    flagPair jetFlags;
4829 +    for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
4830 +      if (cumulativeFlags.at("jets").at(i).size()){
4831 +        jetFlags = cumulativeFlags.at("jets").at(i);
4832 +        break;
4833 +      }
4834 +    }
4835 +    for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
4836 +      if(!jetFlags.at(jetIndex).first) continue;
4837 +      chosenHT += jets->at(jetIndex).pt;
4838 +    }
4839 +  }
4840 +
4841 +  return chosenHT;
4842 + }
4843 +
4844 + pair<const BNmuon *, const BNmuon *>
4845 + OSUAnalysis::leadMuonPair ()
4846 + {
4847 +  pair<const BNmuon *, const BNmuon *> leadMuonPair;
4848 +  leadMuonPair.first = leadMuonPair.second = 0;
4849 +
4850 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4851 +    flagPair muonFlags;
4852 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4853 +      if (cumulativeFlags.at("muons").at(i).size()){
4854 +        muonFlags = cumulativeFlags.at("muons").at(i);
4855 +        break;
4856 +      }
4857 +    }
4858 +    for (uint muonIndex0 = 0; muonIndex0 != muonFlags.size(); muonIndex0++){
4859 +      if(!muonFlags.at(muonIndex0).first) continue;
4860 +      for (uint muonIndex1 = muonIndex0 + 1; muonIndex1 < muonFlags.size(); muonIndex1++){
4861 +        if(!muonFlags.at(muonIndex1).first) continue;
4862 +        const BNmuon *mu0 = & muons->at(muonIndex0);
4863 +        const BNmuon *mu1 = & muons->at(muonIndex1);
4864 +        if(leadMuonPair.first == 0 || leadMuonPair.second == 0){
4865 +          leadMuonPair.first = mu0;
4866 +          leadMuonPair.second = mu1;
4867 +        }
4868 +        else{
4869 +          TVector2 newPt0 (mu0->px, mu0->py),
4870 +                   newPt1 (mu1->px, mu1->py),
4871 +                   oldPt0 (leadMuonPair.first->px, leadMuonPair.first->py),
4872 +                   oldPt1 (leadMuonPair.second->px, leadMuonPair.second->py);
4873 +          newPt0 += newPt1;
4874 +          oldPt0 += oldPt1;
4875 +          if(newPt0.Mod() > oldPt0.Mod())
4876 +            {
4877 +              leadMuonPair.first = mu0;
4878 +              leadMuonPair.second = mu1;
4879 +            }
4880 +        }
4881 +      }
4882 +    }
4883 +  }
4884 +
4885 +  return leadMuonPair;
4886 + }
4887 +
4888 + pair<const BNelectron *, const BNelectron *>
4889 + OSUAnalysis::leadElectronPair ()
4890 + {
4891 +  pair<const BNelectron *, const BNelectron *> leadElectronPair;
4892 +  leadElectronPair.first = leadElectronPair.second = 0;
4893 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4894 +    flagPair electronFlags;
4895 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4896 +      if (cumulativeFlags.at("electrons").at(i).size()){
4897 +        electronFlags = cumulativeFlags.at("electrons").at(i);
4898 +        break;
4899 +      }
4900 +    }
4901 +    for (uint electronIndex0 = 0; electronIndex0 != electronFlags.size(); electronIndex0++){
4902 +      if(!electronFlags.at(electronIndex0).first) continue;
4903 +      for (uint electronIndex1 = electronIndex0 + 1; electronIndex1 < electronFlags.size(); electronIndex1++){
4904 +        if(!electronFlags.at(electronIndex1).first) continue;
4905 +        const BNelectron *el0 = & electrons->at(electronIndex0);
4906 +        const BNelectron *el1 = & electrons->at(electronIndex1);
4907 +        if(leadElectronPair.first == 0 || leadElectronPair.second == 0){
4908 +          leadElectronPair.first = el0;
4909 +          leadElectronPair.second = el1;
4910 +        }
4911 +        else{
4912 +          TVector2 newPt0 (el0->px, el0->py),
4913 +                   newPt1 (el1->px, el1->py),
4914 +                   oldPt0 (leadElectronPair.first->px, leadElectronPair.first->py),
4915 +                   oldPt1 (leadElectronPair.second->px, leadElectronPair.second->py);
4916 +          newPt0 += newPt1;
4917 +          oldPt0 += oldPt1;
4918 +          if(newPt0.Mod() > oldPt0.Mod())
4919 +            {
4920 +              leadElectronPair.first = el0;
4921 +              leadElectronPair.second = el1;
4922 +            }
4923 +        }
4924 +      }
4925 +    }
4926 +  }
4927 +
4928 +  return leadElectronPair;
4929 + }
4930 +
4931 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines