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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines