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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines