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.14 by lantonel, Wed Feb 13 10:05:35 2013 UTC vs.
Revision 1.42 by wulsin, Wed Mar 27 22:38:08 2013 UTC

# Line 16 | Line 16 | OSUAnalysis::OSUAnalysis (const edm::Par
16    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
17    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
18    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
19 <
20 <
19 >  puFile_ (cfg.getParameter<std::string> ("puFile")),
20 >  deadEcalFile_ (cfg.getParameter<std::string> ("deadEcalFile")),
21 >  muonSFFile_ (cfg.getParameter<std::string> ("muonSFFile")),
22 >  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
23 >  electronSFID_ (cfg.getParameter<std::string> ("electronSFID")),
24 >  muonSF_ (cfg.getParameter<std::string> ("muonSF")),
25 >  dataset_ (cfg.getParameter<std::string> ("dataset")),
26 >  datasetType_ (cfg.getParameter<std::string> ("datasetType")),
27    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
22
28    histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
29 <
30 <  plotAllObjectsInPassingEvents (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents"))
29 >  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
30 >  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
31 >  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
32 >  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr"))
33  
34   {
35  
36    TH1::SetDefaultSumw2 ();
37 <  TH2::SetDefaultSumw2 ();
37 >
38 >  //create pile-up reweighting object, if necessary
39 >  if(datasetType_ != "data") {
40 >    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
41 >    //    muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
42 >    //    electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
43 >  }
44 >
45  
46    // Construct Cutflow Objects. These store the results of cut decisions and
47    // handle filling cut flow histograms.
# Line 35 | Line 49 | OSUAnalysis::OSUAnalysis (const edm::Par
49    std::vector<TFileDirectory> directories;
50  
51    //always get vertex collection so we can assign the primary vertex in the event
52 <  allNecessaryObjects.push_back("primaryvertexs");
52 >  objectsToGet.push_back("primaryvertexs");
53 >
54    //always make the plot of number of primary verticex (to check pile-up reweighting)
55    objectsToPlot.push_back("primaryvertexs");
56  
57 +  //always get the MC particles to do GEN-matching
58 +  objectsToGet.push_back("mcparticles");
59 +
60 +  //always get the event collection to do pile-up reweighting
61 +  objectsToGet.push_back("events");
62 +
63    //parse the histogram definitions
64    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
65  
66 <    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string>("inputCollection");
67 <    objectsToPlot.push_back(tempInputCollection);
68 <    allNecessaryObjects.push_back(tempInputCollection);
66 >    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
67 >    if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
68 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
69 >    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
70 >      objectsToGet.push_back(tempInputCollection);
71 >      objectsToPlot.push_back(tempInputCollection);
72 >      objectsToCut.push_back(tempInputCollection);
73 >    }
74 >    else{//pair of objects, need to add them both to the things to objectsToGet
75 >      int dashIndex = tempInputCollection.find("-");
76 >      int spaceIndex = tempInputCollection.find(" ");
77 >      int secondWordLength = spaceIndex - dashIndex;
78 >      objectsToGet.push_back(tempInputCollection);
79 >      objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
80 >      objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
81 >      objectsToPlot.push_back(tempInputCollection);
82 >      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
83 >      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
84 >      objectsToCut.push_back(tempInputCollection);
85 >      objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
86 >      objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
87 >
88 >      }
89 >
90      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
91 <    
91 >
92      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
93  
94        histogram tempHistogram;
# Line 55 | Line 97 | OSUAnalysis::OSUAnalysis (const edm::Par
97        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
98        tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
99        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
100 <      if(histogramList_.at(currentHistogram).exists("function"))
59 <        tempHistogram.function = histogramList_.at(currentHistogram).getParameter<string>("function");
60 <      else
61 <        tempHistogram.function = "";
62 <      
100 >
101        histograms.push_back(tempHistogram);
102  
103      }
104    }
105 +  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
106 +  sort( objectsToPlot.begin(), objectsToPlot.end() );
107 +  objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
108 +
109  
110  
111 +  //add histograms with the gen-matched id, mother id, and grandmother id
112 +  for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
113 +
114 +    string currentObject = objectsToPlot.at(currentObjectIndex);
115 +    if(currentObject != "muons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
116 +
117 +    histogram tempIdHisto;
118 +    histogram tempMomIdHisto;
119 +    histogram tempGmaIdHisto;
120 +    histogram tempIdVsMomIdHisto;
121 +
122 +    tempIdHisto.inputCollection = currentObject;
123 +    tempMomIdHisto.inputCollection = currentObject;
124 +    tempGmaIdHisto.inputCollection = currentObject;
125 +    tempIdVsMomIdHisto.inputCollection = currentObject;
126 +
127 +    currentObject = currentObject.substr(0, currentObject.size()-1);
128 +    tempIdHisto.name = currentObject+"GenMatchId";
129 +    tempMomIdHisto.name = currentObject+"GenMatchMotherId";
130 +    tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
131 +    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
132 +
133 +    currentObject.at(0) = toupper(currentObject.at(0));
134 +    tempIdHisto.title = currentObject+" Gen-matched Particle";
135 +    tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
136 +    tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
137 +    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
138 +
139 +    int maxNum = 24;
140 +    vector<double> binVector;
141 +    binVector.push_back(maxNum);
142 +    binVector.push_back(0);
143 +    binVector.push_back(maxNum);
144 +
145 +    tempIdHisto.bins = binVector;
146 +    tempIdHisto.inputVariables.push_back("genMatchedId");
147 +    tempMomIdHisto.bins = binVector;
148 +    tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
149 +    tempGmaIdHisto.bins = binVector;
150 +    tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
151 +    binVector.push_back(maxNum);
152 +    binVector.push_back(0);
153 +    binVector.push_back(maxNum);
154 +    tempIdVsMomIdHisto.bins = binVector;
155 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
156 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
157 +
158 +    histograms.push_back(tempIdHisto);
159 +    histograms.push_back(tempMomIdHisto);
160 +    histograms.push_back(tempGmaIdHisto);
161 +    histograms.push_back(tempIdVsMomIdHisto);
162 +  }
163  
164  
165    channel tempChannel;
# Line 85 | Line 179 | OSUAnalysis::OSUAnalysis (const edm::Par
179        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
180        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
181          tempChannel.triggers.push_back(triggerNames.at(trigger));
182 <      allNecessaryObjects.push_back("triggers");
182 >      objectsToGet.push_back("triggers");
183      }
184  
185  
# Line 104 | Line 198 | OSUAnalysis::OSUAnalysis (const edm::Par
198      twoDHists_.push_back(twoDhistoMap);
199  
200  
201 +
202      //book all histograms included in the configuration
203      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
204        histogram currentHistogram = histograms.at(currentHistogramIndex);
205        int numBinsElements = currentHistogram.bins.size();
206        int numInputVariables = currentHistogram.inputVariables.size();
207  
113
114
208        if(numBinsElements != 3 && numBinsElements !=6) {
209 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
210 <        exit(0);
209 >        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
210 >        exit(0);
211        }
212        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
213 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
214 <        exit(0);
213 >        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
214 >        exit(0);
215        }
216        else if(numBinsElements == 3){
217 <        oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
217 >        oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
218        }
219        else if(numBinsElements == 6){
220 <        twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2),currentHistogram.bins.at(3),currentHistogram.bins.at(4),currentHistogram.bins.at(5));
220 >        twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2),currentHistogram.bins.at(3),currentHistogram.bins.at(4),currentHistogram.bins.at(5));
221  
222        }
223  
224  
225 +      if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
226 +
227 + // bin      particle type
228 + // ---      -------------
229 + //  0        unmatched
230 + //  1        u
231 + //  2        d
232 + //  3        s
233 + //  4        c
234 + //  5        b
235 + //  6        t
236 + //  7        e
237 + //  8        mu
238 + //  9        tau
239 + // 10        nu
240 + // 11        g
241 + // 12        gamma
242 + // 13        Z
243 + // 14        W
244 + // 15        light meson
245 + // 16        K meson
246 + // 17        D meson
247 + // 18        B meson
248 + // 19        light baryon
249 + // 20        strange baryon
250 + // 21        charm baryon
251 + // 22        bottom baryon
252 + // 23        other
253 +
254 +      vector<TString> labelArray;
255 +      labelArray.push_back("unmatched");
256 +      labelArray.push_back("u");
257 +      labelArray.push_back("d");
258 +      labelArray.push_back("s");
259 +      labelArray.push_back("c");
260 +      labelArray.push_back("b");
261 +      labelArray.push_back("t");
262 +      labelArray.push_back("e");
263 +      labelArray.push_back("#mu");
264 +      labelArray.push_back("#tau");
265 +      labelArray.push_back("#nu");
266 +      labelArray.push_back("g");
267 +      labelArray.push_back("#gamma");
268 +      labelArray.push_back("Z");
269 +      labelArray.push_back("W");
270 +      labelArray.push_back("light meson");
271 +      labelArray.push_back("K meson");
272 +      labelArray.push_back("D meson");
273 +      labelArray.push_back("B meson");
274 +      labelArray.push_back("light baryon");
275 +      labelArray.push_back("strange baryon");
276 +      labelArray.push_back("charm baryon");
277 +      labelArray.push_back("bottom baryon");
278 +      labelArray.push_back("other");
279 +
280 +      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
281 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")==std::string::npos) {
282 +          oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
283 +        }
284 +        else {
285 +          twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
286 +          twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
287 +        }
288 +      }
289 +      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=std::string::npos) {
290 +        twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->CenterTitle();
291 +        twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->CenterTitle();
292 +      }
293 +
294      }
295 <    //book a histogram for the number of each object type to be plotted
295 >
296 >    // Book a histogram for the number of each object type to be plotted.  
297 >    // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().  
298      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
299        string currentObject = objectsToPlot.at(currentObjectIndex);
300        int maxNum = 10;
301        if(currentObject == "mcparticles") maxNum = 50;
302 +      else if(currentObject == "primaryvertexs") maxNum = 50;
303 +      else if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
304 +      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
305 +      else if(currentObject == "electron-muon pairs")     currentObject = "electronMuonPairs";
306 +      else if(currentObject == "track-event pairs")       currentObject = "trackEventPairs";
307 +
308        currentObject.at(0) = toupper(currentObject.at(0));
309        string histoName = "num" + currentObject;
310 <      oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
310 >
311 >      if(histoName == "numPrimaryvertexs"){
312 >        string newHistoName = histoName + "BeforePileupCorrection";
313 >        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
314 >        newHistoName = histoName + "AfterPileupCorrection";
315 >        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
316 >      }
317 >      else
318 >        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
319      }
320  
321  
322 +
323 +
324      //get list of cuts for this channel
325      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
326  
327      //loop over and parse all cuts
328      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
149
329        cut tempCut;
330 <     //store input collection for cut
331 <      string inputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
332 <      tempCut.inputCollection = inputCollection;
333 <      allNecessaryObjects.push_back(inputCollection);
330 >      //store input collection for cut
331 >      string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
332 >      tempCut.inputCollection = tempInputCollection;
333 >      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
334 >        objectsToGet.push_back(tempInputCollection);
335 >        objectsToCut.push_back(tempInputCollection);
336 >      }
337 >      else{//pair of objects, need to add them both to the things to objectsToGet
338 >        int dashIndex = tempInputCollection.find("-");
339 >        int spaceIndex = tempInputCollection.find(" ");
340 >        int secondWordLength = spaceIndex - dashIndex;
341 >        objectsToGet.push_back(tempInputCollection);
342 >        objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
343 >        objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
344 >        objectsToCut.push_back(tempInputCollection);
345 >        objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
346 >        objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
347 >
348 >      }
349 >
350 >
351  
352        //split cut string into parts and store them
353        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
354        std::vector<string> cutStringVector = splitString(cutString);
355 <      if(cutStringVector.size()!=3){
356 <        std::cout << "Error: Didn't find three elements in the following cut string: '" <<cutString << "'\n";
357 <        exit(0);
355 >      if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
356 >        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
357 >        exit(0);
358 >      }
359 >      tempCut.numSubcuts = (cutStringVector.size()+1)/4;
360 >      for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
361 >        int indexOffset = 4 * subcutIndex;
362 >        string currentVariableString = cutStringVector.at(indexOffset);
363 >        if(currentVariableString.find("(")==std::string::npos){
364 >          tempCut.functions.push_back("");//no function was specified
365 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
366 >        }
367 >        else{
368 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
369 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
370 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
371 >        }
372 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
373 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
374 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
375        }
163
164      tempCut.variable = cutStringVector.at(0);// variable to cut on
165      tempCut.comparativeOperator = cutStringVector.at(1);// comparison to make
166      tempCut.cutValue = atof(cutStringVector.at(2).c_str());// threshold value to pass cut
376  
377        //get number of objects required to pass cut for event to pass
378        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
379        std::vector<string> numberRequiredVector = splitString(numberRequiredString);
380        if(numberRequiredVector.size()!=2){
381 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
381 >        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
382          exit(0);
383        }
384  
176      // determine number required if comparison contains "="
385        int numberRequiredInt = atoi(numberRequiredVector.at(1).c_str());
178      if(numberRequiredVector.at(0) == ">") numberRequiredInt++;
179      else if(numberRequiredVector.at(0) == "<") numberRequiredInt--;
180
386        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
387        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
388  
389 <      if(cuts_.at(currentCut).exists("function")){
185 <        tempCut.function = cuts_.at(currentCut).getParameter<string> ("function");
186 <      }
187 <      else tempCut.function = "";
389 >
390        string tempCutName;
391        if(cuts_.at(currentCut).exists("alias")){
392          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
# Line 192 | Line 394 | OSUAnalysis::OSUAnalysis (const edm::Par
394        else{
395          //construct string for cutflow table
396          bool plural = numberRequiredInt != 1;
397 <        string collectionString = plural ? inputCollection : inputCollection.substr(0, inputCollection.size()-1);
397 >        string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
398          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
399          tempCutName = cutName;
400        }
# Line 205 | Line 407 | OSUAnalysis::OSUAnalysis (const edm::Par
407  
408      }//end loop over cuts
409  
208
410      channels.push_back(tempChannel);
411      tempChannel.cuts.clear();
412  
413    }//end loop over channels
414  
415  
416 <  //make unique vector of objects we need to cut on (so we make sure to get them from the event)
417 <  sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
418 <  allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
416 >  //make unique vector of objects we need to get from the event
417 >  sort( objectsToGet.begin(), objectsToGet.end() );
418 >  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
419 >  //make unique vector of objects we need to cut on
420 >  sort( objectsToCut.begin(), objectsToCut.end() );
421 >  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
422  
423  
424   }
# Line 232 | Line 436 | void
436   OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
437   {
438  
235
439    // Retrieve necessary collections from the event.
440 <  edm::Handle<BNtriggerCollection> triggers;
441 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
440 >
441 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
442      event.getByLabel (triggers_, triggers);
443  
444 <  edm::Handle<BNjetCollection> jets;
242 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())
444 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
445      event.getByLabel (jets_, jets);
446  
447 <  edm::Handle<BNmuonCollection> muons;
246 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())
447 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
448      event.getByLabel (muons_, muons);
449  
450 <  edm::Handle<BNelectronCollection> electrons;
250 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())
450 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
451      event.getByLabel (electrons_, electrons);
452  
453 <  edm::Handle<BNeventCollection> events;
254 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())
453 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
454      event.getByLabel (events_, events);
455  
456 <  edm::Handle<BNtauCollection> taus;
258 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())
456 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
457      event.getByLabel (taus_, taus);
458  
459 <  edm::Handle<BNmetCollection> mets;
262 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())
459 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
460      event.getByLabel (mets_, mets);
461  
462 <  edm::Handle<BNtrackCollection> tracks;
266 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())
462 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
463      event.getByLabel (tracks_, tracks);
464  
465 <  edm::Handle<BNgenjetCollection> genjets;
270 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())
465 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
466      event.getByLabel (genjets_, genjets);
467  
468 <  edm::Handle<BNmcparticleCollection> mcparticles;
274 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())
468 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
469      event.getByLabel (mcparticles_, mcparticles);
470  
471 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
278 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())
471 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
472      event.getByLabel (primaryvertexs_, primaryvertexs);
473  
474 <  edm::Handle<BNbxlumiCollection> bxlumis;
282 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())
474 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
475      event.getByLabel (bxlumis_, bxlumis);
476  
477 <  edm::Handle<BNphotonCollection> photons;
286 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())
477 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
478      event.getByLabel (photons_, photons);
479  
480 <  edm::Handle<BNsuperclusterCollection> superclusters;
290 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())
480 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
481      event.getByLabel (superclusters_, superclusters);
482  
483 +  if (useTrackCaloRhoCorr_) {  
484 +    // Used only for pile-up correction of by-hand calculation of isolation energy.  
485 +    // This rho collection is not available in all BEANs.  
486 +    // For description of rho values for different jet reconstruction algorithms, see
487 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms  
488 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
489 +  }
490 +
491 +
492 +  //get pile-up event weight
493 +  double scaleFactor = 1.00;
494 +  if(doPileupReweighting_ && datasetType_ != "data")
495 +    scaleFactor = puWeight_->at (events->at (0).numTruePV);
496  
497  
498    //loop over all channels
# Line 298 | Line 501 | OSUAnalysis::analyze (const edm::Event &
501      channel currentChannel = channels.at(currentChannelIndex);
502  
503      flagMap individualFlags;
301    flagMap cumulativeFlags;
504      counterMap passingCounter;
505 +    cumulativeFlags.clear ();
506  
507      bool triggerDecision = true;
508      if(currentChannel.triggers.size() != 0){  //triggers specified
# Line 308 | Line 511 | OSUAnalysis::analyze (const edm::Event &
511      }
512  
513      //loop over all cuts
514 +
515 +
516 +
517      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
518        cut currentCut = currentChannel.cuts.at(currentCutIndex);
519  
520 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
520 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
521 >        string currentObject = objectsToCut.at(currentObjectIndex);
522  
523 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
523 >        //initialize maps to get ready to set cuts
524          individualFlags[currentObject].push_back (vector<bool> ());
525          cumulativeFlags[currentObject].push_back (vector<bool> ());
526  
527 +      }
528 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
529 +        string currentObject = objectsToCut.at(currentObjectIndex);
530 +
531 +        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
532 +
533  
534          if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
535          else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
# Line 333 | Line 546 | OSUAnalysis::analyze (const edm::Event &
546          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
547  
548  
549 +        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
550 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
551 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
552 +                                                                   "muon-muon pairs");
553 +        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
554 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
555 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
556 +                                                                           "electron-electron pairs");
557 +        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
558 +                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
559 +                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
560 +                                                                       "electron-muon pairs");
561 +        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
562 +                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
563 +                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
564 +                                                                     "track-event pairs");
565 +        
566  
567        }
568  
# Line 341 | Line 571 | OSUAnalysis::analyze (const edm::Event &
571      }//end loop over all cuts
572  
573  
344
345
574      //use cumulative flags to apply cuts at event level
575  
576      bool eventPassedAllCuts = true;
# Line 351 | Line 579 | OSUAnalysis::analyze (const edm::Event &
579      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
580  
581  
582 +
583      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
584  
585        //loop over all objects and count how many passed the cumulative selection up to this point
586        cut currentCut = currentChannel.cuts.at(currentCutIndex);
587        int numberPassing = 0;
588  
589 <      for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++)
589 >      for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
590            if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
591 <
591 >      }
592  
593        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
594        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
# Line 368 | Line 597 | OSUAnalysis::analyze (const edm::Event &
597  
598      }
599  
600 <    cutFlows_.at(currentChannelIndex)->fillCutFlow();
372 <
373 <
374 <    if(!eventPassedAllCuts)continue;
600 >    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
601  
602  
603  
604 +    if(!eventPassedAllCuts)continue;
605  
606 <    //set position of primary vertex in event, in order to calculate quantities relative to it
607 <    primaryVertex_ = 0;
608 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back();
609 <    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
610 <      if(!vertexFlags.at(vertexIndex)) continue;
611 <      primaryVertex_ = new BNprimaryvertex (primaryvertexs->at (vertexIndex));
612 <      break;
606 >    if (printEventInfo_) {
607 >      // Write information about event to screen, for testing purposes.  
608 >      cout << "Event passed all cuts in channel " <<  currentChannel.name
609 >           << ": run="  << events->at(0).run
610 >           << "  lumi=" << events->at(0).lumi
611 >           << "  event=" << events->at(0).evt
612 >           << endl;  
613      }
614  
615  
616 + //     if(datasetType_ != "data") {
617 + //       scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
618 + //       scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
619 + //     }
620  
621      //filling histograms
622      for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
623        histogram currentHistogram = histograms.at(histogramIndex);
624  
625        if(currentHistogram.inputVariables.size() == 1){
626 <        TH1D* histo;
627 <        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
628 <        if(currentHistogram.inputCollection == "jets") fillHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back());
629 <        else if(currentHistogram.inputCollection == "muons") fillHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back());
630 <        else if(currentHistogram.inputCollection == "electrons") fillHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back());
631 <        else if(currentHistogram.inputCollection == "events") fillHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back());
632 <        else if(currentHistogram.inputCollection == "taus") fillHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back());
633 <        else if(currentHistogram.inputCollection == "mets") fillHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back());
634 <        else if(currentHistogram.inputCollection == "tracks") fillHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back());
635 <        else if(currentHistogram.inputCollection == "genjets") fillHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back());
636 <        else if(currentHistogram.inputCollection == "mcparticles") fillHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back());
637 <        else if(currentHistogram.inputCollection == "primaryvertexs") fillHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back());
638 <        else if(currentHistogram.inputCollection == "bxlumis") fillHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back());
639 <        else if(currentHistogram.inputCollection == "photons") fillHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back());
640 <        else if(currentHistogram.inputCollection == "superclusters") fillHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back());
626 >        TH1D* histo;
627 >        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
628 >
629 >
630 >
631 >        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
632 >         else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
633 >        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
634 >                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
635 >                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
636 >        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
637 >        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
638 >                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
639 >                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
640 >        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
641 >                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
642 >                                                                                              cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
643 >        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
644 >        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
645 >        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
646 >        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
647 >        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
648 >        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
649 >        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
650 >        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
651 >        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
652 >        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
653        }
654        else if(currentHistogram.inputVariables.size() == 2){
655 <        TH2D* histo;
656 <        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
414 <        if(currentHistogram.inputCollection == "jets") fillHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back());
415 <        else if(currentHistogram.inputCollection == "muons") fillHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back());
416 <        else if(currentHistogram.inputCollection == "electrons") fillHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back());
417 <        else if(currentHistogram.inputCollection == "events") fillHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back());
418 <        else if(currentHistogram.inputCollection == "taus") fillHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back());
419 <        else if(currentHistogram.inputCollection == "mets") fillHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back());
420 <        else if(currentHistogram.inputCollection == "tracks") fillHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back());
421 <        else if(currentHistogram.inputCollection == "genjets") fillHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back());
422 <        else if(currentHistogram.inputCollection == "mcparticles") fillHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back());
423 <        else if(currentHistogram.inputCollection == "primaryvertexs") fillHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back());
424 <        else if(currentHistogram.inputCollection == "bxlumis") fillHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back());
425 <        else if(currentHistogram.inputCollection == "photons") fillHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back());
426 <        else if(currentHistogram.inputCollection == "superclusters") fillHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back());
427 <      }
428 <    }
655 >        TH2D* histo;
656 >        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
657  
658  
659 +
660 +        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
661 +        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
662 +        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
663 +                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
664 +                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
665 +        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
666 +        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
667 +                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
668 +                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
669 +        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
670 +                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
671 +                                                                                               cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
672 +        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
673 +        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
674 +        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
675 +        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
676 +        else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
677 +                                                                                         cumulativeFlags.at("tracks").back(),cumulativeFlags.at("events").back(),
678 +                                                                                         cumulativeFlags.at("track-event pairs").back(),scaleFactor);  
679 +        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
680 +        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
681 +        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
682 +        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
683 +        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
684 +        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
685 +      }
686 +    }
687 +
688      //fills histograms with the sizes of collections
689      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
690 +
691        string currentObject = objectsToPlot.at(currentObjectIndex);
692 <      string tempCurrentObject = currentObject;
693 <      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
692 >
693 >      string objectToPlot = "";  
694 >
695 >      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().  
696 >      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
697 >      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
698 >      else if(currentObject == "electron-muon pairs")     objectToPlot = "electronMuonPairs";
699 >      else if(currentObject == "track-event pairs")       objectToPlot = "trackEventPairs";  
700 >      else objectToPlot = currentObject;
701 >      string tempCurrentObject = objectToPlot;
702 >      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));  // Capitalize the first letter.  
703        string histoName = "num" + tempCurrentObject;
704  
438      if(currentObject == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size());
439      else if(currentObject == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size());
440      else if(currentObject == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size());
441      else if(currentObject == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size());
442      else if(currentObject == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size());
443      else if(currentObject == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size());
444      else if(currentObject == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size());
445      else if(currentObject == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size());
446      else if(currentObject == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size());
447      else if(currentObject == "primaryvertexs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(primaryvertexs->size());
448      else if(currentObject == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size());
449      else if(currentObject == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size());
450      else if(currentObject == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size());
705  
706 <    }
707 <  } //end loop over channel
706 >      //set position of primary vertex in event, in order to calculate quantities relative to it
707 >      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
708 >        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
709 >        int numToPlot = 0;
710 >        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
711 >          if(lastCutFlags.at(currentFlag)) numToPlot++;
712 >        }
713 >        if(objectToPlot == "primaryvertexs"){
714 >          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
715 >          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
716 >        }
717 >        else {
718 >          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
719 >        }
720 >      }
721 >      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
722 >      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
723 >      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
724 >      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
725 >      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
726 >      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
727 >      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
728 >      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
729 >      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
730 >      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
731 >      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
732 >      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
733 >      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
734 >      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
735 >      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
736 >      else if(objectToPlot == "primaryvertexs"){
737 >        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
738 >        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
739 >      }
740 >
741 >    } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
742  
743 <  masterCutFlow_->fillCutFlow();
743 >  } //end loop over channel
744  
745 +  masterCutFlow_->fillCutFlow(scaleFactor);
746  
747 + } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
748  
459 }
749  
750  
751   bool
# Line 468 | Line 757 | OSUAnalysis::evaluateComparison (double
757    else if(comparison == "<")  return testValue <  cutValue;
758    else if(comparison == "<=") return testValue <= cutValue;
759    else if(comparison == "==") return testValue == cutValue;
760 +  else if(comparison == "=") return testValue == cutValue;
761    else if(comparison == "!=") return testValue != cutValue;
762    else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
763  
# Line 650 | Line 940 | OSUAnalysis::valueLookup (const BNmuon*
940    else if(variable == "ecalIso") value = object->ecalIso;
941    else if(variable == "hcalIso") value = object->hcalIso;
942    else if(variable == "caloIso") value = object->caloIso;
943 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
943 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
944    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
945    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
946    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 789 | Line 1079 | OSUAnalysis::valueLookup (const BNmuon*
1079    else if(variable == "time_ndof") value = object->time_ndof;
1080  
1081    //user-defined variables
1082 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1083 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1084 <  else if(variable == "detIso") value = (object->trackIso) / object->pt;
1085 <  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1082 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1083 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1084 >  else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1085 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1086    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1087 +  else if(variable == "metMT") {
1088 +    const BNmet *met = chosenMET ();
1089 +    if (met)
1090 +      {
1091 +        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1092 +                       p2 (met->px, met->py, 0.0, met->pt);
1093 +
1094 +        value = (p1 + p2).Mt ();
1095 +      }
1096 +    else
1097 +      value = -999;
1098 +  }
1099 +
1100 +
1101 +
1102 +  else if(variable == "correctedD0VertexInEBPlus"){
1103 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1104 +    else value = -999;
1105 +  }
1106 +  else if(variable == "correctedD0VertexOutEBPlus"){
1107 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1108 +    else value = -999;
1109 +  }
1110 +  else if(variable == "correctedD0VertexEEPlus"){
1111 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1112 +    else value = -999;
1113 +  }
1114 +
1115 +  else if(variable == "correctedD0BeamspotInEBPlus"){
1116 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1117 +    else value = -999;
1118 +  }
1119 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
1120 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1121 +    else value = -999;
1122 +  }
1123 +  else if(variable == "correctedD0BeamspotEEPlus"){
1124 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1125 +    else value = -999;
1126 +  }
1127 +
1128 +  else if(variable == "correctedD0VertexInEBMinus"){
1129 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1130 +    else value = -999;
1131 +  }
1132 +  else if(variable == "correctedD0VertexOutEBMinus"){
1133 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1134 +    else value = -999;
1135 +  }
1136 +  else if(variable == "correctedD0VertexEEMinus"){
1137 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1138 +    else value = -999;
1139 +  }
1140 +
1141 +  else if(variable == "correctedD0BeamspotInEBMinus"){
1142 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1143 +    else value = -999;
1144 +  }
1145 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
1146 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1147 +    else value = -999;
1148 +  }
1149 +  else if(variable == "correctedD0BeamspotEEMinus"){
1150 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1151 +    else value = -999;
1152 +  }
1153 +
1154 +
1155 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1156 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1157 +    else value = -999;
1158 +  }
1159 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1160 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1161 +    else value = -999;
1162 +  }
1163 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
1164 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1165 +    else value = -999;
1166 +  }
1167 +
1168 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1169 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1170 +    else value = -999;
1171 +  }
1172 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1173 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1174 +    else value = -999;
1175 +  }
1176 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1177 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1178 +    else value = -999;
1179 +  }
1180 +
1181 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1182 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1183 +    else value = -999;
1184 +  }
1185 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1186 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1187 +    else value = -999;
1188 +  }
1189 +  else if(variable == "correctedD0VertexEENegativeCharge"){
1190 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1191 +    else value = -999;
1192 +  }
1193 +
1194 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1195 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1196 +    else value = -999;
1197 +  }
1198 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1199 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1200 +    else value = -999;
1201 +  }
1202 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1203 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1204 +    else value = -999;
1205 +  }
1206 +
1207 +
1208    else if(variable == "tightID") {
1209 <    value = object->isGlobalMuon > 0            \
1210 <      && object->isPFMuon > 0                   \
1211 <      && object->normalizedChi2 < 10            \
1212 <      && object->numberOfValidMuonHits > 0      \
1213 <      && object->numberOfMatchedStations > 1    \
1214 <      && fabs(object->correctedD0Vertex) < 0.2  \
1215 <      && fabs(object->correctedDZ) < 0.5        \
1216 <      && object->numberOfValidPixelHits > 0     \
1209 >    value = object->isGlobalMuon > 0                \
1210 >      && object->isPFMuon > 0                        \
1211 >      && object->normalizedChi2 < 10                \
1212 >      && object->numberOfValidMuonHits > 0        \
1213 >      && object->numberOfMatchedStations > 1        \
1214 >      && fabs(object->correctedD0Vertex) < 0.2        \
1215 >      && fabs(object->correctedDZ) < 0.5        \
1216 >      && object->numberOfValidPixelHits > 0                \
1217        && object->numberOfLayersWithMeasurement > 5;
807    
808
1218    }
1219    else if(variable == "tightIDdisplaced"){
1220 <    value = object->isGlobalMuon > 0            \
1221 <      && object->isPFMuon > 0                   \
1222 <      && object->normalizedChi2 < 10            \
1223 <      && object->numberOfValidMuonHits > 0      \
1224 <      && object->numberOfMatchedStations > 1    \
816 <      && object->numberOfValidPixelHits > 0     \
1220 >    value = object->isGlobalMuon > 0                \
1221 >      && object->normalizedChi2 < 10                \
1222 >      && object->numberOfValidMuonHits > 0        \
1223 >      && object->numberOfMatchedStations > 1        \
1224 >      && object->numberOfValidPixelHits > 0        \
1225        && object->numberOfLayersWithMeasurement > 5;
1226    }
1227  
1228 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1229 +
1230 +  else if(variable == "genMatchedPdgId"){
1231 +    int index = getGenMatchedParticleIndex(object);
1232 +    if(index == -1) value = 0;
1233 +    else value = mcparticles->at(index).id;
1234 +  }
1235 +
1236 +  else if(variable == "genMatchedId"){
1237 +    int index = getGenMatchedParticleIndex(object);
1238 +    if(index == -1) value = 0;
1239 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
1240 +  }
1241 +  else if(variable == "genMatchedMotherId"){
1242 +    int index = getGenMatchedParticleIndex(object);
1243 +    if(index == -1) value = 0;
1244 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1245 +  }
1246 +  else if(variable == "genMatchedMotherIdReverse"){
1247 +    int index = getGenMatchedParticleIndex(object);
1248 +    if(index == -1) value = 23;
1249 +    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1250 +  }
1251 +  else if(variable == "genMatchedGrandmotherId"){
1252 +    int index = getGenMatchedParticleIndex(object);
1253 +    if(index == -1) value = 0;
1254 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1255 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1256 +      if(motherIndex == -1) value = 0;
1257 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1258 +    }
1259 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1260 +  }
1261 +
1262 +
1263 +
1264    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1265  
1266    value = applyFunction(function, value);
# Line 987 | Line 1431 | OSUAnalysis::valueLookup (const BNelectr
1431    else if(variable == "passConvVeto") value = object->passConvVeto;
1432  
1433    //user-defined variables
1434 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1435 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1434 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1435 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1436    else if(variable == "detIso") value = (object->trackIso) / object->pt;
1437    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1438 +  else if(variable == "metMT") {
1439 +    const BNmet *met = chosenMET ();
1440 +    if (met)
1441 +      {
1442 +        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1443 +                       p2 (met->px, met->py, 0.0, met->pt);
1444 +
1445 +        value = (p1 + p2).Mt ();
1446 +      }
1447 +    else
1448 +      value = -999;
1449 +  }
1450 +
1451 +  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
1452 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
1453 +    else value = -999;
1454 +  }
1455 +  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
1456 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
1457 +    else value = -999;
1458 +  }
1459 +
1460 +  else if(variable == "correctedD0VertexInEBPlus"){
1461 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1462 +    else value = -999;
1463 +  }
1464 +  else if(variable == "correctedD0VertexOutEBPlus"){
1465 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1466 +    else value = -999;
1467 +  }
1468 +  else if(variable == "correctedD0VertexEEPlus"){
1469 +    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
1470 +    else value = -999;
1471 +  }
1472 +
1473 +  else if(variable == "correctedD0BeamspotInEBPlus"){
1474 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1475 +    else value = -999;
1476 +  }
1477 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
1478 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1479 +    else value = -999;
1480 +  }
1481 +  else if(variable == "correctedD0BeamspotEEPlus"){
1482 +    if(object->isEE && object->eta > 0) value = object->correctedD0;
1483 +    else value = -999;
1484 +  }
1485 +
1486 +  else if(variable == "correctedD0VertexInEBMinus"){
1487 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1488 +    else value = -999;
1489 +  }
1490 +  else if(variable == "correctedD0VertexOutEBMinus"){
1491 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1492 +    else value = -999;
1493 +  }
1494 +  else if(variable == "correctedD0VertexEEMinus"){
1495 +    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
1496 +    else value = -999;
1497 +  }
1498 +
1499 +  else if(variable == "correctedD0BeamspotInEBMinus"){
1500 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1501 +    else value = -999;
1502 +  }
1503 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
1504 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1505 +    else value = -999;
1506 +  }
1507 +  else if(variable == "correctedD0BeamspotEEMinus"){
1508 +    if(object->isEE && object->eta < 0) value = object->correctedD0;
1509 +    else value = -999;
1510 +  }
1511 +
1512 +  else if(variable == "tightID"){
1513 +    if (object->isEB)
1514 +      {
1515 +        value = fabs(object->delEtaIn) < 0.004 \
1516 +          && fabs (object->delPhiIn) < 0.03 \
1517 +          && object->scSigmaIEtaIEta < 0.01 \
1518 +          && object->hadOverEm < 0.12 \
1519 +          && fabs (object->correctedD0Vertex) < 0.02 \
1520 +          && fabs (object->correctedDZ) < 0.1 \
1521 +          && object->absInvEMinusInvPin < 0.05 \
1522 +          && object->passConvVeto;
1523 +      }
1524 +    else
1525 +      {
1526 +        value = fabs(object->delEtaIn) < 0.005 \
1527 +          && fabs (object->delPhiIn) < 0.02 \
1528 +          && object->scSigmaIEtaIEta < 0.03 \
1529 +          && object->hadOverEm < 0.10 \
1530 +          && fabs (object->correctedD0Vertex) < 0.02 \
1531 +          && fabs (object->correctedDZ) < 0.1 \
1532 +          && object->absInvEMinusInvPin < 0.05 \
1533 +          && object->passConvVeto;
1534 +      }
1535 +  }
1536 +
1537 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1538 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1539 +    else value = -999;
1540 +  }
1541 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1542 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1543 +    else value = -999;
1544 +  }
1545 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
1546 +    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
1547 +    else value = -999;
1548 +  }
1549 +
1550 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1551 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1552 +    else value = -999;
1553 +  }
1554 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1555 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1556 +    else value = -999;
1557 +  }
1558 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1559 +    if(object->isEE && object->charge > 0) value = object->correctedD0;
1560 +    else value = -999;
1561 +  }
1562 +
1563 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1564 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1565 +    else value = -999;
1566 +  }
1567 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1568 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1569 +    else value = -999;
1570 +  }
1571 +  else if(variable == "correctedD0VertexEENegativeCharge"){
1572 +    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
1573 +    else value = -999;
1574 +  }
1575 +
1576 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1577 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1578 +    else value = -999;
1579 +  }
1580 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1581 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1582 +    else value = -999;
1583 +  }
1584 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1585 +    if(object->isEE && object->charge < 0) value = object->correctedD0;
1586 +    else value = -999;
1587 +  }
1588 +
1589 +
1590 +  else if(variable == "tightIDdisplaced"){
1591 +    if (object->isEB)
1592 +      {
1593 +        value = fabs(object->delEtaIn) < 0.004 \
1594 +          && fabs (object->delPhiIn) < 0.03 \
1595 +          && object->scSigmaIEtaIEta < 0.01 \
1596 +          && object->hadOverEm < 0.12 \
1597 +          && object->absInvEMinusInvPin < 0.05;
1598 +      }
1599 +    else
1600 +      {
1601 +        value = fabs (object->delEtaIn) < 0.005 \
1602 +          && fabs (object->delPhiIn) < 0.02 \
1603 +          && object->scSigmaIEtaIEta < 0.03 \
1604 +          && object->hadOverEm < 0.10 \
1605 +          && object->absInvEMinusInvPin < 0.05;
1606 +      }
1607 +  }
1608 +
1609 +
1610 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1611 +
1612 +  else if(variable == "genMatchedPdgId"){
1613 +    int index = getGenMatchedParticleIndex(object);
1614 +    if(index == -1) value = 0;
1615 +    else value = mcparticles->at(index).id;
1616 +  }
1617 +
1618 +
1619 +  else if(variable == "genMatchedId"){
1620 +    int index = getGenMatchedParticleIndex(object);
1621 +    if(index == -1) value = 0;
1622 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
1623 +  }
1624 +  else if(variable == "genMatchedMotherId"){
1625 +    int index = getGenMatchedParticleIndex(object);
1626 +    if(index == -1) value = 0;
1627 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1628 +  }
1629 +  else if(variable == "genMatchedMotherIdReverse"){
1630 +    int index = getGenMatchedParticleIndex(object);
1631 +    if(index == -1) value = 23;
1632 +    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1633 +  }
1634 +  else if(variable == "genMatchedGrandmotherId"){
1635 +    int index = getGenMatchedParticleIndex(object);
1636 +    if(index == -1) value = 0;
1637 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1638 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1639 +      if(motherIndex == -1) value = 0;
1640 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1641 +    }
1642 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1643 +  }
1644 +
1645  
1646  
1647    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
# Line 1070 | Line 1721 | OSUAnalysis::valueLookup (const BNevent*
1721    else if(variable == "id1") value = object->id1;
1722    else if(variable == "id2") value = object->id2;
1723    else if(variable == "evt") value = object->evt;
1724 +  else if(variable == "puScaleFactor"){
1725 +    if(datasetType_ != "data")
1726 +      value = puWeight_->at (events->at (0).numTruePV);
1727 +    else
1728 +      value = 1.0;
1729 +  }
1730 +  else if(variable == "muonScaleFactor"){
1731 +    if(datasetType_ != "data")
1732 +      //      value = muonSFWeight_->at (chosenMuon ()->eta);
1733 +    value = 1.0;
1734 +    else
1735 +      value = 1.0;
1736 +  }
1737 +  else if(variable == "electronScaleFactor"){
1738 +    if(datasetType_ != "data")
1739 +      //      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1740 +    value = 1.0;
1741 +    else
1742 +      value = 1.0;
1743 +  }
1744  
1745    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1746  
# Line 1124 | Line 1795 | OSUAnalysis::valueLookup (const BNtau* o
1795    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
1796  
1797  
1798 +
1799 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1800 +
1801 +  else if(variable == "genMatchedPdgId"){
1802 +    int index = getGenMatchedParticleIndex(object);
1803 +    if(index == -1) value = 0;
1804 +    else value = mcparticles->at(index).id;
1805 +  }
1806 +
1807 +  else if(variable == "genMatchedId"){
1808 +    int index = getGenMatchedParticleIndex(object);
1809 +    if(index == -1) value = 0;
1810 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
1811 +  }
1812 +  else if(variable == "genMatchedMotherId"){
1813 +    int index = getGenMatchedParticleIndex(object);
1814 +    if(index == -1) value = 0;
1815 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1816 +  }
1817 +  else if(variable == "genMatchedMotherIdReverse"){
1818 +    int index = getGenMatchedParticleIndex(object);
1819 +    if(index == -1) value = 23;
1820 +    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1821 +  }
1822 +  else if(variable == "genMatchedGrandmotherId"){
1823 +    int index = getGenMatchedParticleIndex(object);
1824 +    if(index == -1) value = 0;
1825 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1826 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1827 +      if(motherIndex == -1) value = 0;
1828 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1829 +    }
1830 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1831 +  }
1832 +
1833 +
1834    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1835  
1836    value = applyFunction(function, value);
# Line 1207 | Line 1914 | double
1914   OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
1915  
1916    double value = 0.0;
1917 <
1917 >  double pMag = sqrt(object->pt * object->pt +
1918 >                     object->pz * object->pz);
1919 >  
1920    if(variable == "pt") value = object->pt;
1921    else if(variable == "px") value = object->px;
1922    else if(variable == "py") value = object->py;
# Line 1227 | Line 1936 | OSUAnalysis::valueLookup (const BNtrack*
1936    else if(variable == "isHighPurity") value = object->isHighPurity;
1937  
1938  
1939 +  //additional BNs info for disappTrks
1940 +  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
1941 +  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
1942 +  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
1943 +  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
1944 +  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
1945 +  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
1946 +  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
1947 +  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
1948 +  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
1949 +  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
1950 +  
1951 +
1952 +  //user defined variables
1953 +  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;
1954 +  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
1955 +  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
1956 +  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
1957 +  else if(variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object);  
1958 +  else if(variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object) / pMag;  
1959 +  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
1960 +  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
1961 +  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
1962 +  else if(variable == "ptError")                    value = object->ptError;
1963 +  else if(variable == "ptRes")                      value = getTrkPtRes(object);
1964 +
1965 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1966 +
1967 +  else if(variable == "genMatchedPdgId"){
1968 +    int index = getGenMatchedParticleIndex(object);
1969 +    if(index == -1) value = 0;
1970 +    else value = mcparticles->at(index).id;
1971 +  }
1972 +
1973 +
1974 +  else if(variable == "genMatchedId"){
1975 +    int index = getGenMatchedParticleIndex(object);
1976 +    if(index == -1) value = 0;
1977 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
1978 +  }
1979 +  else if(variable == "genMatchedMotherId"){
1980 +    int index = getGenMatchedParticleIndex(object);
1981 +    if(index == -1) value = 0;
1982 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1983 +  }
1984 +  else if(variable == "genMatchedMotherIdReverse"){
1985 +    int index = getGenMatchedParticleIndex(object);
1986 +    if(index == -1) value = 23;
1987 +    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1988 +  }
1989 +  else if(variable == "genMatchedGrandmotherId"){
1990 +    int index = getGenMatchedParticleIndex(object);
1991 +    if(index == -1) value = 0;
1992 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1993 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1994 +      if(motherIndex == -1) value = 0;
1995 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1996 +    }
1997 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1998 +  }
1999 +
2000 +
2001 +
2002    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2003  
2004    value = applyFunction(function, value);
# Line 1354 | Line 2126 | OSUAnalysis::valueLookup (const BNmcpart
2126  
2127    //user-defined variables
2128    else if (variable == "d0"){
2129 <    double vx = object->vx - primaryVertex_->x,
2130 <      vy = object->vy - primaryVertex_->y,
2129 >    double vx = object->vx - chosenVertex ()->x,
2130 >      vy = object->vy - chosenVertex ()->y,
2131        px = object->px,
2132        py = object->py,
2133        pt = object->pt;
2134      value = (-vx * py + vy * px) / pt;
2135    }
2136    else if (variable == "dz"){
2137 <    double vx = object->vx - primaryVertex_->x,
2138 <      vy = object->vy - primaryVertex_->y,
2139 <      vz = object->vz - primaryVertex_->z,
2137 >    double vx = object->vx - chosenVertex ()->x,
2138 >      vy = object->vy - chosenVertex ()->y,
2139 >      vz = object->vz - chosenVertex ()->z,
2140        px = object->px,
2141        py = object->py,
2142        pz = object->pz,
2143        pt = object->pt;
2144      value = vz - (vx * px + vy * py)/pt * (pz/pt);
2145    }
2146 <
2146 >  else if(variable == "v0"){
2147 >    value = sqrt(object->vx*object->vx + object->vy*object->vy);
2148 >  }
2149 >  else if(variable == "deltaV0"){
2150 >    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
2151 >  }
2152 >  else if (variable == "deltaVx"){
2153 >    value = object->vx - chosenVertex ()->x;
2154 >  }
2155 >  else if (variable == "deltaVy"){
2156 >    value = object->vy - chosenVertex ()->y;
2157 >  }
2158 >  else if (variable == "deltaVz"){
2159 >    value = object->vz - chosenVertex ()->z;
2160 >  }
2161  
2162  
2163    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
# Line 1501 | Line 2287 | OSUAnalysis::valueLookup (const BNphoton
2287    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2288  
2289  
2290 +
2291 +
2292 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2293 +
2294 +  else if(variable == "genMatchedPdgId"){
2295 +    int index = getGenMatchedParticleIndex(object);
2296 +    if(index == -1) value = 0;
2297 +    else value = mcparticles->at(index).id;
2298 +  }
2299 +
2300 +
2301 +
2302 +  else if(variable == "genMatchedId"){
2303 +    int index = getGenMatchedParticleIndex(object);
2304 +    if(index == -1) value = 0;
2305 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
2306 +  }
2307 +  else if(variable == "genMatchedMotherId"){
2308 +    int index = getGenMatchedParticleIndex(object);
2309 +    if(index == -1) value = 0;
2310 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2311 +  }
2312 +  else if(variable == "genMatchedMotherIdReverse"){
2313 +    int index = getGenMatchedParticleIndex(object);
2314 +    if(index == -1) value = 23;
2315 +    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2316 +  }
2317 +  else if(variable == "genMatchedGrandmotherId"){
2318 +    int index = getGenMatchedParticleIndex(object);
2319 +    if(index == -1) value = 0;
2320 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2321 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2322 +      if(motherIndex == -1) value = 0;
2323 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2324 +    }
2325 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2326 +  }
2327 +
2328 +
2329    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2330  
2331    value = applyFunction(function, value);
# Line 1532 | Line 2357 | OSUAnalysis::valueLookup (const BNsuperc
2357  
2358  
2359   double
2360 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
2361 +
2362 +  double value = 0.0;
2363 +
2364 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2365 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2366 +  else if(variable == "invMass"){
2367 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2368 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2369 +    value = (fourVector1 + fourVector2).M();
2370 +  }
2371 +  else if(variable == "pt"){
2372 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2373 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2374 +    value = (fourVector1 + fourVector2).Pt();
2375 +  }
2376 +  else if(variable == "threeDAngle")
2377 +    {
2378 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2379 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2380 +      value = (threeVector1.Angle(threeVector2));
2381 +    }
2382 +  else if(variable == "alpha")
2383 +    {
2384 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
2385 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2386 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2387 +      value = (pi-threeVector1.Angle(threeVector2));
2388 +    }
2389 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2390 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2391 +  else if(variable == "d0Sign"){
2392 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2393 +    if(d0Sign < 0) value = -0.5;
2394 +    else if (d0Sign > 0) value = 0.5;
2395 +    else value = -999;
2396 +  }
2397 +  else if(variable == "chargeProduct"){
2398 +    value = object1->charge*object2->charge;
2399 +  }
2400 +  else if(variable == "muon1CorrectedD0Vertex"){
2401 +    value = object1->correctedD0Vertex;
2402 +  }
2403 +  else if(variable == "muon2CorrectedD0Vertex"){
2404 +    value = object2->correctedD0Vertex;
2405 +  }
2406 + else if(variable == "muon1timeAtIpInOut"){
2407 +    value = object1->timeAtIpInOut;
2408 +  }
2409 + else if(variable == "muon2timeAtIpInOut"){
2410 +    value = object2->timeAtIpInOut;
2411 +  }
2412 + else if(variable == "muon1correctedD0")
2413 +   {
2414 +     value = object1->correctedD0;
2415 +   }
2416 + else if(variable == "muon2correctedD0")
2417 +   {
2418 +     value = object2->correctedD0;
2419 +   }
2420 +
2421 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2422 +
2423 +  value = applyFunction(function, value);
2424 +
2425 +  return value;
2426 + }
2427 +
2428 + double
2429 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
2430 +
2431 +  double value = 0.0;
2432 +
2433 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2434 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2435 +  else if(variable == "invMass"){
2436 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2437 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2438 +    value = (fourVector1 + fourVector2).M();
2439 +  }
2440 +  else if(variable == "pt"){
2441 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2442 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2443 +    value = (fourVector1 + fourVector2).Pt();
2444 +  }
2445 +  else if(variable == "threeDAngle")
2446 +    {
2447 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2448 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2449 +      value = (threeVector1.Angle(threeVector2));
2450 +    }
2451 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2452 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2453 +  else if(variable == "d0Sign"){
2454 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2455 +    if(d0Sign < 0) value = -0.5;
2456 +    else if (d0Sign > 0) value = 0.5;
2457 +    else value = -999;
2458 +  }
2459 +  else if(variable == "chargeProduct"){
2460 +    value = object1->charge*object2->charge;
2461 +  }
2462 +  else if(variable == "electron1CorrectedD0Vertex"){
2463 +    value = object1->correctedD0Vertex;
2464 +  }
2465 +  else if(variable == "electron2CorrectedD0Vertex"){
2466 +    value = object2->correctedD0Vertex;
2467 +  }
2468 +  else if(variable == "electron1CorrectedD0"){
2469 +    value = object1->correctedD0;
2470 +  }
2471 +  else if(variable == "electron2CorrectedD0"){
2472 +    value = object2->correctedD0;
2473 +  }
2474 +
2475 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2476 +
2477 +  value = applyFunction(function, value);
2478 +
2479 +  return value;
2480 + }
2481 +
2482 + double
2483 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
2484 +
2485 +  double value = 0.0;
2486 +
2487 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2488 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2489 +  else if(variable == "invMass"){
2490 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2491 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2492 +    value = (fourVector1 + fourVector2).M();
2493 +  }
2494 +  else if(variable == "pt"){
2495 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2496 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2497 +    value = (fourVector1 + fourVector2).Pt();
2498 +  }
2499 +  else if(variable == "threeDAngle")
2500 +    {
2501 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2502 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2503 +      value = (threeVector1.Angle(threeVector2));
2504 +    }
2505 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2506 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2507 +  else if(variable == "d0Sign"){
2508 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2509 +    if(d0Sign < 0) value = -0.5;
2510 +    else if (d0Sign > 0) value = 0.5;
2511 +    else value = -999;
2512 +  }
2513 +  else if(variable == "chargeProduct"){
2514 +    value = object1->charge*object2->charge;
2515 +  }
2516 +  else if(variable == "electronCorrectedD0Vertex"){
2517 +    value = object1->correctedD0Vertex;
2518 +  }
2519 +  else if(variable == "muonCorrectedD0Vertex"){
2520 +    value = object2->correctedD0Vertex;
2521 +  }
2522 +  else if(variable == "electronCorrectedD0"){
2523 +    value = object1->correctedD0;
2524 +  }
2525 +  else if(variable == "muonCorrectedD0"){
2526 +    value = object2->correctedD0;
2527 +  }
2528 +  else if(variable == "electronDetIso"){
2529 +    value = (object1->trackIso) / object1->pt;
2530 +  }
2531 +  else if(variable == "muonDetIso"){
2532 +    value = (object2->trackIsoDR03) / object2->pt;
2533 +  }
2534 +
2535 +
2536 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2537 +
2538 +  value = applyFunction(function, value);
2539 +
2540 +  return value;
2541 + }
2542 +
2543 +
2544 +
2545 +
2546 + double
2547 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function){
2548 +
2549 +  double value = 0.0;
2550 +  double pMag = sqrt(object1->pt * object1->pt +
2551 +                     object1->pz * object1->pz);  
2552 +
2553 +  if      (variable == "numPV")                      value = object2->numPV;
2554 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
2555 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
2556 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);  
2557 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;  
2558 +
2559 +  else { std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
2560 +
2561 +  value = applyFunction(function, value);
2562 +
2563 +  return value;
2564 +
2565 + }  
2566 +
2567 + // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
2568 + // Return true iff no other tracks are found in this cone.
2569 + int
2570 + OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
2571 +  for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
2572 +    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
2573 +    double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
2574 +    if(deltaRtrk < 0.5) return 0;
2575 +  }
2576 +  return 1;
2577 +
2578 + }
2579 +
2580 +
2581 + double
2582 + OSUAnalysis::getTrkPtRes (const BNtrack* track1){
2583 +
2584 +  double ptTrue = getTrkPtTrue(track1, mcparticles.product());
2585 +  double PtRes = (track1->pt - ptTrue) / ptTrue;
2586 +
2587 +  return PtRes;
2588 +
2589 + }
2590 +
2591 +
2592 + double
2593 + OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
2594 +  double value = -99;
2595 +  double genDeltaRLowest = 999;
2596 +
2597 +  for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
2598 +    double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
2599 +    if (genDeltaRtemp < genDeltaRLowest) {
2600 +      genDeltaRLowest = genDeltaRtemp;
2601 +      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
2602 +        double ptTrue = genPart->pt;
2603 +        value = ptTrue;
2604 +      }
2605 +    }
2606 +  }
2607 +
2608 +  return value;
2609 +
2610 + }
2611 +
2612 + double
2613 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
2614 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.  
2615 +  if (!useTrackCaloRhoCorr_) return -99;  
2616 +  // if (!rhokt6CaloJetsHandle_) {
2617 +  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;  
2618 +  //   return -99;  
2619 +  // }
2620 +  double radDeltaRCone = 0.5;  
2621 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.  
2622 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;  
2623 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);  
2624 +  return caloTotRhoCorrCalo;  
2625 +
2626 + }
2627 +
2628 +
2629 +
2630 +
2631 + //creates a map of the dead Ecal channels in the barrel and endcap
2632 + //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
2633 + //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
2634 + void
2635 + OSUAnalysis::WriteDeadEcal (){
2636 +  double etaEcal, phiEcal;
2637 +  ifstream DeadEcalFile(deadEcalFile_);
2638 +  if(!DeadEcalFile) {
2639 +    cout << "Error: DeadEcalFile has not been found." << endl;
2640 +    return;
2641 +  }
2642 +  if(DeadEcalVec.size()!= 0){
2643 +    cout << "Error: DeadEcalVec has a nonzero size" << endl;
2644 +    return;
2645 +  }
2646 +  while(!DeadEcalFile.eof())
2647 +    {
2648 +      DeadEcalFile >> etaEcal >> phiEcal;
2649 +      DeadEcal newChan;
2650 +      newChan.etaEcal = etaEcal;
2651 +      newChan.phiEcal = phiEcal;
2652 +      DeadEcalVec.push_back(newChan);
2653 +    }
2654 +  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
2655 + }
2656 +
2657 + //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
2658 + int
2659 + OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
2660 +  double deltaRLowest = 999;
2661 +  int value = 0;
2662 +  if (DeadEcalVec.size() == 0) WriteDeadEcal();
2663 +  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
2664 +    double eta = ecal->etaEcal;
2665 +    double phi = ecal->phiEcal;
2666 +    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
2667 +    if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
2668 +  }
2669 +  if (deltaRLowest<0.05) {value = 1;}
2670 +  else {value = 0;}
2671 +  return value;
2672 + }
2673 +
2674 + // Returns the smallest DeltaR between the object and any generated true particle in the event.  
2675 + template <class InputObject>
2676 + double OSUAnalysis::getGenDeltaRLowest(InputObject object){
2677 +  double genDeltaRLowest = 999.;
2678 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
2679 +    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
2680 +    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
2681 + }
2682 +  return genDeltaRLowest;
2683 + }
2684 +
2685 + double
2686   OSUAnalysis::applyFunction(string function, double value){
2687  
2688    if(function == "abs") value = fabs(value);
2689 +  else if(function == "fabs") value = fabs(value);
2690 +  else if(function == "log10") value = log10(value);
2691 +  else if(function == "log") value = log10(value);
2692  
2693 +  else if(function == "") value = value;
2694 +  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
2695  
2696    return value;
2697  
# Line 1548 | Line 2704 | void OSUAnalysis::setObjectFlags(cut &cu
2704  
2705    for (uint object = 0; object != inputCollection->size(); object++){
2706  
2707 +
2708      bool decision = true;//object passes if this cut doesn't cut on that type of object
2709  
1553    if(currentCut.inputCollection == inputType){
2710  
2711 <      double value = valueLookup(&inputCollection->at(object), currentCut.variable, currentCut.function);
2711 >    if(currentCut.inputCollection == inputType){
2712  
2713 <      decision = evaluateComparison(value,currentCut.comparativeOperator,currentCut.cutValue);
2713 >      vector<bool> subcutDecisions;
2714 >      for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
2715 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
2716 >        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
2717 >      }
2718 >      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
2719 >      else{
2720 >        bool tempDecision = true;
2721 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
2722 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
2723 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
2724 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
2725 >            tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
2726 >        }
2727 >        decision = tempDecision;
2728 >      }
2729      }
2730      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
2731  
# Line 1567 | Line 2738 | void OSUAnalysis::setObjectFlags(cut &cu
2738      }
2739      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
2740  
2741 +
2742 +  }
2743 +
2744 + }
2745 +
2746 +
2747 + template <class InputCollection1, class InputCollection2>
2748 + void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
2749 +                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
2750 +
2751 +
2752 +  bool sameObjects = false;
2753 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
2754 +
2755 +
2756 +  int counter = 0;
2757 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
2758 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
2759 +
2760 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
2761 +
2762 +
2763 +      bool decision = true;//object passes if this cut doesn't cut on that type of object
2764 +
2765 +      if(currentCut.inputCollection == inputType){
2766 +
2767 +        vector<bool> subcutDecisions;
2768 +        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
2769 +          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
2770 +          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
2771 +        }
2772 +
2773 +        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
2774 +        else{
2775 +          bool tempDecision = subcutDecisions.at(0);
2776 +          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
2777 +            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
2778 +              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
2779 +            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
2780 +              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
2781 +          }
2782 +          decision = tempDecision;
2783 +        }
2784 +      }
2785 +      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
2786 +
2787 +      //set flags for objects that pass each cut AND all the previous cuts
2788 +      bool previousCumulativeFlag = true;
2789 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
2790 +        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
2791 +        else{ previousCumulativeFlag = false; break;}
2792 +      }
2793 +      //apply flags for the components of the composite object as well
2794 +      bool currentCumulativeFlag = true;
2795 +      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
2796 +      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
2797 +      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
2798 +      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
2799 +      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
2800 +
2801 +      counter++;
2802 +    }
2803 +
2804 +  }
2805 +
2806 +
2807 + }
2808 +
2809 +
2810 + template <class InputCollection>
2811 + void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
2812 +
2813 +  for (uint object = 0; object != inputCollection->size(); object++){
2814 +
2815 +    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
2816 +
2817 +    string currentString = parameters.inputVariables.at(0);
2818 +    string inputVariable = "";
2819 +    string function = "";
2820 +    if(currentString.find("(")==std::string::npos){
2821 +      inputVariable = currentString;// variable to cut on
2822 +    }
2823 +    else{
2824 +      function = currentString.substr(0,currentString.find("("));//function comes before the "("
2825 +      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
2826 +      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
2827 +    }
2828 +
2829 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
2830 +    histo->Fill(value,scaleFactor);
2831 +
2832 +    if (printEventInfo_) {
2833 +      // Write information about event to screen, for testing purposes.  
2834 +      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;  
2835 +    }
2836 +    
2837 +  }
2838 + }
2839 +
2840 + template <class InputCollection1, class InputCollection2>
2841 + void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
2842 +
2843 +  bool sameObjects = false;
2844 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
2845 +
2846 +  int pairCounter = 0;
2847 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
2848 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
2849 +
2850 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
2851 +
2852 +      //only take objects which have passed all cuts and pairs which have passed all cuts
2853 +      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
2854 +      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
2855 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
2856 +
2857 +      string currentString = parameters.inputVariables.at(0);
2858 +      string inputVariable = "";
2859 +      string function = "";
2860 +      if(currentString.find("(")==std::string::npos){
2861 +        inputVariable = currentString;// variable to cut on
2862 +      }
2863 +      else{
2864 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("
2865 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
2866 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
2867 +      }
2868 +
2869 +      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
2870 +      histo->Fill(value,scaleFactor);
2871 +
2872 +      pairCounter++;
2873 +    }
2874    }
2875  
2876   }
2877  
2878  
2879   template <class InputCollection>
2880 < void OSUAnalysis::fillHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags){
2880 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
2881  
2882    for (uint object = 0; object != inputCollection->size(); object++){
2883  
2884 <    if(!plotAllObjectsInPassingEvents && !flags.at(object)) continue;
2884 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
2885  
2886 <    if(parameters.inputVariables.size() == 1){
2887 <      double value = valueLookup(&inputCollection->at(object), parameters.inputVariables.at(0), parameters.function);
2888 <      histo->Fill(value);
2889 <    }
2890 <    else if(parameters.inputVariables.size() == 2){
2891 <      double valueX = valueLookup(&inputCollection->at(object), parameters.inputVariables.at(0), parameters.function);
2892 <      double valueY = valueLookup(&inputCollection->at(object), parameters.inputVariables.at(1), parameters.function);
2893 <      histo->Fill(valueX,valueY);
2886 >    string currentString = parameters.inputVariables.at(0);
2887 >    string inputVariable = "";
2888 >    string function = "";
2889 >    if(currentString.find("(")==std::string::npos){
2890 >      inputVariable = currentString;// variable to cut on
2891 >    }
2892 >    else{
2893 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
2894 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
2895 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
2896      }
2897 +    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
2898 +
2899 +    currentString = parameters.inputVariables.at(1);
2900 +    inputVariable = "";
2901 +    function = "";
2902 +    if(currentString.find("(")==std::string::npos){
2903 +      inputVariable = currentString;// variable to cut on
2904 +    }
2905 +    else{
2906 +      function = currentString.substr(0,currentString.find("("));//function comes before the "("
2907 +      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
2908 +      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
2909 +    }
2910 +
2911 +    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
2912 +
2913 +    histo->Fill(valueX,valueY,scaleFactor);
2914  
2915    }
2916  
2917   }
2918  
2919 + template <class InputCollection1, class InputCollection2>
2920 + void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
2921  
2922 +  bool sameObjects = false;
2923 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
2924  
2925 +  int pairCounter = 0;
2926 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
2927 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
2928 +
2929 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
2930 +
2931 +      //only take objects which have passed all cuts and pairs which have passed all cuts
2932 +      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
2933 +      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
2934 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
2935 +
2936 +      string currentString = parameters.inputVariables.at(0);
2937 +      string inputVariable = "";
2938 +      string function = "";
2939 +      if(currentString.find("(")==std::string::npos){
2940 +        inputVariable = currentString;// variable to cut on
2941 +      }
2942 +      else{
2943 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("
2944 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
2945 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
2946 +      }
2947 +      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
2948  
2949 < DEFINE_FWK_MODULE(OSUAnalysis);
2949 >      currentString = parameters.inputVariables.at(1);
2950 >      inputVariable = "";
2951 >      function = "";
2952 >      if(currentString.find("(")==std::string::npos){
2953 >        inputVariable = currentString;// variable to cut on
2954 >      }
2955 >      else{
2956 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
2957 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
2958 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
2959 >      }
2960 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
2961 >
2962 >
2963 >      histo->Fill(valueX,valueY,scaleFactor);
2964  
2965 +      pairCounter++;
2966  
2967 +    }
2968 +  }
2969 +
2970 + }
2971 +
2972 +
2973 + template <class InputObject>
2974 + int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
2975 +
2976 +  int bestMatchIndex = -1;
2977 +  double bestMatchDeltaR = 999;
2978 +
2979 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
2980 +
2981 +    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
2982 +    if(currentDeltaR > 0.05) continue;
2983 + //     cout << std::setprecision(3) << std::setw(20)
2984 + //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
2985 + //          << std::setw(20)
2986 + //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
2987 + //          << std::setw(20)
2988 + //          << "\tdeltaR = " << currentDeltaR
2989 + //          << std::setprecision(1)
2990 + //          << std::setw(20)
2991 + //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
2992 + //          << std::setw(20)
2993 + //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
2994 + //          << std::setw(20)
2995 + //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
2996 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
2997 +      bestMatchIndex = mcparticle - mcparticles->begin();
2998 +      bestMatchDeltaR = currentDeltaR;
2999 +    }
3000 +
3001 +  }
3002 + //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
3003 + //   else cout << "no match found..." << endl;
3004 +  return bestMatchIndex;
3005 +
3006 + }
3007 +
3008 +
3009 + int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
3010 +
3011 +  int bestMatchIndex = -1;
3012 +  double bestMatchDeltaR = 999;
3013 +
3014 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3015 +
3016 +    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
3017 +
3018 +    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
3019 +    if(currentDeltaR > 0.05) continue;
3020 +
3021 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
3022 +      bestMatchIndex = mcparticle - mcparticles->begin();
3023 +      bestMatchDeltaR = currentDeltaR;
3024 +    }
3025 +
3026 +  }
3027 +
3028 +  return bestMatchIndex;
3029 + }
3030 +
3031 +
3032 + // bin      particle type
3033 + // ---      -------------
3034 + //  0        unmatched
3035 + //  1        u
3036 + //  2        d
3037 + //  3        s
3038 + //  4        c
3039 + //  5        b
3040 + //  6        t
3041 + //  7        e
3042 + //  8        mu
3043 + //  9        tau
3044 + // 10        nu
3045 + // 11        g
3046 + // 12        gamma
3047 + // 13        Z
3048 + // 14        W
3049 + // 15        light meson
3050 + // 16        K meson
3051 + // 17        D meson
3052 + // 18        B meson
3053 + // 19        light baryon
3054 + // 20        strange baryon
3055 + // 21        charm baryon
3056 + // 22        bottom baryon
3057 + // 23        other
3058 +
3059 + int OSUAnalysis::getPdgIdBinValue(int pdgId){
3060 +
3061 +  int binValue = -999;
3062 +  int absPdgId = fabs(pdgId);
3063 +  if(pdgId == -1) binValue = 0;
3064 +  else if(absPdgId <= 6 ) binValue = absPdgId;
3065 +  else if(absPdgId == 11 ) binValue = 7;
3066 +  else if(absPdgId == 13 ) binValue = 8;
3067 +  else if(absPdgId == 15 ) binValue = 9;
3068 +  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
3069 +  else if(absPdgId == 21 ) binValue = 11;
3070 +  else if(absPdgId == 22 ) binValue = 12;
3071 +  else if(absPdgId == 23 ) binValue = 13;
3072 +  else if(absPdgId == 24 ) binValue = 14;
3073 +  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
3074 +  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
3075 +  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
3076 +  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
3077 +  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
3078 +  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
3079 +  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
3080 +  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
3081 +
3082 +  else binValue = 23;
3083 +
3084 +  return binValue;
3085 +
3086 + }
3087 +
3088 + const BNprimaryvertex *
3089 + OSUAnalysis::chosenVertex ()
3090 + {
3091 +  const BNprimaryvertex *chosenVertex = 0;
3092 +  if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
3093 +    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
3094 +                               cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
3095 +    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
3096 +      if(!vertexFlags.at(vertexIndex)) continue;
3097 +      chosenVertex = & primaryvertexs->at(vertexIndex);
3098 +      break;
3099 +    }
3100 +  }
3101 +  else {
3102 +    chosenVertex = &primaryvertexs->at(0);
3103 +  }
3104 +
3105 +  return chosenVertex;
3106 + }
3107 +
3108 + const BNmet *
3109 + OSUAnalysis::chosenMET ()
3110 + {
3111 +  const BNmet *chosenMET = 0;
3112 +  if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
3113 +    vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
3114 +                            cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
3115 +    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
3116 +      if(!metFlags.at(metIndex)) continue;
3117 +      chosenMET = & mets->at(metIndex);
3118 +      break;
3119 +    }
3120 +  }
3121 +  else {
3122 +    chosenMET = &mets->at(0);
3123 +  }
3124 +
3125 +  return chosenMET;
3126 + }
3127 +
3128 + const BNelectron *
3129 + OSUAnalysis::chosenElectron ()
3130 + {
3131 +  const BNelectron *chosenElectron = 0;
3132 +  if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
3133 +    vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
3134 +                                 cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
3135 +    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
3136 +      if(!electronFlags.at(electronIndex)) continue;
3137 +      chosenElectron = & electrons->at(electronIndex);
3138 +      break;
3139 +    }
3140 +  }
3141 +  else {
3142 +    chosenElectron = &electrons->at(0);
3143 +  }
3144 +
3145 +  return chosenElectron;
3146 + }
3147 +
3148 + const BNmuon *
3149 + OSUAnalysis::chosenMuon ()
3150 + {
3151 +  const BNmuon *chosenMuon = 0;
3152 +  if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
3153 +    vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
3154 +                             cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
3155 +    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
3156 +      if(!muonFlags.at(muonIndex)) continue;
3157 +      chosenMuon = & muons->at(muonIndex);
3158 +      break;
3159 +    }
3160 +  }
3161 +  else {
3162 +    chosenMuon = &muons->at(0);
3163 +  }
3164 +
3165 +  return chosenMuon;
3166 + }
3167 +
3168 +
3169 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines