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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines