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

Comparing UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc (file contents):
Revision 1.12 by ahart, Fri Feb 8 11:07:51 2013 UTC vs.
Revision 1.29 by lantonel, Thu Mar 14 13:43:25 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 >  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
22 >  dataset_ (cfg.getParameter<std::string> ("dataset")),
23 >  datasetType_ (cfg.getParameter<std::string> ("datasetType")),
24    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
25 <
26 <  histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets"))
25 >  histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
26 >  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents"))
27  
28   {
29  
27
30    TH1::SetDefaultSumw2 ();
31 <  TH2::SetDefaultSumw2 ();
31 >
32 >  //create pile-up reweighting object, if necessary
33 >  if(datasetType_ != "data") puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
34  
35    // Construct Cutflow Objects. These store the results of cut decisions and
36    // handle filling cut flow histograms.
# Line 34 | Line 38 | OSUAnalysis::OSUAnalysis (const edm::Par
38    std::vector<TFileDirectory> directories;
39  
40    //always get vertex collection so we can assign the primary vertex in the event
41 <  allNecessaryObjects.push_back("primaryvertexs");
41 >  objectsToGet.push_back("primaryvertexs");
42 >
43 >  //always make the plot of number of primary verticex (to check pile-up reweighting)
44 >  objectsToPlot.push_back("primaryvertexs");
45 >
46 >  //always get the MC particles to do GEN-matching
47 >  objectsToGet.push_back("mcparticles");
48  
49 +  //always get the event collection to do pile-up reweighting
50 +  objectsToGet.push_back("events");
51  
52    //parse the histogram definitions
53    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
54  
55 <    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string>("inputCollection");
56 <    objectsToPlot.push_back(tempInputCollection);
57 <    allNecessaryObjects.push_back(tempInputCollection);
55 >    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
56 >    if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
57 >    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
58 >      objectsToGet.push_back(tempInputCollection);
59 >      objectsToPlot.push_back(tempInputCollection);
60 >      objectsToCut.push_back(tempInputCollection);
61 >    }
62 >    else{//pair of objects, need to add them both to the things to objectsToGet
63 >      int dashIndex = tempInputCollection.find("-");
64 >      int spaceIndex = tempInputCollection.find(" ");
65 >      int secondWordLength = spaceIndex - dashIndex;
66 >      objectsToGet.push_back(tempInputCollection);
67 >      objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
68 >      objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
69 >      objectsToPlot.push_back(tempInputCollection);
70 >      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
71 >      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
72 >      objectsToCut.push_back(tempInputCollection);
73 >      objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
74 >      objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
75 >
76 >      }
77 >
78      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
79      
80      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
# Line 53 | Line 85 | OSUAnalysis::OSUAnalysis (const edm::Par
85        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
86        tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
87        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
56      if(histogramList_.at(currentHistogram).exists("function"))
57        tempHistogram.function = histogramList_.at(currentHistogram).getParameter<string>("function");
58      else
59        tempHistogram.function = "";
88        
89        histograms.push_back(tempHistogram);
90  
91      }
92    }
93 +  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
94 +  sort( objectsToPlot.begin(), objectsToPlot.end() );
95 +  objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
96 +
97 +
98 +
99 +  //add histograms with the gen-matched id, mother id, and grandmother id
100 +  for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
101 +
102 +    string currentObject = objectsToPlot.at(currentObjectIndex);
103 +    if(currentObject != "muons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
104 +
105 +    histogram tempIdHisto;
106 +    histogram tempMomIdHisto;
107 +    histogram tempGmaIdHisto;
108 +
109 +    tempIdHisto.inputCollection = currentObject;
110 +    tempMomIdHisto.inputCollection = currentObject;
111 +    tempGmaIdHisto.inputCollection = currentObject;
112 +
113 +    currentObject = currentObject.substr(0, currentObject.size()-1);
114 +    tempIdHisto.name = currentObject+"GenMatchId";
115 +    tempMomIdHisto.name = currentObject+"GenMatchMotherId";
116 +    tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
117 +
118 +    currentObject.at(0) = toupper(currentObject.at(0));
119 +    tempIdHisto.title = currentObject+" Gen-matched Particle";
120 +    tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
121 +    tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
122 +
123 +    int maxNum = 24;
124 +    vector<double> binVector;
125 +    binVector.push_back(maxNum);
126 +    binVector.push_back(0);
127 +    binVector.push_back(maxNum);
128 +
129 +    tempIdHisto.bins = binVector;
130 +    tempIdHisto.inputVariables.push_back("genMatchedId");
131 +    tempMomIdHisto.bins = binVector;
132 +    tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
133 +    tempGmaIdHisto.bins = binVector;
134 +    tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
135 +
136 +    histograms.push_back(tempIdHisto);
137 +    histograms.push_back(tempMomIdHisto);
138 +    histograms.push_back(tempGmaIdHisto);
139 +    
140 +  }
141  
142  
143  
# Line 82 | Line 158 | OSUAnalysis::OSUAnalysis (const edm::Par
158        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
159        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
160          tempChannel.triggers.push_back(triggerNames.at(trigger));
161 <      allNecessaryObjects.push_back("triggers");
161 >      objectsToGet.push_back("triggers");
162      }
163  
164  
165  
166 +
167      //create cutFlow for this channel
168      cutFlows_.push_back (new CutFlow (fs_, channelName));
169  
# Line 99 | Line 176 | OSUAnalysis::OSUAnalysis (const edm::Par
176      std::map<std::string, TH2D*> twoDhistoMap;
177      twoDHists_.push_back(twoDhistoMap);
178  
179 +
180      //book all histograms included in the configuration
181      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
182        histogram currentHistogram = histograms.at(currentHistogramIndex);
183        int numBinsElements = currentHistogram.bins.size();
184        int numInputVariables = currentHistogram.inputVariables.size();
185 +
186        if(numBinsElements != 3 && numBinsElements !=6) {
187          std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
188          exit(0);
# Line 112 | Line 191 | OSUAnalysis::OSUAnalysis (const edm::Par
191          std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
192          exit(0);
193        }
194 <      else if(numBinsElements == 3)
194 >      else if(numBinsElements == 3){
195          oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
196 <      else if(numBinsElements == 6)
196 >      }
197 >      else if(numBinsElements == 6){
198          twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2),currentHistogram.bins.at(3),currentHistogram.bins.at(4),currentHistogram.bins.at(5));
199  
200 +      }
201 +
202 +
203 +      if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
204  
205 + // bin      particle type
206 + // ---      -------------
207 + //  0        unmatched
208 + //  1        u
209 + //  2        d
210 + //  3        s
211 + //  4        c
212 + //  5        b
213 + //  6        t
214 + //  7        e
215 + //  8        mu
216 + //  9        tau
217 + // 10        nu
218 + // 11        g
219 + // 12        gamma
220 + // 13        Z
221 + // 14        W
222 + // 15        light meson
223 + // 16        K meson
224 + // 17        D meson
225 + // 18        B meson
226 + // 19        light baryon
227 + // 20        strange baryon
228 + // 21        charm baryon
229 + // 22        bottom baryon
230 + // 23        other
231 +
232 +      vector<TString> labelArray;
233 +      labelArray.push_back("unmatched");
234 +      labelArray.push_back("u");
235 +      labelArray.push_back("d");
236 +      labelArray.push_back("s");
237 +      labelArray.push_back("c");
238 +      labelArray.push_back("b");
239 +      labelArray.push_back("t");
240 +      labelArray.push_back("e");
241 +      labelArray.push_back("#mu");
242 +      labelArray.push_back("#tau");
243 +      labelArray.push_back("#nu");
244 +      labelArray.push_back("g");
245 +      labelArray.push_back("#gamma");
246 +      labelArray.push_back("Z");
247 +      labelArray.push_back("W");
248 +      labelArray.push_back("light meson");
249 +      labelArray.push_back("K meson");
250 +      labelArray.push_back("D meson");
251 +      labelArray.push_back("B meson");
252 +      labelArray.push_back("light baryon");
253 +      labelArray.push_back("strange baryon");
254 +      labelArray.push_back("charm baryon");
255 +      labelArray.push_back("bottom baryon");
256 +      labelArray.push_back("other");
257 +
258 +      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
259 +        oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
260 +      }
261      }
262 +
263      //book a histogram for the number of each object type to be plotted
264 +
265      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
266        string currentObject = objectsToPlot.at(currentObjectIndex);
267        int maxNum = 10;
268        if(currentObject == "mcparticles") maxNum = 50;
269 <      currentObject[0] = toupper(currentObject[0]);
269 >      else if(currentObject == "primaryvertexs") maxNum = 50;
270 >      else if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
271 >      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
272 >      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
273 >
274 >      currentObject.at(0) = toupper(currentObject.at(0));
275        string histoName = "num" + currentObject;
276 <      oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
276 >
277 >      if(histoName == "numPrimaryvertexs"){
278 >        string newHistoName = histoName + "BeforePileupCorrection";
279 >        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);    
280 >        newHistoName = histoName + "AfterPileupCorrection";
281 >        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
282 >      }
283 >      else
284 >        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
285      }
286  
287  
288 +    
289 +
290 +
291      //get list of cuts for this channel
292      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
293  
294      //loop over and parse all cuts
295      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
138
296        cut tempCut;
297 <     //store input collection for cut
298 <      string inputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
299 <      tempCut.inputCollection = inputCollection;
300 <      allNecessaryObjects.push_back(inputCollection);
297 >      //store input collection for cut
298 >      string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
299 >      tempCut.inputCollection = tempInputCollection;
300 >      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
301 >        objectsToGet.push_back(tempInputCollection);
302 >        objectsToCut.push_back(tempInputCollection);
303 >      }
304 >      else{//pair of objects, need to add them both to the things to objectsToGet
305 >        int dashIndex = tempInputCollection.find("-");
306 >        int spaceIndex = tempInputCollection.find(" ");
307 >        int secondWordLength = spaceIndex - dashIndex;
308 >        objectsToGet.push_back(tempInputCollection);
309 >        objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
310 >        objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
311 >        objectsToCut.push_back(tempInputCollection);
312 >        objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
313 >        objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
314 >
315 >      }
316 >
317 >
318  
319        //split cut string into parts and store them
320        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
321        std::vector<string> cutStringVector = splitString(cutString);
322 <      if(cutStringVector.size()!=3){
323 <        std::cout << "Error: Didn't find three elements in the following cut string: '" <<cutString << "'\n";
322 >      if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
323 >        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
324          exit(0);
325        }
326 <
327 <      tempCut.variable = cutStringVector.at(0);// variable to cut on
328 <      tempCut.comparativeOperator = cutStringVector.at(1);// comparison to make
329 <      tempCut.cutValue = atof(cutStringVector.at(2).c_str());// threshold value to pass cut
326 >      tempCut.numSubcuts = (cutStringVector.size()+1)/4;
327 >      for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
328 >        int indexOffset = 4 * subcutIndex;
329 >        string currentVariableString = cutStringVector.at(indexOffset);
330 >        if(currentVariableString.find("(")==std::string::npos){
331 >          tempCut.functions.push_back("");//no function was specified
332 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
333 >        }
334 >        else{
335 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
336 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
337 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
338 >        }
339 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
340 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
341 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
342 >      }
343  
344        //get number of objects required to pass cut for event to pass
345        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
# Line 162 | Line 349 | OSUAnalysis::OSUAnalysis (const edm::Par
349          exit(0);
350        }
351  
165      // determine number required if comparison contains "="
352        int numberRequiredInt = atoi(numberRequiredVector.at(1).c_str());
167      if(numberRequiredVector.at(0) == ">") numberRequiredInt++;
168      else if(numberRequiredVector.at(0) == "<") numberRequiredInt--;
169
353        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
354        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
355  
356 <      if(cuts_.at(currentCut).exists("function")){
174 <        tempCut.function = cuts_.at(currentCut).getParameter<string> ("function");
175 <      }
176 <      else tempCut.function = "";
356 >
357        string tempCutName;
358        if(cuts_.at(currentCut).exists("alias")){
359          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
# Line 181 | Line 361 | OSUAnalysis::OSUAnalysis (const edm::Par
361        else{
362          //construct string for cutflow table
363          bool plural = numberRequiredInt != 1;
364 <        string collectionString = plural ? inputCollection : inputCollection.substr(0, inputCollection.size()-1);
364 >        string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
365          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
366          tempCutName = cutName;
367        }
# Line 194 | Line 374 | OSUAnalysis::OSUAnalysis (const edm::Par
374  
375      }//end loop over cuts
376  
197
377      channels.push_back(tempChannel);
378      tempChannel.cuts.clear();
379  
380    }//end loop over channels
381  
382  
383 <
384 <
385 <  //make unique vector of objects we need to cut on (so we make sure to get them from the event)
386 <  sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
387 <  allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
383 >  //make unique vector of objects we need to get from the event
384 >  sort( objectsToGet.begin(), objectsToGet.end() );
385 >  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
386 >  //make unique vector of objects we need to cut on
387 >  sort( objectsToCut.begin(), objectsToCut.end() );
388 >  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
389  
390  
391   }
# Line 223 | Line 403 | void
403   OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
404   {
405  
226
406    // Retrieve necessary collections from the event.
407 <  edm::Handle<BNtriggerCollection> triggers;
408 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
407 >
408 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
409      event.getByLabel (triggers_, triggers);
410  
411 <  edm::Handle<BNjetCollection> jets;
233 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())
411 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
412      event.getByLabel (jets_, jets);
413  
414 <  edm::Handle<BNmuonCollection> muons;
237 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())
414 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
415      event.getByLabel (muons_, muons);
416  
417 <  edm::Handle<BNelectronCollection> electrons;
241 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())
417 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
418      event.getByLabel (electrons_, electrons);
419  
420 <  edm::Handle<BNeventCollection> events;
245 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())
420 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
421      event.getByLabel (events_, events);
422  
423 <  edm::Handle<BNtauCollection> taus;
249 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())
423 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
424      event.getByLabel (taus_, taus);
425  
426 <  edm::Handle<BNmetCollection> mets;
253 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())
426 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
427      event.getByLabel (mets_, mets);
428  
429 <  edm::Handle<BNtrackCollection> tracks;
257 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())
429 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
430      event.getByLabel (tracks_, tracks);
431  
432 <  edm::Handle<BNgenjetCollection> genjets;
261 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())
432 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
433      event.getByLabel (genjets_, genjets);
434  
435 <  edm::Handle<BNmcparticleCollection> mcparticles;
265 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())
435 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
436      event.getByLabel (mcparticles_, mcparticles);
437  
438 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
269 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())
438 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
439      event.getByLabel (primaryvertexs_, primaryvertexs);
440  
441 <  edm::Handle<BNbxlumiCollection> bxlumis;
273 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())
441 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
442      event.getByLabel (bxlumis_, bxlumis);
443  
444 <  edm::Handle<BNphotonCollection> photons;
277 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())
444 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
445      event.getByLabel (photons_, photons);
446  
447 <  edm::Handle<BNsuperclusterCollection> superclusters;
281 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())
447 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
448      event.getByLabel (superclusters_, superclusters);
449  
450  
451 +  //get pile-up event weight
452 +  double puScaleFactor = 1.00;
453 +  if(datasetType_ != "data"){
454 +    puScaleFactor = puWeight_->at (events->at (0).numTruePV);
455 +    //cout << puScaleFactor << endl;
456 +  }
457 +
458 +
459 +
460    //loop over all channels
461  
462    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
# Line 298 | Line 473 | OSUAnalysis::analyze (const edm::Event &
473      }
474  
475      //loop over all cuts
476 +
477 +
478 +
479      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
480        cut currentCut = currentChannel.cuts.at(currentCutIndex);
481  
482 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
482 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
483 >        string currentObject = objectsToCut.at(currentObjectIndex);
484  
485 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
485 >        //initialize maps to get ready to set cuts
486          individualFlags[currentObject].push_back (vector<bool> ());
487          cumulativeFlags[currentObject].push_back (vector<bool> ());
488  
489 +      }
490 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
491 +        string currentObject = objectsToCut.at(currentObjectIndex);
492 +
493 +        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
494 +
495          if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
496          else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
497          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
# Line 321 | Line 506 | OSUAnalysis::analyze (const edm::Event &
506          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
507          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
508  
509 +        
510 +        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
511 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
512 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
513 +                                                                   "muon-muon pairs");
514 +        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
515 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
516 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
517 +                                                                           "electron-electron pairs");
518 +        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
519 +                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
520 +                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
521 +                                                                       "electron-muon pairs");
522 +
523  
524        }
525  
# Line 329 | Line 528 | OSUAnalysis::analyze (const edm::Event &
528      }//end loop over all cuts
529  
530  
332
333
531      //use cumulative flags to apply cuts at event level
532  
533      bool eventPassedAllCuts = true;
# Line 339 | Line 536 | OSUAnalysis::analyze (const edm::Event &
536      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
537  
538  
539 +
540      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
541  
542        //loop over all objects and count how many passed the cumulative selection up to this point
543        cut currentCut = currentChannel.cuts.at(currentCutIndex);
544        int numberPassing = 0;
545  
546 <      for (uint object = 0; object != cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).size() ; object++)
547 <          if(cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).at(object)) numberPassing++;
548 <
546 >      for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
547 >          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
548 >      }
549  
550        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
551        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
# Line 356 | Line 554 | OSUAnalysis::analyze (const edm::Event &
554  
555      }
556  
557 <    cutFlows_.at(currentChannelIndex)->fillCutFlow();
557 >    cutFlows_.at(currentChannelIndex)->fillCutFlow(puScaleFactor);
558 >
559  
560  
561      if(!eventPassedAllCuts)continue;
562  
563  
564 +    
565 +
566      //set position of primary vertex in event, in order to calculate quantities relative to it
567 <    primaryVertex_ = 0;
568 <    vector<bool> vertexFlags = cumulativeFlags["primaryvertexs"].back();
569 <    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
570 <      if(!vertexFlags.at(vertexIndex)) continue;
571 <      primaryVertex_ = new BNprimaryvertex (primaryvertexs->at (vertexIndex));
572 <      break;
567 >    if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
568 >      vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back();
569 >      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
570 >        if(!vertexFlags.at(vertexIndex)) continue;
571 >        chosenPrimaryVertex = & primaryvertexs->at(vertexIndex);
572 >        break;
573 >      }
574 >    }
575 >    else {
576 >      chosenPrimaryVertex = & primaryvertexs->at(0);
577      }
578  
579  
# Line 380 | Line 585 | OSUAnalysis::analyze (const edm::Event &
585        if(currentHistogram.inputVariables.size() == 1){
586          TH1D* histo;
587          histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
588 <        if(currentHistogram.inputCollection == "jets") fillHistogram(histo,currentHistogram,jets.product());
589 <        else if(currentHistogram.inputCollection == "muons") fillHistogram(histo,currentHistogram,muons.product());
590 <        else if(currentHistogram.inputCollection == "electrons") fillHistogram(histo,currentHistogram,electrons.product());
591 <        else if(currentHistogram.inputCollection == "events") fillHistogram(histo,currentHistogram,events.product());
592 <        else if(currentHistogram.inputCollection == "taus") fillHistogram(histo,currentHistogram,taus.product());
593 <        else if(currentHistogram.inputCollection == "mets") fillHistogram(histo,currentHistogram,mets.product());
594 <        else if(currentHistogram.inputCollection == "tracks") fillHistogram(histo,currentHistogram,tracks.product());
595 <        else if(currentHistogram.inputCollection == "genjets") fillHistogram(histo,currentHistogram,genjets.product());
596 <        else if(currentHistogram.inputCollection == "mcparticles") fillHistogram(histo,currentHistogram,mcparticles.product());
597 <        else if(currentHistogram.inputCollection == "primaryvertexs") fillHistogram(histo,currentHistogram,primaryvertexs.product());
598 <        else if(currentHistogram.inputCollection == "bxlumis") fillHistogram(histo,currentHistogram,bxlumis.product());
599 <        else if(currentHistogram.inputCollection == "photons") fillHistogram(histo,currentHistogram,photons.product());
600 <        else if(currentHistogram.inputCollection == "superclusters") fillHistogram(histo,currentHistogram,superclusters.product());
588 >
589 >
590 >
591 >        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
592 >        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
593 >        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
594 >                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
595 >                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
596 >        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
597 >        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
598 >                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
599 >                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
600 >        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
601 >                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
602 >                                                                                              cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
603 >        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
604 >        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
605 >        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
606 >        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
607 >        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
608 >        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
609 >        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
610 >        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
611 >        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
612 >        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
613        }
614        else if(currentHistogram.inputVariables.size() == 2){
615          TH2D* histo;
616          histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
617 <        if(currentHistogram.inputCollection == "jets") fillHistogram(histo,currentHistogram,jets.product());
618 <        else if(currentHistogram.inputCollection == "muons") fillHistogram(histo,currentHistogram,muons.product());
619 <        else if(currentHistogram.inputCollection == "electrons") fillHistogram(histo,currentHistogram,electrons.product());
620 <        else if(currentHistogram.inputCollection == "events") fillHistogram(histo,currentHistogram,events.product());
621 <        else if(currentHistogram.inputCollection == "taus") fillHistogram(histo,currentHistogram,taus.product());
622 <        else if(currentHistogram.inputCollection == "mets") fillHistogram(histo,currentHistogram,mets.product());
623 <        else if(currentHistogram.inputCollection == "tracks") fillHistogram(histo,currentHistogram,tracks.product());
624 <        else if(currentHistogram.inputCollection == "genjets") fillHistogram(histo,currentHistogram,genjets.product());
625 <        else if(currentHistogram.inputCollection == "mcparticles") fillHistogram(histo,currentHistogram,mcparticles.product());
626 <        else if(currentHistogram.inputCollection == "primaryvertexs") fillHistogram(histo,currentHistogram,primaryvertexs.product());
627 <        else if(currentHistogram.inputCollection == "bxlumis") fillHistogram(histo,currentHistogram,bxlumis.product());
628 <        else if(currentHistogram.inputCollection == "photons") fillHistogram(histo,currentHistogram,photons.product());
629 <        else if(currentHistogram.inputCollection == "superclusters") fillHistogram(histo,currentHistogram,superclusters.product());
617 >
618 >
619 >
620 >        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
621 >        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
622 >        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
623 >                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
624 >                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
625 >        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
626 >        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
627 >                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
628 >                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
629 >        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
630 >                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
631 >                                                                                               cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
632 >        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
633 >        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
634 >        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
635 >        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
636 >        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
637 >        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
638 >        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
639 >        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
640 >        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
641 >        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
642        }
643      }
644  
416
645      //fills histograms with the sizes of collections
646      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
647        string currentObject = objectsToPlot.at(currentObjectIndex);
648 <      string tempCurrentObject = currentObject;
649 <      tempCurrentObject[0] = toupper(tempCurrentObject[0]);
648 >
649 >      string objectToPlot = "";
650 >
651 >      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
652 >      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
653 >      else if(currentObject == "electron-muon pairs") objectToPlot = "electronMuonPairs";
654 >      else objectToPlot = currentObject;
655 >      string tempCurrentObject = objectToPlot;
656 >      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
657        string histoName = "num" + tempCurrentObject;
658  
659 <      if(currentObject == "jets") oneDHists_.at(currentChannelIndex)[histoName]->Fill(jets->size());
660 <      else if(currentObject == "muons") oneDHists_.at(currentChannelIndex)[histoName]->Fill(muons->size());
661 <      else if(currentObject == "electrons") oneDHists_.at(currentChannelIndex)[histoName]->Fill(electrons->size());
662 <      else if(currentObject == "events") oneDHists_.at(currentChannelIndex)[histoName]->Fill(events->size());
663 <      else if(currentObject == "taus") oneDHists_.at(currentChannelIndex)[histoName]->Fill(taus->size());
664 <      else if(currentObject == "mets") oneDHists_.at(currentChannelIndex)[histoName]->Fill(mets->size());
665 <      else if(currentObject == "tracks") oneDHists_.at(currentChannelIndex)[histoName]->Fill(tracks->size());
666 <      else if(currentObject == "genjets") oneDHists_.at(currentChannelIndex)[histoName]->Fill(genjets->size());
667 <      else if(currentObject == "mcparticles") oneDHists_.at(currentChannelIndex)[histoName]->Fill(mcparticles->size());
668 <      else if(currentObject == "primaryvertexs") oneDHists_.at(currentChannelIndex)[histoName]->Fill(primaryvertexs->size());
669 <      else if(currentObject == "bxlumis") oneDHists_.at(currentChannelIndex)[histoName]->Fill(bxlumis->size());
670 <      else if(currentObject == "photons") oneDHists_.at(currentChannelIndex)[histoName]->Fill(photons->size());
671 <      else if(currentObject == "superclusters") oneDHists_.at(currentChannelIndex)[histoName]->Fill(superclusters->size());
659 >
660 >
661 >
662 >      //set position of primary vertex in event, in order to calculate quantities relative to it
663 >      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
664 >        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
665 >        int numToPlot = 0;
666 >        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
667 >          if(lastCutFlags.at(currentFlag)) numToPlot++;
668 >        }
669 >        if(objectToPlot == "primaryvertexs"){
670 >          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
671 >          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),puScaleFactor);
672 >        }
673 >        else
674 >          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,puScaleFactor);        
675 >      }
676 >      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),puScaleFactor);
677 >      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),puScaleFactor);
678 >      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,puScaleFactor);
679 >      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),puScaleFactor);
680 >      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,puScaleFactor);
681 >      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),puScaleFactor);
682 >      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),puScaleFactor);
683 >      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),puScaleFactor);
684 >      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),puScaleFactor);
685 >      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),puScaleFactor);
686 >      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),puScaleFactor);
687 >      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),puScaleFactor);
688 >      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),puScaleFactor);
689 >      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),puScaleFactor);
690 >      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),puScaleFactor);
691 >      else if(objectToPlot == "primaryvertexs"){
692 >        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
693 >        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),puScaleFactor);
694 >      }
695  
696      }
697 +
698 +
699 +
700 +
701    } //end loop over channel
702  
703 <  masterCutFlow_->fillCutFlow();
703 >  masterCutFlow_->fillCutFlow(puScaleFactor);
704 >
705  
706  
707   }
# Line 453 | Line 716 | OSUAnalysis::evaluateComparison (double
716    else if(comparison == "<")  return testValue <  cutValue;
717    else if(comparison == "<=") return testValue <= cutValue;
718    else if(comparison == "==") return testValue == cutValue;
719 +  else if(comparison == "=") return testValue == cutValue;
720    else if(comparison == "!=") return testValue != cutValue;
721    else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
722  
# Line 635 | Line 899 | OSUAnalysis::valueLookup (const BNmuon*
899    else if(variable == "ecalIso") value = object->ecalIso;
900    else if(variable == "hcalIso") value = object->hcalIso;
901    else if(variable == "caloIso") value = object->caloIso;
902 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
902 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
903    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
904    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
905    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 774 | Line 1038 | OSUAnalysis::valueLookup (const BNmuon*
1038    else if(variable == "time_ndof") value = object->time_ndof;
1039  
1040    //user-defined variables
1041 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1042 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1043 <  else if(variable == "detIso") value = (object->trackIso + object->caloIso) / object->pt;
1041 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenPrimaryVertex->xError, chosenPrimaryVertex->yError));
1042 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenPrimaryVertex->xError, chosenPrimaryVertex->yError));
1043 >  else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1044    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1045    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1046 +
1047 +
1048 +
1049 +  else if(variable == "correctedD0VertexInEBPlus"){
1050 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1051 +    else value = -999;
1052 +  }
1053 +  else if(variable == "correctedD0VertexOutEBPlus"){
1054 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1055 +    else value = -999;
1056 +  }
1057 +  else if(variable == "correctedD0VertexEEPlus"){
1058 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1059 +    else value = -999;
1060 +  }
1061 +
1062 +  else if(variable == "correctedD0BeamspotInEBPlus"){
1063 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1064 +    else value = -999;
1065 +  }
1066 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
1067 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1068 +    else value = -999;
1069 +  }
1070 +  else if(variable == "correctedD0BeamspotEEPlus"){
1071 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1072 +    else value = -999;
1073 +  }
1074 +
1075 +  else if(variable == "correctedD0VertexInEBMinus"){
1076 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1077 +    else value = -999;
1078 +  }
1079 +  else if(variable == "correctedD0VertexOutEBMinus"){
1080 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1081 +    else value = -999;
1082 +  }
1083 +  else if(variable == "correctedD0VertexEEMinus"){
1084 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1085 +    else value = -999;
1086 +  }
1087 +
1088 +  else if(variable == "correctedD0BeamspotInEBMinus"){
1089 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1090 +    else value = -999;
1091 +  }
1092 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
1093 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1094 +    else value = -999;
1095 +  }
1096 +  else if(variable == "correctedD0BeamspotEEMinus"){
1097 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1098 +    else value = -999;
1099 +  }
1100 +
1101 +
1102 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1103 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1104 +    else value = -999;
1105 +  }
1106 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1107 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1108 +    else value = -999;
1109 +  }
1110 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
1111 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1112 +    else value = -999;
1113 +  }
1114 +
1115 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1116 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1117 +    else value = -999;
1118 +  }
1119 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1120 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1121 +    else value = -999;
1122 +  }
1123 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1124 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1125 +    else value = -999;
1126 +  }
1127 +
1128 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1129 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1130 +    else value = -999;
1131 +  }
1132 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1133 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1134 +    else value = -999;
1135 +  }
1136 +  else if(variable == "correctedD0VertexEENegativeCharge"){
1137 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1138 +    else value = -999;
1139 +  }
1140 +
1141 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1142 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1143 +    else value = -999;
1144 +  }
1145 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1146 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1147 +    else value = -999;
1148 +  }
1149 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1150 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1151 +    else value = -999;
1152 +  }
1153 +
1154 +
1155    else if(variable == "tightID") {
1156      value = object->isGlobalMuon > 0            \
1157        && object->isPFMuon > 0                   \
# Line 787 | Line 1160 | OSUAnalysis::valueLookup (const BNmuon*
1160        && object->numberOfMatchedStations > 1    \
1161        && fabs(object->correctedD0Vertex) < 0.2  \
1162        && fabs(object->correctedDZ) < 0.5        \
1163 <      && object->numberOfValidPixelHits > 0     \
1163 >      && object->numberOfValidPixelHits > 0             \
1164        && object->numberOfLayersWithMeasurement > 5;
792    
793
1165    }
1166    else if(variable == "tightIDdisplaced"){
1167      value = object->isGlobalMuon > 0            \
797      && object->isPFMuon > 0                   \
1168        && object->normalizedChi2 < 10            \
1169        && object->numberOfValidMuonHits > 0      \
1170        && object->numberOfMatchedStations > 1    \
# Line 802 | Line 1172 | OSUAnalysis::valueLookup (const BNmuon*
1172        && object->numberOfLayersWithMeasurement > 5;
1173    }
1174  
1175 +
1176 +
1177 +  else if(variable == "genMatchedId"){
1178 +    int index = getGenMatchedParticleIndex(object);
1179 +    if(index == -1) value = 0;
1180 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
1181 +  }
1182 +  else if(variable == "genMatchedMotherId"){
1183 +    int index = getGenMatchedParticleIndex(object);
1184 +    if(index == -1) value = 0;
1185 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1186 +  }
1187 +  else if(variable == "genMatchedGrandmotherId"){
1188 +    int index = getGenMatchedParticleIndex(object);
1189 +    if(index == -1) value = 0;
1190 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1191 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1192 +      if(motherIndex == -1) value = 0;
1193 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1194 +    }
1195 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1196 +  }
1197 +
1198 +
1199 +
1200    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1201  
1202    value = applyFunction(function, value);
# Line 972 | Line 1367 | OSUAnalysis::valueLookup (const BNelectr
1367    else if(variable == "passConvVeto") value = object->passConvVeto;
1368  
1369    //user-defined variables
1370 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1371 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1372 <  else if(variable == "detIso") value = (object->trackIso + object->caloIso) / object->pt;
1370 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenPrimaryVertex->xError, chosenPrimaryVertex->yError));
1371 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenPrimaryVertex->xError, chosenPrimaryVertex->yError));
1372 >  else if(variable == "detIso") value = (object->trackIso) / object->pt;
1373    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1374  
1375  
1376 +  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
1377 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
1378 +    else value = -999;
1379 +  }
1380 +  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
1381 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
1382 +    else value = -999;
1383 +  }
1384 +
1385 +
1386 +  else if(variable == "correctedD0VertexInEBPlus"){
1387 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1388 +    else value = -999;
1389 +  }
1390 +  else if(variable == "correctedD0VertexOutEBPlus"){
1391 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1392 +    else value = -999;
1393 +  }
1394 +  else if(variable == "correctedD0VertexEEPlus"){
1395 +    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
1396 +    else value = -999;
1397 +  }
1398 +
1399 +  else if(variable == "correctedD0BeamspotInEBPlus"){
1400 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1401 +    else value = -999;
1402 +  }
1403 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
1404 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1405 +    else value = -999;
1406 +  }
1407 +  else if(variable == "correctedD0BeamspotEEPlus"){
1408 +    if(object->isEE && object->eta > 0) value = object->correctedD0;
1409 +    else value = -999;
1410 +  }
1411 +
1412 +  else if(variable == "correctedD0VertexInEBMinus"){
1413 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1414 +    else value = -999;
1415 +  }
1416 +  else if(variable == "correctedD0VertexOutEBMinus"){
1417 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1418 +    else value = -999;
1419 +  }
1420 +  else if(variable == "correctedD0VertexEEMinus"){
1421 +    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
1422 +    else value = -999;
1423 +  }
1424 +
1425 +  else if(variable == "correctedD0BeamspotInEBMinus"){
1426 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1427 +    else value = -999;
1428 +  }
1429 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
1430 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1431 +    else value = -999;
1432 +  }
1433 +  else if(variable == "correctedD0BeamspotEEMinus"){
1434 +    if(object->isEE && object->eta < 0) value = object->correctedD0;
1435 +    else value = -999;
1436 +  }
1437 +
1438 +
1439 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1440 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1441 +    else value = -999;
1442 +  }
1443 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1444 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1445 +    else value = -999;
1446 +  }
1447 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
1448 +    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
1449 +    else value = -999;
1450 +  }
1451 +
1452 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1453 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1454 +    else value = -999;
1455 +  }
1456 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1457 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1458 +    else value = -999;
1459 +  }
1460 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1461 +    if(object->isEE && object->charge > 0) value = object->correctedD0;
1462 +    else value = -999;
1463 +  }
1464 +
1465 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1466 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1467 +    else value = -999;
1468 +  }
1469 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1470 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1471 +    else value = -999;
1472 +  }
1473 +  else if(variable == "correctedD0VertexEENegativeCharge"){
1474 +    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
1475 +    else value = -999;
1476 +  }
1477 +
1478 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1479 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1480 +    else value = -999;
1481 +  }
1482 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1483 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1484 +    else value = -999;
1485 +  }
1486 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1487 +    if(object->isEE && object->charge < 0) value = object->correctedD0;
1488 +    else value = -999;
1489 +  }
1490 +
1491 +
1492 +  else if(variable == "tightIDdisplaced"){
1493 +    if (object->isEB)
1494 +      {
1495 +        value = fabs(object->delEtaIn) < 0.004 \
1496 +          && fabs (object->delPhiIn) < 0.03 \
1497 +          && object->scSigmaIEtaIEta < 0.01 \
1498 +          && object->hadOverEm < 0.12 \
1499 +          && object->absInvEMinusInvPin < 0.05;
1500 +      }
1501 +    else
1502 +      {
1503 +        value = fabs (object->delEtaIn) < 0.005 \
1504 +          && fabs (object->delPhiIn) < 0.02 \
1505 +          && object->scSigmaIEtaIEta < 0.03 \
1506 +          && object->hadOverEm < 0.10 \
1507 +          && object->absInvEMinusInvPin < 0.05;
1508 +      }
1509 +  }
1510 +
1511 +  else if(variable == "genMatchedId"){
1512 +    int index = getGenMatchedParticleIndex(object);
1513 +    if(index == -1) value = 0;
1514 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
1515 +  }
1516 +  else if(variable == "genMatchedMotherId"){
1517 +    int index = getGenMatchedParticleIndex(object);
1518 +    if(index == -1) value = 0;
1519 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1520 +  }
1521 +  else if(variable == "genMatchedGrandmotherId"){
1522 +    int index = getGenMatchedParticleIndex(object);
1523 +    if(index == -1) value = 0;
1524 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1525 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1526 +      if(motherIndex == -1) value = 0;
1527 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1528 +    }
1529 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1530 +  }
1531 +
1532 +
1533 +
1534    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1535  
1536    value = applyFunction(function, value);
# Line 1109 | Line 1662 | OSUAnalysis::valueLookup (const BNtau* o
1662    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
1663  
1664  
1665 +  else if(variable == "genMatchedId"){
1666 +    int index = getGenMatchedParticleIndex(object);
1667 +    if(index == -1) value = 0;
1668 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
1669 +  }
1670 +  else if(variable == "genMatchedMotherId"){
1671 +    int index = getGenMatchedParticleIndex(object);
1672 +    if(index == -1) value = 0;
1673 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1674 +  }
1675 +  else if(variable == "genMatchedGrandmotherId"){
1676 +    int index = getGenMatchedParticleIndex(object);
1677 +    if(index == -1) value = 0;
1678 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1679 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1680 +      if(motherIndex == -1) value = 0;
1681 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1682 +    }
1683 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1684 +  }
1685 +
1686 +
1687    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1688  
1689    value = applyFunction(function, value);
# Line 1192 | Line 1767 | double
1767   OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
1768  
1769    double value = 0.0;
1770 <
1770 >  double pMag = sqrt(object->pt * object->pt +
1771 >                         object->pz * object->pz);
1772 >  
1773    if(variable == "pt") value = object->pt;
1774    else if(variable == "px") value = object->px;
1775    else if(variable == "py") value = object->py;
# Line 1212 | Line 1789 | OSUAnalysis::valueLookup (const BNtrack*
1789    else if(variable == "isHighPurity") value = object->isHighPurity;
1790  
1791  
1792 +  //additional BNs info for disappTrks  
1793 +  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
1794 +  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
1795 +  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
1796 +  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
1797 +  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
1798 +  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
1799 +  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
1800 +  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
1801 +  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
1802 +  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
1803 +  //user defined variables
1804 +  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;
1805 +  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
1806 +  else if(variable == "caloTotDeltaRp5") value =(object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
1807 +  else if(variable == "caloTotDeltaRp5ByP") value =( (object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
1808 +  else if(variable == "isIso") value = getTrkIsIso(object, tracks.product());
1809 +  else if(variable == "isMatchedDeadEcal") value = getTrkIsMatchedDeadEcal(object);
1810 +  else if(variable == "ptErrorByPt") value = (object->ptError/object->pt);
1811 +  else if(variable == "ptError") value = object->ptError;
1812 +  else if(variable == "ptRes") value = getTrkPtRes(object);  
1813 +
1814 +
1815 +  else if(variable == "genMatchedId"){
1816 +    int index = getGenMatchedParticleIndex(object);
1817 +    if(index == -1) value = 0;
1818 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
1819 +  }
1820 +  else if(variable == "genMatchedMotherId"){
1821 +    int index = getGenMatchedParticleIndex(object);
1822 +    if(index == -1) value = 0;
1823 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1824 +  }
1825 +  else if(variable == "genMatchedGrandmotherId"){
1826 +    int index = getGenMatchedParticleIndex(object);
1827 +    if(index == -1) value = 0;
1828 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1829 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1830 +      if(motherIndex == -1) value = 0;
1831 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1832 +    }
1833 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1834 +  }
1835 +
1836 +
1837 +
1838    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1839  
1840    value = applyFunction(function, value);
# Line 1339 | Line 1962 | OSUAnalysis::valueLookup (const BNmcpart
1962  
1963    //user-defined variables
1964    else if (variable == "d0"){
1965 <    double vx = object->vx - primaryVertex_->x,
1966 <      vy = object->vy - primaryVertex_->y,
1965 >    double vx = object->vx - chosenPrimaryVertex->x,
1966 >      vy = object->vy - chosenPrimaryVertex->y,
1967        px = object->px,
1968        py = object->py,
1969        pt = object->pt;
1970      value = (-vx * py + vy * px) / pt;
1971    }
1972    else if (variable == "dz"){
1973 <    double vx = object->vx - primaryVertex_->x,
1974 <      vy = object->vy - primaryVertex_->y,
1975 <      vz = object->vz - primaryVertex_->z,
1973 >    double vx = object->vx - chosenPrimaryVertex->x,
1974 >      vy = object->vy - chosenPrimaryVertex->y,
1975 >      vz = object->vz - chosenPrimaryVertex->z,
1976        px = object->px,
1977        py = object->py,
1978        pz = object->pz,
1979        pt = object->pt;
1980      value = vz - (vx * px + vy * py)/pt * (pz/pt);
1981    }
1982 <
1982 >  else if(variable == "v0"){
1983 >    value = sqrt(object->vx*object->vx + object->vy*object->vy);
1984 >  }
1985 >  else if(variable == "deltaV0"){
1986 >    value = sqrt((object->vx-chosenPrimaryVertex->x)*(object->vx-chosenPrimaryVertex->x) + (object->vy-chosenPrimaryVertex->y)*(object->vy-chosenPrimaryVertex->y));
1987 >  }
1988 >  else if (variable == "deltaVx"){
1989 >    value = object->vx - chosenPrimaryVertex->x;
1990 >  }
1991 >  else if (variable == "deltaVy"){
1992 >    value = object->vy - chosenPrimaryVertex->y;
1993 >  }
1994 >  else if (variable == "deltaVz"){
1995 >    value = object->vz - chosenPrimaryVertex->z;
1996 >  }
1997  
1998  
1999    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
# Line 1486 | Line 2123 | OSUAnalysis::valueLookup (const BNphoton
2123    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2124  
2125  
2126 +  else if(variable == "genMatchedId"){
2127 +    int index = getGenMatchedParticleIndex(object);
2128 +    if(index == -1) value = 0;
2129 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
2130 +  }
2131 +  else if(variable == "genMatchedMotherId"){
2132 +    int index = getGenMatchedParticleIndex(object);
2133 +    if(index == -1) value = 0;
2134 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2135 +  }
2136 +  else if(variable == "genMatchedGrandmotherId"){
2137 +    int index = getGenMatchedParticleIndex(object);
2138 +    if(index == -1) value = 0;
2139 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2140 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2141 +      if(motherIndex == -1) value = 0;
2142 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2143 +    }
2144 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2145 +  }
2146 +
2147 +
2148    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2149  
2150    value = applyFunction(function, value);
# Line 1517 | Line 2176 | OSUAnalysis::valueLookup (const BNsuperc
2176  
2177  
2178   double
2179 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
2180 +
2181 +  double value = 0.0;
2182 +
2183 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2184 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2185 +  else if(variable == "invMass"){
2186 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2187 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2188 +    value = (fourVector1 + fourVector2).M();
2189 +  }
2190 +  else if(variable == "threeDAngle")
2191 +    {
2192 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2193 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2194 +      value = (threeVector1.Angle(threeVector2));
2195 +    }
2196 +  else if(variable == "alpha")
2197 +    {
2198 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
2199 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2200 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2201 +      value = (pi-threeVector1.Angle(threeVector2));
2202 +    }
2203 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2204 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2205 +  else if(variable == "d0Sign"){
2206 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2207 +    if(d0Sign < 0) value = -0.5;
2208 +    else if (d0Sign > 0) value = 0.5;
2209 +    else value = -999;
2210 +  }
2211 +  else if(variable == "chargeProduct"){
2212 +    value = object1->charge*object2->charge;
2213 +  }
2214 +  else if(variable == "muon1CorrectedD0Vertex"){
2215 +    value = object1->correctedD0Vertex;
2216 +  }
2217 +  else if(variable == "muon2CorrectedD0Vertex"){
2218 +    value = object2->correctedD0Vertex;
2219 +  }
2220 + else if(variable == "muon1timeAtIpInOut"){
2221 +    value = object1->timeAtIpInOut;
2222 +  }
2223 + else if(variable == "muon2timeAtIpInOut"){
2224 +    value = object2->timeAtIpInOut;
2225 +  }
2226 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2227 +
2228 +  value = applyFunction(function, value);
2229 +
2230 +  return value;
2231 + }
2232 +
2233 + double
2234 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
2235 +
2236 +  double value = 0.0;
2237 +
2238 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2239 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2240 +  else if(variable == "invMass"){
2241 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2242 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2243 +    value = (fourVector1 + fourVector2).M();
2244 +  }
2245 +  else if(variable == "threeDAngle")
2246 +    {
2247 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2248 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2249 +      value = (threeVector1.Angle(threeVector2));
2250 +    }
2251 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2252 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2253 +  else if(variable == "d0Sign"){
2254 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2255 +    if(d0Sign < 0) value = -0.5;
2256 +    else if (d0Sign > 0) value = 0.5;
2257 +    else value = -999;
2258 +  }
2259 +  else if(variable == "chargeProduct"){
2260 +    value = object1->charge*object2->charge;
2261 +  }
2262 +  else if(variable == "electron1CorrectedD0Vertex"){
2263 +    value = object1->correctedD0Vertex;
2264 +  }
2265 +  else if(variable == "electron2CorrectedD0Vertex"){
2266 +    value = object2->correctedD0Vertex;
2267 +  }
2268 +
2269 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2270 +
2271 +  value = applyFunction(function, value);
2272 +
2273 +  return value;
2274 + }
2275 +
2276 + double
2277 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
2278 +
2279 +  double value = 0.0;
2280 +
2281 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2282 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2283 +  else if(variable == "invMass"){
2284 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2285 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2286 +    value = (fourVector1 + fourVector2).M();
2287 +  }
2288 +  else if(variable == "threeDAngle")
2289 +    {
2290 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2291 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2292 +      value = (threeVector1.Angle(threeVector2));
2293 +    }
2294 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2295 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2296 +  else if(variable == "d0Sign"){
2297 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2298 +    if(d0Sign < 0) value = -0.5;
2299 +    else if (d0Sign > 0) value = 0.5;
2300 +    else value = -999;
2301 +  }
2302 +  else if(variable == "chargeProduct"){
2303 +    value = object1->charge*object2->charge;
2304 +  }
2305 +  else if(variable == "electronCorrectedD0Vertex"){
2306 +    value = object1->correctedD0Vertex;
2307 +  }
2308 +  else if(variable == "muonCorrectedD0Vertex"){
2309 +    value = object2->correctedD0Vertex;
2310 +  }
2311 +  else if(variable == "electronCorrectedD0"){
2312 +    value = object1->correctedD0;
2313 +  }
2314 +  else if(variable == "muonCorrectedD0"){
2315 +    value = object2->correctedD0;
2316 +  }
2317 +
2318 +
2319 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2320 +
2321 +  value = applyFunction(function, value);
2322 +
2323 +  return value;
2324 + }
2325 +
2326 +
2327 + // Calculate the number of tracks in cone of DeltaR<0.5 around track1.  
2328 + // Return true iff no other tracks are found in this cone.  
2329 + int
2330 + OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
2331 +  for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
2332 +    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.  
2333 +    double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
2334 +    if(deltaRtrk < 0.5) return 0;
2335 +  }
2336 +  return 1;
2337 +  
2338 + }
2339 +
2340 +
2341 + double
2342 + OSUAnalysis::getTrkPtRes (const BNtrack* track1){
2343 +
2344 +  double ptTrue = getTrkPtTrue(track1, mcparticles.product());
2345 +  double PtRes = (track1->pt - ptTrue) / ptTrue;
2346 +
2347 +  return PtRes;
2348 +  
2349 + }
2350 +
2351 +
2352 + double
2353 + OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
2354 +  double value = -99;
2355 +  double genDeltaRLowest = 999;
2356 +
2357 +  for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
2358 +    double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
2359 +    if (genDeltaRtemp < genDeltaRLowest) {
2360 +      genDeltaRLowest = genDeltaRtemp;
2361 +      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.  
2362 +        double ptTrue = genPart->pt;
2363 +        value = ptTrue;
2364 +      }
2365 +    }
2366 +  }
2367 +
2368 +  return value;
2369 +
2370 + }
2371 +
2372 + //creates a map of the dead Ecal channels in the barrel and endcap
2373 + //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
2374 + //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
2375 + void
2376 + OSUAnalysis::WriteDeadEcal (){
2377 +  double etaEcal, phiEcal;
2378 +  ifstream DeadEcalFile(deadEcalFile_);
2379 +  if(!DeadEcalFile) {
2380 +    cout << "Error: DeadEcalFile has not been found." << endl;
2381 +    return;
2382 +  }
2383 +  if(DeadEcalVec.size()!= 0){
2384 +    cout << "Error: DeadEcalVec has a nonzero size" << endl;
2385 +    return;
2386 +  }
2387 +  while(!DeadEcalFile.eof())
2388 +    {
2389 +      DeadEcalFile >> etaEcal >> phiEcal;
2390 +      DeadEcal newChan;
2391 +      newChan.etaEcal = etaEcal;
2392 +      newChan.phiEcal = phiEcal;
2393 +      DeadEcalVec.push_back(newChan);
2394 +    }
2395 +  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
2396 + }
2397 +
2398 + //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
2399 + int
2400 + OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
2401 +  double deltaRLowest = 999;
2402 +  int value = 0;
2403 +  if (DeadEcalVec.size() == 0) WriteDeadEcal();
2404 +  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
2405 +    double eta = ecal->etaEcal;
2406 +    double phi = ecal->phiEcal;
2407 +    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
2408 +    if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
2409 +  }
2410 +  if (deltaRLowest<0.05) {value = 1;}
2411 +  else {value = 0;}
2412 +  return value;
2413 + }
2414 +
2415 +
2416 +
2417 +
2418 + double
2419   OSUAnalysis::applyFunction(string function, double value){
2420  
2421    if(function == "abs") value = fabs(value);
2422 +  else if(function == "fabs") value = fabs(value);
2423 +  else if(function == "log10") value = log10(value);
2424 +  else if(function == "log") value = log10(value);
2425  
2426 +  else if(function == "") value = value;
2427 +  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
2428  
2429    return value;
2430  
# Line 1533 | Line 2437 | void OSUAnalysis::setObjectFlags(cut &cu
2437  
2438    for (uint object = 0; object != inputCollection->size(); object++){
2439  
2440 +
2441      bool decision = true;//object passes if this cut doesn't cut on that type of object
2442  
1538    if(currentCut.inputCollection == inputType){
2443  
2444 <      double value = valueLookup(&inputCollection->at(object), currentCut.variable, currentCut.function);
2444 >    if(currentCut.inputCollection == inputType){
2445  
2446 <      decision = evaluateComparison(value,currentCut.comparativeOperator,currentCut.cutValue);
2446 >      vector<bool> subcutDecisions;
2447 >      for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
2448 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
2449 >        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
2450 >      }
2451 >      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
2452 >      else{
2453 >        bool tempDecision = true;
2454 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
2455 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
2456 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
2457 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
2458 >            tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
2459 >        }
2460 >        decision = tempDecision;
2461 >      }
2462      }
2463 <    individualFlags[inputType].at(currentCutIndex).push_back(decision);
2463 >    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
2464  
2465  
2466      //set flags for objects that pass each cut AND all the previous cuts
2467      bool previousCumulativeFlag = true;
2468      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
2469 <      if(previousCumulativeFlag && individualFlags[inputType].at(previousCutIndex).at(object)) previousCumulativeFlag = true;
2469 >      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
2470        else{ previousCumulativeFlag = false; break;}
2471      }
2472 <    cumulativeFlags[inputType].at(currentCutIndex).push_back(previousCumulativeFlag && decision);
2472 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
2473 >
2474 >
2475 >  }
2476 >
2477 > }
2478 >
2479 >
2480 > template <class InputCollection1, class InputCollection2>
2481 > void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
2482 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
2483 >
2484 >
2485 >  bool sameObjects = false;
2486 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
2487 >
2488 >
2489 >  int counter = 0;  
2490 >  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
2491 >    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
2492 >      
2493 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
2494  
2495 +
2496 +      bool decision = true;//object passes if this cut doesn't cut on that type of object
2497 +
2498 +      if(currentCut.inputCollection == inputType){
2499 +        
2500 +        vector<bool> subcutDecisions;
2501 +        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
2502 +          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
2503 +          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
2504 +        }
2505 +
2506 +        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
2507 +        else{
2508 +          bool tempDecision = subcutDecisions.at(0);
2509 +          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
2510 +            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
2511 +              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
2512 +            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
2513 +              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
2514 +          }
2515 +          decision = tempDecision;
2516 +        }
2517 +      }
2518 +      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
2519 +      
2520 +      //set flags for objects that pass each cut AND all the previous cuts
2521 +      bool previousCumulativeFlag = true;
2522 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
2523 +        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
2524 +        else{ previousCumulativeFlag = false; break;}
2525 +      }
2526 +      //apply flags for the components of the composite object as well
2527 +      bool currentCumulativeFlag = true;
2528 +      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
2529 +      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
2530 +      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
2531 +      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
2532 +      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
2533 +
2534 +      counter++;      
2535 +    }
2536 +    
2537    }
2538  
2539 +
2540   }
2541  
2542  
2543   template <class InputCollection>
2544 < void OSUAnalysis::fillHistogram(TH1* histo, histogram parameters, InputCollection inputCollection){
2544 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
2545 >
2546 >  for (uint object = 0; object != inputCollection->size(); object++){
2547 >
2548 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
2549 >
2550 >    string currentString = parameters.inputVariables.at(0);
2551 >    string inputVariable = "";
2552 >    string function = "";
2553 >    if(currentString.find("(")==std::string::npos){
2554 >      inputVariable = currentString;// variable to cut on                                                                                                                                        
2555 >    }
2556 >    else{
2557 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
2558 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
2559 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
2560 >    }
2561 >
2562 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
2563 >    histo->Fill(value,puScaleFactor);
2564 >
2565 >  }
2566 >
2567 > }
2568 >
2569 > template <class InputCollection1, class InputCollection2>
2570 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
2571 >
2572 >  bool sameObjects = false;
2573 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
2574 >
2575 >  int pairCounter = 0;  
2576 >  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
2577 >    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
2578 >      
2579 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
2580 >
2581 >      //only take objects which have passed all cuts and pairs which have passed all cuts
2582 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
2583 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
2584 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
2585 >
2586 >      string currentString = parameters.inputVariables.at(0);
2587 >      string inputVariable = "";
2588 >      string function = "";
2589 >      if(currentString.find("(")==std::string::npos){
2590 >        inputVariable = currentString;// variable to cut on                                                                                                          
2591 >      }
2592 >      else{
2593 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
2594 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
2595 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
2596 >      }
2597 >      
2598 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
2599 >      histo->Fill(value,puScaleFactor);
2600  
2601 +      pairCounter++;      
2602 +    }
2603 +  }
2604 +
2605 + }
2606 +
2607 +
2608 + template <class InputCollection>
2609 + void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
2610  
2611    for (uint object = 0; object != inputCollection->size(); object++){
2612 <    if(parameters.inputVariables.size() == 1){
2613 <      double value = valueLookup(&inputCollection->at(object), parameters.inputVariables.at(0), parameters.function);
2614 <      histo->Fill(value);
2615 <    }
2616 <    else if(parameters.inputVariables.size() == 2){
2617 <      double valueX = valueLookup(&inputCollection->at(object), parameters.inputVariables.at(0), parameters.function);
2618 <      double valueY = valueLookup(&inputCollection->at(object), parameters.inputVariables.at(1), parameters.function);
2619 <      histo->Fill(valueX,valueY);
2612 >
2613 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
2614 >
2615 >    string currentString = parameters.inputVariables.at(0);
2616 >    string inputVariable = "";
2617 >    string function = "";
2618 >    if(currentString.find("(")==std::string::npos){
2619 >      inputVariable = currentString;// variable to cut on                                                                                                                                        
2620 >    }
2621 >    else{
2622 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
2623 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
2624 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
2625 >    }
2626 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
2627 >
2628 >    currentString = parameters.inputVariables.at(1);
2629 >    inputVariable = "";
2630 >    function = "";
2631 >    if(currentString.find("(")==std::string::npos){
2632 >      inputVariable = currentString;// variable to cut on                                                                                                                                        
2633 >    }
2634 >    else{
2635 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
2636 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
2637 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
2638 >    }
2639 >
2640 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
2641 >
2642 >    histo->Fill(valueX,valueY,puScaleFactor);
2643 >
2644 >  }
2645 >
2646 > }
2647 >
2648 > template <class InputCollection1, class InputCollection2>
2649 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
2650 >
2651 >  bool sameObjects = false;
2652 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
2653 >
2654 >  int pairCounter = 0;  
2655 >  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
2656 >    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
2657 >      
2658 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
2659 >
2660 >      //only take objects which have passed all cuts and pairs which have passed all cuts
2661 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
2662 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
2663 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
2664 >
2665 >      string currentString = parameters.inputVariables.at(0);
2666 >      string inputVariable = "";
2667 >      string function = "";
2668 >      if(currentString.find("(")==std::string::npos){
2669 >        inputVariable = currentString;// variable to cut on                                                                                                          
2670 >      }
2671 >      else{
2672 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
2673 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
2674 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
2675 >      }
2676 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
2677 >
2678 >      currentString = parameters.inputVariables.at(1);
2679 >      inputVariable = "";
2680 >      function = "";
2681 >      if(currentString.find("(")==std::string::npos){
2682 >        inputVariable = currentString;// variable to cut on                                                                                                          
2683 >      }
2684 >      else{
2685 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
2686 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
2687 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
2688 >      }
2689 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
2690 >
2691 >
2692 >      histo->Fill(valueX,valueY,puScaleFactor);
2693 >
2694 >      pairCounter++;      
2695 >
2696      }
2697    }
2698  
2699   }
2700  
2701  
2702 + template <class InputObject>
2703 + int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
2704 +
2705 +  int bestMatchIndex = -1;
2706 +  double bestMatchDeltaR = 999;
2707 +
2708 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
2709 +
2710 +    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
2711 +    if(currentDeltaR > 0.05) continue;
2712 + //     cout << std::setprecision(3) << std::setw(20)
2713 + //       << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
2714 + //       << std::setw(20)
2715 + //       << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
2716 + //       << std::setw(20)
2717 + //       << "\tdeltaR = " << currentDeltaR  
2718 + //       << std::setprecision(1)
2719 + //       << std::setw(20)
2720 + //       << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
2721 + //       << std::setw(20)
2722 + //       << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
2723 + //       << std::setw(20)
2724 + //       << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
2725 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
2726 +      bestMatchIndex = mcparticle - mcparticles->begin();
2727 +      bestMatchDeltaR = currentDeltaR;
2728 +    }
2729 +
2730 +  }
2731 + //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
2732 + //   else cout << "no match found..." << endl;
2733 +  return bestMatchIndex;
2734 +
2735 + }
2736 +
2737 +
2738 + int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
2739 +
2740 +  int bestMatchIndex = -1;
2741 +  double bestMatchDeltaR = 999;
2742 +
2743 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
2744 +
2745 +    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
2746 +
2747 +    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
2748 +    if(currentDeltaR > 0.05) continue;
2749 +
2750 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
2751 +      bestMatchIndex = mcparticle - mcparticles->begin();
2752 +      bestMatchDeltaR = currentDeltaR;
2753 +    }
2754 +
2755 +  }
2756 +
2757 +  return bestMatchIndex;
2758 + }
2759 +
2760 +
2761 + // bin      particle type
2762 + // ---      -------------
2763 + //  0        unmatched
2764 + //  1        u
2765 + //  2        d
2766 + //  3        s
2767 + //  4        c
2768 + //  5        b
2769 + //  6        t
2770 + //  7        e
2771 + //  8        mu
2772 + //  9        tau
2773 + // 10        nu
2774 + // 11        g
2775 + // 12        gamma
2776 + // 13        Z
2777 + // 14        W
2778 + // 15        light meson
2779 + // 16        K meson
2780 + // 17        D meson
2781 + // 18        B meson
2782 + // 19        light baryon
2783 + // 20        strange baryon
2784 + // 21        charm baryon
2785 + // 22        bottom baryon
2786 + // 23        other
2787 +
2788 + int OSUAnalysis::getPdgIdBinValue(int pdgId){
2789 +
2790 +  int binValue = -999;
2791 +  int absPdgId = fabs(pdgId);  
2792 +  if(pdgId == -1) binValue = 0;
2793 +  else if(absPdgId <= 6 ) binValue = absPdgId;
2794 +  else if(absPdgId == 11 ) binValue = 7;
2795 +  else if(absPdgId == 13 ) binValue = 8;
2796 +  else if(absPdgId == 15 ) binValue = 9;
2797 +  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
2798 +  else if(absPdgId == 21 ) binValue = 11;
2799 +  else if(absPdgId == 22 ) binValue = 12;
2800 +  else if(absPdgId == 23 ) binValue = 13;
2801 +  else if(absPdgId == 24 ) binValue = 14;
2802 +  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
2803 +  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
2804 +  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
2805 +  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
2806 +  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
2807 +  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
2808 +  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
2809 +  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
2810 +
2811 +  else binValue = 23;
2812 +
2813 +  return binValue;
2814 +
2815 + }
2816  
2817  
2818   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines