ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
(Generate patch)

Comparing UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc (file contents):
Revision 1.28 by jbrinson, Thu Mar 14 10:06:38 2013 UTC vs.
Revision 1.112 by wulsin, Thu Jul 25 12:28:54 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")),
# Line 11 | Line 10 | OSUAnalysis::OSUAnalysis (const edm::Par
10    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
11    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
12    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
13 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
14    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
15    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
16    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
17    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
18    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
19 <  puFile_ (cfg.getParameter<std::string> ("puFile")),
20 <  deadEcalFile_ (cfg.getParameter<std::string> ("deadEcalFile")),
21 <  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
22 <  dataset_ (cfg.getParameter<std::string> ("dataset")),
23 <  datasetType_ (cfg.getParameter<std::string> ("datasetType")),
19 >  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
20 >  puFile_ (cfg.getParameter<string> ("puFile")),
21 >  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
22 >  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
23 >  dataPU_ (cfg.getParameter<string> ("dataPU")),
24 >  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
25 >  muonSF_ (cfg.getParameter<string> ("muonSF")),
26 >  dataset_ (cfg.getParameter<string> ("dataset")),
27 >  datasetType_ (cfg.getParameter<string> ("datasetType")),
28    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
29    histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
30 <  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents"))
30 >  useEDMFormat_   (cfg.getParameter<bool>("useEDMFormat")),
31 >  treeBranchSets_   (cfg.getParameter<vector<edm::ParameterSet> >("treeBranchSets")),
32 >  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
33 >  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
34 >  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
35 >  applyBtagSF_ (cfg.getParameter<bool> ("applyBtagSF")),
36 >  minBtag_ (cfg.getParameter<int> ("minBtag")),
37 >  printEventInfo_      (cfg.getParameter<bool> ("printEventInfo")),
38 >  printAllTriggers_    (cfg.getParameter<bool> ("printAllTriggers")),
39 >  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
40 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
41 >  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut")),
42 >  verbose_ (cfg.getParameter<int> ("verbose"))
43 > {
44  
45 < {
45 >  if (verbose_) printEventInfo_ = true;  
46 >  if (verbose_) clog << "Beginning OSUAnalysis::OSUAnalysis constructor." << endl;  
47  
48 <  TH1::SetDefaultSumw2 ();
48 >  TH1::SetDefaultSumw2();
49  
50    //create pile-up reweighting object, if necessary
51 <  //  if(datasetType_ != "data") puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
51 >  if(datasetType_ != "data") {
52 >    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
53 >    if (applyLeptonSF_){
54 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
55 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
56 >    }
57 >    if (applyBtagSF_){
58 >      bTagSFWeight_ = new BtagSFWeight;
59 >    }
60 >  }
61 >  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
62 >    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at(0), stopCTau_.at(1), stops_);
63 >
64  
65    // Construct Cutflow Objects. These store the results of cut decisions and
66    // handle filling cut flow histograms.
67    masterCutFlow_ = new CutFlow (fs_);
38  std::vector<TFileDirectory> directories;
68  
69    //always get vertex collection so we can assign the primary vertex in the event
70 <  
42 < objectsToGet.push_back("primaryvertexs");
43 <  //always make the plot of number of primary verticex (to check pile-up reweighting)
70 >  objectsToGet.push_back("primaryvertexs");
71    objectsToPlot.push_back("primaryvertexs");
72 +  objectsToFlag.push_back("primaryvertexs");
73 +
74  
75    //always get the MC particles to do GEN-matching
76    objectsToGet.push_back("mcparticles");
# Line 49 | Line 78 | objectsToGet.push_back("primaryvertexs")
78    //always get the event collection to do pile-up reweighting
79    objectsToGet.push_back("events");
80  
81 +
82 +  // Parse the tree variable definitions.
83 +  for (uint iBranchSet = 0; !useEDMFormat_ && iBranchSet<treeBranchSets_.size(); iBranchSet++) {
84 +    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
85 +    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; }
86 +    objectsToGet.push_back(tempInputCollection);
87 +    objectsToFlag.push_back(tempInputCollection);
88 +
89 +    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
90 +
91 +    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
92 +      BranchSpecs br;
93 +      br.inputCollection = tempInputCollection;
94 +      br.inputVariable = branchList.at(iBranch);
95 +      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);
96 +      br.name = string(newName.Data());
97 +      treeBranches_.push_back(br);
98 +      if (verbose_>3) clog << "   Adding branch to BNTree: " << br.name << endl;  
99 +    }
100 +
101 +  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++)
102 +
103 +
104    //parse the histogram definitions
105    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
106  
107      string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
108      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
109 <    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
110 <      objectsToGet.push_back(tempInputCollection);
109 >    if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
110 >    if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
111 >    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
112 >    if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
113 >    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
114 >    if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
115 >    if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
116 >    if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
117 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
118 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
119 >    if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
120 >    if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
121 >    if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
122 >    if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
123 >    if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
124 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
125 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
126 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
127 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
128 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
129 >        int spaceIndex = tempInputCollection.find(" ");
130 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
131 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
132 >      }
133 >      else{
134 >        objectsToGet.push_back(tempInputCollection);
135 >      }
136        objectsToPlot.push_back(tempInputCollection);
137 <      objectsToCut.push_back(tempInputCollection);
138 <    }
139 <    else{//pair of objects, need to add them both to the things to objectsToGet
140 <      int dashIndex = tempInputCollection.find("-");
141 <      int spaceIndex = tempInputCollection.find(" ");
142 <      int secondWordLength = spaceIndex - dashIndex;
143 <      objectsToGet.push_back(tempInputCollection);
144 <      objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
145 <      objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
137 >      objectsToFlag.push_back(tempInputCollection);
138 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
139 >      string obj1;
140 >      string obj2;
141 >      getTwoObjs(tempInputCollection, obj1, obj2);
142 >      string obj2ToGet = getObjToGet(obj2);
143 >      objectsToFlag.push_back(tempInputCollection);
144 >      objectsToFlag.push_back(obj1);
145 >      objectsToFlag.push_back(obj2);
146        objectsToPlot.push_back(tempInputCollection);
147 <      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
148 <      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
149 <      objectsToCut.push_back(tempInputCollection);
150 <      objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
151 <      objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
152 <
153 <      }
154 <
78 <    vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
147 >      objectsToPlot.push_back(obj1);
148 >      objectsToPlot.push_back(obj2);
149 >      objectsToGet.push_back(tempInputCollection);
150 >      objectsToGet.push_back(obj1);
151 >      objectsToGet.push_back(obj2ToGet);
152 >    } // end else
153 >    if (find(objectsToPlot.begin(), objectsToPlot.end(), "events") != objectsToPlot.end())
154 >      objectsToGet.push_back("jets");
155      
156 +    
157 +    vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
158 +
159      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
160  
161 +      vector<double> defaultValue;
162 +      defaultValue.push_back (-1.0);
163 +
164        histogram tempHistogram;
165        tempHistogram.inputCollection = tempInputCollection;
166        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
167        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
168 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
168 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
169 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
170 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
171        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
172 <      
172 >
173        histograms.push_back(tempHistogram);
174  
175      }
176 <  }
176 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
177 >
178    //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
179    sort( objectsToPlot.begin(), objectsToPlot.end() );
180    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
# Line 100 | Line 185 | objectsToGet.push_back("primaryvertexs")
185    for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
186  
187      string currentObject = objectsToPlot.at(currentObjectIndex);
188 <    if(currentObject != "muons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
188 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "secondary photons"&& currentObject != "superclusters") continue;
189  
190      histogram tempIdHisto;
191      histogram tempMomIdHisto;
192      histogram tempGmaIdHisto;
193 +    histogram tempIdVsMomIdHisto;
194 +    histogram tempIdVsGmaIdHisto;
195  
196      tempIdHisto.inputCollection = currentObject;
197      tempMomIdHisto.inputCollection = currentObject;
198      tempGmaIdHisto.inputCollection = currentObject;
199 +    tempIdVsMomIdHisto.inputCollection = currentObject;
200 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
201 +
202 +    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
203 +    if(currentObject == "secondary photons") currentObject = "secondaryPhotons";
204 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
205  
206      currentObject = currentObject.substr(0, currentObject.size()-1);
207      tempIdHisto.name = currentObject+"GenMatchId";
208      tempMomIdHisto.name = currentObject+"GenMatchMotherId";
209      tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
210 +    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
211 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
212  
213      currentObject.at(0) = toupper(currentObject.at(0));
214      tempIdHisto.title = currentObject+" Gen-matched Particle";
215      tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
216      tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
217 +    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
218 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
219 +
220  
221 <    int maxNum = 24;
221 >    int maxNum = 25;
222      vector<double> binVector;
223      binVector.push_back(maxNum);
224      binVector.push_back(0);
# Line 132 | Line 230 | objectsToGet.push_back("primaryvertexs")
230      tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
231      tempGmaIdHisto.bins = binVector;
232      tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
233 +    binVector.push_back(maxNum);
234 +    binVector.push_back(0);
235 +    binVector.push_back(maxNum);
236 +    tempIdVsMomIdHisto.bins = binVector;
237 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
238 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
239 +    tempIdVsGmaIdHisto.bins = binVector;
240 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
241 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
242  
243      histograms.push_back(tempIdHisto);
244      histograms.push_back(tempMomIdHisto);
245      histograms.push_back(tempGmaIdHisto);
246 <    
246 >    histograms.push_back(tempIdVsMomIdHisto);
247 >    histograms.push_back(tempIdVsGmaIdHisto);
248    }
249  
250  
143
251    channel tempChannel;
252    //loop over all channels (event selections)
253    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
# Line 149 | Line 256 | objectsToGet.push_back("primaryvertexs")
256      string channelName  (channels_.at(currentChannel).getParameter<string>("name"));
257      tempChannel.name = channelName;
258      TString channelLabel = channelName;
259 +    if (verbose_) clog << "Processing channel:  " << channelName << endl;  
260  
261      //set triggers for this channel
262      vector<string> triggerNames;
263      triggerNames.clear();
264 +    vector<string> triggerToVetoNames;
265 +    triggerToVetoNames.clear();
266 +
267      tempChannel.triggers.clear();
268 +    tempChannel.triggersToVeto.clear();
269      if(channels_.at(currentChannel).exists("triggers")){
270        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
271        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
272          tempChannel.triggers.push_back(triggerNames.at(trigger));
273        objectsToGet.push_back("triggers");
274      }
275 <
275 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
276 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
277 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
278 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
279 >      objectsToGet.push_back("triggers");
280 >    }
281  
282  
283  
284      //create cutFlow for this channel
285      cutFlows_.push_back (new CutFlow (fs_, channelName));
286 <
287 <    //book a directory in the output file with the name of the channel
288 <    TFileDirectory subDir = fs_->mkdir( channelName );
172 <    directories.push_back(subDir);
173 <
174 <    std::map<std::string, TH1D*> oneDhistoMap;
175 <    oneDHists_.push_back(oneDhistoMap);
176 <    std::map<std::string, TH2D*> twoDhistoMap;
177 <    twoDHists_.push_back(twoDhistoMap);
178 <
179 <
180 <    //book all histograms included in the configuration
181 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
182 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
183 <      int numBinsElements = currentHistogram.bins.size();
184 <      int numInputVariables = currentHistogram.inputVariables.size();
185 <
186 <      if(numBinsElements != 3 && numBinsElements !=6) {
187 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
188 <        exit(0);
189 <      }
190 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
191 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
192 <        exit(0);
193 <      }
194 <      else if(numBinsElements == 3){
195 <        oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
196 <      }
197 <      else if(numBinsElements == 6){
198 <        twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2),currentHistogram.bins.at(3),currentHistogram.bins.at(4),currentHistogram.bins.at(5));
199 <
200 <      }
201 <
202 <
203 <      if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
204 <
205 < // bin      particle type
206 < // ---      -------------
207 < //  0        unmatched
208 < //  1        u
209 < //  2        d
210 < //  3        s
211 < //  4        c
212 < //  5        b
213 < //  6        t
214 < //  7        e
215 < //  8        mu
216 < //  9        tau
217 < // 10        nu
218 < // 11        g
219 < // 12        gamma
220 < // 13        Z
221 < // 14        W
222 < // 15        light meson
223 < // 16        K meson
224 < // 17        D meson
225 < // 18        B meson
226 < // 19        light baryon
227 < // 20        strange baryon
228 < // 21        charm baryon
229 < // 22        bottom baryon
230 < // 23        other
231 <
232 <      vector<TString> labelArray;
233 <      labelArray.push_back("unmatched");
234 <      labelArray.push_back("u");
235 <      labelArray.push_back("d");
236 <      labelArray.push_back("s");
237 <      labelArray.push_back("c");
238 <      labelArray.push_back("b");
239 <      labelArray.push_back("t");
240 <      labelArray.push_back("e");
241 <      labelArray.push_back("#mu");
242 <      labelArray.push_back("#tau");
243 <      labelArray.push_back("#nu");
244 <      labelArray.push_back("g");
245 <      labelArray.push_back("#gamma");
246 <      labelArray.push_back("Z");
247 <      labelArray.push_back("W");
248 <      labelArray.push_back("light meson");
249 <      labelArray.push_back("K meson");
250 <      labelArray.push_back("D meson");
251 <      labelArray.push_back("B meson");
252 <      labelArray.push_back("light baryon");
253 <      labelArray.push_back("strange baryon");
254 <      labelArray.push_back("charm baryon");
255 <      labelArray.push_back("bottom baryon");
256 <      labelArray.push_back("other");
257 <
258 <      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
259 <        oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
260 <      }
261 <    }
262 <
263 <    //book a histogram for the number of each object type to be plotted
264 <
265 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
266 <      string currentObject = objectsToPlot.at(currentObjectIndex);
267 <      int maxNum = 10;
268 <      if(currentObject == "mcparticles") maxNum = 50;
269 <      else if(currentObject == "primaryvertexs") maxNum = 50;
270 <      else if(currentObject == "muon-muon pairs")
271 <        {
272 <          currentObject = "dimuonPairs";
273 <        }
274 <      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
275 <      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
276 <
277 <      currentObject.at(0) = toupper(currentObject.at(0));
278 <      string histoName = "num" + currentObject;
279 <
280 <      if(histoName == "numPrimaryvertexs"){
281 <        string newHistoName = histoName + "BeforePileupCorrection";
282 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);    
283 <        newHistoName = histoName + "AfterPileupCorrection";
284 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
285 <      }
286 <      else
287 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
288 <    }
289 <
290 <
291 <    
292 <
293 <
286 >    vector<TFileDirectory> directories; //vector of directories in the output file.
287 >    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
288 >    vector<string> subSubDirNames;//subdirectories in each channel.
289      //get list of cuts for this channel
290      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
291  
292 +
293      //loop over and parse all cuts
294      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
295        cut tempCut;
296        //store input collection for cut
297        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
298 +      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
299 +      if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
300 +      if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
301 +      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
302 +      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
303 +      if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
304 +      if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
305 +      if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
306 +      if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
307 +      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
308 +      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
309 +      if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
310 +      if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
311 +      if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
312 +      if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
313 +      if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
314 +      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
315 +      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
316 +      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
317        tempCut.inputCollection = tempInputCollection;
318 <      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
319 <        objectsToGet.push_back(tempInputCollection);
320 <        objectsToCut.push_back(tempInputCollection);
321 <      }
322 <      else{//pair of objects, need to add them both to the things to objectsToGet
323 <        int dashIndex = tempInputCollection.find("-");
324 <        int spaceIndex = tempInputCollection.find(" ");
325 <        int secondWordLength = spaceIndex - dashIndex;
326 <        objectsToGet.push_back(tempInputCollection);
327 <        objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
328 <        objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
329 <        objectsToCut.push_back(tempInputCollection);
330 <        objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
331 <        objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
318 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
319 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
320 >          int spaceIndex = tempInputCollection.find(" ");
321 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
322 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
323 >        }
324 >        else{
325 >          objectsToGet.push_back(tempInputCollection);
326 >        }
327 >        objectsToCut.push_back(tempInputCollection);
328 >        objectsToFlag.push_back(tempInputCollection);
329 >      }
330 >      else{//pair of objects, need to add them both to objectsToGet
331 >        string obj1;
332 >        string obj2;
333 >        getTwoObjs(tempInputCollection, obj1, obj2);
334 >        string obj2ToGet = getObjToGet(obj2);
335 >        objectsToCut.push_back(tempInputCollection);
336 >        objectsToCut.push_back(obj1);
337 >        objectsToCut.push_back(obj2);
338 >        objectsToFlag.push_back(tempInputCollection);
339 >        objectsToFlag.push_back(obj1);
340 >        objectsToFlag.push_back(obj2);
341 >        objectsToGet.push_back(tempInputCollection);
342 >        objectsToGet.push_back(obj1);
343 >        objectsToGet.push_back(obj2ToGet);
344  
345        }
346  
# Line 321 | Line 348 | objectsToGet.push_back("primaryvertexs")
348  
349        //split cut string into parts and store them
350        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
351 <      std::vector<string> cutStringVector = splitString(cutString);
351 >      vector<string> cutStringVector = splitString(cutString);
352        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
353 <        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
354 <        exit(0);
353 >        clog << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
354 >        exit(0);
355        }
356        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
357        for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
358 <        int indexOffset = 4 * subcutIndex;
359 <        string currentVariableString = cutStringVector.at(indexOffset);
360 <        if(currentVariableString.find("(")==std::string::npos){
361 <          tempCut.functions.push_back("");//no function was specified
362 <          tempCut.variables.push_back(currentVariableString);// variable to cut on
363 <        }
364 <        else{
365 <          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
366 <          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
367 <          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
368 <        }
369 <        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
370 <        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
371 <        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
358 >        int indexOffset = 4 * subcutIndex;
359 >        string currentVariableString = cutStringVector.at(indexOffset);
360 >        if(currentVariableString.find("(")==string::npos){
361 >          tempCut.functions.push_back("");//no function was specified
362 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
363 >        }
364 >        else{
365 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
366 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
367 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
368 >        }
369 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
370 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
371 >        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
372 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
373        }
374  
375        //get number of objects required to pass cut for event to pass
376        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
377 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
377 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
378        if(numberRequiredVector.size()!=2){
379 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
379 >        clog << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
380          exit(0);
381        }
382  
# Line 356 | Line 384 | objectsToGet.push_back("primaryvertexs")
384        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
385        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
386  
387 <
387 >      //Set up vectors to store the directories and subDirectories for each channel.
388 >      string subSubDirName;
389        string tempCutName;
390        if(cuts_.at(currentCut).exists("alias")){
391          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
392 +        subSubDirName = "After " + tempCutName + " Cut Applied";
393        }
394        else{
395          //construct string for cutflow table
# Line 367 | Line 397 | objectsToGet.push_back("primaryvertexs")
397          string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
398          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
399          tempCutName = cutName;
400 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
401        }
371      tempCut.name = tempCutName;
402  
403 +      tempCut.isVeto = false;
404 +      if(cuts_.at(currentCut).exists("isVeto")){
405 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
406 +        if (isVeto == true) tempCut.isVeto = true;
407 +      }
408 +      subSubDirNames.push_back(subSubDirName);
409 +      tempCut.name = tempCutName;
410 +      if (verbose_) clog << "Setting up cut, index: " << currentCut << ", input collection: " << tempInputCollection<< ", name: " << tempCut.name << endl;  
411  
412        tempChannel.cuts.push_back(tempCut);
413  
414  
377
415      }//end loop over cuts
416  
417 +    vector<map<string, TH1D*>> oneDHistsTmp;
418 +    vector<map<string, TH2D*>> twoDHistsTmp;
419 +    //book a directory in the output file with the name of the channel
420 +    TFileDirectory subDir = fs_->mkdir( channelName );
421 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
422 +    if(GetPlotsAfterEachCut_){
423 +      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
424 +        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
425 +        directories.push_back(subSubDir);
426 +        map<string, TH1D*> oneDhistoMap;
427 +        oneDHistsTmp.push_back(oneDhistoMap);
428 +        map<string, TH2D*> twoDhistoMap;
429 +        twoDHistsTmp.push_back(twoDhistoMap);
430 +      }
431 +      treeDirectories.push_back(subDir);
432 +      oneDHists_.push_back(oneDHistsTmp);
433 +      twoDHists_.push_back(twoDHistsTmp);
434 +    }
435 +    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
436 +    else{
437 +      map<string, TH1D*> oneDhistoMap;
438 +      oneDHistsTmp.push_back(oneDhistoMap);
439 +      map<string, TH2D*> twoDhistoMap;
440 +      twoDHistsTmp.push_back(twoDhistoMap);
441 +      oneDHists_.push_back(oneDHistsTmp);
442 +      twoDHists_.push_back(twoDHistsTmp);
443 +      directories.push_back(subDir);
444 +      treeDirectories.push_back(subDir);
445 +
446 +    }
447 +
448 +    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
449 +      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
450 +      BNTrees_.push_back(newTree);
451 +      BNTrees_.back()->Branch("event_runInt",  &BNTreeBranchVals_runInt_,  "event_runInt/I");      
452 +      BNTrees_.back()->Branch("event_lumiInt", &BNTreeBranchVals_lumiInt_, "event_lumiInt/I");      
453 +      BNTrees_.back()->Branch("event_evtLong", &BNTreeBranchVals_evtLong_, "event_evtLong/L");      
454 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
455 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
456 +        vector<float> newVec;
457 +        BNTreeBranchVals_[currentVar.name] = newVec;
458 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
459 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
460 +    }
461 +
462 +    //book all histograms included in the configuration
463 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
464 +
465 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
466 +
467 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
468 +        int numBinsElements = currentHistogram.bins.size();
469 +        int numInputVariables = currentHistogram.inputVariables.size();
470 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
471 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
472 +
473 +        if(numBinsElements == 1){
474 +          if(numBinEdgesX > 1){
475 +            if(numBinEdgesY > 1)
476 +              numBinsElements = 6;
477 +            else
478 +              numBinsElements = 3;
479 +          }
480 +        }
481 +        if(numBinsElements != 3 && numBinsElements !=6){
482 +          clog << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
483 +          exit(0);
484 +        }
485 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
486 +          clog << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
487 +          exit(0);
488 +        }
489 +        else if(numBinsElements == 3){
490 +          if (currentHistogram.bins.size () == 3)
491 +            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));
492 +          else
493 +            {
494 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
495 +            }
496 +        }
497 +        else if(numBinsElements == 6){
498 +          if (currentHistogram.bins.size () == 6)
499 +            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));
500 +          else
501 +            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 ());
502 +        }
503 +
504 +
505 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
506 +
507 +        // bin      particle type
508 +        // ---      -------------
509 +        //  0        unmatched
510 +        //  1        u
511 +        //  2        d
512 +        //  3        s
513 +        //  4        c
514 +        //  5        b
515 +        //  6        t
516 +        //  7        e
517 +        //  8        mu
518 +        //  9        tau
519 +        // 10        nu
520 +        // 11        g
521 +        // 12        gamma
522 +        // 13        Z
523 +        // 14        W
524 +        // 15        light meson
525 +        // 16        K meson
526 +        // 17        D meson
527 +        // 18        B meson
528 +        // 19        light baryon
529 +        // 20        strange baryon
530 +        // 21        charm baryon
531 +        // 22        bottom baryon
532 +        // 23        QCD string
533 +        // 24        other
534 +
535 +        vector<TString> labelArray;
536 +        labelArray.push_back("unmatched");
537 +        labelArray.push_back("u");
538 +        labelArray.push_back("d");
539 +        labelArray.push_back("s");
540 +        labelArray.push_back("c");
541 +        labelArray.push_back("b");
542 +        labelArray.push_back("t");
543 +        labelArray.push_back("e");
544 +        labelArray.push_back("#mu");
545 +        labelArray.push_back("#tau");
546 +        labelArray.push_back("#nu");
547 +        labelArray.push_back("g");
548 +        labelArray.push_back("#gamma");
549 +        labelArray.push_back("Z");
550 +        labelArray.push_back("W");
551 +        labelArray.push_back("light meson");
552 +        labelArray.push_back("K meson");
553 +        labelArray.push_back("D meson");
554 +        labelArray.push_back("B meson");
555 +        labelArray.push_back("light baryon");
556 +        labelArray.push_back("strange baryon");
557 +        labelArray.push_back("charm baryon");
558 +        labelArray.push_back("bottom baryon");
559 +        labelArray.push_back("QCD string");
560 +        labelArray.push_back("other");
561 +
562 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
563 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
564 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
565 +          }
566 +          else {
567 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
568 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
569 +          }
570 +        }
571 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
572 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
573 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
574 +        }
575 +
576 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
577 +
578 +
579 +      // Book a histogram for the number of each object type to be plotted.
580 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
581 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
582 +        string currentObject = objectsToPlot.at(currentObjectIndex);
583 +        int maxNum = 10;
584 +        if(currentObject == "mcparticles") maxNum = 50;
585 +        else if(currentObject == "primaryvertexs") maxNum = 50;
586 +
587 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
588 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
589 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
590 +        else if(currentObject == "electron-photon pairs")     currentObject = "electronPhotonPairs";
591 +        else if(currentObject == "muon-photon pairs")         currentObject = "muonPhotonPairs";
592 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
593 +        else if(currentObject == "secondary photons")            currentObject = "secondaryPhotons";
594 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
595 +        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
596 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
597 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
598 +        else if(currentObject == "muon-event pairs")            currentObject = "muonEventPairs";
599 +        else if(currentObject == "photon-jet pairs")            currentObject = "photonJetPairs";
600 +        else if(currentObject == "met-jet pairs")             currentObject = "metJetPairs";
601 +        else if(currentObject == "track-jet pairs")           currentObject = "trackJetPairs";
602 +        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
603 +        else if(currentObject == "muon-secondary photon pairs")  currentObject = "muonSecondaryPhotonPairs";
604 +        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
605 +        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
606 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
607 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
608 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
609 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
610 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
611 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
612 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
613 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
614 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
615 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
616 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
617 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
618 +
619 +        currentObject.at(0) = toupper(currentObject.at(0));
620 +        string histoName = "num" + currentObject;
621 +
622 +        if(histoName == "numPrimaryvertexs"){
623 +          string newHistoName = histoName + "BeforePileupCorrection";
624 +          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);
625 +          newHistoName = histoName + "AfterPileupCorrection";
626 +          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);
627 +        }
628 +        else
629 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
630 +      }
631 +
632 +      if (verbose_) {
633 +        clog << "List of 1D histograms booked for channel " << channelName << " and directory " << currentDir << ":" << endl;
634 +        for(map<string, TH1D*>::iterator
635 +              iter = oneDHists_.at(currentChannel).at(currentDir).begin();
636 +            iter  != oneDHists_.at(currentChannel).at(currentDir).end();
637 +            iter++) {
638 +          clog << " " << iter->first
639 +               << ":  name=" << iter->second->GetName()
640 +               << ", title=" << iter->second->GetTitle()
641 +               << ", bins=(" << iter->second->GetNbinsX()
642 +               << "," << iter->second->GetXaxis()->GetXmin()
643 +               << "," << iter->second->GetXaxis()->GetXmax()
644 +               << ")" << endl;
645 +        }  
646 +        clog << "List of 2D histograms booked for channel " << channelName << " and directory " << currentDir << ":" << endl;
647 +        for(map<string, TH2D*>::iterator
648 +              iter = twoDHists_.at(currentChannel).at(currentDir).begin();
649 +            iter  != twoDHists_.at(currentChannel).at(currentDir).end();
650 +            iter++) {
651 +          clog << " " << iter->first
652 +               << ":  name=" << iter->second->GetName()
653 +               << ", title=" << iter->second->GetTitle()
654 +               << ", binsX=(" << iter->second->GetNbinsX()
655 +               << "," << iter->second->GetXaxis()->GetXmin()
656 +               << "," << iter->second->GetXaxis()->GetXmax()
657 +               << ")"
658 +               << ", binsY=(" << iter->second->GetNbinsY()
659 +               << "," << iter->second->GetYaxis()->GetXmin()
660 +               << "," << iter->second->GetYaxis()->GetXmax()
661 +               << ")"
662 +               << endl;
663 +        }  
664 +      }
665 +
666 +    }//end of loop over directories
667      channels.push_back(tempChannel);
668      tempChannel.cuts.clear();
382
669    }//end loop over channels
670  
671  
672 +  // Create the cutflow histogram and fill with 0 weight, in case no events are found in the input file.  
673 +  for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
674 +    channel currentChannel = channels.at(currentChannelIndex);
675 +    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
676 +      cutFlows_.at(currentChannelIndex)->at("trigger") = true;  
677 +    }
678 +    for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
679 +      cut currentCut = currentChannel.cuts.at(currentCutIndex);
680 +      cutFlows_.at(currentChannelIndex)->at (currentCut.name) = true;
681 +    }
682 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(0);  // fill cutflow with 0 weight, just to create the cutflow histograms  
683 +  }
684 +
685    //make unique vector of objects we need to get from the event
686    sort( objectsToGet.begin(), objectsToGet.end() );
687    objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
688    //make unique vector of objects we need to cut on
689    sort( objectsToCut.begin(), objectsToCut.end() );
690    objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
691 +  //make unique vector of objects we need to set flags for
692 +  sort( objectsToFlag.begin(), objectsToFlag.end() );
693 +  objectsToFlag.erase( unique( objectsToFlag.begin(), objectsToFlag.end() ), objectsToFlag.end() );
694 +
695 +  // 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.  
696 +  for (uint i=0; i<objectsToFlag.size(); i++) {
697 +    if (objectsToFlag.at(i).find("pairs")!=string::npos) { // if it contains "pairs"
698 +      objectsToFlag.push_back(objectsToFlag.at(i));  
699 +      objectsToFlag.erase(objectsToFlag.begin()+i);  
700 +    }
701 +  }
702  
703 +  if (verbose_) {
704 +    clog << "List of channels:" << endl;
705 +    for (uint i=0; i<channels.size(); i++) {
706 +      clog << " " << channels.at(i).name << endl;
707 +    }
708 +    clog << "List of objects to get:" << endl;
709 +    for (uint i=0; i<objectsToGet.size(); i++) {
710 +      clog << " " << objectsToGet.at(i) << endl;
711 +    }
712 +    clog << "List of objects to plot:" << endl;
713 +    for (uint i=0; i<objectsToPlot.size(); i++) {
714 +      clog << " " << objectsToPlot.at(i) << endl;
715 +    }
716 +    clog << "List of objects to cut:" << endl;
717 +    for (uint i=0; i<objectsToCut.size(); i++) {
718 +      clog << " " << objectsToCut.at(i) << endl;
719 +    }
720 +    clog << "List of objects to flag:" << endl;
721 +    for (uint i=0; i<objectsToFlag.size(); i++) {
722 +      clog << " " << objectsToFlag.at(i) << endl;
723 +    }
724 +  }
725 +
726 +  produces<map<string, bool> > ("channelDecisions");
727 +
728 +  if (printEventInfo_) {
729 +    findEventsLog = new ofstream();  
730 +    findEventsLog->open("findEvents.txt");  
731 +    clog << "Listing run:lumi:event in file findEvents.txt for events that pass full selection (of any channel)." << endl;  
732 +  } else {
733 +    findEventsLog = 0;
734 +  }  
735 +
736 +  isFirstEvent_ = true;  
737 +
738 +  if (verbose_) clog << "Finished OSUAnalysis::OSUAnalysis constructor." << endl;  
739 +
740 +
741 +  } // end constructor OSUAnalysis::OSUAnalysis()
742  
394 }
743  
744   OSUAnalysis::~OSUAnalysis ()
745   {
746 +
747 +  if (verbose_) clog << "Beginning OSUAnalysis::OSUAnalysis destructor." << endl;  
748 +
749    // Destroying the CutFlow objects causes the cut flow numbers and time
750    // information to be printed to standard output.
751    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
752      delete cutFlows_.at(currentChannel);
753    }
754 +
755 +  if (printEventInfo_ && findEventsLog) findEventsLog->close();  
756 +
757 +  clog << "=============================================" << endl;  
758 +  clog << "Successfully completed OSUAnalysis." << endl;  
759 +  clog << "=============================================" << endl;  
760 +
761 +  if (verbose_) clog << "Finished OSUAnalysis::OSUAnalysis destructor." << endl;  
762 +
763   }
764  
765   void
766 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
766 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
767   {
408
768    // Retrieve necessary collections from the event.
769  
770 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
770 >  if (verbose_) clog << "Beginning OSUAnalysis::produce." << endl;  
771 >
772 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
773      event.getByLabel (triggers_, triggers);
774  
775 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
775 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
776 >    event.getByLabel (trigobjs_, trigobjs);
777 >
778 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
779      event.getByLabel (jets_, jets);
780  
781 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
781 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
782      event.getByLabel (muons_, muons);
783  
784 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
784 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
785      event.getByLabel (electrons_, electrons);
786  
787 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
787 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
788      event.getByLabel (events_, events);
789  
790 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
790 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
791      event.getByLabel (taus_, taus);
792  
793 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
793 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
794      event.getByLabel (mets_, mets);
795  
796 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
796 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
797      event.getByLabel (tracks_, tracks);
798  
799 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
799 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
800      event.getByLabel (genjets_, genjets);
801  
802 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
803 <        event.getByLabel (mcparticles_, mcparticles);
440 <    
802 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
803 >    event.getByLabel (mcparticles_, mcparticles);
804  
805 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
805 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
806      event.getByLabel (primaryvertexs_, primaryvertexs);
807  
808 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
808 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
809      event.getByLabel (bxlumis_, bxlumis);
810  
811 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
811 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
812      event.getByLabel (photons_, photons);
813  
814 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
814 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
815      event.getByLabel (superclusters_, superclusters);
816  
817 +  if (datasetType_ == "signalMC"){
818 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
819 +      event.getByLabel (stops_, stops);
820 +  }
821  
822 <  //get pile-up event weight
823 <  double puScaleFactor = 1.00;
824 <  //  if(datasetType_ != "data"){
825 <  // puScaleFactor = puWeight_->at (events->at (0).numTruePV);
826 <    //    cout << puScaleFactor << endl;
827 <  //}
822 >  if (useTrackCaloRhoCorr_) {
823 >    // Used only for pile-up correction of by-hand calculation of isolation energy.
824 >    // This rho collection is not available in all BEANs.
825 >    // For description of rho values for different jet reconstruction algorithms, see
826 >    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
827 >    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
828 >  }
829 >
830 >  double masterScaleFactor = 1.0;
831  
832 +  //get pile-up event weight
833 +  if (doPileupReweighting_ && datasetType_ != "data") {
834 +    //for "data" datasets, the numTruePV is always set to -1
835 +    if (events->at(0).numTruePV < 0 && isFirstEvent_) clog << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
836 +    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
837 +  }
838  
839 +  stopCTauScaleFactor_ = 1.0;
840 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
841 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
842 +  masterScaleFactor *= stopCTauScaleFactor_;
843  
844    //loop over all channels
845  
846 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
847    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
848      channel currentChannel = channels.at(currentChannelIndex);
849 +    if (verbose_>1) clog << " Processing channel " << currentChannel.name << endl;
850  
851      flagMap individualFlags;
470    flagMap cumulativeFlags;
852      counterMap passingCounter;
853 +    cumulativeFlags.clear ();
854 +
855 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
856 +         iter != BNTreeBranchVals_.end(); iter++) {
857 +      iter->second.clear();  // clear array
858 +    }
859  
860      bool triggerDecision = true;
861 <    if(currentChannel.triggers.size() != 0){  //triggers specified
862 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
861 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
862 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
863        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
864      }
865  
866      //loop over all cuts
480
481
482
867      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
868        cut currentCut = currentChannel.cuts.at(currentCutIndex);
869 +      if (verbose_>2) clog << "  Processing cut, index: " << currentCutIndex << ", input collection: " << currentCut.inputCollection << ", name: " << currentCut.name << endl;  
870  
871 <      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
872 <        string currentObject = objectsToCut.at(currentObjectIndex);
488 <
489 <        //initialize maps to get ready to set cuts
490 <        individualFlags[currentObject].push_back (vector<bool> ());
491 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
492 <
493 <      }
494 <      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
495 <        string currentObject = objectsToCut.at(currentObjectIndex);
496 <
497 <        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
498 <
499 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
500 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
501 <        else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
502 <        else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
503 <        else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
504 <        else if(currentObject == "mets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
505 <        else if(currentObject == "tracks") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
506 <        else if(currentObject == "genjets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
507 <        else if(currentObject == "mcparticles") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
508 <        else if(currentObject == "primaryvertexs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
509 <        else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
510 <        else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
511 <        else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
512 <
513 <        
514 <        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
515 <                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
516 <                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
517 <                                                                   "muon-muon pairs");
518 <        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
519 <                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
520 <                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
521 <                                                                           "electron-electron pairs");
522 <        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
523 <                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
524 <                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
525 <                                                                       "electron-muon pairs");
871 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
872 >        string currentObject = objectsToFlag.at(currentObjectIndex);
873  
874 +        //initialize maps to get ready to set cuts
875 +        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
876 +        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
877  
878        }
879  
880 +      //set flags for all relevant objects
881 +      for(int currentObjectIndex = -1; currentObjectIndex != int(objectsToFlag.size()); currentObjectIndex++){
882 +        string currentObject;  
883 +        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.  
884 +        else currentObject = objectsToFlag.at(currentObjectIndex);
885 +        if (currentObjectIndex >= 0 && currentObject == currentCut.inputCollection) continue;  // Flags have already been set for the inputCollection object, so should not be set again.  
886 +
887 +        // single object collections
888 +        if     (currentObject == "jets")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
889 +        else if(currentObject == "secondary jets")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
890 +        else if(currentObject == "secondary photons")   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"secondary photons");
891 +        else if(currentObject == "muons")               setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
892 +        else if(currentObject == "secondary muons")     setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
893 +        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
894 +        else if(currentObject == "electrons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
895 +        else if(currentObject == "events")              setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
896 +        else if(currentObject == "taus")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
897 +        else if(currentObject == "mets")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
898 +        else if(currentObject == "tracks")              setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
899 +        else if(currentObject == "genjets")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
900 +        else if(currentObject == "mcparticles")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
901 +        else if(currentObject == "primaryvertexs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
902 +        else if(currentObject == "bxlumis")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
903 +        else if(currentObject == "photons")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
904 +        else if(currentObject == "superclusters")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
905 +        else if(currentObject == "trigobjs")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
906 +
907 +
908 +        // paired object collections  
909 +        else if(currentObject == "muon-muon pairs")                   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), "muon-muon pairs");
910 +        else if(currentObject == "muon-secondary muon pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), "muon-secondary muon pairs");
911 +
912 +        else if(currentObject == "muon-secondary photon pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), "muon-secondary photon pairs");
913 +        else if(currentObject == "muon-secondary jet pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), "muon-secondary jet pairs");
914 +        else if(currentObject == "photon-secondary jet pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), "photon-secondary jet pairs");
915 +        else if(currentObject == "electron-secondary jet pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), "electron-secondary jet pairs");
916 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), "electron-secondary electron pairs");
917 +
918 +        else if(currentObject == "electron-electron pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), "electron-electron pairs");
919 +        else if(currentObject == "electron-muon pairs")     setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), "electron-muon pairs");
920 +        else if(currentObject == "jet-jet pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), "jet-jet pairs");
921 +        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), "jet-secondary jet pairs");
922 +        else if(currentObject == "electron-jet pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), "electron-jet pairs");
923 +        else if(currentObject == "electron-photon pairs")   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), "electron-photon pairs");
924 +        else if(currentObject == "photon-jet pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), "photon-jet pairs");
925 +        else if(currentObject == "muon-jet pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), "muon-jet pairs");
926 +        else if(currentObject == "muon-event pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),events.product(), "muon-event pairs");
927 +        else if(currentObject == "met-jet pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),jets.product(), "met-jet pairs");
928 +        else if(currentObject == "track-jet pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),jets.product(), "track-jet pairs");
929 +        else if(currentObject == "muon-photon pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), "muon-photon pairs");
930 +        else if(currentObject == "track-event pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(), "track-event pairs");
931 +        else if(currentObject == "electron-track pairs")    setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),"electron-track pairs");
932 +        else if(currentObject == "muon-track pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),"muon-track pairs");
933 +        else if(currentObject == "muon-tau pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),"muon-tau pairs");
934 +        else if(currentObject == "tau-tau pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),"tau-tau pairs");
935 +        else if(currentObject == "tau-track pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),"tau-track pairs");
936 +        else if(currentObject == "electron-trigobj pairs")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),"electron-trigobj pairs");
937 +        else if(currentObject == "muon-trigobj pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),"muon-trigobj pairs");
938  
939 +        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
940 +      }
941  
942      }//end loop over all cuts
943  
944  
535    //use cumulative flags to apply cuts at event level
945  
946 +    //use cumulative flags to apply cuts at event level
947 +    vector<bool> eventPassedPreviousCuts;    //a vector to store cumulative cut descisions after each cut.
948      bool eventPassedAllCuts = true;
949 <
539 <    //apply trigger (true if none were specified)
540 <    eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
541 <
542 <
949 >    eventPassedAllCuts = eventPassedAllCuts && triggerDecision;    //apply trigger (true if none were specified)
950  
951      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
952  
953        //loop over all objects and count how many passed the cumulative selection up to this point
954        cut currentCut = currentChannel.cuts.at(currentCutIndex);
955        int numberPassing = 0;
956 +      int numberPassingPrev = 0;  // number of objects that pass cuts up to the previous one
957  
958        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
959 <          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
959 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
960 >      }
961 >      bool cutDecision;
962 >      if (!currentCut.isVeto) {
963 >        cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
964 >      } else {
965 >        int prevCutIndex = currentCutIndex - 1;
966 >        if (prevCutIndex<0) {
967 >          numberPassingPrev = cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size();  // count all objects in collection if cut is the first
968 >        } else {
969 >          for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(prevCutIndex).size() ; object++){
970 >            if (cumulativeFlags.at(currentCut.inputCollection).at(prevCutIndex).at(object).first) {
971 >              numberPassingPrev++;
972 >              if (verbose_>1) clog << " object passed previous cut" << endl;  
973 >            }
974 >          }  
975 >        }  
976 >        int numberFailCut = numberPassingPrev - numberPassing;
977 >        cutDecision = evaluateComparison(numberFailCut,currentCut.eventComparativeOperator,currentCut.numberRequired);  
978        }
979  
554      bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
980        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
556
981        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
982 +      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
983 +      if (verbose_>1) clog << " Event passed cuts up to cut index " << currentCutIndex << endl;  
984  
985      }
986 +    //applying all appropriate scale factors
987 +    double scaleFactor = masterScaleFactor;
988 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
989 +
990 +    if(applyLeptonSF_ && datasetType_ != "data"){
991 +      //only apply SFs if we've cut on this object
992 +      if(find(objectsToCut.begin(),objectsToCut.end(),"muons") != objectsToCut.end ()){
993 +        flagPair muonFlags;
994 +        //get the last valid flags in the flag map
995 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
996 +          if (cumulativeFlags.at("muons").at(i).size()){
997 +            muonFlags = cumulativeFlags.at("muons").at(i);
998 +            break;
999 +          }
1000 +        }
1001 +        //apply the weight for each of those objects
1002 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
1003 +          if(!muonFlags.at(muonIndex).second) continue;
1004 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
1005 +        }
1006 +      }
1007 +      //only apply SFs if we've cut on this object
1008 +      if(find(objectsToCut.begin(),objectsToCut.end(),"electrons") != objectsToCut.end ()){
1009 +        flagPair electronFlags;
1010 +        //get the last valid flags in the flag map
1011 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
1012 +          if (cumulativeFlags.at("electrons").at(i).size()){
1013 +            electronFlags = cumulativeFlags.at("electrons").at(i);
1014 +            break;
1015 +          }
1016 +        }
1017 +        //apply the weight for each of those objects
1018 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
1019 +          if(!electronFlags.at(electronIndex).second) continue;
1020 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
1021 +        }
1022 +      }
1023 +    }
1024 +    if(applyBtagSF_ && datasetType_ != "data"){
1025 +      //only apply SFs if we've cut on this object
1026 +      if(find(objectsToCut.begin(),objectsToCut.end(),"jets") != objectsToCut.end ()){
1027 +        flagPair jetFlags;
1028 +        vector<double> jetSFs;
1029 +        //get the last valid flags in the flag map
1030 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
1031 +          if (cumulativeFlags.at("jets").at(i).size()){
1032 +            jetFlags = cumulativeFlags.at("jets").at(i);
1033 +            break;
1034 +          }
1035 +        }
1036 +        //apply the weight for each of those objects
1037 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
1038 +          if(!jetFlags.at(jetIndex).second) continue;
1039 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour, jets->at(jetIndex).eta);
1040 +          jetSFs.push_back(jetSFTmp);
1041 +        }
1042 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_);
1043 +      }
1044 +    }
1045 +    scaleFactor *= muonScaleFactor_;
1046 +    scaleFactor *= electronScaleFactor_;
1047 +    scaleFactor *= bTagScaleFactor_;
1048 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
1049 +    if (verbose_>1) clog << " Scale factors applied:  "
1050 +                         << " muonScaleFactor_ = " << muonScaleFactor_
1051 +                         << ", electronScaleFactor_ = " << electronScaleFactor_
1052 +                         << ", bTagScaleFactor_ = " << bTagScaleFactor_
1053 +                         << ", total scale factor = " << scaleFactor
1054 +                         << endl;  
1055 +
1056 +
1057 +    if (printEventInfo_ && eventPassedAllCuts) {
1058 +      // Write information about event to screen, for testing purposes.
1059 +      clog << "Event passed all cuts in channel " <<  currentChannel.name
1060 +           << ":  run:lumi:evt=  "  << events->at(0).run
1061 +           << ":" << events->at(0).lumi
1062 +           << ":" << events->at(0).evt
1063 +           << endl;
1064 +      if (findEventsLog) {
1065 +        (*findEventsLog) << events->at(0).run
1066 +                         << ":" << events->at(0).lumi
1067 +                         << ":" << events->at(0).evt << endl;
1068 +      }
1069  
1070 <    cutFlows_.at(currentChannelIndex)->fillCutFlow(puScaleFactor);
1070 >    }
1071  
1072  
1073 +    //filling histograms
1074 +    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.
1075  
1076 <    if(!eventPassedAllCuts)continue;
1076 >      if (verbose_>2) clog << "  Filling histograms for currentcut = " << currentCut << endl;  
1077  
1078 +      uint currentDir;
1079 +      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
1080 +      else{
1081 +        currentDir = currentCut;
1082 +      }
1083  
568    
1084  
1085 <    //set position of primary vertex in event, in order to calculate quantities relative to it
571 <    if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
572 <      vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back();
573 <      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
574 <        if(!vertexFlags.at(vertexIndex)) continue;
575 <        chosenPrimaryVertex = & primaryvertexs->at(vertexIndex);
576 <        break;
577 <      }
578 <    }
579 <    else {
580 <      chosenPrimaryVertex = & primaryvertexs->at(0);
581 <    }
1085 >      if(eventPassedPreviousCuts.at(currentDir)){
1086  
1087 +        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1088 +          histogram currentHistogram = histograms.at(histogramIndex);
1089  
1090 +          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) clog << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
1091  
1092 <    //filling histograms
586 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
587 <      histogram currentHistogram = histograms.at(histogramIndex);
1092 >          if (verbose_>1) clog << " Filling histogram " << currentHistogram.name << " for collection " << currentHistogram.inputCollection << endl;  
1093  
1094 <      if(currentHistogram.inputVariables.size() == 1){
1095 <        TH1D* histo;
1096 <        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
1097 <
1098 <
1099 <
1100 <        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
1101 <        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
1102 <        else if(currentHistogram.inputCollection == "muon-muon pairs")
1103 <          {
1104 <            fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1105 <                            cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
1106 <                            
1107 <                            cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
1108 <
1109 <          }
1110 <        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
1111 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
1112 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
1113 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
1114 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
1115 <                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
1116 <                                                                                              cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
1117 <        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
1118 <        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
1119 <        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
1120 <        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
1121 <        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
1122 <        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
1123 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
1124 <        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
1125 <        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
1126 <        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
1127 <      }
1128 <      else if(currentHistogram.inputVariables.size() == 2){
1129 <        TH2D* histo;
1130 <        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
1131 <
1132 <
1133 <
1134 <        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
1135 <        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
1136 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1137 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
1138 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
1139 <        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
1140 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1141 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
1142 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
1143 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1144 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
1145 <                                                                                               cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
1146 <        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
1147 <        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
1148 <        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
1149 <        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
1150 <        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
1151 <        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
1152 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
1153 <        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
1154 <        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
1155 <        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
1156 <      }
1157 <    }
1158 <
1159 <    //fills histograms with the sizes of collections
1160 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1161 <      string currentObject = objectsToPlot.at(currentObjectIndex);
1162 <
1163 <      string objectToPlot = "";
1164 <
1165 <      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
1166 <      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
1167 <      else if(currentObject == "electron-muon pairs") objectToPlot = "electronMuonPairs";
1168 <      else objectToPlot = currentObject;
1169 <      string tempCurrentObject = objectToPlot;
1170 <      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1171 <      string histoName = "num" + tempCurrentObject;
1172 <
1173 <
1174 <
1175 <
1176 <      //set position of primary vertex in event, in order to calculate quantities relative to it
1177 <      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1178 <        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
1179 <        int numToPlot = 0;
1180 <        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1181 <          if(lastCutFlags.at(currentFlag)) numToPlot++;
1182 <        }
1183 <        if(objectToPlot == "primaryvertexs"){
1184 <          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1185 <          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),puScaleFactor);
1186 <        }
1187 <        else
1188 <          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,puScaleFactor);        
1189 <      }
1190 <      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),puScaleFactor);
1191 <      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),puScaleFactor);
1192 <      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,puScaleFactor);
1193 <      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),puScaleFactor);
1194 <      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,puScaleFactor);
1195 <      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),puScaleFactor);
1196 <      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),puScaleFactor);
1197 <      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),puScaleFactor);
1198 <      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),puScaleFactor);
1199 <      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),puScaleFactor);
1200 <      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),puScaleFactor);
1201 <      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),puScaleFactor);
1202 <      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),puScaleFactor);
1203 <      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),puScaleFactor);
1204 <      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),puScaleFactor);
1205 <      else if(objectToPlot == "primaryvertexs"){
1206 <        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1207 <        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),puScaleFactor);
1208 <      }
1094 >          if(currentHistogram.inputVariables.size() == 1){
1095 >            TH1D* histo;
1096 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1097 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1098 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1099 >            else if(currentHistogram.inputCollection == "secondary photons")  fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1100 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1101 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1102 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1103 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1104 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1105 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1106 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1107 >             else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1108 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1109 >             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1110 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1111 >             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1112 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1113 >             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1114 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1115 >
1116 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1117 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1118 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1119 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1120 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1121 >             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1122 >                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1123 >
1124 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1125 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1126 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(),
1127 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1128 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(),
1129 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1130 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(),
1131 >                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1132 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(),
1133 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1134 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill1DHistogram(histo,currentHistogram, muons.product(),events.product(),
1135 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1136 >            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, mets.product(),jets.product(),
1137 >                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1138 >            else if(currentHistogram.inputCollection == "track-jet pairs")  fill1DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1139 >                                                                                          cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1140 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(),
1141 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1142 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(),
1143 >                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1144 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1145 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1146 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1147 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1148 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1149 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1150 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1151 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1152 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1153 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1154 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1155 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1156 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1157 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1158 >
1159 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1160 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1161 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1162 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1163 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1164 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1165 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1166 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1167 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1168 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1169 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1170 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1171 >          }
1172 >          else if(currentHistogram.inputVariables.size() == 2){
1173 >            TH2D* histo;
1174 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1175 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1176 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1177 >            else if(currentHistogram.inputCollection == "secondary photons")  fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1178 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1179 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1180 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1181 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1182 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1183 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1184 >            else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1185 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1186 >            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1187 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1188 >            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1189 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1190 >            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1191 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1192 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1193 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1194 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1195 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1196 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1197 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1198 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1199 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1200 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(),
1201 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1202 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1203 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1204 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(),
1205 >                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1206 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1207 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1208 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill2DHistogram(histo,currentHistogram,muons.product(),events.product(),
1209 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1210 >            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,mets.product(),jets.product(),
1211 >                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1212 >            else if(currentHistogram.inputCollection == "track-jet pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1213 >                                                                                         cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1214 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1215 >                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1216 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1217 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1218 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1219 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1220 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1221 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1222 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1223 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1224 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1225 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1226 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1227 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1228 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1229 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1230 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1231 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1232 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1233 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1234 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1235 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1236 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1237 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1238 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1239 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1240 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1241 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1242 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1243 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1244 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1245 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1246 >          }
1247 >
1248 >        }
1249 >
1250 >
1251 >        //fills histograms with the sizes of collections
1252 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1253 >
1254 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1255 >          string objectToPlot = "";
1256 >
1257 >          if (verbose_) clog << "Filling histogram of number of selected objects in collection: " << currentObject << endl;  
1258  
1259 +          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1260 +          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1261 +          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1262 +          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1263 +          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1264 +          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1265 +          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1266 +          else if(currentObject == "muon-event pairs")                   objectToPlot = "muonEventPairs";
1267 +          else if(currentObject == "muon-photon pairs")                  objectToPlot = "muonPhotonPairs";
1268 +          else if(currentObject == "photon-jet pairs")                   objectToPlot = "photonJetPairs";
1269 +          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1270 +          else if(currentObject == "track-jet pairs")                    objectToPlot = "trackJetPairs";
1271 +          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1272 +          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1273 +          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1274 +          else if(currentObject == "secondary photons")                  objectToPlot = "secondaryPhotons";
1275 +          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1276 +          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1277 +          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1278 +          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1279 +          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1280 +          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1281 +          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1282 +          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1283 +          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1284 +          else if(currentObject == "muon-secondary photon pairs")        objectToPlot = "muonSecondaryJetPairs";
1285 +          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1286 +          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1287 +          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1288 +          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1289 +          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1290 +          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1291 +          else objectToPlot = currentObject;
1292 +
1293 +          string tempCurrentObject = objectToPlot;
1294 +          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1295 +          string histoName = "num" + tempCurrentObject;
1296 +
1297 +
1298 +          if(find(objectsToPlot.begin(), objectsToPlot.end(), currentObject) != objectsToPlot.end()) {
1299 +            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1300 +            int numToPlot = 0;
1301 +            for (uint iObj = 0; iObj != lastCutFlags.size(); iObj++){  // loop over all the objects  
1302 +              if(lastCutFlags.at(iObj).second) {
1303 +                numToPlot++;  
1304 +                if (verbose_>3) clog << "   Found object " << iObj << " in collection " << currentObject << " to plot." << endl;
1305 +              }
1306 +            }
1307 +
1308 +            if(objectToPlot == "primaryvertexs"){
1309 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1310 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1311 +            }
1312 +            else {
1313 +              if (printEventInfo_) clog << "Number of selected " << objectToPlot << " to plot:  " << numToPlot << endl;  
1314 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1315 +            }
1316 +          }
1317 +
1318 +        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1319 +
1320 +
1321 +      } // end if(eventPassedPreviousCuts.at(currentDir))
1322 +    } // end loop over cuts
1323 +
1324 +    if (!useEDMFormat_ && eventPassedAllCuts){
1325 +      // Assign BNTree variables
1326 +      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1327 +        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1328 +        string coll = brSpecs.inputCollection;
1329 +        if (cumulativeFlags.count(coll) == 0) clog << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1330 +
1331 +        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1332 +        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1333 +        else if(coll == "secondary photons")      assignTreeBranch(brSpecs,photons.product(),          cumulativeFlags.at(coll).back());
1334 +        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1335 +        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1336 +        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1337 +        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1338 +        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1339 +        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1340 +        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1341 +        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1342 +        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1343 +        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1344 +        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1345 +        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1346 +        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1347 +        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1348 +        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1349 +        else if(coll == "stops"
1350 +                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1351 +      } // end loop over branches
1352 +      // set the evtLong, runInt, and lumiInt variables separately, since they are not type float  
1353 +      BNTreeBranchVals_evtLong_ = events->at(0).evt;
1354 +      BNTreeBranchVals_runInt_  = events->at(0).run;
1355 +      BNTreeBranchVals_lumiInt_ = events->at(0).lumi;
1356 +
1357 +      if (!BNTrees_.at(currentChannelIndex)) { clog << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1358 +      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1359      }
1360  
1361 +    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1362  
1363 +  } // end loop over channel
1364  
1365 +  masterCutFlow_->fillCutFlow(masterScaleFactor);
1366  
1367 <  } //end loop over channel
1367 >  event.put (channelDecisions, "channelDecisions");
1368  
1369 <  masterCutFlow_->fillCutFlow(puScaleFactor);
1369 >  isFirstEvent_ = false;  
1370  
1371 +  if (verbose_) clog << "Finished OSUAnalysis::produce." << endl;  
1372  
1373 + } // end void OSUAnalysis::produce (const edm::Event &event, const edm::EventSetup &setup)
1374  
716 }
1375  
1376  
1377   bool
# Line 727 | Line 1385 | OSUAnalysis::evaluateComparison (double
1385    else if(comparison == "==") return testValue == cutValue;
1386    else if(comparison == "=") return testValue == cutValue;
1387    else if(comparison == "!=") return testValue != cutValue;
1388 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1388 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1389 >
1390 > }
1391 >
1392 > bool
1393 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1394 >
1395 >
1396 >  if(comparison == ">")       return testValue >  cutValue;
1397 >  else if(comparison == ">=") return testValue >= cutValue;
1398 >  else if(comparison == "<")  return testValue <  cutValue;
1399 >  else if(comparison == "<=") return testValue <= cutValue;
1400 >  else if(comparison == "==") return testValue == cutValue;
1401 >  else if(comparison == "=")  return testValue == cutValue;
1402 >  else if(comparison == "!=") return testValue != cutValue;
1403 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1404  
1405   }
1406  
1407   bool
1408 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1408 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1409  
1410 +  //initialize to false until a chosen trigger is passed
1411    bool triggerDecision = false;
1412  
1413 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1414 <    {
1415 <      if(trigger->pass != 1) continue;
1416 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1417 <        {
1418 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1419 <            triggerDecision = true;
1420 <          }
1421 <        }
1413 >  if (printAllTriggers_) clog << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1414 >  //loop over all triggers defined in the event
1415 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1416 >
1417 >    if (printAllTriggers_) clog << "   " << trigger->name << endl;
1418 >
1419 >    //we're only interested in triggers that actually passed
1420 >    if(trigger->pass != 1) continue;
1421 >
1422 >    //if the event passes one of the veto triggers, exit and return false
1423 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1424 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1425 >    }
1426 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1427 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1428 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1429      }
1430 <  return triggerDecision;
1430 >  }
1431 >
1432 >  printAllTriggers_ = false;  // only print triggers once, not every event
1433  
1434 +  //if none of the veto triggers fired:
1435 +  //return the OR of all the chosen triggers
1436 +  if (triggersToTest.size() != 0) return triggerDecision;
1437 +  //or if no triggers were defined return true
1438 +  else return true;
1439   }
1440  
1441 < std::vector<std::string>
1441 >
1442 > vector<string>
1443   OSUAnalysis::splitString (string inputString){
1444  
1445 <  std::stringstream stringStream(inputString);
1446 <  std::istream_iterator<std::string> begin(stringStream);
1447 <  std::istream_iterator<std::string> end;
1448 <  std::vector<std::string> stringVector(begin, end);
1445 >  stringstream stringStream(inputString);
1446 >  istream_iterator<string> begin(stringStream);
1447 >  istream_iterator<string> end;
1448 >  vector<string> stringVector(begin, end);
1449    return stringVector;
1450  
1451   }
1452  
1453 +
1454 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1455 +  // Set two object strings from the tempInputCollection string,
1456 +  // For example, if tempInputCollection is "electron-muon pairs",
1457 +  // then obj1 = "electrons" and obj2 = "muons".
1458 +  // Note that the objects have an "s" appended.
1459 +
1460 +  int dashIndex = tempInputCollection.find("-");
1461 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1462 +  int secondWordLength = spaceIndex - dashIndex;
1463 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1464 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1465 +
1466 + }
1467 +
1468 +
1469 + string OSUAnalysis::getObjToGet(string obj) {
1470 +  // Return the string corresponding to the object to get for the given obj string.
1471 +  // Right now this only handles the case in which obj contains "secondary",
1472 +  // e.g, "secondary muons".
1473 +  // Note that "s" is NOT appended.
1474 +
1475 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1476 +  int firstSpaceIndex = obj.find_first_of(" ");
1477 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1478 +
1479 + }
1480 +
1481 +
1482 + //!jet valueLookup
1483   double
1484 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1484 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1485  
1486    double value = 0.0;
1487    if(variable == "energy") value = object->energy;
# Line 881 | Line 1600 | OSUAnalysis::valueLookup (const BNjet* o
1600    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1601    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1602  
1603 +  //user defined variable
1604 +  else if(variable == "disappTrkLeadingJetID") {
1605 +    value = object->pt > 110
1606 +      && fabs(object->eta) < 2.4
1607 +      && object->chargedHadronEnergyFraction > 0.2
1608 +      && object->neutralHadronEnergyFraction < 0.7
1609 +      && object->chargedEmEnergyFraction < 0.5
1610 +      && object->neutralEmEnergyFraction < 0.7;
1611 +  }
1612 +
1613 +  else if(variable == "disappTrkSubLeadingJetID") {
1614 +    value = object->pt > 30
1615 +      && fabs(object->eta) < 4.5
1616 +      && object->neutralHadronEnergyFraction < 0.7
1617 +      && object->chargedEmEnergyFraction < 0.5;
1618 +  }
1619 +
1620 +  else if(variable == "dPhiMet") {
1621 +    if (const BNmet *met = chosenMET ()) {
1622 +      value = deltaPhi (object->phi, met->phi);
1623 +    } else value = -999;
1624 +  }
1625 +
1626  
1627 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1627 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1628  
1629    value = applyFunction(function, value);
1630  
1631    return value;
1632 < }
891 <
1632 > } // end jet valueLookup
1633  
1634  
1635 + //!muon valueLookup
1636   double
1637 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1637 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1638  
1639    double value = 0.0;
1640    if(variable == "energy") value = object->energy;
# Line 984 | Line 1726 | OSUAnalysis::valueLookup (const BNmuon*
1726    else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1727    else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1728    else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1729 +  else if(variable == "chargedHadronIsoDR04") value = object->chargedHadronIsoDR04;
1730 +  else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1731 +  else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1732 +  else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1733    else if(variable == "rhoPrime") value = object->rhoPrime;
1734    else if(variable == "AEffDr03") value = object->AEffDr03;
1735    else if(variable == "AEffDr04") value = object->AEffDr04;
# Line 991 | Line 1737 | OSUAnalysis::valueLookup (const BNmuon*
1737    else if(variable == "pfIsoR03SumNeutralHadronEt") value = object->pfIsoR03SumNeutralHadronEt;
1738    else if(variable == "pfIsoR03SumPhotonEt") value = object->pfIsoR03SumPhotonEt;
1739    else if(variable == "pfIsoR03SumPUPt") value = object->pfIsoR03SumPUPt;
1740 +  else if(variable == "relpfIsoR04SumExceptChargedHad") value = (object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)/ object->pt;
1741 +  else if(variable == "relpfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt/object->pt;
1742 +  else if(variable == "relpfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt/object->pt;
1743 +  else if(variable == "relpfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt/object->pt;
1744 +  else if(variable == "relpfIsoR04SumPUPt") value = object->pfIsoR04SumPUPt/object->pt;
1745    else if(variable == "pfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt;
1746    else if(variable == "pfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt;
1747    else if(variable == "pfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt;
# Line 1047 | Line 1798 | OSUAnalysis::valueLookup (const BNmuon*
1798    else if(variable == "time_ndof") value = object->time_ndof;
1799  
1800    //user-defined variables
1801 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenPrimaryVertex->xError, chosenPrimaryVertex->yError));
1802 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenPrimaryVertex->xError, chosenPrimaryVertex->yError));
1801 >  else if(variable == "looseID") {
1802 >    value = object->pt > 10 &&
1803 >      (object->isGlobalMuon  > 0 ||
1804 >       object->isTrackerMuon > 0);
1805 >  }
1806 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1807 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1808    else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1809 <  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1809 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1810 >  else if(variable == "relPFdBetaIsoPseudo") value = (object->pfIsoR04SumChargedHadronPt + object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt) / object->pt;
1811    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1812 +  else if(variable == "metMT") {
1813 +    if (const BNmet *met = chosenMET ())
1814 +      {
1815 +        double dPhi = deltaPhi (object->phi, met->phi);
1816 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1817 +      }
1818 +    else
1819 +      value = -999;
1820 +  }
1821  
1822  
1823  
# Line 1162 | Line 1928 | OSUAnalysis::valueLookup (const BNmuon*
1928  
1929  
1930    else if(variable == "tightID") {
1931 <    value = object->isGlobalMuon > 0            \
1932 <      && object->isPFMuon > 0                   \
1933 <      && object->normalizedChi2 < 10            \
1934 <      && object->numberOfValidMuonHits > 0      \
1935 <      && object->numberOfMatchedStations > 1    \
1936 <      && fabs(object->correctedD0Vertex) < 0.2  \
1937 <      && fabs(object->correctedDZ) < 0.5        \
1938 <      && object->numberOfValidPixelHits > 0             \
1931 >    value = object->isGlobalMuon > 0                \
1932 >      && object->isPFMuon > 0                        \
1933 >      && object->normalizedChi2 < 10                \
1934 >      && object->numberOfValidMuonHits > 0        \
1935 >      && object->numberOfMatchedStations > 1        \
1936 >      && fabs(object->correctedD0Vertex) < 0.2        \
1937 >      && fabs(object->correctedDZ) < 0.5        \
1938 >      && object->numberOfValidPixelHits > 0                \
1939        && object->numberOfLayersWithMeasurement > 5;
1940    }
1941    else if(variable == "tightIDdisplaced"){
1942 <    value = object->isGlobalMuon > 0            \
1943 <      && object->normalizedChi2 < 10            \
1944 <      && object->numberOfValidMuonHits > 0      \
1945 <      && object->numberOfMatchedStations > 1    \
1946 <      && object->numberOfValidPixelHits > 0     \
1942 >    value = object->isGlobalMuon > 0                \
1943 >      && object->isPFMuon > 0                        \
1944 >      && object->normalizedChi2 < 10                \
1945 >      && object->numberOfValidMuonHits > 0        \
1946 >      && object->numberOfMatchedStations > 1        \
1947 >      && object->numberOfValidPixelHits > 0        \
1948        && object->numberOfLayersWithMeasurement > 5;
1949    }
1950  
1951 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1952  
1953 +  else if(variable == "genMatchedPdgId"){
1954 +    int index = getGenMatchedParticleIndex(object);
1955 +    if(index == -1) value = 0;
1956 +    else value = mcparticles->at(index).id;
1957 +  }
1958  
1959    else if(variable == "genMatchedId"){
1960      int index = getGenMatchedParticleIndex(object);
# Line 1193 | Line 1966 | OSUAnalysis::valueLookup (const BNmuon*
1966      if(index == -1) value = 0;
1967      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1968    }
1969 +  else if(variable == "genMatchedMotherIdReverse"){
1970 +    int index = getGenMatchedParticleIndex(object);
1971 +    if(index == -1) value = 24;
1972 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1973 +  }
1974    else if(variable == "genMatchedGrandmotherId"){
1975      int index = getGenMatchedParticleIndex(object);
1976      if(index == -1) value = 0;
# Line 1203 | Line 1981 | OSUAnalysis::valueLookup (const BNmuon*
1981      }
1982      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1983    }
1984 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1985 +    int index = getGenMatchedParticleIndex(object);
1986 +    if(index == -1) value = 24;
1987 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1988 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1989 +      if(motherIndex == -1) value = 24;
1990 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1991 +    }
1992 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1993 +  }
1994 +  else if(variable == "pfMuonsFromVertex"){
1995 +    double d0Error, dzError;
1996  
1997 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1998 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1999 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2000 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2001 +      || fabs (object->correctedDZ / dzError) > 99.0;
2002 +    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
2003 +  }
2004  
2005  
2006 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2006 >
2007 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2008  
2009    value = applyFunction(function, value);
2010  
2011    return value;
2012 < }
2012 > } // end muon valueLookup
2013  
2014  
2015 + //!electron valueLookup
2016   double
2017 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
2017 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
2018  
2019    double value = 0.0;
2020    if(variable == "energy") value = object->energy;
# Line 1376 | Line 2175 | OSUAnalysis::valueLookup (const BNelectr
2175    else if(variable == "passConvVeto") value = object->passConvVeto;
2176  
2177    //user-defined variables
2178 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenPrimaryVertex->xError, chosenPrimaryVertex->yError));
2179 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenPrimaryVertex->xError, chosenPrimaryVertex->yError));
2178 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2179 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2180    else if(variable == "detIso") value = (object->trackIso) / object->pt;
2181    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2182 <
2182 >  else if(variable == "relPFrhoIsoEB") value = object->isEB ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2183 >  else if(variable == "relPFrhoIsoEE") value = object->isEE ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2184 >  else if(variable == "metMT") {
2185 >    if (const BNmet *met = chosenMET ())
2186 >      {
2187 >        double dPhi = deltaPhi (object->phi, met->phi);
2188 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2189 >      }
2190 >    else
2191 >      value = -999;
2192 >  }
2193  
2194    else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
2195      if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
# Line 1391 | Line 2200 | OSUAnalysis::valueLookup (const BNelectr
2200      else value = -999;
2201    }
2202  
1394
2203    else if(variable == "correctedD0VertexInEBPlus"){
2204      if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
2205      else value = -999;
# Line 1444 | Line 2252 | OSUAnalysis::valueLookup (const BNelectr
2252      else value = -999;
2253    }
2254  
2255 +  else if(variable == "looseID"){
2256 +    if (object->isEB)
2257 +      {
2258 +        value = fabs(object->delEtaIn) < 0.007 \
2259 +          && fabs (object->delPhiIn) < 0.15 \
2260 +          && object->scSigmaIEtaIEta < 0.01 \
2261 +          && object->hadOverEm < 0.12 \
2262 +          && fabs (object->correctedD0Vertex) < 0.02 \
2263 +          && fabs (object->correctedDZ) < 0.2 \
2264 +          && object->absInvEMinusInvPin < 0.05 \
2265 +          && object->passConvVeto;
2266 +      }
2267 +    else
2268 +      {
2269 +        value = fabs(object->delEtaIn) < 0.009 \
2270 +          && fabs (object->delPhiIn) < 0.10 \
2271 +          && object->scSigmaIEtaIEta < 0.03 \
2272 +          && object->hadOverEm < 0.10 \
2273 +          && fabs (object->correctedD0Vertex) < 0.02 \
2274 +          && fabs (object->correctedDZ) < 0.2 \
2275 +          && object->absInvEMinusInvPin < 0.05 \
2276 +          && object->passConvVeto;
2277 +      }
2278 +  }
2279 +
2280 +  else if(variable == "tightID"){
2281 +    if (object->isEB)
2282 +      {
2283 +        value = fabs(object->delEtaIn) < 0.004 \
2284 +          && fabs (object->delPhiIn) < 0.03 \
2285 +          && object->scSigmaIEtaIEta < 0.01 \
2286 +          && object->hadOverEm < 0.12 \
2287 +          && fabs (object->correctedD0Vertex) < 0.02 \
2288 +          && fabs (object->correctedDZ) < 0.1 \
2289 +          && object->absInvEMinusInvPin < 0.05 \
2290 +          && object->passConvVeto;
2291 +      }
2292 +    else
2293 +      {
2294 +        value = fabs(object->delEtaIn) < 0.005 \
2295 +          && fabs (object->delPhiIn) < 0.02 \
2296 +          && object->scSigmaIEtaIEta < 0.03 \
2297 +          && object->hadOverEm < 0.10 \
2298 +          && fabs (object->correctedD0Vertex) < 0.02 \
2299 +          && fabs (object->correctedDZ) < 0.1 \
2300 +          && object->absInvEMinusInvPin < 0.05 \
2301 +          && object->passConvVeto;
2302 +      }
2303 +  }
2304  
2305 +  else if(variable == "looseID_MVA"){
2306 +    value = object->pt > 10
2307 +      && object->mvaNonTrigV0 > 0;
2308 +      }
2309    else if(variable == "correctedD0VertexInEBPositiveCharge"){
2310      if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2311      else value = -999;
# Line 1501 | Line 2362 | OSUAnalysis::valueLookup (const BNelectr
2362    else if(variable == "tightIDdisplaced"){
2363      if (object->isEB)
2364        {
2365 <        value = fabs(object->delEtaIn) < 0.004 \
2366 <          && fabs (object->delPhiIn) < 0.03 \
2365 >        value = fabs(object->delEtaIn) < 0.004 \
2366 >          && fabs (object->delPhiIn) < 0.03 \
2367            && object->scSigmaIEtaIEta < 0.01 \
2368            && object->hadOverEm < 0.12 \
2369 <          && object->absInvEMinusInvPin < 0.05;
2369 >          && object->absInvEMinusInvPin < 0.05;
2370        }
2371      else
2372        {
2373 <        value = fabs (object->delEtaIn) < 0.005 \
2374 <          && fabs (object->delPhiIn) < 0.02 \
2373 >        value = fabs (object->delEtaIn) < 0.005 \
2374 >          && fabs (object->delPhiIn) < 0.02 \
2375            && object->scSigmaIEtaIEta < 0.03 \
2376            && object->hadOverEm < 0.10 \
2377 <          && object->absInvEMinusInvPin < 0.05;
2377 >          && object->absInvEMinusInvPin < 0.05;
2378        }
2379    }
2380  
2381 +
2382 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2383 +
2384 +  else if(variable == "genMatchedPdgId"){
2385 +    int index = getGenMatchedParticleIndex(object);
2386 +    if(index == -1) value = 0;
2387 +    else value = mcparticles->at(index).id;
2388 +  }
2389 +
2390 +
2391    else if(variable == "genMatchedId"){
2392      int index = getGenMatchedParticleIndex(object);
2393      if(index == -1) value = 0;
# Line 1527 | Line 2398 | OSUAnalysis::valueLookup (const BNelectr
2398      if(index == -1) value = 0;
2399      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2400    }
2401 +  else if(variable == "genMatchedMotherIdReverse"){
2402 +    int index = getGenMatchedParticleIndex(object);
2403 +    if(index == -1) value = 24;
2404 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2405 +  }
2406    else if(variable == "genMatchedGrandmotherId"){
2407      int index = getGenMatchedParticleIndex(object);
2408      if(index == -1) value = 0;
# Line 1537 | Line 2413 | OSUAnalysis::valueLookup (const BNelectr
2413      }
2414      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2415    }
2416 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2417 +    int index = getGenMatchedParticleIndex(object);
2418 +    if(index == -1) value = 24;
2419 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2420 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2421 +      if(motherIndex == -1) value = 24;
2422 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2423 +    }
2424 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2425 +  }
2426 +  else if(variable == "pfElectronsFromVertex"){
2427 +    double d0Error, dzError;
2428  
2429 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2430 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2431 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2432 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2433 +      || fabs (object->correctedDZ / dzError) > 99.0;
2434 +    value = !value;
2435 +  }
2436  
2437  
2438 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2438 >
2439 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2440  
2441    value = applyFunction(function, value);
2442  
2443    return value;
2444 < }
2444 > } // end electron valueLookup
2445  
2446  
2447 + //!event valueLookup
2448   double
2449 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2449 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2450  
2451    double value = 0.0;
2452  
# Line 1557 | Line 2454 | OSUAnalysis::valueLookup (const BNevent*
2454    else if(variable == "pthat") value = object->pthat;
2455    else if(variable == "qScale") value = object->qScale;
2456    else if(variable == "alphaQCD") value = object->alphaQCD;
2457 +  else if(variable == "Ht") value = getHt(jets.product());
2458    else if(variable == "alphaQED") value = object->alphaQED;
2459    else if(variable == "scalePDF") value = object->scalePDF;
2460    else if(variable == "x1") value = object->x1;
# Line 1617 | Line 2515 | OSUAnalysis::valueLookup (const BNevent*
2515    else if(variable == "id1") value = object->id1;
2516    else if(variable == "id2") value = object->id2;
2517    else if(variable == "evt") value = object->evt;
2518 <
2519 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2518 >  else if(variable == "puScaleFactor"){
2519 >    if(doPileupReweighting_ && datasetType_ != "data")
2520 >      value = puWeight_->at (events->at (0).numTruePV);
2521 >    else
2522 >      value = 1.0;
2523 >  }
2524 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2525 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2526 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2527 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2528 >  else if(variable == "ht") value = chosenHT ();
2529 >  else if(variable == "leadMuPairInvMass"){
2530 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2531 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2532 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2533 >    value = (p0 + p1).M ();
2534 >  }
2535 >  else if(variable == "leadMuPairPt"){
2536 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2537 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2538 >             pt1 (muPair.second->px, muPair.second->py);
2539 >    pt0 += pt1;
2540 >    value = pt0.Mod ();
2541 >  }
2542 >  else if(variable == "leadElPairInvMass"){
2543 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2544 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2545 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2546 >    value = (p0 + p1).M ();
2547 >  }
2548 >  else if(variable == "leadElPairPt"){
2549 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2550 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2551 >             pt1 (muPair.second->px, muPair.second->py);
2552 >    pt0 += pt1;
2553 >    value = pt0.Mod ();
2554 >  }
2555 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2556  
2557    value = applyFunction(function, value);
2558  
2559    return value;
2560 < }
2560 > } // end event valueLookup
2561 >
2562  
2563 + //!tau valueLookup
2564   double
2565 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2565 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2566  
2567    double value = 0.0;
2568  
# Line 1670 | Line 2606 | OSUAnalysis::valueLookup (const BNtau* o
2606    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2607    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2608  
2609 +  else if (variable == "looseHadronicID") {
2610 +    value = object->pt > 10
2611 +      && object->eta < 2.3
2612 +      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2613 +      && object->HPSdecayModeFinding > 0
2614 +      && object->HPSagainstElectronLoose > 0
2615 +      && object->HPSagainstMuonTight > 0;
2616 +  }
2617 +
2618 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2619 +
2620 +  else if(variable == "genMatchedPdgId"){
2621 +    int index = getGenMatchedParticleIndex(object);
2622 +    if(index == -1) value = 0;
2623 +    else value = mcparticles->at(index).id;
2624 +  }
2625  
2626    else if(variable == "genMatchedId"){
2627      int index = getGenMatchedParticleIndex(object);
# Line 1681 | Line 2633 | OSUAnalysis::valueLookup (const BNtau* o
2633      if(index == -1) value = 0;
2634      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2635    }
2636 +  else if(variable == "genMatchedMotherIdReverse"){
2637 +    int index = getGenMatchedParticleIndex(object);
2638 +    if(index == -1) value = 24;
2639 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2640 +  }
2641    else if(variable == "genMatchedGrandmotherId"){
2642      int index = getGenMatchedParticleIndex(object);
2643      if(index == -1) value = 0;
# Line 1691 | Line 2648 | OSUAnalysis::valueLookup (const BNtau* o
2648      }
2649      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2650    }
2651 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2652 +    int index = getGenMatchedParticleIndex(object);
2653 +    if(index == -1) value = 24;
2654 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2655 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2656 +      if(motherIndex == -1) value = 24;
2657 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2658 +    }
2659 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2660 +  }
2661  
2662  
2663 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2663 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2664  
2665    value = applyFunction(function, value);
2666  
2667    return value;
2668 < }
2668 > } // end tau valueLookup
2669  
2670 +
2671 + //!met valueLookup
2672   double
2673 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2673 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2674  
2675    double value = 0.0;
2676  
# Line 1765 | Line 2734 | OSUAnalysis::valueLookup (const BNmet* o
2734    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2735    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2736  
2737 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2737 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2738  
2739    value = applyFunction(function, value);
2740  
2741    return value;
2742 < }
2742 > } // end met valueLookup
2743  
2744 +
2745 + //!track valueLookup
2746   double
2747 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2747 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2748  
2749    double value = 0.0;
2750    double pMag = sqrt(object->pt * object->pt +
2751 <                         object->pz * object->pz);
2752 <  
2751 >                     object->pz * object->pz);
2752 >
2753    if(variable == "pt") value = object->pt;
2754    else if(variable == "px") value = object->px;
2755    else if(variable == "py") value = object->py;
# Line 1797 | Line 2768 | OSUAnalysis::valueLookup (const BNtrack*
2768    else if(variable == "numValidHits") value = object->numValidHits;
2769    else if(variable == "isHighPurity") value = object->isHighPurity;
2770  
2771 <
2772 <  //additional BNs info for disappTrks  
2773 <  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2774 <  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2775 <  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2776 <  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2777 <  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2778 <  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2779 <  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
1809 <  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
1810 <  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2771 >  //additional BNs info for disappTrks
2772 >  else if(variable == "caloEMDeltaRp3")     value = object->caloEMDeltaRp3;
2773 >  else if(variable == "caloHadDeltaRp3")    value = object->caloHadDeltaRp3;
2774 >  else if(variable == "caloEMDeltaRp4")     value = object->caloEMDeltaRp4;
2775 >  else if(variable == "caloHadDeltaRp4")    value = object->caloHadDeltaRp4;
2776 >  else if(variable == "caloEMDeltaRp5")     value = object->caloEMDeltaRp5;
2777 >  else if(variable == "caloHadDeltaRp5")    value = object->caloHadDeltaRp5;
2778 >  else if(variable == "nHitsMissingOuter")  value = object->nHitsMissingOuter;
2779 >  else if(variable == "nHitsMissingInner")  value = object->nHitsMissingInner;
2780    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2781 +  else if(variable == "depTrkRp3")          value = object->depTrkRp3;
2782 +  else if(variable == "trkRelIsoRp3")     { value = (object->depTrkRp3 - object->pt) / object->pt; if (value<0) value = 0; }
2783 +  else if(variable == "trkRelIsoRp5")     { value = (object->depTrkRp5 - object->pt) / object->pt; if (value<0) value = 0; }
2784 +  else if(variable == "depEcalRp3")         value = object->depEcalRp3;
2785 +  else if(variable == "depHcalRp3")         value = object->depHcalRp3;
2786 +  else if(variable == "depHoRp3")           value = object->depHoRp3;
2787 +  else if(variable == "nTracksRp3")         value = object->nTracksRp3;
2788 +  else if(variable == "trackerVetoPtRp3")   value = object->trackerVetoPtRp3;
2789 +  else if(variable == "emVetoEtRp3")        value = object->emVetoEtRp3;
2790 +  else if(variable == "hadVetoEtRp3")       value = object->hadVetoEtRp3;
2791 +  else if(variable == "hoVetoEtRp3")        value = object->hoVetoEtRp3;
2792 +  else if(variable == "depTrkRp5")          value = object->depTrkRp5;
2793 +  else if(variable == "depEcalRp5")         value = object->depEcalRp5;
2794 +  else if(variable == "depHcalRp5")         value = object->depHcalRp5;
2795 +  else if(variable == "depHoRp5")           value = object->depHoRp5;
2796 +  else if(variable == "nTracksRp5")         value = object->nTracksRp5;
2797 +  else if(variable == "trackerVetoPtRp5")   value = object->trackerVetoPtRp5;
2798 +  else if(variable == "emVetoEtRp5")        value = object->emVetoEtRp5;
2799 +  else if(variable == "hadVetoEtRp5")       value = object->hadVetoEtRp5;
2800 +  else if(variable == "hoVetoEtRp5")        value = object->hoVetoEtRp5;
2801 +
2802    //user defined variables
2803    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;
2804    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2805 <  else if(variable == "caloTotDeltaRp5") value =(object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2806 <  else if(variable == "caloTotDeltaRp5ByP") value =( (object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2807 <  else if(variable == "isIso") value = getTrkIsIso(object, tracks.product());
2808 <  else if(variable == "isMatchedDeadEcal") value = getTrkIsMatchedDeadEcal(object);
2809 <  else if(variable == "ptErrorByPt") value = (object->ptError/object->pt);
2810 <  else if(variable == "ptError") value = object->ptError;
2811 <  else if(variable == "ptRes") value = getTrkPtRes(object);  
2805 >  else if(variable == "depTrkRp5MinusPt"){
2806 >    if ( (object->depTrkRp5 - object->pt) < 0 ) {
2807 > //       clog << "Warning:  found track with depTrkRp5 < pt:  depTrkRp5=" << object->depTrkRp5
2808 > //         << "; pt=" << object->pt
2809 > //         << "; object->depTrkRp5 - object->pt = " << object->depTrkRp5 - object->pt
2810 > //         << endl;  
2811 >           value = 0;
2812 >         }
2813 >         else value =  (object->depTrkRp5 - object->pt);
2814 >  }
2815 >  else if(variable == "depTrkRp3MinusPt"){
2816 >    if ( (object->depTrkRp3 - object->pt) < 0 ) {
2817 >      value = 0;
2818 >    }
2819 >    else value =  (object->depTrkRp3 - object->pt);
2820 >  }
2821 >
2822 >  else if(variable == "dPhiMet") {
2823 >    if (const BNmet *met = chosenMET ()) {
2824 >      value = deltaPhi (object->phi, met->phi);
2825 >    } else value = -999;
2826 >  }
2827 >  
2828 >  
2829 >  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2830 >  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2831 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2832 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2833 >  else if(variable == "depTrkRp5RhoCorr")           value = getTrkDepTrkRp5RhoCorr(object);
2834 >  else if(variable == "depTrkRp3RhoCorr")           value = getTrkDepTrkRp3RhoCorr(object);
2835 >
2836 >  else if(variable == "depTrkRp5MinusPtRhoCorr")    {
2837 >    if ( (getTrkDepTrkRp5RhoCorr(object) - object->pt) < 0 ) value = 0;
2838 >    else {value = (getTrkDepTrkRp5RhoCorr(object) - object->pt );}
2839 >  }
2840 >  
2841 >  else if(variable == "depTrkRp3MinusPtRhoCorr")    
2842 >    {
2843 >      if ( (getTrkDepTrkRp3RhoCorr(object) - object->pt) < 0 ) value = 0;
2844 >      else {value = (getTrkDepTrkRp3RhoCorr(object) - object->pt );}
2845 >    }
2846 >
2847 >  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2848 >  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2849 >  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2850 >  else if(variable == "ptError")                    value = object->ptError;
2851 >  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2852 >  else if (variable == "d0wrtPV"){
2853 >    double vx = object->vx - chosenVertex ()->x,
2854 >      vy = object->vy - chosenVertex ()->y,
2855 >      px = object->px,
2856 >      py = object->py,
2857 >      pt = object->pt;
2858 >    value = (-vx * py + vy * px) / pt;
2859 >  }
2860 >  else if (variable == "dZwrtPV"){
2861 >    double vx = object->vx - chosenVertex ()->x,
2862 >      vy = object->vy - chosenVertex ()->y,
2863 >      vz = object->vz - chosenVertex ()->z,
2864 >      px = object->px,
2865 >      py = object->py,
2866 >      pz = object->pz,
2867 >      pt = object->pt;
2868 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2869 >  }
2870 >
2871 >  else if(variable == "deltaRMinSubLeadJet") {
2872 >    // calculate minimum deltaR between track and any other subleading jet  
2873 >    double trkJetDeltaRMin = 99.;  
2874 >    for (uint ijet = 0; ijet<jets->size(); ijet++) {
2875 >      string empty = "";  
2876 >      double isSubLeadingJet = valueLookup(&jets->at(ijet), "disappTrkSubLeadingJetID", "", empty);  
2877 >      if (!isSubLeadingJet) continue;  // only consider jets that pass the subleading jet ID criteria  
2878 >      double jetEta = valueLookup(&jets->at(ijet), "eta", "", empty);
2879 >      double jetPhi = valueLookup(&jets->at(ijet), "phi", "", empty);
2880 >      double trkJetDeltaR = deltaR(object->eta, object->phi, jetEta, jetPhi);  
2881 >      if (trkJetDeltaR < trkJetDeltaRMin) trkJetDeltaRMin = trkJetDeltaR;
2882 >    }
2883 >    value = trkJetDeltaRMin;  
2884 >  }  
2885 >  
2886 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2887 >
2888 >  else if(variable == "genMatchedPdgId"){
2889 >    int index = getGenMatchedParticleIndex(object);
2890 >    if(index == -1) value = 0;
2891 >    else value = mcparticles->at(index).id;
2892 >  }
2893  
2894  
2895    else if(variable == "genMatchedId"){
# Line 1831 | Line 2902 | OSUAnalysis::valueLookup (const BNtrack*
2902      if(index == -1) value = 0;
2903      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2904    }
2905 +  else if(variable == "genMatchedMotherIdReverse"){
2906 +    int index = getGenMatchedParticleIndex(object);
2907 +    if(index == -1) value = 24;
2908 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2909 +  }
2910    else if(variable == "genMatchedGrandmotherId"){
2911      int index = getGenMatchedParticleIndex(object);
2912      if(index == -1) value = 0;
# Line 1841 | Line 2917 | OSUAnalysis::valueLookup (const BNtrack*
2917      }
2918      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2919    }
2920 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2921 +    int index = getGenMatchedParticleIndex(object);
2922 +    if(index == -1) value = 24;
2923 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2924 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2925 +      if(motherIndex == -1) value = 24;
2926 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2927 +    }
2928 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2929 +  }
2930  
2931  
2932  
2933 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2933 >  else{clog << "WARNING: invalid variable '" << variable << "' for BNtrack collection.\n"; value = -999;}
2934  
2935    value = applyFunction(function, value);
2936  
2937    return value;
2938 < }
2938 > } // end track valueLookup
2939 >
2940  
2941 + //!genjet valueLookup
2942   double
2943 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2943 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2944  
2945    double value = 0.0;
2946  
# Line 1872 | Line 2960 | OSUAnalysis::valueLookup (const BNgenjet
2960    else if(variable == "charge") value = object->charge;
2961  
2962  
2963 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2963 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2964  
2965    value = applyFunction(function, value);
2966  
2967    return value;
2968   }
2969  
2970 + //!mcparticle valueLookup
2971   double
2972 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2972 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2973  
2974    double value = 0.0;
2975  
# Line 1971 | Line 3060 | OSUAnalysis::valueLookup (const BNmcpart
3060  
3061    //user-defined variables
3062    else if (variable == "d0"){
3063 <    double vx = object->vx - chosenPrimaryVertex->x,
3064 <      vy = object->vy - chosenPrimaryVertex->y,
3063 >    double vx = object->vx - chosenVertex ()->x,
3064 >      vy = object->vy - chosenVertex ()->y,
3065        px = object->px,
3066        py = object->py,
3067        pt = object->pt;
3068      value = (-vx * py + vy * px) / pt;
3069    }
3070    else if (variable == "dz"){
3071 <    double vx = object->vx - chosenPrimaryVertex->x,
3072 <      vy = object->vy - chosenPrimaryVertex->y,
3073 <      vz = object->vz - chosenPrimaryVertex->z,
3071 >    double vx = object->vx - chosenVertex ()->x,
3072 >      vy = object->vy - chosenVertex ()->y,
3073 >      vz = object->vz - chosenVertex ()->z,
3074        px = object->px,
3075        py = object->py,
3076        pz = object->pz,
# Line 1992 | Line 3081 | OSUAnalysis::valueLookup (const BNmcpart
3081      value = sqrt(object->vx*object->vx + object->vy*object->vy);
3082    }
3083    else if(variable == "deltaV0"){
3084 <    value = sqrt((object->vx-chosenPrimaryVertex->x)*(object->vx-chosenPrimaryVertex->x) + (object->vy-chosenPrimaryVertex->y)*(object->vy-chosenPrimaryVertex->y));
3084 >    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
3085    }
3086    else if (variable == "deltaVx"){
3087 <    value = object->vx - chosenPrimaryVertex->x;
3087 >    value = object->vx - chosenVertex ()->x;
3088    }
3089    else if (variable == "deltaVy"){
3090 <    value = object->vy - chosenPrimaryVertex->y;
3090 >    value = object->vy - chosenVertex ()->y;
3091    }
3092    else if (variable == "deltaVz"){
3093 <    value = object->vz - chosenPrimaryVertex->z;
3093 >    value = object->vz - chosenVertex ()->z;
3094    }
3095  
3096  
3097 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3097 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3098  
3099    value = applyFunction(function, value);
3100  
3101    return value;
3102 < }
3102 > } // end mcparticle valueLookup
3103 >
3104  
3105 + //!primaryvertex valueLookup
3106   double
3107 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
3107 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
3108  
3109    double value = 0.0;
3110  
# Line 2032 | Line 3123 | OSUAnalysis::valueLookup (const BNprimar
3123    else if(variable == "isGood") value = object->isGood;
3124  
3125  
3126 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3126 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3127  
3128    value = applyFunction(function, value);
3129  
3130    return value;
3131   }
3132  
3133 + //!bxlumi valueLookup
3134   double
3135 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
3135 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
3136  
3137    double value = 0.0;
3138  
# Line 2049 | Line 3141 | OSUAnalysis::valueLookup (const BNbxlumi
3141    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
3142  
3143  
3144 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3144 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3145  
3146    value = applyFunction(function, value);
3147  
3148    return value;
3149   }
3150  
3151 + //!photon valueLookup
3152   double
3153 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
3153 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
3154  
3155    double value = 0.0;
3156  
# Line 2132 | Line 3225 | OSUAnalysis::valueLookup (const BNphoton
3225    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
3226  
3227  
3228 +
3229 +
3230 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3231 +
3232 +  else if(variable == "genMatchedPdgId"){
3233 +    int index = getGenMatchedParticleIndex(object);
3234 +    if(index == -1) value = 0;
3235 +    else value = mcparticles->at(index).id;
3236 +  }
3237 +
3238 +
3239 +
3240    else if(variable == "genMatchedId"){
3241      int index = getGenMatchedParticleIndex(object);
3242      if(index == -1) value = 0;
# Line 2142 | Line 3247 | OSUAnalysis::valueLookup (const BNphoton
3247      if(index == -1) value = 0;
3248      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
3249    }
3250 +  else if(variable == "genMatchedMotherIdReverse"){
3251 +    int index = getGenMatchedParticleIndex(object);
3252 +    if(index == -1) value = 24;
3253 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
3254 +  }
3255    else if(variable == "genMatchedGrandmotherId"){
3256      int index = getGenMatchedParticleIndex(object);
3257      if(index == -1) value = 0;
# Line 2152 | Line 3262 | OSUAnalysis::valueLookup (const BNphoton
3262      }
3263      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3264    }
3265 +  else if(variable == "genMatchedGrandmotherIdReverse"){
3266 +    int index = getGenMatchedParticleIndex(object);
3267 +    if(index == -1) value = 24;
3268 +    else if(fabs(mcparticles->at(index).motherId) == 15){
3269 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3270 +      if(motherIndex == -1) value = 24;
3271 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3272 +    }
3273 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3274 +  }
3275  
3276  
3277 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3277 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3278  
3279    value = applyFunction(function, value);
3280  
3281    return value;
3282 < }
3282 > } // end photon valueLookup
3283 >
3284  
3285 + //!supercluster valueLookup
3286   double
3287 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
3287 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
3288  
3289    double value = 0.0;
3290  
# Line 2176 | Line 3298 | OSUAnalysis::valueLookup (const BNsuperc
3298    else if(variable == "theta") value = object->theta;
3299  
3300  
3301 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3301 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3302  
3303    value = applyFunction(function, value);
3304  
3305    return value;
3306   }
3307  
3308 + //!trigobj valueLookup
3309 + double
3310 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3311 +
3312 +  double value = 0.0;
3313 +
3314 +  if(variable == "pt") value = object->pt;
3315 +  else if(variable == "eta") value = object->eta;
3316 +  else if(variable == "phi") value = object->phi;
3317 +  else if(variable == "px") value = object->px;
3318 +  else if(variable == "py") value = object->py;
3319 +  else if(variable == "pz") value = object->pz;
3320 +  else if(variable == "et") value = object->et;
3321 +  else if(variable == "energy") value = object->energy;
3322 +  else if(variable == "etTotal") value = object->etTotal;
3323 +  else if(variable == "id") value = object->id;
3324 +  else if(variable == "charge") value = object->charge;
3325 +  else if(variable == "isIsolated") value = object->isIsolated;
3326 +  else if(variable == "isMip") value = object->isMip;
3327 +  else if(variable == "isForward") value = object->isForward;
3328 +  else if(variable == "isRPC") value = object->isRPC;
3329 +  else if(variable == "bx") value = object->bx;
3330 +  else if(variable == "filter") {
3331 +    if ((stringValue = object->filter) == "")
3332 +      stringValue = "none";  // stringValue should only be empty if value is filled
3333 +  }
3334 +
3335 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3336 +
3337 +  value = applyFunction(function, value);
3338 +
3339 +  return value;
3340 + }
3341  
3342 + //!muon-muon pair valueLookup
3343   double
3344 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
3344 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3345  
3346    double value = 0.0;
3347  
3348    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3349 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3350    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3351    else if(variable == "invMass"){
3352      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3353      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3354 <
3355 <    value = (fourVector1 + fourVector2).M();}
3356 <
3354 >    value = (fourVector1 + fourVector2).M();
3355 >  }
3356 >  else if(variable == "pt"){
3357 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3358 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3359 >    value = (fourVector1 + fourVector2).Pt();
3360 >  }
3361    else if(variable == "threeDAngle")
3362      {
3363        TVector3 threeVector1(object1->px, object1->py, object1->pz);
# Line 2208 | Line 3369 | OSUAnalysis::valueLookup (const BNmuon*
3369        static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3370        TVector3 threeVector1(object1->px, object1->py, object1->pz);
3371        TVector3 threeVector2(object2->px, object2->py, object2->pz);
3372 <      value = (pi-threeVector1.Angle( threeVector2));
3372 >      value = (pi-threeVector1.Angle(threeVector2));
3373      }
2213
2214  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2215
2216
3374    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3375    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3376    else if(variable == "d0Sign"){
# Line 2222 | Line 3379 | OSUAnalysis::valueLookup (const BNmuon*
3379      else if (d0Sign > 0) value = 0.5;
3380      else value = -999;
3381    }
3382 +  else if(variable == "chargeProduct"){
3383 +    value = object1->charge*object2->charge;
3384 +  }
3385    else if(variable == "muon1CorrectedD0Vertex"){
3386      value = object1->correctedD0Vertex;
3387    }
3388    else if(variable == "muon2CorrectedD0Vertex"){
3389      value = object2->correctedD0Vertex;
3390    }
3391 < else if(variable == "muon1timeAtIpInOut"){
3391 >  else if(variable == "muon1timeAtIpInOut"){
3392      value = object1->timeAtIpInOut;
3393    }
3394 < else if(variable == "muon2timeAtIpInOut"){
3394 >  else if(variable == "muon2timeAtIpInOut"){
3395      value = object2->timeAtIpInOut;
3396    }
3397 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3397 >  else if(variable == "muon1correctedD0")
3398 >    {
3399 >      value = object1->correctedD0;
3400 >    }
3401 >  else if(variable == "muon2correctedD0")
3402 >    {
3403 >      value = object2->correctedD0;
3404 >    }
3405  
3406 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3407  
3408 +  value = applyFunction(function, value);
3409  
3410 +  return value;
3411 + } // end muon-muon pair valueLookup
3412  
2242
3413  
3414 + //!muon-photon pair valueLookup
3415 + double
3416 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3417  
3418 +  double value = 0.0;
3419 +
3420 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3421 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3422 +  else if(variable == "photonEta") value = object2->eta;
3423 +  else if(variable == "photonPt") value = object2->pt;
3424 +  else if(variable == "muonEta") value = object1->eta;
3425 +  else if(variable == "photonPhi") value = object2->phi;
3426 +  else if(variable == "muonPhi") value = object1->phi;
3427 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3428 +  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3429 +  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3430 +  else if(variable == "invMass"){
3431 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3432 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3433 +    value = (fourVector1 + fourVector2).M();
3434 +  }
3435 +  else if(variable == "pt"){
3436 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3437 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3438 +    value = (fourVector1 + fourVector2).Pt();
3439 +  }
3440 +  else if(variable == "threeDAngle")
3441 +    {
3442 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3443 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3444 +      value = (threeVector1.Angle(threeVector2));
3445 +    }
3446 +  else if(variable == "alpha")
3447 +    {
3448 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3449 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3450 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3451 +      value = (pi-threeVector1.Angle(threeVector2));
3452 +    }
3453 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3454  
3455    value = applyFunction(function, value);
3456  
3457    return value;
3458   }
3459  
3460 + //!electron-photon pair valueLookup
3461   double
3462 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
3462 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3463  
3464    double value = 0.0;
3465  
3466    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3467 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3468 +  else if(variable == "photonEta") value = object2->eta;
3469 +  else if(variable == "photonPt") value = object2->pt;
3470 +  else if(variable == "electronEta") value = object1->eta;
3471 +  else if(variable == "photonPhi") value = object2->phi;
3472 +  else if(variable == "electronPhi") value = object1->phi;
3473    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3474 +  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3475 +  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3476    else if(variable == "invMass"){
3477      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3478      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3479 <
3480 <    value = (fourVector1 + fourVector2).M();}
3481 < else if(variable == "threeDAngle")
3479 >    value = (fourVector1 + fourVector2).M();
3480 >  }
3481 >  else if(variable == "pt"){
3482 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3483 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3484 >    value = (fourVector1 + fourVector2).Pt();
3485 >  }
3486 >  else if(variable == "threeDAngle")
3487      {
3488        TVector3 threeVector1(object1->px, object1->py, object1->pz);
3489        TVector3 threeVector2(object2->px, object2->py, object2->pz);
3490        value = (threeVector1.Angle(threeVector2));
3491      }
3492 <  
3493 <
3494 <
3492 >  else if(variable == "alpha")
3493 >    {
3494 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3495 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3496 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3497 >      value = (pi-threeVector1.Angle(threeVector2));
3498 >    }
3499 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3500  
3501 <  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2274 <  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3501 >  value = applyFunction(function, value);
3502  
3503 <  else if(variable == "d0Sign") value = object1->correctedD0Vertex*object2->correctedD0Vertex/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3503 >  return value;
3504 > }
3505  
3506 + //!electron-electron pair valueLookup
3507 + double
3508 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3509  
3510 +  double value = 0.0;
3511  
3512 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3513 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3514 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3515 +  else if(variable == "invMass"){
3516 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3517 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3518 +    value = (fourVector1 + fourVector2).M();
3519 +  }
3520 +  else if(variable == "pt"){
3521 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3522 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3523 +    value = (fourVector1 + fourVector2).Pt();
3524 +  }
3525 +  else if(variable == "threeDAngle")
3526 +    {
3527 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3528 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3529 +      value = (threeVector1.Angle(threeVector2));
3530 +    }
3531 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3532 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3533    else if(variable == "d0Sign"){
3534      double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3535      if(d0Sign < 0) value = -0.5;
3536      else if (d0Sign > 0) value = 0.5;
3537      else value = -999;
3538    }
3539 +  else if(variable == "chargeProduct"){
3540 +    value = object1->charge*object2->charge;
3541 +  }
3542    else if(variable == "electron1CorrectedD0Vertex"){
3543      value = object1->correctedD0Vertex;
3544    }
3545    else if(variable == "electron2CorrectedD0Vertex"){
3546      value = object2->correctedD0Vertex;
3547    }
3548 +  else if(variable == "electron1CorrectedD0"){
3549 +    value = object1->correctedD0;
3550 +  }
3551 +  else if(variable == "electron2CorrectedD0"){
3552 +    value = object2->correctedD0;
3553 +  }
3554  
3555 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3555 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3556  
3557    value = applyFunction(function, value);
3558  
3559    return value;
3560   }
3561  
3562 + //!electron-muon pair valueLookup
3563   double
3564 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3564 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3565  
3566    double value = 0.0;
3567  
3568    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3569 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3570    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3571    else if(variable == "invMass"){
3572      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3573      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3574 <
3575 <    value = (fourVector1 + fourVector2).M();}
3576 < else if(variable == "threeDAngle")
3574 >    value = (fourVector1 + fourVector2).M();
3575 >  }
3576 >  else if(variable == "pt"){
3577 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3578 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3579 >    value = (fourVector1 + fourVector2).Pt();
3580 >  }
3581 >  else if(variable == "threeDAngle")
3582      {
3583        TVector3 threeVector1(object1->px, object1->py, object1->pz);
3584        TVector3 threeVector2(object2->px, object2->py, object2->pz);
3585        value = (threeVector1.Angle(threeVector2));
3586      }
2318
2319
3587    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3588    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3589    else if(variable == "d0Sign"){
# Line 2325 | Line 3592 | OSUAnalysis::valueLookup (const BNelectr
3592      else if (d0Sign > 0) value = 0.5;
3593      else value = -999;
3594    }
3595 +  else if(variable == "chargeProduct"){
3596 +    value = object1->charge*object2->charge;
3597 +  }
3598    else if(variable == "electronCorrectedD0Vertex"){
3599      value = object1->correctedD0Vertex;
3600    }
# Line 2337 | Line 3607 | OSUAnalysis::valueLookup (const BNelectr
3607    else if(variable == "muonCorrectedD0"){
3608      value = object2->correctedD0;
3609    }
3610 +  else if(variable == "electronDetIso"){
3611 +    value = (object1->trackIso) / object1->pt;
3612 +  }
3613 +  else if(variable == "muonDetIso"){
3614 +    value = (object2->trackIsoDR03) / object2->pt;
3615 +  }
3616 +  else if(variable == "electronRelPFrhoIso"){
3617 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3618 +  }
3619 +  else if(variable == "muonRelPFdBetaIso"){
3620 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3621 +  }
3622 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3623 +  value = applyFunction(function, value);
3624 +
3625 +  return value;
3626 + } // end electron-muon pair valueLookup
3627 +
3628 +
3629 + //!electron-jet pair valueLookup
3630 + double
3631 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3632 +
3633 +  double value = 0.0;
3634 +
3635 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3636 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3637 +  else if(variable == "jetEta") value = object2->eta;
3638 +  else if(variable == "jetPhi") value = object2->phi;
3639 +  else if(variable == "electronEta") value = object1->eta;
3640 +  else if(variable == "electronPhi") value = object1->phi;
3641 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3642 +  else if(variable == "invMass"){
3643 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3644 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3645 +    value = (fourVector1 + fourVector2).M();
3646 +  }
3647 +  else if(variable == "pt"){
3648 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3649 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3650 +    value = (fourVector1 + fourVector2).Pt();
3651 +  }
3652 +  else if(variable == "threeDAngle")
3653 +    {
3654 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3655 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3656 +      value = (threeVector1.Angle(threeVector2));
3657 +    }
3658 +  else if(variable == "chargeProduct"){
3659 +    value = object1->charge*object2->charge;
3660 +  }
3661 +
3662 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3663 +  value = applyFunction(function, value);
3664 +
3665 +  return value;
3666 + }
3667 +
3668 + //!photon-jet pair valueLookup
3669 + double
3670 + OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3671 +
3672 +  double value = 0.0;
3673 +
3674 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3675 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3676 +  else if(variable == "jetEta") value = object2->eta;
3677 +  else if(variable == "jetPhi") value = object2->phi;
3678 +  else if(variable == "photonEta") value = object1->eta;
3679 +  else if(variable == "photonPhi") value = object1->phi;
3680 +  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3681 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3682 +  else if(variable == "invMass"){
3683 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3684 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3685 +    value = (fourVector1 + fourVector2).M();
3686 +  }
3687 +  else if(variable == "pt"){
3688 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3689 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3690 +    value = (fourVector1 + fourVector2).Pt();
3691 +  }
3692 +  else if(variable == "threeDAngle")
3693 +    {
3694 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3695 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3696 +      value = (threeVector1.Angle(threeVector2));
3697 +    }
3698 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3699 +  value = applyFunction(function, value);
3700 +
3701 +  return value;
3702 + }
3703 +
3704 + // track-jet pair valueLookup
3705 + double
3706 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNjet* object2, string variable, string function, string &stringValue){
3707 +
3708 +  double value = 0.0;
3709 +
3710 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3711 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3712 +
3713 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3714 +  value = applyFunction(function, value);
3715 +
3716 +  return value;
3717 +
3718 + }
3719 +
3720 +
3721 +
3722 + // met-jet pair valueLookup
3723 + double
3724 + OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3725 +
3726 +  double value = 0.0;
3727 +
3728 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3729 +
3730 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3731 +  value = applyFunction(function, value);
3732 +
3733 +  return value;
3734 +
3735 + }  
3736 +
3737 +
3738 +
3739 + //!muon-jet pair valueLookup
3740 + double
3741 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3742 +
3743 +  double value = 0.0;
3744 +
3745 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3746 +  else if(variable == "jetEta") value = object2->eta;
3747 +  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3748 +  else if(variable == "jetPt") value = object2->pt;
3749 +  else if(variable == "jetPhi") value = object2->phi;
3750 +  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3751 +  else if(variable == "muonEta") value = object1->eta;
3752 +  else if(variable == "muonPt") value = object1->pt;
3753 +  else if(variable == "muonPhi") value = object1->phi;
3754 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3755 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3756 +  else if(variable == "invMass"){
3757 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3758 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3759 +    value = (fourVector1 + fourVector2).M();
3760 +  }
3761 +  else if(variable == "pt"){
3762 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3763 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3764 +    value = (fourVector1 + fourVector2).Pt();
3765 +  }
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 + //!muon-event valueLookup
3783 + double
3784 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNevent* object2, string variable, string function, string &stringValue){
3785 +
3786 +  double value = 0.0;
3787 +
3788 +  if(variable == "muonEta") value = object1->eta;
3789 +  else if(variable == "muonPt") value = object1->pt;
3790 +  else if(variable == "muonPhi") value = object1->phi;
3791 +  else if(variable == "Ht") value = getHt(jets.product());
3792 +  else if(variable == "pthat")   value = object2->pthat;
3793 +  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3794 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3795 +  value = applyFunction(function, value);
3796 +
3797 +  return value;
3798 + }
3799 + //!jet-jet pair valueLookup
3800 + double
3801 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3802 +
3803 +  double value = 0.0;
3804 +
3805 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3806 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3807 +  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3808 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3809 +  else if(variable == "invMass"){
3810 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3811 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3812 +    value = (fourVector1 + fourVector2).M();
3813 +  }
3814 +  else if(variable == "pt"){
3815 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3816 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3817 +    value = (fourVector1 + fourVector2).Pt();
3818 +  }
3819 +  else if(variable == "threeDAngle")
3820 +    {
3821 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3822 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3823 +      value = (threeVector1.Angle(threeVector2));
3824 +    }
3825 +  else if(variable == "chargeProduct"){
3826 +    value = object1->charge*object2->charge;
3827 +  }
3828 +
3829 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3830 +  value = applyFunction(function, value);
3831 +
3832 +  return value;
3833 + }
3834 +
3835 + //!electron-track pair valueLookup
3836 + double
3837 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
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 == "deltaEta") value = fabs(object1->eta - object2->eta);
3844 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3845 +  else if(variable == "invMass"){
3846 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3847 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3848 +
3849 +    value = (fourVector1 + fourVector2).M();
3850 +  }
3851 +  else if(variable == "chargeProduct"){
3852 +    value = object1->charge*object2->charge;
3853 +  }
3854 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3855 +  value = applyFunction(function, value);
3856 +  return value;
3857 +
3858 + }
3859 +
3860 +
3861 + //!muon-track pair valueLookup
3862 + double
3863 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3864 +  double pionMass = 0.140;
3865 +  double muonMass = 0.106;
3866 +  double value = 0.0;
3867 +  TLorentzVector fourVector1(0, 0, 0, 0);
3868 +  TLorentzVector fourVector2(0, 0, 0, 0);
3869 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3870 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3871 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3872 +  else if(variable == "invMass"){
3873 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3874 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3875 +
3876 +    value = (fourVector1 + fourVector2).M();
3877 +  }
3878 +  else if(variable == "chargeProduct"){
3879 +    value = object1->charge*object2->charge;
3880 +  }
3881 +
3882 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3883 +  value = applyFunction(function, value);
3884 +  return value;
3885 + }
3886 +
3887 + //!tau-tau pair valueLookup
3888 + double
3889 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3890 +  double value = 0.0;
3891 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3892 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3893 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3894 +  else if(variable == "invMass"){
3895 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3896 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3897 +    value = (fourVector1 + fourVector2).M();
3898 +  }
3899 +
3900 +  else if(variable == "chargeProduct"){
3901 +    value = object1->charge*object2->charge;
3902 +  }
3903 +
3904 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3905 +  value = applyFunction(function, value);
3906 +  return value;
3907 + }
3908 +
3909 + //!muon-tau pair valueLookup
3910 + double
3911 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3912 +  double value = 0.0;
3913 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3914 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3915 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3916 +  else if(variable == "invMass"){
3917 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3918 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3919 +    value = (fourVector1 + fourVector2).M();
3920 +  }
3921 +
3922 +  else if(variable == "chargeProduct"){
3923 +    value = object1->charge*object2->charge;
3924 +  }
3925 +
3926 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3927 +  value = applyFunction(function, value);
3928 +  return value;
3929 + }
3930 +
3931 + //!tau-track pair valueLookup
3932 + double
3933 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3934 +  double value = 0.0;
3935 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3936 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3937 +  else if(variable == "chargeProduct"){
3938 +    value = object1->charge*object2->charge;
3939 +  }
3940  
3941 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3942 +  value = applyFunction(function, value);
3943 +  return value;
3944 + }
3945 +
3946 +
3947 + //!track-event pair valueLookup
3948 + double
3949 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3950 +
3951 +  double value = 0.0;
3952 +  double pMag = sqrt(object1->pt * object1->pt +
3953 +                     object1->pz * object1->pz);
3954 +
3955 +  if      (variable == "numPV")                      value = object2->numPV;
3956 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3957 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3958 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3959 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3960 +
3961 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3962 +
3963 +  value = applyFunction(function, value);
3964 +
3965 +  return value;
3966 +
3967 + }
3968  
3969 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3969 > //!electron-trigobj pair valueLookup
3970 > double
3971 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3972 >
3973 >  double value = 0.0;
3974 >
3975 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3976 >  else if (variable == "match"){
3977 >    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3978 >      stringValue = object2->filter;
3979 >    else
3980 >      stringValue = "none";
3981 >  }
3982 >
3983 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3984  
3985    value = applyFunction(function, value);
3986  
3987    return value;
3988 +
3989   }
3990  
3991 + //!muon-trigobj pair valueLookup
3992 + double
3993 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3994 +
3995 +  double value = 0.0;
3996 +
3997 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3998 +
3999 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4000 +
4001 +  value = applyFunction(function, value);
4002 +
4003 +  return value;
4004 +
4005 + }
4006 +
4007 + //!stop valueLookup
4008 + double
4009 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
4010 +
4011 +
4012 +  double value = 0.0;
4013 +
4014 +  if(variable == "ctau") value = object->ctau;
4015 +
4016 +  else if (variable == "d0"){
4017 +    double vx = object->vx - chosenVertex ()->x,
4018 +      vy = object->vy - chosenVertex ()->y,
4019 +      px = object->px,
4020 +      py = object->py,
4021 +      pt = object->pt;
4022 +    value = (-vx * py + vy * px) / pt;
4023 +  }
4024 +
4025 +  else if (variable == "dz"){
4026 +    double vx = object->vx - chosenVertex ()->x,
4027 +      vy = object->vy - chosenVertex ()->y,
4028 +      vz = object->vz - chosenVertex ()->z,
4029 +      px = object->px,
4030 +      py = object->py,
4031 +      pz = object->pz,
4032 +      pt = object->pt;
4033 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
4034 +  }
4035 +
4036 +  else if (variable == "minD0"){
4037 +    double minD0=999;
4038 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4039 +      double vx = object->vx - vertex->x,
4040 +        vy = object->vy - vertex->y,
4041 +        px = object->px,
4042 +        py = object->py,
4043 +        pt = object->pt;
4044 +      value = (-vx * py + vy * px) / pt;
4045 +      if(abs(value) < abs(minD0)) minD0 = value;
4046 +    }
4047 +    value = minD0;
4048 +  }
4049 +  else if (variable == "minDz"){
4050 +    double minDz=999;
4051 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4052 +      double vx = object->vx - vertex->x,
4053 +        vy = object->vy - vertex->y,
4054 +        vz = object->vz - vertex->z,
4055 +        px = object->px,
4056 +        py = object->py,
4057 +        pz = object->pz,
4058 +        pt = object->pt;
4059 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
4060 +      if(abs(value) < abs(minDz)) minDz = value;
4061 +    }
4062 +    value = minDz;
4063 +  }
4064 +  else if(variable == "distToVertex"){
4065 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4066 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4067 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4068 +  }
4069 +  else if (variable == "minDistToVertex"){
4070 +    double minDistToVertex=999;
4071 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4072 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4073 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4074 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
4075 +
4076 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4077 +    }
4078 +    value = minDistToVertex;
4079 +  }
4080 +  else if (variable == "distToVertexDifference"){
4081 +    double minDistToVertex=999;
4082 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4083 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4084 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4085 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
4086 +
4087 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4088 +    }
4089 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4090 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4091 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4092 +
4093 +    value = distToChosenVertex - minDistToVertex;
4094 +  }
4095 +
4096 +  else if (variable == "closestVertexRank"){
4097 +    double minDistToVertex=999;
4098 +    int vertex_rank = 0;
4099 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4100 +      vertex_rank++;
4101 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4102 +                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
4103 +                      (object->vz-vertex->z)*(object->vz-vertex->z));
4104 +
4105 +      if(abs(dist) < abs(minDistToVertex)){
4106 +        value = vertex_rank;
4107 +        minDistToVertex = dist;
4108 +      }
4109 +    }
4110 +  }
4111 +
4112 +  else if (variable == "decaysToTau"){
4113 +    value = abs (object->daughter0Id) == 15 || abs (object->daughter1Id) == 15;
4114 +  }
4115 +
4116 +
4117 +
4118 +
4119 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4120 +
4121 +  value = applyFunction(function, value);
4122 +
4123 +  return value;
4124 +
4125 + } // end stop valueLookup
4126 +
4127 +
4128 +
4129  
4130 < // Calculate the number of tracks in cone of DeltaR<0.5 around track1.  
4131 < // Return true iff no other tracks are found in this cone.  
4132 < int
4130 >
4131 > // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
4132 > // Return true iff no other tracks are found in this cone.
4133 > int
4134   OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
4135    for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
4136 <    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.  
4136 >    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
4137      double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
4138      if(deltaRtrk < 0.5) return 0;
4139    }
4140    return 1;
4141 <  
4141 >
4142   }
4143  
4144 + //calculate the scalar sum of Jet Pt in the event.
4145 + double
4146 + OSUAnalysis::getHt (const BNjetCollection* jetColl){
4147 +  double Ht = 0;
4148 +  for(BNjetCollection::const_iterator jet = jetColl->begin(); jet !=jetColl->end(); jet++){
4149 +    Ht += abs(jet->pt);
4150 +  }
4151 +  return Ht;
4152 + }
4153  
4154 < double
4154 > double
4155   OSUAnalysis::getTrkPtRes (const BNtrack* track1){
4156  
4157    double ptTrue = getTrkPtTrue(track1, mcparticles.product());
4158    double PtRes = (track1->pt - ptTrue) / ptTrue;
4159  
4160    return PtRes;
4161 <  
4161 >
4162   }
4163  
4164  
4165 < double
4165 > double
4166   OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
4167    double value = -99;
4168    double genDeltaRLowest = 999;
# Line 2381 | Line 4171 | OSUAnalysis::getTrkPtTrue (const BNtrack
4171      double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
4172      if (genDeltaRtemp < genDeltaRLowest) {
4173        genDeltaRLowest = genDeltaRtemp;
4174 <      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.  
4175 <        double ptTrue = genPart->pt;
4176 <        value = ptTrue;
4174 >      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
4175 >        double ptTrue = genPart->pt;
4176 >        value = ptTrue;
4177        }
4178 <    }
4178 >    }
4179    }
4180  
4181    return value;
4182  
4183   }
4184  
4185 + double
4186 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
4187 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
4188 +  if (!useTrackCaloRhoCorr_) return -99;
4189 +  // if (!rhokt6CaloJetsHandle_) {
4190 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
4191 +  //   return -99;
4192 +  // }
4193 +  double radDeltaRCone = 0.5;
4194 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
4195 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
4196 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
4197 +  return caloTotRhoCorrCalo;
4198 +
4199 + }
4200 +
4201 + double
4202 + OSUAnalysis::getTrkDepTrkRp5RhoCorr(const BNtrack* track) {
4203 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.              
4204 +  if (!useTrackCaloRhoCorr_) return -99;
4205 +  // if (!rhokt6CaloJetsHandle_) {                                                                                                    
4206 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;                        
4207 +  //   return -99;                                                                                                                    
4208 +  // }                                                                                                                                
4209 +  double radDeltaRCone = 0.5;
4210 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.                                                                                                          
4211 +  double rawDepTrkRp5 = track->depTrkRp5;
4212 + double depTrkRp5RhoCorr = TMath::Max(0., rawDepTrkRp5 - rhoCorr_kt6CaloJets);
4213 + return depTrkRp5RhoCorr;
4214 +
4215 + }
4216 +
4217 + double
4218 + OSUAnalysis::getTrkDepTrkRp3RhoCorr(const BNtrack* track) {
4219 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.                                                
4220 +  if (!useTrackCaloRhoCorr_) return -99;
4221 +  // if (!rhokt6CaloJetsHandle_) {                                                                                                                                      
4222 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;                                                          
4223 +  //   return -99;                                                                                                                                                      
4224 +  // }                                                                                                                                                                  
4225 +  double radDeltaRCone = 0.3;
4226 + // Define effective area as pi*r^2, where r is radius of DeltaR cone
4227 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  
4228 +  double rawDepTrkRp3 = track->depTrkRp3;
4229 +  double depTrkRp3RhoCorr = TMath::Max(0., rawDepTrkRp3 - rhoCorr_kt6CaloJets);
4230 +  return depTrkRp3RhoCorr;
4231 +  
4232 + }
4233 +
4234 +
4235 +
4236 +
4237   //creates a map of the dead Ecal channels in the barrel and endcap
4238   //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
4239   //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
4240 < void
4240 > void
4241   OSUAnalysis::WriteDeadEcal (){
4242    double etaEcal, phiEcal;
4243    ifstream DeadEcalFile(deadEcalFile_);
4244    if(!DeadEcalFile) {
4245 <    cout << "Error: DeadEcalFile has not been found." << endl;
2404 <    return;
2405 <  }
2406 <  if(DeadEcalVec.size()!= 0){
2407 <    cout << "Error: DeadEcalVec has a nonzero size" << endl;
4245 >    clog << "Error: DeadEcalFile has not been found." << endl;
4246      return;
4247 <  }
4247 >  }
4248 >  if(DeadEcalVec.size()!= 0){
4249 >    clog << "Error: DeadEcalVec has a nonzero size" << endl;
4250 >    return;
4251 >  }
4252    while(!DeadEcalFile.eof())
4253      {
4254        DeadEcalFile >> etaEcal >> phiEcal;
# Line 2415 | Line 4257 | OSUAnalysis::WriteDeadEcal (){
4257        newChan.phiEcal = phiEcal;
4258        DeadEcalVec.push_back(newChan);
4259      }
4260 <  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
4260 >  if(DeadEcalVec.size() == 0) clog << "Warning: No dead Ecal channels have been found." << endl;
4261   }
4262  
4263   //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
4264 < int
4264 > int
4265   OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
4266    double deltaRLowest = 999;
4267    int value = 0;
4268    if (DeadEcalVec.size() == 0) WriteDeadEcal();
4269 <  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4269 >  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4270      double eta = ecal->etaEcal;
4271      double phi = ecal->phiEcal;
4272 <    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
4272 >    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
4273      if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
4274    }
4275    if (deltaRLowest<0.05) {value = 1;}
# Line 2435 | Line 4277 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
4277    return value;
4278   }
4279  
4280 <
4281 <
4280 > // Returns the smallest DeltaR between the object and any generated true particle in the event.
4281 > template <class InputObject>
4282 > double OSUAnalysis::getGenDeltaRLowest(InputObject object){
4283 >  double genDeltaRLowest = 999.;
4284 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4285 >    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
4286 >    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
4287 >  }
4288 >  return genDeltaRLowest;
4289 > }
4290  
4291   double
4292   OSUAnalysis::applyFunction(string function, double value){
# Line 2447 | Line 4297 | OSUAnalysis::applyFunction(string functi
4297    else if(function == "log") value = log10(value);
4298  
4299    else if(function == "") value = value;
4300 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
4300 >  else{clog << "WARNING: invalid function '" << function << "'\n";}
4301  
4302    return value;
4303  
# Line 2457 | Line 4307 | OSUAnalysis::applyFunction(string functi
4307   template <class InputCollection>
4308   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
4309  
4310 +  if (verbose_>2) clog << "  Beginning setObjectFlags for cut " << currentCutIndex << ": " << currentCut.name
4311 +                       << ", inputType=" << inputType
4312 +                       << endl;  
4313 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
4314 +    string obj1, obj2;
4315 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
4316 +    if (inputType==obj1 ||
4317 +        inputType==obj2) {
4318 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
4319 +      // and the inputType is a member of the pair.
4320 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
4321 +      // For example, if currentCut.inputCollection==electron-muon pairs,
4322 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
4323 +      return;
4324 +    }
4325 +  }
4326  
4327    for (uint object = 0; object != inputCollection->size(); object++){
4328  
4329 <
4330 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
2465 <
4329 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4330 >    bool plotDecision = true;
4331  
4332      if(currentCut.inputCollection == inputType){
4333  
4334        vector<bool> subcutDecisions;
4335        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4336 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4337 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4336 >        string stringValue = "";
4337 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4338 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4339 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4340 >
4341        }
4342 <      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4342 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4343        else{
4344 <        bool tempDecision = true;
4345 <        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4346 <          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4347 <            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4348 <          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4344 >        bool tempDecision = true;
4345 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4346 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4347 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4348 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4349              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4350 <        }
4351 <        decision = tempDecision;
4350 >        }
4351 >        cutDecision = tempDecision;
4352        }
4353 +      //invert the cut if this cut is a veto
4354 +      if(currentCut.isVeto) cutDecision = !cutDecision;
4355 +      plotDecision = cutDecision;
4356      }
2486    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4357  
4358 +    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4359  
4360 <    //set flags for objects that pass each cut AND all the previous cuts
4361 <    bool previousCumulativeFlag = true;
4360 >    //set flags for objects that pass this cut AND all the previous cuts
4361 >    bool previousCumulativeCutFlag = true;
4362      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4363 <      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4364 <      else{ previousCumulativeFlag = false; break;}
4363 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4364 >      else{ previousCumulativeCutFlag = false; break;}
4365      }
4366 <    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4366 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4367 >    bool previousCumulativePlotFlag = true;
4368 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4369 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4370 >      else{ previousCumulativePlotFlag = false; break;}
4371 >    }
4372 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4373  
4374 +    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4375  
4376    }
4377  
4378 < }
4378 > } // end void OSUAnalysis::setObjectFlags
4379  
4380  
4381   template <class InputCollection1, class InputCollection2>
4382 < void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
4383 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
4384 <
4382 > void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags,
4383 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, string inputType){
4384 >  // This function sets the flags for the paired object collection.  
4385 >  // If the cut is applying on the given paired object collection, then the flags for the single object collections are also set.
4386 >  // If not, then the flags for the paired object collection are taken as the AND of the flags for each single object collection.  
4387 >
4388 >  if (verbose_>2) clog << "  Beginning setObjectFlags for cut=" << currentCut.name
4389 >                       << ", inputType=" << inputType
4390 >                       << endl;  
4391  
4392    bool sameObjects = false;
4393 <  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4393 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;  // FIXME:  is sameObjects just the not of isTwoTypesOfObject?  If so, it's redundant.  
4394 >
4395 >  // Get the strings for the two objects that make up the pair.
4396 >  string obj1Type, obj2Type;
4397 >  getTwoObjs(inputType, obj1Type, obj2Type);
4398 >  bool isTwoTypesOfObject = true;
4399 >  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
4400 >
4401 >  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
4402 >  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4403 >  if (currentCut.inputCollection == inputType) {
4404 >    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4405 >      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4406 >      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4407 >    }
4408 >    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4409 >      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4410 >        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4411 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4412 >      }
4413 >    }
4414 >  }
4415  
4416 +  int counter = 0;
4417  
2512  int counter = 0;  
4418    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4419      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4420 <      
4420 >
4421        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4422  
4423  
4424 <      bool decision = true;//object passes if this cut doesn't cut on that type of object
4424 >      bool cutDecision  = true;//object passes if this cut doesn't cut on that type of object
4425 >      bool plotDecision = true;
4426  
4427 +      // Determine whether each pair passes the cut, only if inputCollection is the same as the inputType.  
4428        if(currentCut.inputCollection == inputType){
4429  
4430 <        vector<bool> subcutDecisions;
4431 <        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4432 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4433 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4434 <        }
4430 >        vector<bool> subcutDecisions;
4431 >        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4432 >          string stringValue = "";
4433 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4434 >          if (verbose_>1) clog << currentCut.variables.at(subcutIndex) << " = " << value
4435 >                               << endl;  
4436 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4437 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4438 >        }
4439  
4440 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4441 <        else{
4442 <          bool tempDecision = true;
4443 <          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4444 <            if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4445 <              tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4446 <            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4447 <              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4448 <          }
4449 <          decision = tempDecision;
4440 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4441 >        else{
4442 >          bool tempDecision = subcutDecisions.at(0);
4443 >          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
4444 >            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
4445 >              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
4446 >            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4447 >              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4448 >          }
4449 >          cutDecision = tempDecision;
4450 >        }
4451 >        //invert the cut if this cut is a veto
4452 >        if (currentCut.isVeto) cutDecision = !cutDecision;
4453 >        plotDecision = cutDecision;
4454 >
4455 >        if (verbose_>1) clog << " cutDecision = " << cutDecision
4456 >                             << "; for currentCut.inputCollection = " << currentCut.inputCollection
4457 >                             << "; object1 (" << obj1Type << ") = " << object1
4458 >                             << "; object2 (" << obj2Type << ") = " << object2
4459 >                             << endl;  
4460 >        
4461 >        if (cutDecision) {  // only set the flags for the individual objects if the pair object is being cut on
4462 >          individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4463 >          individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4464          }
4465 +        if (plotDecision) {  // only set the flags for the individual objects if the pair object is being cut on
4466 +          individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4467 +          individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4468 +        }
4469 +        
4470 +
4471 +      } // if(currentCut.inputCollection == inputType){
4472 +
4473 +      // The individualFlags will be true if the inputCollection is not the same as the inputType.
4474 +      // They are also independent of the previous flags on the single objects.  
4475 +      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));  
4476 +
4477 +
4478 +
4479 +      // ************************************
4480 +      // Determine cumulative flags
4481 +      // ************************************
4482 +      // determine whether this paired object passes this cut AND all previous cuts
4483 +      bool previousCumulativeCutFlag = true;
4484 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4485 +        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4486 +        else{ previousCumulativeCutFlag = false; break;}
4487        }
4488 <      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4489 <      
4490 <      //set flags for objects that pass each cut AND all the previous cuts
2544 <      bool previousCumulativeFlag = true;
4488 >      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4489 >
4490 >      bool previousCumulativePlotFlag = true;
4491        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4492 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
4493 <        else{ previousCumulativeFlag = false; break;}
4492 >        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4493 >        else{ previousCumulativePlotFlag = false; break;}
4494 >      }
4495 >      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4496 >      
4497 >      // 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.    
4498 >      int cutIdxFlagsObj1 = max(int(currentCutIndex-1),0);
4499 >      int cutIdxFlagsObj2 = max(int(currentCutIndex-1),0);
4500 >      // 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.
4501 >      // 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.  
4502 >      // 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).  
4503 >      if (currentCut.inputCollection != inputType) {  
4504 >        if (currentCut.inputCollection.find(obj1Type)!=string::npos) cutIdxFlagsObj1 = currentCutIndex;
4505 >        if (currentCut.inputCollection.find(obj2Type)!=string::npos) cutIdxFlagsObj2 = currentCutIndex;
4506 >      }  
4507 >      flagPair flags1 = cumulativeFlags.at(obj1Type).at(cutIdxFlagsObj1);  // flag for input collection 1
4508 >      flagPair flags2 = cumulativeFlags.at(obj2Type).at(cutIdxFlagsObj2);  // flag for input collection 2
4509 >      
4510 >      // The cumulative flag is only true if the paired object cumulative flag is true, and if the single object cumulative flags are true.  
4511 >      bool currentCumulativeCutFlag = true;
4512 >      bool currentCumulativePlotFlag = true;
4513 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4514 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4515 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4516 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4517 >
4518 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4519 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4520 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4521 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4522 >
4523 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));  // Set the flag for the paired object
4524 >
4525 >
4526 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // Set the flags for the individual objects if the paired object is being cut on.  
4527 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first  = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4528 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first  = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4529 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4530 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4531 >
4532 >        if (verbose_>1) clog << " previousCumulativeCutFlag for object1 = " << getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object1, "cut") << endl;  
4533 >        if (verbose_>1) clog << " previousCumulativeCutFlag for object2 = " << getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut") << endl;  
4534 >
4535        }
2549      //apply flags for the components of the composite object as well
2550      bool currentCumulativeFlag = true;
2551      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
2552      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
2553      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
2554      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
2555      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
4536  
4537 <      counter++;      
4537 >      counter++;
4538 >
4539 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4540 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4541 >
4542 > } // end void OSUAnalysis::setObjectFlags
4543 >
4544 >
4545 > bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4546 >  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4547 >  // all cuts up to currentCutIndex
4548 >  bool previousCumulativeFlag = true;
4549 >  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4550 >    bool tempFlag = false;
4551 >    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4552 >    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4553 >
4554 >    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4555 >    else {
4556 >      previousCumulativeFlag = false; break;
4557      }
2559    
4558    }
4559 +  return previousCumulativeFlag;
4560 + }
4561 +
4562  
4563  
4564 +
4565 + template <class InputCollection>
4566 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4567 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4568 +
4569 +  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;
4570 +  for (uint object = 0; object != inputCollection->size(); object++) {
4571 +
4572 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4573 +
4574 +    string inputVariable = parameters.inputVariable;
4575 +    string function = "";
4576 +    string stringValue = "";
4577 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4578 +    BNTreeBranchVals_.at(parameters.name).push_back(value);
4579 +
4580 +  }
4581   }
4582  
4583  
4584   template <class InputCollection>
4585 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
4585 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4586 >
4587 >  if (verbose_>2) clog << "  Filling histogram for " << parameters.name << endl;  
4588  
4589    for (uint object = 0; object != inputCollection->size(); object++){
4590  
4591 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4591 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4592  
4593      string currentString = parameters.inputVariables.at(0);
4594      string inputVariable = "";
4595      string function = "";
4596 <    if(currentString.find("(")==std::string::npos){
4597 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
4596 >    if(currentString.find("(")==string::npos){
4597 >      inputVariable = currentString;// variable to cut on
4598      }
4599      else{
4600 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4601 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4602 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4600 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4601 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4602 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4603      }
4604  
4605 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
4606 <    histo->Fill(value,puScaleFactor);
4605 >    string stringValue = "";
4606 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4607 >    histo->Fill(value,scaleFactor);
4608 >
4609 >    if (printEventInfo_) {
4610 >      // Write information about event to screen, for testing purposes.
4611 >      clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << " (object number " << object << ")" << endl;
4612 >    }
4613  
4614    }
2589
4615   }
4616  
4617   template <class InputCollection1, class InputCollection2>
4618 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
4618 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2,
4619 >                                  flagPair pairFlags, double scaleFactor){
4620  
4621    bool sameObjects = false;
4622    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4623  
4624 <  int pairCounter = 0;  
4624 >  int pairCounter = -1;
4625    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4626      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4627 <      
4627 >
4628        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4629  
4630 <      //only take objects which have passed all cuts and pairs which have passed all cuts
4631 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
2606 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
2607 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4630 >      pairCounter++;
4631 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4632  
4633        string currentString = parameters.inputVariables.at(0);
4634        string inputVariable = "";
4635        string function = "";
4636 <      if(currentString.find("(")==std::string::npos){
4637 <        inputVariable = currentString;// variable to cut on                                                                                                          
4636 >      if(currentString.find("(")==string::npos){
4637 >        inputVariable = currentString;// variable to cut on
4638        }
4639        else{
4640 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4641 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4642 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4640 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4641 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4642 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4643        }
2620      
2621      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
2622      histo->Fill(value,puScaleFactor);
4644  
4645 <      pairCounter++;      
4645 >      string stringValue = "";
4646 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4647 >      histo->Fill(value,scaleFactor);
4648 >
4649 >      if (printEventInfo_) {
4650 >        // Write information about event to screen, for testing purposes.
4651 >        clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value
4652 >             << " (object1 number " << object1 << "), "
4653 >             << " (object2 number " << object2 << ")"
4654 >             << endl;
4655 >      }
4656 >      
4657      }
4658    }
4659  
# Line 2629 | Line 4661 | void OSUAnalysis::fill1DHistogram(TH1* h
4661  
4662  
4663   template <class InputCollection>
4664 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
4664 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4665  
4666    for (uint object = 0; object != inputCollection->size(); object++){
4667  
4668 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4668 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4669  
4670 +    string stringValue = "";
4671      string currentString = parameters.inputVariables.at(0);
4672      string inputVariable = "";
4673      string function = "";
4674 <    if(currentString.find("(")==std::string::npos){
4675 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
4674 >    if(currentString.find("(")==string::npos){
4675 >      inputVariable = currentString;// variable to cut on
4676      }
4677      else{
4678 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4679 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4680 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4678 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4679 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4680 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4681      }
4682 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
4682 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4683  
4684      currentString = parameters.inputVariables.at(1);
4685      inputVariable = "";
4686      function = "";
4687 <    if(currentString.find("(")==std::string::npos){
4688 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
4687 >    if(currentString.find("(")==string::npos){
4688 >      inputVariable = currentString;// variable to cut on
4689      }
4690      else{
4691 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4692 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4693 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4691 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4692 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4693 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4694      }
4695  
4696 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
4696 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4697  
4698 <    histo->Fill(valueX,valueY,puScaleFactor);
4698 >    histo->Fill(valueX,valueY,scaleFactor);
4699  
4700    }
4701  
4702   }
4703  
4704   template <class InputCollection1, class InputCollection2>
4705 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
4705 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2,
4706 >                                  flagPair pairFlags, double scaleFactor){
4707  
4708    bool sameObjects = false;
4709    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4710  
4711 <  int pairCounter = 0;  
4711 >  int pairCounter = -1;
4712    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4713      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4714 <      
4714 >
4715        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4716  
4717 <      //only take objects which have passed all cuts and pairs which have passed all cuts
2684 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
2685 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
2686 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4717 >      pairCounter++;
4718  
4719 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4720 +
4721 +      string stringValue = "";
4722        string currentString = parameters.inputVariables.at(0);
4723        string inputVariable = "";
4724        string function = "";
4725 <      if(currentString.find("(")==std::string::npos){
4726 <        inputVariable = currentString;// variable to cut on                                                                                                          
4725 >      if(currentString.find("(")==string::npos){
4726 >        inputVariable = currentString;// variable to cut on
4727        }
4728        else{
4729 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4730 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4731 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4729 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4730 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4731 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4732        }
4733 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4733 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4734  
4735        currentString = parameters.inputVariables.at(1);
4736        inputVariable = "";
4737        function = "";
4738 <      if(currentString.find("(")==std::string::npos){
4739 <        inputVariable = currentString;// variable to cut on                                                                                                          
4738 >      if(currentString.find("(")==string::npos){
4739 >        inputVariable = currentString;// variable to cut on
4740        }
4741        else{
4742 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4743 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4744 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4742 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4743 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4744 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4745        }
4746 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
2713 <
4746 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4747  
2715      histo->Fill(valueX,valueY,puScaleFactor);
4748  
4749 <      pairCounter++;      
4749 >      histo->Fill(valueX,valueY,scaleFactor);
4750  
4751      }
4752    }
# Line 2732 | Line 4764 | int OSUAnalysis::getGenMatchedParticleIn
4764  
4765      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4766      if(currentDeltaR > 0.05) continue;
4767 <
4767 >    //     clog << setprecision(3) << setw(20)
4768 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4769 >    //          << setw(20)
4770 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4771 >    //          << setw(20)
4772 >    //          << "\tdeltaR = " << currentDeltaR
4773 >    //          << setprecision(1)
4774 >    //          << setw(20)
4775 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4776 >    //          << setw(20)
4777 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4778 >    //          << setw(20)
4779 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4780      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4781        bestMatchIndex = mcparticle - mcparticles->begin();
4782        bestMatchDeltaR = currentDeltaR;
4783      }
4784  
4785    }
4786 <
4786 >  //   if(bestMatchDeltaR != 999)  clog << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4787 >  //   else clog << "no match found..." << endl;
4788    return bestMatchIndex;
4789  
4790   }
# Line 2793 | Line 4838 | int OSUAnalysis::findTauMotherIndex(cons
4838   // 20        strange baryon
4839   // 21        charm baryon
4840   // 22        bottom baryon
4841 < // 23        other
4841 > // 23        QCD string
4842 > // 24        other
4843  
4844   int OSUAnalysis::getPdgIdBinValue(int pdgId){
4845  
4846    int binValue = -999;
4847 <  int absPdgId = fabs(pdgId);  
4847 >  int absPdgId = fabs(pdgId);
4848    if(pdgId == -1) binValue = 0;
4849    else if(absPdgId <= 6 ) binValue = absPdgId;
4850    else if(absPdgId == 11 ) binValue = 7;
# Line 2817 | Line 4863 | int OSUAnalysis::getPdgIdBinValue(int pd
4863    else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4864    else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4865    else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4866 +  else if(absPdgId == 92  ) binValue = 23;
4867  
4868 <  else binValue = 23;
4868 >  else binValue = 24;
4869  
4870    return binValue;
4871  
4872   }
4873  
4874 + const BNprimaryvertex *
4875 + OSUAnalysis::chosenVertex ()
4876 + {
4877 +  const BNprimaryvertex *chosenVertex = 0;
4878 +  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4879 +    flagPair vertexFlags;
4880 +    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4881 +      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4882 +        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4883 +        break;
4884 +      }
4885 +    }
4886 +    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4887 +      if(!vertexFlags.at(vertexIndex).first) continue;
4888 +      chosenVertex = & primaryvertexs->at(vertexIndex);
4889 +      break;
4890 +    }
4891 +  }
4892 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4893 +    chosenVertex = & primaryvertexs->at (0);
4894 +
4895 +  return chosenVertex;
4896 + }
4897 +
4898 + const BNmet *
4899 + OSUAnalysis::chosenMET ()
4900 + {
4901 +  const BNmet *chosenMET = 0;
4902 +  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4903 +    flagPair metFlags;
4904 +    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4905 +      if (cumulativeFlags.at("mets").at(i).size()){
4906 +        metFlags = cumulativeFlags.at("mets").at(i);
4907 +        break;
4908 +      }
4909 +    }
4910 +    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4911 +      if(!metFlags.at(metIndex).first) continue;
4912 +      chosenMET = & mets->at(metIndex);
4913 +      break;
4914 +    }
4915 +  }
4916 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4917 +    chosenMET = & mets->at (0);
4918 +
4919 +  return chosenMET;
4920 + }
4921  
4922 < DEFINE_FWK_MODULE(OSUAnalysis);
4922 > const BNelectron *
4923 > OSUAnalysis::chosenElectron ()
4924 > {
4925 >  const BNelectron *chosenElectron = 0;
4926 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4927 >    flagPair electronFlags;
4928 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4929 >      if (cumulativeFlags.at("electrons").at(i).size()){
4930 >        electronFlags = cumulativeFlags.at("electrons").at(i);
4931 >        break;
4932 >      }
4933 >    }
4934 >    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4935 >      if(!electronFlags.at(electronIndex).first) continue;
4936 >      chosenElectron = & electrons->at(electronIndex);
4937 >      break;
4938 >    }
4939 >  }
4940 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4941 >    chosenElectron = & electrons->at (0);
4942 >
4943 >  return chosenElectron;
4944 > }
4945 >
4946 >
4947 > const BNmuon *
4948 > OSUAnalysis::chosenMuon ()
4949 > {
4950 >  const BNmuon *chosenMuon = 0;
4951 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4952 >    flagPair muonFlags;
4953 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4954 >      if (cumulativeFlags.at("muons").at(i).size()){
4955 >        muonFlags = cumulativeFlags.at("muons").at(i);
4956 >        break;
4957 >      }
4958 >    }
4959 >    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4960 >      if(!muonFlags.at(muonIndex).first) continue;
4961 >      chosenMuon = & muons->at(muonIndex);
4962 >      break;
4963 >    }
4964 >  }
4965 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4966 >    chosenMuon = & muons->at (0);
4967  
4968 +  return chosenMuon;
4969 + }
4970  
4971 + double
4972 + OSUAnalysis::chosenHT ()
4973 + {
4974 +  double chosenHT = 0.0;
4975 +  if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
4976 +    flagPair jetFlags;
4977 +    for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
4978 +      if (cumulativeFlags.at("jets").at(i).size()){
4979 +        jetFlags = cumulativeFlags.at("jets").at(i);
4980 +        break;
4981 +      }
4982 +    }
4983 +    for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
4984 +      if(!jetFlags.at(jetIndex).first) continue;
4985 +      chosenHT += jets->at(jetIndex).pt;
4986 +    }
4987 +  }
4988 +
4989 +  return chosenHT;
4990 + }
4991 +
4992 + pair<const BNmuon *, const BNmuon *>
4993 + OSUAnalysis::leadMuonPair ()
4994 + {
4995 +  pair<const BNmuon *, const BNmuon *> leadMuonPair;
4996 +  leadMuonPair.first = leadMuonPair.second = 0;
4997 +
4998 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4999 +    flagPair muonFlags;
5000 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
5001 +      if (cumulativeFlags.at("muons").at(i).size()){
5002 +        muonFlags = cumulativeFlags.at("muons").at(i);
5003 +        break;
5004 +      }
5005 +    }
5006 +    for (uint muonIndex0 = 0; muonIndex0 != muonFlags.size(); muonIndex0++){
5007 +      if(!muonFlags.at(muonIndex0).first) continue;
5008 +      for (uint muonIndex1 = muonIndex0 + 1; muonIndex1 < muonFlags.size(); muonIndex1++){
5009 +        if(!muonFlags.at(muonIndex1).first) continue;
5010 +        const BNmuon *mu0 = & muons->at(muonIndex0);
5011 +        const BNmuon *mu1 = & muons->at(muonIndex1);
5012 +        if(leadMuonPair.first == 0 || leadMuonPair.second == 0){
5013 +          leadMuonPair.first = mu0;
5014 +          leadMuonPair.second = mu1;
5015 +        }
5016 +        else{
5017 +          TVector2 newPt0 (mu0->px, mu0->py),
5018 +                   newPt1 (mu1->px, mu1->py),
5019 +                   oldPt0 (leadMuonPair.first->px, leadMuonPair.first->py),
5020 +                   oldPt1 (leadMuonPair.second->px, leadMuonPair.second->py);
5021 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
5022 +            {
5023 +              leadMuonPair.first = mu0;
5024 +              leadMuonPair.second = mu1;
5025 +            }
5026 +        }
5027 +      }
5028 +    }
5029 +  }
5030 +
5031 +  return leadMuonPair;
5032 + }
5033 +
5034 + pair<const BNelectron *, const BNelectron *>
5035 + OSUAnalysis::leadElectronPair ()
5036 + {
5037 +  pair<const BNelectron *, const BNelectron *> leadElectronPair;
5038 +  leadElectronPair.first = leadElectronPair.second = 0;
5039 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
5040 +    flagPair electronFlags;
5041 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
5042 +      if (cumulativeFlags.at("electrons").at(i).size()){
5043 +        electronFlags = cumulativeFlags.at("electrons").at(i);
5044 +        break;
5045 +      }
5046 +    }
5047 +    for (uint electronIndex0 = 0; electronIndex0 != electronFlags.size(); electronIndex0++){
5048 +      if(!electronFlags.at(electronIndex0).first) continue;
5049 +      for (uint electronIndex1 = electronIndex0 + 1; electronIndex1 < electronFlags.size(); electronIndex1++){
5050 +        if(!electronFlags.at(electronIndex1).first) continue;
5051 +        const BNelectron *el0 = & electrons->at(electronIndex0);
5052 +        const BNelectron *el1 = & electrons->at(electronIndex1);
5053 +        if(leadElectronPair.first == 0 || leadElectronPair.second == 0){
5054 +          leadElectronPair.first = el0;
5055 +          leadElectronPair.second = el1;
5056 +        }
5057 +        else{
5058 +          TVector2 newPt0 (el0->px, el0->py),
5059 +                   newPt1 (el1->px, el1->py),
5060 +                   oldPt0 (leadElectronPair.first->px, leadElectronPair.first->py),
5061 +                   oldPt1 (leadElectronPair.second->px, leadElectronPair.second->py);
5062 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
5063 +            {
5064 +              leadElectronPair.first = el0;
5065 +              leadElectronPair.second = el1;
5066 +            }
5067 +        }
5068 +      }
5069 +    }
5070 +  }
5071 +
5072 +  return leadElectronPair;
5073 + }
5074 +
5075 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines