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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines