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.115 by wulsin, Thu Aug 1 09:49:57 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 == "muon-tau pairs")            currentObject = "muonTauPairs";
624 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
625 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
626 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
627 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
628 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
629 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
630 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
631 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
632 +        else if(currentObject == "electron-mcparticle pairs")   currentObject = "electronMCparticlePairs";
633 +
634 +
635 +        currentObject.at(0) = toupper(currentObject.at(0));
636 +        string histoName = "num" + currentObject;
637 +
638 +        if(histoName == "numPrimaryvertexs"){
639 +          string newHistoName = histoName + "BeforePileupCorrection";
640 +          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);
641 +          newHistoName = histoName + "AfterPileupCorrection";
642 +          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);
643 +        }
644 +        else
645 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
646 +      }
647 +
648 +      if (verbose_) {
649 +        clog << "List of 1D histograms booked for channel " << channelName << " and directory " << currentDir << ":" << endl;
650 +        for(map<string, TH1D*>::iterator
651 +              iter = oneDHists_.at(currentChannel).at(currentDir).begin();
652 +            iter  != oneDHists_.at(currentChannel).at(currentDir).end();
653 +            iter++) {
654 +          clog << " " << iter->first
655 +               << ":  name=" << iter->second->GetName()
656 +               << ", title=" << iter->second->GetTitle()
657 +               << ", bins=(" << iter->second->GetNbinsX()
658 +               << "," << iter->second->GetXaxis()->GetXmin()
659 +               << "," << iter->second->GetXaxis()->GetXmax()
660 +               << ")" << endl;
661 +        }  
662 +        clog << "List of 2D histograms booked for channel " << channelName << " and directory " << currentDir << ":" << endl;
663 +        for(map<string, TH2D*>::iterator
664 +              iter = twoDHists_.at(currentChannel).at(currentDir).begin();
665 +            iter  != twoDHists_.at(currentChannel).at(currentDir).end();
666 +            iter++) {
667 +          clog << " " << iter->first
668 +               << ":  name=" << iter->second->GetName()
669 +               << ", title=" << iter->second->GetTitle()
670 +               << ", binsX=(" << iter->second->GetNbinsX()
671 +               << "," << iter->second->GetXaxis()->GetXmin()
672 +               << "," << iter->second->GetXaxis()->GetXmax()
673 +               << ")"
674 +               << ", binsY=(" << iter->second->GetNbinsY()
675 +               << "," << iter->second->GetYaxis()->GetXmin()
676 +               << "," << iter->second->GetYaxis()->GetXmax()
677 +               << ")"
678 +               << endl;
679 +        }  
680 +      }
681 +
682 +    }//end of loop over directories
683      channels.push_back(tempChannel);
684      tempChannel.cuts.clear();
382
685    }//end loop over channels
686  
687  
688 +  // Create the cutflow histogram and fill with 0 weight, in case no events are found in the input file.  
689 +  for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
690 +    channel currentChannel = channels.at(currentChannelIndex);
691 +    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
692 +      cutFlows_.at(currentChannelIndex)->at("trigger") = true;  
693 +    }
694 +    for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
695 +      cut currentCut = currentChannel.cuts.at(currentCutIndex);
696 +      cutFlows_.at(currentChannelIndex)->at (currentCut.name) = true;
697 +    }
698 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(0);  // fill cutflow with 0 weight, just to create the cutflow histograms  
699 +  }
700 +
701    //make unique vector of objects we need to get from the event
702    sort( objectsToGet.begin(), objectsToGet.end() );
703    objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
704    //make unique vector of objects we need to cut on
705    sort( objectsToCut.begin(), objectsToCut.end() );
706    objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
707 +  //make unique vector of objects we need to set flags for
708 +  sort( objectsToFlag.begin(), objectsToFlag.end() );
709 +  objectsToFlag.erase( unique( objectsToFlag.begin(), objectsToFlag.end() ), objectsToFlag.end() );
710 +
711 +  // 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.  
712 +  for (uint i=0; i<objectsToFlag.size(); i++) {
713 +    if (objectsToFlag.at(i).find("pairs")!=string::npos) { // if it contains "pairs"
714 +      objectsToFlag.push_back(objectsToFlag.at(i));  
715 +      objectsToFlag.erase(objectsToFlag.begin()+i);  
716 +    }
717 +  }
718  
719 +  if (verbose_) {
720 +    clog << "List of channels:" << endl;
721 +    for (uint i=0; i<channels.size(); i++) {
722 +      clog << " " << channels.at(i).name << endl;
723 +    }
724 +    clog << "List of objects to get:" << endl;
725 +    for (uint i=0; i<objectsToGet.size(); i++) {
726 +      clog << " " << objectsToGet.at(i) << endl;
727 +    }
728 +    clog << "List of objects to plot:" << endl;
729 +    for (uint i=0; i<objectsToPlot.size(); i++) {
730 +      clog << " " << objectsToPlot.at(i) << endl;
731 +    }
732 +    clog << "List of objects to cut:" << endl;
733 +    for (uint i=0; i<objectsToCut.size(); i++) {
734 +      clog << " " << objectsToCut.at(i) << endl;
735 +    }
736 +    clog << "List of objects to flag:" << endl;
737 +    for (uint i=0; i<objectsToFlag.size(); i++) {
738 +      clog << " " << objectsToFlag.at(i) << endl;
739 +    }
740 +  }
741 +
742 +  produces<map<string, bool> > ("channelDecisions");
743 +
744 +  if (printEventInfo_) {
745 +    findEventsLog = new ofstream();  
746 +    findEventsLog->open("findEvents.txt");  
747 +    clog << "Listing run:lumi:event in file findEvents.txt for events that pass full selection (of any channel)." << endl;  
748 +  } else {
749 +    findEventsLog = 0;
750 +  }  
751 +
752 +  isFirstEvent_ = true;  
753 +
754 +  if (verbose_) clog << "Finished OSUAnalysis::OSUAnalysis constructor." << endl;  
755 +
756 +
757 +  } // end constructor OSUAnalysis::OSUAnalysis()
758  
394 }
759  
760   OSUAnalysis::~OSUAnalysis ()
761   {
762 +
763 +  if (verbose_) clog << "Beginning OSUAnalysis::OSUAnalysis destructor." << endl;  
764 +
765    // Destroying the CutFlow objects causes the cut flow numbers and time
766    // information to be printed to standard output.
767    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
768      delete cutFlows_.at(currentChannel);
769    }
770 +
771 +  if (printEventInfo_ && findEventsLog) findEventsLog->close();  
772 +
773 +  clog << "=============================================" << endl;  
774 +  clog << "Successfully completed OSUAnalysis." << endl;  
775 +  clog << "=============================================" << endl;  
776 +
777 +  if (verbose_) clog << "Finished OSUAnalysis::OSUAnalysis destructor." << endl;  
778 +
779   }
780  
781   void
782 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
782 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
783   {
408
784    // Retrieve necessary collections from the event.
785  
786 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
786 >  if (verbose_) clog << "Beginning OSUAnalysis::produce." << endl;  
787 >
788 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end()) {
789      event.getByLabel (triggers_, triggers);
790 +    if (!triggers.product()) cout << "ERROR:  could not get triggers input collection" << endl;  
791 +  }
792  
793 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
793 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end()) {
794 >    event.getByLabel (trigobjs_, trigobjs);
795 >    if (!trigobjs.product()) cout << "ERROR:  could not get trigobjs input collection" << endl;  
796 >  }
797 >
798 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end()) {
799      event.getByLabel (jets_, jets);
800 +    if (!jets.product()) cout << "ERROR:  could not get jets input collection" << endl;  
801 +  }
802  
803 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
803 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end()) {
804      event.getByLabel (muons_, muons);
805 +    if (!muons.product()) cout << "ERROR:  could not get muons input collection" << endl;  
806 +  }
807  
808 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
808 >  if (find(objectsToGet.begin(), objectsToGet.end(), "secondary muons") != objectsToGet.end()) {
809 >    event.getByLabel (secMuons_, secMuons);
810 >    if (!secMuons.product()) cout << "ERROR:  could not get secMuons input collection" << endl;  
811 >  }
812 >
813 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end()) {
814      event.getByLabel (electrons_, electrons);
815 +    if (!electrons.product()) cout << "ERROR:  could not get electrons input collection" << endl;  
816 +  }
817  
818 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
818 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end()) {
819      event.getByLabel (events_, events);
820 +    if (!events.product()) cout << "ERROR:  could not get events input collection" << endl;  
821 +  }
822  
823 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
823 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end()) {
824      event.getByLabel (taus_, taus);
825 +    if (!taus.product()) cout << "ERROR:  could not get taus input collection" << endl;  
826 +  }
827  
828 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
828 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end()) {
829      event.getByLabel (mets_, mets);
830 +    if (!mets.product()) cout << "ERROR:  could not get mets input collection" << endl;  
831 +  }
832  
833 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
833 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end()) {
834      event.getByLabel (tracks_, tracks);
835 +    if (!tracks.product()) cout << "ERROR:  could not get tracks input collection" << endl;  
836 +  }
837  
838 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
838 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end()) {
839      event.getByLabel (genjets_, genjets);
840 +    if (!genjets.product()) cout << "ERROR:  could not get genjets input collection" << endl;  
841 +  }
842  
843 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
844 <        event.getByLabel (mcparticles_, mcparticles);
845 <    
843 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end()) {
844 >    event.getByLabel (mcparticles_, mcparticles);
845 >    if (!mcparticles.product()) cout << "ERROR:  could not get mcparticles input collection" << endl;  
846 >  }
847  
848 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
848 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end()) {
849      event.getByLabel (primaryvertexs_, primaryvertexs);
850 +    if (!primaryvertexs.product()) cout << "ERROR:  could not get primaryvertexs input collection" << endl;  
851 +  }
852  
853 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
853 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end()) {
854      event.getByLabel (bxlumis_, bxlumis);
855 +    if (!bxlumis.product()) cout << "ERROR:  could not get bxlumis input collection" << endl;  
856 +  }
857  
858 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
858 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end()) {
859      event.getByLabel (photons_, photons);
860 +    if (!photons.product()) cout << "ERROR:  could not get photons input collection" << endl;  
861 +  }
862  
863 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
863 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end()) {
864      event.getByLabel (superclusters_, superclusters);
865 +    if (!superclusters.product()) cout << "ERROR:  could not get superclusters input collection" << endl;  
866 +  }
867  
868 +  if (datasetType_ == "signalMC"){
869 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end()) {
870 +      event.getByLabel (stops_, stops);
871 +      if (!stops.product()) cout << "ERROR:  could not get stops input collection" << endl;  
872 +    }
873 +  }
874  
875 <  //get pile-up event weight
876 <  double puScaleFactor = 1.00;
877 <  //  if(datasetType_ != "data"){
878 <  // puScaleFactor = puWeight_->at (events->at (0).numTruePV);
879 <    //    cout << puScaleFactor << endl;
880 <  //}
875 >  if (useTrackCaloRhoCorr_) {
876 >    // Used only for pile-up correction of by-hand calculation of isolation energy.
877 >    // This rho collection is not available in all BEANs.
878 >    // For description of rho values for different jet reconstruction algorithms, see
879 >    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
880 >    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
881 >    if (!rhokt6CaloJetsHandle_.product()) cout << "ERROR:  could not get kt6CaloJets input collection" << endl;  
882 >  }
883 >
884 >  double masterScaleFactor = 1.0;
885  
886 +  //get pile-up event weight
887 +  if (doPileupReweighting_ && datasetType_ != "data") {
888 +    //for "data" datasets, the numTruePV is always set to -1
889 +    if (events->at(0).numTruePV < 0 && isFirstEvent_) clog << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
890 +    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
891 +  }
892  
893 +  stopCTauScaleFactor_ = 1.0;
894 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
895 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
896 +  masterScaleFactor *= stopCTauScaleFactor_;
897  
898    //loop over all channels
899  
900 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
901    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
902      channel currentChannel = channels.at(currentChannelIndex);
903 +    if (verbose_>1) clog << " Processing channel " << currentChannel.name << endl;
904  
905      flagMap individualFlags;
470    flagMap cumulativeFlags;
906      counterMap passingCounter;
907 +    cumulativeFlags.clear ();
908 +
909 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
910 +         iter != BNTreeBranchVals_.end(); iter++) {
911 +      iter->second.clear();  // clear array
912 +    }
913  
914      bool triggerDecision = true;
915 <    if(currentChannel.triggers.size() != 0){  //triggers specified
916 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
915 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
916 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
917        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
918      }
919  
920      //loop over all cuts
480
481
482
921      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
922        cut currentCut = currentChannel.cuts.at(currentCutIndex);
923 +      if (verbose_>2) clog << "  Processing cut, index: " << currentCutIndex << ", input collection: " << currentCut.inputCollection << ", name: " << currentCut.name << endl;  
924  
925 <      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
926 <        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");
925 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
926 >        string currentObject = objectsToFlag.at(currentObjectIndex);
927  
928 +        //initialize maps to get ready to set cuts
929 +        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
930 +        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
931  
932        }
933  
934 +      //set flags for all relevant objects
935 +      for(int currentObjectIndex = -1; currentObjectIndex != int(objectsToFlag.size()); currentObjectIndex++){
936 +        string currentObject;  
937 +        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.  
938 +        else currentObject = objectsToFlag.at(currentObjectIndex);
939 +        if (currentObjectIndex >= 0 && currentObject == currentCut.inputCollection) continue;  // Flags have already been set for the inputCollection object, so should not be set again.  
940 +
941 +        // single object collections
942 +        if     (currentObject == "jets")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
943 +        else if(currentObject == "secondary jets")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
944 +        else if(currentObject == "secondary photons")   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"secondary photons");
945 +        else if(currentObject == "muons")               setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
946 +        else if(currentObject == "secondary muons")     setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,secMuons.product(),"secondary muons");
947 +        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
948 +        else if(currentObject == "electrons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
949 +        else if(currentObject == "events")              setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
950 +        else if(currentObject == "taus")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
951 +        else if(currentObject == "mets")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
952 +        else if(currentObject == "tracks")              setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
953 +        else if(currentObject == "genjets")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
954 +        else if(currentObject == "mcparticles")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
955 +        else if(currentObject == "primaryvertexs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
956 +        else if(currentObject == "bxlumis")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
957 +        else if(currentObject == "photons")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
958 +        else if(currentObject == "superclusters")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
959 +        else if(currentObject == "trigobjs")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
960 +
961 +
962 +        // paired object collections  
963 +        else if(currentObject == "muon-muon pairs")                   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), "muon-muon pairs");
964 +        else if(currentObject == "muon-secondary muon pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),secMuons.product(), "muon-secondary muon pairs");
965 +
966 +        else if(currentObject == "muon-secondary photon pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), "muon-secondary photon pairs");
967 +        else if(currentObject == "muon-secondary jet pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), "muon-secondary jet pairs");
968 +        else if(currentObject == "photon-secondary jet pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), "photon-secondary jet pairs");
969 +        else if(currentObject == "electron-secondary jet pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), "electron-secondary jet pairs");
970 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), "electron-secondary electron pairs");
971 +
972 +        else if(currentObject == "electron-electron pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), "electron-electron pairs");
973 +        else if(currentObject == "electron-muon pairs")     setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), "electron-muon pairs");
974 +        else if(currentObject == "jet-jet pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), "jet-jet pairs");
975 +        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), "jet-secondary jet pairs");
976 +        else if(currentObject == "electron-jet pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), "electron-jet pairs");
977 +        else if(currentObject == "electron-photon pairs")   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), "electron-photon pairs");
978 +        else if(currentObject == "photon-jet pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), "photon-jet pairs");
979 +        else if(currentObject == "muon-jet pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), "muon-jet pairs");
980 +        else if(currentObject == "muon-event pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),events.product(), "muon-event pairs");
981 +        else if(currentObject == "met-jet pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),jets.product(), "met-jet pairs");
982 +        else if(currentObject == "track-jet pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),jets.product(), "track-jet pairs");
983 +        else if(currentObject == "muon-photon pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), "muon-photon pairs");
984 +        else if(currentObject == "track-event pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(), "track-event pairs");
985 +        else if(currentObject == "electron-track pairs")    setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),"electron-track pairs");
986 +        else if(currentObject == "muon-track pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),"muon-track pairs");
987 +        else if(currentObject == "muon-tau pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),"muon-tau pairs");
988 +        else if(currentObject == "tau-tau pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),"tau-tau pairs");
989 +        else if(currentObject == "tau-track pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),"tau-track pairs");
990 +        else if(currentObject == "electron-trigobj pairs")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),"electron-trigobj pairs");
991 +        else if(currentObject == "muon-trigobj pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),"muon-trigobj pairs");
992 +        else if(currentObject == "electron-mcparticle pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),mcparticles.product(),"electron-mcparticle pairs");
993  
994 +        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
995 +      }
996  
997      }//end loop over all cuts
998  
999  
535    //use cumulative flags to apply cuts at event level
1000  
1001 +    //use cumulative flags to apply cuts at event level
1002 +    vector<bool> eventPassedPreviousCuts;    //a vector to store cumulative cut descisions after each cut.
1003      bool eventPassedAllCuts = true;
1004 <
539 <    //apply trigger (true if none were specified)
540 <    eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
541 <
542 <
1004 >    eventPassedAllCuts = eventPassedAllCuts && triggerDecision;    //apply trigger (true if none were specified)
1005  
1006      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
1007  
1008        //loop over all objects and count how many passed the cumulative selection up to this point
1009        cut currentCut = currentChannel.cuts.at(currentCutIndex);
1010        int numberPassing = 0;
1011 +      int numberPassingPrev = 0;  // number of objects that pass cuts up to the previous one
1012  
1013        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
1014 <          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
1014 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
1015 >      }
1016 >      bool cutDecision;
1017 >      if (!currentCut.isVeto) {
1018 >        cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
1019 >      } else {
1020 >        int prevCutIndex = currentCutIndex - 1;
1021 >        if (prevCutIndex<0) {
1022 >          numberPassingPrev = cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size();  // count all objects in collection if cut is the first
1023 >        } else {
1024 >          for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(prevCutIndex).size() ; object++){
1025 >            if (cumulativeFlags.at(currentCut.inputCollection).at(prevCutIndex).at(object).first) {
1026 >              numberPassingPrev++;
1027 >              if (verbose_>1) clog << " object passed previous cut" << endl;  
1028 >            }
1029 >          }  
1030 >        }  
1031 >        int numberFailCut = numberPassingPrev - numberPassing;
1032 >        cutDecision = evaluateComparison(numberFailCut,currentCut.eventComparativeOperator,currentCut.numberRequired);  
1033        }
1034  
554      bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
1035        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
556
1036        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
1037 +      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
1038 +      if (verbose_>1) clog << " Event passed cuts up to cut index " << currentCutIndex << endl;  
1039 +
1040 +    }
1041 +    //applying all appropriate scale factors
1042 +    double scaleFactor = masterScaleFactor;
1043 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
1044 +
1045 +    if(applyLeptonSF_ && datasetType_ != "data"){
1046 +      //only apply SFs if we've cut on this object
1047 +      if(find(objectsToCut.begin(),objectsToCut.end(),"muons") != objectsToCut.end ()){
1048 +        flagPair muonFlags;
1049 +        //get the last valid flags in the flag map
1050 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
1051 +          if (cumulativeFlags.at("muons").at(i).size()){
1052 +            muonFlags = cumulativeFlags.at("muons").at(i);
1053 +            break;
1054 +          }
1055 +        }
1056 +        //apply the weight for each of those objects
1057 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
1058 +          if(!muonFlags.at(muonIndex).second) continue;
1059 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
1060 +        }
1061 +      }
1062 +      //only apply SFs if we've cut on this object
1063 +      if(find(objectsToCut.begin(),objectsToCut.end(),"electrons") != objectsToCut.end ()){
1064 +        flagPair electronFlags;
1065 +        //get the last valid flags in the flag map
1066 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
1067 +          if (cumulativeFlags.at("electrons").at(i).size()){
1068 +            electronFlags = cumulativeFlags.at("electrons").at(i);
1069 +            break;
1070 +          }
1071 +        }
1072 +        //apply the weight for each of those objects
1073 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
1074 +          if(!electronFlags.at(electronIndex).second) continue;
1075 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
1076 +        }
1077 +      }
1078 +    }
1079 +    if(applyBtagSF_ && datasetType_ != "data"){
1080 +      //only apply SFs if we've cut on this object
1081 +      if(find(objectsToCut.begin(),objectsToCut.end(),"jets") != objectsToCut.end ()){
1082 +        flagPair jetFlags;
1083 +        vector<double> jetSFs;
1084 +        //get the last valid flags in the flag map
1085 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
1086 +          if (cumulativeFlags.at("jets").at(i).size()){
1087 +            jetFlags = cumulativeFlags.at("jets").at(i);
1088 +            break;
1089 +          }
1090 +        }
1091 +        //apply the weight for each of those objects
1092 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
1093 +          if(!jetFlags.at(jetIndex).second) continue;
1094 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour, jets->at(jetIndex).eta);
1095 +          jetSFs.push_back(jetSFTmp);
1096 +        }
1097 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_);
1098 +      }
1099 +    }
1100 +    scaleFactor *= muonScaleFactor_;
1101 +    scaleFactor *= electronScaleFactor_;
1102 +    scaleFactor *= bTagScaleFactor_;
1103 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
1104 +    if (verbose_>1) clog << " Scale factors applied:  "
1105 +                         << " muonScaleFactor_ = " << muonScaleFactor_
1106 +                         << ", electronScaleFactor_ = " << electronScaleFactor_
1107 +                         << ", bTagScaleFactor_ = " << bTagScaleFactor_
1108 +                         << ", total scale factor = " << scaleFactor
1109 +                         << endl;  
1110 +
1111 +
1112 +    if (printEventInfo_ && eventPassedAllCuts) {
1113 +      // Write information about event to screen, for testing purposes.
1114 +      clog << "Event passed all cuts in channel " <<  currentChannel.name
1115 +           << ":  run:lumi:evt=  "  << events->at(0).run
1116 +           << ":" << events->at(0).lumi
1117 +           << ":" << events->at(0).evt
1118 +           << endl;
1119 +      if (findEventsLog) {
1120 +        (*findEventsLog) << events->at(0).run
1121 +                         << ":" << events->at(0).lumi
1122 +                         << ":" << events->at(0).evt << endl;
1123 +      }
1124  
1125      }
1126  
561    cutFlows_.at(currentChannelIndex)->fillCutFlow(puScaleFactor);
1127  
1128 +    //filling histograms
1129 +    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.
1130  
1131 +      if (verbose_>2) clog << "  Filling histograms for currentcut = " << currentCut << endl;  
1132  
1133 <    if(!eventPassedAllCuts)continue;
1133 >      uint currentDir;
1134 >      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
1135 >      else{
1136 >        currentDir = currentCut;
1137 >      }
1138  
1139  
1140 <    
1140 >      if(eventPassedPreviousCuts.at(currentDir)){
1141  
1142 <    //set position of primary vertex in event, in order to calculate quantities relative to it
1143 <    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 <    }
1142 >        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1143 >          histogram currentHistogram = histograms.at(histogramIndex);
1144  
1145 +          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) clog << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
1146  
1147 +          if (verbose_>1) clog << " Filling histogram " << currentHistogram.name << " for collection " << currentHistogram.inputCollection << endl;  
1148  
1149 <    //filling histograms
1150 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1151 <      histogram currentHistogram = histograms.at(histogramIndex);
1149 >          if(currentHistogram.inputVariables.size() == 1){
1150 >            TH1D* histo;
1151 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1152 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1153 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1154 >            else if(currentHistogram.inputCollection == "secondary photons")  fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1155 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1156 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,secMuons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1157 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1158 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1159 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1160 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),secMuons.product(),
1161 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1162 >             else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1163 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1164 >             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1165 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1166 >             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1167 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1168 >             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1169 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1170 >
1171 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1172 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1173 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1174 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1175 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1176 >             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1177 >                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1178 >
1179 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1180 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1181 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(),
1182 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1183 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(),
1184 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1185 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(),
1186 >                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1187 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(),
1188 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1189 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill1DHistogram(histo,currentHistogram, muons.product(),events.product(),
1190 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1191 >            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, mets.product(),jets.product(),
1192 >                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1193 >            else if(currentHistogram.inputCollection == "track-jet pairs")  fill1DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1194 >                                                                                          cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1195 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(),
1196 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1197 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(),
1198 >                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1199 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1200 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1201 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1202 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1203 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1204 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1205 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1206 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1207 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1208 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1209 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1210 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1211 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1212 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1213 >
1214 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1215 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1216 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1217 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1218 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1219 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1220 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1221 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1222 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1223 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1224 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1225 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1226 >          }
1227 >          else if(currentHistogram.inputVariables.size() == 2){
1228 >            TH2D* histo;
1229 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1230 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1231 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1232 >            else if(currentHistogram.inputCollection == "secondary photons")  fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1233 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1234 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,secMuons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1235 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1236 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1237 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),secMuons.product(),
1238 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1239 >            else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1240 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1241 >            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1242 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1243 >            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1244 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1245 >            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1246 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1247 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1248 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1249 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1250 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1251 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1252 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1253 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1254 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1255 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(),
1256 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1257 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1258 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1259 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(),
1260 >                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1261 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1262 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1263 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill2DHistogram(histo,currentHistogram,muons.product(),events.product(),
1264 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1265 >            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,mets.product(),jets.product(),
1266 >                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1267 >            else if(currentHistogram.inputCollection == "track-jet pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1268 >                                                                                         cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1269 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1270 >                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1271 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1272 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1273 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1274 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1275 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1276 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1277 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1278 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1279 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1280 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1281 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1282 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1283 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1284 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1285 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1286 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1287 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1288 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1289 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1290 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1291 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1292 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1293 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1294 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1295 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1296 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1297 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1298 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1299 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1300 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1301 >          }
1302  
1303 <      if(currentHistogram.inputVariables.size() == 1){
590 <        TH1D* histo;
591 <        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
1303 >        }
1304  
1305  
1306 +        //fills histograms with the sizes of collections
1307 +        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1308  
1309 <        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
1310 <        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);
1309 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1310 >          string objectToPlot = "";
1311  
1312 <          }
1313 <        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
1314 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
1315 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
1316 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
1317 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
1318 <                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
1319 <                                                                                              cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
1320 <        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
1321 <        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
1322 <        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
1323 <        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
1324 <        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
1325 <        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
1326 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
1327 <        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
1328 <        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
1329 <        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
1330 <      }
1331 <      else if(currentHistogram.inputVariables.size() == 2){
1332 <        TH2D* histo;
1333 <        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
1334 <
1335 <
1336 <
1337 <        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
1338 <        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
1339 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1340 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
1341 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
1342 <        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
1343 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1344 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
1345 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
1346 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1347 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
1348 <                                                                                               cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
1349 <        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
1350 <        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
1351 <        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
1352 <        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
1353 <        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
1354 <        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
1355 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
1356 <        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
1357 <        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
1358 <        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
1359 <      }
1360 <    }
1361 <
1362 <    //fills histograms with the sizes of collections
1363 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1364 <      string currentObject = objectsToPlot.at(currentObjectIndex);
1365 <
1366 <      string objectToPlot = "";
1367 <
1368 <      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
1369 <      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
1370 <      else if(currentObject == "electron-muon pairs") objectToPlot = "electronMuonPairs";
1371 <      else objectToPlot = currentObject;
1372 <      string tempCurrentObject = objectToPlot;
1373 <      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1374 <      string histoName = "num" + tempCurrentObject;
1375 <
1376 <
1377 <
1378 <
671 <      //set position of primary vertex in event, in order to calculate quantities relative to it
672 <      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
673 <        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
674 <        int numToPlot = 0;
675 <        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
676 <          if(lastCutFlags.at(currentFlag)) numToPlot++;
677 <        }
678 <        if(objectToPlot == "primaryvertexs"){
679 <          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
680 <          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),puScaleFactor);
681 <        }
682 <        else
683 <          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,puScaleFactor);        
684 <      }
685 <      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),puScaleFactor);
686 <      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),puScaleFactor);
687 <      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,puScaleFactor);
688 <      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),puScaleFactor);
689 <      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,puScaleFactor);
690 <      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),puScaleFactor);
691 <      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),puScaleFactor);
692 <      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),puScaleFactor);
693 <      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),puScaleFactor);
694 <      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),puScaleFactor);
695 <      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),puScaleFactor);
696 <      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),puScaleFactor);
697 <      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),puScaleFactor);
698 <      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),puScaleFactor);
699 <      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),puScaleFactor);
700 <      else if(objectToPlot == "primaryvertexs"){
701 <        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
702 <        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),puScaleFactor);
703 <      }
1312 >          if (verbose_) clog << "Filling histogram of number of selected objects in collection: " << currentObject << endl;  
1313 >
1314 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1315 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1316 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1317 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1318 >          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1319 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1320 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1321 >          else if(currentObject == "muon-event pairs")                   objectToPlot = "muonEventPairs";
1322 >          else if(currentObject == "muon-photon pairs")                  objectToPlot = "muonPhotonPairs";
1323 >          else if(currentObject == "photon-jet pairs")                   objectToPlot = "photonJetPairs";
1324 >          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1325 >          else if(currentObject == "track-jet pairs")                    objectToPlot = "trackJetPairs";
1326 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1327 >          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1328 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1329 >          else if(currentObject == "secondary photons")                  objectToPlot = "secondaryPhotons";
1330 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1331 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1332 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1333 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1334 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1335 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1336 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1337 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1338 >          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1339 >          else if(currentObject == "muon-secondary photon pairs")        objectToPlot = "muonSecondaryJetPairs";
1340 >          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1341 >          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1342 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1343 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1344 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1345 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1346 >          else if(currentObject == "electron-mcparticle pairs")          objectToPlot = "electronMCparticlePairs";
1347 >          else objectToPlot = currentObject;
1348 >
1349 >          string tempCurrentObject = objectToPlot;
1350 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1351 >          string histoName = "num" + tempCurrentObject;
1352 >
1353 >
1354 >          if(find(objectsToPlot.begin(), objectsToPlot.end(), currentObject) != objectsToPlot.end()) {
1355 >            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1356 >            int numToPlot = 0;
1357 >            for (uint iObj = 0; iObj != lastCutFlags.size(); iObj++){  // loop over all the objects  
1358 >              if(lastCutFlags.at(iObj).second) {
1359 >                numToPlot++;  
1360 >                if (verbose_>3) clog << "   Found object " << iObj << " in collection " << currentObject << " to plot." << endl;
1361 >              }
1362 >            }
1363 >
1364 >            if(objectToPlot == "primaryvertexs"){
1365 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1366 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1367 >            }
1368 >            else {
1369 >              if (printEventInfo_) clog << "Number of selected " << objectToPlot << " to plot:  " << numToPlot << endl;  
1370 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1371 >            }
1372 >          }
1373 >
1374 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1375 >
1376 >
1377 >      } // end if(eventPassedPreviousCuts.at(currentDir))
1378 >    } // end loop over cuts
1379  
1380 +    if (!useEDMFormat_ && eventPassedAllCuts){
1381 +      // Assign BNTree variables
1382 +      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1383 +        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1384 +        string coll = brSpecs.inputCollection;
1385 +        if (cumulativeFlags.count(coll) == 0) clog << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1386 +
1387 +        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1388 +        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1389 +        else if(coll == "secondary photons")   assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1390 +        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1391 +        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,secMuons.product(),      cumulativeFlags.at(coll).back());
1392 +        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1393 +        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1394 +        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1395 +        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1396 +        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1397 +        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1398 +        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1399 +        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1400 +        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1401 +        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1402 +        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1403 +        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1404 +        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1405 +        else if(coll == "stops"
1406 +                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1407 +      } // end loop over branches
1408 +      // set the evtLong, runInt, and lumiInt variables separately, since they are not type float  
1409 +      BNTreeBranchVals_evtLong_ = events->at(0).evt;
1410 +      BNTreeBranchVals_runInt_  = events->at(0).run;
1411 +      BNTreeBranchVals_lumiInt_ = events->at(0).lumi;
1412 +
1413 +      if (!BNTrees_.at(currentChannelIndex)) { clog << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1414 +      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1415      }
1416  
1417 +    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1418  
1419 +  } // end loop over channel
1420  
1421 +  masterCutFlow_->fillCutFlow(masterScaleFactor);
1422  
1423 <  } //end loop over channel
1423 >  event.put (channelDecisions, "channelDecisions");
1424  
1425 <  masterCutFlow_->fillCutFlow(puScaleFactor);
1425 >  isFirstEvent_ = false;  
1426  
1427 +  if (verbose_) clog << "Finished OSUAnalysis::produce." << endl;  
1428  
1429 + } // end void OSUAnalysis::produce (const edm::Event &event, const edm::EventSetup &setup)
1430  
716 }
1431  
1432  
1433   bool
# Line 727 | Line 1441 | OSUAnalysis::evaluateComparison (double
1441    else if(comparison == "==") return testValue == cutValue;
1442    else if(comparison == "=") return testValue == cutValue;
1443    else if(comparison == "!=") return testValue != cutValue;
1444 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1444 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1445  
1446   }
1447  
1448   bool
1449 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1449 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1450  
1451 +
1452 +  if(comparison == ">")       return testValue >  cutValue;
1453 +  else if(comparison == ">=") return testValue >= cutValue;
1454 +  else if(comparison == "<")  return testValue <  cutValue;
1455 +  else if(comparison == "<=") return testValue <= cutValue;
1456 +  else if(comparison == "==") return testValue == cutValue;
1457 +  else if(comparison == "=")  return testValue == cutValue;
1458 +  else if(comparison == "!=") return testValue != cutValue;
1459 +  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1460 +
1461 + }
1462 +
1463 + bool
1464 + OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1465 +
1466 +  //initialize to false until a chosen trigger is passed
1467    bool triggerDecision = false;
1468  
1469 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1470 <    {
1471 <      if(trigger->pass != 1) continue;
1472 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1473 <        {
1474 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1475 <            triggerDecision = true;
1476 <          }
1477 <        }
1469 >  if (printAllTriggers_) clog << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1470 >  //loop over all triggers defined in the event
1471 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1472 >
1473 >    if (printAllTriggers_) clog << "   " << trigger->name << endl;
1474 >
1475 >    //we're only interested in triggers that actually passed
1476 >    if(trigger->pass != 1) continue;
1477 >
1478 >    //if the event passes one of the veto triggers, exit and return false
1479 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1480 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1481      }
1482 <  return triggerDecision;
1482 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1483 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1484 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1485 >    }
1486 >  }
1487  
1488 +  printAllTriggers_ = false;  // only print triggers once, not every event
1489 +
1490 +  //if none of the veto triggers fired:
1491 +  //return the OR of all the chosen triggers
1492 +  if (triggersToTest.size() != 0) return triggerDecision;
1493 +  //or if no triggers were defined return true
1494 +  else return true;
1495   }
1496  
1497 < std::vector<std::string>
1497 >
1498 > vector<string>
1499   OSUAnalysis::splitString (string inputString){
1500  
1501 <  std::stringstream stringStream(inputString);
1502 <  std::istream_iterator<std::string> begin(stringStream);
1503 <  std::istream_iterator<std::string> end;
1504 <  std::vector<std::string> stringVector(begin, end);
1501 >  stringstream stringStream(inputString);
1502 >  istream_iterator<string> begin(stringStream);
1503 >  istream_iterator<string> end;
1504 >  vector<string> stringVector(begin, end);
1505    return stringVector;
1506  
1507   }
1508  
1509 +
1510 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1511 +  // Set two object strings from the tempInputCollection string,
1512 +  // For example, if tempInputCollection is "electron-muon pairs",
1513 +  // then obj1 = "electrons" and obj2 = "muons".
1514 +  // Note that the objects have an "s" appended.
1515 +
1516 +  int dashIndex = tempInputCollection.find("-");
1517 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1518 +  int secondWordLength = spaceIndex - dashIndex;
1519 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1520 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1521 +
1522 + }
1523 +
1524 +
1525 + string OSUAnalysis::getObjToGet(string obj) {
1526 +  // Return the string corresponding to the object to get for the given obj string.
1527 +  // Right now this only handles the case in which obj contains "secondary",
1528 +  // e.g, "secondary muons".
1529 +  // Note that "s" is NOT appended.
1530 +
1531 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1532 +  int firstSpaceIndex = obj.find_first_of(" ");
1533 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1534 +
1535 + }
1536 +
1537 +
1538 + //!jet valueLookup
1539   double
1540 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1540 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1541  
1542    double value = 0.0;
1543    if(variable == "energy") value = object->energy;
# Line 881 | Line 1656 | OSUAnalysis::valueLookup (const BNjet* o
1656    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1657    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1658  
1659 +  //user defined variable
1660 +  else if(variable == "disappTrkLeadingJetID") {
1661 +    value = object->pt > 110
1662 +      && fabs(object->eta) < 2.4
1663 +      && object->chargedHadronEnergyFraction > 0.2
1664 +      && object->neutralHadronEnergyFraction < 0.7
1665 +      && object->chargedEmEnergyFraction < 0.5
1666 +      && object->neutralEmEnergyFraction < 0.7;
1667 +  }
1668 +
1669 +  else if(variable == "disappTrkSubLeadingJetID") {
1670 +    value = object->pt > 30
1671 +      && fabs(object->eta) < 4.5
1672 +      && object->neutralHadronEnergyFraction < 0.7
1673 +      && object->chargedEmEnergyFraction < 0.5;
1674 +  }
1675  
1676 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1676 >  else if(variable == "dPhiMet") {
1677 >    if (const BNmet *met = chosenMET ()) {
1678 >      value = deltaPhi (object->phi, met->phi);
1679 >    } else value = -999;
1680 >  }
1681 >
1682 >
1683 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1684  
1685    value = applyFunction(function, value);
1686  
1687    return value;
1688 < }
891 <
1688 > } // end jet valueLookup
1689  
1690  
1691 + //!muon valueLookup
1692   double
1693 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1693 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1694  
1695    double value = 0.0;
1696    if(variable == "energy") value = object->energy;
# Line 984 | Line 1782 | OSUAnalysis::valueLookup (const BNmuon*
1782    else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1783    else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1784    else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1785 +  else if(variable == "chargedHadronIsoDR04") value = object->chargedHadronIsoDR04;
1786 +  else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1787 +  else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1788 +  else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1789    else if(variable == "rhoPrime") value = object->rhoPrime;
1790    else if(variable == "AEffDr03") value = object->AEffDr03;
1791    else if(variable == "AEffDr04") value = object->AEffDr04;
# Line 991 | Line 1793 | OSUAnalysis::valueLookup (const BNmuon*
1793    else if(variable == "pfIsoR03SumNeutralHadronEt") value = object->pfIsoR03SumNeutralHadronEt;
1794    else if(variable == "pfIsoR03SumPhotonEt") value = object->pfIsoR03SumPhotonEt;
1795    else if(variable == "pfIsoR03SumPUPt") value = object->pfIsoR03SumPUPt;
1796 +  else if(variable == "relpfIsoR04SumExceptChargedHad") value = (object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)/ object->pt;
1797 +  else if(variable == "relpfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt/object->pt;
1798 +  else if(variable == "relpfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt/object->pt;
1799 +  else if(variable == "relpfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt/object->pt;
1800 +  else if(variable == "relpfIsoR04SumPUPt") value = object->pfIsoR04SumPUPt/object->pt;
1801    else if(variable == "pfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt;
1802    else if(variable == "pfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt;
1803    else if(variable == "pfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt;
# Line 1047 | Line 1854 | OSUAnalysis::valueLookup (const BNmuon*
1854    else if(variable == "time_ndof") value = object->time_ndof;
1855  
1856    //user-defined variables
1857 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenPrimaryVertex->xError, chosenPrimaryVertex->yError));
1858 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenPrimaryVertex->xError, chosenPrimaryVertex->yError));
1857 >  else if(variable == "looseID") {
1858 >    value = object->pt > 10 &&
1859 >      (object->isGlobalMuon  > 0 ||
1860 >       object->isTrackerMuon > 0);
1861 >  }
1862 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1863 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1864    else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1865 <  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1865 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1866 >  else if(variable == "relPFdBetaIsoPseudo") value = (object->pfIsoR04SumChargedHadronPt + object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt) / object->pt;
1867    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1868 <
1869 <
1868 >  else if(variable == "metMT") {
1869 >    if (const BNmet *met = chosenMET ())
1870 >      {
1871 >        double dPhi = deltaPhi (object->phi, met->phi);
1872 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1873 >      }
1874 >    else
1875 >      value = -999;
1876 >  }
1877 >  else if(variable == "ptPlusMet") {
1878 >    // Calculate the magnitude of the vector sum of the muon pT and the Met.  
1879 >    if (const BNmet *met = chosenMET ())
1880 >      {
1881 >        TVector2 p2Met;
1882 >        TVector2 p2Muon;
1883 >        p2Met. SetMagPhi(   met->pt,    met->phi);
1884 >        p2Muon.SetMagPhi(object->pt, object->phi);  
1885 >        TVector2 p2MetElec = p2Met + p2Muon;
1886 >        value = p2MetElec.Mod();  
1887 >      }
1888 >    else
1889 >      value = -999;
1890 >  }
1891  
1892    else if(variable == "correctedD0VertexInEBPlus"){
1893      if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
# Line 1162 | Line 1996 | OSUAnalysis::valueLookup (const BNmuon*
1996  
1997  
1998    else if(variable == "tightID") {
1999 <    value = object->isGlobalMuon > 0            \
2000 <      && object->isPFMuon > 0                   \
2001 <      && object->normalizedChi2 < 10            \
2002 <      && object->numberOfValidMuonHits > 0      \
2003 <      && object->numberOfMatchedStations > 1    \
2004 <      && fabs(object->correctedD0Vertex) < 0.2  \
2005 <      && fabs(object->correctedDZ) < 0.5        \
2006 <      && object->numberOfValidPixelHits > 0             \
1999 >    value = object->isGlobalMuon > 0                \
2000 >      && object->isPFMuon > 0                        \
2001 >      && object->normalizedChi2 < 10                \
2002 >      && object->numberOfValidMuonHits > 0        \
2003 >      && object->numberOfMatchedStations > 1        \
2004 >      && fabs(object->correctedD0Vertex) < 0.2        \
2005 >      && fabs(object->correctedDZ) < 0.5        \
2006 >      && object->numberOfValidPixelHits > 0                \
2007        && object->numberOfLayersWithMeasurement > 5;
2008    }
2009    else if(variable == "tightIDdisplaced"){
2010 <    value = object->isGlobalMuon > 0            \
2011 <      && object->normalizedChi2 < 10            \
2012 <      && object->numberOfValidMuonHits > 0      \
2013 <      && object->numberOfMatchedStations > 1    \
2014 <      && 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 >      && object->numberOfValidPixelHits > 0        \
2016        && object->numberOfLayersWithMeasurement > 5;
2017    }
2018  
2019 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2020  
2021 +  else if(variable == "genMatchedPdgId"){
2022 +    int index = getGenMatchedParticleIndex(object);
2023 +    if(index == -1) value = 0;
2024 +    else value = mcparticles->at(index).id;
2025 +  }
2026  
2027    else if(variable == "genMatchedId"){
2028      int index = getGenMatchedParticleIndex(object);
# Line 1193 | Line 2034 | OSUAnalysis::valueLookup (const BNmuon*
2034      if(index == -1) value = 0;
2035      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2036    }
2037 +  else if(variable == "genMatchedMotherIdReverse"){
2038 +    int index = getGenMatchedParticleIndex(object);
2039 +    if(index == -1) value = 24;
2040 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
2041 +  }
2042    else if(variable == "genMatchedGrandmotherId"){
2043      int index = getGenMatchedParticleIndex(object);
2044      if(index == -1) value = 0;
# Line 1203 | Line 2049 | OSUAnalysis::valueLookup (const BNmuon*
2049      }
2050      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2051    }
2052 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2053 +    int index = getGenMatchedParticleIndex(object);
2054 +    if(index == -1) value = 24;
2055 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2056 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2057 +      if(motherIndex == -1) value = 24;
2058 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2059 +    }
2060 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2061 +  }
2062 +  else if(variable == "pfMuonsFromVertex"){
2063 +    double d0Error, dzError;
2064 +
2065 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2066 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2067 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2068 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2069 +      || fabs (object->correctedDZ / dzError) > 99.0;
2070 +    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
2071 +  }
2072  
2073  
2074  
2075 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2075 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2076  
2077    value = applyFunction(function, value);
2078  
2079    return value;
2080 < }
2080 > } // end muon valueLookup
2081  
2082  
2083 + //!electron valueLookup
2084   double
2085 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
2085 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
2086  
2087    double value = 0.0;
2088    if(variable == "energy") value = object->energy;
# Line 1376 | Line 2243 | OSUAnalysis::valueLookup (const BNelectr
2243    else if(variable == "passConvVeto") value = object->passConvVeto;
2244  
2245    //user-defined variables
2246 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenPrimaryVertex->xError, chosenPrimaryVertex->yError));
2247 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenPrimaryVertex->xError, chosenPrimaryVertex->yError));
2246 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2247 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2248    else if(variable == "detIso") value = (object->trackIso) / object->pt;
2249    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2250 +  else if(variable == "relPFrhoIsoEB") value = object->isEB ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2251 +  else if(variable == "relPFrhoIsoEE") value = object->isEE ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2252 +  else if(variable == "metMT") {
2253 +    if (const BNmet *met = chosenMET ())
2254 +      {
2255 +        double dPhi = deltaPhi (object->phi, met->phi);
2256 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2257 +      }
2258 +    else
2259 +      value = -999;
2260 +  }
2261  
2262 +  else if(variable == "ptPlusMet") {
2263 +    // Calculate the magnitude of the vector sum of the electron pT and the Met.  
2264 +    if (const BNmet *met = chosenMET ())
2265 +      {
2266 +        TVector2 p2Met;
2267 +        TVector2 p2Elec;
2268 +        p2Met. SetMagPhi(   met->pt,    met->phi);
2269 +        p2Elec.SetMagPhi(object->pt, object->phi);  
2270 +        TVector2 p2MetElec = p2Met + p2Elec;
2271 +        value = p2MetElec.Mod();  
2272 +      }
2273 +    else
2274 +      value = -999;
2275 +  }
2276  
2277    else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
2278      if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
# Line 1391 | Line 2283 | OSUAnalysis::valueLookup (const BNelectr
2283      else value = -999;
2284    }
2285  
1394
2286    else if(variable == "correctedD0VertexInEBPlus"){
2287      if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
2288      else value = -999;
# Line 1444 | Line 2335 | OSUAnalysis::valueLookup (const BNelectr
2335      else value = -999;
2336    }
2337  
2338 +  else if(variable == "looseID"){
2339 +    if (object->isEB)
2340 +      {
2341 +        value = fabs(object->delEtaIn) < 0.007 \
2342 +          && fabs (object->delPhiIn) < 0.15 \
2343 +          && object->scSigmaIEtaIEta < 0.01 \
2344 +          && object->hadOverEm < 0.12 \
2345 +          && fabs (object->correctedD0Vertex) < 0.02 \
2346 +          && fabs (object->correctedDZ) < 0.2 \
2347 +          && object->absInvEMinusInvPin < 0.05 \
2348 +          && object->passConvVeto;
2349 +      }
2350 +    else
2351 +      {
2352 +        value = fabs(object->delEtaIn) < 0.009 \
2353 +          && fabs (object->delPhiIn) < 0.10 \
2354 +          && object->scSigmaIEtaIEta < 0.03 \
2355 +          && object->hadOverEm < 0.10 \
2356 +          && fabs (object->correctedD0Vertex) < 0.02 \
2357 +          && fabs (object->correctedDZ) < 0.2 \
2358 +          && object->absInvEMinusInvPin < 0.05 \
2359 +          && object->passConvVeto;
2360 +      }
2361 +  }
2362  
2363 +  else if(variable == "tightID"){
2364 +    if (object->isEB)
2365 +      {
2366 +        value = fabs(object->delEtaIn) < 0.004 \
2367 +          && fabs (object->delPhiIn) < 0.03 \
2368 +          && object->scSigmaIEtaIEta < 0.01 \
2369 +          && object->hadOverEm < 0.12 \
2370 +          && fabs (object->correctedD0Vertex) < 0.02 \
2371 +          && fabs (object->correctedDZ) < 0.1 \
2372 +          && object->absInvEMinusInvPin < 0.05 \
2373 +          && object->passConvVeto;
2374 +      }
2375 +    else
2376 +      {
2377 +        value = fabs(object->delEtaIn) < 0.005 \
2378 +          && fabs (object->delPhiIn) < 0.02 \
2379 +          && object->scSigmaIEtaIEta < 0.03 \
2380 +          && object->hadOverEm < 0.10 \
2381 +          && fabs (object->correctedD0Vertex) < 0.02 \
2382 +          && fabs (object->correctedDZ) < 0.1 \
2383 +          && object->absInvEMinusInvPin < 0.05 \
2384 +          && object->passConvVeto;
2385 +      }
2386 +  }
2387 +
2388 +  else if(variable == "looseID_MVA"){
2389 +    value = object->pt > 10
2390 +      && object->mvaNonTrigV0 > 0;
2391 +      }
2392    else if(variable == "correctedD0VertexInEBPositiveCharge"){
2393      if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2394      else value = -999;
# Line 1501 | Line 2445 | OSUAnalysis::valueLookup (const BNelectr
2445    else if(variable == "tightIDdisplaced"){
2446      if (object->isEB)
2447        {
2448 <        value = fabs(object->delEtaIn) < 0.004 \
2449 <          && fabs (object->delPhiIn) < 0.03 \
2448 >        value = fabs(object->delEtaIn) < 0.004 \
2449 >          && fabs (object->delPhiIn) < 0.03 \
2450            && object->scSigmaIEtaIEta < 0.01 \
2451            && object->hadOverEm < 0.12 \
2452 <          && object->absInvEMinusInvPin < 0.05;
2452 >          && object->absInvEMinusInvPin < 0.05;
2453        }
2454      else
2455        {
2456 <        value = fabs (object->delEtaIn) < 0.005 \
2457 <          && fabs (object->delPhiIn) < 0.02 \
2456 >        value = fabs (object->delEtaIn) < 0.005 \
2457 >          && fabs (object->delPhiIn) < 0.02 \
2458            && object->scSigmaIEtaIEta < 0.03 \
2459            && object->hadOverEm < 0.10 \
2460 <          && object->absInvEMinusInvPin < 0.05;
2460 >          && object->absInvEMinusInvPin < 0.05;
2461        }
2462    }
2463  
2464 +
2465 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2466 +
2467 +  else if(variable == "genMatchedPdgId"){
2468 +    int index = getGenMatchedParticleIndex(object);
2469 +    if(index == -1) value = 0;
2470 +    else value = mcparticles->at(index).id;
2471 +  }
2472 +
2473 +
2474    else if(variable == "genMatchedId"){
2475      int index = getGenMatchedParticleIndex(object);
2476      if(index == -1) value = 0;
# Line 1527 | Line 2481 | OSUAnalysis::valueLookup (const BNelectr
2481      if(index == -1) value = 0;
2482      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2483    }
2484 +  else if(variable == "genMatchedMotherIdReverse"){
2485 +    int index = getGenMatchedParticleIndex(object);
2486 +    if(index == -1) value = 24;
2487 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2488 +  }
2489    else if(variable == "genMatchedGrandmotherId"){
2490      int index = getGenMatchedParticleIndex(object);
2491      if(index == -1) value = 0;
# Line 1537 | Line 2496 | OSUAnalysis::valueLookup (const BNelectr
2496      }
2497      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2498    }
2499 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2500 +    int index = getGenMatchedParticleIndex(object);
2501 +    if(index == -1) value = 24;
2502 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2503 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2504 +      if(motherIndex == -1) value = 24;
2505 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2506 +    }
2507 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2508 +  }
2509 +  else if(variable == "pfElectronsFromVertex"){
2510 +    double d0Error, dzError;
2511 +
2512 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2513 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2514 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2515 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2516 +      || fabs (object->correctedDZ / dzError) > 99.0;
2517 +    value = !value;
2518 +  }
2519  
2520  
2521  
2522 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2522 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2523  
2524    value = applyFunction(function, value);
2525  
2526    return value;
2527 < }
2527 > } // end electron valueLookup
2528  
2529  
2530 + //!event valueLookup
2531   double
2532 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2532 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2533  
2534    double value = 0.0;
2535  
# Line 1617 | Line 2597 | OSUAnalysis::valueLookup (const BNevent*
2597    else if(variable == "id1") value = object->id1;
2598    else if(variable == "id2") value = object->id2;
2599    else if(variable == "evt") value = object->evt;
2600 <
2601 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2600 >  else if(variable == "puScaleFactor"){
2601 >    if(doPileupReweighting_ && datasetType_ != "data")
2602 >      value = puWeight_->at (events->at (0).numTruePV);
2603 >    else
2604 >      value = 1.0;
2605 >  }
2606 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2607 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2608 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2609 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2610 >
2611 >  else if(variable == "unfilteredHt") value = getHt(jets.product());
2612 >  else if(variable == "ht") value = chosenHT ();
2613 >
2614 >  else if(variable == "leadMuPairInvMass"){
2615 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2616 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2617 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2618 >    value = (p0 + p1).M ();
2619 >  }
2620 >  else if(variable == "leadMuPairPt"){
2621 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2622 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2623 >             pt1 (muPair.second->px, muPair.second->py);
2624 >    pt0 += pt1;
2625 >    value = pt0.Mod ();
2626 >  }
2627 >  else if(variable == "leadElPairInvMass"){
2628 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2629 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2630 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2631 >    value = (p0 + p1).M ();
2632 >  }
2633 >  else if(variable == "leadElPairPt"){
2634 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2635 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2636 >             pt1 (muPair.second->px, muPair.second->py);
2637 >    pt0 += pt1;
2638 >    value = pt0.Mod ();
2639 >  }
2640 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2641  
2642    value = applyFunction(function, value);
2643  
2644    return value;
2645 < }
2645 > } // end event valueLookup
2646  
2647 +
2648 + //!tau valueLookup
2649   double
2650 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2650 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2651  
2652    double value = 0.0;
2653  
# Line 1670 | Line 2691 | OSUAnalysis::valueLookup (const BNtau* o
2691    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2692    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2693  
2694 +  else if (variable == "looseHadronicID") {
2695 +    value = object->pt > 10
2696 +      && object->eta < 2.3
2697 +      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2698 +      && object->HPSdecayModeFinding > 0
2699 +      && object->HPSagainstElectronLoose > 0
2700 +      && object->HPSagainstMuonTight > 0;
2701 +  }
2702 +
2703 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2704 +
2705 +  else if(variable == "genMatchedPdgId"){
2706 +    int index = getGenMatchedParticleIndex(object);
2707 +    if(index == -1) value = 0;
2708 +    else value = mcparticles->at(index).id;
2709 +  }
2710  
2711    else if(variable == "genMatchedId"){
2712      int index = getGenMatchedParticleIndex(object);
# Line 1681 | Line 2718 | OSUAnalysis::valueLookup (const BNtau* o
2718      if(index == -1) value = 0;
2719      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2720    }
2721 +  else if(variable == "genMatchedMotherIdReverse"){
2722 +    int index = getGenMatchedParticleIndex(object);
2723 +    if(index == -1) value = 24;
2724 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2725 +  }
2726    else if(variable == "genMatchedGrandmotherId"){
2727      int index = getGenMatchedParticleIndex(object);
2728      if(index == -1) value = 0;
# Line 1691 | Line 2733 | OSUAnalysis::valueLookup (const BNtau* o
2733      }
2734      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2735    }
2736 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2737 +    int index = getGenMatchedParticleIndex(object);
2738 +    if(index == -1) value = 24;
2739 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2740 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2741 +      if(motherIndex == -1) value = 24;
2742 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2743 +    }
2744 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2745 +  }
2746  
2747  
2748 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2748 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2749  
2750    value = applyFunction(function, value);
2751  
2752    return value;
2753 < }
2753 > } // end tau valueLookup
2754 >
2755  
2756 + //!met valueLookup
2757   double
2758 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2758 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2759  
2760    double value = 0.0;
2761  
# Line 1765 | Line 2819 | OSUAnalysis::valueLookup (const BNmet* o
2819    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2820    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2821  
2822 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2822 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2823  
2824    value = applyFunction(function, value);
2825  
2826    return value;
2827 < }
2827 > } // end met valueLookup
2828 >
2829  
2830 + //!track valueLookup
2831   double
2832 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2832 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2833  
2834    double value = 0.0;
2835    double pMag = sqrt(object->pt * object->pt +
2836 <                         object->pz * object->pz);
2837 <  
2836 >                     object->pz * object->pz);
2837 >
2838    if(variable == "pt") value = object->pt;
2839    else if(variable == "px") value = object->px;
2840    else if(variable == "py") value = object->py;
# Line 1797 | Line 2853 | OSUAnalysis::valueLookup (const BNtrack*
2853    else if(variable == "numValidHits") value = object->numValidHits;
2854    else if(variable == "isHighPurity") value = object->isHighPurity;
2855  
2856 <
2857 <  //additional BNs info for disappTrks  
2858 <  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2859 <  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2860 <  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2861 <  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2862 <  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2863 <  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2864 <  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
1809 <  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
1810 <  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2856 >  //additional BNs info for disappTrks
2857 >  else if(variable == "caloEMDeltaRp3")     value = object->caloEMDeltaRp3;
2858 >  else if(variable == "caloHadDeltaRp3")    value = object->caloHadDeltaRp3;
2859 >  else if(variable == "caloEMDeltaRp4")     value = object->caloEMDeltaRp4;
2860 >  else if(variable == "caloHadDeltaRp4")    value = object->caloHadDeltaRp4;
2861 >  else if(variable == "caloEMDeltaRp5")     value = object->caloEMDeltaRp5;
2862 >  else if(variable == "caloHadDeltaRp5")    value = object->caloHadDeltaRp5;
2863 >  else if(variable == "nHitsMissingOuter")  value = object->nHitsMissingOuter;
2864 >  else if(variable == "nHitsMissingInner")  value = object->nHitsMissingInner;
2865    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2866 +  else if(variable == "depTrkRp3")          value = object->depTrkRp3;
2867 +  else if(variable == "trkRelIsoRp3")     { value = (object->depTrkRp3 - object->pt) / object->pt; if (value<0) value = 0; }
2868 +  else if(variable == "trkRelIsoRp5")     { value = (object->depTrkRp5 - object->pt) / object->pt; if (value<0) value = 0; }
2869 +  else if(variable == "depEcalRp3")         value = object->depEcalRp3;
2870 +  else if(variable == "depHcalRp3")         value = object->depHcalRp3;
2871 +  else if(variable == "depHoRp3")           value = object->depHoRp3;
2872 +  else if(variable == "nTracksRp3")         value = object->nTracksRp3;
2873 +  else if(variable == "trackerVetoPtRp3")   value = object->trackerVetoPtRp3;
2874 +  else if(variable == "emVetoEtRp3")        value = object->emVetoEtRp3;
2875 +  else if(variable == "hadVetoEtRp3")       value = object->hadVetoEtRp3;
2876 +  else if(variable == "hoVetoEtRp3")        value = object->hoVetoEtRp3;
2877 +  else if(variable == "depTrkRp5")          value = object->depTrkRp5;
2878 +  else if(variable == "depEcalRp5")         value = object->depEcalRp5;
2879 +  else if(variable == "depHcalRp5")         value = object->depHcalRp5;
2880 +  else if(variable == "depHoRp5")           value = object->depHoRp5;
2881 +  else if(variable == "nTracksRp5")         value = object->nTracksRp5;
2882 +  else if(variable == "trackerVetoPtRp5")   value = object->trackerVetoPtRp5;
2883 +  else if(variable == "emVetoEtRp5")        value = object->emVetoEtRp5;
2884 +  else if(variable == "hadVetoEtRp5")       value = object->hadVetoEtRp5;
2885 +  else if(variable == "hoVetoEtRp5")        value = object->hoVetoEtRp5;
2886 +
2887    //user defined variables
2888    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;
2889    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2890 <  else if(variable == "caloTotDeltaRp5") value =(object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2891 <  else if(variable == "caloTotDeltaRp5ByP") value =( (object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2892 <  else if(variable == "isIso") value = getTrkIsIso(object, tracks.product());
2893 <  else if(variable == "isMatchedDeadEcal") value = getTrkIsMatchedDeadEcal(object);
2894 <  else if(variable == "ptErrorByPt") value = (object->ptError/object->pt);
2895 <  else if(variable == "ptError") value = object->ptError;
2896 <  else if(variable == "ptRes") value = getTrkPtRes(object);  
2890 >  else if(variable == "depTrkRp5MinusPt"){
2891 >    if ( (object->depTrkRp5 - object->pt) < 0 ) {
2892 > //       clog << "Warning:  found track with depTrkRp5 < pt:  depTrkRp5=" << object->depTrkRp5
2893 > //         << "; pt=" << object->pt
2894 > //         << "; object->depTrkRp5 - object->pt = " << object->depTrkRp5 - object->pt
2895 > //         << endl;  
2896 >           value = 0;
2897 >         }
2898 >         else value =  (object->depTrkRp5 - object->pt);
2899 >  }
2900 >  else if(variable == "depTrkRp3MinusPt"){
2901 >    if ( (object->depTrkRp3 - object->pt) < 0 ) {
2902 >      value = 0;
2903 >    }
2904 >    else value =  (object->depTrkRp3 - object->pt);
2905 >  }
2906 >
2907 >  else if(variable == "dPhiMet") {
2908 >    if (const BNmet *met = chosenMET ()) {
2909 >      value = deltaPhi (object->phi, met->phi);
2910 >    } else value = -999;
2911 >  }
2912 >  
2913 >  
2914 >  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2915 >  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2916 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2917 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2918 >  else if(variable == "depTrkRp5RhoCorr")           value = getTrkDepTrkRp5RhoCorr(object);
2919 >  else if(variable == "depTrkRp3RhoCorr")           value = getTrkDepTrkRp3RhoCorr(object);
2920 >
2921 >  else if(variable == "depTrkRp5MinusPtRhoCorr")    {
2922 >    if ( (getTrkDepTrkRp5RhoCorr(object) - object->pt) < 0 ) value = 0;
2923 >    else {value = (getTrkDepTrkRp5RhoCorr(object) - object->pt );}
2924 >  }
2925 >  
2926 >  else if(variable == "depTrkRp3MinusPtRhoCorr")    
2927 >    {
2928 >      if ( (getTrkDepTrkRp3RhoCorr(object) - object->pt) < 0 ) value = 0;
2929 >      else {value = (getTrkDepTrkRp3RhoCorr(object) - object->pt );}
2930 >    }
2931 >
2932 >  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2933 >  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2934 >  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2935 >  else if(variable == "ptError")                    value = object->ptError;
2936 >  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2937 >  else if (variable == "d0wrtPV"){
2938 >    double vx = object->vx - chosenVertex ()->x,
2939 >      vy = object->vy - chosenVertex ()->y,
2940 >      px = object->px,
2941 >      py = object->py,
2942 >      pt = object->pt;
2943 >    value = (-vx * py + vy * px) / pt;
2944 >  }
2945 >  else if (variable == "dZwrtPV"){
2946 >    double vx = object->vx - chosenVertex ()->x,
2947 >      vy = object->vy - chosenVertex ()->y,
2948 >      vz = object->vz - chosenVertex ()->z,
2949 >      px = object->px,
2950 >      py = object->py,
2951 >      pz = object->pz,
2952 >      pt = object->pt;
2953 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2954 >  }
2955 >
2956 >  else if(variable == "deltaRMinSubLeadJet") {
2957 >    // calculate minimum deltaR between track and any other subleading jet  
2958 >    double trkJetDeltaRMin = 99.;  
2959 >    for (uint ijet = 0; ijet<jets->size(); ijet++) {
2960 >      string empty = "";  
2961 >      double isSubLeadingJet = valueLookup(&jets->at(ijet), "disappTrkSubLeadingJetID", "", empty);  
2962 >      if (!isSubLeadingJet) continue;  // only consider jets that pass the subleading jet ID criteria  
2963 >      double jetEta = valueLookup(&jets->at(ijet), "eta", "", empty);
2964 >      double jetPhi = valueLookup(&jets->at(ijet), "phi", "", empty);
2965 >      double trkJetDeltaR = deltaR(object->eta, object->phi, jetEta, jetPhi);  
2966 >      if (trkJetDeltaR < trkJetDeltaRMin) trkJetDeltaRMin = trkJetDeltaR;
2967 >    }
2968 >    value = trkJetDeltaRMin;  
2969 >  }  
2970 >  
2971 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2972 >
2973 >  else if(variable == "genMatchedPdgId"){
2974 >    int index = getGenMatchedParticleIndex(object);
2975 >    if(index == -1) value = 0;
2976 >    else value = mcparticles->at(index).id;
2977 >  }
2978  
2979  
2980    else if(variable == "genMatchedId"){
# Line 1831 | Line 2987 | OSUAnalysis::valueLookup (const BNtrack*
2987      if(index == -1) value = 0;
2988      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2989    }
2990 +  else if(variable == "genMatchedMotherIdReverse"){
2991 +    int index = getGenMatchedParticleIndex(object);
2992 +    if(index == -1) value = 24;
2993 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2994 +  }
2995    else if(variable == "genMatchedGrandmotherId"){
2996      int index = getGenMatchedParticleIndex(object);
2997      if(index == -1) value = 0;
# Line 1841 | Line 3002 | OSUAnalysis::valueLookup (const BNtrack*
3002      }
3003      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3004    }
3005 +  else if(variable == "genMatchedGrandmotherIdReverse"){
3006 +    int index = getGenMatchedParticleIndex(object);
3007 +    if(index == -1) value = 24;
3008 +    else if(fabs(mcparticles->at(index).motherId) == 15){
3009 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3010 +      if(motherIndex == -1) value = 24;
3011 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3012 +    }
3013 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3014 +  }
3015  
3016  
3017  
3018 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3018 >  else{clog << "WARNING: invalid variable '" << variable << "' for BNtrack collection.\n"; value = -999;}
3019  
3020    value = applyFunction(function, value);
3021  
3022    return value;
3023 < }
3023 > } // end track valueLookup
3024 >
3025  
3026 + //!genjet valueLookup
3027   double
3028 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
3028 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
3029  
3030    double value = 0.0;
3031  
# Line 1872 | Line 3045 | OSUAnalysis::valueLookup (const BNgenjet
3045    else if(variable == "charge") value = object->charge;
3046  
3047  
3048 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3048 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3049  
3050    value = applyFunction(function, value);
3051  
3052    return value;
3053   }
3054  
3055 + //!mcparticle valueLookup
3056   double
3057 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
3057 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
3058  
3059    double value = 0.0;
3060  
# Line 1971 | Line 3145 | OSUAnalysis::valueLookup (const BNmcpart
3145  
3146    //user-defined variables
3147    else if (variable == "d0"){
3148 <    double vx = object->vx - chosenPrimaryVertex->x,
3149 <      vy = object->vy - chosenPrimaryVertex->y,
3148 >    double vx = object->vx - chosenVertex ()->x,
3149 >      vy = object->vy - chosenVertex ()->y,
3150        px = object->px,
3151        py = object->py,
3152        pt = object->pt;
3153      value = (-vx * py + vy * px) / pt;
3154    }
3155    else if (variable == "dz"){
3156 <    double vx = object->vx - chosenPrimaryVertex->x,
3157 <      vy = object->vy - chosenPrimaryVertex->y,
3158 <      vz = object->vz - chosenPrimaryVertex->z,
3156 >    double vx = object->vx - chosenVertex ()->x,
3157 >      vy = object->vy - chosenVertex ()->y,
3158 >      vz = object->vz - chosenVertex ()->z,
3159        px = object->px,
3160        py = object->py,
3161        pz = object->pz,
# Line 1992 | Line 3166 | OSUAnalysis::valueLookup (const BNmcpart
3166      value = sqrt(object->vx*object->vx + object->vy*object->vy);
3167    }
3168    else if(variable == "deltaV0"){
3169 <    value = sqrt((object->vx-chosenPrimaryVertex->x)*(object->vx-chosenPrimaryVertex->x) + (object->vy-chosenPrimaryVertex->y)*(object->vy-chosenPrimaryVertex->y));
3169 >    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
3170    }
3171    else if (variable == "deltaVx"){
3172 <    value = object->vx - chosenPrimaryVertex->x;
3172 >    value = object->vx - chosenVertex ()->x;
3173    }
3174    else if (variable == "deltaVy"){
3175 <    value = object->vy - chosenPrimaryVertex->y;
3175 >    value = object->vy - chosenVertex ()->y;
3176    }
3177    else if (variable == "deltaVz"){
3178 <    value = object->vz - chosenPrimaryVertex->z;
3178 >    value = object->vz - chosenVertex ()->z;
3179    }
3180  
3181  
3182 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3182 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3183  
3184    value = applyFunction(function, value);
3185  
3186    return value;
3187 < }
3187 > } // end mcparticle valueLookup
3188 >
3189  
3190 + //!primaryvertex valueLookup
3191   double
3192 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
3192 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
3193  
3194    double value = 0.0;
3195  
# Line 2032 | Line 3208 | OSUAnalysis::valueLookup (const BNprimar
3208    else if(variable == "isGood") value = object->isGood;
3209  
3210  
3211 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3211 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3212  
3213    value = applyFunction(function, value);
3214  
3215    return value;
3216   }
3217  
3218 + //!bxlumi valueLookup
3219   double
3220 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
3220 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
3221  
3222    double value = 0.0;
3223  
# Line 2049 | Line 3226 | OSUAnalysis::valueLookup (const BNbxlumi
3226    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
3227  
3228  
3229 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3229 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3230  
3231    value = applyFunction(function, value);
3232  
3233    return value;
3234   }
3235  
3236 + //!photon valueLookup
3237   double
3238 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
3238 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
3239  
3240    double value = 0.0;
3241  
# Line 2132 | Line 3310 | OSUAnalysis::valueLookup (const BNphoton
3310    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
3311  
3312  
3313 +
3314 +
3315 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3316 +
3317 +  else if(variable == "genMatchedPdgId"){
3318 +    int index = getGenMatchedParticleIndex(object);
3319 +    if(index == -1) value = 0;
3320 +    else value = mcparticles->at(index).id;
3321 +  }
3322 +
3323 +
3324 +
3325    else if(variable == "genMatchedId"){
3326      int index = getGenMatchedParticleIndex(object);
3327      if(index == -1) value = 0;
# Line 2142 | Line 3332 | OSUAnalysis::valueLookup (const BNphoton
3332      if(index == -1) value = 0;
3333      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
3334    }
3335 +  else if(variable == "genMatchedMotherIdReverse"){
3336 +    int index = getGenMatchedParticleIndex(object);
3337 +    if(index == -1) value = 24;
3338 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
3339 +  }
3340    else if(variable == "genMatchedGrandmotherId"){
3341      int index = getGenMatchedParticleIndex(object);
3342      if(index == -1) value = 0;
# Line 2152 | Line 3347 | OSUAnalysis::valueLookup (const BNphoton
3347      }
3348      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3349    }
3350 +  else if(variable == "genMatchedGrandmotherIdReverse"){
3351 +    int index = getGenMatchedParticleIndex(object);
3352 +    if(index == -1) value = 24;
3353 +    else if(fabs(mcparticles->at(index).motherId) == 15){
3354 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3355 +      if(motherIndex == -1) value = 24;
3356 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3357 +    }
3358 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3359 +  }
3360  
3361  
3362 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3362 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3363  
3364    value = applyFunction(function, value);
3365  
3366    return value;
3367 < }
3367 > } // end photon valueLookup
3368 >
3369  
3370 + //!supercluster valueLookup
3371   double
3372 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
3372 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
3373  
3374    double value = 0.0;
3375  
# Line 2176 | Line 3383 | OSUAnalysis::valueLookup (const BNsuperc
3383    else if(variable == "theta") value = object->theta;
3384  
3385  
3386 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3386 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3387  
3388    value = applyFunction(function, value);
3389  
3390    return value;
3391   }
3392  
3393 + //!trigobj valueLookup
3394 + double
3395 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3396 +
3397 +  double value = 0.0;
3398 +
3399 +  if(variable == "pt") value = object->pt;
3400 +  else if(variable == "eta") value = object->eta;
3401 +  else if(variable == "phi") value = object->phi;
3402 +  else if(variable == "px") value = object->px;
3403 +  else if(variable == "py") value = object->py;
3404 +  else if(variable == "pz") value = object->pz;
3405 +  else if(variable == "et") value = object->et;
3406 +  else if(variable == "energy") value = object->energy;
3407 +  else if(variable == "etTotal") value = object->etTotal;
3408 +  else if(variable == "id") value = object->id;
3409 +  else if(variable == "charge") value = object->charge;
3410 +  else if(variable == "isIsolated") value = object->isIsolated;
3411 +  else if(variable == "isMip") value = object->isMip;
3412 +  else if(variable == "isForward") value = object->isForward;
3413 +  else if(variable == "isRPC") value = object->isRPC;
3414 +  else if(variable == "bx") value = object->bx;
3415 +  else if(variable == "filter") {
3416 +    if ((stringValue = object->filter) == "")
3417 +      stringValue = "none";  // stringValue should only be empty if value is filled
3418 +  }
3419 +
3420 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3421 +
3422 +  value = applyFunction(function, value);
3423 +
3424 +  return value;
3425 + }
3426  
3427 + //!muon-muon pair valueLookup
3428   double
3429 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
3429 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3430  
3431    double value = 0.0;
3432  
3433    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3434 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3435    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3436    else if(variable == "invMass"){
3437      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3438      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3439 <
3440 <    value = (fourVector1 + fourVector2).M();}
3441 <
3439 >    value = (fourVector1 + fourVector2).M();
3440 >  }
3441 >  else if(variable == "pt"){
3442 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3443 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3444 >    value = (fourVector1 + fourVector2).Pt();
3445 >  }
3446    else if(variable == "threeDAngle")
3447      {
3448        TVector3 threeVector1(object1->px, object1->py, object1->pz);
# Line 2208 | Line 3454 | OSUAnalysis::valueLookup (const BNmuon*
3454        static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3455        TVector3 threeVector1(object1->px, object1->py, object1->pz);
3456        TVector3 threeVector2(object2->px, object2->py, object2->pz);
3457 <      value = (pi-threeVector1.Angle( threeVector2));
3457 >      value = (pi-threeVector1.Angle(threeVector2));
3458      }
2213
2214  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2215
2216
3459    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3460    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3461    else if(variable == "d0Sign"){
# Line 2222 | Line 3464 | OSUAnalysis::valueLookup (const BNmuon*
3464      else if (d0Sign > 0) value = 0.5;
3465      else value = -999;
3466    }
3467 +  else if(variable == "chargeProduct"){
3468 +    value = object1->charge*object2->charge;
3469 +  }
3470    else if(variable == "muon1CorrectedD0Vertex"){
3471      value = object1->correctedD0Vertex;
3472    }
3473    else if(variable == "muon2CorrectedD0Vertex"){
3474      value = object2->correctedD0Vertex;
3475    }
3476 < else if(variable == "muon1timeAtIpInOut"){
3476 >  else if(variable == "muon1timeAtIpInOut"){
3477      value = object1->timeAtIpInOut;
3478    }
3479 < else if(variable == "muon2timeAtIpInOut"){
3479 >  else if(variable == "muon2timeAtIpInOut"){
3480      value = object2->timeAtIpInOut;
3481    }
3482 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3482 >  else if(variable == "muon1correctedD0")
3483 >    {
3484 >      value = object1->correctedD0;
3485 >    }
3486 >  else if(variable == "muon2correctedD0")
3487 >    {
3488 >      value = object2->correctedD0;
3489 >    }
3490  
3491 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3492  
3493 +  value = applyFunction(function, value);
3494  
3495 +  return value;
3496 + } // end muon-muon pair valueLookup
3497  
2242
3498  
3499 + //!muon-photon pair valueLookup
3500 + double
3501 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3502  
3503 +  double value = 0.0;
3504 +
3505 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3506 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3507 +  else if(variable == "photonEta") value = object2->eta;
3508 +  else if(variable == "photonPt") value = object2->pt;
3509 +  else if(variable == "muonEta") value = object1->eta;
3510 +  else if(variable == "photonPhi") value = object2->phi;
3511 +  else if(variable == "muonPhi") value = object1->phi;
3512 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3513 +  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3514 +  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3515 +  else if(variable == "invMass"){
3516 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3517 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3518 +    value = (fourVector1 + fourVector2).M();
3519 +  }
3520 +  else if(variable == "pt"){
3521 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3522 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3523 +    value = (fourVector1 + fourVector2).Pt();
3524 +  }
3525 +  else if(variable == "threeDAngle")
3526 +    {
3527 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3528 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3529 +      value = (threeVector1.Angle(threeVector2));
3530 +    }
3531 +  else if(variable == "alpha")
3532 +    {
3533 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3534 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3535 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3536 +      value = (pi-threeVector1.Angle(threeVector2));
3537 +    }
3538 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3539  
3540    value = applyFunction(function, value);
3541  
3542    return value;
3543   }
3544  
3545 + //!electron-photon pair valueLookup
3546   double
3547 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
3547 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3548  
3549    double value = 0.0;
3550  
3551    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3552 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3553 +  else if(variable == "photonEta") value = object2->eta;
3554 +  else if(variable == "photonPt") value = object2->pt;
3555 +  else if(variable == "electronEta") value = object1->eta;
3556 +  else if(variable == "photonPhi") value = object2->phi;
3557 +  else if(variable == "electronPhi") value = object1->phi;
3558    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3559 +  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3560 +  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3561    else if(variable == "invMass"){
3562      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3563      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3564 <
3565 <    value = (fourVector1 + fourVector2).M();}
3566 < else if(variable == "threeDAngle")
3564 >    value = (fourVector1 + fourVector2).M();
3565 >  }
3566 >  else if(variable == "pt"){
3567 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3568 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3569 >    value = (fourVector1 + fourVector2).Pt();
3570 >  }
3571 >  else if(variable == "threeDAngle")
3572      {
3573        TVector3 threeVector1(object1->px, object1->py, object1->pz);
3574        TVector3 threeVector2(object2->px, object2->py, object2->pz);
3575        value = (threeVector1.Angle(threeVector2));
3576      }
3577 <  
3578 <
3579 <
3577 >  else if(variable == "alpha")
3578 >    {
3579 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3580 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3581 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3582 >      value = (pi-threeVector1.Angle(threeVector2));
3583 >    }
3584 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3585  
3586 <  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2274 <  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3586 >  value = applyFunction(function, value);
3587  
3588 <  else if(variable == "d0Sign") value = object1->correctedD0Vertex*object2->correctedD0Vertex/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3588 >  return value;
3589 > }
3590  
3591 + //!electron-electron pair valueLookup
3592 + double
3593 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3594  
3595 +  double value = 0.0;
3596  
3597 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3598 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3599 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3600 +  else if(variable == "invMass"){
3601 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3602 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3603 +    value = (fourVector1 + fourVector2).M();
3604 +  }
3605 +  else if(variable == "pt"){
3606 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3607 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3608 +    value = (fourVector1 + fourVector2).Pt();
3609 +  }
3610 +  else if(variable == "threeDAngle")
3611 +    {
3612 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3613 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3614 +      value = (threeVector1.Angle(threeVector2));
3615 +    }
3616 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3617 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3618    else if(variable == "d0Sign"){
3619      double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3620      if(d0Sign < 0) value = -0.5;
3621      else if (d0Sign > 0) value = 0.5;
3622      else value = -999;
3623    }
3624 +  else if(variable == "chargeProduct"){
3625 +    value = object1->charge*object2->charge;
3626 +  }
3627    else if(variable == "electron1CorrectedD0Vertex"){
3628      value = object1->correctedD0Vertex;
3629    }
3630    else if(variable == "electron2CorrectedD0Vertex"){
3631      value = object2->correctedD0Vertex;
3632    }
3633 +  else if(variable == "electron1CorrectedD0"){
3634 +    value = object1->correctedD0;
3635 +  }
3636 +  else if(variable == "electron2CorrectedD0"){
3637 +    value = object2->correctedD0;
3638 +  }
3639  
3640 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3640 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3641  
3642    value = applyFunction(function, value);
3643  
3644    return value;
3645   }
3646  
3647 + //!electron-muon pair valueLookup
3648   double
3649 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3649 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3650  
3651    double value = 0.0;
3652  
3653    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3654 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3655    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3656    else if(variable == "invMass"){
3657      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3658      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3659 <
3660 <    value = (fourVector1 + fourVector2).M();}
3661 < else if(variable == "threeDAngle")
3659 >    value = (fourVector1 + fourVector2).M();
3660 >  }
3661 >  else if(variable == "pt"){
3662 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3663 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3664 >    value = (fourVector1 + fourVector2).Pt();
3665 >  }
3666 >  else if(variable == "threeDAngle")
3667      {
3668        TVector3 threeVector1(object1->px, object1->py, object1->pz);
3669        TVector3 threeVector2(object2->px, object2->py, object2->pz);
3670        value = (threeVector1.Angle(threeVector2));
3671      }
2318
2319
3672    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3673    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3674    else if(variable == "d0Sign"){
# Line 2325 | Line 3677 | OSUAnalysis::valueLookup (const BNelectr
3677      else if (d0Sign > 0) value = 0.5;
3678      else value = -999;
3679    }
3680 +  else if(variable == "chargeProduct"){
3681 +    value = object1->charge*object2->charge;
3682 +  }
3683    else if(variable == "electronCorrectedD0Vertex"){
3684      value = object1->correctedD0Vertex;
3685    }
# Line 2337 | Line 3692 | OSUAnalysis::valueLookup (const BNelectr
3692    else if(variable == "muonCorrectedD0"){
3693      value = object2->correctedD0;
3694    }
3695 +  else if(variable == "electronDetIso"){
3696 +    value = (object1->trackIso) / object1->pt;
3697 +  }
3698 +  else if(variable == "muonDetIso"){
3699 +    value = (object2->trackIsoDR03) / object2->pt;
3700 +  }
3701 +  else if(variable == "electronRelPFrhoIso"){
3702 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3703 +  }
3704 +  else if(variable == "muonRelPFdBetaIso"){
3705 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3706 +  }
3707 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3708 +  value = applyFunction(function, value);
3709 +
3710 +  return value;
3711 + } // end electron-muon pair valueLookup
3712 +
3713 +
3714 + //!electron-jet pair valueLookup
3715 + double
3716 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3717 +
3718 +  double value = 0.0;
3719 +
3720 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3721 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3722 +  else if(variable == "jetEta") value = object2->eta;
3723 +  else if(variable == "jetPhi") value = object2->phi;
3724 +  else if(variable == "electronEta") value = object1->eta;
3725 +  else if(variable == "electronPhi") value = object1->phi;
3726 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3727 +  else if(variable == "invMass"){
3728 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3729 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3730 +    value = (fourVector1 + fourVector2).M();
3731 +  }
3732 +  else if(variable == "pt"){
3733 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3734 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3735 +    value = (fourVector1 + fourVector2).Pt();
3736 +  }
3737 +  else if(variable == "threeDAngle")
3738 +    {
3739 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3740 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3741 +      value = (threeVector1.Angle(threeVector2));
3742 +    }
3743 +  else if(variable == "chargeProduct"){
3744 +    value = object1->charge*object2->charge;
3745 +  }
3746 +
3747 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3748 +  value = applyFunction(function, value);
3749 +
3750 +  return value;
3751 + }
3752 +
3753 + //!electron-mcparticle pair valueLookup
3754 + double
3755 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmcparticle* object2, string variable, string function, string &stringValue){
3756 +
3757 +  double value = 0.0;
3758 +
3759 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3760 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3761 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3762 +  else if(variable == "threeDAngle")
3763 +    {
3764 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3765 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3766 +      value = (threeVector1.Angle(threeVector2));
3767 +    }
3768 +  else if(variable == "chargeProduct"){
3769 +    value = object1->charge*object2->charge;
3770 +  }
3771 +
3772 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3773 +  value = applyFunction(function, value);
3774 +
3775 +  return value;
3776 + }
3777 +
3778 +
3779 + //!photon-jet pair valueLookup
3780 + double
3781 + OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3782 +
3783 +  double value = 0.0;
3784 +
3785 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3786 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3787 +  else if(variable == "jetEta") value = object2->eta;
3788 +  else if(variable == "jetPhi") value = object2->phi;
3789 +  else if(variable == "photonEta") value = object1->eta;
3790 +  else if(variable == "photonPhi") value = object1->phi;
3791 +  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3792 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3793 +  else if(variable == "invMass"){
3794 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3795 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3796 +    value = (fourVector1 + fourVector2).M();
3797 +  }
3798 +  else if(variable == "pt"){
3799 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3800 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3801 +    value = (fourVector1 + fourVector2).Pt();
3802 +  }
3803 +  else if(variable == "threeDAngle")
3804 +    {
3805 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3806 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3807 +      value = (threeVector1.Angle(threeVector2));
3808 +    }
3809 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3810 +  value = applyFunction(function, value);
3811 +
3812 +  return value;
3813 + }
3814 +
3815 + // track-jet pair valueLookup
3816 + double
3817 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNjet* object2, string variable, string function, string &stringValue){
3818 +
3819 +  double value = 0.0;
3820 +
3821 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3822 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3823 +
3824 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3825 +  value = applyFunction(function, value);
3826 +
3827 +  return value;
3828 +
3829 + }
3830 +
3831 +
3832 +
3833 + // met-jet pair valueLookup
3834 + double
3835 + OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3836 +
3837 +  double value = 0.0;
3838 +
3839 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3840 +
3841 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3842 +  value = applyFunction(function, value);
3843 +
3844 +  return value;
3845 +
3846 + }  
3847 +
3848 +
3849 +
3850 + //!muon-jet pair valueLookup
3851 + double
3852 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3853 +
3854 +  double value = 0.0;
3855 +
3856 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3857 +  else if(variable == "jetEta") value = object2->eta;
3858 +  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3859 +  else if(variable == "jetPt") value = object2->pt;
3860 +  else if(variable == "jetPhi") value = object2->phi;
3861 +  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3862 +  else if(variable == "muonEta") value = object1->eta;
3863 +  else if(variable == "muonPt") value = object1->pt;
3864 +  else if(variable == "muonPhi") value = object1->phi;
3865 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3866 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3867 +  else if(variable == "invMass"){
3868 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3869 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3870 +    value = (fourVector1 + fourVector2).M();
3871 +  }
3872 +  else if(variable == "pt"){
3873 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3874 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3875 +    value = (fourVector1 + fourVector2).Pt();
3876 +  }
3877 +  else if(variable == "threeDAngle")
3878 +    {
3879 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3880 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3881 +      value = (threeVector1.Angle(threeVector2));
3882 +    }
3883 +  else if(variable == "chargeProduct"){
3884 +    value = object1->charge*object2->charge;
3885 +  }
3886 +
3887 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3888 +  value = applyFunction(function, value);
3889 +
3890 +  return value;
3891 + }
3892 +
3893 + //!muon-event valueLookup
3894 + double
3895 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNevent* object2, string variable, string function, string &stringValue){
3896 +
3897 +  double value = 0.0;
3898 +
3899 +  if(variable == "muonEta") value = object1->eta;
3900 +  else if(variable == "muonPt") value = object1->pt;
3901 +  else if(variable == "muonPhi") value = object1->phi;
3902 +  else if(variable == "Ht") value = getHt(jets.product());
3903 +  else if(variable == "pthat")   value = object2->pthat;
3904 +  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3905 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3906 +  value = applyFunction(function, value);
3907 +
3908 +  return value;
3909 + }
3910 + //!jet-jet pair valueLookup
3911 + double
3912 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3913 +
3914 +  double value = 0.0;
3915 +
3916 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3917 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3918 +  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3919 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3920 +  else if(variable == "invMass"){
3921 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3922 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3923 +    value = (fourVector1 + fourVector2).M();
3924 +  }
3925 +  else if(variable == "pt"){
3926 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3927 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3928 +    value = (fourVector1 + fourVector2).Pt();
3929 +  }
3930 +  else if(variable == "threeDAngle")
3931 +    {
3932 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3933 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3934 +      value = (threeVector1.Angle(threeVector2));
3935 +    }
3936 +  else if(variable == "chargeProduct"){
3937 +    value = object1->charge*object2->charge;
3938 +  }
3939 +
3940 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3941 +  value = applyFunction(function, value);
3942 +
3943 +  return value;
3944 + }
3945 +
3946 + //!electron-track pair valueLookup
3947 + double
3948 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3949 +  double electronMass = 0.000511;
3950 +  double value = 0.0;
3951 +  TLorentzVector fourVector1(0, 0, 0, 0);
3952 +  TLorentzVector fourVector2(0, 0, 0, 0);
3953 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3954 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3955 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3956 +  else if(variable == "invMass"){
3957 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3958 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3959 +
3960 +    value = (fourVector1 + fourVector2).M();
3961 +  }
3962 +  else if(variable == "chargeProduct"){
3963 +    value = object1->charge*object2->charge;
3964 +  }
3965 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3966 +  value = applyFunction(function, value);
3967 +  return value;
3968 +
3969 + }
3970 +
3971 +
3972 + //!muon-track pair valueLookup
3973 + double
3974 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3975 +  double pionMass = 0.140;
3976 +  double muonMass = 0.106;
3977 +  double value = 0.0;
3978 +  TLorentzVector fourVector1(0, 0, 0, 0);
3979 +  TLorentzVector fourVector2(0, 0, 0, 0);
3980 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3981 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3982 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3983 +  else if(variable == "invMass"){
3984 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3985 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3986 +
3987 +    value = (fourVector1 + fourVector2).M();
3988 +  }
3989 +  else if(variable == "chargeProduct"){
3990 +    value = object1->charge*object2->charge;
3991 +  }
3992 +
3993 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3994 +  value = applyFunction(function, value);
3995 +  return value;
3996 + }
3997 +
3998 + //!tau-tau pair valueLookup
3999 + double
4000 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
4001 +  double value = 0.0;
4002 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
4003 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
4004 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4005 +  else if(variable == "invMass"){
4006 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
4007 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
4008 +    value = (fourVector1 + fourVector2).M();
4009 +  }
4010 +
4011 +  else if(variable == "chargeProduct"){
4012 +    value = object1->charge*object2->charge;
4013 +  }
4014 +
4015 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4016 +  value = applyFunction(function, value);
4017 +  return value;
4018 + }
4019 +
4020 + //!muon-tau pair valueLookup
4021 + double
4022 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
4023 +  double value = 0.0;
4024 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
4025 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
4026 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4027 +  else if(variable == "invMass"){
4028 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
4029 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
4030 +    value = (fourVector1 + fourVector2).M();
4031 +  }
4032 +
4033 +  else if(variable == "chargeProduct"){
4034 +    value = object1->charge*object2->charge;
4035 +  }
4036 +
4037 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4038 +  value = applyFunction(function, value);
4039 +  return value;
4040 + }
4041 +
4042 + //!tau-track pair valueLookup
4043 + double
4044 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
4045 +  double value = 0.0;
4046 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
4047 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4048 +  else if(variable == "chargeProduct"){
4049 +    value = object1->charge*object2->charge;
4050 +  }
4051 +
4052 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4053 +  value = applyFunction(function, value);
4054 +  return value;
4055 + }
4056 +
4057 +
4058 + //!track-event pair valueLookup
4059 + double
4060 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
4061 +
4062 +  double value = 0.0;
4063 +  double pMag = sqrt(object1->pt * object1->pt +
4064 +                     object1->pz * object1->pz);
4065  
4066 +  if      (variable == "numPV")                      value = object2->numPV;
4067 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
4068 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
4069 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
4070 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
4071  
4072 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4072 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4073  
4074    value = applyFunction(function, value);
4075  
4076    return value;
4077 +
4078   }
4079  
4080 + //!electron-trigobj pair valueLookup
4081 + double
4082 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
4083  
4084 < // Calculate the number of tracks in cone of DeltaR<0.5 around track1.  
4085 < // Return true iff no other tracks are found in this cone.  
4086 < int
4084 >  double value = 0.0;
4085 >
4086 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4087 >  else if (variable == "match"){
4088 >    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
4089 >      stringValue = object2->filter;
4090 >    else
4091 >      stringValue = "none";
4092 >  }
4093 >
4094 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4095 >
4096 >  value = applyFunction(function, value);
4097 >
4098 >  return value;
4099 >
4100 > }
4101 >
4102 > //!muon-trigobj pair valueLookup
4103 > double
4104 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
4105 >
4106 >  double value = 0.0;
4107 >
4108 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4109 >
4110 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4111 >
4112 >  value = applyFunction(function, value);
4113 >
4114 >  return value;
4115 >
4116 > }
4117 >
4118 > //!stop valueLookup
4119 > double
4120 > OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
4121 >
4122 >
4123 >  double value = 0.0;
4124 >
4125 >  if(variable == "ctau") value = object->ctau;
4126 >
4127 >  else if (variable == "d0"){
4128 >    double vx = object->vx - chosenVertex ()->x,
4129 >      vy = object->vy - chosenVertex ()->y,
4130 >      px = object->px,
4131 >      py = object->py,
4132 >      pt = object->pt;
4133 >    value = (-vx * py + vy * px) / pt;
4134 >  }
4135 >
4136 >  else if (variable == "dz"){
4137 >    double vx = object->vx - chosenVertex ()->x,
4138 >      vy = object->vy - chosenVertex ()->y,
4139 >      vz = object->vz - chosenVertex ()->z,
4140 >      px = object->px,
4141 >      py = object->py,
4142 >      pz = object->pz,
4143 >      pt = object->pt;
4144 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
4145 >  }
4146 >
4147 >  else if (variable == "minD0"){
4148 >    double minD0=999;
4149 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4150 >      double vx = object->vx - vertex->x,
4151 >        vy = object->vy - vertex->y,
4152 >        px = object->px,
4153 >        py = object->py,
4154 >        pt = object->pt;
4155 >      value = (-vx * py + vy * px) / pt;
4156 >      if(abs(value) < abs(minD0)) minD0 = value;
4157 >    }
4158 >    value = minD0;
4159 >  }
4160 >  else if (variable == "minDz"){
4161 >    double minDz=999;
4162 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4163 >      double vx = object->vx - vertex->x,
4164 >        vy = object->vy - vertex->y,
4165 >        vz = object->vz - vertex->z,
4166 >        px = object->px,
4167 >        py = object->py,
4168 >        pz = object->pz,
4169 >        pt = object->pt;
4170 >      value = vz - (vx * px + vy * py)/pt * (pz/pt);
4171 >      if(abs(value) < abs(minDz)) minDz = value;
4172 >    }
4173 >    value = minDz;
4174 >  }
4175 >  else if(variable == "distToVertex"){
4176 >    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4177 >                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4178 >                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4179 >  }
4180 >  else if (variable == "minDistToVertex"){
4181 >    double minDistToVertex=999;
4182 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4183 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4184 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4185 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
4186 >
4187 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4188 >    }
4189 >    value = minDistToVertex;
4190 >  }
4191 >  else if (variable == "distToVertexDifference"){
4192 >    double minDistToVertex=999;
4193 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4194 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4195 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4196 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
4197 >
4198 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4199 >    }
4200 >    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4201 >                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4202 >                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4203 >
4204 >    value = distToChosenVertex - minDistToVertex;
4205 >  }
4206 >
4207 >  else if (variable == "closestVertexRank"){
4208 >    double minDistToVertex=999;
4209 >    int vertex_rank = 0;
4210 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4211 >      vertex_rank++;
4212 >      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4213 >                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
4214 >                      (object->vz-vertex->z)*(object->vz-vertex->z));
4215 >
4216 >      if(abs(dist) < abs(minDistToVertex)){
4217 >        value = vertex_rank;
4218 >        minDistToVertex = dist;
4219 >      }
4220 >    }
4221 >  }
4222 >
4223 >  else if (variable == "decaysToTau"){
4224 >    value = abs (object->daughter0Id) == 15 || abs (object->daughter1Id) == 15;
4225 >  }
4226 >
4227 >
4228 >
4229 >
4230 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4231 >
4232 >  value = applyFunction(function, value);
4233 >
4234 >  return value;
4235 >
4236 > } // end stop valueLookup
4237 >
4238 >
4239 >
4240 >
4241 >
4242 > // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
4243 > // Return true iff no other tracks are found in this cone.
4244 > int
4245   OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
4246    for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
4247 <    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.  
4247 >    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
4248      double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
4249      if(deltaRtrk < 0.5) return 0;
4250    }
4251    return 1;
4252 <  
4252 >
4253   }
4254  
4255 + //calculate the scalar sum of Jet Pt in the event.
4256 + double
4257 + OSUAnalysis::getHt (const BNjetCollection* jetColl){
4258 +  double Ht = 0;
4259 +  for(BNjetCollection::const_iterator jet = jetColl->begin(); jet !=jetColl->end(); jet++){
4260 +    Ht += abs(jet->pt);
4261 +  }
4262 +  return Ht;
4263 + }
4264  
4265 < double
4265 > double
4266   OSUAnalysis::getTrkPtRes (const BNtrack* track1){
4267  
4268    double ptTrue = getTrkPtTrue(track1, mcparticles.product());
4269    double PtRes = (track1->pt - ptTrue) / ptTrue;
4270  
4271    return PtRes;
4272 <  
4272 >
4273   }
4274  
4275  
4276 < double
4276 > double
4277   OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
4278    double value = -99;
4279    double genDeltaRLowest = 999;
# Line 2381 | Line 4282 | OSUAnalysis::getTrkPtTrue (const BNtrack
4282      double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
4283      if (genDeltaRtemp < genDeltaRLowest) {
4284        genDeltaRLowest = genDeltaRtemp;
4285 <      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.  
4286 <        double ptTrue = genPart->pt;
4287 <        value = ptTrue;
4285 >      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
4286 >        double ptTrue = genPart->pt;
4287 >        value = ptTrue;
4288        }
4289 <    }
4289 >    }
4290    }
4291  
4292    return value;
4293  
4294   }
4295  
4296 + double
4297 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
4298 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
4299 +  if (!useTrackCaloRhoCorr_) return -99;
4300 +  // if (!rhokt6CaloJetsHandle_) {
4301 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
4302 +  //   return -99;
4303 +  // }
4304 +  double radDeltaRCone = 0.5;
4305 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
4306 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
4307 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
4308 +  return caloTotRhoCorrCalo;
4309 +
4310 + }
4311 +
4312 + double
4313 + OSUAnalysis::getTrkDepTrkRp5RhoCorr(const BNtrack* track) {
4314 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.              
4315 +  if (!useTrackCaloRhoCorr_) return -99;
4316 +  // if (!rhokt6CaloJetsHandle_) {                                                                                                    
4317 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;                        
4318 +  //   return -99;                                                                                                                    
4319 +  // }                                                                                                                                
4320 +  double radDeltaRCone = 0.5;
4321 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.                                                                                                          
4322 +  double rawDepTrkRp5 = track->depTrkRp5;
4323 + double depTrkRp5RhoCorr = TMath::Max(0., rawDepTrkRp5 - rhoCorr_kt6CaloJets);
4324 + return depTrkRp5RhoCorr;
4325 +
4326 + }
4327 +
4328 + double
4329 + OSUAnalysis::getTrkDepTrkRp3RhoCorr(const BNtrack* track) {
4330 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.                                                
4331 +  if (!useTrackCaloRhoCorr_) return -99;
4332 +  // if (!rhokt6CaloJetsHandle_) {                                                                                                                                      
4333 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;                                                          
4334 +  //   return -99;                                                                                                                                                      
4335 +  // }                                                                                                                                                                  
4336 +  double radDeltaRCone = 0.3;
4337 + // Define effective area as pi*r^2, where r is radius of DeltaR cone
4338 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  
4339 +  double rawDepTrkRp3 = track->depTrkRp3;
4340 +  double depTrkRp3RhoCorr = TMath::Max(0., rawDepTrkRp3 - rhoCorr_kt6CaloJets);
4341 +  return depTrkRp3RhoCorr;
4342 +  
4343 + }
4344 +
4345 +
4346 +
4347 +
4348   //creates a map of the dead Ecal channels in the barrel and endcap
4349   //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
4350   //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
4351 < void
4351 > void
4352   OSUAnalysis::WriteDeadEcal (){
4353    double etaEcal, phiEcal;
4354    ifstream DeadEcalFile(deadEcalFile_);
4355    if(!DeadEcalFile) {
4356 <    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;
4356 >    clog << "Error: DeadEcalFile has not been found." << endl;
4357      return;
4358 <  }
4358 >  }
4359 >  if(DeadEcalVec.size()!= 0){
4360 >    clog << "Error: DeadEcalVec has a nonzero size" << endl;
4361 >    return;
4362 >  }
4363    while(!DeadEcalFile.eof())
4364      {
4365        DeadEcalFile >> etaEcal >> phiEcal;
# Line 2415 | Line 4368 | OSUAnalysis::WriteDeadEcal (){
4368        newChan.phiEcal = phiEcal;
4369        DeadEcalVec.push_back(newChan);
4370      }
4371 <  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
4371 >  if(DeadEcalVec.size() == 0) clog << "Warning: No dead Ecal channels have been found." << endl;
4372   }
4373  
4374   //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
4375 < int
4375 > int
4376   OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
4377    double deltaRLowest = 999;
4378    int value = 0;
4379    if (DeadEcalVec.size() == 0) WriteDeadEcal();
4380 <  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4380 >  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4381      double eta = ecal->etaEcal;
4382      double phi = ecal->phiEcal;
4383 <    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
4383 >    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
4384      if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
4385    }
4386    if (deltaRLowest<0.05) {value = 1;}
# Line 2435 | Line 4388 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
4388    return value;
4389   }
4390  
4391 <
4392 <
4391 > // Returns the smallest DeltaR between the object and any generated true particle in the event.
4392 > template <class InputObject>
4393 > double OSUAnalysis::getGenDeltaRLowest(InputObject object){
4394 >  double genDeltaRLowest = 999.;
4395 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4396 >    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
4397 >    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
4398 >  }
4399 >  return genDeltaRLowest;
4400 > }
4401  
4402   double
4403   OSUAnalysis::applyFunction(string function, double value){
# Line 2447 | Line 4408 | OSUAnalysis::applyFunction(string functi
4408    else if(function == "log") value = log10(value);
4409  
4410    else if(function == "") value = value;
4411 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
4411 >  else{clog << "WARNING: invalid function '" << function << "'\n";}
4412  
4413    return value;
4414  
# Line 2457 | Line 4418 | OSUAnalysis::applyFunction(string functi
4418   template <class InputCollection>
4419   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
4420  
4421 +  if (verbose_>2) clog << "  Beginning setObjectFlags for cut " << currentCutIndex << ": " << currentCut.name
4422 +                       << ", inputType=" << inputType
4423 +                       << endl;  
4424 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
4425 +    string obj1, obj2;
4426 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
4427 +    if (verbose_>2) clog << "  Two object types:  " << obj1 << ", " << obj2 << endl;
4428 +    if (inputType==obj1 ||
4429 +        inputType==obj2) {
4430 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
4431 +      // and the inputType is a member of the pair.
4432 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
4433 +      // For example, if currentCut.inputCollection==electron-muon pairs,
4434 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
4435 +      return;
4436 +    }
4437 +  }
4438  
4439 <  for (uint object = 0; object != inputCollection->size(); object++){
4439 >  if (!inputCollection) cout << "ERROR:  invalid input collection for inputType=" << inputType << endl;  
4440  
4441 +  if (verbose_>3) clog << "   Collection size:  " << inputCollection->size() << endl;
4442  
4443 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
4443 >  for (uint object = 0; object != inputCollection->size(); object++){
4444  
4445 +    if (verbose_>4) clog << "    Setting flags for object " << object << endl;
4446 +
4447 +    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4448 +    bool plotDecision = true;
4449  
4450      if(currentCut.inputCollection == inputType){
4451  
4452        vector<bool> subcutDecisions;
4453        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4454 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4455 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4454 >        string stringValue = "";
4455 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4456 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4457 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4458 >
4459        }
4460 <      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4460 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4461        else{
4462 <        bool tempDecision = true;
4463 <        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4464 <          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4465 <            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4466 <          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4462 >        bool tempDecision = true;
4463 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4464 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4465 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4466 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4467              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4468 <        }
4469 <        decision = tempDecision;
4468 >        }
4469 >        cutDecision = tempDecision;
4470        }
4471 +      //invert the cut if this cut is a veto
4472 +      if(currentCut.isVeto) cutDecision = !cutDecision;
4473 +      plotDecision = cutDecision;
4474      }
2486    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4475  
4476 +    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4477  
4478 <    //set flags for objects that pass each cut AND all the previous cuts
4479 <    bool previousCumulativeFlag = true;
4478 >    //set flags for objects that pass this cut AND all the previous cuts
4479 >    bool previousCumulativeCutFlag = true;
4480      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4481 <      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4482 <      else{ previousCumulativeFlag = false; break;}
4481 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4482 >      else{ previousCumulativeCutFlag = false; break;}
4483      }
4484 <    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4484 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4485 >    bool previousCumulativePlotFlag = true;
4486 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4487 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4488 >      else{ previousCumulativePlotFlag = false; break;}
4489 >    }
4490 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4491  
4492 +    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4493  
4494 <  }
4494 >  }  //   for (uint object = 0; object != inputCollection->size(); object++){
4495  
4496 < }
4496 > } // end void OSUAnalysis::setObjectFlags
4497  
4498  
4499   template <class InputCollection1, class InputCollection2>
4500 < void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
4501 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
4502 <
4500 > void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags,
4501 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, string inputType){
4502 >  // This function sets the flags for the paired object collection.  
4503 >  // If the cut is applying on the given paired object collection, then the flags for the single object collections are also set.
4504 >  // If not, then the flags for the paired object collection are taken as the AND of the flags for each single object collection.  
4505 >
4506 >  if (verbose_>2) clog << "  Beginning setObjectFlags for cut=" << currentCut.name
4507 >                       << ", inputType=" << inputType
4508 >                       << endl;  
4509  
4510    bool sameObjects = false;
4511 <  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4511 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;  // FIXME:  is sameObjects just the not of isTwoTypesOfObject?  If so, it's redundant.  
4512 >
4513 >  // Get the strings for the two objects that make up the pair.
4514 >  string obj1Type, obj2Type;
4515 >  getTwoObjs(inputType, obj1Type, obj2Type);
4516 >  bool isTwoTypesOfObject = true;
4517 >  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
4518 >
4519 >  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
4520 >  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4521 >  if (currentCut.inputCollection == inputType) {
4522 >    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4523 >      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4524 >      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4525 >    }
4526 >    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4527 >      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4528 >        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4529 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4530 >      }
4531 >    }
4532 >  }
4533  
4534 +  int counter = 0;
4535  
2512  int counter = 0;  
4536    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4537      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4538 <      
4538 >
4539        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4540  
4541  
4542 <      bool decision = true;//object passes if this cut doesn't cut on that type of object
4542 >      bool cutDecision  = true;//object passes if this cut doesn't cut on that type of object
4543 >      bool plotDecision = true;
4544  
4545 +      // Determine whether each pair passes the cut, only if inputCollection is the same as the inputType.  
4546        if(currentCut.inputCollection == inputType){
4547  
4548 <        vector<bool> subcutDecisions;
4549 <        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4550 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4551 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4552 <        }
4548 >        vector<bool> subcutDecisions;
4549 >        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4550 >          string stringValue = "";
4551 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4552 >          if (verbose_>1) clog << currentCut.variables.at(subcutIndex) << " = " << value
4553 >                               << endl;  
4554 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4555 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4556 >        }
4557  
4558 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4559 <        else{
4560 <          bool tempDecision = true;
4561 <          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4562 <            if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4563 <              tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4564 <            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4565 <              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4566 <          }
4567 <          decision = tempDecision;
4558 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4559 >        else{
4560 >          bool tempDecision = subcutDecisions.at(0);
4561 >          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
4562 >            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
4563 >              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
4564 >            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4565 >              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4566 >          }
4567 >          cutDecision = tempDecision;
4568 >        }
4569 >        //invert the cut if this cut is a veto
4570 >        if (currentCut.isVeto) cutDecision = !cutDecision;
4571 >        plotDecision = cutDecision;
4572 >
4573 >        if (verbose_>1) clog << " cutDecision = " << cutDecision
4574 >                             << "; for currentCut.inputCollection = " << currentCut.inputCollection
4575 >                             << "; object1 (" << obj1Type << ") = " << object1
4576 >                             << "; object2 (" << obj2Type << ") = " << object2
4577 >                             << endl;  
4578 >        
4579 >        if (cutDecision) {  // only set the flags for the individual objects if the pair object is being cut on
4580 >          individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4581 >          individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4582          }
4583 +        if (plotDecision) {  // only set the flags for the individual objects if the pair object is being cut on
4584 +          individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4585 +          individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4586 +        }
4587 +        
4588 +
4589 +      } // if(currentCut.inputCollection == inputType){
4590 +
4591 +      // The individualFlags will be true if the inputCollection is not the same as the inputType.
4592 +      // They are also independent of the previous flags on the single objects.  
4593 +      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));  
4594 +
4595 +
4596 +
4597 +      // ************************************
4598 +      // Determine cumulative flags
4599 +      // ************************************
4600 +      // determine whether this paired object passes this cut AND all previous cuts
4601 +      bool previousCumulativeCutFlag = true;
4602 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4603 +        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4604 +        else{ previousCumulativeCutFlag = false; break;}
4605        }
4606 <      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4607 <      
4608 <      //set flags for objects that pass each cut AND all the previous cuts
2544 <      bool previousCumulativeFlag = true;
4606 >      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4607 >
4608 >      bool previousCumulativePlotFlag = true;
4609        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4610 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
4611 <        else{ previousCumulativeFlag = false; break;}
4610 >        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4611 >        else{ previousCumulativePlotFlag = false; break;}
4612 >      }
4613 >      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4614 >      
4615 >      // 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.    
4616 >      int cutIdxFlagsObj1 = max(int(currentCutIndex-1),0);
4617 >      int cutIdxFlagsObj2 = max(int(currentCutIndex-1),0);
4618 >      // 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.
4619 >      // 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.  
4620 >      // 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).  
4621 >      if (currentCut.inputCollection != inputType) {  
4622 >        if (currentCut.inputCollection.find(obj1Type)!=string::npos) cutIdxFlagsObj1 = currentCutIndex;
4623 >        if (currentCut.inputCollection.find(obj2Type)!=string::npos) cutIdxFlagsObj2 = currentCutIndex;
4624 >      }  
4625 >      flagPair flags1 = cumulativeFlags.at(obj1Type).at(cutIdxFlagsObj1);  // flag for input collection 1
4626 >      flagPair flags2 = cumulativeFlags.at(obj2Type).at(cutIdxFlagsObj2);  // flag for input collection 2
4627 >      
4628 >      // The cumulative flag is only true if the paired object cumulative flag is true, and if the single object cumulative flags are true.  
4629 >      bool currentCumulativeCutFlag = true;
4630 >      bool currentCumulativePlotFlag = true;
4631 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4632 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4633 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4634 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4635 >
4636 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4637 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4638 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4639 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4640 >
4641 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));  // Set the flag for the paired object
4642 >
4643 >
4644 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // Set the flags for the individual objects if the paired object is being cut on.  
4645 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first  = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4646 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first  = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4647 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4648 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4649 >
4650 >        if (verbose_>1) clog << " previousCumulativeCutFlag for object1 = " << getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object1, "cut") << endl;  
4651 >        if (verbose_>1) clog << " previousCumulativeCutFlag for object2 = " << getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut") << endl;  
4652 >
4653        }
2549      //apply flags for the components of the composite object as well
2550      bool currentCumulativeFlag = true;
2551      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
2552      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
2553      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
2554      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
2555      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
4654  
4655 <      counter++;      
4655 >      counter++;
4656 >
4657 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4658 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4659 >
4660 > } // end void OSUAnalysis::setObjectFlags
4661 >
4662 >
4663 > bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4664 >  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4665 >  // all cuts up to currentCutIndex
4666 >  bool previousCumulativeFlag = true;
4667 >  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4668 >    bool tempFlag = false;
4669 >    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4670 >    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4671 >
4672 >    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4673 >    else {
4674 >      previousCumulativeFlag = false; break;
4675      }
2559    
4676    }
4677 +  return previousCumulativeFlag;
4678 + }
4679 +
4680 +
4681 +
4682 +
4683 + template <class InputCollection>
4684 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4685 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4686  
4687 +  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;
4688 +  for (uint object = 0; object != inputCollection->size(); object++) {
4689  
4690 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4691 +
4692 +    string inputVariable = parameters.inputVariable;
4693 +    string function = "";
4694 +    string stringValue = "";
4695 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4696 +    BNTreeBranchVals_.at(parameters.name).push_back(value);
4697 +
4698 +  }
4699   }
4700  
4701  
4702   template <class InputCollection>
4703 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
4703 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4704 >
4705 >  if (verbose_>2) clog << "  Filling histogram for " << parameters.name << endl;  
4706  
4707    for (uint object = 0; object != inputCollection->size(); object++){
4708  
4709 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4709 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4710  
4711      string currentString = parameters.inputVariables.at(0);
4712      string inputVariable = "";
4713      string function = "";
4714 <    if(currentString.find("(")==std::string::npos){
4715 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
4714 >    if(currentString.find("(")==string::npos){
4715 >      inputVariable = currentString;// variable to cut on
4716      }
4717      else{
4718 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4719 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4720 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4718 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4719 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4720 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4721      }
4722  
4723 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
4724 <    histo->Fill(value,puScaleFactor);
4723 >    string stringValue = "";
4724 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4725 >    histo->Fill(value,scaleFactor);
4726 >
4727 >    if (printEventInfo_) {
4728 >      // Write information about event to screen, for testing purposes.
4729 >      clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << " (object number " << object << ")" << endl;
4730 >    }
4731  
4732    }
2589
4733   }
4734  
4735   template <class InputCollection1, class InputCollection2>
4736 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
4736 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2,
4737 >                                  flagPair pairFlags, double scaleFactor){
4738  
4739    bool sameObjects = false;
4740    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4741  
4742 <  int pairCounter = 0;  
4742 >  int pairCounter = -1;
4743    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4744      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4745 <      
4745 >
4746        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4747  
4748 <      //only take objects which have passed all cuts and pairs which have passed all cuts
4749 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
2606 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
2607 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4748 >      pairCounter++;
4749 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4750  
4751        string currentString = parameters.inputVariables.at(0);
4752        string inputVariable = "";
4753        string function = "";
4754 <      if(currentString.find("(")==std::string::npos){
4755 <        inputVariable = currentString;// variable to cut on                                                                                                          
4754 >      if(currentString.find("(")==string::npos){
4755 >        inputVariable = currentString;// variable to cut on
4756        }
4757        else{
4758 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4759 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4760 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4758 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4759 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4760 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4761        }
2620      
2621      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
2622      histo->Fill(value,puScaleFactor);
4762  
4763 <      pairCounter++;      
4763 >      string stringValue = "";
4764 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4765 >      histo->Fill(value,scaleFactor);
4766 >
4767 >      if (printEventInfo_) {
4768 >        // Write information about event to screen, for testing purposes.
4769 >        clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value
4770 >             << " (object1 number " << object1 << "), "
4771 >             << " (object2 number " << object2 << ")"
4772 >             << endl;
4773 >      }
4774 >      
4775      }
4776    }
4777  
# Line 2629 | Line 4779 | void OSUAnalysis::fill1DHistogram(TH1* h
4779  
4780  
4781   template <class InputCollection>
4782 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
4782 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4783  
4784    for (uint object = 0; object != inputCollection->size(); object++){
4785  
4786 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4786 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4787  
4788 +    string stringValue = "";
4789      string currentString = parameters.inputVariables.at(0);
4790      string inputVariable = "";
4791      string function = "";
4792 <    if(currentString.find("(")==std::string::npos){
4793 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
4792 >    if(currentString.find("(")==string::npos){
4793 >      inputVariable = currentString;// variable to cut on
4794      }
4795      else{
4796 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4797 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4798 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4796 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4797 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4798 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4799      }
4800 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
4800 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4801  
4802      currentString = parameters.inputVariables.at(1);
4803      inputVariable = "";
4804      function = "";
4805 <    if(currentString.find("(")==std::string::npos){
4806 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
4805 >    if(currentString.find("(")==string::npos){
4806 >      inputVariable = currentString;// variable to cut on
4807      }
4808      else{
4809 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4810 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4811 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4809 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4810 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4811 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4812      }
4813  
4814 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
4814 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4815  
4816 <    histo->Fill(valueX,valueY,puScaleFactor);
4816 >    histo->Fill(valueX,valueY,scaleFactor);
4817  
4818    }
4819  
4820   }
4821  
4822   template <class InputCollection1, class InputCollection2>
4823 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
4823 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2,
4824 >                                  flagPair pairFlags, double scaleFactor){
4825  
4826    bool sameObjects = false;
4827    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4828  
4829 <  int pairCounter = 0;  
4829 >  int pairCounter = -1;
4830    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4831      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4832 <      
4832 >
4833        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4834  
4835 <      //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;
4835 >      pairCounter++;
4836  
4837 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4838 +
4839 +      string stringValue = "";
4840        string currentString = parameters.inputVariables.at(0);
4841        string inputVariable = "";
4842        string function = "";
4843 <      if(currentString.find("(")==std::string::npos){
4844 <        inputVariable = currentString;// variable to cut on                                                                                                          
4843 >      if(currentString.find("(")==string::npos){
4844 >        inputVariable = currentString;// variable to cut on
4845        }
4846        else{
4847 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4848 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4849 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4847 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4848 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4849 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4850        }
4851 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4851 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4852  
4853        currentString = parameters.inputVariables.at(1);
4854        inputVariable = "";
4855        function = "";
4856 <      if(currentString.find("(")==std::string::npos){
4857 <        inputVariable = currentString;// variable to cut on                                                                                                          
4856 >      if(currentString.find("(")==string::npos){
4857 >        inputVariable = currentString;// variable to cut on
4858        }
4859        else{
4860 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4861 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4862 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4860 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4861 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4862 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4863        }
4864 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
2713 <
4864 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4865  
2715      histo->Fill(valueX,valueY,puScaleFactor);
4866  
4867 <      pairCounter++;      
4867 >      histo->Fill(valueX,valueY,scaleFactor);
4868  
4869      }
4870    }
# Line 2732 | Line 4882 | int OSUAnalysis::getGenMatchedParticleIn
4882  
4883      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4884      if(currentDeltaR > 0.05) continue;
4885 <
4885 >    //     clog << setprecision(3) << setw(20)
4886 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4887 >    //          << setw(20)
4888 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4889 >    //          << setw(20)
4890 >    //          << "\tdeltaR = " << currentDeltaR
4891 >    //          << setprecision(1)
4892 >    //          << setw(20)
4893 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4894 >    //          << setw(20)
4895 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4896 >    //          << setw(20)
4897 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4898      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4899        bestMatchIndex = mcparticle - mcparticles->begin();
4900        bestMatchDeltaR = currentDeltaR;
4901      }
4902  
4903    }
4904 <
4904 >  //   if(bestMatchDeltaR != 999)  clog << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4905 >  //   else clog << "no match found..." << endl;
4906    return bestMatchIndex;
4907  
4908   }
# Line 2793 | Line 4956 | int OSUAnalysis::findTauMotherIndex(cons
4956   // 20        strange baryon
4957   // 21        charm baryon
4958   // 22        bottom baryon
4959 < // 23        other
4959 > // 23        QCD string
4960 > // 24        other
4961  
4962   int OSUAnalysis::getPdgIdBinValue(int pdgId){
4963  
4964    int binValue = -999;
4965 <  int absPdgId = fabs(pdgId);  
4965 >  int absPdgId = fabs(pdgId);
4966    if(pdgId == -1) binValue = 0;
4967    else if(absPdgId <= 6 ) binValue = absPdgId;
4968    else if(absPdgId == 11 ) binValue = 7;
# Line 2817 | Line 4981 | int OSUAnalysis::getPdgIdBinValue(int pd
4981    else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4982    else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4983    else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4984 +  else if(absPdgId == 92  ) binValue = 23;
4985  
4986 <  else binValue = 23;
4986 >  else binValue = 24;
4987  
4988    return binValue;
4989  
4990   }
4991  
4992 + const BNprimaryvertex *
4993 + OSUAnalysis::chosenVertex ()
4994 + {
4995 +  const BNprimaryvertex *chosenVertex = 0;
4996 +  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4997 +    flagPair vertexFlags;
4998 +    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4999 +      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
5000 +        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
5001 +        break;
5002 +      }
5003 +    }
5004 +    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
5005 +      if(!vertexFlags.at(vertexIndex).first) continue;
5006 +      chosenVertex = & primaryvertexs->at(vertexIndex);
5007 +      break;
5008 +    }
5009 +  }
5010 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
5011 +    chosenVertex = & primaryvertexs->at (0);
5012  
5013 < DEFINE_FWK_MODULE(OSUAnalysis);
5013 >  return chosenVertex;
5014 > }
5015 >
5016 > const BNmet *
5017 > OSUAnalysis::chosenMET ()
5018 > {
5019 >  const BNmet *chosenMET = 0;
5020 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
5021 >    flagPair metFlags;
5022 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
5023 >      if (cumulativeFlags.at("mets").at(i).size()){
5024 >        metFlags = cumulativeFlags.at("mets").at(i);
5025 >        break;
5026 >      }
5027 >    }
5028 >    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
5029 >      if(!metFlags.at(metIndex).first) continue;
5030 >      chosenMET = & mets->at(metIndex);
5031 >      break;
5032 >    }
5033 >  }
5034 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
5035 >    chosenMET = & mets->at (0);
5036 >
5037 >  return chosenMET;
5038 > }
5039 >
5040 > const BNelectron *
5041 > OSUAnalysis::chosenElectron ()
5042 > {
5043 >  const BNelectron *chosenElectron = 0;
5044 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
5045 >    flagPair electronFlags;
5046 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
5047 >      if (cumulativeFlags.at("electrons").at(i).size()){
5048 >        electronFlags = cumulativeFlags.at("electrons").at(i);
5049 >        break;
5050 >      }
5051 >    }
5052 >    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
5053 >      if(!electronFlags.at(electronIndex).first) continue;
5054 >      chosenElectron = & electrons->at(electronIndex);
5055 >      break;
5056 >    }
5057 >  }
5058 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
5059 >    chosenElectron = & electrons->at (0);
5060 >
5061 >  return chosenElectron;
5062 > }
5063 >
5064 >
5065 > const BNmuon *
5066 > OSUAnalysis::chosenMuon ()
5067 > {
5068 >  const BNmuon *chosenMuon = 0;
5069 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
5070 >    flagPair muonFlags;
5071 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
5072 >      if (cumulativeFlags.at("muons").at(i).size()){
5073 >        muonFlags = cumulativeFlags.at("muons").at(i);
5074 >        break;
5075 >      }
5076 >    }
5077 >    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
5078 >      if(!muonFlags.at(muonIndex).first) continue;
5079 >      chosenMuon = & muons->at(muonIndex);
5080 >      break;
5081 >    }
5082 >  }
5083 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
5084 >    chosenMuon = & muons->at (0);
5085 >
5086 >  return chosenMuon;
5087 > }
5088  
5089 + double
5090 + OSUAnalysis::chosenHT ()
5091 + {
5092 +  double chosenHT = 0.0;
5093 +  if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
5094 +    flagPair jetFlags;
5095 +    for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
5096 +      if (cumulativeFlags.at("jets").at(i).size()){
5097 +        jetFlags = cumulativeFlags.at("jets").at(i);
5098 +        break;
5099 +      }
5100 +    }
5101 +    for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
5102 +      if(!jetFlags.at(jetIndex).first) continue;
5103 +      chosenHT += jets->at(jetIndex).pt;
5104 +    }
5105 +  }
5106 +
5107 +  return chosenHT;
5108 + }
5109  
5110 + pair<const BNmuon *, const BNmuon *>
5111 + OSUAnalysis::leadMuonPair ()
5112 + {
5113 +  pair<const BNmuon *, const BNmuon *> leadMuonPair;
5114 +  leadMuonPair.first = leadMuonPair.second = 0;
5115 +
5116 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
5117 +    flagPair muonFlags;
5118 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
5119 +      if (cumulativeFlags.at("muons").at(i).size()){
5120 +        muonFlags = cumulativeFlags.at("muons").at(i);
5121 +        break;
5122 +      }
5123 +    }
5124 +    for (uint muonIndex0 = 0; muonIndex0 != muonFlags.size(); muonIndex0++){
5125 +      if(!muonFlags.at(muonIndex0).first) continue;
5126 +      for (uint muonIndex1 = muonIndex0 + 1; muonIndex1 < muonFlags.size(); muonIndex1++){
5127 +        if(!muonFlags.at(muonIndex1).first) continue;
5128 +        const BNmuon *mu0 = & muons->at(muonIndex0);
5129 +        const BNmuon *mu1 = & muons->at(muonIndex1);
5130 +        if(leadMuonPair.first == 0 || leadMuonPair.second == 0){
5131 +          leadMuonPair.first = mu0;
5132 +          leadMuonPair.second = mu1;
5133 +        }
5134 +        else{
5135 +          TVector2 newPt0 (mu0->px, mu0->py),
5136 +                   newPt1 (mu1->px, mu1->py),
5137 +                   oldPt0 (leadMuonPair.first->px, leadMuonPair.first->py),
5138 +                   oldPt1 (leadMuonPair.second->px, leadMuonPair.second->py);
5139 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
5140 +            {
5141 +              leadMuonPair.first = mu0;
5142 +              leadMuonPair.second = mu1;
5143 +            }
5144 +        }
5145 +      }
5146 +    }
5147 +  }
5148 +
5149 +  return leadMuonPair;
5150 + }
5151 +
5152 + pair<const BNelectron *, const BNelectron *>
5153 + OSUAnalysis::leadElectronPair ()
5154 + {
5155 +  pair<const BNelectron *, const BNelectron *> leadElectronPair;
5156 +  leadElectronPair.first = leadElectronPair.second = 0;
5157 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
5158 +    flagPair electronFlags;
5159 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
5160 +      if (cumulativeFlags.at("electrons").at(i).size()){
5161 +        electronFlags = cumulativeFlags.at("electrons").at(i);
5162 +        break;
5163 +      }
5164 +    }
5165 +    for (uint electronIndex0 = 0; electronIndex0 != electronFlags.size(); electronIndex0++){
5166 +      if(!electronFlags.at(electronIndex0).first) continue;
5167 +      for (uint electronIndex1 = electronIndex0 + 1; electronIndex1 < electronFlags.size(); electronIndex1++){
5168 +        if(!electronFlags.at(electronIndex1).first) continue;
5169 +        const BNelectron *el0 = & electrons->at(electronIndex0);
5170 +        const BNelectron *el1 = & electrons->at(electronIndex1);
5171 +        if(leadElectronPair.first == 0 || leadElectronPair.second == 0){
5172 +          leadElectronPair.first = el0;
5173 +          leadElectronPair.second = el1;
5174 +        }
5175 +        else{
5176 +          TVector2 newPt0 (el0->px, el0->py),
5177 +                   newPt1 (el1->px, el1->py),
5178 +                   oldPt0 (leadElectronPair.first->px, leadElectronPair.first->py),
5179 +                   oldPt1 (leadElectronPair.second->px, leadElectronPair.second->py);
5180 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
5181 +            {
5182 +              leadElectronPair.first = el0;
5183 +              leadElectronPair.second = el1;
5184 +            }
5185 +        }
5186 +      }
5187 +    }
5188 +  }
5189 +
5190 +  return leadElectronPair;
5191 + }
5192 +
5193 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines