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.12 by ahart, Fri Feb 8 11:07:51 2013 UTC vs.
Revision 1.123 by wulsin, Mon Aug 12 21:03:10 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")),
5    muons_ (cfg.getParameter<edm::InputTag> ("muons")),
6 +  secMuons_ (cfg.getParameter<edm::InputTag> ("secMuons")),
7    electrons_ (cfg.getParameter<edm::InputTag> ("electrons")),
8    events_ (cfg.getParameter<edm::InputTag> ("events")),
9    taus_ (cfg.getParameter<edm::InputTag> ("taus")),
# Line 11 | Line 11 | OSUAnalysis::OSUAnalysis (const edm::Par
11    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
12    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
13    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
14 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
15    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
16    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
17    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
18    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
19    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
20 <
21 <
20 >  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
21 >  puFile_ (cfg.getParameter<string> ("puFile")),
22 >  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
23 >  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
24 >  dataPU_ (cfg.getParameter<string> ("dataPU")),
25 >  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
26 >  muonSF_ (cfg.getParameter<string> ("muonSF")),
27 >  dataset_ (cfg.getParameter<string> ("dataset")),
28 >  datasetType_ (cfg.getParameter<string> ("datasetType")),
29    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
30 +  histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
31 +  useEDMFormat_   (cfg.getParameter<bool>("useEDMFormat")),
32 +  treeBranchSets_   (cfg.getParameter<vector<edm::ParameterSet> >("treeBranchSets")),
33 +  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
34 +  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
35 +  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
36 +  applyBtagSF_ (cfg.getParameter<bool> ("applyBtagSF")),
37 +  minBtag_ (cfg.getParameter<int> ("minBtag")),
38 +  printEventInfo_      (cfg.getParameter<bool> ("printEventInfo")),
39 +  printAllTriggers_    (cfg.getParameter<bool> ("printAllTriggers")),
40 +  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
41 +  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
42 +  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut")),
43 +  verbose_ (cfg.getParameter<int> ("verbose"))
44 + {
45 +
46 +  if (verbose_) printEventInfo_ = true;  
47 +  if (verbose_) clog << "Beginning OSUAnalysis::OSUAnalysis constructor." << endl;  
48 +
49 +  TH1::SetDefaultSumw2();
50 +
51 +  //create pile-up reweighting object, if necessary
52 +  if(datasetType_ != "data") {
53 +    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
54 +    if (applyLeptonSF_){
55 +      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
56 +      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
57 +    }
58 +    if (applyBtagSF_){
59 +      bTagSFWeight_ = new BtagSFWeight;
60 +    }
61 +  }
62 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
63 +    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at(0), stopCTau_.at(1), stops_);
64  
23  histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets"))
24
25 {
26
27
28  TH1::SetDefaultSumw2 ();
29  TH2::SetDefaultSumw2 ();
65  
66    // Construct Cutflow Objects. These store the results of cut decisions and
67    // handle filling cut flow histograms.
68    masterCutFlow_ = new CutFlow (fs_);
34  std::vector<TFileDirectory> directories;
69  
70    //always get vertex collection so we can assign the primary vertex in the event
71 <  allNecessaryObjects.push_back("primaryvertexs");
71 >  objectsToGet.push_back("primaryvertexs");
72 >  objectsToPlot.push_back("primaryvertexs");
73 >  objectsToFlag.push_back("primaryvertexs");
74 >
75 >
76 >  //always get the MC particles to do GEN-matching
77 >  objectsToGet.push_back("mcparticles");
78 >
79 >  //always get the event collection to do pile-up reweighting
80 >  objectsToGet.push_back("events");
81 >
82 >
83 >  // Parse the tree variable definitions.
84 >  for (uint iBranchSet = 0; !useEDMFormat_ && iBranchSet<treeBranchSets_.size(); iBranchSet++) {
85 >    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
86 >    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; }
87 >    objectsToGet.push_back(tempInputCollection);
88 >    objectsToFlag.push_back(tempInputCollection);
89 >
90 >    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
91 >
92 >    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
93 >      BranchSpecs br;
94 >      br.inputCollection = tempInputCollection;
95 >      br.inputVariable = branchList.at(iBranch);
96 >      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);
97 >      br.name = string(newName.Data());
98 >      treeBranches_.push_back(br);
99 >      if (verbose_>3) clog << "   Adding branch to BNTree: " << br.name << endl;  
100 >    }
101 >
102 >  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++)
103  
104  
105    //parse the histogram definitions
106    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
107  
108 <    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string>("inputCollection");
109 <    objectsToPlot.push_back(tempInputCollection);
110 <    allNecessaryObjects.push_back(tempInputCollection);
111 <    vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
108 >    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
109 >    if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
110 >    if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
111 >    if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
112 >    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
113 >    if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
114 >    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
115 >    if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
116 >    if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
117 >    if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
118 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
119 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
120 >    if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
121 >    if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
122 >    if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
123 >    if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
124 >    if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
125 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
126 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
127 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
128 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
129 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
130 >        if(tempInputCollection.find("secondary muons")!=string::npos){//treat secondary muons differently; allow for a different input collection
131 >          objectsToGet.push_back("secondary muons");  
132 >        } else {
133 >          int spaceIndex = tempInputCollection.find(" ");
134 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
135 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
136 >        }
137 >      } else{
138 >        objectsToGet.push_back(tempInputCollection);
139 >      }
140 >      objectsToPlot.push_back(tempInputCollection);
141 >      objectsToFlag.push_back(tempInputCollection);
142 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
143 >      string obj1;
144 >      string obj2;
145 >      getTwoObjs(tempInputCollection, obj1, obj2);
146 >      string obj2ToGet = getObjToGet(obj2);
147 >      objectsToFlag.push_back(tempInputCollection);
148 >      objectsToFlag.push_back(obj1);
149 >      objectsToFlag.push_back(obj2);
150 >      objectsToPlot.push_back(tempInputCollection);
151 >      objectsToPlot.push_back(obj1);
152 >      objectsToPlot.push_back(obj2);
153 >      objectsToGet.push_back(tempInputCollection);
154 >      objectsToGet.push_back(obj1);
155 >      objectsToGet.push_back(obj2ToGet);
156 >    } // end else
157 >    if (find(objectsToPlot.begin(), objectsToPlot.end(), "events") != objectsToPlot.end())
158 >      objectsToGet.push_back("jets");
159      
160 +    
161 +    vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
162 +
163      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
164  
165 +      vector<double> defaultValue;
166 +      defaultValue.push_back (-1.0);
167 +
168        histogram tempHistogram;
169        tempHistogram.inputCollection = tempInputCollection;
170        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
171        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
172 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
172 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
173 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
174 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
175        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
176 <      if(histogramList_.at(currentHistogram).exists("function"))
177 <        tempHistogram.function = histogramList_.at(currentHistogram).getParameter<string>("function");
178 <      else
179 <        tempHistogram.function = "";
180 <      
181 <      histograms.push_back(tempHistogram);
176 >
177 >      bool histExists = false;
178 >      for (uint i=0; i<histograms.size(); i++) {
179 >        if (histograms.at(i).name == tempHistogram.name) { histExists = true; break; }
180 >      }  
181 >      if (histExists) {
182 >        clog << "Warning:  histogram " << tempHistogram.name << " already exists; will not book an additional instance." << endl;  
183 >      } else {
184 >        histograms.push_back(tempHistogram);
185 >      }
186  
187      }
188 <  }
188 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
189  
190 +  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
191 +  sort( objectsToPlot.begin(), objectsToPlot.end() );
192 +  objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
193 +
194 +
195 +
196 +  //add histograms with the gen-matched id, mother id, and grandmother id
197 +  for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
198 +
199 +    string currentObject = objectsToPlot.at(currentObjectIndex);
200 +    if(currentObject != "muons" &&
201 +       currentObject != "secondary muons" &&
202 +       currentObject != "secondary electrons" &&
203 +       currentObject != "electrons" &&
204 +       currentObject != "taus" &&
205 +       currentObject != "tracks" &&
206 +       currentObject != "photons" &&
207 +       currentObject != "secondary photons"&&
208 +       currentObject != "superclusters")
209 +      continue;
210 +
211 +    histogram tempIdHisto;
212 +    histogram tempMomIdHisto;
213 +    histogram tempGmaIdHisto;
214 +    histogram tempIdVsMomIdHisto;
215 +    histogram tempIdVsGmaIdHisto;
216 +
217 +    tempIdHisto.inputCollection = currentObject;
218 +    tempMomIdHisto.inputCollection = currentObject;
219 +    tempGmaIdHisto.inputCollection = currentObject;
220 +    tempIdVsMomIdHisto.inputCollection = currentObject;
221 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
222 +
223 +    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
224 +    if(currentObject == "secondary photons") currentObject = "secondaryPhotons";
225 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
226 +
227 +    currentObject = currentObject.substr(0, currentObject.size()-1);
228 +    tempIdHisto.name = currentObject+"GenMatchId";
229 +    tempMomIdHisto.name = currentObject+"GenMatchMotherId";
230 +    tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
231 +    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
232 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
233 +
234 +    currentObject.at(0) = toupper(currentObject.at(0));
235 +    tempIdHisto.title = currentObject+" Gen-matched Particle";
236 +    tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
237 +    tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
238 +    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
239 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
240 +
241 +
242 +    int maxNum = 25;
243 +    vector<double> binVector;
244 +    binVector.push_back(maxNum);
245 +    binVector.push_back(0);
246 +    binVector.push_back(maxNum);
247 +
248 +    tempIdHisto.bins = binVector;
249 +    tempIdHisto.inputVariables.push_back("genMatchedId");
250 +    tempMomIdHisto.bins = binVector;
251 +    tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
252 +    tempGmaIdHisto.bins = binVector;
253 +    tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
254 +    binVector.push_back(maxNum);
255 +    binVector.push_back(0);
256 +    binVector.push_back(maxNum);
257 +    tempIdVsMomIdHisto.bins = binVector;
258 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
259 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
260 +    tempIdVsGmaIdHisto.bins = binVector;
261 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
262 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
263 +
264 +    histograms.push_back(tempIdHisto);
265 +    histograms.push_back(tempMomIdHisto);
266 +    histograms.push_back(tempGmaIdHisto);
267 +    histograms.push_back(tempIdVsMomIdHisto);
268 +    histograms.push_back(tempIdVsGmaIdHisto);
269 +  }
270  
271  
272    channel tempChannel;
# Line 73 | Line 277 | OSUAnalysis::OSUAnalysis (const edm::Par
277      string channelName  (channels_.at(currentChannel).getParameter<string>("name"));
278      tempChannel.name = channelName;
279      TString channelLabel = channelName;
280 +    if (verbose_) clog << "Processing channel:  " << channelName << endl;  
281  
282      //set triggers for this channel
283      vector<string> triggerNames;
284      triggerNames.clear();
285 +    vector<string> triggerToVetoNames;
286 +    triggerToVetoNames.clear();
287 +
288      tempChannel.triggers.clear();
289 +    tempChannel.triggersToVeto.clear();
290      if(channels_.at(currentChannel).exists("triggers")){
291        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
292        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
293          tempChannel.triggers.push_back(triggerNames.at(trigger));
294 <      allNecessaryObjects.push_back("triggers");
294 >      objectsToGet.push_back("triggers");
295 >    }
296 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
297 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
298 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
299 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
300 >      objectsToGet.push_back("triggers");
301      }
302  
303  
304  
305      //create cutFlow for this channel
306      cutFlows_.push_back (new CutFlow (fs_, channelName));
307 <
308 <    //book a directory in the output file with the name of the channel
309 <    TFileDirectory subDir = fs_->mkdir( channelName );
95 <    directories.push_back(subDir);
96 <
97 <    std::map<std::string, TH1D*> oneDhistoMap;
98 <    oneDHists_.push_back(oneDhistoMap);
99 <    std::map<std::string, TH2D*> twoDhistoMap;
100 <    twoDHists_.push_back(twoDhistoMap);
101 <
102 <    //book all histograms included in the configuration
103 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
104 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
105 <      int numBinsElements = currentHistogram.bins.size();
106 <      int numInputVariables = currentHistogram.inputVariables.size();
107 <      if(numBinsElements != 3 && numBinsElements !=6) {
108 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
109 <        exit(0);
110 <      }
111 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
112 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
113 <        exit(0);
114 <      }
115 <      else if(numBinsElements == 3)
116 <        oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
117 <      else if(numBinsElements == 6)
118 <        twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).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));
119 <
120 <
121 <    }
122 <    //book a histogram for the number of each object type to be plotted
123 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
124 <      string currentObject = objectsToPlot.at(currentObjectIndex);
125 <      int maxNum = 10;
126 <      if(currentObject == "mcparticles") maxNum = 50;
127 <      currentObject[0] = toupper(currentObject[0]);
128 <      string histoName = "num" + currentObject;
129 <      oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
130 <    }
131 <
132 <
307 >    vector<TFileDirectory> directories; //vector of directories in the output file.
308 >    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
309 >    vector<string> subSubDirNames;//subdirectories in each channel.
310      //get list of cuts for this channel
311      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
312  
313 +
314      //loop over and parse all cuts
315      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
138
316        cut tempCut;
317 <     //store input collection for cut
318 <      string inputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
319 <      tempCut.inputCollection = inputCollection;
320 <      allNecessaryObjects.push_back(inputCollection);
317 >      //store input collection for cut
318 >      string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
319 >      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
320 >      if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
321 >      if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
322 >      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
323 >      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
324 >      if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
325 >      if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
326 >      if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
327 >      if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
328 >      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
329 >      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
330 >      if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
331 >      if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
332 >      if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
333 >      if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
334 >      if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
335 >      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
336 >      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
337 >      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
338 >      tempCut.inputCollection = tempInputCollection;
339 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
340 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
341 >          if(tempInputCollection.find("secondary muons")!=string::npos){//treat secondary muons differently; allow for a different input collection
342 >            objectsToGet.push_back("secondary muons");  
343 >          } else {
344 >            int spaceIndex = tempInputCollection.find(" ");
345 >            int secondWordLength = tempInputCollection.size() - spaceIndex;
346 >            objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
347 >          }
348 >        }
349 >        else{
350 >          objectsToGet.push_back(tempInputCollection);
351 >        }
352 >        objectsToCut.push_back(tempInputCollection);
353 >        objectsToFlag.push_back(tempInputCollection);
354 >      }
355 >      else{//pair of objects, need to add them both to objectsToGet
356 >        string obj1;
357 >        string obj2;
358 >        getTwoObjs(tempInputCollection, obj1, obj2);
359 >        string obj2ToGet = getObjToGet(obj2);
360 >        objectsToCut.push_back(tempInputCollection);
361 >        objectsToCut.push_back(obj1);
362 >        objectsToCut.push_back(obj2);
363 >        objectsToFlag.push_back(tempInputCollection);
364 >        objectsToFlag.push_back(obj1);
365 >        objectsToFlag.push_back(obj2);
366 >        objectsToGet.push_back(tempInputCollection);
367 >        objectsToGet.push_back(obj1);
368 >        objectsToGet.push_back(obj2ToGet);
369 >
370 >      }
371 >
372 >
373  
374        //split cut string into parts and store them
375        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
376 <      std::vector<string> cutStringVector = splitString(cutString);
377 <      if(cutStringVector.size()!=3){
378 <        std::cout << "Error: Didn't find three elements in the following cut string: '" <<cutString << "'\n";
379 <        exit(0);
376 >      vector<string> cutStringVector = splitString(cutString);
377 >      if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
378 >        clog << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
379 >        exit(0);
380 >      }
381 >      tempCut.numSubcuts = (cutStringVector.size()+1)/4;
382 >      for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
383 >        int indexOffset = 4 * subcutIndex;
384 >        string currentVariableString = cutStringVector.at(indexOffset);
385 >        if(currentVariableString.find("(")==string::npos){
386 >          tempCut.functions.push_back("");//no function was specified
387 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
388 >        }
389 >        else{
390 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
391 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
392 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
393 >        }
394 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
395 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
396 >        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
397 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
398        }
152
153      tempCut.variable = cutStringVector.at(0);// variable to cut on
154      tempCut.comparativeOperator = cutStringVector.at(1);// comparison to make
155      tempCut.cutValue = atof(cutStringVector.at(2).c_str());// threshold value to pass cut
399  
400        //get number of objects required to pass cut for event to pass
401        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
402 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
402 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
403        if(numberRequiredVector.size()!=2){
404 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
404 >        clog << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
405          exit(0);
406        }
407  
165      // determine number required if comparison contains "="
408        int numberRequiredInt = atoi(numberRequiredVector.at(1).c_str());
167      if(numberRequiredVector.at(0) == ">") numberRequiredInt++;
168      else if(numberRequiredVector.at(0) == "<") numberRequiredInt--;
169
409        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
410        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
411  
412 <      if(cuts_.at(currentCut).exists("function")){
413 <        tempCut.function = cuts_.at(currentCut).getParameter<string> ("function");
175 <      }
176 <      else tempCut.function = "";
412 >      //Set up vectors to store the directories and subDirectories for each channel.
413 >      string subSubDirName;
414        string tempCutName;
415        if(cuts_.at(currentCut).exists("alias")){
416          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
417 +        subSubDirName = "After " + tempCutName + " Cut Applied";
418        }
419        else{
420          //construct string for cutflow table
421          bool plural = numberRequiredInt != 1;
422 <        string collectionString = plural ? inputCollection : inputCollection.substr(0, inputCollection.size()-1);
422 >        string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
423          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
424          tempCutName = cutName;
425 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
426        }
188      tempCut.name = tempCutName;
427  
428 +      tempCut.isVeto = false;
429 +      if(cuts_.at(currentCut).exists("isVeto")){
430 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
431 +        if (isVeto == true) tempCut.isVeto = true;
432 +      }
433 +      subSubDirNames.push_back(subSubDirName);
434 +      tempCut.name = tempCutName;
435 +      if (verbose_) clog << "Setting up cut, index: " << currentCut << ", input collection: " << tempInputCollection<< ", name: " << tempCut.name << endl;  
436  
437        tempChannel.cuts.push_back(tempCut);
438  
439  
194
440      }//end loop over cuts
441  
442 +    vector<map<string, TH1D*>> oneDHistsTmp;
443 +    vector<map<string, TH2D*>> twoDHistsTmp;
444 +    //book a directory in the output file with the name of the channel
445 +    TFileDirectory subDir = fs_->mkdir( channelName );
446 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
447 +    if(GetPlotsAfterEachCut_){
448 +      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
449 +        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
450 +        directories.push_back(subSubDir);
451 +        map<string, TH1D*> oneDhistoMap;
452 +        oneDHistsTmp.push_back(oneDhistoMap);
453 +        map<string, TH2D*> twoDhistoMap;
454 +        twoDHistsTmp.push_back(twoDhistoMap);
455 +      }
456 +      treeDirectories.push_back(subDir);
457 +      oneDHists_.push_back(oneDHistsTmp);
458 +      twoDHists_.push_back(twoDHistsTmp);
459 +    }
460 +    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
461 +    else{
462 +      map<string, TH1D*> oneDhistoMap;
463 +      oneDHistsTmp.push_back(oneDhistoMap);
464 +      map<string, TH2D*> twoDhistoMap;
465 +      twoDHistsTmp.push_back(twoDhistoMap);
466 +      oneDHists_.push_back(oneDHistsTmp);
467 +      twoDHists_.push_back(twoDHistsTmp);
468 +      directories.push_back(subDir);
469 +      treeDirectories.push_back(subDir);
470  
471 +    }
472 +
473 +    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
474 +      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
475 +      BNTrees_.push_back(newTree);
476 +      BNTrees_.back()->Branch("event_runInt",  &BNTreeBranchVals_runInt_,  "event_runInt/I");      
477 +      BNTrees_.back()->Branch("event_lumiInt", &BNTreeBranchVals_lumiInt_, "event_lumiInt/I");      
478 +      BNTrees_.back()->Branch("event_evtLong", &BNTreeBranchVals_evtLong_, "event_evtLong/L");      
479 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
480 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
481 +        vector<float> newVec;
482 +        BNTreeBranchVals_[currentVar.name] = newVec;
483 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
484 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
485 +    }
486 +
487 +    //book all histograms included in the configuration
488 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
489 +
490 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
491 +
492 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
493 +        int numBinsElements = currentHistogram.bins.size();
494 +        int numInputVariables = currentHistogram.inputVariables.size();
495 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
496 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
497 +
498 +        if(numBinsElements == 1){
499 +          if(numBinEdgesX > 1){
500 +            if(numBinEdgesY > 1)
501 +              numBinsElements = 6;
502 +            else
503 +              numBinsElements = 3;
504 +          }
505 +        }
506 +        if(numBinsElements != 3 && numBinsElements !=6){
507 +          clog << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
508 +          exit(0);
509 +        }
510 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
511 +          clog << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
512 +          exit(0);
513 +        }
514 +        else if(numBinsElements == 3){
515 +          if (currentHistogram.bins.size () == 3)
516 +            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));
517 +          else
518 +            {
519 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
520 +            }
521 +        }
522 +        else if(numBinsElements == 6){
523 +          if (currentHistogram.bins.size () == 6)
524 +            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));
525 +          else
526 +            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 ());
527 +        }
528 +
529 +
530 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
531 +
532 +        // bin      particle type
533 +        // ---      -------------
534 +        //  0        unmatched
535 +        //  1        u
536 +        //  2        d
537 +        //  3        s
538 +        //  4        c
539 +        //  5        b
540 +        //  6        t
541 +        //  7        e
542 +        //  8        mu
543 +        //  9        tau
544 +        // 10        nu
545 +        // 11        g
546 +        // 12        gamma
547 +        // 13        Z
548 +        // 14        W
549 +        // 15        light meson
550 +        // 16        K meson
551 +        // 17        D meson
552 +        // 18        B meson
553 +        // 19        light baryon
554 +        // 20        strange baryon
555 +        // 21        charm baryon
556 +        // 22        bottom baryon
557 +        // 23        QCD string
558 +        // 24        other
559 +
560 +        vector<TString> labelArray;
561 +        labelArray.push_back("unmatched");
562 +        labelArray.push_back("u");
563 +        labelArray.push_back("d");
564 +        labelArray.push_back("s");
565 +        labelArray.push_back("c");
566 +        labelArray.push_back("b");
567 +        labelArray.push_back("t");
568 +        labelArray.push_back("e");
569 +        labelArray.push_back("#mu");
570 +        labelArray.push_back("#tau");
571 +        labelArray.push_back("#nu");
572 +        labelArray.push_back("g");
573 +        labelArray.push_back("#gamma");
574 +        labelArray.push_back("Z");
575 +        labelArray.push_back("W");
576 +        labelArray.push_back("light meson");
577 +        labelArray.push_back("K meson");
578 +        labelArray.push_back("D meson");
579 +        labelArray.push_back("B meson");
580 +        labelArray.push_back("light baryon");
581 +        labelArray.push_back("strange baryon");
582 +        labelArray.push_back("charm baryon");
583 +        labelArray.push_back("bottom baryon");
584 +        labelArray.push_back("QCD string");
585 +        labelArray.push_back("other");
586 +
587 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
588 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
589 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
590 +          }
591 +          else {
592 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
593 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
594 +          }
595 +        }
596 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
597 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
598 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
599 +        }
600 +
601 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
602 +
603 +
604 +      // Book a histogram for the number of each object type to be plotted.
605 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
606 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
607 +        string currentObject = objectsToPlot.at(currentObjectIndex);
608 +        int maxNum = 10;
609 +        if(currentObject == "mcparticles") maxNum = 50;
610 +        else if(currentObject == "primaryvertexs") maxNum = 50;
611 +
612 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
613 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
614 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
615 +        else if(currentObject == "electron-photon pairs")     currentObject = "electronPhotonPairs";
616 +        else if(currentObject == "muon-photon pairs")         currentObject = "muonPhotonPairs";
617 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
618 +        else if(currentObject == "secondary photons")            currentObject = "secondaryPhotons";
619 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
620 +        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
621 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
622 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
623 +        else if(currentObject == "muon-event pairs")            currentObject = "muonEventPairs";
624 +        else if(currentObject == "photon-jet pairs")            currentObject = "photonJetPairs";
625 +        else if(currentObject == "met-jet pairs")             currentObject = "metJetPairs";
626 +        else if(currentObject == "track-jet pairs")           currentObject = "trackJetPairs";
627 +        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
628 +        else if(currentObject == "muon-secondary photon pairs")  currentObject = "muonSecondaryPhotonPairs";
629 +        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
630 +        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
631 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
632 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
633 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
634 +        else if(currentObject == "secondary muon-track pairs") currentObject = "secondaryMuonTrackPairs";
635 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
636 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
637 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
638 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
639 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
640 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
641 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
642 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
643 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
644 +        else if(currentObject == "electron-mcparticle pairs")   currentObject = "electronMCparticlePairs";
645 +
646 +
647 +        currentObject.at(0) = toupper(currentObject.at(0));
648 +        string histoName = "num" + currentObject;
649 +
650 +        if(histoName == "numPrimaryvertexs"){
651 +          string newHistoName = histoName + "BeforePileupCorrection";
652 +          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);
653 +          newHistoName = histoName + "AfterPileupCorrection";
654 +          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);
655 +        }
656 +        else
657 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
658 +      }
659 +
660 +      if (verbose_) {
661 +        clog << "List of 1D histograms booked for channel " << channelName << " and directory " << currentDir << ":" << endl;
662 +        for(map<string, TH1D*>::iterator
663 +              iter = oneDHists_.at(currentChannel).at(currentDir).begin();
664 +            iter  != oneDHists_.at(currentChannel).at(currentDir).end();
665 +            iter++) {
666 +          clog << " " << iter->first
667 +               << ":  name=" << iter->second->GetName()
668 +               << ", title=" << iter->second->GetTitle()
669 +               << ", bins=(" << iter->second->GetNbinsX()
670 +               << "," << iter->second->GetXaxis()->GetXmin()
671 +               << "," << iter->second->GetXaxis()->GetXmax()
672 +               << ")" << endl;
673 +        }  
674 +        clog << "List of 2D histograms booked for channel " << channelName << " and directory " << currentDir << ":" << endl;
675 +        for(map<string, TH2D*>::iterator
676 +              iter = twoDHists_.at(currentChannel).at(currentDir).begin();
677 +            iter  != twoDHists_.at(currentChannel).at(currentDir).end();
678 +            iter++) {
679 +          clog << " " << iter->first
680 +               << ":  name=" << iter->second->GetName()
681 +               << ", title=" << iter->second->GetTitle()
682 +               << ", binsX=(" << iter->second->GetNbinsX()
683 +               << "," << iter->second->GetXaxis()->GetXmin()
684 +               << "," << iter->second->GetXaxis()->GetXmax()
685 +               << ")"
686 +               << ", binsY=(" << iter->second->GetNbinsY()
687 +               << "," << iter->second->GetYaxis()->GetXmin()
688 +               << "," << iter->second->GetYaxis()->GetXmax()
689 +               << ")"
690 +               << endl;
691 +        }  
692 +      }
693 +
694 +    }//end of loop over directories
695      channels.push_back(tempChannel);
696      tempChannel.cuts.clear();
200
697    }//end loop over channels
698  
699  
700 +  // Create the cutflow histogram and fill with 0 weight, in case no events are found in the input file.  
701 +  for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
702 +    channel currentChannel = channels.at(currentChannelIndex);
703 +    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
704 +      cutFlows_.at(currentChannelIndex)->at("trigger") = true;  
705 +    }
706 +    for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
707 +      cut currentCut = currentChannel.cuts.at(currentCutIndex);
708 +      cutFlows_.at(currentChannelIndex)->at (currentCut.name) = true;
709 +    }
710 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(0);  // fill cutflow with 0 weight, just to create the cutflow histograms  
711 +  }
712  
713 +  //make unique vector of objects we need to get from the event
714 +  sort( objectsToGet.begin(), objectsToGet.end() );
715 +  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
716 +  //make unique vector of objects we need to cut on
717 +  sort( objectsToCut.begin(), objectsToCut.end() );
718 +  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
719 +  //make unique vector of objects we need to set flags for
720 +  sort( objectsToFlag.begin(), objectsToFlag.end() );
721 +  objectsToFlag.erase( unique( objectsToFlag.begin(), objectsToFlag.end() ), objectsToFlag.end() );
722 +
723 +  // 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.  
724 +  for (uint i=0; i<objectsToFlag.size(); i++) {
725 +    if (objectsToFlag.at(i).find("pairs")!=string::npos) { // if it contains "pairs"
726 +      objectsToFlag.push_back(objectsToFlag.at(i));  
727 +      objectsToFlag.erase(objectsToFlag.begin()+i);  
728 +    }
729 +  }
730  
731 <  //make unique vector of objects we need to cut on (so we make sure to get them from the event)
732 <  sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
733 <  allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
731 >  if (verbose_) {
732 >    clog << "List of channels:" << endl;
733 >    for (uint i=0; i<channels.size(); i++) {
734 >      clog << " " << channels.at(i).name << endl;
735 >    }
736 >    clog << "List of objects to get:" << endl;
737 >    for (uint i=0; i<objectsToGet.size(); i++) {
738 >      clog << " " << objectsToGet.at(i) << endl;
739 >    }
740 >    clog << "List of objects to plot:" << endl;
741 >    for (uint i=0; i<objectsToPlot.size(); i++) {
742 >      clog << " " << objectsToPlot.at(i) << endl;
743 >    }
744 >    clog << "List of objects to cut:" << endl;
745 >    for (uint i=0; i<objectsToCut.size(); i++) {
746 >      clog << " " << objectsToCut.at(i) << endl;
747 >    }
748 >    clog << "List of objects to flag:" << endl;
749 >    for (uint i=0; i<objectsToFlag.size(); i++) {
750 >      clog << " " << objectsToFlag.at(i) << endl;
751 >    }
752 >  }
753  
754 +  produces<map<string, bool> > ("channelDecisions");
755 +
756 +  if (printEventInfo_) {
757 +    findEventsLog = new ofstream();  
758 +    findEventsLog->open("findEvents.txt");  
759 +    clog << "Listing run:lumi:event in file findEvents.txt for events that pass full selection (of any channel)." << endl;  
760 +  } else {
761 +    findEventsLog = 0;
762 +  }  
763 +
764 +  isFirstEvent_ = true;  
765 +
766 +  if (verbose_) clog << "Finished OSUAnalysis::OSUAnalysis constructor." << endl;  
767 +
768 +
769 +  } // end constructor OSUAnalysis::OSUAnalysis()
770  
211 }
771  
772   OSUAnalysis::~OSUAnalysis ()
773   {
774 +
775 +  if (verbose_) clog << "Beginning OSUAnalysis::OSUAnalysis destructor." << endl;  
776 +
777    // Destroying the CutFlow objects causes the cut flow numbers and time
778    // information to be printed to standard output.
779    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
780      delete cutFlows_.at(currentChannel);
781    }
782 +
783 +  if (printEventInfo_ && findEventsLog) findEventsLog->close();  
784 +
785 +  clog << "=============================================" << endl;  
786 +  clog << "Successfully completed OSUAnalysis." << endl;  
787 +  clog << "=============================================" << endl;  
788 +
789 +  if (verbose_) clog << "Finished OSUAnalysis::OSUAnalysis destructor." << endl;  
790 +
791   }
792  
793   void
794 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
794 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
795   {
796 +  // Retrieve necessary collections from the event.
797  
798 +  if (verbose_) clog << "Beginning OSUAnalysis::produce." << endl;  
799  
800 <  // Retrieve necessary collections from the event.
228 <  edm::Handle<BNtriggerCollection> triggers;
229 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
800 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end()) {
801      event.getByLabel (triggers_, triggers);
802 +    if (!triggers.product()) clog << "ERROR:  could not get triggers input collection" << endl;  
803 +  }
804 +
805 +  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end()) {
806 +    event.getByLabel (trigobjs_, trigobjs);
807 +    if (!trigobjs.product()) clog << "ERROR:  could not get trigobjs input collection" << endl;  
808 +  }
809  
810 <  edm::Handle<BNjetCollection> jets;
233 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())
810 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end()) {
811      event.getByLabel (jets_, jets);
812 +    if (!jets.product()) clog << "ERROR:  could not get jets input collection" << endl;  
813 +  }
814  
815 <  edm::Handle<BNmuonCollection> muons;
237 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())
815 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end()) {
816      event.getByLabel (muons_, muons);
817 +    if (!muons.product()) clog << "ERROR:  could not get muons input collection" << endl;  
818 +  }
819  
820 <  edm::Handle<BNelectronCollection> electrons;
821 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())
820 >  if (find(objectsToGet.begin(), objectsToGet.end(), "secondary muons") != objectsToGet.end()) {
821 >    event.getByLabel (secMuons_, secMuons);
822 >    if (!secMuons.product()) clog << "ERROR:  could not get secMuons input collection" << endl;  
823 >  }
824 >
825 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end()) {
826      event.getByLabel (electrons_, electrons);
827 +    if (!electrons.product()) clog << "ERROR:  could not get electrons input collection" << endl;  
828 +  }
829  
830 <  edm::Handle<BNeventCollection> events;
245 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())
830 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end()) {
831      event.getByLabel (events_, events);
832 +    if (!events.product()) clog << "ERROR:  could not get events input collection" << endl;  
833 +  }
834  
835 <  edm::Handle<BNtauCollection> taus;
249 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())
835 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end()) {
836      event.getByLabel (taus_, taus);
837 +    if (!taus.product()) clog << "ERROR:  could not get taus input collection" << endl;  
838 +  }
839  
840 <  edm::Handle<BNmetCollection> mets;
253 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())
840 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end()) {
841      event.getByLabel (mets_, mets);
842 +    if (!mets.product()) clog << "ERROR:  could not get mets input collection" << endl;  
843 +  }
844  
845 <  edm::Handle<BNtrackCollection> tracks;
257 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())
845 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end()) {
846      event.getByLabel (tracks_, tracks);
847 +    if (!tracks.product()) clog << "ERROR:  could not get tracks input collection" << endl;  
848 +  }
849  
850 <  edm::Handle<BNgenjetCollection> genjets;
261 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())
850 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end()) {
851      event.getByLabel (genjets_, genjets);
852 +    if (!genjets.product()) clog << "ERROR:  could not get genjets input collection" << endl;  
853 +  }
854  
855 <  edm::Handle<BNmcparticleCollection> mcparticles;
265 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())
855 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end()) {
856      event.getByLabel (mcparticles_, mcparticles);
857 +    if (!mcparticles.product()) clog << "ERROR:  could not get mcparticles input collection" << endl;  
858 +  }
859  
860 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
269 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())
860 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end()) {
861      event.getByLabel (primaryvertexs_, primaryvertexs);
862 +    if (!primaryvertexs.product()) clog << "ERROR:  could not get primaryvertexs input collection" << endl;  
863 +  }
864  
865 <  edm::Handle<BNbxlumiCollection> bxlumis;
273 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())
865 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end()) {
866      event.getByLabel (bxlumis_, bxlumis);
867 +    if (!bxlumis.product()) clog << "ERROR:  could not get bxlumis input collection" << endl;  
868 +  }
869  
870 <  edm::Handle<BNphotonCollection> photons;
277 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())
870 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end()) {
871      event.getByLabel (photons_, photons);
872 +    if (!photons.product()) clog << "ERROR:  could not get photons input collection" << endl;  
873 +  }
874  
875 <  edm::Handle<BNsuperclusterCollection> superclusters;
281 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())
875 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end()) {
876      event.getByLabel (superclusters_, superclusters);
877 +    if (!superclusters.product()) clog << "ERROR:  could not get superclusters input collection" << endl;  
878 +  }
879 +
880 +  if (datasetType_ == "signalMC"){
881 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end()) {
882 +      event.getByLabel (stops_, stops);
883 +      if (!stops.product()) clog << "ERROR:  could not get stops input collection" << endl;  
884 +    }
885 +  }
886  
887 +  if (useTrackCaloRhoCorr_) {
888 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
889 +    // This rho collection is not available in all BEANs.
890 +    // For description of rho values for different jet reconstruction algorithms, see
891 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
892 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
893 +    if (!rhokt6CaloJetsHandle_.product()) clog << "ERROR:  could not get kt6CaloJets input collection" << endl;  
894 +  }
895 +
896 +  double masterScaleFactor = 1.0;
897 +
898 +  //get pile-up event weight
899 +  if (doPileupReweighting_ && datasetType_ != "data") {
900 +    //for "data" datasets, the numTruePV is always set to -1
901 +    if (events->at(0).numTruePV < 0 && isFirstEvent_) clog << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
902 +    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
903 +  }
904 +
905 +  stopCTauScaleFactor_ = 1.0;
906 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
907 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
908 +  masterScaleFactor *= stopCTauScaleFactor_;
909  
910    //loop over all channels
911  
912 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
913    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
914      channel currentChannel = channels.at(currentChannelIndex);
915 +    if (verbose_>1) clog << " Processing channel " << currentChannel.name << endl;
916  
917      flagMap individualFlags;
291    flagMap cumulativeFlags;
918      counterMap passingCounter;
919 +    cumulativeFlags.clear ();
920 +
921 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
922 +         iter != BNTreeBranchVals_.end(); iter++) {
923 +      iter->second.clear();  // clear array
924 +    }
925  
926      bool triggerDecision = true;
927 <    if(currentChannel.triggers.size() != 0){  //triggers specified
928 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
927 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
928 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
929        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
930      }
931  
932      //loop over all cuts
933      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
934        cut currentCut = currentChannel.cuts.at(currentCutIndex);
935 +      if (verbose_>2) clog << "  Processing cut, index: " << currentCutIndex << ", input collection: " << currentCut.inputCollection << ", name: " << currentCut.name << endl;  
936  
937 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
938 <
306 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
307 <        individualFlags[currentObject].push_back (vector<bool> ());
308 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
309 <
310 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
311 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
312 <        else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
313 <        else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
314 <        else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
315 <        else if(currentObject == "mets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
316 <        else if(currentObject == "tracks") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
317 <        else if(currentObject == "genjets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
318 <        else if(currentObject == "mcparticles") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
319 <        else if(currentObject == "primaryvertexs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
320 <        else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
321 <        else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
322 <        else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
937 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
938 >        string currentObject = objectsToFlag.at(currentObjectIndex);
939  
940 +        //initialize maps to get ready to set cuts
941 +        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
942 +        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
943  
944        }
945  
946 +      //set flags for all relevant objects
947 +      for(int currentObjectIndex = -1; currentObjectIndex != int(objectsToFlag.size()); currentObjectIndex++){
948 +        string currentObject;  
949 +        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.  
950 +        else currentObject = objectsToFlag.at(currentObjectIndex);
951 +        if (currentObjectIndex >= 0 && currentObject == currentCut.inputCollection) continue;  // Flags have already been set for the inputCollection object, so should not be set again.  
952 +
953 +        // single object collections
954 +        if     (currentObject == "jets")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
955 +        else if(currentObject == "secondary jets")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
956 +        else if(currentObject == "secondary photons")   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"secondary photons");
957 +        else if(currentObject == "muons")               setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
958 +        else if(currentObject == "secondary muons")     setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,secMuons.product(),"secondary muons");
959 +        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
960 +        else if(currentObject == "electrons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
961 +        else if(currentObject == "events")              setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
962 +        else if(currentObject == "taus")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
963 +        else if(currentObject == "mets")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
964 +        else if(currentObject == "tracks")              setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
965 +        else if(currentObject == "genjets")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
966 +        else if(currentObject == "mcparticles")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
967 +        else if(currentObject == "primaryvertexs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
968 +        else if(currentObject == "bxlumis")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
969 +        else if(currentObject == "photons")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
970 +        else if(currentObject == "superclusters")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
971 +        else if(currentObject == "trigobjs")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
972 +
973 +
974 +        // paired object collections  
975 +        else if(currentObject == "muon-muon pairs")                   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), "muon-muon pairs");
976 +        else if(currentObject == "muon-secondary muon pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),secMuons.product(), "muon-secondary muon pairs");
977 +
978 +        else if(currentObject == "muon-secondary photon pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), "muon-secondary photon pairs");
979 +        else if(currentObject == "muon-secondary jet pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), "muon-secondary jet pairs");
980 +        else if(currentObject == "photon-secondary jet pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), "photon-secondary jet pairs");
981 +        else if(currentObject == "electron-secondary jet pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), "electron-secondary jet pairs");
982 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), "electron-secondary electron pairs");
983 +
984 +        else if(currentObject == "electron-electron pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), "electron-electron pairs");
985 +        else if(currentObject == "electron-muon pairs")     setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), "electron-muon pairs");
986 +        else if(currentObject == "jet-jet pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), "jet-jet pairs");
987 +        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), "jet-secondary jet pairs");
988 +        else if(currentObject == "electron-jet pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), "electron-jet pairs");
989 +        else if(currentObject == "electron-photon pairs")   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), "electron-photon pairs");
990 +        else if(currentObject == "photon-jet pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), "photon-jet pairs");
991 +        else if(currentObject == "muon-jet pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), "muon-jet pairs");
992 +        else if(currentObject == "muon-event pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),events.product(), "muon-event pairs");
993 +        else if(currentObject == "met-jet pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),jets.product(), "met-jet pairs");
994 +        else if(currentObject == "track-jet pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),jets.product(), "track-jet pairs");
995 +        else if(currentObject == "muon-photon pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), "muon-photon pairs");
996 +        else if(currentObject == "track-event pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(), "track-event pairs");
997 +        else if(currentObject == "electron-track pairs")    setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),"electron-track pairs");
998 +        else if(currentObject == "muon-track pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),"muon-track pairs");
999 +        else if(currentObject == "secondary muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,secMuons.product(),tracks.product(),"secondary muon-track pairs");
1000 +        else if(currentObject == "muon-tau pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),"muon-tau pairs");
1001 +        else if(currentObject == "tau-tau pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),"tau-tau pairs");
1002 +        else if(currentObject == "tau-track pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),"tau-track pairs");
1003 +        else if(currentObject == "electron-trigobj pairs")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),"electron-trigobj pairs");
1004 +        else if(currentObject == "muon-trigobj pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),"muon-trigobj pairs");
1005 +        else if(currentObject == "electron-mcparticle pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),mcparticles.product(),"electron-mcparticle pairs");
1006  
1007 +        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
1008 +      }
1009  
1010      }//end loop over all cuts
1011  
1012  
1013  
333
1014      //use cumulative flags to apply cuts at event level
1015 <
1015 >    vector<bool> eventPassedPreviousCuts;    //a vector to store cumulative cut descisions after each cut.
1016      bool eventPassedAllCuts = true;
1017 <
338 <    //apply trigger (true if none were specified)
339 <    eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
340 <
1017 >    eventPassedAllCuts = eventPassedAllCuts && triggerDecision;    //apply trigger (true if none were specified)
1018  
1019      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
1020  
1021        //loop over all objects and count how many passed the cumulative selection up to this point
1022        cut currentCut = currentChannel.cuts.at(currentCutIndex);
1023        int numberPassing = 0;
1024 +      int numberPassingPrev = 0;  // number of objects that pass cuts up to the previous one
1025  
1026 <      for (uint object = 0; object != cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).size() ; object++)
1027 <          if(cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).at(object)) numberPassing++;
1028 <
1026 >      for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
1027 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
1028 >      }
1029 >      bool cutDecision;
1030 >      if (!currentCut.isVeto) {
1031 >        cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
1032 >      } else {
1033 >        int prevCutIndex = currentCutIndex - 1;
1034 >        if (prevCutIndex<0) {
1035 >          numberPassingPrev = cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size();  // count all objects in collection if cut is the first
1036 >        } else {
1037 >          for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(prevCutIndex).size() ; object++){
1038 >            if (cumulativeFlags.at(currentCut.inputCollection).at(prevCutIndex).at(object).first) {
1039 >              numberPassingPrev++;
1040 >              if (verbose_>1) clog << " object passed previous cut" << endl;  
1041 >            }
1042 >          }  
1043 >        }  
1044 >        int numberFailCut = numberPassingPrev - numberPassing;
1045 >        cutDecision = evaluateComparison(numberFailCut,currentCut.eventComparativeOperator,currentCut.numberRequired);  
1046 >      }
1047  
352      bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
1048        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
354
1049        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
1050 +      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
1051 +      if (verbose_>1) clog << " Event passed cuts up to cut index " << currentCutIndex << endl;  
1052  
1053      }
1054 +    //applying all appropriate scale factors
1055 +    double scaleFactor = masterScaleFactor;
1056 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
1057 +
1058 +    if(applyLeptonSF_ && datasetType_ != "data"){
1059 +      //only apply SFs if we've cut on this object
1060 +      if(find(objectsToCut.begin(),objectsToCut.end(),"muons") != objectsToCut.end ()){
1061 +        flagPair muonFlags;
1062 +        //get the last valid flags in the flag map
1063 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
1064 +          if (cumulativeFlags.at("muons").at(i).size()){
1065 +            muonFlags = cumulativeFlags.at("muons").at(i);
1066 +            break;
1067 +          }
1068 +        }
1069 +        //apply the weight for each of those objects
1070 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
1071 +          if(!muonFlags.at(muonIndex).second) continue;
1072 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
1073 +        }
1074 +      }
1075 +      //only apply SFs if we've cut on this object
1076 +      if(find(objectsToCut.begin(),objectsToCut.end(),"electrons") != objectsToCut.end ()){
1077 +        flagPair electronFlags;
1078 +        //get the last valid flags in the flag map
1079 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
1080 +          if (cumulativeFlags.at("electrons").at(i).size()){
1081 +            electronFlags = cumulativeFlags.at("electrons").at(i);
1082 +            break;
1083 +          }
1084 +        }
1085 +        //apply the weight for each of those objects
1086 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
1087 +          if(!electronFlags.at(electronIndex).second) continue;
1088 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
1089 +        }
1090 +      }
1091 +    }
1092 +    if(applyBtagSF_ && datasetType_ != "data"){
1093 +      //only apply SFs if we've cut on this object
1094 +      if(find(objectsToCut.begin(),objectsToCut.end(),"jets") != objectsToCut.end ()){
1095 +        flagPair jetFlags;
1096 +        vector<double> jetSFs;
1097 +        //get the last valid flags in the flag map
1098 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
1099 +          if (cumulativeFlags.at("jets").at(i).size()){
1100 +            jetFlags = cumulativeFlags.at("jets").at(i);
1101 +            break;
1102 +          }
1103 +        }
1104 +        //apply the weight for each of those objects
1105 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
1106 +          if(!jetFlags.at(jetIndex).second) continue;
1107 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour, jets->at(jetIndex).eta);
1108 +          jetSFs.push_back(jetSFTmp);
1109 +        }
1110 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_);
1111 +      }
1112 +    }
1113 +    scaleFactor *= muonScaleFactor_;
1114 +    scaleFactor *= electronScaleFactor_;
1115 +    scaleFactor *= bTagScaleFactor_;
1116 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
1117 +    if (verbose_>1) clog << " Scale factors applied:  "
1118 +                         << " muonScaleFactor_ = " << muonScaleFactor_
1119 +                         << ", electronScaleFactor_ = " << electronScaleFactor_
1120 +                         << ", bTagScaleFactor_ = " << bTagScaleFactor_
1121 +                         << ", total scale factor = " << scaleFactor
1122 +                         << endl;  
1123 +
1124 +
1125 +    if (printEventInfo_ && eventPassedAllCuts) {
1126 +      // Write information about event to screen, for testing purposes.
1127 +      clog << "Event passed all cuts in channel " <<  currentChannel.name
1128 +           << ":  run:lumi:evt=  "  << events->at(0).run
1129 +           << ":" << events->at(0).lumi
1130 +           << ":" << events->at(0).evt
1131 +           << endl;
1132 +      if (findEventsLog) {
1133 +        (*findEventsLog) << events->at(0).run
1134 +                         << ":" << events->at(0).lumi
1135 +                         << ":" << events->at(0).evt << endl;
1136 +      }
1137  
1138 <    cutFlows_.at(currentChannelIndex)->fillCutFlow();
1138 >    }
1139  
1140  
1141 <    if(!eventPassedAllCuts)continue;
1141 >    //filling histograms
1142 >    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.
1143  
1144 +      if (verbose_>2) clog << "  Filling histograms for currentcut = " << currentCut << endl;  
1145  
1146 <    //set position of primary vertex in event, in order to calculate quantities relative to it
1147 <    primaryVertex_ = 0;
1148 <    vector<bool> vertexFlags = cumulativeFlags["primaryvertexs"].back();
1149 <    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
1150 <      if(!vertexFlags.at(vertexIndex)) continue;
370 <      primaryVertex_ = new BNprimaryvertex (primaryvertexs->at (vertexIndex));
371 <      break;
372 <    }
1146 >      uint currentDir;
1147 >      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
1148 >      else{
1149 >        currentDir = currentCut;
1150 >      }
1151  
1152  
1153 +      if(eventPassedPreviousCuts.at(currentDir)){
1154  
1155 <    //filling histograms
1156 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1157 <      histogram currentHistogram = histograms.at(histogramIndex);
1155 >        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1156 >          histogram currentHistogram = histograms.at(histogramIndex);
1157 >
1158 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) clog << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
1159 >
1160 >          if (verbose_>1) clog << " Filling histogram " << currentHistogram.name << " for collection " << currentHistogram.inputCollection << endl;  
1161 >
1162 >          if(currentHistogram.inputVariables.size() == 1){
1163 >            TH1D* histo;
1164 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1165 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1166 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1167 >            else if(currentHistogram.inputCollection == "secondary photons")  fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1168 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1169 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,secMuons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1170 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1171 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1172 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1173 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),secMuons.product(),
1174 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1175 >             else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1176 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1177 >             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1178 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1179 >             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1180 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1181 >             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1182 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1183 >
1184 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1185 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1186 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1187 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1188 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1189 >             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1190 >                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1191 >
1192 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1193 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1194 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(),
1195 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1196 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(),
1197 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1198 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(),
1199 >                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1200 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(),
1201 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1202 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill1DHistogram(histo,currentHistogram, muons.product(),events.product(),
1203 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1204 >            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, mets.product(),jets.product(),
1205 >                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1206 >            else if(currentHistogram.inputCollection == "track-jet pairs")  fill1DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1207 >                                                                                          cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1208 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(),
1209 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1210 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(),
1211 >                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1212 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1213 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1214 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1215 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1216 >            else if(currentHistogram.inputCollection == "secondary muon-track pairs") fill1DHistogram(histo,currentHistogram, secMuons.product(),tracks.product(),
1217 >                                                                                            cumulativeFlags.at("secondary muon-track pairs").at(currentDir),scaleFactor);
1218 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1219 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1220 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1221 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1222 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1223 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1224 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1225 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1226 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1227 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1228 >
1229 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1230 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1231 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1232 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1233 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1234 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1235 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1236 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1237 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1238 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1239 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1240 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1241 >          }
1242 >          else if(currentHistogram.inputVariables.size() == 2){
1243 >            TH2D* histo;
1244 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1245 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1246 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1247 >            else if(currentHistogram.inputCollection == "secondary photons")  fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1248 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1249 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,secMuons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1250 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1251 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1252 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),secMuons.product(),
1253 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1254 >            else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1255 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1256 >            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1257 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1258 >            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1259 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1260 >            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1261 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1262 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1263 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1264 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1265 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1266 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1267 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1268 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1269 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1270 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(),
1271 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1272 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1273 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1274 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(),
1275 >                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1276 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1277 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1278 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill2DHistogram(histo,currentHistogram,muons.product(),events.product(),
1279 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1280 >            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,mets.product(),jets.product(),
1281 >                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1282 >            else if(currentHistogram.inputCollection == "track-jet pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1283 >                                                                                         cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1284 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1285 >                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1286 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1287 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1288 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1289 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1290 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1291 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1292 >            else if(currentHistogram.inputCollection == "secondary muon-track pairs") fill2DHistogram(histo,currentHistogram,secMuons.product(),tracks.product(),
1293 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1294 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1295 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1296 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1297 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1298 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1299 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1300 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1301 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1302 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1303 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1304 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1305 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1306 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1307 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1308 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1309 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1310 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1311 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1312 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1313 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1314 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1315 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1316 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1317 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1318 >          }
1319 >
1320 >        }
1321  
380      if(currentHistogram.inputVariables.size() == 1){
381        TH1D* histo;
382        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
383        if(currentHistogram.inputCollection == "jets") fillHistogram(histo,currentHistogram,jets.product());
384        else if(currentHistogram.inputCollection == "muons") fillHistogram(histo,currentHistogram,muons.product());
385        else if(currentHistogram.inputCollection == "electrons") fillHistogram(histo,currentHistogram,electrons.product());
386        else if(currentHistogram.inputCollection == "events") fillHistogram(histo,currentHistogram,events.product());
387        else if(currentHistogram.inputCollection == "taus") fillHistogram(histo,currentHistogram,taus.product());
388        else if(currentHistogram.inputCollection == "mets") fillHistogram(histo,currentHistogram,mets.product());
389        else if(currentHistogram.inputCollection == "tracks") fillHistogram(histo,currentHistogram,tracks.product());
390        else if(currentHistogram.inputCollection == "genjets") fillHistogram(histo,currentHistogram,genjets.product());
391        else if(currentHistogram.inputCollection == "mcparticles") fillHistogram(histo,currentHistogram,mcparticles.product());
392        else if(currentHistogram.inputCollection == "primaryvertexs") fillHistogram(histo,currentHistogram,primaryvertexs.product());
393        else if(currentHistogram.inputCollection == "bxlumis") fillHistogram(histo,currentHistogram,bxlumis.product());
394        else if(currentHistogram.inputCollection == "photons") fillHistogram(histo,currentHistogram,photons.product());
395        else if(currentHistogram.inputCollection == "superclusters") fillHistogram(histo,currentHistogram,superclusters.product());
396      }
397      else if(currentHistogram.inputVariables.size() == 2){
398        TH2D* histo;
399        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
400        if(currentHistogram.inputCollection == "jets") fillHistogram(histo,currentHistogram,jets.product());
401        else if(currentHistogram.inputCollection == "muons") fillHistogram(histo,currentHistogram,muons.product());
402        else if(currentHistogram.inputCollection == "electrons") fillHistogram(histo,currentHistogram,electrons.product());
403        else if(currentHistogram.inputCollection == "events") fillHistogram(histo,currentHistogram,events.product());
404        else if(currentHistogram.inputCollection == "taus") fillHistogram(histo,currentHistogram,taus.product());
405        else if(currentHistogram.inputCollection == "mets") fillHistogram(histo,currentHistogram,mets.product());
406        else if(currentHistogram.inputCollection == "tracks") fillHistogram(histo,currentHistogram,tracks.product());
407        else if(currentHistogram.inputCollection == "genjets") fillHistogram(histo,currentHistogram,genjets.product());
408        else if(currentHistogram.inputCollection == "mcparticles") fillHistogram(histo,currentHistogram,mcparticles.product());
409        else if(currentHistogram.inputCollection == "primaryvertexs") fillHistogram(histo,currentHistogram,primaryvertexs.product());
410        else if(currentHistogram.inputCollection == "bxlumis") fillHistogram(histo,currentHistogram,bxlumis.product());
411        else if(currentHistogram.inputCollection == "photons") fillHistogram(histo,currentHistogram,photons.product());
412        else if(currentHistogram.inputCollection == "superclusters") fillHistogram(histo,currentHistogram,superclusters.product());
413      }
414    }
1322  
1323 +        //fills histograms with the sizes of collections
1324 +        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1325 +
1326 +          string currentObject = objectsToPlot.at(currentObjectIndex);
1327 +          string objectToPlot = "";
1328 +
1329 +          if (verbose_) clog << "Filling histogram of number of selected objects in collection: " << currentObject << endl;  
1330 +
1331 +          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1332 +          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1333 +          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1334 +          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1335 +          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1336 +          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1337 +          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1338 +          else if(currentObject == "muon-event pairs")                   objectToPlot = "muonEventPairs";
1339 +          else if(currentObject == "muon-photon pairs")                  objectToPlot = "muonPhotonPairs";
1340 +          else if(currentObject == "photon-jet pairs")                   objectToPlot = "photonJetPairs";
1341 +          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1342 +          else if(currentObject == "track-jet pairs")                    objectToPlot = "trackJetPairs";
1343 +          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1344 +          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1345 +          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1346 +          else if(currentObject == "secondary photons")                  objectToPlot = "secondaryPhotons";
1347 +          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1348 +          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1349 +          else if(currentObject == "secondary muon-track pairs")         objectToPlot = "secondaryMuonTrackPairs";
1350 +          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1351 +          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1352 +          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1353 +          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1354 +          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1355 +          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1356 +          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1357 +          else if(currentObject == "muon-secondary photon pairs")        objectToPlot = "muonSecondaryJetPairs";
1358 +          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1359 +          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1360 +          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1361 +          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1362 +          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1363 +          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1364 +          else if(currentObject == "electron-mcparticle pairs")          objectToPlot = "electronMCparticlePairs";
1365 +          else objectToPlot = currentObject;
1366 +
1367 +          string tempCurrentObject = objectToPlot;
1368 +          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1369 +          string histoName = "num" + tempCurrentObject;
1370 +
1371 +
1372 +          if(find(objectsToPlot.begin(), objectsToPlot.end(), currentObject) != objectsToPlot.end()) {
1373 +            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1374 +            int numToPlot = 0;
1375 +            for (uint iObj = 0; iObj != lastCutFlags.size(); iObj++){  // loop over all the objects  
1376 +              if(lastCutFlags.at(iObj).second) {
1377 +                numToPlot++;  
1378 +                if (verbose_>3) clog << "   Found object " << iObj << " in collection " << currentObject << " to plot." << endl;
1379 +              }
1380 +            }
1381 +
1382 +            if(objectToPlot == "primaryvertexs"){
1383 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1384 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1385 +            }
1386 +            else {
1387 +              if (printEventInfo_) clog << "Number of selected " << objectToPlot << " to plot:  " << numToPlot << endl;  
1388 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1389 +            }
1390 +          }
1391  
1392 <    //fills histograms with the sizes of collections
418 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
419 <      string currentObject = objectsToPlot.at(currentObjectIndex);
420 <      string tempCurrentObject = currentObject;
421 <      tempCurrentObject[0] = toupper(tempCurrentObject[0]);
422 <      string histoName = "num" + tempCurrentObject;
423 <
424 <      if(currentObject == "jets") oneDHists_.at(currentChannelIndex)[histoName]->Fill(jets->size());
425 <      else if(currentObject == "muons") oneDHists_.at(currentChannelIndex)[histoName]->Fill(muons->size());
426 <      else if(currentObject == "electrons") oneDHists_.at(currentChannelIndex)[histoName]->Fill(electrons->size());
427 <      else if(currentObject == "events") oneDHists_.at(currentChannelIndex)[histoName]->Fill(events->size());
428 <      else if(currentObject == "taus") oneDHists_.at(currentChannelIndex)[histoName]->Fill(taus->size());
429 <      else if(currentObject == "mets") oneDHists_.at(currentChannelIndex)[histoName]->Fill(mets->size());
430 <      else if(currentObject == "tracks") oneDHists_.at(currentChannelIndex)[histoName]->Fill(tracks->size());
431 <      else if(currentObject == "genjets") oneDHists_.at(currentChannelIndex)[histoName]->Fill(genjets->size());
432 <      else if(currentObject == "mcparticles") oneDHists_.at(currentChannelIndex)[histoName]->Fill(mcparticles->size());
433 <      else if(currentObject == "primaryvertexs") oneDHists_.at(currentChannelIndex)[histoName]->Fill(primaryvertexs->size());
434 <      else if(currentObject == "bxlumis") oneDHists_.at(currentChannelIndex)[histoName]->Fill(bxlumis->size());
435 <      else if(currentObject == "photons") oneDHists_.at(currentChannelIndex)[histoName]->Fill(photons->size());
436 <      else if(currentObject == "superclusters") oneDHists_.at(currentChannelIndex)[histoName]->Fill(superclusters->size());
1392 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1393  
1394 +
1395 +      } // end if(eventPassedPreviousCuts.at(currentDir))
1396 +    } // end loop over cuts
1397 +
1398 +    if (!useEDMFormat_ && eventPassedAllCuts){
1399 +      // Assign BNTree variables
1400 +      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1401 +        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1402 +        string coll = brSpecs.inputCollection;
1403 +        if (cumulativeFlags.count(coll) == 0) clog << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1404 +
1405 +        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1406 +        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1407 +        else if(coll == "secondary photons")   assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1408 +        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1409 +        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,secMuons.product(),      cumulativeFlags.at(coll).back());
1410 +        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1411 +        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1412 +        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1413 +        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1414 +        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1415 +        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1416 +        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1417 +        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1418 +        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1419 +        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1420 +        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1421 +        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1422 +        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1423 +        else if(coll == "stops"
1424 +                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1425 +      } // end loop over branches
1426 +      // set the evtLong, runInt, and lumiInt variables separately, since they are not type float  
1427 +      BNTreeBranchVals_evtLong_ = events->at(0).evt;
1428 +      BNTreeBranchVals_runInt_  = events->at(0).run;
1429 +      BNTreeBranchVals_lumiInt_ = events->at(0).lumi;
1430 +
1431 +      if (!BNTrees_.at(currentChannelIndex)) { clog << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1432 +      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1433      }
439  } //end loop over channel
1434  
1435 <  masterCutFlow_->fillCutFlow();
1435 >    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1436  
1437 +  } // end loop over channel
1438 +
1439 +  masterCutFlow_->fillCutFlow(masterScaleFactor);
1440 +
1441 +  event.put (channelDecisions, "channelDecisions");
1442 +
1443 +  isFirstEvent_ = false;  
1444 +
1445 +  if (verbose_) clog << "Finished OSUAnalysis::produce." << endl;  
1446 +
1447 + } // end void OSUAnalysis::produce (const edm::Event &event, const edm::EventSetup &setup)
1448  
444 }
1449  
1450  
1451   bool
# Line 453 | Line 1457 | OSUAnalysis::evaluateComparison (double
1457    else if(comparison == "<")  return testValue <  cutValue;
1458    else if(comparison == "<=") return testValue <= cutValue;
1459    else if(comparison == "==") return testValue == cutValue;
1460 +  else if(comparison == "=") return testValue == cutValue;
1461    else if(comparison == "!=") return testValue != cutValue;
1462 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1462 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1463  
1464   }
1465  
1466   bool
1467 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1467 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1468 >
1469 >
1470 >  if(comparison == ">")       return testValue >  cutValue;
1471 >  else if(comparison == ">=") return testValue >= cutValue;
1472 >  else if(comparison == "<")  return testValue <  cutValue;
1473 >  else if(comparison == "<=") return testValue <= cutValue;
1474 >  else if(comparison == "==") return testValue == cutValue;
1475 >  else if(comparison == "=")  return testValue == cutValue;
1476 >  else if(comparison == "!=") return testValue != cutValue;
1477 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1478  
1479 + }
1480 +
1481 + bool
1482 + OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1483 +
1484 +  //initialize to false until a chosen trigger is passed
1485    bool triggerDecision = false;
1486  
1487 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1488 <    {
1489 <      if(trigger->pass != 1) continue;
1490 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1491 <        {
1492 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1493 <            triggerDecision = true;
1494 <          }
1495 <        }
1487 >  if (printAllTriggers_) clog << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1488 >  //loop over all triggers defined in the event
1489 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1490 >
1491 >    if (printAllTriggers_) clog << "   " << trigger->name << endl;
1492 >
1493 >    //we're only interested in triggers that actually passed
1494 >    if(trigger->pass != 1) continue;
1495 >
1496 >    //if the event passes one of the veto triggers, exit and return false
1497 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1498 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1499      }
1500 <  return triggerDecision;
1500 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1501 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1502 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1503 >    }
1504 >  }
1505  
1506 +  printAllTriggers_ = false;  // only print triggers once, not every event
1507 +
1508 +  //if none of the veto triggers fired:
1509 +  //return the OR of all the chosen triggers
1510 +  if (triggersToTest.size() != 0) return triggerDecision;
1511 +  //or if no triggers were defined return true
1512 +  else return true;
1513   }
1514  
1515 < std::vector<std::string>
1515 >
1516 > vector<string>
1517   OSUAnalysis::splitString (string inputString){
1518  
1519 <  std::stringstream stringStream(inputString);
1520 <  std::istream_iterator<std::string> begin(stringStream);
1521 <  std::istream_iterator<std::string> end;
1522 <  std::vector<std::string> stringVector(begin, end);
1519 >  stringstream stringStream(inputString);
1520 >  istream_iterator<string> begin(stringStream);
1521 >  istream_iterator<string> end;
1522 >  vector<string> stringVector(begin, end);
1523    return stringVector;
1524  
1525   }
1526  
1527 +
1528 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1529 +  // Set two object strings from the tempInputCollection string,
1530 +  // For example, if tempInputCollection is "electron-muon pairs",
1531 +  // then obj1 = "electrons" and obj2 = "muons".
1532 +  // Note that the objects have an "s" appended.
1533 +
1534 +  int dashIndex = tempInputCollection.find("-");
1535 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1536 +  int secondWordLength = spaceIndex - dashIndex;
1537 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1538 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1539 +
1540 + }
1541 +
1542 +
1543 + string OSUAnalysis::getObjToGet(string obj) {
1544 +  // Return the string corresponding to the object to get for the given obj string.
1545 +  // Right now this only handles the case in which obj contains "secondary",
1546 +  // e.g, "secondary muons".
1547 +  // Note that "s" is NOT appended.
1548 +
1549 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1550 +  int firstSpaceIndex = obj.find_first_of(" ");
1551 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1552 +
1553 + }
1554 +
1555 +
1556 + //!jet valueLookup
1557   double
1558 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1558 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1559  
1560    double value = 0.0;
1561    if(variable == "energy") value = object->energy;
# Line 608 | Line 1674 | OSUAnalysis::valueLookup (const BNjet* o
1674    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1675    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1676  
1677 +  //user defined variable
1678 +  else if(variable == "disappTrkLeadingJetID") {
1679 +    value = object->pt > 110
1680 +      && fabs(object->eta) < 2.4
1681 +      && object->chargedHadronEnergyFraction > 0.2
1682 +      && object->neutralHadronEnergyFraction < 0.7
1683 +      && object->chargedEmEnergyFraction < 0.5
1684 +      && object->neutralEmEnergyFraction < 0.7;
1685 +  }
1686  
1687 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1687 >  else if(variable == "disappTrkSubLeadingJetID") {
1688 >    value = object->pt > 30
1689 >      && fabs(object->eta) < 4.5
1690 >      && object->neutralHadronEnergyFraction < 0.7
1691 >      && object->chargedEmEnergyFraction < 0.5;
1692 >  }
1693 >
1694 >  else if(variable == "dPhiMet") {
1695 >    if (const BNmet *met = chosenMET ()) {
1696 >      value = deltaPhi (object->phi, met->phi);
1697 >    } else value = -999;
1698 >  }
1699 >
1700 >
1701 >  else{clog << "WARNING: invalid jet variable '" << variable << "'\n"; value = -999;}
1702  
1703    value = applyFunction(function, value);
1704  
1705    return value;
1706 < }
618 <
1706 > } // end jet valueLookup
1707  
1708  
1709 + //!muon valueLookup
1710   double
1711 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1711 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1712  
1713    double value = 0.0;
1714    if(variable == "energy") value = object->energy;
# Line 635 | Line 1724 | OSUAnalysis::valueLookup (const BNmuon*
1724    else if(variable == "ecalIso") value = object->ecalIso;
1725    else if(variable == "hcalIso") value = object->hcalIso;
1726    else if(variable == "caloIso") value = object->caloIso;
1727 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
1727 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
1728    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
1729    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
1730    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 711 | Line 1800 | OSUAnalysis::valueLookup (const BNmuon*
1800    else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1801    else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1802    else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1803 +  else if(variable == "chargedHadronIsoDR04") value = object->chargedHadronIsoDR04;
1804 +  else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1805 +  else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1806 +  else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1807    else if(variable == "rhoPrime") value = object->rhoPrime;
1808    else if(variable == "AEffDr03") value = object->AEffDr03;
1809    else if(variable == "AEffDr04") value = object->AEffDr04;
# Line 718 | Line 1811 | OSUAnalysis::valueLookup (const BNmuon*
1811    else if(variable == "pfIsoR03SumNeutralHadronEt") value = object->pfIsoR03SumNeutralHadronEt;
1812    else if(variable == "pfIsoR03SumPhotonEt") value = object->pfIsoR03SumPhotonEt;
1813    else if(variable == "pfIsoR03SumPUPt") value = object->pfIsoR03SumPUPt;
1814 +  else if(variable == "relpfIsoR04SumExceptChargedHad") value = (object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)/ object->pt;
1815 +  else if(variable == "relpfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt/object->pt;
1816 +  else if(variable == "relpfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt/object->pt;
1817 +  else if(variable == "relpfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt/object->pt;
1818 +  else if(variable == "relpfIsoR04SumPUPt") value = object->pfIsoR04SumPUPt/object->pt;
1819    else if(variable == "pfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt;
1820    else if(variable == "pfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt;
1821    else if(variable == "pfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt;
# Line 774 | Line 1872 | OSUAnalysis::valueLookup (const BNmuon*
1872    else if(variable == "time_ndof") value = object->time_ndof;
1873  
1874    //user-defined variables
1875 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1876 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1877 <  else if(variable == "detIso") value = (object->trackIso + object->caloIso) / object->pt;
1878 <  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1875 >  else if(variable == "looseID") {
1876 >    value = object->pt > 10 &&
1877 >      (object->isGlobalMuon  > 0 ||
1878 >       object->isTrackerMuon > 0);
1879 >  }
1880 >
1881 >  else if(variable == "looseIDGlobalMuon") {
1882 >    value = object->pt > 10 &&
1883 >      object->isGlobalMuon  > 0;
1884 >  }
1885 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1886 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1887 >  else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1888 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1889 >  else if(variable == "relPFdBetaIsoPseudo") value = (object->pfIsoR04SumChargedHadronPt + object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt) / object->pt;
1890    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1891 +  else if(variable == "metMT") {
1892 +    if (const BNmet *met = chosenMET ())
1893 +      {
1894 +        double dPhi = deltaPhi (object->phi, met->phi);
1895 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1896 +      }
1897 +    else
1898 +      value = -999;
1899 +  }
1900 +  else if(variable == "ptPlusMet") {
1901 +    // Calculate the magnitude of the vector sum of the muon pT and the Met.  
1902 +    if (const BNmet *met = chosenMET ())
1903 +      {
1904 +        TVector2 p2Met;
1905 +        TVector2 p2Muon;
1906 +        p2Met. SetMagPhi(   met->pt,    met->phi);
1907 +        p2Muon.SetMagPhi(object->pt, object->phi);  
1908 +        TVector2 p2MetElec = p2Met + p2Muon;
1909 +        value = p2MetElec.Mod();  
1910 +      }
1911 +    else
1912 +      value = -999;
1913 +  }
1914 +
1915 +  else if(variable == "correctedD0VertexInEBPlus"){
1916 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1917 +    else value = -999;
1918 +  }
1919 +  else if(variable == "correctedD0VertexOutEBPlus"){
1920 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1921 +    else value = -999;
1922 +  }
1923 +  else if(variable == "correctedD0VertexEEPlus"){
1924 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1925 +    else value = -999;
1926 +  }
1927 +
1928 +  else if(variable == "correctedD0BeamspotInEBPlus"){
1929 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1930 +    else value = -999;
1931 +  }
1932 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
1933 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1934 +    else value = -999;
1935 +  }
1936 +  else if(variable == "correctedD0BeamspotEEPlus"){
1937 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1938 +    else value = -999;
1939 +  }
1940 +
1941 +  else if(variable == "correctedD0VertexInEBMinus"){
1942 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1943 +    else value = -999;
1944 +  }
1945 +  else if(variable == "correctedD0VertexOutEBMinus"){
1946 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1947 +    else value = -999;
1948 +  }
1949 +  else if(variable == "correctedD0VertexEEMinus"){
1950 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1951 +    else value = -999;
1952 +  }
1953 +
1954 +  else if(variable == "correctedD0BeamspotInEBMinus"){
1955 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1956 +    else value = -999;
1957 +  }
1958 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
1959 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1960 +    else value = -999;
1961 +  }
1962 +  else if(variable == "correctedD0BeamspotEEMinus"){
1963 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1964 +    else value = -999;
1965 +  }
1966 +
1967 +
1968 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1969 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1970 +    else value = -999;
1971 +  }
1972 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1973 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1974 +    else value = -999;
1975 +  }
1976 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
1977 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1978 +    else value = -999;
1979 +  }
1980 +
1981 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1982 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1983 +    else value = -999;
1984 +  }
1985 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1986 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1987 +    else value = -999;
1988 +  }
1989 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1990 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1991 +    else value = -999;
1992 +  }
1993 +
1994 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1995 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1996 +    else value = -999;
1997 +  }
1998 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1999 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2000 +    else value = -999;
2001 +  }
2002 +  else if(variable == "correctedD0VertexEENegativeCharge"){
2003 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
2004 +    else value = -999;
2005 +  }
2006 +
2007 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
2008 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
2009 +    else value = -999;
2010 +  }
2011 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
2012 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
2013 +    else value = -999;
2014 +  }
2015 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
2016 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
2017 +    else value = -999;
2018 +  }
2019 +
2020 +
2021    else if(variable == "tightID") {
2022 <    value = object->isGlobalMuon > 0            \
2023 <      && object->isPFMuon > 0                   \
2024 <      && object->normalizedChi2 < 10            \
2025 <      && object->numberOfValidMuonHits > 0      \
2026 <      && object->numberOfMatchedStations > 1    \
2027 <      && fabs(object->correctedD0Vertex) < 0.2  \
2028 <      && fabs(object->correctedDZ) < 0.5        \
2029 <      && object->numberOfValidPixelHits > 0     \
2022 >    value = object->isGlobalMuon > 0                \
2023 >      && object->isPFMuon > 0                        \
2024 >      && object->normalizedChi2 < 10                \
2025 >      && object->numberOfValidMuonHits > 0        \
2026 >      && object->numberOfMatchedStations > 1        \
2027 >      && fabs(object->correctedD0Vertex) < 0.2        \
2028 >      && fabs(object->correctedDZ) < 0.5        \
2029 >      && object->numberOfValidPixelHits > 0                \
2030        && object->numberOfLayersWithMeasurement > 5;
792    
793
2031    }
2032    else if(variable == "tightIDdisplaced"){
2033 <    value = object->isGlobalMuon > 0            \
2034 <      && object->isPFMuon > 0                   \
2035 <      && object->normalizedChi2 < 10            \
2036 <      && object->numberOfValidMuonHits > 0      \
2037 <      && object->numberOfMatchedStations > 1    \
2038 <      && object->numberOfValidPixelHits > 0     \
2033 >    value = object->isGlobalMuon > 0                \
2034 >      && object->isPFMuon > 0                        \
2035 >      && object->normalizedChi2 < 10                \
2036 >      && object->numberOfValidMuonHits > 0        \
2037 >      && object->numberOfMatchedStations > 1        \
2038 >      && object->numberOfValidPixelHits > 0        \
2039        && object->numberOfLayersWithMeasurement > 5;
2040    }
2041  
2042 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2042 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2043 >
2044 >  else if(variable == "genMatchedPdgId"){
2045 >    int index = getGenMatchedParticleIndex(object);
2046 >    if(index == -1) value = 0;
2047 >    else value = mcparticles->at(index).id;
2048 >  }
2049 >
2050 >  else if(variable == "genMatchedId"){
2051 >    int index = getGenMatchedParticleIndex(object);
2052 >    if(index == -1) value = 0;
2053 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2054 >  }
2055 >  else if(variable == "genMatchedMotherId"){
2056 >    int index = getGenMatchedParticleIndex(object);
2057 >    if(index == -1) value = 0;
2058 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2059 >  }
2060 >  else if(variable == "genMatchedMotherIdReverse"){
2061 >    int index = getGenMatchedParticleIndex(object);
2062 >    if(index == -1) value = 24;
2063 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
2064 >  }
2065 >  else if(variable == "genMatchedGrandmotherId"){
2066 >    int index = getGenMatchedParticleIndex(object);
2067 >    if(index == -1) value = 0;
2068 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2069 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2070 >      if(motherIndex == -1) value = 0;
2071 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2072 >    }
2073 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2074 >  }
2075 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2076 >    int index = getGenMatchedParticleIndex(object);
2077 >    if(index == -1) value = 24;
2078 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2079 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2080 >      if(motherIndex == -1) value = 24;
2081 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2082 >    }
2083 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2084 >  }
2085 >  else if(variable == "pfMuonsFromVertex"){
2086 >    double d0Error, dzError;
2087 >
2088 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2089 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2090 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2091 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2092 >      || fabs (object->correctedDZ / dzError) > 99.0;
2093 >    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
2094 >  }
2095 >
2096 >
2097 >
2098 >  else{clog << "WARNING: invalid muon variable '" << variable << "'\n"; value = -999;}
2099  
2100    value = applyFunction(function, value);
2101  
2102    return value;
2103 < }
2103 > } // end muon valueLookup
2104  
2105  
2106 + //!electron valueLookup
2107   double
2108 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
2108 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
2109  
2110    double value = 0.0;
2111    if(variable == "energy") value = object->energy;
# Line 972 | Line 2266 | OSUAnalysis::valueLookup (const BNelectr
2266    else if(variable == "passConvVeto") value = object->passConvVeto;
2267  
2268    //user-defined variables
2269 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
2270 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
2271 <  else if(variable == "detIso") value = (object->trackIso + object->caloIso) / object->pt;
2269 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2270 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2271 >  else if(variable == "detIso") value = (object->trackIso) / object->pt;
2272    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2273 +  else if(variable == "relPFrhoIsoEB") value = object->isEB ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2274 +  else if(variable == "relPFrhoIsoEE") value = object->isEE ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2275 +  else if(variable == "metMT") {
2276 +    if (const BNmet *met = chosenMET ())
2277 +      {
2278 +        double dPhi = deltaPhi (object->phi, met->phi);
2279 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2280 +      }
2281 +    else
2282 +      value = -999;
2283 +  }
2284 +
2285 +  else if(variable == "ptPlusMet") {
2286 +    // Calculate the magnitude of the vector sum of the electron pT and the Met.  
2287 +    if (const BNmet *met = chosenMET ())
2288 +      {
2289 +        TVector2 p2Met;
2290 +        TVector2 p2Elec;
2291 +        p2Met. SetMagPhi(   met->pt,    met->phi);
2292 +        p2Elec.SetMagPhi(object->pt, object->phi);  
2293 +        TVector2 p2MetElec = p2Met + p2Elec;
2294 +        value = p2MetElec.Mod();  
2295 +      }
2296 +    else
2297 +      value = -999;
2298 +  }
2299 +
2300 +  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
2301 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
2302 +    else value = -999;
2303 +  }
2304 +  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
2305 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
2306 +    else value = -999;
2307 +  }
2308 +
2309 +  else if(variable == "correctedD0VertexInEBPlus"){
2310 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
2311 +    else value = -999;
2312 +  }
2313 +  else if(variable == "correctedD0VertexOutEBPlus"){
2314 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
2315 +    else value = -999;
2316 +  }
2317 +  else if(variable == "correctedD0VertexEEPlus"){
2318 +    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
2319 +    else value = -999;
2320 +  }
2321 +
2322 +  else if(variable == "correctedD0BeamspotInEBPlus"){
2323 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
2324 +    else value = -999;
2325 +  }
2326 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
2327 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
2328 +    else value = -999;
2329 +  }
2330 +  else if(variable == "correctedD0BeamspotEEPlus"){
2331 +    if(object->isEE && object->eta > 0) value = object->correctedD0;
2332 +    else value = -999;
2333 +  }
2334 +
2335 +  else if(variable == "correctedD0VertexInEBMinus"){
2336 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
2337 +    else value = -999;
2338 +  }
2339 +  else if(variable == "correctedD0VertexOutEBMinus"){
2340 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
2341 +    else value = -999;
2342 +  }
2343 +  else if(variable == "correctedD0VertexEEMinus"){
2344 +    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
2345 +    else value = -999;
2346 +  }
2347  
2348 +  else if(variable == "correctedD0BeamspotInEBMinus"){
2349 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
2350 +    else value = -999;
2351 +  }
2352 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
2353 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
2354 +    else value = -999;
2355 +  }
2356 +  else if(variable == "correctedD0BeamspotEEMinus"){
2357 +    if(object->isEE && object->eta < 0) value = object->correctedD0;
2358 +    else value = -999;
2359 +  }
2360  
2361 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2361 >  else if(variable == "looseID"){
2362 >    if (object->isEB)
2363 >      {
2364 >        value = fabs(object->delEtaIn) < 0.007 \
2365 >          && fabs (object->delPhiIn) < 0.15 \
2366 >          && object->scSigmaIEtaIEta < 0.01 \
2367 >          && object->hadOverEm < 0.12 \
2368 >          && fabs (object->correctedD0Vertex) < 0.02 \
2369 >          && fabs (object->correctedDZ) < 0.2 \
2370 >          && object->absInvEMinusInvPin < 0.05 \
2371 >          && object->passConvVeto;
2372 >      }
2373 >    else
2374 >      {
2375 >        value = fabs(object->delEtaIn) < 0.009 \
2376 >          && fabs (object->delPhiIn) < 0.10 \
2377 >          && object->scSigmaIEtaIEta < 0.03 \
2378 >          && object->hadOverEm < 0.10 \
2379 >          && fabs (object->correctedD0Vertex) < 0.02 \
2380 >          && fabs (object->correctedDZ) < 0.2 \
2381 >          && object->absInvEMinusInvPin < 0.05 \
2382 >          && object->passConvVeto;
2383 >      }
2384 >  }
2385 >
2386 >  else if(variable == "tightID"){
2387 >    if (object->isEB)
2388 >      {
2389 >        value = fabs(object->delEtaIn) < 0.004 \
2390 >          && fabs (object->delPhiIn) < 0.03 \
2391 >          && object->scSigmaIEtaIEta < 0.01 \
2392 >          && object->hadOverEm < 0.12 \
2393 >          && fabs (object->correctedD0Vertex) < 0.02 \
2394 >          && fabs (object->correctedDZ) < 0.1 \
2395 >          && object->absInvEMinusInvPin < 0.05 \
2396 >          && object->passConvVeto;
2397 >      }
2398 >    else
2399 >      {
2400 >        value = fabs(object->delEtaIn) < 0.005 \
2401 >          && fabs (object->delPhiIn) < 0.02 \
2402 >          && object->scSigmaIEtaIEta < 0.03 \
2403 >          && object->hadOverEm < 0.10 \
2404 >          && fabs (object->correctedD0Vertex) < 0.02 \
2405 >          && fabs (object->correctedDZ) < 0.1 \
2406 >          && object->absInvEMinusInvPin < 0.05 \
2407 >          && object->passConvVeto;
2408 >      }
2409 >  }
2410 >
2411 >  else if(variable == "looseID_MVA"){
2412 >    value = object->pt > 10
2413 >      && object->mvaNonTrigV0 > 0;
2414 >      }
2415 >  else if(variable == "correctedD0VertexInEBPositiveCharge"){
2416 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2417 >    else value = -999;
2418 >  }
2419 >  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
2420 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2421 >    else value = -999;
2422 >  }
2423 >  else if(variable == "correctedD0VertexEEPositiveCharge"){
2424 >    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
2425 >    else value = -999;
2426 >  }
2427 >
2428 >  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
2429 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
2430 >    else value = -999;
2431 >  }
2432 >  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
2433 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
2434 >    else value = -999;
2435 >  }
2436 >  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
2437 >    if(object->isEE && object->charge > 0) value = object->correctedD0;
2438 >    else value = -999;
2439 >  }
2440 >
2441 >  else if(variable == "correctedD0VertexInEBNegativeCharge"){
2442 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2443 >    else value = -999;
2444 >  }
2445 >  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
2446 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2447 >    else value = -999;
2448 >  }
2449 >  else if(variable == "correctedD0VertexEENegativeCharge"){
2450 >    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
2451 >    else value = -999;
2452 >  }
2453 >
2454 >  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
2455 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
2456 >    else value = -999;
2457 >  }
2458 >  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
2459 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
2460 >    else value = -999;
2461 >  }
2462 >  else if(variable == "correctedD0BeamspotEENegativeCharge"){
2463 >    if(object->isEE && object->charge < 0) value = object->correctedD0;
2464 >    else value = -999;
2465 >  }
2466 >
2467 >
2468 >  else if(variable == "tightIDdisplaced"){
2469 >    if (object->isEB)
2470 >      {
2471 >        value = fabs(object->delEtaIn) < 0.004 \
2472 >          && fabs (object->delPhiIn) < 0.03 \
2473 >          && object->scSigmaIEtaIEta < 0.01 \
2474 >          && object->hadOverEm < 0.12 \
2475 >          && object->absInvEMinusInvPin < 0.05;
2476 >      }
2477 >    else
2478 >      {
2479 >        value = fabs (object->delEtaIn) < 0.005 \
2480 >          && fabs (object->delPhiIn) < 0.02 \
2481 >          && object->scSigmaIEtaIEta < 0.03 \
2482 >          && object->hadOverEm < 0.10 \
2483 >          && object->absInvEMinusInvPin < 0.05;
2484 >      }
2485 >  }
2486 >
2487 >
2488 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2489 >
2490 >  else if(variable == "genMatchedPdgId"){
2491 >    int index = getGenMatchedParticleIndex(object);
2492 >    if(index == -1) value = 0;
2493 >    else value = mcparticles->at(index).id;
2494 >  }
2495 >
2496 >
2497 >  else if(variable == "genMatchedId"){
2498 >    int index = getGenMatchedParticleIndex(object);
2499 >    if(index == -1) value = 0;
2500 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2501 >  }
2502 >  else if(variable == "genMatchedMotherId"){
2503 >    int index = getGenMatchedParticleIndex(object);
2504 >    if(index == -1) value = 0;
2505 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2506 >  }
2507 >  else if(variable == "genMatchedMotherIdReverse"){
2508 >    int index = getGenMatchedParticleIndex(object);
2509 >    if(index == -1) value = 24;
2510 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2511 >  }
2512 >  else if(variable == "genMatchedGrandmotherId"){
2513 >    int index = getGenMatchedParticleIndex(object);
2514 >    if(index == -1) value = 0;
2515 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2516 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2517 >      if(motherIndex == -1) value = 0;
2518 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2519 >    }
2520 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2521 >  }
2522 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2523 >    int index = getGenMatchedParticleIndex(object);
2524 >    if(index == -1) value = 24;
2525 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2526 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2527 >      if(motherIndex == -1) value = 24;
2528 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2529 >    }
2530 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2531 >  }
2532 >  else if(variable == "pfElectronsFromVertex"){
2533 >    double d0Error, dzError;
2534 >
2535 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2536 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2537 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2538 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2539 >      || fabs (object->correctedDZ / dzError) > 99.0;
2540 >    value = !value;
2541 >  }
2542 >
2543 >
2544 >
2545 >  else{clog << "WARNING: invalid electron variable '" << variable << "'\n"; value = -999;}
2546  
2547    value = applyFunction(function, value);
2548  
2549    return value;
2550 < }
2550 > } // end electron valueLookup
2551  
2552  
2553 + //!event valueLookup
2554   double
2555 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2555 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2556  
2557    double value = 0.0;
2558  
# Line 1055 | Line 2620 | OSUAnalysis::valueLookup (const BNevent*
2620    else if(variable == "id1") value = object->id1;
2621    else if(variable == "id2") value = object->id2;
2622    else if(variable == "evt") value = object->evt;
2623 <
2624 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2623 >  else if(variable == "puScaleFactor"){
2624 >    if(doPileupReweighting_ && datasetType_ != "data")
2625 >      value = puWeight_->at (events->at (0).numTruePV);
2626 >    else
2627 >      value = 1.0;
2628 >  }
2629 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2630 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2631 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2632 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2633 >
2634 >  else if(variable == "unfilteredHt") value = getHt(jets.product());
2635 >  else if(variable == "ht") value = chosenHT ();
2636 >
2637 >  else if(variable == "leadMuPairInvMass"){
2638 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2639 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2640 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2641 >    value = (p0 + p1).M ();
2642 >  }
2643 >  else if(variable == "leadMuPairPt"){
2644 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2645 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2646 >             pt1 (muPair.second->px, muPair.second->py);
2647 >    pt0 += pt1;
2648 >    value = pt0.Mod ();
2649 >  }
2650 >  else if(variable == "leadElPairInvMass"){
2651 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2652 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2653 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2654 >    value = (p0 + p1).M ();
2655 >  }
2656 >  else if(variable == "leadElPairPt"){
2657 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2658 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2659 >             pt1 (muPair.second->px, muPair.second->py);
2660 >    pt0 += pt1;
2661 >    value = pt0.Mod ();
2662 >  }
2663 >  else{clog << "WARNING: invalid event variable '" << variable << "'\n"; value = -999;}
2664  
2665    value = applyFunction(function, value);
2666  
2667    return value;
2668 < }
2668 > } // end event valueLookup
2669  
2670 +
2671 + //!tau valueLookup
2672   double
2673 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2673 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2674  
2675    double value = 0.0;
2676  
# Line 1108 | Line 2714 | OSUAnalysis::valueLookup (const BNtau* o
2714    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2715    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2716  
2717 +  else if (variable == "looseHadronicID") {
2718 +    //criteria taken from http://cms.cern.ch/iCMS/jsp/db_notes/showNoteDetails.jsp?noteID=CMS%20AN-2011/019
2719 +    value = object->pt > 30
2720 +      && fabs(object->eta) < 2.3
2721 +      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2722 +      && object->HPSdecayModeFinding > 0
2723 +      && object->HPSagainstElectronLoose > 0
2724 +      && object->HPSagainstMuonTight > 0;
2725 +  }
2726  
2727 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2727 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2728 >
2729 >  else if(variable == "genMatchedPdgId"){
2730 >    int index = getGenMatchedParticleIndex(object);
2731 >    if(index == -1) value = 0;
2732 >    else value = mcparticles->at(index).id;
2733 >  }
2734 >
2735 >  else if(variable == "genMatchedId"){
2736 >    int index = getGenMatchedParticleIndex(object);
2737 >    if(index == -1) value = 0;
2738 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2739 >  }
2740 >  else if(variable == "genMatchedMotherId"){
2741 >    int index = getGenMatchedParticleIndex(object);
2742 >    if(index == -1) value = 0;
2743 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2744 >  }
2745 >  else if(variable == "genMatchedMotherIdReverse"){
2746 >    int index = getGenMatchedParticleIndex(object);
2747 >    if(index == -1) value = 24;
2748 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2749 >  }
2750 >  else if(variable == "genMatchedGrandmotherId"){
2751 >    int index = getGenMatchedParticleIndex(object);
2752 >    if(index == -1) value = 0;
2753 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2754 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2755 >      if(motherIndex == -1) value = 0;
2756 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2757 >    }
2758 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2759 >  }
2760 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2761 >    int index = getGenMatchedParticleIndex(object);
2762 >    if(index == -1) value = 24;
2763 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2764 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2765 >      if(motherIndex == -1) value = 24;
2766 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2767 >    }
2768 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2769 >  }
2770 >
2771 >
2772 >  else{clog << "WARNING: invalid tau variable '" << variable << "'\n"; value = -999;}
2773  
2774    value = applyFunction(function, value);
2775  
2776    return value;
2777 < }
2777 > } // end tau valueLookup
2778  
2779 +
2780 + //!met valueLookup
2781   double
2782 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2782 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2783  
2784    double value = 0.0;
2785  
# Line 1181 | Line 2843 | OSUAnalysis::valueLookup (const BNmet* o
2843    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2844    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2845  
2846 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2846 >  else{clog << "WARNING: invalid met variable '" << variable << "'\n"; value = -999;}
2847  
2848    value = applyFunction(function, value);
2849  
2850    return value;
2851 < }
2851 > } // end met valueLookup
2852  
2853 +
2854 + //!track valueLookup
2855   double
2856 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2856 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2857  
2858    double value = 0.0;
2859 +  double pMag = sqrt(object->pt * object->pt +
2860 +                     object->pz * object->pz);
2861  
2862    if(variable == "pt") value = object->pt;
2863    else if(variable == "px") value = object->px;
# Line 1211 | Line 2877 | OSUAnalysis::valueLookup (const BNtrack*
2877    else if(variable == "numValidHits") value = object->numValidHits;
2878    else if(variable == "isHighPurity") value = object->isHighPurity;
2879  
2880 +  //additional BNs info for disappTrks
2881 +  else if(variable == "caloEMDeltaRp3")     value = object->caloEMDeltaRp3;
2882 +  else if(variable == "caloHadDeltaRp3")    value = object->caloHadDeltaRp3;
2883 +  else if(variable == "caloEMDeltaRp4")     value = object->caloEMDeltaRp4;
2884 +  else if(variable == "caloHadDeltaRp4")    value = object->caloHadDeltaRp4;
2885 +  else if(variable == "caloEMDeltaRp5")     value = object->caloEMDeltaRp5;
2886 +  else if(variable == "caloHadDeltaRp5")    value = object->caloHadDeltaRp5;
2887 +  else if(variable == "nHitsMissingOuter")  value = object->nHitsMissingOuter;
2888 +  else if(variable == "nHitsMissingInner")  value = object->nHitsMissingInner;
2889 +  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2890 +  else if(variable == "depTrkRp3")          value = object->depTrkRp3;
2891 +  else if(variable == "trkRelIsoRp3")     { value = (object->depTrkRp3 - object->pt) / object->pt; if (value<0) value = 0; }
2892 +  else if(variable == "trkRelIsoRp5")     { value = (object->depTrkRp5 - object->pt) / object->pt; if (value<0) value = 0; }
2893 +  else if(variable == "depEcalRp3")         value = object->depEcalRp3;
2894 +  else if(variable == "depHcalRp3")         value = object->depHcalRp3;
2895 +  else if(variable == "depHoRp3")           value = object->depHoRp3;
2896 +  else if(variable == "nTracksRp3")         value = object->nTracksRp3;
2897 +  else if(variable == "trackerVetoPtRp3")   value = object->trackerVetoPtRp3;
2898 +  else if(variable == "emVetoEtRp3")        value = object->emVetoEtRp3;
2899 +  else if(variable == "hadVetoEtRp3")       value = object->hadVetoEtRp3;
2900 +  else if(variable == "hoVetoEtRp3")        value = object->hoVetoEtRp3;
2901 +  else if(variable == "depTrkRp5")          value = object->depTrkRp5;
2902 +  else if(variable == "depEcalRp5")         value = object->depEcalRp5;
2903 +  else if(variable == "depHcalRp5")         value = object->depHcalRp5;
2904 +  else if(variable == "depHoRp5")           value = object->depHoRp5;
2905 +  else if(variable == "nTracksRp5")         value = object->nTracksRp5;
2906 +  else if(variable == "trackerVetoPtRp5")   value = object->trackerVetoPtRp5;
2907 +  else if(variable == "emVetoEtRp5")        value = object->emVetoEtRp5;
2908 +  else if(variable == "hadVetoEtRp5")       value = object->hadVetoEtRp5;
2909 +  else if(variable == "hoVetoEtRp5")        value = object->hoVetoEtRp5;
2910 +
2911 +  //user defined variables
2912 +  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;
2913 +  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2914 +  else if(variable == "depTrkRp5MinusPt"){
2915 +    if ( (object->depTrkRp5 - object->pt) < 0 ) {
2916 + //       clog << "Warning:  found track with depTrkRp5 < pt:  depTrkRp5=" << object->depTrkRp5
2917 + //         << "; pt=" << object->pt
2918 + //         << "; object->depTrkRp5 - object->pt = " << object->depTrkRp5 - object->pt
2919 + //         << endl;  
2920 +           value = 0;
2921 +         }
2922 +         else value =  (object->depTrkRp5 - object->pt);
2923 +  }
2924 +  else if(variable == "depTrkRp3MinusPt"){
2925 +    if ( (object->depTrkRp3 - object->pt) < 0 ) {
2926 +      value = 0;
2927 +    }
2928 +    else value =  (object->depTrkRp3 - object->pt);
2929 +  }
2930  
2931 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2931 >  else if(variable == "dPhiMet") {
2932 >    if (const BNmet *met = chosenMET ()) {
2933 >      value = deltaPhi (object->phi, met->phi);
2934 >    } else value = -999;
2935 >  }
2936 >  
2937 >  
2938 >  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2939 >  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2940 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2941 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2942 >  else if(variable == "depTrkRp5RhoCorr")           value = getTrkDepTrkRp5RhoCorr(object);
2943 >  else if(variable == "depTrkRp3RhoCorr")           value = getTrkDepTrkRp3RhoCorr(object);
2944 >
2945 >  else if(variable == "depTrkRp5MinusPtRhoCorr")    {
2946 >    if ( (getTrkDepTrkRp5RhoCorr(object) - object->pt) < 0 ) value = 0;
2947 >    else {value = (getTrkDepTrkRp5RhoCorr(object) - object->pt );}
2948 >  }
2949 >  
2950 >  else if(variable == "depTrkRp3MinusPtRhoCorr")    
2951 >    {
2952 >      if ( (getTrkDepTrkRp3RhoCorr(object) - object->pt) < 0 ) value = 0;
2953 >      else {value = (getTrkDepTrkRp3RhoCorr(object) - object->pt );}
2954 >    }
2955 >
2956 >  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2957 >  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2958 >  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2959 >  else if(variable == "ptError")                    value = object->ptError;
2960 >  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2961 >  else if (variable == "d0wrtPV"){
2962 >    double vx = object->vx - chosenVertex ()->x,
2963 >      vy = object->vy - chosenVertex ()->y,
2964 >      px = object->px,
2965 >      py = object->py,
2966 >      pt = object->pt;
2967 >    value = (-vx * py + vy * px) / pt;
2968 >  }
2969 >  else if (variable == "dZwrtPV"){
2970 >    double vx = object->vx - chosenVertex ()->x,
2971 >      vy = object->vy - chosenVertex ()->y,
2972 >      vz = object->vz - chosenVertex ()->z,
2973 >      px = object->px,
2974 >      py = object->py,
2975 >      pz = object->pz,
2976 >      pt = object->pt;
2977 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2978 >  }
2979 >
2980 >  else if(variable == "deltaRMinSubLeadJet") {
2981 >    // calculate minimum deltaR between track and any other subleading jet  
2982 >    double trkJetDeltaRMin = 99.;  
2983 >    if (!jets.product()) clog << "ERROR:  cannot find deltaRMinSubLeadJet because jets collection is not initialized." << endl;
2984 >    for (uint ijet = 0; ijet<jets->size(); ijet++) {
2985 >      string empty = "";  
2986 >      double isSubLeadingJet = valueLookup(&jets->at(ijet), "disappTrkSubLeadingJetID", "", empty);  
2987 >      if (!isSubLeadingJet) continue;  // only consider jets that pass the subleading jet ID criteria  
2988 >      double jetEta = valueLookup(&jets->at(ijet), "eta", "", empty);
2989 >      double jetPhi = valueLookup(&jets->at(ijet), "phi", "", empty);
2990 >      double trkJetDeltaR = deltaR(object->eta, object->phi, jetEta, jetPhi);  
2991 >      if (trkJetDeltaR < trkJetDeltaRMin) trkJetDeltaRMin = trkJetDeltaR;
2992 >    }
2993 >    value = trkJetDeltaRMin;  
2994 >  }  
2995 >  
2996 >  else if(variable == "deltaRMinElecLooseMvaId") {
2997 >    // calculate minimum deltaR between track and any other electron passing loose mva ID, i.e., mvaNonTrigV0 > 0
2998 >    double trkElecDeltaRMin = 99.;  
2999 >    if (!electrons.product()) clog << "ERROR:  cannot find deltaRMinElecLooseMvaId because electrons collection is not initialized." << endl;
3000 >    for (uint ielec = 0; ielec<electrons->size(); ielec++) {
3001 >      string empty = "";  
3002 >      double mvaNonTrigV0 = valueLookup(&electrons->at(ielec), "mvaNonTrigV0", "", empty);  
3003 >      if (mvaNonTrigV0 < 0) continue;  // only consider electrons with mvaNonTrigV0 > 0  
3004 >      double elecEta = valueLookup(&electrons->at(ielec), "eta", "", empty);
3005 >      double elecPhi = valueLookup(&electrons->at(ielec), "phi", "", empty);
3006 >      double trkElecDeltaR = deltaR(object->eta, object->phi, elecEta, elecPhi);  
3007 >      if (trkElecDeltaR < trkElecDeltaRMin) trkElecDeltaRMin = trkElecDeltaR;
3008 >    }
3009 >    value = trkElecDeltaRMin;  
3010 >  }  
3011 >
3012 >  else if(variable == "deltaRMinMuonLooseId") {
3013 >    // calculate minimum deltaR between track and any other loose-Id muon
3014 >    double trkMuonDeltaRMin = 99.;  
3015 >    if (!muons.product()) clog << "ERROR:  cannot find deltaRMinMuonLooseId because muons collection is not initialized." << endl;
3016 >    for (uint imuon = 0; imuon<muons->size(); imuon++) {
3017 >      string empty = "";  
3018 >      double isLooseIdMuon = valueLookup(&muons->at(imuon), "looseID", "", empty);  
3019 >      if (!isLooseIdMuon) continue;  // only consider muons that pass the looseID criteria  
3020 >      double muonEta = valueLookup(&muons->at(imuon), "eta", "", empty);
3021 >      double muonPhi = valueLookup(&muons->at(imuon), "phi", "", empty);
3022 >      double trkMuonDeltaR = deltaR(object->eta, object->phi, muonEta, muonPhi);  
3023 >      if (trkMuonDeltaR < trkMuonDeltaRMin) trkMuonDeltaRMin = trkMuonDeltaR;
3024 >    }
3025 >    value = trkMuonDeltaRMin;  
3026 >  }  
3027 >
3028 >  else if(variable == "isPassMuonLooseIDVeto") {
3029 >
3030 >    // calculate minimum deltaR between track and any other loose-Id
3031 >    double trkMuonDeltaRMin = 99.;
3032 >    if (!muons.product()) clog << "ERROR:  cannot find deltaRMinMuonLooseId because muons collection is not initialized." << endl;
3033 >    for (uint imuon = 0; imuon<muons->size(); imuon++) {
3034 >      string empty = "";
3035 >      double isLooseIdMuon = valueLookup(&muons->at(imuon), "looseID", "", empty);
3036 >      if (!isLooseIdMuon) continue;  // only consider muons that pass the looseID                                
3037 >        double muonEta = valueLookup(&muons->at(imuon), "eta", "", empty);
3038 >        double muonPhi = valueLookup(&muons->at(imuon), "phi", "", empty);
3039 >        double trkMuonDeltaR = deltaR(object->eta, object->phi, muonEta, muonPhi);
3040 >        if (trkMuonDeltaR < trkMuonDeltaRMin) trkMuonDeltaRMin = trkMuonDeltaR;
3041 >    }
3042 >    if (trkMuonDeltaRMin  < 0.15) value = 1;
3043 >    if (trkMuonDeltaRMin  > 0.15) value = 0;
3044 >  }
3045 >
3046 >
3047 >  
3048 >  else if(variable == "deltaRMinSecMuonLooseIdGlobal") {
3049 >    // calculate minimum deltaR between track and any other loose-Id muon
3050 >    double trkMuonDeltaRMin = 99.;  
3051 >    if (!secMuons.product()) clog << "ERROR:  cannot find deltaRMinSecMuonLooseIdGlobal because secMuons collection is not initialized." << endl;
3052 >    for (uint imuon = 0; imuon<secMuons->size(); imuon++) {  
3053 >      string empty = "";  
3054 >      double isLooseIdMuon = valueLookup(&secMuons->at(imuon), "looseIDGlobalMuon", "", empty);  
3055 >      if (!isLooseIdMuon) continue;  // only consider muons that pass the looseIDGlobal criteria  
3056 >      double muonEta = valueLookup(&secMuons->at(imuon), "eta", "", empty);
3057 >      double muonPhi = valueLookup(&secMuons->at(imuon), "phi", "", empty);
3058 >      double trkMuonDeltaR = deltaR(object->eta, object->phi, muonEta, muonPhi);  
3059 >      if (trkMuonDeltaR < trkMuonDeltaRMin) trkMuonDeltaRMin = trkMuonDeltaR;
3060 >    }
3061 >    value = trkMuonDeltaRMin;  
3062 >  }  
3063 >  
3064 >  else if(variable == "deltaRMinTauLooseHadronicId") {
3065 >    // calculate minimum deltaR between track and any other tau passing loose hadronic ID  
3066 >    double trkTauDeltaRMin = 99.;  
3067 >    if (!taus.product()) clog << "ERROR:  cannot find deltaRMinTauLooseHadronicId because taus collection is not initialized." << endl;
3068 >    for (uint itau = 0; itau<taus->size(); itau++) {
3069 >      string empty = "";  
3070 >      double isIdTau = valueLookup(&taus->at(itau), "looseHadronicID", "", empty);  
3071 >      if (!isIdTau) continue;  // only consider taus that pass the loose hadronic ID criteria  
3072 >      double tauEta = valueLookup(&taus->at(itau), "eta", "", empty);
3073 >      double tauPhi = valueLookup(&taus->at(itau), "phi", "", empty);
3074 >      double trkTauDeltaR = deltaR(object->eta, object->phi, tauEta, tauPhi);  
3075 >      if (trkTauDeltaR < trkTauDeltaRMin) trkTauDeltaRMin = trkTauDeltaR;
3076 >    }
3077 >    value = trkTauDeltaRMin;  
3078 >  }  
3079 >
3080 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3081 >
3082 >  else if(variable == "genMatchedPdgId"){
3083 >    int index = getGenMatchedParticleIndex(object);
3084 >    if(index == -1) value = 0;
3085 >    else value = mcparticles->at(index).id;
3086 >  }
3087 >
3088 >
3089 >  else if(variable == "genMatchedId"){
3090 >    int index = getGenMatchedParticleIndex(object);
3091 >    if(index == -1) value = 0;
3092 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
3093 >  }
3094 >  else if(variable == "genMatchedMotherId"){
3095 >    int index = getGenMatchedParticleIndex(object);
3096 >    if(index == -1) value = 0;
3097 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
3098 >  }
3099 >  else if(variable == "genMatchedMotherIdReverse"){
3100 >    int index = getGenMatchedParticleIndex(object);
3101 >    if(index == -1) value = 24;
3102 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
3103 >  }
3104 >  else if(variable == "genMatchedGrandmotherId"){
3105 >    int index = getGenMatchedParticleIndex(object);
3106 >    if(index == -1) value = 0;
3107 >    else if(fabs(mcparticles->at(index).motherId) == 15){
3108 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3109 >      if(motherIndex == -1) value = 0;
3110 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3111 >    }
3112 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3113 >  }
3114 >  else if(variable == "genMatchedGrandmotherIdReverse"){
3115 >    int index = getGenMatchedParticleIndex(object);
3116 >    if(index == -1) value = 24;
3117 >    else if(fabs(mcparticles->at(index).motherId) == 15){
3118 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3119 >      if(motherIndex == -1) value = 24;
3120 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3121 >    }
3122 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3123 >  }
3124 >
3125 >
3126 >
3127 >  else{clog << "WARNING: invalid track variable '" << variable << "'\n"; value = -999;}
3128  
3129    value = applyFunction(function, value);
3130  
3131    return value;
3132 < }
3132 > } // end track valueLookup
3133 >
3134  
3135 + //!genjet valueLookup
3136   double
3137 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
3137 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
3138  
3139    double value = 0.0;
3140  
# Line 1240 | Line 3154 | OSUAnalysis::valueLookup (const BNgenjet
3154    else if(variable == "charge") value = object->charge;
3155  
3156  
3157 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3157 >  else{clog << "WARNING: invalid genjet variable '" << variable << "'\n"; value = -999;}
3158  
3159    value = applyFunction(function, value);
3160  
3161    return value;
3162   }
3163  
3164 + //!mcparticle valueLookup
3165   double
3166 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
3166 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
3167  
3168    double value = 0.0;
3169  
# Line 1339 | Line 3254 | OSUAnalysis::valueLookup (const BNmcpart
3254  
3255    //user-defined variables
3256    else if (variable == "d0"){
3257 <    double vx = object->vx - primaryVertex_->x,
3258 <      vy = object->vy - primaryVertex_->y,
3257 >    double vx = object->vx - chosenVertex ()->x,
3258 >      vy = object->vy - chosenVertex ()->y,
3259        px = object->px,
3260        py = object->py,
3261        pt = object->pt;
3262      value = (-vx * py + vy * px) / pt;
3263    }
3264    else if (variable == "dz"){
3265 <    double vx = object->vx - primaryVertex_->x,
3266 <      vy = object->vy - primaryVertex_->y,
3267 <      vz = object->vz - primaryVertex_->z,
3265 >    double vx = object->vx - chosenVertex ()->x,
3266 >      vy = object->vy - chosenVertex ()->y,
3267 >      vz = object->vz - chosenVertex ()->z,
3268        px = object->px,
3269        py = object->py,
3270        pz = object->pz,
3271        pt = object->pt;
3272      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3273    }
3274 +  else if(variable == "v0"){
3275 +    value = sqrt(object->vx*object->vx + object->vy*object->vy);
3276 +  }
3277 +  else if(variable == "deltaV0"){
3278 +    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
3279 +  }
3280 +  else if (variable == "deltaVx"){
3281 +    value = object->vx - chosenVertex ()->x;
3282 +  }
3283 +  else if (variable == "deltaVy"){
3284 +    value = object->vy - chosenVertex ()->y;
3285 +  }
3286 +  else if (variable == "deltaVz"){
3287 +    value = object->vz - chosenVertex ()->z;
3288 +  }
3289  
3290  
3291 <
1362 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3291 >  else{clog << "WARNING: invalid mcparticle variable '" << variable << "'\n"; value = -999;}
3292  
3293    value = applyFunction(function, value);
3294  
3295    return value;
3296 < }
3296 > } // end mcparticle valueLookup
3297  
3298 +
3299 + //!primaryvertex valueLookup
3300   double
3301 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
3301 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
3302  
3303    double value = 0.0;
3304  
# Line 1386 | Line 3317 | OSUAnalysis::valueLookup (const BNprimar
3317    else if(variable == "isGood") value = object->isGood;
3318  
3319  
3320 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3320 >  else{clog << "WARNING: invalid primaryvertex variable '" << variable << "'\n"; value = -999;}
3321  
3322    value = applyFunction(function, value);
3323  
3324    return value;
3325   }
3326  
3327 + //!bxlumi valueLookup
3328   double
3329 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
3329 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
3330  
3331    double value = 0.0;
3332  
# Line 1403 | Line 3335 | OSUAnalysis::valueLookup (const BNbxlumi
3335    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
3336  
3337  
3338 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3338 >  else{clog << "WARNING: invalid bxlumi variable '" << variable << "'\n"; value = -999;}
3339  
3340    value = applyFunction(function, value);
3341  
3342    return value;
3343   }
3344  
3345 + //!photon valueLookup
3346   double
3347 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
3347 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
3348  
3349    double value = 0.0;
3350  
# Line 1486 | Line 3419 | OSUAnalysis::valueLookup (const BNphoton
3419    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
3420  
3421  
3422 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3422 >
3423 >
3424 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3425 >
3426 >  else if(variable == "genMatchedPdgId"){
3427 >    int index = getGenMatchedParticleIndex(object);
3428 >    if(index == -1) value = 0;
3429 >    else value = mcparticles->at(index).id;
3430 >  }
3431 >
3432 >
3433 >
3434 >  else if(variable == "genMatchedId"){
3435 >    int index = getGenMatchedParticleIndex(object);
3436 >    if(index == -1) value = 0;
3437 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
3438 >  }
3439 >  else if(variable == "genMatchedMotherId"){
3440 >    int index = getGenMatchedParticleIndex(object);
3441 >    if(index == -1) value = 0;
3442 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
3443 >  }
3444 >  else if(variable == "genMatchedMotherIdReverse"){
3445 >    int index = getGenMatchedParticleIndex(object);
3446 >    if(index == -1) value = 24;
3447 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
3448 >  }
3449 >  else if(variable == "genMatchedGrandmotherId"){
3450 >    int index = getGenMatchedParticleIndex(object);
3451 >    if(index == -1) value = 0;
3452 >    else if(fabs(mcparticles->at(index).motherId) == 15){
3453 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3454 >      if(motherIndex == -1) value = 0;
3455 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3456 >    }
3457 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3458 >  }
3459 >  else if(variable == "genMatchedGrandmotherIdReverse"){
3460 >    int index = getGenMatchedParticleIndex(object);
3461 >    if(index == -1) value = 24;
3462 >    else if(fabs(mcparticles->at(index).motherId) == 15){
3463 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3464 >      if(motherIndex == -1) value = 24;
3465 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3466 >    }
3467 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3468 >  }
3469 >
3470 >
3471 >  else{clog << "WARNING: invalid photon variable '" << variable << "'\n"; value = -999;}
3472  
3473    value = applyFunction(function, value);
3474  
3475    return value;
3476 < }
3476 > } // end photon valueLookup
3477 >
3478  
3479 + //!supercluster valueLookup
3480   double
3481 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
3481 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
3482  
3483    double value = 0.0;
3484  
# Line 1508 | Line 3492 | OSUAnalysis::valueLookup (const BNsuperc
3492    else if(variable == "theta") value = object->theta;
3493  
3494  
3495 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3495 >  else{clog << "WARNING: invalid supercluster variable '" << variable << "'\n"; value = -999;}
3496 >
3497 >  value = applyFunction(function, value);
3498 >
3499 >  return value;
3500 > }
3501 >
3502 > //!trigobj valueLookup
3503 > double
3504 > OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3505 >
3506 >  double value = 0.0;
3507 >
3508 >  if(variable == "pt") value = object->pt;
3509 >  else if(variable == "eta") value = object->eta;
3510 >  else if(variable == "phi") value = object->phi;
3511 >  else if(variable == "px") value = object->px;
3512 >  else if(variable == "py") value = object->py;
3513 >  else if(variable == "pz") value = object->pz;
3514 >  else if(variable == "et") value = object->et;
3515 >  else if(variable == "energy") value = object->energy;
3516 >  else if(variable == "etTotal") value = object->etTotal;
3517 >  else if(variable == "id") value = object->id;
3518 >  else if(variable == "charge") value = object->charge;
3519 >  else if(variable == "isIsolated") value = object->isIsolated;
3520 >  else if(variable == "isMip") value = object->isMip;
3521 >  else if(variable == "isForward") value = object->isForward;
3522 >  else if(variable == "isRPC") value = object->isRPC;
3523 >  else if(variable == "bx") value = object->bx;
3524 >  else if(variable == "filter") {
3525 >    if ((stringValue = object->filter) == "")
3526 >      stringValue = "none";  // stringValue should only be empty if value is filled
3527 >  }
3528 >
3529 >  else{clog << "WARNING: invalid trigobj variable '" << variable << "'\n"; value = -999;}
3530  
3531    value = applyFunction(function, value);
3532  
3533    return value;
3534   }
3535  
3536 + //!muon-muon pair valueLookup
3537 + double
3538 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3539 +
3540 +  double value = 0.0;
3541 +
3542 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3543 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3544 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3545 +  else if(variable == "invMass"){
3546 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3547 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3548 +    value = (fourVector1 + fourVector2).M();
3549 +  }
3550 +  else if(variable == "pt"){
3551 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3552 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3553 +    value = (fourVector1 + fourVector2).Pt();
3554 +  }
3555 +  else if(variable == "threeDAngle")
3556 +    {
3557 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3558 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3559 +      value = (threeVector1.Angle(threeVector2));
3560 +    }
3561 +  else if(variable == "alpha")
3562 +    {
3563 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3564 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3565 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3566 +      value = (pi-threeVector1.Angle(threeVector2));
3567 +    }
3568 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3569 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3570 +  else if(variable == "d0Sign"){
3571 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3572 +    if(d0Sign < 0) value = -0.5;
3573 +    else if (d0Sign > 0) value = 0.5;
3574 +    else value = -999;
3575 +  }
3576 +  else if(variable == "chargeProduct"){
3577 +    value = object1->charge*object2->charge;
3578 +  }
3579 +  else if(variable == "muon1CorrectedD0Vertex"){
3580 +    value = object1->correctedD0Vertex;
3581 +  }
3582 +  else if(variable == "muon2CorrectedD0Vertex"){
3583 +    value = object2->correctedD0Vertex;
3584 +  }
3585 +  else if(variable == "muon1timeAtIpInOut"){
3586 +    value = object1->timeAtIpInOut;
3587 +  }
3588 +  else if(variable == "muon2timeAtIpInOut"){
3589 +    value = object2->timeAtIpInOut;
3590 +  }
3591 +  else if(variable == "muon1correctedD0")
3592 +    {
3593 +      value = object1->correctedD0;
3594 +    }
3595 +  else if(variable == "muon2correctedD0")
3596 +    {
3597 +      value = object2->correctedD0;
3598 +    }
3599 +
3600 +  else{clog << "WARNING: invalid muon-muon pair variable '" << variable << "'\n"; value = -999;}
3601 +
3602 +  value = applyFunction(function, value);
3603 +
3604 +  return value;
3605 + } // end muon-muon pair valueLookup
3606 +
3607 +
3608 + //!muon-photon pair valueLookup
3609 + double
3610 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3611 +
3612 +  double value = 0.0;
3613 +
3614 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3615 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3616 +  else if(variable == "photonEta") value = object2->eta;
3617 +  else if(variable == "photonPt") value = object2->pt;
3618 +  else if(variable == "muonEta") value = object1->eta;
3619 +  else if(variable == "photonPhi") value = object2->phi;
3620 +  else if(variable == "muonPhi") value = object1->phi;
3621 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3622 +  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3623 +  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3624 +  else if(variable == "invMass"){
3625 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3626 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3627 +    value = (fourVector1 + fourVector2).M();
3628 +  }
3629 +  else if(variable == "pt"){
3630 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3631 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3632 +    value = (fourVector1 + fourVector2).Pt();
3633 +  }
3634 +  else if(variable == "threeDAngle")
3635 +    {
3636 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3637 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3638 +      value = (threeVector1.Angle(threeVector2));
3639 +    }
3640 +  else if(variable == "alpha")
3641 +    {
3642 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3643 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3644 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3645 +      value = (pi-threeVector1.Angle(threeVector2));
3646 +    }
3647 +  else{clog << "WARNING: invalid muon-photon pair variable '" << variable << "'\n"; value = -999;}
3648 +
3649 +  value = applyFunction(function, value);
3650 +
3651 +  return value;
3652 + } // end muon-photon pair valueLookup
3653 +
3654 +
3655 + //!electron-photon pair valueLookup
3656 + double
3657 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3658 +
3659 +  double value = 0.0;
3660 +
3661 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3662 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3663 +  else if(variable == "photonEta") value = object2->eta;
3664 +  else if(variable == "photonPt") value = object2->pt;
3665 +  else if(variable == "electronEta") value = object1->eta;
3666 +  else if(variable == "photonPhi") value = object2->phi;
3667 +  else if(variable == "electronPhi") value = object1->phi;
3668 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3669 +  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3670 +  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3671 +  else if(variable == "invMass"){
3672 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3673 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3674 +    value = (fourVector1 + fourVector2).M();
3675 +  }
3676 +  else if(variable == "pt"){
3677 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3678 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3679 +    value = (fourVector1 + fourVector2).Pt();
3680 +  }
3681 +  else if(variable == "threeDAngle")
3682 +    {
3683 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3684 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3685 +      value = (threeVector1.Angle(threeVector2));
3686 +    }
3687 +  else if(variable == "alpha")
3688 +    {
3689 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3690 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3691 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3692 +      value = (pi-threeVector1.Angle(threeVector2));
3693 +    }
3694 +  else{clog << "WARNING: invalid electron-photon pair variable '" << variable << "'\n"; value = -999;}
3695 +
3696 +  value = applyFunction(function, value);
3697 +
3698 +  return value;
3699 + } // end electron-photon pair valueLookup
3700 +
3701 +
3702 + //!electron-electron pair valueLookup
3703 + double
3704 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3705 +
3706 +  double value = 0.0;
3707 +
3708 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3709 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3710 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3711 +  else if(variable == "invMass"){
3712 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3713 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3714 +    value = (fourVector1 + fourVector2).M();
3715 +  }
3716 +  else if(variable == "pt"){
3717 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3718 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3719 +    value = (fourVector1 + fourVector2).Pt();
3720 +  }
3721 +  else if(variable == "threeDAngle")
3722 +    {
3723 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3724 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3725 +      value = (threeVector1.Angle(threeVector2));
3726 +    }
3727 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3728 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3729 +  else if(variable == "d0Sign"){
3730 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3731 +    if(d0Sign < 0) value = -0.5;
3732 +    else if (d0Sign > 0) value = 0.5;
3733 +    else value = -999;
3734 +  }
3735 +  else if(variable == "chargeProduct"){
3736 +    value = object1->charge*object2->charge;
3737 +  }
3738 +  else if(variable == "electron1CorrectedD0Vertex"){
3739 +    value = object1->correctedD0Vertex;
3740 +  }
3741 +  else if(variable == "electron2CorrectedD0Vertex"){
3742 +    value = object2->correctedD0Vertex;
3743 +  }
3744 +  else if(variable == "electron1CorrectedD0"){
3745 +    value = object1->correctedD0;
3746 +  }
3747 +  else if(variable == "electron2CorrectedD0"){
3748 +    value = object2->correctedD0;
3749 +  }
3750 +
3751 +  else{clog << "WARNING: invalid electron-electron pair variable '" << variable << "'\n"; value = -999;}
3752 +
3753 +  value = applyFunction(function, value);
3754 +
3755 +  return value;
3756 + } // end electron-electron pair valueLookup
3757 +
3758 +
3759 + //!electron-muon pair valueLookup
3760 + double
3761 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3762 +
3763 +  double value = 0.0;
3764 +
3765 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3766 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3767 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3768 +  else if(variable == "invMass"){
3769 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3770 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3771 +    value = (fourVector1 + fourVector2).M();
3772 +  }
3773 +  else if(variable == "pt"){
3774 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3775 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3776 +    value = (fourVector1 + fourVector2).Pt();
3777 +  }
3778 +  else if(variable == "threeDAngle")
3779 +    {
3780 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3781 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3782 +      value = (threeVector1.Angle(threeVector2));
3783 +    }
3784 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3785 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3786 +  else if(variable == "d0Sign"){
3787 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3788 +    if(d0Sign < 0) value = -0.5;
3789 +    else if (d0Sign > 0) value = 0.5;
3790 +    else value = -999;
3791 +  }
3792 +  else if(variable == "chargeProduct"){
3793 +    value = object1->charge*object2->charge;
3794 +  }
3795 +  else if(variable == "electronCorrectedD0Vertex"){
3796 +    value = object1->correctedD0Vertex;
3797 +  }
3798 +  else if(variable == "muonCorrectedD0Vertex"){
3799 +    value = object2->correctedD0Vertex;
3800 +  }
3801 +  else if(variable == "electronCorrectedD0"){
3802 +    value = object1->correctedD0;
3803 +  }
3804 +  else if(variable == "muonCorrectedD0"){
3805 +    value = object2->correctedD0;
3806 +  }
3807 +  else if(variable == "electronDetIso"){
3808 +    value = (object1->trackIso) / object1->pt;
3809 +  }
3810 +  else if(variable == "muonDetIso"){
3811 +    value = (object2->trackIsoDR03) / object2->pt;
3812 +  }
3813 +  else if(variable == "electronRelPFrhoIso"){
3814 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3815 +  }
3816 +  else if(variable == "muonRelPFdBetaIso"){
3817 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3818 +  }
3819 +  else{clog << "WARNING: invalid electron-muon pair variable '" << variable << "'\n"; value = -999;}
3820 +  value = applyFunction(function, value);
3821 +
3822 +  return value;
3823 + } // end electron-muon pair valueLookup
3824 +
3825 +
3826 + //!electron-jet pair valueLookup
3827 + double
3828 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3829 +
3830 +  double value = 0.0;
3831 +
3832 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3833 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3834 +  else if(variable == "jetEta") value = object2->eta;
3835 +  else if(variable == "jetPhi") value = object2->phi;
3836 +  else if(variable == "electronEta") value = object1->eta;
3837 +  else if(variable == "electronPhi") value = object1->phi;
3838 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3839 +  else if(variable == "invMass"){
3840 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3841 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3842 +    value = (fourVector1 + fourVector2).M();
3843 +  }
3844 +  else if(variable == "pt"){
3845 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3846 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3847 +    value = (fourVector1 + fourVector2).Pt();
3848 +  }
3849 +  else if(variable == "threeDAngle")
3850 +    {
3851 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3852 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3853 +      value = (threeVector1.Angle(threeVector2));
3854 +    }
3855 +  else if(variable == "chargeProduct"){
3856 +    value = object1->charge*object2->charge;
3857 +  }
3858 +
3859 +  else{clog << "WARNING: invalid electron-jet pair variable '" << variable << "'\n"; value = -999;}
3860 +  value = applyFunction(function, value);
3861 +
3862 +  return value;
3863 + }
3864 +
3865 + //!electron-mcparticle pair valueLookup
3866 + double
3867 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmcparticle* object2, string variable, string function, string &stringValue){
3868 +
3869 +  double value = 0.0;
3870 +
3871 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3872 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3873 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3874 +  else if(variable == "threeDAngle")
3875 +    {
3876 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3877 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3878 +      value = (threeVector1.Angle(threeVector2));
3879 +    }
3880 +  else if(variable == "chargeProduct"){
3881 +    value = object1->charge*object2->charge;
3882 +  }
3883 +
3884 +  else{clog << "WARNING: invalid electron-mcparticle variable '" << variable << "'\n"; value = -999;}
3885 +  value = applyFunction(function, value);
3886 +
3887 +  return value;
3888 + }
3889 +
3890 +
3891 + //!photon-jet pair valueLookup
3892 + double
3893 + OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3894 +
3895 +  double value = 0.0;
3896 +
3897 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3898 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3899 +  else if(variable == "jetEta") value = object2->eta;
3900 +  else if(variable == "jetPhi") value = object2->phi;
3901 +  else if(variable == "photonEta") value = object1->eta;
3902 +  else if(variable == "photonPhi") value = object1->phi;
3903 +  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3904 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3905 +  else if(variable == "invMass"){
3906 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3907 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3908 +    value = (fourVector1 + fourVector2).M();
3909 +  }
3910 +  else if(variable == "pt"){
3911 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3912 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3913 +    value = (fourVector1 + fourVector2).Pt();
3914 +  }
3915 +  else if(variable == "threeDAngle")
3916 +    {
3917 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3918 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3919 +      value = (threeVector1.Angle(threeVector2));
3920 +    }
3921 +  else{clog << "WARNING: invalid photon-jet pair variable '" << variable << "'\n"; value = -999;}
3922 +  value = applyFunction(function, value);
3923 +
3924 +  return value;
3925 + }
3926 +
3927 + // track-jet pair valueLookup
3928 + double
3929 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNjet* object2, string variable, string function, string &stringValue){
3930 +
3931 +  double value = 0.0;
3932 +
3933 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3934 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3935 +
3936 +  else{clog << "WARNING: invalid track-jet pair variable '" << variable << "'\n"; value = -999;}
3937 +  value = applyFunction(function, value);
3938 +
3939 +  return value;
3940 +
3941 + }
3942 +
3943 +
3944 +
3945 + // met-jet pair valueLookup
3946 + double
3947 + OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3948 +
3949 +  double value = 0.0;
3950 +
3951 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3952 +
3953 +  else{clog << "WARNING: invalid met-jet pair variable '" << variable << "'\n"; value = -999;}
3954 +  value = applyFunction(function, value);
3955 +
3956 +  return value;
3957 +
3958 + }  
3959 +
3960 +
3961 +
3962 + //!muon-jet pair valueLookup
3963 + double
3964 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3965 +
3966 +  double value = 0.0;
3967 +
3968 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3969 +  else if(variable == "jetEta") value = object2->eta;
3970 +  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3971 +  else if(variable == "jetPt") value = object2->pt;
3972 +  else if(variable == "jetPhi") value = object2->phi;
3973 +  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3974 +  else if(variable == "muonEta") value = object1->eta;
3975 +  else if(variable == "muonPt") value = object1->pt;
3976 +  else if(variable == "muonPhi") value = object1->phi;
3977 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3978 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3979 +  else if(variable == "invMass"){
3980 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3981 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3982 +    value = (fourVector1 + fourVector2).M();
3983 +  }
3984 +  else if(variable == "pt"){
3985 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3986 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3987 +    value = (fourVector1 + fourVector2).Pt();
3988 +  }
3989 +  else if(variable == "threeDAngle")
3990 +    {
3991 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3992 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3993 +      value = (threeVector1.Angle(threeVector2));
3994 +    }
3995 +  else if(variable == "chargeProduct"){
3996 +    value = object1->charge*object2->charge;
3997 +  }
3998 +
3999 +  else{clog << "WARNING: invalid muon-jet pair variable '" << variable << "'\n"; value = -999;}
4000 +  value = applyFunction(function, value);
4001 +
4002 +  return value;
4003 + } // end muon-jet pair valueLookup
4004 +
4005 +
4006 + //!muon-event valueLookup
4007 + double
4008 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNevent* object2, string variable, string function, string &stringValue){
4009 +
4010 +  double value = 0.0;
4011 +
4012 +  if(variable == "muonEta") value = object1->eta;
4013 +  else if(variable == "muonPt") value = object1->pt;
4014 +  else if(variable == "muonPhi") value = object1->phi;
4015 +  else if(variable == "Ht") value = getHt(jets.product());
4016 +  else if(variable == "pthat")   value = object2->pthat;
4017 +  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
4018 +  else{clog << "WARNING: invalid muon-event pair variable '" << variable << "'\n"; value = -999;}
4019 +  value = applyFunction(function, value);
4020 +
4021 +  return value;
4022 + }
4023 + //!jet-jet pair valueLookup
4024 + double
4025 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
4026 +
4027 +  double value = 0.0;
4028 +
4029 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
4030 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
4031 +  else if(variable == "deltaPt") value = object1->pt - object2->pt;
4032 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4033 +  else if(variable == "invMass"){
4034 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
4035 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
4036 +    value = (fourVector1 + fourVector2).M();
4037 +  }
4038 +  else if(variable == "pt"){
4039 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
4040 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
4041 +    value = (fourVector1 + fourVector2).Pt();
4042 +  }
4043 +  else if(variable == "threeDAngle")
4044 +    {
4045 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
4046 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
4047 +      value = (threeVector1.Angle(threeVector2));
4048 +    }
4049 +  else if(variable == "chargeProduct"){
4050 +    value = object1->charge*object2->charge;
4051 +  }
4052 +
4053 +  else{clog << "WARNING: invalid jet-jet pair variable '" << variable << "'\n"; value = -999;}
4054 +  value = applyFunction(function, value);
4055 +
4056 +  return value;
4057 + }
4058 +
4059 + //!electron-track pair valueLookup
4060 + double
4061 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
4062 +  double electronMass = 0.000511;
4063 +  double value = 0.0;
4064 +  TLorentzVector fourVector1(0, 0, 0, 0);
4065 +  TLorentzVector fourVector2(0, 0, 0, 0);
4066 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
4067 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
4068 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4069 +  else if(variable == "deltaRLooseMvaId") {
4070 +    // only consider electrons that pass "loose MVA id", i.e., mvaNonTrigV0 > 0;
4071 +    // otherwise return very large value (99)  
4072 +    if (object1->mvaNonTrigV0>0) value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4073 +    else                         value = 99.;  
4074 +  }
4075 +  else if(variable == "invMass"){
4076 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
4077 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
4078 +
4079 +    value = (fourVector1 + fourVector2).M();
4080 +  }
4081 +  else if(variable == "chargeProduct"){
4082 +    value = object1->charge*object2->charge;
4083 +  }
4084 +  else{clog << "WARNING: invalid electron-track pair variable '" << variable << "'\n"; value = -999;}
4085 +  value = applyFunction(function, value);
4086 +  return value;
4087 +
4088 + }
4089 +
4090 +
4091 + //!muon-track pair valueLookup
4092 + double
4093 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
4094 +  double value = 0.0;
4095 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
4096 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
4097 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4098 +  else if(variable == "deltaRLooseID") {
4099 +    // only consider muons that pass looseId criteria; otherwise return very large value (99.)  
4100 +    string empty = "";  
4101 +    double isLooseId = valueLookup(object1, "looseID", "", empty);    
4102 +    if (isLooseId) value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4103 +    else           value = 99.;  
4104 +  }
4105 +  else if(variable == "deltaRGlobalMuon") {
4106 +    // only consider muons that pass looseId criteria; otherwise return very large value (99.)  
4107 +    if (object1->isGlobalMuon) value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4108 +    else                       value = 99.;  
4109 +  }
4110 +  else if(variable == "invMass"){
4111 +    double pionMass = 0.140;
4112 +    double muonMass = 0.106;
4113 +    TLorentzVector fourVector1(0, 0, 0, 0);
4114 +    TLorentzVector fourVector2(0, 0, 0, 0);
4115 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
4116 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
4117 +    value = (fourVector1 + fourVector2).M();
4118 +  }
4119 +  else if(variable == "chargeProduct"){
4120 +    value = object1->charge*object2->charge;
4121 +  }
4122 +
4123 +  else{clog << "WARNING: invalid muon-track pair variable '" << variable << "'\n"; value = -999;}
4124 +  value = applyFunction(function, value);
4125 +  return value;
4126 + }
4127 +
4128 + //!tau-tau pair valueLookup
4129 + double
4130 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
4131 +  double value = 0.0;
4132 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
4133 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
4134 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4135 +  else if(variable == "invMass"){
4136 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
4137 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
4138 +    value = (fourVector1 + fourVector2).M();
4139 +  }
4140 +
4141 +  else if(variable == "chargeProduct"){
4142 +    value = object1->charge*object2->charge;
4143 +  }
4144 +
4145 +  else{clog << "WARNING: invalid tau-tau pair variable '" << variable << "'\n"; value = -999;}
4146 +  value = applyFunction(function, value);
4147 +  return value;
4148 + }
4149 +
4150 + //!muon-tau pair valueLookup
4151 + double
4152 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
4153 +  double value = 0.0;
4154 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
4155 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
4156 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4157 +  else if(variable == "invMass"){
4158 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
4159 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
4160 +    value = (fourVector1 + fourVector2).M();
4161 +  }
4162 +
4163 +  else if(variable == "chargeProduct"){
4164 +    value = object1->charge*object2->charge;
4165 +  }
4166 +
4167 +  else{clog << "WARNING: invalid muon-tau pair variable '" << variable << "'\n"; value = -999;}
4168 +  value = applyFunction(function, value);
4169 +  return value;
4170 + }
4171 +
4172 + //!tau-track pair valueLookup
4173 + double
4174 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
4175 +  double value = 0.0;
4176 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
4177 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4178 +  else if(variable == "deltaRLooseHadronicID") {
4179 +    // only consider tau's that pass the loose hadronic ID criteria; otherwise return very large value (99)  
4180 +    string empty = "";  
4181 +    double isLooseHadronicID = valueLookup(object1, "looseHadronicID", "", empty);    
4182 +  
4183 +    if (isLooseHadronicID) value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4184 +    else                   value = 99.;  
4185 +  }
4186 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
4187 +  else if(variable == "invMass"){
4188 +    double tauMass = 1.777;  // PDG 2010
4189 +    double pionMass = 0.140; // PDG 2010  
4190 +    TLorentzVector fourVector1(0, 0, 0, 0);
4191 +    TLorentzVector fourVector2(0, 0, 0, 0);
4192 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, tauMass);
4193 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
4194 +    value = (fourVector1 + fourVector2).M();
4195 +  }
4196 +  else if(variable == "chargeProduct"){
4197 +    value = object1->charge*object2->charge;
4198 +  }
4199 +
4200 +  else{clog << "WARNING: invalid tau-track pair variable '" << variable << "'\n"; value = -999;}
4201 +  value = applyFunction(function, value);
4202 +  return value;
4203 + }
4204 +
4205 +
4206 + //!track-event pair valueLookup
4207 + double
4208 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
4209 +
4210 +  double value = 0.0;
4211 +  double pMag = sqrt(object1->pt * object1->pt +
4212 +                     object1->pz * object1->pz);
4213 +
4214 +  if      (variable == "numPV")                      value = object2->numPV;
4215 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
4216 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
4217 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
4218 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
4219 +
4220 +  else { clog << "WARNING: invalid track-event pair variable '" << variable << "'\n"; value = -999; }
4221 +
4222 +  value = applyFunction(function, value);
4223 +
4224 +  return value;
4225 +
4226 + }
4227 +
4228 + //!electron-trigobj pair valueLookup
4229 + double
4230 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
4231 +
4232 +  double value = 0.0;
4233 +
4234 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4235 +  else if (variable == "match"){
4236 +    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
4237 +      stringValue = object2->filter;
4238 +    else
4239 +      stringValue = "none";
4240 +  }
4241 +
4242 +  else { clog << "WARNING: invalid electron-trigobj variable '" << variable << "'\n"; value = -999; }
4243 +
4244 +  value = applyFunction(function, value);
4245 +
4246 +  return value;
4247 +
4248 + }
4249 +
4250 + //!muon-trigobj pair valueLookup
4251 + double
4252 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
4253 +
4254 +  double value = 0.0;
4255 +
4256 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4257 +
4258 +  else { clog << "WARNING: invalid muon-trigobj variable '" << variable << "'\n"; value = -999; }
4259 +
4260 +  value = applyFunction(function, value);
4261 +
4262 +  return value;
4263 +
4264 + }
4265 +
4266 + //!stop valueLookup
4267 + double
4268 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
4269 +
4270 +
4271 +  double value = 0.0;
4272 +
4273 +  if(variable == "ctau") value = object->ctau;
4274 +
4275 +  else if (variable == "d0"){
4276 +    double vx = object->vx - chosenVertex ()->x,
4277 +      vy = object->vy - chosenVertex ()->y,
4278 +      px = object->px,
4279 +      py = object->py,
4280 +      pt = object->pt;
4281 +    value = (-vx * py + vy * px) / pt;
4282 +  }
4283 +
4284 +  else if (variable == "dz"){
4285 +    double vx = object->vx - chosenVertex ()->x,
4286 +      vy = object->vy - chosenVertex ()->y,
4287 +      vz = object->vz - chosenVertex ()->z,
4288 +      px = object->px,
4289 +      py = object->py,
4290 +      pz = object->pz,
4291 +      pt = object->pt;
4292 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
4293 +  }
4294 +
4295 +  else if (variable == "minD0"){
4296 +    double minD0=999;
4297 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4298 +      double vx = object->vx - vertex->x,
4299 +        vy = object->vy - vertex->y,
4300 +        px = object->px,
4301 +        py = object->py,
4302 +        pt = object->pt;
4303 +      value = (-vx * py + vy * px) / pt;
4304 +      if(abs(value) < abs(minD0)) minD0 = value;
4305 +    }
4306 +    value = minD0;
4307 +  }
4308 +  else if (variable == "minDz"){
4309 +    double minDz=999;
4310 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4311 +      double vx = object->vx - vertex->x,
4312 +        vy = object->vy - vertex->y,
4313 +        vz = object->vz - vertex->z,
4314 +        px = object->px,
4315 +        py = object->py,
4316 +        pz = object->pz,
4317 +        pt = object->pt;
4318 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
4319 +      if(abs(value) < abs(minDz)) minDz = value;
4320 +    }
4321 +    value = minDz;
4322 +  }
4323 +  else if(variable == "distToVertex"){
4324 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4325 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4326 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4327 +  }
4328 +  else if (variable == "minDistToVertex"){
4329 +    double minDistToVertex=999;
4330 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4331 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4332 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4333 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
4334 +
4335 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4336 +    }
4337 +    value = minDistToVertex;
4338 +  }
4339 +  else if (variable == "distToVertexDifference"){
4340 +    double minDistToVertex=999;
4341 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4342 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4343 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4344 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
4345 +
4346 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4347 +    }
4348 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4349 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4350 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4351 +
4352 +    value = distToChosenVertex - minDistToVertex;
4353 +  }
4354 +
4355 +  else if (variable == "closestVertexRank"){
4356 +    double minDistToVertex=999;
4357 +    int vertex_rank = 0;
4358 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4359 +      vertex_rank++;
4360 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4361 +                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
4362 +                      (object->vz-vertex->z)*(object->vz-vertex->z));
4363 +
4364 +      if(abs(dist) < abs(minDistToVertex)){
4365 +        value = vertex_rank;
4366 +        minDistToVertex = dist;
4367 +      }
4368 +    }
4369 +  }
4370 +
4371 +  else if (variable == "decaysToTau"){
4372 +    value = abs (object->daughter0Id) == 15 || abs (object->daughter1Id) == 15;
4373 +  }
4374 +
4375 +
4376 +
4377 +
4378 +  else { clog << "WARNING: invalid stop variable '" << variable << "'\n"; value = -999; }
4379 +
4380 +  value = applyFunction(function, value);
4381 +
4382 +  return value;
4383 +
4384 + } // end stop valueLookup
4385 +
4386 +
4387 +
4388 +
4389 +
4390 + // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
4391 + // Return true iff no other tracks are found in this cone.
4392 + int
4393 + OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
4394 +  for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
4395 +    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
4396 +    double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
4397 +    if(deltaRtrk < 0.5) return 0;
4398 +  }
4399 +  return 1;
4400 +
4401 + }
4402 +
4403 + //calculate the scalar sum of Jet Pt in the event.
4404 + double
4405 + OSUAnalysis::getHt (const BNjetCollection* jetColl){
4406 +  double Ht = 0;
4407 +  for(BNjetCollection::const_iterator jet = jetColl->begin(); jet !=jetColl->end(); jet++){
4408 +    Ht += abs(jet->pt);
4409 +  }
4410 +  return Ht;
4411 + }
4412 +
4413 + double
4414 + OSUAnalysis::getTrkPtRes (const BNtrack* track1){
4415 +
4416 +  double ptTrue = getTrkPtTrue(track1, mcparticles.product());
4417 +  double PtRes = (track1->pt - ptTrue) / ptTrue;
4418 +
4419 +  return PtRes;
4420 +
4421 + }
4422 +
4423 +
4424 + double
4425 + OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
4426 +  double value = -99;
4427 +  double genDeltaRLowest = 999;
4428 +
4429 +  for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
4430 +    double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
4431 +    if (genDeltaRtemp < genDeltaRLowest) {
4432 +      genDeltaRLowest = genDeltaRtemp;
4433 +      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
4434 +        double ptTrue = genPart->pt;
4435 +        value = ptTrue;
4436 +      }
4437 +    }
4438 +  }
4439 +
4440 +  return value;
4441 +
4442 + }
4443 +
4444 + double
4445 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
4446 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
4447 +  if (!useTrackCaloRhoCorr_) return -99;
4448 +  // if (!rhokt6CaloJetsHandle_) {
4449 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
4450 +  //   return -99;
4451 +  // }
4452 +  double radDeltaRCone = 0.5;
4453 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
4454 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
4455 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
4456 +  return caloTotRhoCorrCalo;
4457 +
4458 + }
4459 +
4460 + double
4461 + OSUAnalysis::getTrkDepTrkRp5RhoCorr(const BNtrack* track) {
4462 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.              
4463 +  if (!useTrackCaloRhoCorr_) return -99;
4464 +  // if (!rhokt6CaloJetsHandle_) {                                                                                                    
4465 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;                        
4466 +  //   return -99;                                                                                                                    
4467 +  // }                                                                                                                                
4468 +  double radDeltaRCone = 0.5;
4469 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.                                                                                                          
4470 +  double rawDepTrkRp5 = track->depTrkRp5;
4471 + double depTrkRp5RhoCorr = TMath::Max(0., rawDepTrkRp5 - rhoCorr_kt6CaloJets);
4472 + return depTrkRp5RhoCorr;
4473 +
4474 + }
4475 +
4476 + double
4477 + OSUAnalysis::getTrkDepTrkRp3RhoCorr(const BNtrack* track) {
4478 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.                                                
4479 +  if (!useTrackCaloRhoCorr_) return -99;
4480 +  // if (!rhokt6CaloJetsHandle_) {                                                                                                                                      
4481 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;                                                          
4482 +  //   return -99;                                                                                                                                                      
4483 +  // }                                                                                                                                                                  
4484 +  double radDeltaRCone = 0.3;
4485 + // Define effective area as pi*r^2, where r is radius of DeltaR cone
4486 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  
4487 +  double rawDepTrkRp3 = track->depTrkRp3;
4488 +  double depTrkRp3RhoCorr = TMath::Max(0., rawDepTrkRp3 - rhoCorr_kt6CaloJets);
4489 +  return depTrkRp3RhoCorr;
4490 +  
4491 + }
4492 +
4493 +
4494 +
4495 +
4496 + //creates a map of the dead Ecal channels in the barrel and endcap
4497 + //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
4498 + //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
4499 + void
4500 + OSUAnalysis::WriteDeadEcal (){
4501 +  double etaEcal, phiEcal;
4502 +  ifstream DeadEcalFile(deadEcalFile_);
4503 +  if(!DeadEcalFile) {
4504 +    clog << "Error: DeadEcalFile has not been found." << endl;
4505 +    return;
4506 +  }
4507 +  if(DeadEcalVec.size()!= 0){
4508 +    clog << "Error: DeadEcalVec has a nonzero size" << endl;
4509 +    return;
4510 +  }
4511 +  while(!DeadEcalFile.eof())
4512 +    {
4513 +      DeadEcalFile >> etaEcal >> phiEcal;
4514 +      DeadEcal newChan;
4515 +      newChan.etaEcal = etaEcal;
4516 +      newChan.phiEcal = phiEcal;
4517 +      DeadEcalVec.push_back(newChan);
4518 +    }
4519 +  if(DeadEcalVec.size() == 0) clog << "Warning: No dead Ecal channels have been found." << endl;
4520 + }
4521 +
4522 + //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
4523 + int
4524 + OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
4525 +  double deltaRLowest = 999;
4526 +  int value = 0;
4527 +  if (DeadEcalVec.size() == 0) WriteDeadEcal();
4528 +  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4529 +    double eta = ecal->etaEcal;
4530 +    double phi = ecal->phiEcal;
4531 +    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
4532 +    if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
4533 +  }
4534 +  if (deltaRLowest<0.05) {value = 1;}
4535 +  else {value = 0;}
4536 +  return value;
4537 + }
4538 +
4539 + // Returns the smallest DeltaR between the object and any generated true particle in the event.
4540 + template <class InputObject>
4541 + double OSUAnalysis::getGenDeltaRLowest(InputObject object){
4542 +  double genDeltaRLowest = 999.;
4543 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4544 +    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
4545 +    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
4546 +  }
4547 +  return genDeltaRLowest;
4548 + }
4549  
4550   double
4551   OSUAnalysis::applyFunction(string function, double value){
4552  
4553    if(function == "abs") value = fabs(value);
4554 +  else if(function == "fabs") value = fabs(value);
4555 +  else if(function == "log10") value = log10(value);
4556 +  else if(function == "log") value = log10(value);
4557  
4558 +  else if(function == "") value = value;
4559 +  else{clog << "WARNING: invalid function '" << function << "'\n";}
4560  
4561    return value;
4562  
# Line 1530 | Line 4566 | OSUAnalysis::applyFunction(string functi
4566   template <class InputCollection>
4567   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
4568  
4569 +  if (verbose_>2) clog << "  Beginning setObjectFlags for cut " << currentCutIndex << ": " << currentCut.name
4570 +                       << ", inputType=" << inputType
4571 +                       << endl;  
4572 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
4573 +    string obj1, obj2;
4574 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
4575 +    if (verbose_>2) clog << "  Two object types:  " << obj1 << ", " << obj2 << endl;
4576 +    if (inputType==obj1 ||
4577 +        inputType==obj2) {
4578 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
4579 +      // and the inputType is a member of the pair.
4580 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
4581 +      // For example, if currentCut.inputCollection==electron-muon pairs,
4582 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
4583 +      return;
4584 +    }
4585 +  }
4586 +
4587 +  if (!inputCollection) clog << "ERROR:  invalid input collection for inputType=" << inputType << endl;  
4588 +
4589 +  if (verbose_>3) clog << "   Collection size:  " << inputCollection->size() << endl;
4590  
4591    for (uint object = 0; object != inputCollection->size(); object++){
4592  
4593 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
4593 >    if (verbose_>4) clog << "    Setting flags for object " << object << endl;
4594 >
4595 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4596 >    bool plotDecision = true;
4597  
4598      if(currentCut.inputCollection == inputType){
4599  
4600 <      double value = valueLookup(&inputCollection->at(object), currentCut.variable, currentCut.function);
4600 >      vector<bool> subcutDecisions;
4601 >      for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4602 >        string stringValue = "";
4603 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4604 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4605 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4606  
4607 <      decision = evaluateComparison(value,currentCut.comparativeOperator,currentCut.cutValue);
4607 >      }
4608 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4609 >      else{
4610 >        bool tempDecision = true;
4611 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4612 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4613 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4614 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4615 >            tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4616 >        }
4617 >        cutDecision = tempDecision;
4618 >      }
4619 >      //invert the cut if this cut is a veto
4620 >      if(currentCut.isVeto) cutDecision = !cutDecision;
4621 >      plotDecision = cutDecision;
4622      }
1544    individualFlags[inputType].at(currentCutIndex).push_back(decision);
4623  
4624 +    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4625  
4626 <    //set flags for objects that pass each cut AND all the previous cuts
4627 <    bool previousCumulativeFlag = true;
4626 >    //set flags for objects that pass this cut AND all the previous cuts
4627 >    bool previousCumulativeCutFlag = true;
4628      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4629 <      if(previousCumulativeFlag && individualFlags[inputType].at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4630 <      else{ previousCumulativeFlag = false; break;}
4629 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4630 >      else{ previousCumulativeCutFlag = false; break;}
4631      }
4632 <    cumulativeFlags[inputType].at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4632 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4633 >    bool previousCumulativePlotFlag = true;
4634 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4635 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4636 >      else{ previousCumulativePlotFlag = false; break;}
4637 >    }
4638 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4639 >
4640 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4641 >
4642 >  }  //   for (uint object = 0; object != inputCollection->size(); object++){
4643  
4644 + } // end void OSUAnalysis::setObjectFlags
4645 +
4646 +
4647 + template <class InputCollection1, class InputCollection2>
4648 + void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags,
4649 +                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, string inputType){
4650 +  // This function sets the flags for the paired object collection.  
4651 +  // If the cut is applying on the given paired object collection, then the flags for the single object collections are also set.
4652 +  // If not, then the flags for the paired object collection are taken as the AND of the flags for each single object collection.  
4653 +
4654 +  if (verbose_>2) clog << "  Beginning setObjectFlags for cut=" << currentCut.name
4655 +                       << ", inputType=" << inputType
4656 +                       << endl;  
4657 +
4658 +  bool sameObjects = false;
4659 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;  // FIXME:  is sameObjects just the not of isTwoTypesOfObject?  If so, it's redundant.  
4660 +
4661 +  // Get the strings for the two objects that make up the pair.
4662 +  string obj1Type, obj2Type;
4663 +  getTwoObjs(inputType, obj1Type, obj2Type);
4664 +  bool isTwoTypesOfObject = true;
4665 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
4666 +
4667 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
4668 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4669 +  if (currentCut.inputCollection == inputType) {
4670 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4671 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4672 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4673 +    }
4674 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4675 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4676 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4677 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4678 +      }
4679 +    }
4680    }
4681  
4682 +  int counter = 0;
4683 +
4684 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4685 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4686 +
4687 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4688 +
4689 +
4690 +      bool cutDecision  = true;//object passes if this cut doesn't cut on that type of object
4691 +      bool plotDecision = true;
4692 +
4693 +      // Determine whether each pair passes the cut, only if inputCollection is the same as the inputType.  
4694 +      if(currentCut.inputCollection == inputType){
4695 +
4696 +        vector<bool> subcutDecisions;
4697 +        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4698 +          string stringValue = "";
4699 +          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4700 +          if (verbose_>1) clog << currentCut.variables.at(subcutIndex) << " = " << value
4701 +                               << endl;  
4702 +          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4703 +          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4704 +        }
4705 +
4706 +        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4707 +        else{
4708 +          bool tempDecision = subcutDecisions.at(0);
4709 +          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
4710 +            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
4711 +              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
4712 +            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4713 +              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4714 +          }
4715 +          cutDecision = tempDecision;
4716 +        }
4717 +        //invert the cut if this cut is a veto
4718 +        if (currentCut.isVeto) cutDecision = !cutDecision;
4719 +        plotDecision = cutDecision;
4720 +
4721 +        if (verbose_>1) clog << " cutDecision = " << cutDecision
4722 +                             << "; for currentCut.inputCollection = " << currentCut.inputCollection
4723 +                             << "; object1 (" << obj1Type << ") = " << object1
4724 +                             << "; object2 (" << obj2Type << ") = " << object2
4725 +                             << endl;  
4726 +        
4727 +        if (cutDecision) {  // only set the flags for the individual objects if the pair object is being cut on
4728 +          individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4729 +          individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4730 +        }
4731 +        if (plotDecision) {  // only set the flags for the individual objects if the pair object is being cut on
4732 +          individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4733 +          individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4734 +        }
4735 +        
4736 +
4737 +      } // if(currentCut.inputCollection == inputType){
4738 +
4739 +      // The individualFlags will be true if the inputCollection is not the same as the inputType.
4740 +      // They are also independent of the previous flags on the single objects.  
4741 +      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));  
4742 +
4743 +
4744 +
4745 +      // ************************************
4746 +      // Determine cumulative flags
4747 +      // ************************************
4748 +      // determine whether this paired object passes this cut AND all previous cuts
4749 +      bool previousCumulativeCutFlag = true;
4750 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4751 +        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4752 +        else{ previousCumulativeCutFlag = false; break;}
4753 +      }
4754 +      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4755 +
4756 +      bool previousCumulativePlotFlag = true;
4757 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4758 +        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4759 +        else{ previousCumulativePlotFlag = false; break;}
4760 +      }
4761 +      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4762 +      
4763 +      // 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.    
4764 +      int cutIdxFlagsObj1 = max(int(currentCutIndex-1),0);
4765 +      int cutIdxFlagsObj2 = max(int(currentCutIndex-1),0);
4766 +      // 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.
4767 +      // 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.  
4768 +      // 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).  
4769 +      if (currentCut.inputCollection != inputType) {  
4770 +        if (currentCut.inputCollection.find(obj1Type)!=string::npos) cutIdxFlagsObj1 = currentCutIndex;
4771 +        if (currentCut.inputCollection.find(obj2Type)!=string::npos) cutIdxFlagsObj2 = currentCutIndex;
4772 +      }  
4773 +      flagPair flags1 = cumulativeFlags.at(obj1Type).at(cutIdxFlagsObj1);  // flag for input collection 1
4774 +      flagPair flags2 = cumulativeFlags.at(obj2Type).at(cutIdxFlagsObj2);  // flag for input collection 2
4775 +      
4776 +      // The cumulative flag is only true if the paired object cumulative flag is true, and if the single object cumulative flags are true.  
4777 +      bool currentCumulativeCutFlag = true;
4778 +      bool currentCumulativePlotFlag = true;
4779 +      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4780 +      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4781 +      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4782 +      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4783 +
4784 +      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4785 +      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4786 +      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4787 +      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4788 +
4789 +      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));  // Set the flag for the paired object
4790 +
4791 +
4792 +      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // Set the flags for the individual objects if the paired object is being cut on.  
4793 +        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first  = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4794 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first  = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4795 +        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4796 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4797 +
4798 +        if (verbose_>1) clog << " previousCumulativeCutFlag for object1 = " << getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object1, "cut") << endl;  
4799 +        if (verbose_>1) clog << " previousCumulativeCutFlag for object2 = " << getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut") << endl;  
4800 +
4801 +      }
4802 +
4803 +      counter++;
4804 +
4805 +    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4806 +  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4807 +
4808 + } // end void OSUAnalysis::setObjectFlags
4809 +
4810 +
4811 + bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4812 +  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4813 +  // all cuts up to currentCutIndex
4814 +  bool previousCumulativeFlag = true;
4815 +  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4816 +    bool tempFlag = false;
4817 +    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4818 +    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4819 +
4820 +    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4821 +    else {
4822 +      previousCumulativeFlag = false; break;
4823 +    }
4824 +  }
4825 +  return previousCumulativeFlag;
4826 + }
4827 +
4828 +
4829 +
4830 +
4831 + template <class InputCollection>
4832 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4833 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4834 +
4835 +  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;
4836 +  for (uint object = 0; object != inputCollection->size(); object++) {
4837 +
4838 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4839 +
4840 +    string inputVariable = parameters.inputVariable;
4841 +    string function = "";
4842 +    string stringValue = "";
4843 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4844 +    BNTreeBranchVals_.at(parameters.name).push_back(value);
4845 +
4846 +  }
4847   }
4848  
4849  
4850   template <class InputCollection>
4851 < void OSUAnalysis::fillHistogram(TH1* histo, histogram parameters, InputCollection inputCollection){
4851 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4852  
4853 +  if (verbose_>2) clog << "  Filling histogram for " << parameters.name << endl;  
4854  
4855    for (uint object = 0; object != inputCollection->size(); object++){
4856 <    if(parameters.inputVariables.size() == 1){
4857 <      double value = valueLookup(&inputCollection->at(object), parameters.inputVariables.at(0), parameters.function);
4858 <      histo->Fill(value);
4859 <    }
4860 <    else if(parameters.inputVariables.size() == 2){
4861 <      double valueX = valueLookup(&inputCollection->at(object), parameters.inputVariables.at(0), parameters.function);
4862 <      double valueY = valueLookup(&inputCollection->at(object), parameters.inputVariables.at(1), parameters.function);
4863 <      histo->Fill(valueX,valueY);
4856 >
4857 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4858 >
4859 >    string currentString = parameters.inputVariables.at(0);
4860 >    string inputVariable = "";
4861 >    string function = "";
4862 >    if(currentString.find("(")==string::npos){
4863 >      inputVariable = currentString;// variable to cut on
4864 >    }
4865 >    else{
4866 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4867 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4868 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4869 >    }
4870 >
4871 >    string stringValue = "";
4872 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4873 >    histo->Fill(value,scaleFactor);
4874 >
4875 >    if (printEventInfo_) {
4876 >      // Write information about event to screen, for testing purposes.
4877 >      clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << " (object number " << object << ")" << endl;
4878 >    }
4879 >
4880 >  }
4881 > }
4882 >
4883 > template <class InputCollection1, class InputCollection2>
4884 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2,
4885 >                                  flagPair pairFlags, double scaleFactor){
4886 >
4887 >  bool sameObjects = false;
4888 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4889 >
4890 >  int pairCounter = -1;
4891 >  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4892 >    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4893 >
4894 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4895 >
4896 >      pairCounter++;
4897 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4898 >
4899 >      string currentString = parameters.inputVariables.at(0);
4900 >      string inputVariable = "";
4901 >      string function = "";
4902 >      if(currentString.find("(")==string::npos){
4903 >        inputVariable = currentString;// variable to cut on
4904 >      }
4905 >      else{
4906 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4907 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4908 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4909 >      }
4910 >
4911 >      string stringValue = "";
4912 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4913 >      histo->Fill(value,scaleFactor);
4914 >
4915 >      if (printEventInfo_) {
4916 >        // Write information about event to screen, for testing purposes.
4917 >        clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value
4918 >             << " (object1 number " << object1 << "), "
4919 >             << " (object2 number " << object2 << ")"
4920 >             << endl;
4921 >      }
4922 >      
4923      }
4924    }
4925  
4926   }
4927  
4928  
4929 + template <class InputCollection>
4930 + void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4931  
4932 +  for (uint object = 0; object != inputCollection->size(); object++){
4933  
4934 < DEFINE_FWK_MODULE(OSUAnalysis);
4934 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4935 >
4936 >    string stringValue = "";
4937 >    string currentString = parameters.inputVariables.at(0);
4938 >    string inputVariable = "";
4939 >    string function = "";
4940 >    if(currentString.find("(")==string::npos){
4941 >      inputVariable = currentString;// variable to cut on
4942 >    }
4943 >    else{
4944 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4945 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4946 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4947 >    }
4948 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4949 >
4950 >    currentString = parameters.inputVariables.at(1);
4951 >    inputVariable = "";
4952 >    function = "";
4953 >    if(currentString.find("(")==string::npos){
4954 >      inputVariable = currentString;// variable to cut on
4955 >    }
4956 >    else{
4957 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4958 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4959 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4960 >    }
4961 >
4962 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4963 >
4964 >    histo->Fill(valueX,valueY,scaleFactor);
4965 >
4966 >  }
4967 >
4968 > }
4969 >
4970 > template <class InputCollection1, class InputCollection2>
4971 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2,
4972 >                                  flagPair pairFlags, double scaleFactor){
4973 >
4974 >  bool sameObjects = false;
4975 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4976 >
4977 >  int pairCounter = -1;
4978 >  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4979 >    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4980 >
4981 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4982 >
4983 >      pairCounter++;
4984 >
4985 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4986 >
4987 >      string stringValue = "";
4988 >      string currentString = parameters.inputVariables.at(0);
4989 >      string inputVariable = "";
4990 >      string function = "";
4991 >      if(currentString.find("(")==string::npos){
4992 >        inputVariable = currentString;// variable to cut on
4993 >      }
4994 >      else{
4995 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4996 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4997 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4998 >      }
4999 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
5000 >
5001 >      currentString = parameters.inputVariables.at(1);
5002 >      inputVariable = "";
5003 >      function = "";
5004 >      if(currentString.find("(")==string::npos){
5005 >        inputVariable = currentString;// variable to cut on
5006 >      }
5007 >      else{
5008 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
5009 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
5010 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
5011 >      }
5012 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
5013 >
5014 >
5015 >      histo->Fill(valueX,valueY,scaleFactor);
5016 >
5017 >    }
5018 >  }
5019 >
5020 > }
5021 >
5022 >
5023 > template <class InputObject>
5024 > int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
5025 >
5026 >  int bestMatchIndex = -1;
5027 >  double bestMatchDeltaR = 999;
5028 >
5029 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
5030 >
5031 >    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
5032 >    if(currentDeltaR > 0.05) continue;
5033 >    //     clog << setprecision(3) << setw(20)
5034 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
5035 >    //          << setw(20)
5036 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
5037 >    //          << setw(20)
5038 >    //          << "\tdeltaR = " << currentDeltaR
5039 >    //          << setprecision(1)
5040 >    //          << setw(20)
5041 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
5042 >    //          << setw(20)
5043 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
5044 >    //          << setw(20)
5045 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
5046 >    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
5047 >      bestMatchIndex = mcparticle - mcparticles->begin();
5048 >      bestMatchDeltaR = currentDeltaR;
5049 >    }
5050 >
5051 >  }
5052 >  //   if(bestMatchDeltaR != 999)  clog << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
5053 >  //   else clog << "no match found..." << endl;
5054 >  return bestMatchIndex;
5055 >
5056 > }
5057 >
5058 >
5059 > int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
5060 >
5061 >  int bestMatchIndex = -1;
5062 >  double bestMatchDeltaR = 999;
5063 >
5064 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
5065 >
5066 >    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
5067 >
5068 >    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
5069 >    if(currentDeltaR > 0.05) continue;
5070 >
5071 >    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
5072 >      bestMatchIndex = mcparticle - mcparticles->begin();
5073 >      bestMatchDeltaR = currentDeltaR;
5074 >    }
5075 >
5076 >  }
5077 >
5078 >  return bestMatchIndex;
5079 > }
5080 >
5081 >
5082 > // bin      particle type
5083 > // ---      -------------
5084 > //  0        unmatched
5085 > //  1        u
5086 > //  2        d
5087 > //  3        s
5088 > //  4        c
5089 > //  5        b
5090 > //  6        t
5091 > //  7        e
5092 > //  8        mu
5093 > //  9        tau
5094 > // 10        nu
5095 > // 11        g
5096 > // 12        gamma
5097 > // 13        Z
5098 > // 14        W
5099 > // 15        light meson
5100 > // 16        K meson
5101 > // 17        D meson
5102 > // 18        B meson
5103 > // 19        light baryon
5104 > // 20        strange baryon
5105 > // 21        charm baryon
5106 > // 22        bottom baryon
5107 > // 23        QCD string
5108 > // 24        other
5109 >
5110 > int OSUAnalysis::getPdgIdBinValue(int pdgId){
5111 >
5112 >  int binValue = -999;
5113 >  int absPdgId = fabs(pdgId);
5114 >  if(pdgId == -1) binValue = 0;
5115 >  else if(absPdgId <= 6 ) binValue = absPdgId;
5116 >  else if(absPdgId == 11 ) binValue = 7;
5117 >  else if(absPdgId == 13 ) binValue = 8;
5118 >  else if(absPdgId == 15 ) binValue = 9;
5119 >  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
5120 >  else if(absPdgId == 21 ) binValue = 11;
5121 >  else if(absPdgId == 22 ) binValue = 12;
5122 >  else if(absPdgId == 23 ) binValue = 13;
5123 >  else if(absPdgId == 24 ) binValue = 14;
5124 >  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
5125 >  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
5126 >  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
5127 >  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
5128 >  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
5129 >  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
5130 >  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
5131 >  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
5132 >  else if(absPdgId == 92  ) binValue = 23;
5133 >
5134 >  else binValue = 24;
5135 >
5136 >  return binValue;
5137 >
5138 > }
5139 >
5140 > const BNprimaryvertex *
5141 > OSUAnalysis::chosenVertex ()
5142 > {
5143 >  const BNprimaryvertex *chosenVertex = 0;
5144 >  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
5145 >    flagPair vertexFlags;
5146 >    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
5147 >      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
5148 >        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
5149 >        break;
5150 >      }
5151 >    }
5152 >    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
5153 >      if(!vertexFlags.at(vertexIndex).first) continue;
5154 >      chosenVertex = & primaryvertexs->at(vertexIndex);
5155 >      break;
5156 >    }
5157 >  }
5158 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
5159 >    chosenVertex = & primaryvertexs->at (0);
5160 >
5161 >  return chosenVertex;
5162 > }
5163  
5164 + const BNmet *
5165 + OSUAnalysis::chosenMET ()
5166 + {
5167 +  const BNmet *chosenMET = 0;
5168 +  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
5169 +    flagPair metFlags;
5170 +    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
5171 +      if (cumulativeFlags.at("mets").at(i).size()){
5172 +        metFlags = cumulativeFlags.at("mets").at(i);
5173 +        break;
5174 +      }
5175 +    }
5176 +    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
5177 +      if(!metFlags.at(metIndex).first) continue;
5178 +      chosenMET = & mets->at(metIndex);
5179 +      break;
5180 +    }
5181 +  }
5182 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
5183 +    chosenMET = & mets->at (0);
5184 +
5185 +  return chosenMET;
5186 + }
5187  
5188 + const BNelectron *
5189 + OSUAnalysis::chosenElectron ()
5190 + {
5191 +  const BNelectron *chosenElectron = 0;
5192 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
5193 +    flagPair electronFlags;
5194 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
5195 +      if (cumulativeFlags.at("electrons").at(i).size()){
5196 +        electronFlags = cumulativeFlags.at("electrons").at(i);
5197 +        break;
5198 +      }
5199 +    }
5200 +    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
5201 +      if(!electronFlags.at(electronIndex).first) continue;
5202 +      chosenElectron = & electrons->at(electronIndex);
5203 +      break;
5204 +    }
5205 +  }
5206 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
5207 +    chosenElectron = & electrons->at (0);
5208 +
5209 +  return chosenElectron;
5210 + }
5211 +
5212 +
5213 + const BNmuon *
5214 + OSUAnalysis::chosenMuon ()
5215 + {
5216 +  const BNmuon *chosenMuon = 0;
5217 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
5218 +    flagPair muonFlags;
5219 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
5220 +      if (cumulativeFlags.at("muons").at(i).size()){
5221 +        muonFlags = cumulativeFlags.at("muons").at(i);
5222 +        break;
5223 +      }
5224 +    }
5225 +    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
5226 +      if(!muonFlags.at(muonIndex).first) continue;
5227 +      chosenMuon = & muons->at(muonIndex);
5228 +      break;
5229 +    }
5230 +  }
5231 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
5232 +    chosenMuon = & muons->at (0);
5233 +
5234 +  return chosenMuon;
5235 + }
5236 +
5237 + double
5238 + OSUAnalysis::chosenHT ()
5239 + {
5240 +  double chosenHT = 0.0;
5241 +  if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
5242 +    flagPair jetFlags;
5243 +    for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
5244 +      if (cumulativeFlags.at("jets").at(i).size()){
5245 +        jetFlags = cumulativeFlags.at("jets").at(i);
5246 +        break;
5247 +      }
5248 +    }
5249 +    for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
5250 +      if(!jetFlags.at(jetIndex).first) continue;
5251 +      chosenHT += jets->at(jetIndex).pt;
5252 +    }
5253 +  }
5254 +
5255 +  return chosenHT;
5256 + }
5257 +
5258 + pair<const BNmuon *, const BNmuon *>
5259 + OSUAnalysis::leadMuonPair ()
5260 + {
5261 +  pair<const BNmuon *, const BNmuon *> leadMuonPair;
5262 +  leadMuonPair.first = leadMuonPair.second = 0;
5263 +
5264 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
5265 +    flagPair muonFlags;
5266 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
5267 +      if (cumulativeFlags.at("muons").at(i).size()){
5268 +        muonFlags = cumulativeFlags.at("muons").at(i);
5269 +        break;
5270 +      }
5271 +    }
5272 +    for (uint muonIndex0 = 0; muonIndex0 != muonFlags.size(); muonIndex0++){
5273 +      if(!muonFlags.at(muonIndex0).first) continue;
5274 +      for (uint muonIndex1 = muonIndex0 + 1; muonIndex1 < muonFlags.size(); muonIndex1++){
5275 +        if(!muonFlags.at(muonIndex1).first) continue;
5276 +        const BNmuon *mu0 = & muons->at(muonIndex0);
5277 +        const BNmuon *mu1 = & muons->at(muonIndex1);
5278 +        if(leadMuonPair.first == 0 || leadMuonPair.second == 0){
5279 +          leadMuonPair.first = mu0;
5280 +          leadMuonPair.second = mu1;
5281 +        }
5282 +        else{
5283 +          TVector2 newPt0 (mu0->px, mu0->py),
5284 +                   newPt1 (mu1->px, mu1->py),
5285 +                   oldPt0 (leadMuonPair.first->px, leadMuonPair.first->py),
5286 +                   oldPt1 (leadMuonPair.second->px, leadMuonPair.second->py);
5287 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
5288 +            {
5289 +              leadMuonPair.first = mu0;
5290 +              leadMuonPair.second = mu1;
5291 +            }
5292 +        }
5293 +      }
5294 +    }
5295 +  }
5296 +
5297 +  return leadMuonPair;
5298 + }
5299 +
5300 + pair<const BNelectron *, const BNelectron *>
5301 + OSUAnalysis::leadElectronPair ()
5302 + {
5303 +  pair<const BNelectron *, const BNelectron *> leadElectronPair;
5304 +  leadElectronPair.first = leadElectronPair.second = 0;
5305 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
5306 +    flagPair electronFlags;
5307 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
5308 +      if (cumulativeFlags.at("electrons").at(i).size()){
5309 +        electronFlags = cumulativeFlags.at("electrons").at(i);
5310 +        break;
5311 +      }
5312 +    }
5313 +    for (uint electronIndex0 = 0; electronIndex0 != electronFlags.size(); electronIndex0++){
5314 +      if(!electronFlags.at(electronIndex0).first) continue;
5315 +      for (uint electronIndex1 = electronIndex0 + 1; electronIndex1 < electronFlags.size(); electronIndex1++){
5316 +        if(!electronFlags.at(electronIndex1).first) continue;
5317 +        const BNelectron *el0 = & electrons->at(electronIndex0);
5318 +        const BNelectron *el1 = & electrons->at(electronIndex1);
5319 +        if(leadElectronPair.first == 0 || leadElectronPair.second == 0){
5320 +          leadElectronPair.first = el0;
5321 +          leadElectronPair.second = el1;
5322 +        }
5323 +        else{
5324 +          TVector2 newPt0 (el0->px, el0->py),
5325 +                   newPt1 (el1->px, el1->py),
5326 +                   oldPt0 (leadElectronPair.first->px, leadElectronPair.first->py),
5327 +                   oldPt1 (leadElectronPair.second->px, leadElectronPair.second->py);
5328 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
5329 +            {
5330 +              leadElectronPair.first = el0;
5331 +              leadElectronPair.second = el1;
5332 +            }
5333 +        }
5334 +      }
5335 +    }
5336 +  }
5337 +
5338 +  return leadElectronPair;
5339 + }
5340 +
5341 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines