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.12 by ahart, Fri Feb 8 11:07:51 2013 UTC vs.
Revision 1.64 by ahart, Sun May 19 00:04:50 2013 UTC

# Line 11 | Line 11 | OSUAnalysis::OSUAnalysis (const edm::Par
11    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
12    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
13    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
14 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
15    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
16    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
17    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
18    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
19    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
20 <
21 <
20 >  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
21 >  puFile_ (cfg.getParameter<string> ("puFile")),
22 >  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
23 >  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
24 >  dataPU_ (cfg.getParameter<string> ("dataPU")),
25 >  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
26 >  muonSF_ (cfg.getParameter<string> ("muonSF")),
27 >  dataset_ (cfg.getParameter<string> ("dataset")),
28 >  datasetType_ (cfg.getParameter<string> ("datasetType")),
29    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
30 <
31 <  histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets"))
30 >  histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
31 >  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
32 >  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
33 >  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
34 >  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
35 >  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
36 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau"))
37  
38   {
39  
27
40    TH1::SetDefaultSumw2 ();
41 <  TH2::SetDefaultSumw2 ();
41 >
42 >  //create pile-up reweighting object, if necessary
43 >  if(datasetType_ != "data") {
44 >    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
45 >    if (applyLeptonSF_){
46 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
47 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
48 >    }
49 >  }
50 >  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
51 >    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
52 >
53  
54    // Construct Cutflow Objects. These store the results of cut decisions and
55    // handle filling cut flow histograms.
56    masterCutFlow_ = new CutFlow (fs_);
57 <  std::vector<TFileDirectory> directories;
57 >  vector<TFileDirectory> directories;
58  
59    //always get vertex collection so we can assign the primary vertex in the event
60 <  allNecessaryObjects.push_back("primaryvertexs");
60 >  objectsToGet.push_back("primaryvertexs");
61 >
62 >  //always make the plot of number of primary vertices (to check pile-up reweighting)
63 >  objectsToPlot.push_back("primaryvertexs");
64 >
65 >  //always get the MC particles to do GEN-matching
66 >  objectsToGet.push_back("mcparticles");
67  
68 +  //always get the event collection to do pile-up reweighting
69 +  objectsToGet.push_back("events");
70  
71    //parse the histogram definitions
72    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
73  
74 <    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string>("inputCollection");
75 <    objectsToPlot.push_back(tempInputCollection);
76 <    allNecessaryObjects.push_back(tempInputCollection);
74 >    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
75 >    if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
76 >    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
77 >    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
78 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
79 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
80 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
81 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
82 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
83 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
84 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
85 >        int spaceIndex = tempInputCollection.find(" ");
86 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
87 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
88 >      }
89 >      else{
90 >        objectsToGet.push_back(tempInputCollection);
91 >      }
92 >      objectsToPlot.push_back(tempInputCollection);
93 >      objectsToCut.push_back(tempInputCollection);
94 >    }
95 >    else{//pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
96 >      string obj1;
97 >      string obj2;
98 >      getTwoObjs(tempInputCollection, obj1, obj2);
99 >      string obj2ToGet = getObjToGet(obj2);
100 >      objectsToCut.push_back(tempInputCollection);
101 >      objectsToCut.push_back(obj1);
102 >      objectsToCut.push_back(obj2);
103 >      objectsToPlot.push_back(tempInputCollection);
104 >      objectsToPlot.push_back(obj1);
105 >      objectsToPlot.push_back(obj2);
106 >      objectsToGet.push_back(tempInputCollection);
107 >      objectsToGet.push_back(obj1);
108 >      objectsToGet.push_back(obj2ToGet);
109 >
110 >    }
111 >
112      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
113 <    
113 >
114      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
115  
116 +      vector<double> defaultValue;
117 +      defaultValue.push_back (-1.0);
118 +
119        histogram tempHistogram;
120        tempHistogram.inputCollection = tempInputCollection;
121        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
122        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
123 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
123 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
124 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
125 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
126        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
127 <      if(histogramList_.at(currentHistogram).exists("function"))
57 <        tempHistogram.function = histogramList_.at(currentHistogram).getParameter<string>("function");
58 <      else
59 <        tempHistogram.function = "";
60 <      
127 >
128        histograms.push_back(tempHistogram);
129  
130      }
131    }
132 <
132 >  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
133 >  sort( objectsToPlot.begin(), objectsToPlot.end() );
134 >  objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
135 >
136 >
137 >
138 >  //add histograms with the gen-matched id, mother id, and grandmother id
139 >  for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
140 >
141 >    string currentObject = objectsToPlot.at(currentObjectIndex);
142 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
143 >
144 >    histogram tempIdHisto;
145 >    histogram tempMomIdHisto;
146 >    histogram tempGmaIdHisto;
147 >    histogram tempIdVsMomIdHisto;
148 >    histogram tempIdVsGmaIdHisto;
149 >
150 >    tempIdHisto.inputCollection = currentObject;
151 >    tempMomIdHisto.inputCollection = currentObject;
152 >    tempGmaIdHisto.inputCollection = currentObject;
153 >    tempIdVsMomIdHisto.inputCollection = currentObject;
154 >    tempIdVsGmaIdHisto.inputCollection = currentObject;
155 >
156 >    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
157 >    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
158 >
159 >    currentObject = currentObject.substr(0, currentObject.size()-1);
160 >    tempIdHisto.name = currentObject+"GenMatchId";
161 >    tempMomIdHisto.name = currentObject+"GenMatchMotherId";
162 >    tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
163 >    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
164 >    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
165 >
166 >    currentObject.at(0) = toupper(currentObject.at(0));
167 >    tempIdHisto.title = currentObject+" Gen-matched Particle";
168 >    tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
169 >    tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
170 >    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
171 >    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
172 >
173 >
174 >    int maxNum = 25;
175 >    vector<double> binVector;
176 >    binVector.push_back(maxNum);
177 >    binVector.push_back(0);
178 >    binVector.push_back(maxNum);
179 >
180 >    tempIdHisto.bins = binVector;
181 >    tempIdHisto.inputVariables.push_back("genMatchedId");
182 >    tempMomIdHisto.bins = binVector;
183 >    tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
184 >    tempGmaIdHisto.bins = binVector;
185 >    tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
186 >    binVector.push_back(maxNum);
187 >    binVector.push_back(0);
188 >    binVector.push_back(maxNum);
189 >    tempIdVsMomIdHisto.bins = binVector;
190 >    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
191 >    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
192 >    tempIdVsGmaIdHisto.bins = binVector;
193 >    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
194 >    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
195 >
196 >    histograms.push_back(tempIdHisto);
197 >    histograms.push_back(tempMomIdHisto);
198 >    histograms.push_back(tempGmaIdHisto);
199 >    histograms.push_back(tempIdVsMomIdHisto);
200 >    histograms.push_back(tempIdVsGmaIdHisto);
201 >  }
202  
203  
204    channel tempChannel;
# Line 82 | Line 218 | OSUAnalysis::OSUAnalysis (const edm::Par
218        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
219        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
220          tempChannel.triggers.push_back(triggerNames.at(trigger));
221 <      allNecessaryObjects.push_back("triggers");
221 >      objectsToGet.push_back("triggers");
222      }
223  
224  
225  
226 +
227      //create cutFlow for this channel
228      cutFlows_.push_back (new CutFlow (fs_, channelName));
229  
# Line 94 | Line 231 | OSUAnalysis::OSUAnalysis (const edm::Par
231      TFileDirectory subDir = fs_->mkdir( channelName );
232      directories.push_back(subDir);
233  
234 <    std::map<std::string, TH1D*> oneDhistoMap;
234 >    map<string, TH1D*> oneDhistoMap;
235      oneDHists_.push_back(oneDhistoMap);
236 <    std::map<std::string, TH2D*> twoDhistoMap;
236 >    map<string, TH2D*> twoDhistoMap;
237      twoDHists_.push_back(twoDhistoMap);
238  
239 +
240 +
241      //book all histograms included in the configuration
242      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
243        histogram currentHistogram = histograms.at(currentHistogramIndex);
244        int numBinsElements = currentHistogram.bins.size();
245        int numInputVariables = currentHistogram.inputVariables.size();
246 <      if(numBinsElements != 3 && numBinsElements !=6) {
247 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
248 <        exit(0);
246 >      int numBinEdgesX = currentHistogram.variableBinsX.size();
247 >      int numBinEdgesY = currentHistogram.variableBinsY.size();
248 >
249 >      if(numBinsElements == 1){
250 >        if(numBinEdgesX > 1){
251 >          if(numBinEdgesY > 1)
252 >            numBinsElements = 6;
253 >          else
254 >            numBinsElements = 3;
255 >        }
256 >      }
257 >      if(numBinsElements != 3 && numBinsElements !=6){
258 >        cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
259 >        exit(0);
260        }
261        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
262 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
263 <        exit(0);
262 >        cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
263 >        exit(0);
264 >      }
265 >      else if(numBinsElements == 3){
266 >        if (currentHistogram.bins.size () == 3)
267 >          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));
268 >        else
269 >          {
270 >            oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
271 >          }
272        }
273 <      else if(numBinsElements == 3)
274 <        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));
275 <      else if(numBinsElements == 6)
276 <        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));
273 >      else if(numBinsElements == 6){
274 >        if (currentHistogram.bins.size () == 6)
275 >          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));
276 >        else
277 >          twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data (), numBinEdgesY - 1, currentHistogram.variableBinsY.data ());
278 >      }
279 >
280  
281 +      if(currentHistogram.name.find("GenMatch")==string::npos) continue;
282 +
283 +      // bin      particle type
284 +      // ---      -------------
285 +      //  0        unmatched
286 +      //  1        u
287 +      //  2        d
288 +      //  3        s
289 +      //  4        c
290 +      //  5        b
291 +      //  6        t
292 +      //  7        e
293 +      //  8        mu
294 +      //  9        tau
295 +      // 10        nu
296 +      // 11        g
297 +      // 12        gamma
298 +      // 13        Z
299 +      // 14        W
300 +      // 15        light meson
301 +      // 16        K meson
302 +      // 17        D meson
303 +      // 18        B meson
304 +      // 19        light baryon
305 +      // 20        strange baryon
306 +      // 21        charm baryon
307 +      // 22        bottom baryon
308 +      // 23        QCD string
309 +      // 24        other
310 +
311 +      vector<TString> labelArray;
312 +      labelArray.push_back("unmatched");
313 +      labelArray.push_back("u");
314 +      labelArray.push_back("d");
315 +      labelArray.push_back("s");
316 +      labelArray.push_back("c");
317 +      labelArray.push_back("b");
318 +      labelArray.push_back("t");
319 +      labelArray.push_back("e");
320 +      labelArray.push_back("#mu");
321 +      labelArray.push_back("#tau");
322 +      labelArray.push_back("#nu");
323 +      labelArray.push_back("g");
324 +      labelArray.push_back("#gamma");
325 +      labelArray.push_back("Z");
326 +      labelArray.push_back("W");
327 +      labelArray.push_back("light meson");
328 +      labelArray.push_back("K meson");
329 +      labelArray.push_back("D meson");
330 +      labelArray.push_back("B meson");
331 +      labelArray.push_back("light baryon");
332 +      labelArray.push_back("strange baryon");
333 +      labelArray.push_back("charm baryon");
334 +      labelArray.push_back("bottom baryon");
335 +      labelArray.push_back("QCD string");
336 +      labelArray.push_back("other");
337 +
338 +      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
339 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
340 +          oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
341 +        }
342 +        else {
343 +          twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
344 +          twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
345 +        }
346 +      }
347 +      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
348 +        twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->CenterTitle();
349 +        twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->CenterTitle();
350 +      }
351  
352      }
353 <    //book a histogram for the number of each object type to be plotted
353 >
354 >    // Book a histogram for the number of each object type to be plotted.
355 >    // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
356      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
357        string currentObject = objectsToPlot.at(currentObjectIndex);
358        int maxNum = 10;
359        if(currentObject == "mcparticles") maxNum = 50;
360 <      currentObject[0] = toupper(currentObject[0]);
360 >      else if(currentObject == "primaryvertexs") maxNum = 50;
361 >
362 >      if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
363 >      else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
364 >      else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
365 >      else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
366 >      else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
367 >      else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
368 >      else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
369 >      else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
370 >      else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
371 >      else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
372 >      else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
373 >      else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
374 >      else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
375 >      else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
376 >      else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
377 >      else if(currentObject == "secondary electrons")           currentObject = "secondaryElectrons";
378 >      else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
379 >      else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
380 >
381 >      currentObject.at(0) = toupper(currentObject.at(0));
382        string histoName = "num" + currentObject;
383 <      oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
383 >
384 >      if(histoName == "numPrimaryvertexs"){
385 >        string newHistoName = histoName + "BeforePileupCorrection";
386 >        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
387 >        newHistoName = histoName + "AfterPileupCorrection";
388 >        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
389 >      }
390 >      else
391 >        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
392      }
393  
394  
395 +
396 +
397      //get list of cuts for this channel
398      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
399  
400      //loop over and parse all cuts
401      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
138
402        cut tempCut;
403 <     //store input collection for cut
404 <      string inputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
405 <      tempCut.inputCollection = inputCollection;
406 <      allNecessaryObjects.push_back(inputCollection);
403 >      //store input collection for cut
404 >      string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
405 >      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
406 >      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
407 >      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
408 >      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
409 >      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
410 >      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
411 >      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
412 >      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
413 >      tempCut.inputCollection = tempInputCollection;
414 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
415 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
416 >          int spaceIndex = tempInputCollection.find(" ");
417 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
418 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
419 >        }
420 >        else{
421 >          objectsToGet.push_back(tempInputCollection);
422 >        }
423 >        objectsToCut.push_back(tempInputCollection);
424 >      }
425 >      else{//pair of objects, need to add them both to objectsToGet
426 >        string obj1;
427 >        string obj2;
428 >        getTwoObjs(tempInputCollection, obj1, obj2);
429 >        string obj2ToGet = getObjToGet(obj2);
430 >        objectsToCut.push_back(tempInputCollection);
431 >        objectsToCut.push_back(obj1);
432 >        objectsToCut.push_back(obj2);
433 >        objectsToGet.push_back(tempInputCollection);
434 >        objectsToGet.push_back(obj1);
435 >        objectsToGet.push_back(obj2ToGet);
436 >
437 >      }
438 >
439 >
440  
441        //split cut string into parts and store them
442        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
443 <      std::vector<string> cutStringVector = splitString(cutString);
444 <      if(cutStringVector.size()!=3){
445 <        std::cout << "Error: Didn't find three elements in the following cut string: '" <<cutString << "'\n";
446 <        exit(0);
443 >      vector<string> cutStringVector = splitString(cutString);
444 >      if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
445 >        cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
446 >        exit(0);
447 >      }
448 >      tempCut.numSubcuts = (cutStringVector.size()+1)/4;
449 >      for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
450 >        int indexOffset = 4 * subcutIndex;
451 >        string currentVariableString = cutStringVector.at(indexOffset);
452 >        if(currentVariableString.find("(")==string::npos){
453 >          tempCut.functions.push_back("");//no function was specified
454 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
455 >        }
456 >        else{
457 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
458 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
459 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
460 >        }
461 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
462 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
463 >        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
464 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
465        }
152
153      tempCut.variable = cutStringVector.at(0);// variable to cut on
154      tempCut.comparativeOperator = cutStringVector.at(1);// comparison to make
155      tempCut.cutValue = atof(cutStringVector.at(2).c_str());// threshold value to pass cut
466  
467        //get number of objects required to pass cut for event to pass
468        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
469 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
469 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
470        if(numberRequiredVector.size()!=2){
471 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
471 >        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
472          exit(0);
473        }
474  
165      // determine number required if comparison contains "="
475        int numberRequiredInt = atoi(numberRequiredVector.at(1).c_str());
167      if(numberRequiredVector.at(0) == ">") numberRequiredInt++;
168      else if(numberRequiredVector.at(0) == "<") numberRequiredInt--;
169
476        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
477        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
478  
479 <      if(cuts_.at(currentCut).exists("function")){
174 <        tempCut.function = cuts_.at(currentCut).getParameter<string> ("function");
175 <      }
176 <      else tempCut.function = "";
479 >
480        string tempCutName;
481        if(cuts_.at(currentCut).exists("alias")){
482          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
# Line 181 | Line 484 | OSUAnalysis::OSUAnalysis (const edm::Par
484        else{
485          //construct string for cutflow table
486          bool plural = numberRequiredInt != 1;
487 <        string collectionString = plural ? inputCollection : inputCollection.substr(0, inputCollection.size()-1);
487 >        string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
488          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
489          tempCutName = cutName;
490        }
491        tempCut.name = tempCutName;
492  
190
493        tempChannel.cuts.push_back(tempCut);
494  
495  
194
496      }//end loop over cuts
497  
197
498      channels.push_back(tempChannel);
499      tempChannel.cuts.clear();
500  
501    }//end loop over channels
502  
503  
504 <
505 <
506 <  //make unique vector of objects we need to cut on (so we make sure to get them from the event)
507 <  sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
508 <  allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
504 >  //make unique vector of objects we need to get from the event
505 >  sort( objectsToGet.begin(), objectsToGet.end() );
506 >  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
507 >  //make unique vector of objects we need to cut on
508 >  sort( objectsToCut.begin(), objectsToCut.end() );
509 >  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
510  
511  
512   }
# Line 223 | Line 524 | void
524   OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
525   {
526  
226
527    // Retrieve necessary collections from the event.
528 <  edm::Handle<BNtriggerCollection> triggers;
529 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
528 >
529 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
530      event.getByLabel (triggers_, triggers);
531  
532 <  edm::Handle<BNjetCollection> jets;
533 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())
532 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
533 >    event.getByLabel (trigobjs_, trigobjs);
534 >
535 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
536      event.getByLabel (jets_, jets);
537  
538 <  edm::Handle<BNmuonCollection> muons;
237 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())
538 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
539      event.getByLabel (muons_, muons);
540  
541 <  edm::Handle<BNelectronCollection> electrons;
241 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())
541 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
542      event.getByLabel (electrons_, electrons);
543  
544 <  edm::Handle<BNeventCollection> events;
245 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())
544 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
545      event.getByLabel (events_, events);
546  
547 <  edm::Handle<BNtauCollection> taus;
249 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())
547 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
548      event.getByLabel (taus_, taus);
549  
550 <  edm::Handle<BNmetCollection> mets;
253 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())
550 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
551      event.getByLabel (mets_, mets);
552  
553 <  edm::Handle<BNtrackCollection> tracks;
257 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())
553 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
554      event.getByLabel (tracks_, tracks);
555  
556 <  edm::Handle<BNgenjetCollection> genjets;
261 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())
556 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
557      event.getByLabel (genjets_, genjets);
558  
559 <  edm::Handle<BNmcparticleCollection> mcparticles;
265 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())
559 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
560      event.getByLabel (mcparticles_, mcparticles);
561  
562 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
269 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())
562 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
563      event.getByLabel (primaryvertexs_, primaryvertexs);
564  
565 <  edm::Handle<BNbxlumiCollection> bxlumis;
273 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())
565 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
566      event.getByLabel (bxlumis_, bxlumis);
567  
568 <  edm::Handle<BNphotonCollection> photons;
277 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())
568 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
569      event.getByLabel (photons_, photons);
570  
571 <  edm::Handle<BNsuperclusterCollection> superclusters;
281 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())
571 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
572      event.getByLabel (superclusters_, superclusters);
573  
574 +  if (datasetType_ == "signalMC"){
575 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
576 +      event.getByLabel (stops_, stops);
577 +  }
578 +
579 +  if (useTrackCaloRhoCorr_) {
580 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
581 +    // This rho collection is not available in all BEANs.
582 +    // For description of rho values for different jet reconstruction algorithms, see
583 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
584 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
585 +  }
586 +
587 +  double masterScaleFactor = 1.0;
588 +
589 +  //get pile-up event weight
590 +  if(doPileupReweighting_ && datasetType_ != "data") masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
591 +
592 +  stopCTauScaleFactor_ = 1.0;
593 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
594 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
595 +  masterScaleFactor *= stopCTauScaleFactor_;
596  
597    //loop over all channels
598  
# Line 288 | Line 600 | OSUAnalysis::analyze (const edm::Event &
600      channel currentChannel = channels.at(currentChannelIndex);
601  
602      flagMap individualFlags;
291    flagMap cumulativeFlags;
603      counterMap passingCounter;
604 +    cumulativeFlags.clear ();
605  
606      bool triggerDecision = true;
607      if(currentChannel.triggers.size() != 0){  //triggers specified
# Line 298 | Line 610 | OSUAnalysis::analyze (const edm::Event &
610      }
611  
612      //loop over all cuts
613 +
614      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
615        cut currentCut = currentChannel.cuts.at(currentCutIndex);
616  
617 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
617 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
618 >        string currentObject = objectsToCut.at(currentObjectIndex);
619  
620 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
620 >        //initialize maps to get ready to set cuts
621          individualFlags[currentObject].push_back (vector<bool> ());
622          cumulativeFlags[currentObject].push_back (vector<bool> ());
623  
624 +      }
625 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
626 +        string currentObject = objectsToCut.at(currentObjectIndex);
627 +
628 +        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
629 +
630 +
631          if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
632 +
633          else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
634 +
635 +        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
636 +        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
637          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
638          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
639          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 320 | Line 645 | OSUAnalysis::analyze (const edm::Event &
645          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
646          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
647          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
648 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
649  
650  
325      }
651  
652 +        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
653 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
654 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
655 +                                                                   "muon-muon pairs");
656 +
657 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
658 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
659 +                                                                   cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
660 +                                                                   "muon-secondary muon pairs");
661 +
662 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
663 +                                                                   cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
664 +                                                                   cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
665 +                                                                   "electron-secondary electron pairs");
666 +
667 +        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
668 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
669 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
670 +                                                                           "electron-electron pairs");
671 +        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
672 +                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
673 +                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
674 +                                                                       "electron-muon pairs");
675 +        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
676 +                                                                           cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
677 +                                                                           cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
678 +                                                                           "jet-jet pairs");
679 +        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
680 +                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
681 +                                                                       cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
682 +                                                                       "electron-jet pairs");
683 +        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
684 +                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
685 +                                                                       cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
686 +                                                                       "muon-jet pairs");
687 +        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
688 +                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
689 +                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
690 +                                                                     "track-event pairs");
691 +        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
692 +                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
693 +                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
694 +                                                                        "electron-track pairs");
695 +        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
696 +                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
697 +                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
698 +                                                                    "muon-track pairs");
699 +        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
700 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
701 +                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
702 +                                                                  "muon-tau pairs");
703 +        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
704 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
705 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
706 +                                                                 "tau-tau pairs");
707 +        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
708 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
709 +                                                                 cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
710 +                                                                 "tau-track pairs");
711 +        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
712 +                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
713 +                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
714 +                                                                          "electron-trigobj pairs");
715 +        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
716 +                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
717 +                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
718 +                                                                      "muon-trigobj pairs");
719  
720 +        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
721 +      }
722  
329    }//end loop over all cuts
723  
724  
725 +    }//end loop over all cuts
726  
727  
728      //use cumulative flags to apply cuts at event level
# Line 345 | Line 739 | OSUAnalysis::analyze (const edm::Event &
739        cut currentCut = currentChannel.cuts.at(currentCutIndex);
740        int numberPassing = 0;
741  
742 <      for (uint object = 0; object != cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).size() ; object++)
743 <          if(cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).at(object)) numberPassing++;
744 <
351 <
742 >      for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
743 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
744 >      }
745        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
746        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
354
747        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
748  
749      }
750  
751 <    cutFlows_.at(currentChannelIndex)->fillCutFlow();
751 >    double scaleFactor = masterScaleFactor;
752  
753 +    muonScaleFactor_ = electronScaleFactor_ = 1.0;
754 +    if(applyLeptonSF_ && datasetType_ != "data"){
755 +      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
756 +        vector<bool> muonFlags;
757 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
758 +          if (cumulativeFlags.at("muons").at(i).size()){
759 +            muonFlags = cumulativeFlags.at("muons").at(i);
760 +            break;
761 +          }
762 +        }
763 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
764 +          if(!muonFlags.at(muonIndex)) continue;
765 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
766 +        }
767 +      }
768 +      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
769 +        vector<bool> electronFlags;
770 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
771 +          if (cumulativeFlags.at("electrons").at(i).size()){
772 +            electronFlags = cumulativeFlags.at("electrons").at(i);
773 +            break;
774 +          }
775 +        }
776 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
777 +          if(!electronFlags.at(electronIndex)) continue;
778 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
779 +        }
780 +      }
781 +    }
782 +    scaleFactor *= muonScaleFactor_;
783 +    scaleFactor *= electronScaleFactor_;
784  
785 <    if(!eventPassedAllCuts)continue;
785 >    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
786  
787 +    if(!eventPassedAllCuts)continue;
788  
789 <    //set position of primary vertex in event, in order to calculate quantities relative to it
790 <    primaryVertex_ = 0;
791 <    vector<bool> vertexFlags = cumulativeFlags["primaryvertexs"].back();
792 <    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
793 <      if(!vertexFlags.at(vertexIndex)) continue;
794 <      primaryVertex_ = new BNprimaryvertex (primaryvertexs->at (vertexIndex));
795 <      break;
789 >    if (printEventInfo_) {
790 >      // Write information about event to screen, for testing purposes.
791 >      cout << "Event passed all cuts in channel " <<  currentChannel.name
792 >           << ": run="  << events->at(0).run
793 >           << "  lumi=" << events->at(0).lumi
794 >           << "  event=" << events->at(0).evt
795 >           << endl;
796      }
797  
374
375
798      //filling histograms
799      for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
800        histogram currentHistogram = histograms.at(histogramIndex);
801  
802        if(currentHistogram.inputVariables.size() == 1){
803 <        TH1D* histo;
804 <        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
805 <        if(currentHistogram.inputCollection == "jets") fillHistogram(histo,currentHistogram,jets.product());
806 <        else if(currentHistogram.inputCollection == "muons") fillHistogram(histo,currentHistogram,muons.product());
807 <        else if(currentHistogram.inputCollection == "electrons") fillHistogram(histo,currentHistogram,electrons.product());
808 <        else if(currentHistogram.inputCollection == "events") fillHistogram(histo,currentHistogram,events.product());
809 <        else if(currentHistogram.inputCollection == "taus") fillHistogram(histo,currentHistogram,taus.product());
810 <        else if(currentHistogram.inputCollection == "mets") fillHistogram(histo,currentHistogram,mets.product());
811 <        else if(currentHistogram.inputCollection == "tracks") fillHistogram(histo,currentHistogram,tracks.product());
812 <        else if(currentHistogram.inputCollection == "genjets") fillHistogram(histo,currentHistogram,genjets.product());
813 <        else if(currentHistogram.inputCollection == "mcparticles") fillHistogram(histo,currentHistogram,mcparticles.product());
814 <        else if(currentHistogram.inputCollection == "primaryvertexs") fillHistogram(histo,currentHistogram,primaryvertexs.product());
815 <        else if(currentHistogram.inputCollection == "bxlumis") fillHistogram(histo,currentHistogram,bxlumis.product());
816 <        else if(currentHistogram.inputCollection == "photons") fillHistogram(histo,currentHistogram,photons.product());
817 <        else if(currentHistogram.inputCollection == "superclusters") fillHistogram(histo,currentHistogram,superclusters.product());
803 >        TH1D* histo;
804 >        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
805 >
806 >        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
807 >        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
808 >        else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").back(),scaleFactor);
809 >        else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").back(),scaleFactor);
810 >        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
811 >                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
812 >                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
813 >        else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
814 >                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("secondary muons").back(), \
815 >                                                                                       cumulativeFlags.at("muon-secondary muon pairs").back(),scaleFactor);
816 >        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
817 >        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
818 >                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
819 >                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
820 >        else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
821 >                                                                                               cumulativeFlags.at("jets").back(),cumulativeFlags.at("jets").back(),\
822 >                                                                                               cumulativeFlags.at("jet-jet pairs").back(),scaleFactor);
823 >        else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
824 >                                                                                       cumulativeFlags.at("electrons").back(),cumulativeFlags.at("secondary electrons").back(), \
825 >                                                                                       cumulativeFlags.at("electron-secondary electron pairs").back(),scaleFactor);
826 >        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
827 >                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
828 >                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
829 >        else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
830 >                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("jets").back(),
831 >                                                                                           cumulativeFlags.at("electron-jet pairs").back(),scaleFactor);
832 >        else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
833 >                                                                                           cumulativeFlags.at("muons").back(),cumulativeFlags.at("jets").back(),
834 >                                                                                           cumulativeFlags.at("muon-jet pairs").back(),scaleFactor);
835 >        else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
836 >                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),
837 >                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);
838 >        else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
839 >                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),
840 >                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);
841 >        else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
842 >                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),
843 >                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);
844 >        else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
845 >                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),
846 >                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);
847 >        else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
848 >                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("tracks").back(),
849 >                                                                                     cumulativeFlags.at("tau-track pairs").back(),scaleFactor);
850 >        else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
851 >                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("trigobjs").back(),
852 >                                                                                              cumulativeFlags.at("electron-trigobj pairs").back(),scaleFactor);
853 >        else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
854 >                                                                                          cumulativeFlags.at("muons").back(),cumulativeFlags.at("trigobjs").back(),
855 >                                                                                          cumulativeFlags.at("muon-trigobj pairs").back(),scaleFactor);
856 >
857 >        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
858 >        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
859 >        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
860 >        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
861 >        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
862 >        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
863 >        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
864 >        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
865 >        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
866 >        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
867 >        else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").back(),scaleFactor);
868 >        else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").back(),scaleFactor);
869        }
870        else if(currentHistogram.inputVariables.size() == 2){
871 <        TH2D* histo;
872 <        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
873 <        if(currentHistogram.inputCollection == "jets") fillHistogram(histo,currentHistogram,jets.product());
874 <        else if(currentHistogram.inputCollection == "muons") fillHistogram(histo,currentHistogram,muons.product());
875 <        else if(currentHistogram.inputCollection == "electrons") fillHistogram(histo,currentHistogram,electrons.product());
876 <        else if(currentHistogram.inputCollection == "events") fillHistogram(histo,currentHistogram,events.product());
877 <        else if(currentHistogram.inputCollection == "taus") fillHistogram(histo,currentHistogram,taus.product());
878 <        else if(currentHistogram.inputCollection == "mets") fillHistogram(histo,currentHistogram,mets.product());
879 <        else if(currentHistogram.inputCollection == "tracks") fillHistogram(histo,currentHistogram,tracks.product());
880 <        else if(currentHistogram.inputCollection == "genjets") fillHistogram(histo,currentHistogram,genjets.product());
881 <        else if(currentHistogram.inputCollection == "mcparticles") fillHistogram(histo,currentHistogram,mcparticles.product());
882 <        else if(currentHistogram.inputCollection == "primaryvertexs") fillHistogram(histo,currentHistogram,primaryvertexs.product());
883 <        else if(currentHistogram.inputCollection == "bxlumis") fillHistogram(histo,currentHistogram,bxlumis.product());
884 <        else if(currentHistogram.inputCollection == "photons") fillHistogram(histo,currentHistogram,photons.product());
885 <        else if(currentHistogram.inputCollection == "superclusters") fillHistogram(histo,currentHistogram,superclusters.product());
886 <      }
871 >        TH2D* histo;
872 >        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
873 >
874 >        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
875 >        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
876 >        else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").back(),scaleFactor);
877 >        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
878 >                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
879 >                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
880 >        else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
881 >                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("secondary muons").back(), \
882 >                                                                                       cumulativeFlags.at("muon-secondary muon pairs").back(),scaleFactor);
883 >        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
884 >        else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").back(),scaleFactor);
885 >        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
886 >                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
887 >                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
888 >        else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
889 >                                                                                               cumulativeFlags.at("jets").back(),cumulativeFlags.at("jets").back(), \
890 >                                                                                               cumulativeFlags.at("jet-jet pairs").back(),scaleFactor);
891 >        else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
892 >                                                                                       cumulativeFlags.at("electrons").back(),cumulativeFlags.at("secondary electrons").back(), \
893 >                                                                                       cumulativeFlags.at("electron-secondary electron pairs").back(),scaleFactor);
894 >        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
895 >                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
896 >                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
897 >        else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
898 >                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("jets").back(), \
899 >                                                                                           cumulativeFlags.at("electron-jet pairs").back(),scaleFactor);
900 >        else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
901 >                                                                                           cumulativeFlags.at("muons").back(),cumulativeFlags.at("jets").back(), \
902 >                                                                                           cumulativeFlags.at("muon-jet pairs").back(),scaleFactor);
903 >        else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
904 >                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),
905 >                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);
906 >        else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
907 >                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),
908 >                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);
909 >        else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
910 >                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),
911 >                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);
912 >        else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
913 >                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),
914 >                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);
915 >        else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
916 >                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("tracks").back(),
917 >                                                                                     cumulativeFlags.at("tau-track pairs").back(),scaleFactor);
918 >        else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
919 >                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("trigobjs").back(),
920 >                                                                                              cumulativeFlags.at("electron-trigobj pairs").back(),scaleFactor);
921 >        else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
922 >                                                                                          cumulativeFlags.at("muons").back(),cumulativeFlags.at("trigobjs").back(),
923 >                                                                                          cumulativeFlags.at("muon-trigobj pairs").back(),scaleFactor);
924 >        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
925 >        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
926 >        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
927 >        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
928 >        else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
929 >                                                                                         cumulativeFlags.at("tracks").back(),cumulativeFlags.at("events").back(),
930 >                                                                                         cumulativeFlags.at("track-event pairs").back(),scaleFactor);
931 >        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
932 >        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
933 >        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
934 >        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
935 >        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
936 >        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
937 >        else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").back(),scaleFactor);
938 >        else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").back(),scaleFactor);
939 >      }
940      }
941  
942  
943 +
944      //fills histograms with the sizes of collections
945      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
946 +
947        string currentObject = objectsToPlot.at(currentObjectIndex);
948 <      string tempCurrentObject = currentObject;
949 <      tempCurrentObject[0] = toupper(tempCurrentObject[0]);
948 >
949 >      string objectToPlot = "";
950 >
951 >      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
952 >      if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
953 >      else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
954 >      else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
955 >      else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
956 >      else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
957 >      else if(currentObject == "jet-jet pairs")            objectToPlot = "dijetPairs";
958 >      else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
959 >      else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
960 >      else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
961 >      else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
962 >      else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
963 >      else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
964 >      else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
965 >      else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
966 >      else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
967 >      else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
968 >      else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
969 >      else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
970 >      else objectToPlot = currentObject;
971 >
972 >      string tempCurrentObject = objectToPlot;
973 >      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
974        string histoName = "num" + tempCurrentObject;
975  
976 <      if(currentObject == "jets") oneDHists_.at(currentChannelIndex)[histoName]->Fill(jets->size());
977 <      else if(currentObject == "muons") oneDHists_.at(currentChannelIndex)[histoName]->Fill(muons->size());
978 <      else if(currentObject == "electrons") oneDHists_.at(currentChannelIndex)[histoName]->Fill(electrons->size());
979 <      else if(currentObject == "events") oneDHists_.at(currentChannelIndex)[histoName]->Fill(events->size());
980 <      else if(currentObject == "taus") oneDHists_.at(currentChannelIndex)[histoName]->Fill(taus->size());
981 <      else if(currentObject == "mets") oneDHists_.at(currentChannelIndex)[histoName]->Fill(mets->size());
982 <      else if(currentObject == "tracks") oneDHists_.at(currentChannelIndex)[histoName]->Fill(tracks->size());
983 <      else if(currentObject == "genjets") oneDHists_.at(currentChannelIndex)[histoName]->Fill(genjets->size());
984 <      else if(currentObject == "mcparticles") oneDHists_.at(currentChannelIndex)[histoName]->Fill(mcparticles->size());
985 <      else if(currentObject == "primaryvertexs") oneDHists_.at(currentChannelIndex)[histoName]->Fill(primaryvertexs->size());
986 <      else if(currentObject == "bxlumis") oneDHists_.at(currentChannelIndex)[histoName]->Fill(bxlumis->size());
987 <      else if(currentObject == "photons") oneDHists_.at(currentChannelIndex)[histoName]->Fill(photons->size());
988 <      else if(currentObject == "superclusters") oneDHists_.at(currentChannelIndex)[histoName]->Fill(superclusters->size());
976 >      //set position of primary vertex in event, in order to calculate quantities relative to it
977 >      if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
978 >        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
979 >        int numToPlot = 0;
980 >        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
981 >          if(lastCutFlags.at(currentFlag)) numToPlot++;
982 >        }
983 >        if(objectToPlot == "primaryvertexs"){
984 >          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
985 >          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
986 >        }
987 >        else {
988 >          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
989 >        }
990 >      }
991 >      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
992 >      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
993 >      else if(objectToPlot == "secondaryMuons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
994 >      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
995 >      else if(objectToPlot == "muonSecondaryMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
996 >      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
997 >      else if(objectToPlot == "secondaryElectrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
998 >      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
999 >      else if(objectToPlot == "electronSecondaryElectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
1000 >      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
1001 >      else if(objectToPlot == "electronJetPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*jets->size(),scaleFactor);
1002 >      else if(objectToPlot == "muonJetPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*jets->size(),scaleFactor);
1003 >      else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
1004 >      else if(objectToPlot == "electronTrigobjPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*trigobjs->size(),scaleFactor);
1005 >      else if(objectToPlot == "muonTrigobjPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*trigobjs->size(),scaleFactor);
1006 >      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
1007 >      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
1008 >      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
1009 >      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
1010 >      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
1011 >      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
1012 >      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
1013 >      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
1014 >      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
1015 >      else if(objectToPlot == "trigobjs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(trigobjs->size(),scaleFactor);
1016 >      else if(objectToPlot == "primaryvertexs"){
1017 >        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1018 >        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1019 >      }
1020 >      if(objectToPlot == "stops" && datasetType_ == "signalMC") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(stops->size(),scaleFactor);
1021 >
1022 >    } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1023  
438    }
1024    } //end loop over channel
1025  
1026 <  masterCutFlow_->fillCutFlow();
1026 >  masterCutFlow_->fillCutFlow(masterScaleFactor);
1027  
1028 + } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1029  
444 }
1030  
1031  
1032   bool
# Line 453 | Line 1038 | OSUAnalysis::evaluateComparison (double
1038    else if(comparison == "<")  return testValue <  cutValue;
1039    else if(comparison == "<=") return testValue <= cutValue;
1040    else if(comparison == "==") return testValue == cutValue;
1041 +  else if(comparison == "=") return testValue == cutValue;
1042    else if(comparison == "!=") return testValue != cutValue;
1043 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1043 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1044 >
1045 > }
1046 >
1047 > bool
1048 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1049 >
1050 >
1051 >  if(comparison == ">")       return testValue >  cutValue;
1052 >  else if(comparison == ">=") return testValue >= cutValue;
1053 >  else if(comparison == "<")  return testValue <  cutValue;
1054 >  else if(comparison == "<=") return testValue <= cutValue;
1055 >  else if(comparison == "==") return testValue == cutValue;
1056 >  else if(comparison == "=") return testValue == cutValue;
1057 >  else if(comparison == "!=") return testValue != cutValue;
1058 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1059  
1060   }
1061  
# Line 468 | Line 1069 | OSUAnalysis::evaluateTriggers (vector<st
1069        if(trigger->pass != 1) continue;
1070        for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1071          {
1072 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1072 >          if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos){
1073              triggerDecision = true;
1074            }
1075          }
# Line 477 | Line 1078 | OSUAnalysis::evaluateTriggers (vector<st
1078  
1079   }
1080  
1081 < std::vector<std::string>
1081 > vector<string>
1082   OSUAnalysis::splitString (string inputString){
1083  
1084 <  std::stringstream stringStream(inputString);
1085 <  std::istream_iterator<std::string> begin(stringStream);
1086 <  std::istream_iterator<std::string> end;
1087 <  std::vector<std::string> stringVector(begin, end);
1084 >  stringstream stringStream(inputString);
1085 >  istream_iterator<string> begin(stringStream);
1086 >  istream_iterator<string> end;
1087 >  vector<string> stringVector(begin, end);
1088    return stringVector;
1089  
1090   }
1091  
1092 +
1093 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1094 +  // Set two object strings from the tempInputCollection string,
1095 +  // For example, if tempInputCollection is "electron-muon pairs",
1096 +  // then obj1 = "electrons" and obj2 = "muons".
1097 +  // Note that the objects have an "s" appended.
1098 +
1099 +  int dashIndex = tempInputCollection.find("-");
1100 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1101 +  int secondWordLength = spaceIndex - dashIndex;
1102 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1103 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1104 +
1105 + }
1106 +
1107 +
1108 + string OSUAnalysis::getObjToGet(string obj) {
1109 +  // Return the string corresponding to the object to get for the given obj string.
1110 +  // Right now this only handles the case in which obj contains "secondary",
1111 +  // e.g, "secondary muons".
1112 +  // Note that "s" is NOT appended.
1113 +
1114 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1115 +  int firstSpaceIndex = obj.find_first_of(" ");
1116 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1117 +
1118 + }
1119 +
1120 +
1121 + //!jet valueLookup
1122   double
1123 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1123 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1124  
1125    double value = 0.0;
1126    if(variable == "energy") value = object->energy;
# Line 609 | Line 1240 | OSUAnalysis::valueLookup (const BNjet* o
1240    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1241  
1242  
1243 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1243 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1244  
1245    value = applyFunction(function, value);
1246  
# Line 617 | Line 1248 | OSUAnalysis::valueLookup (const BNjet* o
1248   }
1249  
1250  
1251 <
1251 > //!muon valueLookup
1252   double
1253 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1253 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1254  
1255    double value = 0.0;
1256    if(variable == "energy") value = object->energy;
# Line 635 | Line 1266 | OSUAnalysis::valueLookup (const BNmuon*
1266    else if(variable == "ecalIso") value = object->ecalIso;
1267    else if(variable == "hcalIso") value = object->hcalIso;
1268    else if(variable == "caloIso") value = object->caloIso;
1269 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
1269 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
1270    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
1271    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
1272    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 774 | Line 1405 | OSUAnalysis::valueLookup (const BNmuon*
1405    else if(variable == "time_ndof") value = object->time_ndof;
1406  
1407    //user-defined variables
1408 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1409 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1410 <  else if(variable == "detIso") value = (object->trackIso + object->caloIso) / object->pt;
1411 <  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1408 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1409 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1410 >  else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1411 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1412    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1413 +  else if(variable == "metMT") {
1414 +    if (const BNmet *met = chosenMET ())
1415 +      {
1416 +        double dPhi = deltaPhi (object->phi, met->phi);
1417 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1418 +      }
1419 +    else
1420 +      value = -999;
1421 +  }
1422 +
1423 +
1424 +
1425 +  else if(variable == "correctedD0VertexInEBPlus"){
1426 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1427 +    else value = -999;
1428 +  }
1429 +  else if(variable == "correctedD0VertexOutEBPlus"){
1430 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1431 +    else value = -999;
1432 +  }
1433 +  else if(variable == "correctedD0VertexEEPlus"){
1434 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1435 +    else value = -999;
1436 +  }
1437 +
1438 +  else if(variable == "correctedD0BeamspotInEBPlus"){
1439 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1440 +    else value = -999;
1441 +  }
1442 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
1443 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1444 +    else value = -999;
1445 +  }
1446 +  else if(variable == "correctedD0BeamspotEEPlus"){
1447 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1448 +    else value = -999;
1449 +  }
1450 +
1451 +  else if(variable == "correctedD0VertexInEBMinus"){
1452 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1453 +    else value = -999;
1454 +  }
1455 +  else if(variable == "correctedD0VertexOutEBMinus"){
1456 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1457 +    else value = -999;
1458 +  }
1459 +  else if(variable == "correctedD0VertexEEMinus"){
1460 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1461 +    else value = -999;
1462 +  }
1463 +
1464 +  else if(variable == "correctedD0BeamspotInEBMinus"){
1465 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1466 +    else value = -999;
1467 +  }
1468 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
1469 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1470 +    else value = -999;
1471 +  }
1472 +  else if(variable == "correctedD0BeamspotEEMinus"){
1473 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1474 +    else value = -999;
1475 +  }
1476 +
1477 +
1478 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1479 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1480 +    else value = -999;
1481 +  }
1482 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1483 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1484 +    else value = -999;
1485 +  }
1486 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
1487 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1488 +    else value = -999;
1489 +  }
1490 +
1491 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1492 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1493 +    else value = -999;
1494 +  }
1495 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1496 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1497 +    else value = -999;
1498 +  }
1499 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1500 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1501 +    else value = -999;
1502 +  }
1503 +
1504 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1505 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1506 +    else value = -999;
1507 +  }
1508 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1509 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1510 +    else value = -999;
1511 +  }
1512 +  else if(variable == "correctedD0VertexEENegativeCharge"){
1513 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1514 +    else value = -999;
1515 +  }
1516 +
1517 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1518 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1519 +    else value = -999;
1520 +  }
1521 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1522 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1523 +    else value = -999;
1524 +  }
1525 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1526 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1527 +    else value = -999;
1528 +  }
1529 +
1530 +
1531    else if(variable == "tightID") {
1532 <    value = object->isGlobalMuon > 0            \
1533 <      && object->isPFMuon > 0                   \
1534 <      && object->normalizedChi2 < 10            \
1535 <      && object->numberOfValidMuonHits > 0      \
1536 <      && object->numberOfMatchedStations > 1    \
1537 <      && fabs(object->correctedD0Vertex) < 0.2  \
1538 <      && fabs(object->correctedDZ) < 0.5        \
1539 <      && object->numberOfValidPixelHits > 0     \
1532 >    value = object->isGlobalMuon > 0                \
1533 >      && object->isPFMuon > 0                        \
1534 >      && object->normalizedChi2 < 10                \
1535 >                                  && object->numberOfValidMuonHits > 0        \
1536 >      && object->numberOfMatchedStations > 1        \
1537 >      && fabs(object->correctedD0Vertex) < 0.2        \
1538 >      && fabs(object->correctedDZ) < 0.5        \
1539 >      && object->numberOfValidPixelHits > 0                \
1540        && object->numberOfLayersWithMeasurement > 5;
792    
793
1541    }
1542    else if(variable == "tightIDdisplaced"){
1543 <    value = object->isGlobalMuon > 0            \
1544 <      && object->isPFMuon > 0                   \
1545 <      && object->normalizedChi2 < 10            \
1546 <      && object->numberOfValidMuonHits > 0      \
1547 <      && object->numberOfMatchedStations > 1    \
801 <      && object->numberOfValidPixelHits > 0     \
1543 >    value = object->isGlobalMuon > 0                \
1544 >      && object->normalizedChi2 < 10                \
1545 >                                  && object->numberOfValidMuonHits > 0        \
1546 >      && object->numberOfMatchedStations > 1        \
1547 >      && object->numberOfValidPixelHits > 0        \
1548        && object->numberOfLayersWithMeasurement > 5;
1549    }
1550  
1551 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1551 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1552 >
1553 >  else if(variable == "genMatchedPdgId"){
1554 >    int index = getGenMatchedParticleIndex(object);
1555 >    if(index == -1) value = 0;
1556 >    else value = mcparticles->at(index).id;
1557 >  }
1558 >
1559 >  else if(variable == "genMatchedId"){
1560 >    int index = getGenMatchedParticleIndex(object);
1561 >    if(index == -1) value = 0;
1562 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
1563 >  }
1564 >  else if(variable == "genMatchedMotherId"){
1565 >    int index = getGenMatchedParticleIndex(object);
1566 >    if(index == -1) value = 0;
1567 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1568 >  }
1569 >  else if(variable == "genMatchedMotherIdReverse"){
1570 >    int index = getGenMatchedParticleIndex(object);
1571 >    if(index == -1) value = 24;
1572 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1573 >  }
1574 >  else if(variable == "genMatchedGrandmotherId"){
1575 >    int index = getGenMatchedParticleIndex(object);
1576 >    if(index == -1) value = 0;
1577 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1578 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1579 >      if(motherIndex == -1) value = 0;
1580 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1581 >    }
1582 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1583 >  }
1584 >  else if(variable == "genMatchedGrandmotherIdReverse"){
1585 >    int index = getGenMatchedParticleIndex(object);
1586 >    if(index == -1) value = 24;
1587 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1588 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1589 >      if(motherIndex == -1) value = 24;
1590 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1591 >    }
1592 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1593 >  }
1594 >  else if(variable == "pfMuonsFromVertex"){
1595 >    double d0Error, dzError;
1596 >
1597 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1598 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1599 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1600 >         || fabs (object->correctedD0Vertex / d0Error) > 99.0
1601 >         || fabs (object->correctedDZ / dzError) > 99.0;
1602 >    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1603 >  }
1604 >
1605 >
1606 >
1607 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1608  
1609    value = applyFunction(function, value);
1610  
1611    return value;
1612   }
1613  
1614 <
1614 > //!electron valueLookup
1615   double
1616 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1616 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1617  
1618    double value = 0.0;
1619    if(variable == "energy") value = object->energy;
# Line 972 | Line 1774 | OSUAnalysis::valueLookup (const BNelectr
1774    else if(variable == "passConvVeto") value = object->passConvVeto;
1775  
1776    //user-defined variables
1777 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1778 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1779 <  else if(variable == "detIso") value = (object->trackIso + object->caloIso) / object->pt;
1777 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1778 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1779 >  else if(variable == "detIso") value = (object->trackIso) / object->pt;
1780    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1781 +  else if(variable == "metMT") {
1782 +    if (const BNmet *met = chosenMET ())
1783 +      {
1784 +        double dPhi = deltaPhi (object->phi, met->phi);
1785 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1786 +      }
1787 +    else
1788 +      value = -999;
1789 +  }
1790  
1791 +  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
1792 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
1793 +    else value = -999;
1794 +  }
1795 +  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
1796 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
1797 +    else value = -999;
1798 +  }
1799  
1800 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1800 >  else if(variable == "correctedD0VertexInEBPlus"){
1801 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1802 >    else value = -999;
1803 >  }
1804 >  else if(variable == "correctedD0VertexOutEBPlus"){
1805 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1806 >    else value = -999;
1807 >  }
1808 >  else if(variable == "correctedD0VertexEEPlus"){
1809 >    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
1810 >    else value = -999;
1811 >  }
1812 >
1813 >  else if(variable == "correctedD0BeamspotInEBPlus"){
1814 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1815 >    else value = -999;
1816 >  }
1817 >  else if(variable == "correctedD0BeamspotOutEBPlus"){
1818 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1819 >    else value = -999;
1820 >  }
1821 >  else if(variable == "correctedD0BeamspotEEPlus"){
1822 >    if(object->isEE && object->eta > 0) value = object->correctedD0;
1823 >    else value = -999;
1824 >  }
1825 >
1826 >  else if(variable == "correctedD0VertexInEBMinus"){
1827 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1828 >    else value = -999;
1829 >  }
1830 >  else if(variable == "correctedD0VertexOutEBMinus"){
1831 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1832 >    else value = -999;
1833 >  }
1834 >  else if(variable == "correctedD0VertexEEMinus"){
1835 >    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
1836 >    else value = -999;
1837 >  }
1838 >
1839 >  else if(variable == "correctedD0BeamspotInEBMinus"){
1840 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1841 >    else value = -999;
1842 >  }
1843 >  else if(variable == "correctedD0BeamspotOutEBMinus"){
1844 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1845 >    else value = -999;
1846 >  }
1847 >  else if(variable == "correctedD0BeamspotEEMinus"){
1848 >    if(object->isEE && object->eta < 0) value = object->correctedD0;
1849 >    else value = -999;
1850 >  }
1851 >
1852 >  else if(variable == "tightID"){
1853 >    if (object->isEB)
1854 >      {
1855 >        value = fabs(object->delEtaIn) < 0.004 \
1856 >          && fabs (object->delPhiIn) < 0.03 \
1857 >          && object->scSigmaIEtaIEta < 0.01 \
1858 >          && object->hadOverEm < 0.12 \
1859 >          && fabs (object->correctedD0Vertex) < 0.02 \
1860 >          && fabs (object->correctedDZ) < 0.1 \
1861 >          && object->absInvEMinusInvPin < 0.05 \
1862 >          && object->passConvVeto;
1863 >      }
1864 >    else
1865 >      {
1866 >        value = fabs(object->delEtaIn) < 0.005 \
1867 >          && fabs (object->delPhiIn) < 0.02 \
1868 >          && object->scSigmaIEtaIEta < 0.03 \
1869 >          && object->hadOverEm < 0.10 \
1870 >          && fabs (object->correctedD0Vertex) < 0.02 \
1871 >          && fabs (object->correctedDZ) < 0.1 \
1872 >          && object->absInvEMinusInvPin < 0.05 \
1873 >          && object->passConvVeto;
1874 >      }
1875 >  }
1876 >
1877 >  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1878 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1879 >    else value = -999;
1880 >  }
1881 >  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1882 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1883 >    else value = -999;
1884 >  }
1885 >  else if(variable == "correctedD0VertexEEPositiveCharge"){
1886 >    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
1887 >    else value = -999;
1888 >  }
1889 >
1890 >  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1891 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1892 >    else value = -999;
1893 >  }
1894 >  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1895 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1896 >    else value = -999;
1897 >  }
1898 >  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1899 >    if(object->isEE && object->charge > 0) value = object->correctedD0;
1900 >    else value = -999;
1901 >  }
1902 >
1903 >  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1904 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1905 >    else value = -999;
1906 >  }
1907 >  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1908 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1909 >    else value = -999;
1910 >  }
1911 >  else if(variable == "correctedD0VertexEENegativeCharge"){
1912 >    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
1913 >    else value = -999;
1914 >  }
1915 >
1916 >  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1917 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1918 >    else value = -999;
1919 >  }
1920 >  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1921 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1922 >    else value = -999;
1923 >  }
1924 >  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1925 >    if(object->isEE && object->charge < 0) value = object->correctedD0;
1926 >    else value = -999;
1927 >  }
1928 >
1929 >
1930 >  else if(variable == "tightIDdisplaced"){
1931 >    if (object->isEB)
1932 >      {
1933 >        value = fabs(object->delEtaIn) < 0.004 \
1934 >          && fabs (object->delPhiIn) < 0.03 \
1935 >          && object->scSigmaIEtaIEta < 0.01 \
1936 >          && object->hadOverEm < 0.12 \
1937 >          && object->absInvEMinusInvPin < 0.05;
1938 >      }
1939 >    else
1940 >      {
1941 >        value = fabs (object->delEtaIn) < 0.005 \
1942 >          && fabs (object->delPhiIn) < 0.02 \
1943 >          && object->scSigmaIEtaIEta < 0.03 \
1944 >          && object->hadOverEm < 0.10 \
1945 >          && object->absInvEMinusInvPin < 0.05;
1946 >      }
1947 >  }
1948 >
1949 >
1950 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1951 >
1952 >  else if(variable == "genMatchedPdgId"){
1953 >    int index = getGenMatchedParticleIndex(object);
1954 >    if(index == -1) value = 0;
1955 >    else value = mcparticles->at(index).id;
1956 >  }
1957 >
1958 >
1959 >  else if(variable == "genMatchedId"){
1960 >    int index = getGenMatchedParticleIndex(object);
1961 >    if(index == -1) value = 0;
1962 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
1963 >  }
1964 >  else if(variable == "genMatchedMotherId"){
1965 >    int index = getGenMatchedParticleIndex(object);
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;
1977 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1978 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1979 >      if(motherIndex == -1) value = 0;
1980 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
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 == "pfElectronsFromVertex"){
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 = !value;
2003 >  }
2004 >
2005 >
2006 >
2007 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2008  
2009    value = applyFunction(function, value);
2010  
2011    return value;
2012   }
2013  
2014 <
2014 > //!event valueLookup
2015   double
2016 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2016 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2017  
2018    double value = 0.0;
2019  
# Line 1055 | Line 2081 | OSUAnalysis::valueLookup (const BNevent*
2081    else if(variable == "id1") value = object->id1;
2082    else if(variable == "id2") value = object->id2;
2083    else if(variable == "evt") value = object->evt;
2084 +  else if(variable == "puScaleFactor"){
2085 +    if(datasetType_ != "data")
2086 +      value = puWeight_->at (events->at (0).numTruePV);
2087 +    else
2088 +      value = 1.0;
2089 +  }
2090 +  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2091 +  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2092 +  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2093  
2094 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2094 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2095  
2096    value = applyFunction(function, value);
2097  
2098    return value;
2099   }
2100  
2101 + //!tau valueLookup
2102   double
2103 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2103 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2104  
2105    double value = 0.0;
2106  
# Line 1109 | Line 2145 | OSUAnalysis::valueLookup (const BNtau* o
2145    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2146  
2147  
2148 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2148 >
2149 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2150 >
2151 >  else if(variable == "genMatchedPdgId"){
2152 >    int index = getGenMatchedParticleIndex(object);
2153 >    if(index == -1) value = 0;
2154 >    else value = mcparticles->at(index).id;
2155 >  }
2156 >
2157 >  else if(variable == "genMatchedId"){
2158 >    int index = getGenMatchedParticleIndex(object);
2159 >    if(index == -1) value = 0;
2160 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2161 >  }
2162 >  else if(variable == "genMatchedMotherId"){
2163 >    int index = getGenMatchedParticleIndex(object);
2164 >    if(index == -1) value = 0;
2165 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2166 >  }
2167 >  else if(variable == "genMatchedMotherIdReverse"){
2168 >    int index = getGenMatchedParticleIndex(object);
2169 >    if(index == -1) value = 24;
2170 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2171 >  }
2172 >  else if(variable == "genMatchedGrandmotherId"){
2173 >    int index = getGenMatchedParticleIndex(object);
2174 >    if(index == -1) value = 0;
2175 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2176 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2177 >      if(motherIndex == -1) value = 0;
2178 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2179 >    }
2180 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2181 >  }
2182 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2183 >    int index = getGenMatchedParticleIndex(object);
2184 >    if(index == -1) value = 24;
2185 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2186 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2187 >      if(motherIndex == -1) value = 24;
2188 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2189 >    }
2190 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2191 >  }
2192 >
2193 >
2194 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2195  
2196    value = applyFunction(function, value);
2197  
2198    return value;
2199   }
2200  
2201 + //!met valueLookup
2202   double
2203 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2203 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2204  
2205    double value = 0.0;
2206  
# Line 1181 | Line 2264 | OSUAnalysis::valueLookup (const BNmet* o
2264    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2265    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2266  
2267 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2267 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2268  
2269    value = applyFunction(function, value);
2270  
2271    return value;
2272   }
2273  
2274 + //!track valueLookup
2275   double
2276 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2276 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2277  
2278    double value = 0.0;
2279 +  double pMag = sqrt(object->pt * object->pt +
2280 +                     object->pz * object->pz);
2281  
2282    if(variable == "pt") value = object->pt;
2283    else if(variable == "px") value = object->px;
# Line 1212 | Line 2298 | OSUAnalysis::valueLookup (const BNtrack*
2298    else if(variable == "isHighPurity") value = object->isHighPurity;
2299  
2300  
2301 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2301 >  //additional BNs info for disappTrks
2302 >  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2303 >  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2304 >  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2305 >  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2306 >  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2307 >  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2308 >  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2309 >  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2310 >  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2311 >  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2312 >  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2313 >
2314 >  //user defined variables
2315 >  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;
2316 >  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2317 >  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2318 >  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2319 >  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2320 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2321 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2322 >  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2323 >  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2324 >  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2325 >  else if(variable == "ptError")                    value = object->ptError;
2326 >  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2327 >  else if (variable == "d0wrtPV"){
2328 >    double vx = object->vx - chosenVertex ()->x,
2329 >      vy = object->vy - chosenVertex ()->y,
2330 >      px = object->px,
2331 >      py = object->py,
2332 >      pt = object->pt;
2333 >    value = (-vx * py + vy * px) / pt;
2334 >  }
2335 >  else if (variable == "dZwrtPV"){
2336 >    double vx = object->vx - chosenVertex ()->x,
2337 >      vy = object->vy - chosenVertex ()->y,
2338 >      vz = object->vz - chosenVertex ()->z,
2339 >      px = object->px,
2340 >      py = object->py,
2341 >      pz = object->pz,
2342 >      pt = object->pt;
2343 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2344 >  }
2345 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2346 >
2347 >  else if(variable == "genMatchedPdgId"){
2348 >    int index = getGenMatchedParticleIndex(object);
2349 >    if(index == -1) value = 0;
2350 >    else value = mcparticles->at(index).id;
2351 >  }
2352 >
2353 >
2354 >  else if(variable == "genMatchedId"){
2355 >    int index = getGenMatchedParticleIndex(object);
2356 >    if(index == -1) value = 0;
2357 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2358 >  }
2359 >  else if(variable == "genMatchedMotherId"){
2360 >    int index = getGenMatchedParticleIndex(object);
2361 >    if(index == -1) value = 0;
2362 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2363 >  }
2364 >  else if(variable == "genMatchedMotherIdReverse"){
2365 >    int index = getGenMatchedParticleIndex(object);
2366 >    if(index == -1) value = 24;
2367 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2368 >  }
2369 >  else if(variable == "genMatchedGrandmotherId"){
2370 >    int index = getGenMatchedParticleIndex(object);
2371 >    if(index == -1) value = 0;
2372 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2373 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2374 >      if(motherIndex == -1) value = 0;
2375 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2376 >    }
2377 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2378 >  }
2379 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2380 >    int index = getGenMatchedParticleIndex(object);
2381 >    if(index == -1) value = 24;
2382 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2383 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2384 >      if(motherIndex == -1) value = 24;
2385 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2386 >    }
2387 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2388 >  }
2389 >
2390 >
2391 >
2392 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2393  
2394    value = applyFunction(function, value);
2395  
2396    return value;
2397   }
2398  
2399 + //!genjet valueLookup
2400   double
2401 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2401 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2402  
2403    double value = 0.0;
2404  
# Line 1240 | Line 2418 | OSUAnalysis::valueLookup (const BNgenjet
2418    else if(variable == "charge") value = object->charge;
2419  
2420  
2421 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2421 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2422  
2423    value = applyFunction(function, value);
2424  
2425    return value;
2426   }
2427  
2428 + //!mcparticle valueLookup
2429   double
2430 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2430 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2431  
2432    double value = 0.0;
2433  
# Line 1339 | Line 2518 | OSUAnalysis::valueLookup (const BNmcpart
2518  
2519    //user-defined variables
2520    else if (variable == "d0"){
2521 <    double vx = object->vx - primaryVertex_->x,
2522 <      vy = object->vy - primaryVertex_->y,
2521 >    double vx = object->vx - chosenVertex ()->x,
2522 >      vy = object->vy - chosenVertex ()->y,
2523        px = object->px,
2524        py = object->py,
2525        pt = object->pt;
2526      value = (-vx * py + vy * px) / pt;
2527    }
2528    else if (variable == "dz"){
2529 <    double vx = object->vx - primaryVertex_->x,
2530 <      vy = object->vy - primaryVertex_->y,
2531 <      vz = object->vz - primaryVertex_->z,
2529 >    double vx = object->vx - chosenVertex ()->x,
2530 >      vy = object->vy - chosenVertex ()->y,
2531 >      vz = object->vz - chosenVertex ()->z,
2532        px = object->px,
2533        py = object->py,
2534        pz = object->pz,
2535        pt = object->pt;
2536      value = vz - (vx * px + vy * py)/pt * (pz/pt);
2537    }
2538 +  else if(variable == "v0"){
2539 +    value = sqrt(object->vx*object->vx + object->vy*object->vy);
2540 +  }
2541 +  else if(variable == "deltaV0"){
2542 +    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
2543 +  }
2544 +  else if (variable == "deltaVx"){
2545 +    value = object->vx - chosenVertex ()->x;
2546 +  }
2547 +  else if (variable == "deltaVy"){
2548 +    value = object->vy - chosenVertex ()->y;
2549 +  }
2550 +  else if (variable == "deltaVz"){
2551 +    value = object->vz - chosenVertex ()->z;
2552 +  }
2553  
2554  
2555 <
1362 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2555 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2556  
2557    value = applyFunction(function, value);
2558  
2559    return value;
2560   }
2561  
2562 + //!primaryvertex valueLookup
2563   double
2564 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2564 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2565  
2566    double value = 0.0;
2567  
# Line 1386 | Line 2580 | OSUAnalysis::valueLookup (const BNprimar
2580    else if(variable == "isGood") value = object->isGood;
2581  
2582  
2583 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2583 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2584  
2585    value = applyFunction(function, value);
2586  
2587    return value;
2588   }
2589  
2590 + //!bxlumi valueLookup
2591   double
2592 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2592 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2593  
2594    double value = 0.0;
2595  
# Line 1403 | Line 2598 | OSUAnalysis::valueLookup (const BNbxlumi
2598    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2599  
2600  
2601 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2601 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2602  
2603    value = applyFunction(function, value);
2604  
2605    return value;
2606   }
2607  
2608 + //!photon valueLookup
2609   double
2610 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2610 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2611  
2612    double value = 0.0;
2613  
# Line 1486 | Line 2682 | OSUAnalysis::valueLookup (const BNphoton
2682    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2683  
2684  
2685 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2685 >
2686 >
2687 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2688 >
2689 >  else if(variable == "genMatchedPdgId"){
2690 >    int index = getGenMatchedParticleIndex(object);
2691 >    if(index == -1) value = 0;
2692 >    else value = mcparticles->at(index).id;
2693 >  }
2694 >
2695 >
2696 >
2697 >  else if(variable == "genMatchedId"){
2698 >    int index = getGenMatchedParticleIndex(object);
2699 >    if(index == -1) value = 0;
2700 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2701 >  }
2702 >  else if(variable == "genMatchedMotherId"){
2703 >    int index = getGenMatchedParticleIndex(object);
2704 >    if(index == -1) value = 0;
2705 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2706 >  }
2707 >  else if(variable == "genMatchedMotherIdReverse"){
2708 >    int index = getGenMatchedParticleIndex(object);
2709 >    if(index == -1) value = 24;
2710 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2711 >  }
2712 >  else if(variable == "genMatchedGrandmotherId"){
2713 >    int index = getGenMatchedParticleIndex(object);
2714 >    if(index == -1) value = 0;
2715 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2716 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2717 >      if(motherIndex == -1) value = 0;
2718 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2719 >    }
2720 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2721 >  }
2722 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2723 >    int index = getGenMatchedParticleIndex(object);
2724 >    if(index == -1) value = 24;
2725 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2726 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2727 >      if(motherIndex == -1) value = 24;
2728 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2729 >    }
2730 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2731 >  }
2732 >
2733 >
2734 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2735  
2736    value = applyFunction(function, value);
2737  
2738    return value;
2739   }
2740  
2741 + //!supercluster valueLookup
2742   double
2743 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
2743 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
2744  
2745    double value = 0.0;
2746  
# Line 1508 | Line 2754 | OSUAnalysis::valueLookup (const BNsuperc
2754    else if(variable == "theta") value = object->theta;
2755  
2756  
2757 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2758 +
2759 +  value = applyFunction(function, value);
2760 +
2761 +  return value;
2762 + }
2763 +
2764 + //!trigobj valueLookup
2765 + double
2766 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
2767 +
2768 +  double value = 0.0;
2769 +
2770 +  if(variable == "pt") value = object->pt;
2771 +  else if(variable == "eta") value = object->eta;
2772 +  else if(variable == "phi") value = object->phi;
2773 +  else if(variable == "px") value = object->px;
2774 +  else if(variable == "py") value = object->py;
2775 +  else if(variable == "pz") value = object->pz;
2776 +  else if(variable == "et") value = object->et;
2777 +  else if(variable == "energy") value = object->energy;
2778 +  else if(variable == "etTotal") value = object->etTotal;
2779 +  else if(variable == "id") value = object->id;
2780 +  else if(variable == "charge") value = object->charge;
2781 +  else if(variable == "isIsolated") value = object->isIsolated;
2782 +  else if(variable == "isMip") value = object->isMip;
2783 +  else if(variable == "isForward") value = object->isForward;
2784 +  else if(variable == "isRPC") value = object->isRPC;
2785 +  else if(variable == "bx") value = object->bx;
2786 +  else if(variable == "filter") {
2787 +    if ((stringValue = object->filter) == "")
2788 +      stringValue = "none";  // stringValue should only be empty if value is filled
2789 +  }
2790 +
2791 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2792 +
2793 +  value = applyFunction(function, value);
2794 +
2795 +  return value;
2796 + }
2797 +
2798 + //!muon-muon pair valueLookup
2799 + double
2800 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
2801 +
2802 +  double value = 0.0;
2803 +
2804 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2805 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2806 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2807 +  else if(variable == "invMass"){
2808 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2809 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2810 +    value = (fourVector1 + fourVector2).M();
2811 +  }
2812 +  else if(variable == "pt"){
2813 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2814 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2815 +    value = (fourVector1 + fourVector2).Pt();
2816 +  }
2817 +  else if(variable == "threeDAngle")
2818 +    {
2819 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2820 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2821 +      value = (threeVector1.Angle(threeVector2));
2822 +    }
2823 +  else if(variable == "alpha")
2824 +    {
2825 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
2826 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2827 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2828 +      value = (pi-threeVector1.Angle(threeVector2));
2829 +    }
2830 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2831 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2832 +  else if(variable == "d0Sign"){
2833 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2834 +    if(d0Sign < 0) value = -0.5;
2835 +    else if (d0Sign > 0) value = 0.5;
2836 +    else value = -999;
2837 +  }
2838 +  else if(variable == "chargeProduct"){
2839 +    value = object1->charge*object2->charge;
2840 +  }
2841 +  else if(variable == "muon1CorrectedD0Vertex"){
2842 +    value = object1->correctedD0Vertex;
2843 +  }
2844 +  else if(variable == "muon2CorrectedD0Vertex"){
2845 +    value = object2->correctedD0Vertex;
2846 +  }
2847 +  else if(variable == "muon1timeAtIpInOut"){
2848 +    value = object1->timeAtIpInOut;
2849 +  }
2850 +  else if(variable == "muon2timeAtIpInOut"){
2851 +    value = object2->timeAtIpInOut;
2852 +  }
2853 +  else if(variable == "muon1correctedD0")
2854 +    {
2855 +      value = object1->correctedD0;
2856 +    }
2857 +  else if(variable == "muon2correctedD0")
2858 +    {
2859 +      value = object2->correctedD0;
2860 +    }
2861 +
2862 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2863 +
2864 +  value = applyFunction(function, value);
2865 +
2866 +  return value;
2867 + }
2868 +
2869 + //!electron-electron pair valueLookup
2870 + double
2871 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
2872 +
2873 +  double value = 0.0;
2874 +
2875 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2876 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2877 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2878 +  else if(variable == "invMass"){
2879 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2880 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2881 +    value = (fourVector1 + fourVector2).M();
2882 +  }
2883 +  else if(variable == "pt"){
2884 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2885 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2886 +    value = (fourVector1 + fourVector2).Pt();
2887 +  }
2888 +  else if(variable == "threeDAngle")
2889 +    {
2890 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2891 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2892 +      value = (threeVector1.Angle(threeVector2));
2893 +    }
2894 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2895 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2896 +  else if(variable == "d0Sign"){
2897 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2898 +    if(d0Sign < 0) value = -0.5;
2899 +    else if (d0Sign > 0) value = 0.5;
2900 +    else value = -999;
2901 +  }
2902 +  else if(variable == "chargeProduct"){
2903 +    value = object1->charge*object2->charge;
2904 +  }
2905 +  else if(variable == "electron1CorrectedD0Vertex"){
2906 +    value = object1->correctedD0Vertex;
2907 +  }
2908 +  else if(variable == "electron2CorrectedD0Vertex"){
2909 +    value = object2->correctedD0Vertex;
2910 +  }
2911 +  else if(variable == "electron1CorrectedD0"){
2912 +    value = object1->correctedD0;
2913 +  }
2914 +  else if(variable == "electron2CorrectedD0"){
2915 +    value = object2->correctedD0;
2916 +  }
2917 +
2918 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2919 +
2920 +  value = applyFunction(function, value);
2921 +
2922 +  return value;
2923 + }
2924 + //!electron-muon pair valueLookup
2925 + double
2926 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
2927 +
2928 +  double value = 0.0;
2929 +
2930 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2931 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2932 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2933 +  else if(variable == "invMass"){
2934 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2935 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2936 +    value = (fourVector1 + fourVector2).M();
2937 +  }
2938 +  else if(variable == "pt"){
2939 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2940 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2941 +    value = (fourVector1 + fourVector2).Pt();
2942 +  }
2943 +  else if(variable == "threeDAngle")
2944 +    {
2945 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2946 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2947 +      value = (threeVector1.Angle(threeVector2));
2948 +    }
2949 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2950 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2951 +  else if(variable == "d0Sign"){
2952 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2953 +    if(d0Sign < 0) value = -0.5;
2954 +    else if (d0Sign > 0) value = 0.5;
2955 +    else value = -999;
2956 +  }
2957 +  else if(variable == "chargeProduct"){
2958 +    value = object1->charge*object2->charge;
2959 +  }
2960 +  else if(variable == "electronCorrectedD0Vertex"){
2961 +    value = object1->correctedD0Vertex;
2962 +  }
2963 +  else if(variable == "muonCorrectedD0Vertex"){
2964 +    value = object2->correctedD0Vertex;
2965 +  }
2966 +  else if(variable == "electronCorrectedD0"){
2967 +    value = object1->correctedD0;
2968 +  }
2969 +  else if(variable == "muonCorrectedD0"){
2970 +    value = object2->correctedD0;
2971 +  }
2972 +  else if(variable == "electronDetIso"){
2973 +    value = (object1->trackIso) / object1->pt;
2974 +  }
2975 +  else if(variable == "muonDetIso"){
2976 +    value = (object2->trackIsoDR03) / object2->pt;
2977 +  }
2978 +  else if(variable == "electronRelPFrhoIso"){
2979 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
2980 +  }
2981 +  else if(variable == "muonRelPFdBetaIso"){
2982 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
2983 +  }
2984 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2985 +  value = applyFunction(function, value);
2986 +
2987 +  return value;
2988 + }
2989 +
2990 + //!electron-jet pair valueLookup
2991 + double
2992 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
2993 +
2994 +  double value = 0.0;
2995 +
2996 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2997 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2998 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2999 +  else if(variable == "invMass"){
3000 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3001 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3002 +    value = (fourVector1 + fourVector2).M();
3003 +  }
3004 +  else if(variable == "pt"){
3005 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3006 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3007 +    value = (fourVector1 + fourVector2).Pt();
3008 +  }
3009 +  else if(variable == "threeDAngle")
3010 +    {
3011 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3012 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3013 +      value = (threeVector1.Angle(threeVector2));
3014 +    }
3015 +  else if(variable == "chargeProduct"){
3016 +    value = object1->charge*object2->charge;
3017 +  }
3018 +
3019 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3020 +  value = applyFunction(function, value);
3021 +
3022 +  return value;
3023 + }
3024 +
3025 + //!muon-jet pair valueLookup
3026 + double
3027 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3028 +
3029 +  double value = 0.0;
3030 +
3031 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3032 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3033 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3034 +  else if(variable == "invMass"){
3035 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3036 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3037 +    value = (fourVector1 + fourVector2).M();
3038 +  }
3039 +  else if(variable == "pt"){
3040 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3041 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3042 +    value = (fourVector1 + fourVector2).Pt();
3043 +  }
3044 +  else if(variable == "threeDAngle")
3045 +    {
3046 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3047 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3048 +      value = (threeVector1.Angle(threeVector2));
3049 +    }
3050 +  else if(variable == "chargeProduct"){
3051 +    value = object1->charge*object2->charge;
3052 +  }
3053 +
3054 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3055 +  value = applyFunction(function, value);
3056 +
3057 +  return value;
3058 + }
3059 +
3060 + //!jet-jet pair valueLookup
3061 + double
3062 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3063 +
3064 +  double value = 0.0;
3065 +
3066 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3067 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3068 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3069 +  else if(variable == "invMass"){
3070 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3071 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3072 +    value = (fourVector1 + fourVector2).M();
3073 +  }
3074 +  else if(variable == "pt"){
3075 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3076 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3077 +    value = (fourVector1 + fourVector2).Pt();
3078 +  }
3079 +  else if(variable == "threeDAngle")
3080 +    {
3081 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3082 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3083 +      value = (threeVector1.Angle(threeVector2));
3084 +    }
3085 +  else if(variable == "chargeProduct"){
3086 +    value = object1->charge*object2->charge;
3087 +  }
3088 +
3089 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3090 +  value = applyFunction(function, value);
3091 +
3092 +  return value;
3093 + }
3094 + //!electron-track pair valueLookup
3095 + double
3096 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3097 +  double electronMass = 0.000511;
3098 +  double value = 0.0;
3099 +  TLorentzVector fourVector1(0, 0, 0, 0);
3100 +  TLorentzVector fourVector2(0, 0, 0, 0);
3101 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3102 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3103 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3104 +  else if(variable == "invMass"){
3105 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3106 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3107 +
3108 +    value = (fourVector1 + fourVector2).M();
3109 +  }
3110 +  else if(variable == "chargeProduct"){
3111 +    value = object1->charge*object2->charge;
3112 +  }
3113    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3114 +  value = applyFunction(function, value);
3115 +  return value;
3116 +
3117 + }
3118 +
3119 +
3120 + //!muon-track pair valueLookup
3121 + double
3122 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3123 +  double pionMass = 0.140;
3124 +  double muonMass = 0.106;
3125 +  double value = 0.0;
3126 +  TLorentzVector fourVector1(0, 0, 0, 0);
3127 +  TLorentzVector fourVector2(0, 0, 0, 0);
3128 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3129 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3130 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3131 +  else if(variable == "invMass"){
3132 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3133 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3134 +
3135 +    value = (fourVector1 + fourVector2).M();
3136 +  }
3137 +  else if(variable == "chargeProduct"){
3138 +    value = object1->charge*object2->charge;
3139 +  }
3140 +
3141 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3142 +  value = applyFunction(function, value);
3143 +  return value;
3144 + }
3145 +
3146 + //!tau-tau pair valueLookup
3147 + double
3148 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3149 +  double value = 0.0;
3150 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3151 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3152 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3153 +  else if(variable == "invMass"){
3154 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3155 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3156 +    value = (fourVector1 + fourVector2).M();
3157 +  }
3158 +
3159 +  else if(variable == "chargeProduct"){
3160 +    value = object1->charge*object2->charge;
3161 +  }
3162 +
3163 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3164 +  value = applyFunction(function, value);
3165 +  return value;
3166 + }
3167 +
3168 + //!muon-tau pair valueLookup
3169 + double
3170 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3171 +  double value = 0.0;
3172 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3173 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3174 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3175 +  else if(variable == "invMass"){
3176 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3177 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3178 +    value = (fourVector1 + fourVector2).M();
3179 +  }
3180 +
3181 +  else if(variable == "chargeProduct"){
3182 +    value = object1->charge*object2->charge;
3183 +  }
3184 +
3185 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3186 +  value = applyFunction(function, value);
3187 +  return value;
3188 + }
3189 +
3190 + //!tau-track pair valueLookup
3191 + double
3192 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3193 +  double value = 0.0;
3194 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3195 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3196 +  else if(variable == "chargeProduct"){
3197 +    value = object1->charge*object2->charge;
3198 +  }
3199 +
3200 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3201 +  value = applyFunction(function, value);
3202 +  return value;
3203 + }
3204 +
3205 +
3206 + //!track-event pair valueLookup
3207 + double
3208 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3209 +
3210 +  double value = 0.0;
3211 +  double pMag = sqrt(object1->pt * object1->pt +
3212 +                     object1->pz * object1->pz);
3213 +
3214 +  if      (variable == "numPV")                      value = object2->numPV;
3215 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3216 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3217 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3218 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3219 +
3220 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3221 +
3222 +  value = applyFunction(function, value);
3223 +
3224 +  return value;
3225 +
3226 + }
3227 +
3228 + //!electron-trigobj pair valueLookup
3229 + double
3230 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3231 +
3232 +  double value = 0.0;
3233 +
3234 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3235 +  else if (variable == "match"){
3236 +    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3237 +      stringValue = object2->filter;
3238 +    else
3239 +      stringValue = "none";
3240 +  }
3241 +
3242 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3243 +
3244 +  value = applyFunction(function, value);
3245 +
3246 +  return value;
3247 +
3248 + }
3249 +
3250 + //!muon-trigobj pair valueLookup
3251 + double
3252 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3253 +
3254 +  double value = 0.0;
3255 +
3256 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3257 +
3258 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3259 +
3260 +  value = applyFunction(function, value);
3261 +
3262 +  return value;
3263 +
3264 + }
3265 +
3266 + //!stop valueLookup
3267 + double
3268 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3269 +
3270 +
3271 +  double value = 0.0;
3272 +
3273 +  if(variable == "ctau") value = object->ctau;
3274 +
3275 +  else if (variable == "d0"){
3276 +    double vx = object->vx - chosenVertex ()->x,
3277 +      vy = object->vy - chosenVertex ()->y,
3278 +      px = object->px,
3279 +      py = object->py,
3280 +      pt = object->pt;
3281 +    value = (-vx * py + vy * px) / pt;
3282 +  }
3283 +
3284 +  else if (variable == "dz"){
3285 +    double vx = object->vx - chosenVertex ()->x,
3286 +      vy = object->vy - chosenVertex ()->y,
3287 +      vz = object->vz - chosenVertex ()->z,
3288 +      px = object->px,
3289 +      py = object->py,
3290 +      pz = object->pz,
3291 +      pt = object->pt;
3292 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3293 +  }
3294 +
3295 +  else if (variable == "minD0"){
3296 +    double minD0=999;
3297 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3298 +      double vx = object->vx - vertex->x,
3299 +        vy = object->vy - vertex->y,
3300 +        px = object->px,
3301 +        py = object->py,
3302 +        pt = object->pt;
3303 +      value = (-vx * py + vy * px) / pt;
3304 +      if(abs(value) < abs(minD0)) minD0 = value;
3305 +    }
3306 +    value = minD0;
3307 +  }
3308 +  else if (variable == "minDz"){
3309 +    double minDz=999;
3310 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3311 +      double vx = object->vx - vertex->x,
3312 +        vy = object->vy - vertex->y,
3313 +        vz = object->vz - vertex->z,
3314 +        px = object->px,
3315 +        py = object->py,
3316 +        pz = object->pz,
3317 +        pt = object->pt;
3318 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3319 +      if(abs(value) < abs(minDz)) minDz = value;
3320 +    }
3321 +    value = minDz;
3322 +  }
3323 +  else if(variable == "distToVertex"){
3324 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3325 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3326 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3327 +  }
3328 +  else if (variable == "minDistToVertex"){
3329 +    double minDistToVertex=999;
3330 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3331 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3332 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3333 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3334 +
3335 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3336 +    }
3337 +    value = minDistToVertex;
3338 +  }
3339 +  else if (variable == "distToVertexDifference"){
3340 +    double minDistToVertex=999;
3341 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3342 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3343 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3344 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3345 +
3346 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3347 +    }
3348 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3349 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3350 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3351 +
3352 +    value = distToChosenVertex - minDistToVertex;
3353 +  }
3354 +
3355 +  else if (variable == "closestVertexRank"){
3356 +    double minDistToVertex=999;
3357 +    int vertex_rank = 0;
3358 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3359 +      vertex_rank++;
3360 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3361 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3362 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3363 +
3364 +      if(abs(dist) < abs(minDistToVertex)){
3365 +        value = vertex_rank;
3366 +        minDistToVertex = dist;
3367 +      }
3368 +    }
3369 +  }
3370 +
3371 +
3372 +
3373 +
3374 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3375  
3376    value = applyFunction(function, value);
3377  
3378    return value;
3379 +
3380 + }
3381 +
3382 +
3383 +
3384 +
3385 + // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3386 + // Return true iff no other tracks are found in this cone.
3387 + int
3388 + OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
3389 +  for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
3390 +    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
3391 +    double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
3392 +    if(deltaRtrk < 0.5) return 0;
3393 +  }
3394 +  return 1;
3395 +
3396 + }
3397 +
3398 +
3399 + double
3400 + OSUAnalysis::getTrkPtRes (const BNtrack* track1){
3401 +
3402 +  double ptTrue = getTrkPtTrue(track1, mcparticles.product());
3403 +  double PtRes = (track1->pt - ptTrue) / ptTrue;
3404 +
3405 +  return PtRes;
3406 +
3407 + }
3408 +
3409 +
3410 + double
3411 + OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
3412 +  double value = -99;
3413 +  double genDeltaRLowest = 999;
3414 +
3415 +  for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
3416 +    double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
3417 +    if (genDeltaRtemp < genDeltaRLowest) {
3418 +      genDeltaRLowest = genDeltaRtemp;
3419 +      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
3420 +        double ptTrue = genPart->pt;
3421 +        value = ptTrue;
3422 +      }
3423 +    }
3424 +  }
3425 +
3426 +  return value;
3427 +
3428 + }
3429 +
3430 + double
3431 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3432 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3433 +  if (!useTrackCaloRhoCorr_) return -99;
3434 +  // if (!rhokt6CaloJetsHandle_) {
3435 +  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3436 +  //   return -99;
3437 +  // }
3438 +  double radDeltaRCone = 0.5;
3439 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3440 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3441 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3442 +  return caloTotRhoCorrCalo;
3443 +
3444 + }
3445 +
3446 +
3447 +
3448 +
3449 + //creates a map of the dead Ecal channels in the barrel and endcap
3450 + //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
3451 + //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
3452 + void
3453 + OSUAnalysis::WriteDeadEcal (){
3454 +  double etaEcal, phiEcal;
3455 +  ifstream DeadEcalFile(deadEcalFile_);
3456 +  if(!DeadEcalFile) {
3457 +    cout << "Error: DeadEcalFile has not been found." << endl;
3458 +    return;
3459 +  }
3460 +  if(DeadEcalVec.size()!= 0){
3461 +    cout << "Error: DeadEcalVec has a nonzero size" << endl;
3462 +    return;
3463 +  }
3464 +  while(!DeadEcalFile.eof())
3465 +    {
3466 +      DeadEcalFile >> etaEcal >> phiEcal;
3467 +      DeadEcal newChan;
3468 +      newChan.etaEcal = etaEcal;
3469 +      newChan.phiEcal = phiEcal;
3470 +      DeadEcalVec.push_back(newChan);
3471 +    }
3472 +  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
3473 + }
3474 +
3475 + //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
3476 + int
3477 + OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
3478 +  double deltaRLowest = 999;
3479 +  int value = 0;
3480 +  if (DeadEcalVec.size() == 0) WriteDeadEcal();
3481 +  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3482 +    double eta = ecal->etaEcal;
3483 +    double phi = ecal->phiEcal;
3484 +    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
3485 +    if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3486 +  }
3487 +  if (deltaRLowest<0.05) {value = 1;}
3488 +  else {value = 0;}
3489 +  return value;
3490   }
3491  
3492 + // Returns the smallest DeltaR between the object and any generated true particle in the event.
3493 + template <class InputObject>
3494 + double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3495 +  double genDeltaRLowest = 999.;
3496 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3497 +    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
3498 +    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
3499 +  }
3500 +  return genDeltaRLowest;
3501 + }
3502  
3503   double
3504   OSUAnalysis::applyFunction(string function, double value){
3505  
3506    if(function == "abs") value = fabs(value);
3507 +  else if(function == "fabs") value = fabs(value);
3508 +  else if(function == "log10") value = log10(value);
3509 +  else if(function == "log") value = log10(value);
3510  
3511 +  else if(function == "") value = value;
3512 +  else{cout << "WARNING: invalid function '" << function << "'\n";}
3513  
3514    return value;
3515  
# Line 1530 | Line 3519 | OSUAnalysis::applyFunction(string functi
3519   template <class InputCollection>
3520   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
3521  
3522 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
3523 +    string obj1, obj2;
3524 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
3525 +    if (inputType==obj1 ||
3526 +          inputType==obj2) {
3527 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
3528 +      // and the inputType is a member of the pair.
3529 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
3530 +      // For example, if currentCut.inputCollection==electron-muon pairs,
3531 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
3532 +      return;
3533 +    }
3534 +  }
3535  
3536    for (uint object = 0; object != inputCollection->size(); object++){
3537  
# Line 1537 | Line 3539 | void OSUAnalysis::setObjectFlags(cut &cu
3539  
3540      if(currentCut.inputCollection == inputType){
3541  
3542 <      double value = valueLookup(&inputCollection->at(object), currentCut.variable, currentCut.function);
3542 >      vector<bool> subcutDecisions;
3543 >      for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3544 >        string stringValue = "";
3545 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3546 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3547 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3548  
3549 <      decision = evaluateComparison(value,currentCut.comparativeOperator,currentCut.cutValue);
3549 >      }
3550 >      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3551 >      else{
3552 >        bool tempDecision = true;
3553 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
3554 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
3555 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
3556 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
3557 >            tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
3558 >        }
3559 >        decision = tempDecision;
3560 >      }
3561      }
1544    individualFlags[inputType].at(currentCutIndex).push_back(decision);
3562  
3563 +    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3564  
3565      //set flags for objects that pass each cut AND all the previous cuts
3566      bool previousCumulativeFlag = true;
3567      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3568 <      if(previousCumulativeFlag && individualFlags[inputType].at(previousCutIndex).at(object)) previousCumulativeFlag = true;
3568 >      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
3569        else{ previousCumulativeFlag = false; break;}
3570      }
3571 <    cumulativeFlags[inputType].at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3571 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3572  
3573    }
3574  
3575   }
3576  
3577  
3578 + template <class InputCollection1, class InputCollection2>
3579 + void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
3580 +                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
3581 +
3582 +
3583 +  bool sameObjects = false;
3584 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3585 +
3586 +  // Get the strings for the two objects that make up the pair.
3587 +  string obj1Type, obj2Type;
3588 +  getTwoObjs(inputType, obj1Type, obj2Type);
3589 +  bool isTwoTypesOfObject = true;
3590 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
3591 +
3592 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
3593 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
3594 +  if (currentCut.inputCollection == inputType) {
3595 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
3596 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3597 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3598 +    }
3599 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
3600 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
3601 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3602 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3603 +      }
3604 +    }
3605 +  }
3606 +
3607 +  int counter = 0;
3608 +
3609 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3610 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3611 +
3612 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3613 +
3614 +
3615 +      bool decision = true;//object passes if this cut doesn't cut on that type of object
3616 +
3617 +      if(currentCut.inputCollection == inputType){
3618 +
3619 +        vector<bool> subcutDecisions;
3620 +        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3621 +          string stringValue = "";
3622 +          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3623 +          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3624 +          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3625 +        }
3626 +
3627 +        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3628 +        else{
3629 +          bool tempDecision = subcutDecisions.at(0);
3630 +          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
3631 +            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
3632 +              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
3633 +            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
3634 +              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
3635 +          }
3636 +          decision = tempDecision;
3637 +        }
3638 +      }
3639 +      // if (decision) isPassObj1.at(object1) = true;
3640 +      // if (decision) isPassObj2.at(object2) = true;
3641 +      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3642 +      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3643 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;
3644 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;
3645 +      }
3646 +
3647 +      //set flags for objects that pass each cut AND all the previous cuts
3648 +      bool previousCumulativeFlag = true;
3649 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3650 +        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
3651 +        else{ previousCumulativeFlag = false; break;}
3652 +      }
3653 +      //apply flags for the components of the composite object as well
3654 +      bool currentCumulativeFlag = true;
3655 +      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
3656 +      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
3657 +      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
3658 +      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
3659 +      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
3660 +      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3661 +        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);
3662 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);
3663 +      }
3664 +      counter++;
3665 +
3666 +    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
3667 +  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
3668 +
3669 + }
3670 +
3671 +
3672 + bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
3673 +  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
3674 +  // all cuts up to currentCutIndex
3675 +  bool previousCumulativeFlag = true;
3676 +  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
3677 +    if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
3678 +    else {
3679 +      previousCumulativeFlag = false; break;
3680 +    }
3681 +  }
3682 +  return previousCumulativeFlag;
3683 + }
3684 +
3685 +
3686   template <class InputCollection>
3687 < void OSUAnalysis::fillHistogram(TH1* histo, histogram parameters, InputCollection inputCollection){
3687 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3688  
3689 +  for (uint object = 0; object != inputCollection->size(); object++){
3690 +
3691 +    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3692 +
3693 +    string currentString = parameters.inputVariables.at(0);
3694 +    string inputVariable = "";
3695 +    string function = "";
3696 +    if(currentString.find("(")==string::npos){
3697 +      inputVariable = currentString;// variable to cut on
3698 +    }
3699 +    else{
3700 +      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3701 +      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3702 +      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3703 +    }
3704 +
3705 +    string stringValue = "";
3706 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3707 +    histo->Fill(value,scaleFactor);
3708 +
3709 +    if (printEventInfo_) {
3710 +      // Write information about event to screen, for testing purposes.
3711 +      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
3712 +    }
3713 +
3714 +  }
3715 + }
3716 +
3717 + template <class InputCollection1, class InputCollection2>
3718 + void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3719 +
3720 +  bool sameObjects = false;
3721 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3722 +
3723 +  int pairCounter = -1;
3724 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3725 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3726 +
3727 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3728 +
3729 +      pairCounter++;
3730 +      //only take objects which have passed all cuts and pairs which have passed all cuts
3731 +      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3732 +      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3733 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3734 +
3735 +      string currentString = parameters.inputVariables.at(0);
3736 +      string inputVariable = "";
3737 +      string function = "";
3738 +      if(currentString.find("(")==string::npos){
3739 +        inputVariable = currentString;// variable to cut on
3740 +      }
3741 +      else{
3742 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3743 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3744 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3745 +      }
3746 +
3747 +      string stringValue = "";
3748 +      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3749 +      histo->Fill(value,scaleFactor);
3750 +
3751 +    }
3752 +  }
3753 +
3754 + }
3755 +
3756 +
3757 + template <class InputCollection>
3758 + void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3759  
3760    for (uint object = 0; object != inputCollection->size(); object++){
3761 <    if(parameters.inputVariables.size() == 1){
3762 <      double value = valueLookup(&inputCollection->at(object), parameters.inputVariables.at(0), parameters.function);
3763 <      histo->Fill(value);
3764 <    }
3765 <    else if(parameters.inputVariables.size() == 2){
3766 <      double valueX = valueLookup(&inputCollection->at(object), parameters.inputVariables.at(0), parameters.function);
3767 <      double valueY = valueLookup(&inputCollection->at(object), parameters.inputVariables.at(1), parameters.function);
3768 <      histo->Fill(valueX,valueY);
3761 >
3762 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3763 >
3764 >    string stringValue = "";
3765 >    string currentString = parameters.inputVariables.at(0);
3766 >    string inputVariable = "";
3767 >    string function = "";
3768 >    if(currentString.find("(")==string::npos){
3769 >      inputVariable = currentString;// variable to cut on
3770 >    }
3771 >    else{
3772 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3773 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3774 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3775 >    }
3776 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3777 >
3778 >    currentString = parameters.inputVariables.at(1);
3779 >    inputVariable = "";
3780 >    function = "";
3781 >    if(currentString.find("(")==string::npos){
3782 >      inputVariable = currentString;// variable to cut on
3783      }
3784 +    else{
3785 +      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3786 +      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3787 +      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3788 +    }
3789 +
3790 +    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3791 +
3792 +    histo->Fill(valueX,valueY,scaleFactor);
3793 +
3794    }
3795  
3796   }
3797  
3798 + template <class InputCollection1, class InputCollection2>
3799 + void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3800  
3801 +  bool sameObjects = false;
3802 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3803  
3804 +  int pairCounter = -1;
3805 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3806 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3807 +
3808 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3809 +
3810 +      pairCounter++;
3811 +
3812 +      //only take objects which have passed all cuts and pairs which have passed all cuts
3813 +      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3814 +      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3815 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3816 +
3817 +      string stringValue = "";
3818 +      string currentString = parameters.inputVariables.at(0);
3819 +      string inputVariable = "";
3820 +      string function = "";
3821 +      if(currentString.find("(")==string::npos){
3822 +        inputVariable = currentString;// variable to cut on
3823 +      }
3824 +      else{
3825 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3826 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3827 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3828 +      }
3829 +      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3830  
3831 < DEFINE_FWK_MODULE(OSUAnalysis);
3831 >      currentString = parameters.inputVariables.at(1);
3832 >      inputVariable = "";
3833 >      function = "";
3834 >      if(currentString.find("(")==string::npos){
3835 >        inputVariable = currentString;// variable to cut on
3836 >      }
3837 >      else{
3838 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3839 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3840 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3841 >      }
3842 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3843  
3844  
3845 +      histo->Fill(valueX,valueY,scaleFactor);
3846 +
3847 +    }
3848 +  }
3849 +
3850 + }
3851 +
3852 +
3853 + template <class InputObject>
3854 + int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
3855 +
3856 +  int bestMatchIndex = -1;
3857 +  double bestMatchDeltaR = 999;
3858 +
3859 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3860 +
3861 +    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
3862 +    if(currentDeltaR > 0.05) continue;
3863 +    //     cout << setprecision(3) << setw(20)
3864 +    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
3865 +    //          << setw(20)
3866 +    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
3867 +    //          << setw(20)
3868 +    //          << "\tdeltaR = " << currentDeltaR
3869 +    //          << setprecision(1)
3870 +    //          << setw(20)
3871 +    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
3872 +    //          << setw(20)
3873 +    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
3874 +    //          << setw(20)
3875 +    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
3876 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
3877 +      bestMatchIndex = mcparticle - mcparticles->begin();
3878 +      bestMatchDeltaR = currentDeltaR;
3879 +    }
3880 +
3881 +  }
3882 +  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
3883 +  //   else cout << "no match found..." << endl;
3884 +  return bestMatchIndex;
3885 +
3886 + }
3887 +
3888 +
3889 + int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
3890 +
3891 +  int bestMatchIndex = -1;
3892 +  double bestMatchDeltaR = 999;
3893 +
3894 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3895 +
3896 +    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
3897 +
3898 +    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
3899 +    if(currentDeltaR > 0.05) continue;
3900 +
3901 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
3902 +      bestMatchIndex = mcparticle - mcparticles->begin();
3903 +      bestMatchDeltaR = currentDeltaR;
3904 +    }
3905 +
3906 +  }
3907 +
3908 +  return bestMatchIndex;
3909 + }
3910 +
3911 +
3912 + // bin      particle type
3913 + // ---      -------------
3914 + //  0        unmatched
3915 + //  1        u
3916 + //  2        d
3917 + //  3        s
3918 + //  4        c
3919 + //  5        b
3920 + //  6        t
3921 + //  7        e
3922 + //  8        mu
3923 + //  9        tau
3924 + // 10        nu
3925 + // 11        g
3926 + // 12        gamma
3927 + // 13        Z
3928 + // 14        W
3929 + // 15        light meson
3930 + // 16        K meson
3931 + // 17        D meson
3932 + // 18        B meson
3933 + // 19        light baryon
3934 + // 20        strange baryon
3935 + // 21        charm baryon
3936 + // 22        bottom baryon
3937 + // 23        QCD string
3938 + // 24        other
3939 +
3940 + int OSUAnalysis::getPdgIdBinValue(int pdgId){
3941 +
3942 +  int binValue = -999;
3943 +  int absPdgId = fabs(pdgId);
3944 +  if(pdgId == -1) binValue = 0;
3945 +  else if(absPdgId <= 6 ) binValue = absPdgId;
3946 +  else if(absPdgId == 11 ) binValue = 7;
3947 +  else if(absPdgId == 13 ) binValue = 8;
3948 +  else if(absPdgId == 15 ) binValue = 9;
3949 +  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
3950 +  else if(absPdgId == 21 ) binValue = 11;
3951 +  else if(absPdgId == 22 ) binValue = 12;
3952 +  else if(absPdgId == 23 ) binValue = 13;
3953 +  else if(absPdgId == 24 ) binValue = 14;
3954 +  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
3955 +  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
3956 +  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
3957 +  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
3958 +  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
3959 +  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
3960 +  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
3961 +  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
3962 +  else if(absPdgId == 92  ) binValue = 23;
3963 +
3964 +  else binValue = 24;
3965 +
3966 +  return binValue;
3967 +
3968 + }
3969 +
3970 + const BNprimaryvertex *
3971 + OSUAnalysis::chosenVertex ()
3972 + {
3973 +  const BNprimaryvertex *chosenVertex = 0;
3974 +  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
3975 +    vector<bool> vertexFlags;
3976 +    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
3977 +      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
3978 +        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
3979 +        break;
3980 +      }
3981 +    }
3982 +    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
3983 +      if(!vertexFlags.at(vertexIndex)) continue;
3984 +      chosenVertex = & primaryvertexs->at(vertexIndex);
3985 +      break;
3986 +    }
3987 +  }
3988 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
3989 +    chosenVertex = & primaryvertexs->at (0);
3990 +
3991 +  return chosenVertex;
3992 + }
3993 +
3994 + const BNmet *
3995 + OSUAnalysis::chosenMET ()
3996 + {
3997 +  const BNmet *chosenMET = 0;
3998 +  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
3999 +    vector<bool> metFlags;
4000 +    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4001 +      if (cumulativeFlags.at("mets").at(i).size()){
4002 +        metFlags = cumulativeFlags.at("mets").at(i);
4003 +        break;
4004 +      }
4005 +    }
4006 +    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4007 +      if(!metFlags.at(metIndex)) continue;
4008 +      chosenMET = & mets->at(metIndex);
4009 +      break;
4010 +    }
4011 +  }
4012 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4013 +    chosenMET = & mets->at (0);
4014 +
4015 +  return chosenMET;
4016 + }
4017 +
4018 + const BNelectron *
4019 + OSUAnalysis::chosenElectron ()
4020 + {
4021 +  const BNelectron *chosenElectron = 0;
4022 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4023 +    vector<bool> electronFlags;
4024 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4025 +      if (cumulativeFlags.at("electrons").at(i).size()){
4026 +        electronFlags = cumulativeFlags.at("electrons").at(i);
4027 +        break;
4028 +      }
4029 +    }
4030 +    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4031 +      if(!electronFlags.at(electronIndex)) continue;
4032 +      chosenElectron = & electrons->at(electronIndex);
4033 +      break;
4034 +    }
4035 +  }
4036 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4037 +    chosenElectron = & electrons->at (0);
4038 +
4039 +  return chosenElectron;
4040 + }
4041 +
4042 + const BNmuon *
4043 + OSUAnalysis::chosenMuon ()
4044 + {
4045 +  const BNmuon *chosenMuon = 0;
4046 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4047 +    vector<bool> muonFlags;
4048 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4049 +      if (cumulativeFlags.at("muons").at(i).size()){
4050 +        muonFlags = cumulativeFlags.at("muons").at(i);
4051 +        break;
4052 +      }
4053 +    }
4054 +    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4055 +      if(!muonFlags.at(muonIndex)) continue;
4056 +      chosenMuon = & muons->at(muonIndex);
4057 +      break;
4058 +    }
4059 +  }
4060 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4061 +    chosenMuon = & muons->at (0);
4062 +
4063 +  return chosenMuon;
4064 + }
4065 +
4066 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines