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.43 by wulsin, Thu Mar 28 10:17:32 2013 UTC vs.
Revision 1.116 by wulsin, Sun Aug 4 21:17:37 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 <  muonSFFile_ (cfg.getParameter<std::string> ("muonSFFile")),
23 <  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
24 <  electronSFID_ (cfg.getParameter<std::string> ("electronSFID")),
25 <  muonSF_ (cfg.getParameter<std::string> ("muonSF")),
26 <  dataset_ (cfg.getParameter<std::string> ("dataset")),
27 <  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 +  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 <  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
36 <  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr"))
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") {
53      if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
54 <    //    muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
55 <    //    electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
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_);
49  std::vector<TFileDirectory> directories;
69  
70    //always get vertex collection so we can assign the primary vertex in the event
71    objectsToGet.push_back("primaryvertexs");
53
54  //always make the plot of number of primary verticex (to check pile-up reweighting)
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 60 | Line 79 | OSUAnalysis::OSUAnalysis (const edm::Par
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 == "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.find("pairs")==std::string::npos){ //just a single object
120 <      objectsToGet.push_back(tempInputCollection);
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 <
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  
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 112 | Line 186 | OSUAnalysis::OSUAnalysis (const edm::Par
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 154 | Line 246 | OSUAnalysis::OSUAnalysis (const edm::Par
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      histograms.push_back(tempIdVsMomIdHisto);
257 +    histograms.push_back(tempIdVsGmaIdHisto);
258    }
259  
260  
# Line 170 | Line 266 | OSUAnalysis::OSUAnalysis (const edm::Par
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 );
193 <    directories.push_back(subDir);
194 <
195 <    std::map<std::string, TH1D*> oneDhistoMap;
196 <    oneDHists_.push_back(oneDhistoMap);
197 <    std::map<std::string, TH2D*> twoDhistoMap;
198 <    twoDHists_.push_back(twoDhistoMap);
199 <
200 <
201 <
202 <    //book all histograms included in the configuration
203 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
204 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
205 <      int numBinsElements = currentHistogram.bins.size();
206 <      int numInputVariables = currentHistogram.inputVariables.size();
207 <
208 <      if(numBinsElements != 3 && numBinsElements !=6) {
209 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
210 <        exit(0);
211 <      }
212 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
213 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
214 <        exit(0);
215 <      }
216 <      else if(numBinsElements == 3){
217 <        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));
218 <      }
219 <      else if(numBinsElements == 6){
220 <        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));
221 <
222 <      }
223 <
224 <
225 <      if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
226 <
227 <      // bin      particle type
228 <      // ---      -------------
229 <      //  0        unmatched
230 <      //  1        u
231 <      //  2        d
232 <      //  3        s
233 <      //  4        c
234 <      //  5        b
235 <      //  6        t
236 <      //  7        e
237 <      //  8        mu
238 <      //  9        tau
239 <      // 10        nu
240 <      // 11        g
241 <      // 12        gamma
242 <      // 13        Z
243 <      // 14        W
244 <      // 15        light meson
245 <      // 16        K meson
246 <      // 17        D meson
247 <      // 18        B meson
248 <      // 19        light baryon
249 <      // 20        strange baryon
250 <      // 21        charm baryon
251 <      // 22        bottom baryon
252 <      // 23        other
253 <
254 <      vector<TString> labelArray;
255 <      labelArray.push_back("unmatched");
256 <      labelArray.push_back("u");
257 <      labelArray.push_back("d");
258 <      labelArray.push_back("s");
259 <      labelArray.push_back("c");
260 <      labelArray.push_back("b");
261 <      labelArray.push_back("t");
262 <      labelArray.push_back("e");
263 <      labelArray.push_back("#mu");
264 <      labelArray.push_back("#tau");
265 <      labelArray.push_back("#nu");
266 <      labelArray.push_back("g");
267 <      labelArray.push_back("#gamma");
268 <      labelArray.push_back("Z");
269 <      labelArray.push_back("W");
270 <      labelArray.push_back("light meson");
271 <      labelArray.push_back("K meson");
272 <      labelArray.push_back("D meson");
273 <      labelArray.push_back("B meson");
274 <      labelArray.push_back("light baryon");
275 <      labelArray.push_back("strange baryon");
276 <      labelArray.push_back("charm baryon");
277 <      labelArray.push_back("bottom baryon");
278 <      labelArray.push_back("other");
279 <
280 <      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
281 <        if(currentHistogram.name.find("GenMatchIdVsMotherId")==std::string::npos) {
282 <          oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
283 <        }
284 <        else {
285 <          twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
286 <          twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
287 <        }
288 <      }
289 <      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=std::string::npos) {
290 <        twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->CenterTitle();
291 <        twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->CenterTitle();
292 <      }
293 <
294 <    }
295 <
296 <    // Book a histogram for the number of each object type to be plotted.  
297 <    // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().  
298 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
299 <      string currentObject = objectsToPlot.at(currentObjectIndex);
300 <      int maxNum = 10;
301 <      if(currentObject == "mcparticles") maxNum = 50;
302 <      else if(currentObject == "primaryvertexs") maxNum = 50;
303 <      else if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
304 <      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
305 <      else if(currentObject == "electron-muon pairs")     currentObject = "electronMuonPairs";
306 <      else if(currentObject == "track-event pairs")       currentObject = "trackEventPairs";
307 <      else if(currentObject == "electron-track pairs")    currentObject = "electronTrackPairs";  
308 <      else if(currentObject == "muon-track pairs")        currentObject = "muonTrackPairs";      
309 <      else if(currentObject == "muon-tau pairs")          currentObject = "muonTauPairs";        
310 <      else if(currentObject == "tau-tau pairs")           currentObject = "ditauPairs";
311 <      currentObject.at(0) = toupper(currentObject.at(0));  
312 <      string histoName = "num" + currentObject;
313 <
314 <      if(histoName == "numPrimaryvertexs"){
315 <        string newHistoName = histoName + "BeforePileupCorrection";
316 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
317 <        newHistoName = histoName + "AfterPileupCorrection";
318 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
319 <      }
320 <      else
321 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
322 <    }
323 <
324 <
325 <
326 <
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);
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 the things to objectsToGet
345 <        int dashIndex = tempInputCollection.find("-");
346 <        int spaceIndex = tempInputCollection.find(" ");
347 <        int secondWordLength = spaceIndex - dashIndex;
348 <        objectsToGet.push_back(tempInputCollection);
345 <        objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
346 <        objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
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(tempInputCollection.substr(0,dashIndex)+"s");
351 <        objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
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 354 | Line 362 | OSUAnalysis::OSUAnalysis (const edm::Par
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";
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){
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          }
# Line 374 | Line 382 | OSUAnalysis::OSUAnalysis (const edm::Par
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 389 | Line 398 | OSUAnalysis::OSUAnalysis (const edm::Par
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 400 | Line 411 | OSUAnalysis::OSUAnalysis (const edm::Par
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        }
404      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  
410
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();
415
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  
427 }
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   {
441
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())
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 (useTrackCaloRhoCorr_) {  
869 <    // Used only for pile-up correction of by-hand calculation of isolation energy.  
870 <    // This rho collection is not available in all BEANs.  
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 >  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_);
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 <  double scaleFactor = 1.00;
888 <  if(doPileupReweighting_ && datasetType_ != "data")
889 <    scaleFactor = puWeight_->at (events->at (0).numTruePV);
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;
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
517
518
519
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);
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<bool> ());
930 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
929 >        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
930 >        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
931  
932        }
531      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
532        string currentObject = objectsToCut.at(currentObjectIndex);
933  
934 <        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
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 <
537 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
538 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
539 <        else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
540 <        else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
541 <        else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
542 <        else if(currentObject == "mets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
543 <        else if(currentObject == "tracks") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
544 <        else if(currentObject == "genjets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
545 <        else if(currentObject == "mcparticles") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
546 <        else if(currentObject == "primaryvertexs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
547 <        else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
548 <        else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
549 <        else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
550 <
551 <
552 <        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
553 <                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
554 <                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
555 <                                                                   "muon-muon pairs");
556 <        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
557 <                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
558 <                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
559 <                                                                           "electron-electron pairs");
560 <        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
561 <                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
562 <                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
563 <                                                                       "electron-muon pairs");
564 <        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
565 <                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
566 <                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
567 <                                                                     "track-event pairs");
568 <        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
569 <                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
570 <                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
571 <                                                                        "electron-track pairs");
572 <        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
573 <                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
574 <                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
575 <                                                                    "muon-track pairs");
576 <        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
577 <                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
578 <                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
579 <                                                                  "muon-tau pairs");
580 <        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),taus.product(),
581 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
582 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
583 <                                                                 "tau-tau pairs");
584 <        
585 <        
994 >        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
995        }
996  
588
589
997      }//end loop over all cuts
998  
999  
593    //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 <
597 <    //apply trigger (true if none were specified)
598 <    eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
599 <
600 <
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  
612      bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
1035        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
614
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 <
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  
1127  
1128 <    if(!eventPassedAllCuts)continue;
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 (printEventInfo_) {
626 <      // Write information about event to screen, for testing purposes.  
627 <      cout << "Event passed all cuts in channel " <<  currentChannel.name
628 <           << ": run="  << events->at(0).run
629 <           << "  lumi=" << events->at(0).lumi
630 <           << "  event=" << events->at(0).evt
631 <           << endl;  
632 <    }
1131 >      if (verbose_>2) clog << "  Filling histograms for currentcut = " << currentCut << endl;  
1132  
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  
635    //     if(datasetType_ != "data") {
636    //       scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
637    //       scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
638    //     }
1139  
1140 <    //filling histograms
1141 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1142 <      histogram currentHistogram = histograms.at(histogramIndex);
1140 >      if(eventPassedPreviousCuts.at(currentDir)){
1141 >
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 >          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  
644      if(currentHistogram.inputVariables.size() == 1){
645        TH1D* histo;
646        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
647
648
649
650        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
651        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
652        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
653                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
654                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
655        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
656        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
657                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
658                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
659        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
660                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
661                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
662        else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),        
663                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),  
664                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);      
665        else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),        
666                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),  
667                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);      
668        else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),    
669                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),      
670                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);  
671        else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),      
672                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),        
673                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);    
674        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
675        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
676        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
677        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
678        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
679        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
680        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
681        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
682        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
683        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
684      }
685      else if(currentHistogram.inputVariables.size() == 2){
686        TH2D* histo;
687        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
688
689
690
691        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
692        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
693        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
694                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
695                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
696        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
697        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
698                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
699                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
700        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
701                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
702                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
703        else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),        
704                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),          
705                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);      
706        else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),        
707                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),          
708                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);      
709        else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),    
710                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),      
711                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);  
712        else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),      
713                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),        
714                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);    
715        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
716        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
717        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
718        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
719        else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
720                                                                                         cumulativeFlags.at("tracks").back(),cumulativeFlags.at("events").back(),
721                                                                                         cumulativeFlags.at("track-event pairs").back(),scaleFactor);  
722        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
723        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
724        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
725        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
726        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
727        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
728      }
729    }
730
731    //fills histograms with the sizes of collections
732    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
733
734      string currentObject = objectsToPlot.at(currentObjectIndex);
735
736      string objectToPlot = "";  
737
738      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().  
739      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
740      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
741      else if(currentObject == "electron-muon pairs")     objectToPlot = "electronMuonPairs";
742      else if(currentObject == "electron-track pairs")    objectToPlot = "electronTrackPairs";
743      else if(currentObject == "muon-track pairs")        objectToPlot = "muonTrackPairs";      
744      else if(currentObject == "muon-tau pairs")          objectToPlot = "muonTauPairs";        
745      else if(currentObject == "tau-tau pairs")           objectToPlot = "ditauPairs";
746      else if(currentObject == "track-event pairs")       objectToPlot = "trackEventPairs";  
747      else objectToPlot = currentObject;
748      string tempCurrentObject = objectToPlot;
749      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));  
750      string histoName = "num" + tempCurrentObject;
751
752
753      //set position of primary vertex in event, in order to calculate quantities relative to it
754      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
755        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
756        int numToPlot = 0;
757        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
758          if(lastCutFlags.at(currentFlag)) numToPlot++;
759        }
760        if(objectToPlot == "primaryvertexs"){
761          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
762          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1303          }
764        else {
765          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
766        }
767      }
768      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
769      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
770      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
771      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
772      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
773      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
774      else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
775      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
776      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
777      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
778      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
779      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
780      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
781      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
782      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
783      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
784      else if(objectToPlot == "primaryvertexs"){
785        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
786        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
787      }
1304  
789    } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1305  
1306 <  } //end loop over channel
1306 >        //fills histograms with the sizes of collections
1307 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1308 >
1309 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1310 >          string objectToPlot = "";
1311 >
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 <  masterCutFlow_->fillCutFlow(scaleFactor);
1423 >  event.put (channelDecisions, "channelDecisions");
1424  
1425 < } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
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  
1431  
1432  
# Line 807 | 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::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, const BNtriggerCollection* triggerCollection){
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 >    //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 <  return triggerDecision;
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 961 | 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 < }
971 <
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 1064 | 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 1071 | 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 1127 | 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 == "looseID") {
1858 +    value = object->pt > 10 &&
1859 +      (object->isGlobalMuon  > 0 ||
1860 +       object->isTrackerMuon > 0);
1861 +  }
1862 +  else if(variable == "looseIDGlobalMuon") {
1863 +    value = object->pt > 10 &&
1864 +      object->isGlobalMuon  > 0;
1865 +  }
1866    else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1867    else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1868    else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1869    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1870 +  else if(variable == "relPFdBetaIsoPseudo") value = (object->pfIsoR04SumChargedHadronPt + object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt) / object->pt;
1871    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1872    else if(variable == "metMT") {
1873 <    const BNmet *met = chosenMET ();
1137 <    if (met)
1873 >    if (const BNmet *met = chosenMET ())
1874        {
1875 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1876 <          p2 (met->px, met->py, 0.0, met->pt);
1877 <
1878 <        value = (p1 + p2).Mt ();
1875 >        double dPhi = deltaPhi (object->phi, met->phi);
1876 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1877 >      }
1878 >    else
1879 >      value = -999;
1880 >  }
1881 >  else if(variable == "ptPlusMet") {
1882 >    // Calculate the magnitude of the vector sum of the muon pT and the Met.  
1883 >    if (const BNmet *met = chosenMET ())
1884 >      {
1885 >        TVector2 p2Met;
1886 >        TVector2 p2Muon;
1887 >        p2Met. SetMagPhi(   met->pt,    met->phi);
1888 >        p2Muon.SetMagPhi(object->pt, object->phi);  
1889 >        TVector2 p2MetElec = p2Met + p2Muon;
1890 >        value = p2MetElec.Mod();  
1891        }
1892      else
1893        value = -999;
1894    }
1147
1148
1895  
1896    else if(variable == "correctedD0VertexInEBPlus"){
1897      if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
# Line 1257 | Line 2003 | OSUAnalysis::valueLookup (const BNmuon*
2003      value = object->isGlobalMuon > 0                \
2004        && object->isPFMuon > 0                        \
2005        && object->normalizedChi2 < 10                \
2006 <                                  && object->numberOfValidMuonHits > 0        \
2006 >      && object->numberOfValidMuonHits > 0        \
2007        && object->numberOfMatchedStations > 1        \
2008        && fabs(object->correctedD0Vertex) < 0.2        \
2009        && fabs(object->correctedDZ) < 0.5        \
# Line 1266 | Line 2012 | OSUAnalysis::valueLookup (const BNmuon*
2012    }
2013    else if(variable == "tightIDdisplaced"){
2014      value = object->isGlobalMuon > 0                \
2015 +      && object->isPFMuon > 0                        \
2016        && object->normalizedChi2 < 10                \
2017 <                                  && object->numberOfValidMuonHits > 0        \
2017 >      && object->numberOfValidMuonHits > 0        \
2018        && object->numberOfMatchedStations > 1        \
2019        && object->numberOfValidPixelHits > 0        \
2020        && object->numberOfLayersWithMeasurement > 5;
2021    }
2022  
2023 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2023 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2024  
2025    else if(variable == "genMatchedPdgId"){
2026      int index = getGenMatchedParticleIndex(object);
# Line 1293 | Line 2040 | OSUAnalysis::valueLookup (const BNmuon*
2040    }
2041    else if(variable == "genMatchedMotherIdReverse"){
2042      int index = getGenMatchedParticleIndex(object);
2043 <    if(index == -1) value = 23;
2044 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2043 >    if(index == -1) value = 24;
2044 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
2045    }
2046    else if(variable == "genMatchedGrandmotherId"){
2047      int index = getGenMatchedParticleIndex(object);
# Line 1306 | Line 2053 | OSUAnalysis::valueLookup (const BNmuon*
2053      }
2054      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2055    }
2056 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2057 +    int index = getGenMatchedParticleIndex(object);
2058 +    if(index == -1) value = 24;
2059 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2060 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2061 +      if(motherIndex == -1) value = 24;
2062 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2063 +    }
2064 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2065 +  }
2066 +  else if(variable == "pfMuonsFromVertex"){
2067 +    double d0Error, dzError;
2068 +
2069 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2070 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2071 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2072 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2073 +      || fabs (object->correctedDZ / dzError) > 99.0;
2074 +    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
2075 +  }
2076  
2077  
2078  
2079 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2079 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2080  
2081    value = applyFunction(function, value);
2082  
2083    return value;
2084 < }
2084 > } // end muon valueLookup
2085  
2086  
2087 + //!electron valueLookup
2088   double
2089 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
2089 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
2090  
2091    double value = 0.0;
2092    if(variable == "energy") value = object->energy;
# Line 1483 | Line 2251 | OSUAnalysis::valueLookup (const BNelectr
2251    else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2252    else if(variable == "detIso") value = (object->trackIso) / object->pt;
2253    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2254 +  else if(variable == "relPFrhoIsoEB") value = object->isEB ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2255 +  else if(variable == "relPFrhoIsoEE") value = object->isEE ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2256    else if(variable == "metMT") {
2257 <    const BNmet *met = chosenMET ();
1488 <    if (met)
2257 >    if (const BNmet *met = chosenMET ())
2258        {
2259 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
2260 <          p2 (met->px, met->py, 0.0, met->pt);
2259 >        double dPhi = deltaPhi (object->phi, met->phi);
2260 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2261 >      }
2262 >    else
2263 >      value = -999;
2264 >  }
2265  
2266 <        value = (p1 + p2).Mt ();
2266 >  else if(variable == "ptPlusMet") {
2267 >    // Calculate the magnitude of the vector sum of the electron pT and the Met.  
2268 >    if (const BNmet *met = chosenMET ())
2269 >      {
2270 >        TVector2 p2Met;
2271 >        TVector2 p2Elec;
2272 >        p2Met. SetMagPhi(   met->pt,    met->phi);
2273 >        p2Elec.SetMagPhi(object->pt, object->phi);  
2274 >        TVector2 p2MetElec = p2Met + p2Elec;
2275 >        value = p2MetElec.Mod();  
2276        }
2277      else
2278        value = -999;
# Line 1557 | Line 2339 | OSUAnalysis::valueLookup (const BNelectr
2339      else value = -999;
2340    }
2341  
2342 +  else if(variable == "looseID"){
2343 +    if (object->isEB)
2344 +      {
2345 +        value = fabs(object->delEtaIn) < 0.007 \
2346 +          && fabs (object->delPhiIn) < 0.15 \
2347 +          && object->scSigmaIEtaIEta < 0.01 \
2348 +          && object->hadOverEm < 0.12 \
2349 +          && fabs (object->correctedD0Vertex) < 0.02 \
2350 +          && fabs (object->correctedDZ) < 0.2 \
2351 +          && object->absInvEMinusInvPin < 0.05 \
2352 +          && object->passConvVeto;
2353 +      }
2354 +    else
2355 +      {
2356 +        value = fabs(object->delEtaIn) < 0.009 \
2357 +          && fabs (object->delPhiIn) < 0.10 \
2358 +          && object->scSigmaIEtaIEta < 0.03 \
2359 +          && object->hadOverEm < 0.10 \
2360 +          && fabs (object->correctedD0Vertex) < 0.02 \
2361 +          && fabs (object->correctedDZ) < 0.2 \
2362 +          && object->absInvEMinusInvPin < 0.05 \
2363 +          && object->passConvVeto;
2364 +      }
2365 +  }
2366 +
2367    else if(variable == "tightID"){
2368      if (object->isEB)
2369        {
# Line 1582 | Line 2389 | OSUAnalysis::valueLookup (const BNelectr
2389        }
2390    }
2391  
2392 +  else if(variable == "looseID_MVA"){
2393 +    value = object->pt > 10
2394 +      && object->mvaNonTrigV0 > 0;
2395 +      }
2396    else if(variable == "correctedD0VertexInEBPositiveCharge"){
2397      if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2398      else value = -999;
# Line 1655 | Line 2466 | OSUAnalysis::valueLookup (const BNelectr
2466    }
2467  
2468  
2469 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2469 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2470  
2471    else if(variable == "genMatchedPdgId"){
2472      int index = getGenMatchedParticleIndex(object);
# Line 1676 | Line 2487 | OSUAnalysis::valueLookup (const BNelectr
2487    }
2488    else if(variable == "genMatchedMotherIdReverse"){
2489      int index = getGenMatchedParticleIndex(object);
2490 <    if(index == -1) value = 23;
2491 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2490 >    if(index == -1) value = 24;
2491 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2492    }
2493    else if(variable == "genMatchedGrandmotherId"){
2494      int index = getGenMatchedParticleIndex(object);
# Line 1689 | Line 2500 | OSUAnalysis::valueLookup (const BNelectr
2500      }
2501      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2502    }
2503 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2504 +    int index = getGenMatchedParticleIndex(object);
2505 +    if(index == -1) value = 24;
2506 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2507 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2508 +      if(motherIndex == -1) value = 24;
2509 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2510 +    }
2511 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2512 +  }
2513 +  else if(variable == "pfElectronsFromVertex"){
2514 +    double d0Error, dzError;
2515  
2516 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2517 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2518 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2519 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2520 +      || fabs (object->correctedDZ / dzError) > 99.0;
2521 +    value = !value;
2522 +  }
2523  
2524  
2525 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2525 >
2526 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2527  
2528    value = applyFunction(function, value);
2529  
2530    return value;
2531 < }
2531 > } // end electron valueLookup
2532  
2533  
2534 + //!event valueLookup
2535   double
2536 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2536 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2537  
2538    double value = 0.0;
2539  
# Line 1770 | Line 2602 | OSUAnalysis::valueLookup (const BNevent*
2602    else if(variable == "id2") value = object->id2;
2603    else if(variable == "evt") value = object->evt;
2604    else if(variable == "puScaleFactor"){
2605 <    if(datasetType_ != "data")
2605 >    if(doPileupReweighting_ && datasetType_ != "data")
2606        value = puWeight_->at (events->at (0).numTruePV);
2607      else
2608        value = 1.0;
2609    }
2610 <  else if(variable == "muonScaleFactor"){
2611 <    if(datasetType_ != "data")
2612 <      //      value = muonSFWeight_->at (chosenMuon ()->eta);
2613 <      value = 1.0;
2614 <    else
2615 <      value = 1.0;
2610 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2611 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2612 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2613 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2614 >
2615 >  else if(variable == "unfilteredHt") value = getHt(jets.product());
2616 >  else if(variable == "ht") value = chosenHT ();
2617 >
2618 >  else if(variable == "leadMuPairInvMass"){
2619 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2620 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2621 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2622 >    value = (p0 + p1).M ();
2623 >  }
2624 >  else if(variable == "leadMuPairPt"){
2625 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2626 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2627 >             pt1 (muPair.second->px, muPair.second->py);
2628 >    pt0 += pt1;
2629 >    value = pt0.Mod ();
2630 >  }
2631 >  else if(variable == "leadElPairInvMass"){
2632 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2633 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2634 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2635 >    value = (p0 + p1).M ();
2636 >  }
2637 >  else if(variable == "leadElPairPt"){
2638 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2639 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2640 >             pt1 (muPair.second->px, muPair.second->py);
2641 >    pt0 += pt1;
2642 >    value = pt0.Mod ();
2643    }
2644 <  else if(variable == "electronScaleFactor"){
1786 <    if(datasetType_ != "data")
1787 <      //      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1788 <      value = 1.0;
1789 <    else
1790 <      value = 1.0;
1791 <  }
1792 <
1793 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2644 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2645  
2646    value = applyFunction(function, value);
2647  
2648    return value;
2649 < }
2649 > } // end event valueLookup
2650 >
2651  
2652 + //!tau valueLookup
2653   double
2654 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2654 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2655  
2656    double value = 0.0;
2657  
# Line 1842 | Line 2695 | OSUAnalysis::valueLookup (const BNtau* o
2695    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2696    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2697  
2698 +  else if (variable == "looseHadronicID") {
2699 +    value = object->pt > 10
2700 +      && object->eta < 2.3
2701 +      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2702 +      && object->HPSdecayModeFinding > 0
2703 +      && object->HPSagainstElectronLoose > 0
2704 +      && object->HPSagainstMuonTight > 0;
2705 +  }
2706  
2707 <
1847 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2707 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2708  
2709    else if(variable == "genMatchedPdgId"){
2710      int index = getGenMatchedParticleIndex(object);
# Line 1864 | Line 2724 | OSUAnalysis::valueLookup (const BNtau* o
2724    }
2725    else if(variable == "genMatchedMotherIdReverse"){
2726      int index = getGenMatchedParticleIndex(object);
2727 <    if(index == -1) value = 23;
2728 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2727 >    if(index == -1) value = 24;
2728 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2729    }
2730    else if(variable == "genMatchedGrandmotherId"){
2731      int index = getGenMatchedParticleIndex(object);
# Line 1877 | Line 2737 | OSUAnalysis::valueLookup (const BNtau* o
2737      }
2738      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2739    }
2740 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2741 +    int index = getGenMatchedParticleIndex(object);
2742 +    if(index == -1) value = 24;
2743 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2744 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2745 +      if(motherIndex == -1) value = 24;
2746 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2747 +    }
2748 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2749 +  }
2750  
2751  
2752 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2752 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2753  
2754    value = applyFunction(function, value);
2755  
2756    return value;
2757 < }
2757 > } // end tau valueLookup
2758  
2759 +
2760 + //!met valueLookup
2761   double
2762 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2762 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2763  
2764    double value = 0.0;
2765  
# Line 1951 | Line 2823 | OSUAnalysis::valueLookup (const BNmet* o
2823    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2824    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2825  
2826 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2826 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2827  
2828    value = applyFunction(function, value);
2829  
2830    return value;
2831 < }
2831 > } // end met valueLookup
2832 >
2833  
2834 + //!track valueLookup
2835   double
2836 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2836 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2837  
2838    double value = 0.0;
2839    double pMag = sqrt(object->pt * object->pt +
2840 <                     object->pz * object->pz);
2841 <  
2840 >                     object->pz * object->pz);
2841 >
2842    if(variable == "pt") value = object->pt;
2843    else if(variable == "px") value = object->px;
2844    else if(variable == "py") value = object->py;
# Line 1983 | Line 2857 | OSUAnalysis::valueLookup (const BNtrack*
2857    else if(variable == "numValidHits") value = object->numValidHits;
2858    else if(variable == "isHighPurity") value = object->isHighPurity;
2859  
1986
2860    //additional BNs info for disappTrks
2861 <  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2862 <  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2863 <  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2864 <  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2865 <  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2866 <  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2867 <  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2868 <  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
1996 <  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2861 >  else if(variable == "caloEMDeltaRp3")     value = object->caloEMDeltaRp3;
2862 >  else if(variable == "caloHadDeltaRp3")    value = object->caloHadDeltaRp3;
2863 >  else if(variable == "caloEMDeltaRp4")     value = object->caloEMDeltaRp4;
2864 >  else if(variable == "caloHadDeltaRp4")    value = object->caloHadDeltaRp4;
2865 >  else if(variable == "caloEMDeltaRp5")     value = object->caloEMDeltaRp5;
2866 >  else if(variable == "caloHadDeltaRp5")    value = object->caloHadDeltaRp5;
2867 >  else if(variable == "nHitsMissingOuter")  value = object->nHitsMissingOuter;
2868 >  else if(variable == "nHitsMissingInner")  value = object->nHitsMissingInner;
2869    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2870 <  
2870 >  else if(variable == "depTrkRp3")          value = object->depTrkRp3;
2871 >  else if(variable == "trkRelIsoRp3")     { value = (object->depTrkRp3 - object->pt) / object->pt; if (value<0) value = 0; }
2872 >  else if(variable == "trkRelIsoRp5")     { value = (object->depTrkRp5 - object->pt) / object->pt; if (value<0) value = 0; }
2873 >  else if(variable == "depEcalRp3")         value = object->depEcalRp3;
2874 >  else if(variable == "depHcalRp3")         value = object->depHcalRp3;
2875 >  else if(variable == "depHoRp3")           value = object->depHoRp3;
2876 >  else if(variable == "nTracksRp3")         value = object->nTracksRp3;
2877 >  else if(variable == "trackerVetoPtRp3")   value = object->trackerVetoPtRp3;
2878 >  else if(variable == "emVetoEtRp3")        value = object->emVetoEtRp3;
2879 >  else if(variable == "hadVetoEtRp3")       value = object->hadVetoEtRp3;
2880 >  else if(variable == "hoVetoEtRp3")        value = object->hoVetoEtRp3;
2881 >  else if(variable == "depTrkRp5")          value = object->depTrkRp5;
2882 >  else if(variable == "depEcalRp5")         value = object->depEcalRp5;
2883 >  else if(variable == "depHcalRp5")         value = object->depHcalRp5;
2884 >  else if(variable == "depHoRp5")           value = object->depHoRp5;
2885 >  else if(variable == "nTracksRp5")         value = object->nTracksRp5;
2886 >  else if(variable == "trackerVetoPtRp5")   value = object->trackerVetoPtRp5;
2887 >  else if(variable == "emVetoEtRp5")        value = object->emVetoEtRp5;
2888 >  else if(variable == "hadVetoEtRp5")       value = object->hadVetoEtRp5;
2889 >  else if(variable == "hoVetoEtRp5")        value = object->hoVetoEtRp5;
2890  
2891    //user defined variables
2892    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;
2893    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2894 +  else if(variable == "depTrkRp5MinusPt"){
2895 +    if ( (object->depTrkRp5 - object->pt) < 0 ) {
2896 + //       clog << "Warning:  found track with depTrkRp5 < pt:  depTrkRp5=" << object->depTrkRp5
2897 + //         << "; pt=" << object->pt
2898 + //         << "; object->depTrkRp5 - object->pt = " << object->depTrkRp5 - object->pt
2899 + //         << endl;  
2900 +           value = 0;
2901 +         }
2902 +         else value =  (object->depTrkRp5 - object->pt);
2903 +  }
2904 +  else if(variable == "depTrkRp3MinusPt"){
2905 +    if ( (object->depTrkRp3 - object->pt) < 0 ) {
2906 +      value = 0;
2907 +    }
2908 +    else value =  (object->depTrkRp3 - object->pt);
2909 +  }
2910 +
2911 +  else if(variable == "dPhiMet") {
2912 +    if (const BNmet *met = chosenMET ()) {
2913 +      value = deltaPhi (object->phi, met->phi);
2914 +    } else value = -999;
2915 +  }
2916 +  
2917 +  
2918    else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2919    else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2920 <  else if(variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object);  
2921 <  else if(variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object) / pMag;  
2920 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2921 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2922 >  else if(variable == "depTrkRp5RhoCorr")           value = getTrkDepTrkRp5RhoCorr(object);
2923 >  else if(variable == "depTrkRp3RhoCorr")           value = getTrkDepTrkRp3RhoCorr(object);
2924 >
2925 >  else if(variable == "depTrkRp5MinusPtRhoCorr")    {
2926 >    if ( (getTrkDepTrkRp5RhoCorr(object) - object->pt) < 0 ) value = 0;
2927 >    else {value = (getTrkDepTrkRp5RhoCorr(object) - object->pt );}
2928 >  }
2929 >  
2930 >  else if(variable == "depTrkRp3MinusPtRhoCorr")    
2931 >    {
2932 >      if ( (getTrkDepTrkRp3RhoCorr(object) - object->pt) < 0 ) value = 0;
2933 >      else {value = (getTrkDepTrkRp3RhoCorr(object) - object->pt );}
2934 >    }
2935 >
2936    else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2937    else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2938    else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2939    else if(variable == "ptError")                    value = object->ptError;
2940    else if(variable == "ptRes")                      value = getTrkPtRes(object);
2941 <  else if (variable == "d0wrtPV"){      
2942 <    double vx = object->vx - chosenVertex ()->x,        
2943 <      vy = object->vy - chosenVertex ()->y,      
2944 <      px = object->px,  
2945 <      py = object->py,  
2946 <      pt = object->pt;  
2947 <    value = (-vx * py + vy * px) / pt;  
2948 <  }      
2949 <  else if (variable == "dZwrtPV"){      
2950 <    double vx = object->vx - chosenVertex ()->x,        
2951 <      vy = object->vy - chosenVertex ()->y,      
2952 <      vz = object->vz - chosenVertex ()->z,      
2953 <      px = object->px,  
2954 <      py = object->py,  
2955 <      pz = object->pz,  
2956 <      pt = object->pt;  
2957 <    value = vz - (vx * px + vy * py)/pt * (pz/pt);      
2958 <  }    
2959 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2941 >  else if (variable == "d0wrtPV"){
2942 >    double vx = object->vx - chosenVertex ()->x,
2943 >      vy = object->vy - chosenVertex ()->y,
2944 >      px = object->px,
2945 >      py = object->py,
2946 >      pt = object->pt;
2947 >    value = (-vx * py + vy * px) / pt;
2948 >  }
2949 >  else if (variable == "dZwrtPV"){
2950 >    double vx = object->vx - chosenVertex ()->x,
2951 >      vy = object->vy - chosenVertex ()->y,
2952 >      vz = object->vz - chosenVertex ()->z,
2953 >      px = object->px,
2954 >      py = object->py,
2955 >      pz = object->pz,
2956 >      pt = object->pt;
2957 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2958 >  }
2959 >
2960 >  else if(variable == "deltaRMinSubLeadJet") {
2961 >    // calculate minimum deltaR between track and any other subleading jet  
2962 >    double trkJetDeltaRMin = 99.;  
2963 >    for (uint ijet = 0; ijet<jets->size(); ijet++) {
2964 >      string empty = "";  
2965 >      double isSubLeadingJet = valueLookup(&jets->at(ijet), "disappTrkSubLeadingJetID", "", empty);  
2966 >      if (!isSubLeadingJet) continue;  // only consider jets that pass the subleading jet ID criteria  
2967 >      double jetEta = valueLookup(&jets->at(ijet), "eta", "", empty);
2968 >      double jetPhi = valueLookup(&jets->at(ijet), "phi", "", empty);
2969 >      double trkJetDeltaR = deltaR(object->eta, object->phi, jetEta, jetPhi);  
2970 >      if (trkJetDeltaR < trkJetDeltaRMin) trkJetDeltaRMin = trkJetDeltaR;
2971 >    }
2972 >    value = trkJetDeltaRMin;  
2973 >  }  
2974 >  
2975 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2976  
2977    else if(variable == "genMatchedPdgId"){
2978      int index = getGenMatchedParticleIndex(object);
# Line 2048 | Line 2993 | OSUAnalysis::valueLookup (const BNtrack*
2993    }
2994    else if(variable == "genMatchedMotherIdReverse"){
2995      int index = getGenMatchedParticleIndex(object);
2996 <    if(index == -1) value = 23;
2997 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2996 >    if(index == -1) value = 24;
2997 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2998    }
2999    else if(variable == "genMatchedGrandmotherId"){
3000      int index = getGenMatchedParticleIndex(object);
# Line 2061 | Line 3006 | OSUAnalysis::valueLookup (const BNtrack*
3006      }
3007      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3008    }
3009 +  else if(variable == "genMatchedGrandmotherIdReverse"){
3010 +    int index = getGenMatchedParticleIndex(object);
3011 +    if(index == -1) value = 24;
3012 +    else if(fabs(mcparticles->at(index).motherId) == 15){
3013 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3014 +      if(motherIndex == -1) value = 24;
3015 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3016 +    }
3017 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3018 +  }
3019  
3020  
3021  
3022 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3022 >  else{clog << "WARNING: invalid variable '" << variable << "' for BNtrack collection.\n"; value = -999;}
3023  
3024    value = applyFunction(function, value);
3025  
3026    return value;
3027 < }
3027 > } // end track valueLookup
3028  
3029 +
3030 + //!genjet valueLookup
3031   double
3032 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
3032 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
3033  
3034    double value = 0.0;
3035  
# Line 2092 | Line 3049 | OSUAnalysis::valueLookup (const BNgenjet
3049    else if(variable == "charge") value = object->charge;
3050  
3051  
3052 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3052 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3053  
3054    value = applyFunction(function, value);
3055  
3056    return value;
3057   }
3058  
3059 + //!mcparticle valueLookup
3060   double
3061 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
3061 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
3062  
3063    double value = 0.0;
3064  
# Line 2225 | Line 3183 | OSUAnalysis::valueLookup (const BNmcpart
3183    }
3184  
3185  
3186 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3186 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3187  
3188    value = applyFunction(function, value);
3189  
3190    return value;
3191 < }
3191 > } // end mcparticle valueLookup
3192  
3193 +
3194 + //!primaryvertex valueLookup
3195   double
3196 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
3196 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
3197  
3198    double value = 0.0;
3199  
# Line 2252 | Line 3212 | OSUAnalysis::valueLookup (const BNprimar
3212    else if(variable == "isGood") value = object->isGood;
3213  
3214  
3215 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3215 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3216  
3217    value = applyFunction(function, value);
3218  
3219    return value;
3220   }
3221  
3222 + //!bxlumi valueLookup
3223   double
3224 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
3224 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
3225  
3226    double value = 0.0;
3227  
# Line 2269 | Line 3230 | OSUAnalysis::valueLookup (const BNbxlumi
3230    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
3231  
3232  
3233 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3233 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3234  
3235    value = applyFunction(function, value);
3236  
3237    return value;
3238   }
3239  
3240 + //!photon valueLookup
3241   double
3242 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
3242 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
3243  
3244    double value = 0.0;
3245  
# Line 2352 | Line 3314 | OSUAnalysis::valueLookup (const BNphoton
3314    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
3315  
3316  
2355
3317  
3318 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3318 >
3319 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3320  
3321    else if(variable == "genMatchedPdgId"){
3322      int index = getGenMatchedParticleIndex(object);
# Line 2376 | Line 3338 | OSUAnalysis::valueLookup (const BNphoton
3338    }
3339    else if(variable == "genMatchedMotherIdReverse"){
3340      int index = getGenMatchedParticleIndex(object);
3341 <    if(index == -1) value = 23;
3342 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
3341 >    if(index == -1) value = 24;
3342 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
3343    }
3344    else if(variable == "genMatchedGrandmotherId"){
3345      int index = getGenMatchedParticleIndex(object);
# Line 2389 | Line 3351 | OSUAnalysis::valueLookup (const BNphoton
3351      }
3352      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3353    }
3354 +  else if(variable == "genMatchedGrandmotherIdReverse"){
3355 +    int index = getGenMatchedParticleIndex(object);
3356 +    if(index == -1) value = 24;
3357 +    else if(fabs(mcparticles->at(index).motherId) == 15){
3358 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3359 +      if(motherIndex == -1) value = 24;
3360 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3361 +    }
3362 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3363 +  }
3364  
3365  
3366 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3366 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3367  
3368    value = applyFunction(function, value);
3369  
3370    return value;
3371 < }
3371 > } // end photon valueLookup
3372  
3373 +
3374 + //!supercluster valueLookup
3375   double
3376 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
3376 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
3377  
3378    double value = 0.0;
3379  
# Line 2413 | Line 3387 | OSUAnalysis::valueLookup (const BNsuperc
3387    else if(variable == "theta") value = object->theta;
3388  
3389  
3390 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3390 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3391  
3392    value = applyFunction(function, value);
3393  
3394    return value;
3395   }
3396  
3397 + //!trigobj valueLookup
3398 + double
3399 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3400 +
3401 +  double value = 0.0;
3402 +
3403 +  if(variable == "pt") value = object->pt;
3404 +  else if(variable == "eta") value = object->eta;
3405 +  else if(variable == "phi") value = object->phi;
3406 +  else if(variable == "px") value = object->px;
3407 +  else if(variable == "py") value = object->py;
3408 +  else if(variable == "pz") value = object->pz;
3409 +  else if(variable == "et") value = object->et;
3410 +  else if(variable == "energy") value = object->energy;
3411 +  else if(variable == "etTotal") value = object->etTotal;
3412 +  else if(variable == "id") value = object->id;
3413 +  else if(variable == "charge") value = object->charge;
3414 +  else if(variable == "isIsolated") value = object->isIsolated;
3415 +  else if(variable == "isMip") value = object->isMip;
3416 +  else if(variable == "isForward") value = object->isForward;
3417 +  else if(variable == "isRPC") value = object->isRPC;
3418 +  else if(variable == "bx") value = object->bx;
3419 +  else if(variable == "filter") {
3420 +    if ((stringValue = object->filter) == "")
3421 +      stringValue = "none";  // stringValue should only be empty if value is filled
3422 +  }
3423 +
3424 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3425 +
3426 +  value = applyFunction(function, value);
3427 +
3428 +  return value;
3429 + }
3430  
3431 + //!muon-muon pair valueLookup
3432   double
3433 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
3433 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3434  
3435    double value = 0.0;
3436  
3437    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3438 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3439    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3440    else if(variable == "invMass"){
3441      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2483 | Line 3492 | OSUAnalysis::valueLookup (const BNmuon*
3492        value = object2->correctedD0;
3493      }
3494  
3495 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3495 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3496 >
3497 >  value = applyFunction(function, value);
3498 >
3499 >  return value;
3500 > } // end muon-muon pair valueLookup
3501 >
3502 >
3503 > //!muon-photon pair valueLookup
3504 > double
3505 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3506 >
3507 >  double value = 0.0;
3508 >
3509 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3510 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3511 >  else if(variable == "photonEta") value = object2->eta;
3512 >  else if(variable == "photonPt") value = object2->pt;
3513 >  else if(variable == "muonEta") value = object1->eta;
3514 >  else if(variable == "photonPhi") value = object2->phi;
3515 >  else if(variable == "muonPhi") value = object1->phi;
3516 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3517 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3518 >  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3519 >  else if(variable == "invMass"){
3520 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3521 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3522 >    value = (fourVector1 + fourVector2).M();
3523 >  }
3524 >  else if(variable == "pt"){
3525 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3526 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3527 >    value = (fourVector1 + fourVector2).Pt();
3528 >  }
3529 >  else if(variable == "threeDAngle")
3530 >    {
3531 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3532 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3533 >      value = (threeVector1.Angle(threeVector2));
3534 >    }
3535 >  else if(variable == "alpha")
3536 >    {
3537 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3538 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3539 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3540 >      value = (pi-threeVector1.Angle(threeVector2));
3541 >    }
3542 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3543 >
3544 >  value = applyFunction(function, value);
3545 >
3546 >  return value;
3547 > }
3548 >
3549 > //!electron-photon pair valueLookup
3550 > double
3551 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3552 >
3553 >  double value = 0.0;
3554 >
3555 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3556 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3557 >  else if(variable == "photonEta") value = object2->eta;
3558 >  else if(variable == "photonPt") value = object2->pt;
3559 >  else if(variable == "electronEta") value = object1->eta;
3560 >  else if(variable == "photonPhi") value = object2->phi;
3561 >  else if(variable == "electronPhi") value = object1->phi;
3562 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3563 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3564 >  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3565 >  else if(variable == "invMass"){
3566 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3567 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3568 >    value = (fourVector1 + fourVector2).M();
3569 >  }
3570 >  else if(variable == "pt"){
3571 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3572 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3573 >    value = (fourVector1 + fourVector2).Pt();
3574 >  }
3575 >  else if(variable == "threeDAngle")
3576 >    {
3577 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3578 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3579 >      value = (threeVector1.Angle(threeVector2));
3580 >    }
3581 >  else if(variable == "alpha")
3582 >    {
3583 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3584 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3585 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3586 >      value = (pi-threeVector1.Angle(threeVector2));
3587 >    }
3588 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3589  
3590    value = applyFunction(function, value);
3591  
3592    return value;
3593   }
3594  
3595 + //!electron-electron pair valueLookup
3596   double
3597 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
3597 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3598  
3599    double value = 0.0;
3600  
3601    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3602 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3603    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3604    else if(variable == "invMass"){
3605      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2537 | Line 3641 | OSUAnalysis::valueLookup (const BNelectr
3641      value = object2->correctedD0;
3642    }
3643  
3644 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3644 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3645  
3646    value = applyFunction(function, value);
3647  
3648    return value;
3649   }
3650  
3651 + //!electron-muon pair valueLookup
3652   double
3653 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3653 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3654  
3655    double value = 0.0;
3656  
3657    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3658 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3659    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3660    else if(variable == "invMass"){
3661      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2596 | Line 3702 | OSUAnalysis::valueLookup (const BNelectr
3702    else if(variable == "muonDetIso"){
3703      value = (object2->trackIsoDR03) / object2->pt;
3704    }
3705 +  else if(variable == "electronRelPFrhoIso"){
3706 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3707 +  }
3708 +  else if(variable == "muonRelPFdBetaIso"){
3709 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3710 +  }
3711 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3712 +  value = applyFunction(function, value);
3713 +
3714 +  return value;
3715 + } // end electron-muon pair valueLookup
3716 +
3717 +
3718 + //!electron-jet pair valueLookup
3719 + double
3720 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3721 +
3722 +  double value = 0.0;
3723 +
3724 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3725 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3726 +  else if(variable == "jetEta") value = object2->eta;
3727 +  else if(variable == "jetPhi") value = object2->phi;
3728 +  else if(variable == "electronEta") value = object1->eta;
3729 +  else if(variable == "electronPhi") value = object1->phi;
3730 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3731 +  else if(variable == "invMass"){
3732 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3733 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3734 +    value = (fourVector1 + fourVector2).M();
3735 +  }
3736 +  else if(variable == "pt"){
3737 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3738 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3739 +    value = (fourVector1 + fourVector2).Pt();
3740 +  }
3741 +  else if(variable == "threeDAngle")
3742 +    {
3743 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3744 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3745 +      value = (threeVector1.Angle(threeVector2));
3746 +    }
3747 +  else if(variable == "chargeProduct"){
3748 +    value = object1->charge*object2->charge;
3749 +  }
3750 +
3751 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3752 +  value = applyFunction(function, value);
3753 +
3754 +  return value;
3755 + }
3756 +
3757 + //!electron-mcparticle pair valueLookup
3758 + double
3759 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmcparticle* object2, string variable, string function, string &stringValue){
3760 +
3761 +  double value = 0.0;
3762 +
3763 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3764 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3765 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3766 +  else if(variable == "threeDAngle")
3767 +    {
3768 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3769 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3770 +      value = (threeVector1.Angle(threeVector2));
3771 +    }
3772 +  else if(variable == "chargeProduct"){
3773 +    value = object1->charge*object2->charge;
3774 +  }
3775 +
3776 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3777 +  value = applyFunction(function, value);
3778 +
3779 +  return value;
3780 + }
3781 +
3782 +
3783 + //!photon-jet pair valueLookup
3784 + double
3785 + OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3786 +
3787 +  double value = 0.0;
3788 +
3789 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3790 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3791 +  else if(variable == "jetEta") value = object2->eta;
3792 +  else if(variable == "jetPhi") value = object2->phi;
3793 +  else if(variable == "photonEta") value = object1->eta;
3794 +  else if(variable == "photonPhi") value = object1->phi;
3795 +  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3796 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3797 +  else if(variable == "invMass"){
3798 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3799 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3800 +    value = (fourVector1 + fourVector2).M();
3801 +  }
3802 +  else if(variable == "pt"){
3803 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3804 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3805 +    value = (fourVector1 + fourVector2).Pt();
3806 +  }
3807 +  else if(variable == "threeDAngle")
3808 +    {
3809 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3810 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3811 +      value = (threeVector1.Angle(threeVector2));
3812 +    }
3813 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3814 +  value = applyFunction(function, value);
3815 +
3816 +  return value;
3817 + }
3818 +
3819 + // track-jet pair valueLookup
3820 + double
3821 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNjet* object2, string variable, string function, string &stringValue){
3822  
3823 +  double value = 0.0;
3824  
3825 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3825 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3826 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3827  
3828 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3829    value = applyFunction(function, value);
3830  
3831    return value;
3832 +
3833   }
3834  
3835  
3836 < double  
3837 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function){  
3838 <  double electronMass = 0.000511;        
3839 <  double value = 0.0;    
3840 <  TLorentzVector fourVector1(0, 0, 0, 0);        
3841 <  TLorentzVector fourVector2(0, 0, 0, 0);        
3842 <  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));  
3843 <  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);    
3844 <  else if(variable == "invMass"){        
3845 <    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);    
3846 <    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );    
3847 <        
3848 <    value = (fourVector1 + fourVector2).M();    
3836 >
3837 > // met-jet pair valueLookup
3838 > double
3839 > OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3840 >
3841 >  double value = 0.0;
3842 >
3843 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3844 >
3845 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3846 >  value = applyFunction(function, value);
3847 >
3848 >  return value;
3849 >
3850 > }  
3851 >
3852 >
3853 >
3854 > //!muon-jet pair valueLookup
3855 > double
3856 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3857 >
3858 >  double value = 0.0;
3859 >
3860 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3861 >  else if(variable == "jetEta") value = object2->eta;
3862 >  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3863 >  else if(variable == "jetPt") value = object2->pt;
3864 >  else if(variable == "jetPhi") value = object2->phi;
3865 >  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3866 >  else if(variable == "muonEta") value = object1->eta;
3867 >  else if(variable == "muonPt") value = object1->pt;
3868 >  else if(variable == "muonPhi") value = object1->phi;
3869 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3870 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3871 >  else if(variable == "invMass"){
3872 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3873 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3874 >    value = (fourVector1 + fourVector2).M();
3875    }
3876 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}  
3877 <  value = applyFunction(function, value);        
3878 <  return value;  
3876 >  else if(variable == "pt"){
3877 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3878 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3879 >    value = (fourVector1 + fourVector2).Pt();
3880 >  }
3881 >  else if(variable == "threeDAngle")
3882 >    {
3883 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3884 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3885 >      value = (threeVector1.Angle(threeVector2));
3886 >    }
3887 >  else if(variable == "chargeProduct"){
3888 >    value = object1->charge*object2->charge;
3889 >  }
3890 >
3891 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3892 >  value = applyFunction(function, value);
3893 >
3894 >  return value;
3895   }
3896  
3897 + //!muon-event valueLookup
3898 + double
3899 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNevent* object2, string variable, string function, string &stringValue){
3900 +
3901 +  double value = 0.0;
3902  
3903 +  if(variable == "muonEta") value = object1->eta;
3904 +  else if(variable == "muonPt") value = object1->pt;
3905 +  else if(variable == "muonPhi") value = object1->phi;
3906 +  else if(variable == "Ht") value = getHt(jets.product());
3907 +  else if(variable == "pthat")   value = object2->pthat;
3908 +  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3909 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3910 +  value = applyFunction(function, value);
3911  
3912 +  return value;
3913 + }
3914 + //!jet-jet pair valueLookup
3915   double
3916 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function){
3916 > OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3917 >
3918 >  double value = 0.0;
3919 >
3920 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3921 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3922 >  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3923 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3924 >  else if(variable == "invMass"){
3925 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3926 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3927 >    value = (fourVector1 + fourVector2).M();
3928 >  }
3929 >  else if(variable == "pt"){
3930 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3931 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3932 >    value = (fourVector1 + fourVector2).Pt();
3933 >  }
3934 >  else if(variable == "threeDAngle")
3935 >    {
3936 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3937 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3938 >      value = (threeVector1.Angle(threeVector2));
3939 >    }
3940 >  else if(variable == "chargeProduct"){
3941 >    value = object1->charge*object2->charge;
3942 >  }
3943 >
3944 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3945 >  value = applyFunction(function, value);
3946 >
3947 >  return value;
3948 > }
3949 >
3950 > //!electron-track pair valueLookup
3951 > double
3952 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3953 >  double electronMass = 0.000511;
3954 >  double value = 0.0;
3955 >  TLorentzVector fourVector1(0, 0, 0, 0);
3956 >  TLorentzVector fourVector2(0, 0, 0, 0);
3957 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3958 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3959 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3960 >  else if(variable == "deltaRLooseMvaId") {
3961 >    // only consider electrons that pass "loose MVA id", i.e., mvaNonTrigV0 > 0;
3962 >    // otherwise return very large value (99)  
3963 >    if (object1->mvaNonTrigV0>0) value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3964 >    else                         value = 99.;  
3965 >  }
3966 >  else if(variable == "invMass"){
3967 >    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3968 >    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3969 >
3970 >    value = (fourVector1 + fourVector2).M();
3971 >  }
3972 >  else if(variable == "chargeProduct"){
3973 >    value = object1->charge*object2->charge;
3974 >  }
3975 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3976 >  value = applyFunction(function, value);
3977 >  return value;
3978 >
3979 > }
3980 >
3981 >
3982 > //!muon-track pair valueLookup
3983 > double
3984 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3985    double pionMass = 0.140;
3986    double muonMass = 0.106;
3987    double value = 0.0;
3988    TLorentzVector fourVector1(0, 0, 0, 0);
3989    TLorentzVector fourVector2(0, 0, 0, 0);
3990    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3991 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3992    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3993 +  else if(variable == "deltaRLooseID") {
3994 +    // only consider muons that pass looseId criteria; otherwise return very large value (99.)  
3995 +    string empty = "";  
3996 +    double isLooseId = valueLookup(object1, "looseID", "", empty);    
3997 +    if (isLooseId) value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3998 +    else           value = 99.;  
3999 +  }
4000    else if(variable == "invMass"){
4001      fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
4002      fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
4003  
4004      value = (fourVector1 + fourVector2).M();
4005    }
4006 +  else if(variable == "chargeProduct"){
4007 +    value = object1->charge*object2->charge;
4008 +  }
4009  
4010 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4010 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4011    value = applyFunction(function, value);
4012    return value;
4013   }
4014  
4015 <
4015 > //!tau-tau pair valueLookup
4016   double
4017 < OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function){
4017 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
4018    double value = 0.0;
4019    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
4020 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
4021    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4022    else if(variable == "invMass"){
4023      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2660 | Line 4025 | OSUAnalysis::valueLookup (const BNtau* o
4025      value = (fourVector1 + fourVector2).M();
4026    }
4027  
4028 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4028 >  else if(variable == "chargeProduct"){
4029 >    value = object1->charge*object2->charge;
4030 >  }
4031 >
4032 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4033    value = applyFunction(function, value);
4034    return value;
4035   }
4036  
4037 <
4037 > //!muon-tau pair valueLookup
4038   double
4039 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function){
4039 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
4040    double value = 0.0;
4041    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
4042 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
4043    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4044    else if(variable == "invMass"){
4045      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2677 | Line 4047 | OSUAnalysis::valueLookup (const BNmuon*
4047      value = (fourVector1 + fourVector2).M();
4048    }
4049  
4050 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4050 >  else if(variable == "chargeProduct"){
4051 >    value = object1->charge*object2->charge;
4052 >  }
4053 >
4054 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4055 >  value = applyFunction(function, value);
4056 >  return value;
4057 > }
4058 >
4059 > //!tau-track pair valueLookup
4060 > double
4061 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
4062 >  double value = 0.0;
4063 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
4064 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4065 >  else if(variable == "deltaRLooseHadronicID") {
4066 >    // only consider tau's that pass the loose hadronic ID criteria; otherwise return very large value (99)  
4067 >    string empty = "";  
4068 >    double isLooseHadronicID = valueLookup(object1, "looseHadronicID", "", empty);    
4069 >  
4070 >    if (isLooseHadronicID) value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4071 >    else                   value = 99.;  
4072 >  }
4073 >  else if(variable == "chargeProduct"){
4074 >    value = object1->charge*object2->charge;
4075 >  }
4076 >
4077 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
4078    value = applyFunction(function, value);
4079    return value;
4080   }
4081  
4082  
4083 + //!track-event pair valueLookup
4084   double
4085 < OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function){
4085 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
4086  
4087    double value = 0.0;
4088    double pMag = sqrt(object1->pt * object1->pt +
4089 <                     object1->pz * object1->pz);  
4089 >                     object1->pz * object1->pz);
4090  
4091    if      (variable == "numPV")                      value = object2->numPV;
4092    else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
4093    else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
4094 <  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);  
4095 <  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;  
4094 >  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
4095 >  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
4096  
4097 <  else { std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4097 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4098  
4099    value = applyFunction(function, value);
4100  
4101    return value;
4102  
4103 < }  
4103 > }
4104 >
4105 > //!electron-trigobj pair valueLookup
4106 > double
4107 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
4108 >
4109 >  double value = 0.0;
4110 >
4111 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4112 >  else if (variable == "match"){
4113 >    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
4114 >      stringValue = object2->filter;
4115 >    else
4116 >      stringValue = "none";
4117 >  }
4118 >
4119 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4120 >
4121 >  value = applyFunction(function, value);
4122 >
4123 >  return value;
4124 >
4125 > }
4126 >
4127 > //!muon-trigobj pair valueLookup
4128 > double
4129 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
4130 >
4131 >  double value = 0.0;
4132 >
4133 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4134 >
4135 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4136 >
4137 >  value = applyFunction(function, value);
4138 >
4139 >  return value;
4140 >
4141 > }
4142 >
4143 > //!stop valueLookup
4144 > double
4145 > OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
4146 >
4147 >
4148 >  double value = 0.0;
4149 >
4150 >  if(variable == "ctau") value = object->ctau;
4151 >
4152 >  else if (variable == "d0"){
4153 >    double vx = object->vx - chosenVertex ()->x,
4154 >      vy = object->vy - chosenVertex ()->y,
4155 >      px = object->px,
4156 >      py = object->py,
4157 >      pt = object->pt;
4158 >    value = (-vx * py + vy * px) / pt;
4159 >  }
4160 >
4161 >  else if (variable == "dz"){
4162 >    double vx = object->vx - chosenVertex ()->x,
4163 >      vy = object->vy - chosenVertex ()->y,
4164 >      vz = object->vz - chosenVertex ()->z,
4165 >      px = object->px,
4166 >      py = object->py,
4167 >      pz = object->pz,
4168 >      pt = object->pt;
4169 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
4170 >  }
4171 >
4172 >  else if (variable == "minD0"){
4173 >    double minD0=999;
4174 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4175 >      double vx = object->vx - vertex->x,
4176 >        vy = object->vy - vertex->y,
4177 >        px = object->px,
4178 >        py = object->py,
4179 >        pt = object->pt;
4180 >      value = (-vx * py + vy * px) / pt;
4181 >      if(abs(value) < abs(minD0)) minD0 = value;
4182 >    }
4183 >    value = minD0;
4184 >  }
4185 >  else if (variable == "minDz"){
4186 >    double minDz=999;
4187 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4188 >      double vx = object->vx - vertex->x,
4189 >        vy = object->vy - vertex->y,
4190 >        vz = object->vz - vertex->z,
4191 >        px = object->px,
4192 >        py = object->py,
4193 >        pz = object->pz,
4194 >        pt = object->pt;
4195 >      value = vz - (vx * px + vy * py)/pt * (pz/pt);
4196 >      if(abs(value) < abs(minDz)) minDz = value;
4197 >    }
4198 >    value = minDz;
4199 >  }
4200 >  else if(variable == "distToVertex"){
4201 >    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4202 >                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4203 >                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4204 >  }
4205 >  else if (variable == "minDistToVertex"){
4206 >    double minDistToVertex=999;
4207 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4208 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4209 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4210 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
4211 >
4212 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4213 >    }
4214 >    value = minDistToVertex;
4215 >  }
4216 >  else if (variable == "distToVertexDifference"){
4217 >    double minDistToVertex=999;
4218 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4219 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4220 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4221 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
4222 >
4223 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4224 >    }
4225 >    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4226 >                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4227 >                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4228 >
4229 >    value = distToChosenVertex - minDistToVertex;
4230 >  }
4231 >
4232 >  else if (variable == "closestVertexRank"){
4233 >    double minDistToVertex=999;
4234 >    int vertex_rank = 0;
4235 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4236 >      vertex_rank++;
4237 >      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4238 >                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
4239 >                      (object->vz-vertex->z)*(object->vz-vertex->z));
4240 >
4241 >      if(abs(dist) < abs(minDistToVertex)){
4242 >        value = vertex_rank;
4243 >        minDistToVertex = dist;
4244 >      }
4245 >    }
4246 >  }
4247 >
4248 >  else if (variable == "decaysToTau"){
4249 >    value = abs (object->daughter0Id) == 15 || abs (object->daughter1Id) == 15;
4250 >  }
4251 >
4252 >
4253 >
4254 >
4255 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4256 >
4257 >  value = applyFunction(function, value);
4258 >
4259 >  return value;
4260 >
4261 > } // end stop valueLookup
4262 >
4263 >
4264 >
4265 >
4266  
4267   // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
4268   // Return true iff no other tracks are found in this cone.
# Line 2717 | Line 4277 | OSUAnalysis::getTrkIsIso (const BNtrack*
4277  
4278   }
4279  
4280 + //calculate the scalar sum of Jet Pt in the event.
4281 + double
4282 + OSUAnalysis::getHt (const BNjetCollection* jetColl){
4283 +  double Ht = 0;
4284 +  for(BNjetCollection::const_iterator jet = jetColl->begin(); jet !=jetColl->end(); jet++){
4285 +    Ht += abs(jet->pt);
4286 +  }
4287 +  return Ht;
4288 + }
4289  
4290   double
4291   OSUAnalysis::getTrkPtRes (const BNtrack* track1){
# Line 2751 | Line 4320 | OSUAnalysis::getTrkPtTrue (const BNtrack
4320  
4321   double
4322   OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
4323 <  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.  
4324 <  if (!useTrackCaloRhoCorr_) return -99;  
4325 <  // if (!rhokt6CaloJetsHandle_) {
4326 <  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;  
4327 <  //   return -99;  
4323 >  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
4324 >  if (!useTrackCaloRhoCorr_) return -99;
4325 >  // if (!rhokt6CaloJetsHandle_) {
4326 >  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
4327 >  //   return -99;
4328    // }
4329 <  double radDeltaRCone = 0.5;  
4330 <  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.  
4331 <  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;  
4332 <  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);  
4333 <  return caloTotRhoCorrCalo;  
4334 <
4329 >  double radDeltaRCone = 0.5;
4330 >  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
4331 >  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
4332 >  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
4333 >  return caloTotRhoCorrCalo;
4334 >
4335 > }
4336 >
4337 > double
4338 > OSUAnalysis::getTrkDepTrkRp5RhoCorr(const BNtrack* track) {
4339 >  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.              
4340 >  if (!useTrackCaloRhoCorr_) return -99;
4341 >  // if (!rhokt6CaloJetsHandle_) {                                                                                                    
4342 >  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;                        
4343 >  //   return -99;                                                                                                                    
4344 >  // }                                                                                                                                
4345 >  double radDeltaRCone = 0.5;
4346 >  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.                                                                                                          
4347 >  double rawDepTrkRp5 = track->depTrkRp5;
4348 > double depTrkRp5RhoCorr = TMath::Max(0., rawDepTrkRp5 - rhoCorr_kt6CaloJets);
4349 > return depTrkRp5RhoCorr;
4350 >
4351 > }
4352 >
4353 > double
4354 > OSUAnalysis::getTrkDepTrkRp3RhoCorr(const BNtrack* track) {
4355 >  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.                                                
4356 >  if (!useTrackCaloRhoCorr_) return -99;
4357 >  // if (!rhokt6CaloJetsHandle_) {                                                                                                                                      
4358 >  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;                                                          
4359 >  //   return -99;                                                                                                                                                      
4360 >  // }                                                                                                                                                                  
4361 >  double radDeltaRCone = 0.3;
4362 > // Define effective area as pi*r^2, where r is radius of DeltaR cone
4363 >  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  
4364 >  double rawDepTrkRp3 = track->depTrkRp3;
4365 >  double depTrkRp3RhoCorr = TMath::Max(0., rawDepTrkRp3 - rhoCorr_kt6CaloJets);
4366 >  return depTrkRp3RhoCorr;
4367 >  
4368   }
4369  
4370  
# Line 2776 | Line 4378 | OSUAnalysis::WriteDeadEcal (){
4378    double etaEcal, phiEcal;
4379    ifstream DeadEcalFile(deadEcalFile_);
4380    if(!DeadEcalFile) {
4381 <    cout << "Error: DeadEcalFile has not been found." << endl;
4381 >    clog << "Error: DeadEcalFile has not been found." << endl;
4382      return;
4383    }
4384    if(DeadEcalVec.size()!= 0){
4385 <    cout << "Error: DeadEcalVec has a nonzero size" << endl;
4385 >    clog << "Error: DeadEcalVec has a nonzero size" << endl;
4386      return;
4387    }
4388    while(!DeadEcalFile.eof())
# Line 2791 | Line 4393 | OSUAnalysis::WriteDeadEcal (){
4393        newChan.phiEcal = phiEcal;
4394        DeadEcalVec.push_back(newChan);
4395      }
4396 <  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
4396 >  if(DeadEcalVec.size() == 0) clog << "Warning: No dead Ecal channels have been found." << endl;
4397   }
4398  
4399   //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
# Line 2800 | Line 4402 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
4402    double deltaRLowest = 999;
4403    int value = 0;
4404    if (DeadEcalVec.size() == 0) WriteDeadEcal();
4405 <  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4405 >  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4406      double eta = ecal->etaEcal;
4407      double phi = ecal->phiEcal;
4408 <    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
4408 >    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
4409      if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
4410    }
4411    if (deltaRLowest<0.05) {value = 1;}
# Line 2811 | Line 4413 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
4413    return value;
4414   }
4415  
4416 < // Returns the smallest DeltaR between the object and any generated true particle in the event.  
4416 > // Returns the smallest DeltaR between the object and any generated true particle in the event.
4417   template <class InputObject>
4418   double OSUAnalysis::getGenDeltaRLowest(InputObject object){
4419    double genDeltaRLowest = 999.;
# Line 2831 | Line 4433 | OSUAnalysis::applyFunction(string functi
4433    else if(function == "log") value = log10(value);
4434  
4435    else if(function == "") value = value;
4436 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
4436 >  else{clog << "WARNING: invalid function '" << function << "'\n";}
4437  
4438    return value;
4439  
# Line 2841 | Line 4443 | OSUAnalysis::applyFunction(string functi
4443   template <class InputCollection>
4444   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
4445  
4446 +  if (verbose_>2) clog << "  Beginning setObjectFlags for cut " << currentCutIndex << ": " << currentCut.name
4447 +                       << ", inputType=" << inputType
4448 +                       << endl;  
4449 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
4450 +    string obj1, obj2;
4451 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
4452 +    if (verbose_>2) clog << "  Two object types:  " << obj1 << ", " << obj2 << endl;
4453 +    if (inputType==obj1 ||
4454 +        inputType==obj2) {
4455 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
4456 +      // and the inputType is a member of the pair.
4457 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
4458 +      // For example, if currentCut.inputCollection==electron-muon pairs,
4459 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
4460 +      return;
4461 +    }
4462 +  }
4463  
4464 <  for (uint object = 0; object != inputCollection->size(); object++){
4464 >  if (!inputCollection) cout << "ERROR:  invalid input collection for inputType=" << inputType << endl;  
4465 >
4466 >  if (verbose_>3) clog << "   Collection size:  " << inputCollection->size() << endl;
4467  
4468 +  for (uint object = 0; object != inputCollection->size(); object++){
4469  
4470 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
4470 >    if (verbose_>4) clog << "    Setting flags for object " << object << endl;
4471  
4472 +    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4473 +    bool plotDecision = true;
4474  
4475      if(currentCut.inputCollection == inputType){
4476  
4477        vector<bool> subcutDecisions;
4478        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4479 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4480 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4479 >        string stringValue = "";
4480 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4481 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4482 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4483 >
4484        }
4485 <      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4485 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4486        else{
4487          bool tempDecision = true;
4488          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
# Line 2864 | Line 4491 | void OSUAnalysis::setObjectFlags(cut &cu
4491            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4492              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4493          }
4494 <        decision = tempDecision;
4494 >        cutDecision = tempDecision;
4495        }
4496 +      //invert the cut if this cut is a veto
4497 +      if(currentCut.isVeto) cutDecision = !cutDecision;
4498 +      plotDecision = cutDecision;
4499      }
2870    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4500  
4501 +    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4502  
4503 <    //set flags for objects that pass each cut AND all the previous cuts
4504 <    bool previousCumulativeFlag = true;
4503 >    //set flags for objects that pass this cut AND all the previous cuts
4504 >    bool previousCumulativeCutFlag = true;
4505 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4506 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4507 >      else{ previousCumulativeCutFlag = false; break;}
4508 >    }
4509 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4510 >    bool previousCumulativePlotFlag = true;
4511      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4512 <      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4513 <      else{ previousCumulativeFlag = false; break;}
4512 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4513 >      else{ previousCumulativePlotFlag = false; break;}
4514      }
4515 <    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4515 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4516  
4517 +    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4518  
4519 <  }
4519 >  }  //   for (uint object = 0; object != inputCollection->size(); object++){
4520  
4521 < }
4521 > } // end void OSUAnalysis::setObjectFlags
4522  
4523  
4524   template <class InputCollection1, class InputCollection2>
4525 < void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
4526 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
4527 <
4525 > void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags,
4526 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, string inputType){
4527 >  // This function sets the flags for the paired object collection.  
4528 >  // If the cut is applying on the given paired object collection, then the flags for the single object collections are also set.
4529 >  // If not, then the flags for the paired object collection are taken as the AND of the flags for each single object collection.  
4530 >
4531 >  if (verbose_>2) clog << "  Beginning setObjectFlags for cut=" << currentCut.name
4532 >                       << ", inputType=" << inputType
4533 >                       << endl;  
4534  
4535    bool sameObjects = false;
4536 <  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4536 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;  // FIXME:  is sameObjects just the not of isTwoTypesOfObject?  If so, it's redundant.  
4537  
4538 +  // Get the strings for the two objects that make up the pair.
4539 +  string obj1Type, obj2Type;
4540 +  getTwoObjs(inputType, obj1Type, obj2Type);
4541 +  bool isTwoTypesOfObject = true;
4542 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
4543 +
4544 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
4545 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4546 +  if (currentCut.inputCollection == inputType) {
4547 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4548 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4549 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4550 +    }
4551 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4552 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4553 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4554 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4555 +      }
4556 +    }
4557 +  }
4558  
4559    int counter = 0;
4560 +
4561    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4562      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4563  
4564        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4565  
4566  
4567 <      bool decision = true;//object passes if this cut doesn't cut on that type of object
4567 >      bool cutDecision  = true;//object passes if this cut doesn't cut on that type of object
4568 >      bool plotDecision = true;
4569  
4570 +      // Determine whether each pair passes the cut, only if inputCollection is the same as the inputType.  
4571        if(currentCut.inputCollection == inputType){
4572  
4573          vector<bool> subcutDecisions;
4574          for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4575 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4576 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4575 >          string stringValue = "";
4576 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4577 >          if (verbose_>1) clog << currentCut.variables.at(subcutIndex) << " = " << value
4578 >                               << endl;  
4579 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4580 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4581          }
4582  
4583 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4583 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4584          else{
4585            bool tempDecision = subcutDecisions.at(0);
4586            for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
# Line 2919 | Line 4589 | void OSUAnalysis::setObjectFlags(cut &cu
4589              else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4590                tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4591            }
4592 <          decision = tempDecision;
4592 >          cutDecision = tempDecision;
4593          }
4594 +        //invert the cut if this cut is a veto
4595 +        if (currentCut.isVeto) cutDecision = !cutDecision;
4596 +        plotDecision = cutDecision;
4597 +
4598 +        if (verbose_>1) clog << " cutDecision = " << cutDecision
4599 +                             << "; for currentCut.inputCollection = " << currentCut.inputCollection
4600 +                             << "; object1 (" << obj1Type << ") = " << object1
4601 +                             << "; object2 (" << obj2Type << ") = " << object2
4602 +                             << endl;  
4603 +        
4604 +        if (cutDecision) {  // only set the flags for the individual objects if the pair object is being cut on
4605 +          individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4606 +          individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4607 +        }
4608 +        if (plotDecision) {  // only set the flags for the individual objects if the pair object is being cut on
4609 +          individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4610 +          individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4611 +        }
4612 +        
4613 +
4614 +      } // if(currentCut.inputCollection == inputType){
4615 +
4616 +      // The individualFlags will be true if the inputCollection is not the same as the inputType.
4617 +      // They are also independent of the previous flags on the single objects.  
4618 +      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));  
4619 +
4620 +
4621 +
4622 +      // ************************************
4623 +      // Determine cumulative flags
4624 +      // ************************************
4625 +      // determine whether this paired object passes this cut AND all previous cuts
4626 +      bool previousCumulativeCutFlag = true;
4627 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4628 +        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4629 +        else{ previousCumulativeCutFlag = false; break;}
4630        }
4631 <      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4631 >      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4632  
4633 <      //set flags for objects that pass each cut AND all the previous cuts
2928 <      bool previousCumulativeFlag = true;
4633 >      bool previousCumulativePlotFlag = true;
4634        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4635 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
4636 <        else{ previousCumulativeFlag = false; break;}
4635 >        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4636 >        else{ previousCumulativePlotFlag = false; break;}
4637 >      }
4638 >      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4639 >      
4640 >      // 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.    
4641 >      int cutIdxFlagsObj1 = max(int(currentCutIndex-1),0);
4642 >      int cutIdxFlagsObj2 = max(int(currentCutIndex-1),0);
4643 >      // 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.
4644 >      // 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.  
4645 >      // 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).  
4646 >      if (currentCut.inputCollection != inputType) {  
4647 >        if (currentCut.inputCollection.find(obj1Type)!=string::npos) cutIdxFlagsObj1 = currentCutIndex;
4648 >        if (currentCut.inputCollection.find(obj2Type)!=string::npos) cutIdxFlagsObj2 = currentCutIndex;
4649 >      }  
4650 >      flagPair flags1 = cumulativeFlags.at(obj1Type).at(cutIdxFlagsObj1);  // flag for input collection 1
4651 >      flagPair flags2 = cumulativeFlags.at(obj2Type).at(cutIdxFlagsObj2);  // flag for input collection 2
4652 >      
4653 >      // The cumulative flag is only true if the paired object cumulative flag is true, and if the single object cumulative flags are true.  
4654 >      bool currentCumulativeCutFlag = true;
4655 >      bool currentCumulativePlotFlag = true;
4656 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4657 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4658 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4659 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4660 >
4661 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4662 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4663 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4664 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4665 >
4666 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));  // Set the flag for the paired object
4667 >
4668 >
4669 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // Set the flags for the individual objects if the paired object is being cut on.  
4670 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first  = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4671 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first  = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4672 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4673 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4674 >
4675 >        if (verbose_>1) clog << " previousCumulativeCutFlag for object1 = " << getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object1, "cut") << endl;  
4676 >        if (verbose_>1) clog << " previousCumulativeCutFlag for object2 = " << getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut") << endl;  
4677 >
4678        }
2933      //apply flags for the components of the composite object as well
2934      bool currentCumulativeFlag = true;
2935      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
2936      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
2937      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
2938      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
2939      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
4679  
4680        counter++;
2942    }
4681  
4682 +    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4683 +  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4684 +
4685 + } // end void OSUAnalysis::setObjectFlags
4686 +
4687 +
4688 + bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4689 +  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4690 +  // all cuts up to currentCutIndex
4691 +  bool previousCumulativeFlag = true;
4692 +  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4693 +    bool tempFlag = false;
4694 +    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4695 +    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4696 +
4697 +    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4698 +    else {
4699 +      previousCumulativeFlag = false; break;
4700 +    }
4701    }
4702 +  return previousCumulativeFlag;
4703 + }
4704 +
4705  
4706  
4707 +
4708 + template <class InputCollection>
4709 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4710 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4711 +
4712 +  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;
4713 +  for (uint object = 0; object != inputCollection->size(); object++) {
4714 +
4715 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4716 +
4717 +    string inputVariable = parameters.inputVariable;
4718 +    string function = "";
4719 +    string stringValue = "";
4720 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4721 +    BNTreeBranchVals_.at(parameters.name).push_back(value);
4722 +
4723 +  }
4724   }
4725  
4726  
4727   template <class InputCollection>
4728 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4728 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4729 >
4730 >  if (verbose_>2) clog << "  Filling histogram for " << parameters.name << endl;  
4731  
4732    for (uint object = 0; object != inputCollection->size(); object++){
4733  
4734 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4734 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4735  
4736      string currentString = parameters.inputVariables.at(0);
4737      string inputVariable = "";
4738      string function = "";
4739 <    if(currentString.find("(")==std::string::npos){
4739 >    if(currentString.find("(")==string::npos){
4740        inputVariable = currentString;// variable to cut on
4741      }
4742      else{
# Line 2966 | Line 4745 | void OSUAnalysis::fill1DHistogram(TH1* h
4745        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4746      }
4747  
4748 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
4748 >    string stringValue = "";
4749 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4750      histo->Fill(value,scaleFactor);
4751  
4752      if (printEventInfo_) {
4753 <      // Write information about event to screen, for testing purposes.  
4754 <      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;  
4753 >      // Write information about event to screen, for testing purposes.
4754 >      clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << " (object number " << object << ")" << endl;
4755      }
4756 <    
4756 >
4757    }
4758   }
4759  
4760   template <class InputCollection1, class InputCollection2>
4761 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4761 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2,
4762 >                                  flagPair pairFlags, double scaleFactor){
4763  
4764    bool sameObjects = false;
4765    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4766  
4767 <  int pairCounter = 0;
4767 >  int pairCounter = -1;
4768    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4769      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4770  
4771        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4772  
4773 <      //only take objects which have passed all cuts and pairs which have passed all cuts
4774 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
2994 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
2995 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4773 >      pairCounter++;
4774 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4775  
4776        string currentString = parameters.inputVariables.at(0);
4777        string inputVariable = "";
4778        string function = "";
4779 <      if(currentString.find("(")==std::string::npos){
4779 >      if(currentString.find("(")==string::npos){
4780          inputVariable = currentString;// variable to cut on
4781        }
4782        else{
# Line 3006 | Line 4785 | void OSUAnalysis::fill1DHistogram(TH1* h
4785          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4786        }
4787  
4788 <      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4788 >      string stringValue = "";
4789 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4790        histo->Fill(value,scaleFactor);
4791  
4792 <      pairCounter++;
4792 >      if (printEventInfo_) {
4793 >        // Write information about event to screen, for testing purposes.
4794 >        clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value
4795 >             << " (object1 number " << object1 << "), "
4796 >             << " (object2 number " << object2 << ")"
4797 >             << endl;
4798 >      }
4799 >      
4800      }
4801    }
4802  
# Line 3017 | Line 4804 | void OSUAnalysis::fill1DHistogram(TH1* h
4804  
4805  
4806   template <class InputCollection>
4807 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4807 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4808  
4809    for (uint object = 0; object != inputCollection->size(); object++){
4810  
4811 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4811 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4812  
4813 +    string stringValue = "";
4814      string currentString = parameters.inputVariables.at(0);
4815      string inputVariable = "";
4816      string function = "";
4817 <    if(currentString.find("(")==std::string::npos){
4817 >    if(currentString.find("(")==string::npos){
4818        inputVariable = currentString;// variable to cut on
4819      }
4820      else{
# Line 3034 | Line 4822 | void OSUAnalysis::fill2DHistogram(TH2* h
4822        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4823        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4824      }
4825 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
4825 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4826  
4827      currentString = parameters.inputVariables.at(1);
4828      inputVariable = "";
4829      function = "";
4830 <    if(currentString.find("(")==std::string::npos){
4830 >    if(currentString.find("(")==string::npos){
4831        inputVariable = currentString;// variable to cut on
4832      }
4833      else{
# Line 3048 | Line 4836 | void OSUAnalysis::fill2DHistogram(TH2* h
4836        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4837      }
4838  
4839 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
4839 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4840  
4841      histo->Fill(valueX,valueY,scaleFactor);
4842  
# Line 3057 | Line 4845 | void OSUAnalysis::fill2DHistogram(TH2* h
4845   }
4846  
4847   template <class InputCollection1, class InputCollection2>
4848 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4848 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2,
4849 >                                  flagPair pairFlags, double scaleFactor){
4850  
4851    bool sameObjects = false;
4852    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4853  
4854 <  int pairCounter = 0;
4854 >  int pairCounter = -1;
4855    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4856      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4857  
4858        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4859  
4860 <      //only take objects which have passed all cuts and pairs which have passed all cuts
4861 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4862 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3074 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4860 >      pairCounter++;
4861 >
4862 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4863  
4864 +      string stringValue = "";
4865        string currentString = parameters.inputVariables.at(0);
4866        string inputVariable = "";
4867        string function = "";
4868 <      if(currentString.find("(")==std::string::npos){
4868 >      if(currentString.find("(")==string::npos){
4869          inputVariable = currentString;// variable to cut on
4870        }
4871        else{
# Line 3084 | Line 4873 | void OSUAnalysis::fill2DHistogram(TH2* h
4873          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4874          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4875        }
4876 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4876 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4877  
4878        currentString = parameters.inputVariables.at(1);
4879        inputVariable = "";
4880        function = "";
4881 <      if(currentString.find("(")==std::string::npos){
4881 >      if(currentString.find("(")==string::npos){
4882          inputVariable = currentString;// variable to cut on
4883        }
4884        else{
# Line 3097 | Line 4886 | void OSUAnalysis::fill2DHistogram(TH2* h
4886          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4887          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4888        }
4889 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4889 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4890  
4891  
4892        histo->Fill(valueX,valueY,scaleFactor);
4893  
3105      pairCounter++;
3106
4894      }
4895    }
4896  
# Line 3120 | Line 4907 | int OSUAnalysis::getGenMatchedParticleIn
4907  
4908      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4909      if(currentDeltaR > 0.05) continue;
4910 <    //     cout << std::setprecision(3) << std::setw(20)
4910 >    //     clog << setprecision(3) << setw(20)
4911      //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4912 <    //          << std::setw(20)
4912 >    //          << setw(20)
4913      //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4914 <    //          << std::setw(20)
4914 >    //          << setw(20)
4915      //          << "\tdeltaR = " << currentDeltaR
4916 <    //          << std::setprecision(1)
4917 <    //          << std::setw(20)
4916 >    //          << setprecision(1)
4917 >    //          << setw(20)
4918      //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4919 <    //          << std::setw(20)
4919 >    //          << setw(20)
4920      //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4921 <    //          << std::setw(20)
4921 >    //          << setw(20)
4922      //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4923      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4924        bestMatchIndex = mcparticle - mcparticles->begin();
# Line 3139 | Line 4926 | int OSUAnalysis::getGenMatchedParticleIn
4926      }
4927  
4928    }
4929 <  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4930 <  //   else cout << "no match found..." << endl;
4929 >  //   if(bestMatchDeltaR != 999)  clog << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4930 >  //   else clog << "no match found..." << endl;
4931    return bestMatchIndex;
4932  
4933   }
# Line 3194 | Line 4981 | int OSUAnalysis::findTauMotherIndex(cons
4981   // 20        strange baryon
4982   // 21        charm baryon
4983   // 22        bottom baryon
4984 < // 23        other
4984 > // 23        QCD string
4985 > // 24        other
4986  
4987   int OSUAnalysis::getPdgIdBinValue(int pdgId){
4988  
# Line 3218 | Line 5006 | int OSUAnalysis::getPdgIdBinValue(int pd
5006    else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
5007    else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
5008    else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
5009 +  else if(absPdgId == 92  ) binValue = 23;
5010  
5011 <  else binValue = 23;
5011 >  else binValue = 24;
5012  
5013    return binValue;
5014  
# Line 3229 | Line 5018 | const BNprimaryvertex *
5018   OSUAnalysis::chosenVertex ()
5019   {
5020    const BNprimaryvertex *chosenVertex = 0;
5021 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
5022 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
5023 <      cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
5021 >  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
5022 >    flagPair vertexFlags;
5023 >    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
5024 >      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
5025 >        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
5026 >        break;
5027 >      }
5028 >    }
5029      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
5030 <      if(!vertexFlags.at(vertexIndex)) continue;
5030 >      if(!vertexFlags.at(vertexIndex).first) continue;
5031        chosenVertex = & primaryvertexs->at(vertexIndex);
5032        break;
5033      }
5034    }
5035 <  else {
5036 <    chosenVertex = &primaryvertexs->at(0);
3243 <  }
5035 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
5036 >    chosenVertex = & primaryvertexs->at (0);
5037  
5038    return chosenVertex;
5039   }
# Line 3249 | Line 5042 | const BNmet *
5042   OSUAnalysis::chosenMET ()
5043   {
5044    const BNmet *chosenMET = 0;
5045 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
5046 <    vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
5047 <      cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
5045 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
5046 >    flagPair metFlags;
5047 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
5048 >      if (cumulativeFlags.at("mets").at(i).size()){
5049 >        metFlags = cumulativeFlags.at("mets").at(i);
5050 >        break;
5051 >      }
5052 >    }
5053      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
5054 <      if(!metFlags.at(metIndex)) continue;
5054 >      if(!metFlags.at(metIndex).first) continue;
5055        chosenMET = & mets->at(metIndex);
5056        break;
5057      }
5058    }
5059 <  else {
5060 <    chosenMET = &mets->at(0);
3263 <  }
5059 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
5060 >    chosenMET = & mets->at (0);
5061  
5062    return chosenMET;
5063   }
# Line 3269 | Line 5066 | const BNelectron *
5066   OSUAnalysis::chosenElectron ()
5067   {
5068    const BNelectron *chosenElectron = 0;
5069 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
5070 <    vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
5071 <      cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
5069 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
5070 >    flagPair electronFlags;
5071 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
5072 >      if (cumulativeFlags.at("electrons").at(i).size()){
5073 >        electronFlags = cumulativeFlags.at("electrons").at(i);
5074 >        break;
5075 >      }
5076 >    }
5077      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
5078 <      if(!electronFlags.at(electronIndex)) continue;
5078 >      if(!electronFlags.at(electronIndex).first) continue;
5079        chosenElectron = & electrons->at(electronIndex);
5080        break;
5081      }
5082    }
5083 <  else {
5084 <    chosenElectron = &electrons->at(0);
3283 <  }
5083 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
5084 >    chosenElectron = & electrons->at (0);
5085  
5086    return chosenElectron;
5087   }
5088  
5089 +
5090   const BNmuon *
5091   OSUAnalysis::chosenMuon ()
5092   {
5093    const BNmuon *chosenMuon = 0;
5094 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
5095 <    vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
5096 <      cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
5094 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
5095 >    flagPair muonFlags;
5096 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
5097 >      if (cumulativeFlags.at("muons").at(i).size()){
5098 >        muonFlags = cumulativeFlags.at("muons").at(i);
5099 >        break;
5100 >      }
5101 >    }
5102      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
5103 <      if(!muonFlags.at(muonIndex)) continue;
5103 >      if(!muonFlags.at(muonIndex).first) continue;
5104        chosenMuon = & muons->at(muonIndex);
5105        break;
5106      }
5107    }
5108 <  else {
5109 <    chosenMuon = &muons->at(0);
3303 <  }
5108 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
5109 >    chosenMuon = & muons->at (0);
5110  
5111    return chosenMuon;
5112   }
5113  
5114 + double
5115 + OSUAnalysis::chosenHT ()
5116 + {
5117 +  double chosenHT = 0.0;
5118 +  if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
5119 +    flagPair jetFlags;
5120 +    for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
5121 +      if (cumulativeFlags.at("jets").at(i).size()){
5122 +        jetFlags = cumulativeFlags.at("jets").at(i);
5123 +        break;
5124 +      }
5125 +    }
5126 +    for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
5127 +      if(!jetFlags.at(jetIndex).first) continue;
5128 +      chosenHT += jets->at(jetIndex).pt;
5129 +    }
5130 +  }
5131 +
5132 +  return chosenHT;
5133 + }
5134 +
5135 + pair<const BNmuon *, const BNmuon *>
5136 + OSUAnalysis::leadMuonPair ()
5137 + {
5138 +  pair<const BNmuon *, const BNmuon *> leadMuonPair;
5139 +  leadMuonPair.first = leadMuonPair.second = 0;
5140 +
5141 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
5142 +    flagPair muonFlags;
5143 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
5144 +      if (cumulativeFlags.at("muons").at(i).size()){
5145 +        muonFlags = cumulativeFlags.at("muons").at(i);
5146 +        break;
5147 +      }
5148 +    }
5149 +    for (uint muonIndex0 = 0; muonIndex0 != muonFlags.size(); muonIndex0++){
5150 +      if(!muonFlags.at(muonIndex0).first) continue;
5151 +      for (uint muonIndex1 = muonIndex0 + 1; muonIndex1 < muonFlags.size(); muonIndex1++){
5152 +        if(!muonFlags.at(muonIndex1).first) continue;
5153 +        const BNmuon *mu0 = & muons->at(muonIndex0);
5154 +        const BNmuon *mu1 = & muons->at(muonIndex1);
5155 +        if(leadMuonPair.first == 0 || leadMuonPair.second == 0){
5156 +          leadMuonPair.first = mu0;
5157 +          leadMuonPair.second = mu1;
5158 +        }
5159 +        else{
5160 +          TVector2 newPt0 (mu0->px, mu0->py),
5161 +                   newPt1 (mu1->px, mu1->py),
5162 +                   oldPt0 (leadMuonPair.first->px, leadMuonPair.first->py),
5163 +                   oldPt1 (leadMuonPair.second->px, leadMuonPair.second->py);
5164 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
5165 +            {
5166 +              leadMuonPair.first = mu0;
5167 +              leadMuonPair.second = mu1;
5168 +            }
5169 +        }
5170 +      }
5171 +    }
5172 +  }
5173 +
5174 +  return leadMuonPair;
5175 + }
5176 +
5177 + pair<const BNelectron *, const BNelectron *>
5178 + OSUAnalysis::leadElectronPair ()
5179 + {
5180 +  pair<const BNelectron *, const BNelectron *> leadElectronPair;
5181 +  leadElectronPair.first = leadElectronPair.second = 0;
5182 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
5183 +    flagPair electronFlags;
5184 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
5185 +      if (cumulativeFlags.at("electrons").at(i).size()){
5186 +        electronFlags = cumulativeFlags.at("electrons").at(i);
5187 +        break;
5188 +      }
5189 +    }
5190 +    for (uint electronIndex0 = 0; electronIndex0 != electronFlags.size(); electronIndex0++){
5191 +      if(!electronFlags.at(electronIndex0).first) continue;
5192 +      for (uint electronIndex1 = electronIndex0 + 1; electronIndex1 < electronFlags.size(); electronIndex1++){
5193 +        if(!electronFlags.at(electronIndex1).first) continue;
5194 +        const BNelectron *el0 = & electrons->at(electronIndex0);
5195 +        const BNelectron *el1 = & electrons->at(electronIndex1);
5196 +        if(leadElectronPair.first == 0 || leadElectronPair.second == 0){
5197 +          leadElectronPair.first = el0;
5198 +          leadElectronPair.second = el1;
5199 +        }
5200 +        else{
5201 +          TVector2 newPt0 (el0->px, el0->py),
5202 +                   newPt1 (el1->px, el1->py),
5203 +                   oldPt0 (leadElectronPair.first->px, leadElectronPair.first->py),
5204 +                   oldPt1 (leadElectronPair.second->px, leadElectronPair.second->py);
5205 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
5206 +            {
5207 +              leadElectronPair.first = el0;
5208 +              leadElectronPair.second = el1;
5209 +            }
5210 +        }
5211 +      }
5212 +    }
5213 +  }
5214 +
5215 +  return leadElectronPair;
5216 + }
5217  
5218   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines