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.17 by lantonel, Thu Feb 21 16:38:25 2013 UTC vs.
Revision 1.31 by ahart, Mon Mar 18 10:21:44 2013 UTC

# Line 17 | Line 17 | OSUAnalysis::OSUAnalysis (const edm::Par
17    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
18    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
19    puFile_ (cfg.getParameter<std::string> ("puFile")),
20 +  deadEcalFile_ (cfg.getParameter<std::string> ("deadEcalFile")),
21 +  muonSFFile_ (cfg.getParameter<std::string> ("muonSFFile")),
22    dataPU_ (cfg.getParameter<std::string> ("dataPU")),
23 +  electronSFID_ (cfg.getParameter<std::string> ("electronSFID")),
24 +  muonSF_ (cfg.getParameter<std::string> ("muonSF")),
25    dataset_ (cfg.getParameter<std::string> ("dataset")),
26    datasetType_ (cfg.getParameter<std::string> ("datasetType")),
27    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
28    histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
29 <  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents"))
30 <
29 >  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
30 >  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting"))
31   {
32  
33    TH1::SetDefaultSumw2 ();
34  
35    //create pile-up reweighting object, if necessary
36 <  if(datasetType_ != "data") puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
36 >  if(datasetType_ != "data") {
37 >    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
38 >    muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
39 >    electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
40 >  }
41  
42    // Construct Cutflow Objects. These store the results of cut decisions and
43    // handle filling cut flow histograms.
# Line 37 | Line 45 | OSUAnalysis::OSUAnalysis (const edm::Par
45    std::vector<TFileDirectory> directories;
46  
47    //always get vertex collection so we can assign the primary vertex in the event
48 <  allNecessaryObjects.push_back("primaryvertexs");
48 >  objectsToGet.push_back("primaryvertexs");
49 >
50    //always make the plot of number of primary verticex (to check pile-up reweighting)
51    objectsToPlot.push_back("primaryvertexs");
52  
53 +  //always get the MC particles to do GEN-matching
54 +  objectsToGet.push_back("mcparticles");
55 +
56    //always get the event collection to do pile-up reweighting
57 <  allNecessaryObjects.push_back("events");
57 >  objectsToGet.push_back("events");
58  
59    //parse the histogram definitions
60    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
61  
62      string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
63      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
64 <    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
64 >    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
65 >      objectsToGet.push_back(tempInputCollection);
66        objectsToPlot.push_back(tempInputCollection);
67 <      allNecessaryObjects.push_back(tempInputCollection);
67 >      objectsToCut.push_back(tempInputCollection);
68      }
69 <    else{//pair of objects, need to add them both to the things to allNecessaryObjects
69 >    else{//pair of objects, need to add them both to the things to objectsToGet
70        int dashIndex = tempInputCollection.find("-");
71        int spaceIndex = tempInputCollection.find(" ");
72        int secondWordLength = spaceIndex - dashIndex;
73 <      allNecessaryObjects.push_back(tempInputCollection);
74 <      allNecessaryObjects.push_back(tempInputCollection.substr(0,dashIndex)+"s");
75 <      allNecessaryObjects.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
73 >      objectsToGet.push_back(tempInputCollection);
74 >      objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
75 >      objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
76        objectsToPlot.push_back(tempInputCollection);
77        objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
78        objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
79 +      objectsToCut.push_back(tempInputCollection);
80 +      objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
81 +      objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
82 +
83        }
84  
85      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
86 <    
86 >
87      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
88  
89        histogram tempHistogram;
# Line 75 | Line 92 | OSUAnalysis::OSUAnalysis (const edm::Par
92        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
93        tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
94        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
95 <      
95 >
96        histograms.push_back(tempHistogram);
97  
98      }
99    }
100 <  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object
100 >  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
101    sort( objectsToPlot.begin(), objectsToPlot.end() );
102    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
103  
104  
105  
106 +  //add histograms with the gen-matched id, mother id, and grandmother id
107 +  for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
108 +
109 +    string currentObject = objectsToPlot.at(currentObjectIndex);
110 +    if(currentObject != "muons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
111 +
112 +    histogram tempIdHisto;
113 +    histogram tempMomIdHisto;
114 +    histogram tempGmaIdHisto;
115 +
116 +    tempIdHisto.inputCollection = currentObject;
117 +    tempMomIdHisto.inputCollection = currentObject;
118 +    tempGmaIdHisto.inputCollection = currentObject;
119 +
120 +    currentObject = currentObject.substr(0, currentObject.size()-1);
121 +    tempIdHisto.name = currentObject+"GenMatchId";
122 +    tempMomIdHisto.name = currentObject+"GenMatchMotherId";
123 +    tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
124 +
125 +    currentObject.at(0) = toupper(currentObject.at(0));
126 +    tempIdHisto.title = currentObject+" Gen-matched Particle";
127 +    tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
128 +    tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
129 +
130 +    int maxNum = 24;
131 +    vector<double> binVector;
132 +    binVector.push_back(maxNum);
133 +    binVector.push_back(0);
134 +    binVector.push_back(maxNum);
135 +
136 +    tempIdHisto.bins = binVector;
137 +    tempIdHisto.inputVariables.push_back("genMatchedId");
138 +    tempMomIdHisto.bins = binVector;
139 +    tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
140 +    tempGmaIdHisto.bins = binVector;
141 +    tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
142 +
143 +    histograms.push_back(tempIdHisto);
144 +    histograms.push_back(tempMomIdHisto);
145 +    histograms.push_back(tempGmaIdHisto);
146 +
147 +  }
148 +
149 +
150  
151    channel tempChannel;
152    //loop over all channels (event selections)
# Line 104 | Line 165 | OSUAnalysis::OSUAnalysis (const edm::Par
165        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
166        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
167          tempChannel.triggers.push_back(triggerNames.at(trigger));
168 <      allNecessaryObjects.push_back("triggers");
168 >      objectsToGet.push_back("triggers");
169      }
170  
171  
# Line 129 | Line 190 | OSUAnalysis::OSUAnalysis (const edm::Par
190        int numBinsElements = currentHistogram.bins.size();
191        int numInputVariables = currentHistogram.inputVariables.size();
192  
132
133
193        if(numBinsElements != 3 && numBinsElements !=6) {
194 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
195 <        exit(0);
194 >        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
195 >        exit(0);
196        }
197        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
198 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
199 <        exit(0);
198 >        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
199 >        exit(0);
200        }
201        else if(numBinsElements == 3){
202 <        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));
202 >        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));
203        }
204        else if(numBinsElements == 6){
205 <        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));
205 >        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));
206  
207        }
208  
209  
210 +      if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
211 +
212 + // bin      particle type
213 + // ---      -------------
214 + //  0        unmatched
215 + //  1        u
216 + //  2        d
217 + //  3        s
218 + //  4        c
219 + //  5        b
220 + //  6        t
221 + //  7        e
222 + //  8        mu
223 + //  9        tau
224 + // 10        nu
225 + // 11        g
226 + // 12        gamma
227 + // 13        Z
228 + // 14        W
229 + // 15        light meson
230 + // 16        K meson
231 + // 17        D meson
232 + // 18        B meson
233 + // 19        light baryon
234 + // 20        strange baryon
235 + // 21        charm baryon
236 + // 22        bottom baryon
237 + // 23        other
238 +
239 +      vector<TString> labelArray;
240 +      labelArray.push_back("unmatched");
241 +      labelArray.push_back("u");
242 +      labelArray.push_back("d");
243 +      labelArray.push_back("s");
244 +      labelArray.push_back("c");
245 +      labelArray.push_back("b");
246 +      labelArray.push_back("t");
247 +      labelArray.push_back("e");
248 +      labelArray.push_back("#mu");
249 +      labelArray.push_back("#tau");
250 +      labelArray.push_back("#nu");
251 +      labelArray.push_back("g");
252 +      labelArray.push_back("#gamma");
253 +      labelArray.push_back("Z");
254 +      labelArray.push_back("W");
255 +      labelArray.push_back("light meson");
256 +      labelArray.push_back("K meson");
257 +      labelArray.push_back("D meson");
258 +      labelArray.push_back("B meson");
259 +      labelArray.push_back("light baryon");
260 +      labelArray.push_back("strange baryon");
261 +      labelArray.push_back("charm baryon");
262 +      labelArray.push_back("bottom baryon");
263 +      labelArray.push_back("other");
264 +
265 +      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
266 +        oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
267 +      }
268      }
269 +
270      //book a histogram for the number of each object type to be plotted
271 +
272      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
273        string currentObject = objectsToPlot.at(currentObjectIndex);
274        int maxNum = 10;
# Line 163 | Line 282 | OSUAnalysis::OSUAnalysis (const edm::Par
282        string histoName = "num" + currentObject;
283  
284        if(histoName == "numPrimaryvertexs"){
285 <        string newHistoName = histoName + "BeforePileupCorrection";
286 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);    
287 <        newHistoName = histoName + "AfterPileupCorrection";
288 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
285 >        string newHistoName = histoName + "BeforePileupCorrection";
286 >        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
287 >        newHistoName = histoName + "AfterPileupCorrection";
288 >        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
289        }
290        else
291 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
291 >        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
292      }
293  
294  
295 +
296 +
297 +
298      //get list of cuts for this channel
299      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
300  
# Line 182 | Line 304 | OSUAnalysis::OSUAnalysis (const edm::Par
304        //store input collection for cut
305        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
306        tempCut.inputCollection = tempInputCollection;
307 <      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
308 <        allNecessaryObjects.push_back(tempInputCollection);
309 <      }
310 <      else{//pair of objects, need to add them both to the things to allNecessaryObjects
311 <        int dashIndex = tempInputCollection.find("-");
312 <        int spaceIndex = tempInputCollection.find(" ");
313 <        int secondWordLength = spaceIndex - dashIndex;
314 <        allNecessaryObjects.push_back(tempInputCollection);
315 <        allNecessaryObjects.push_back(tempInputCollection.substr(0,dashIndex)+"s");
316 <        allNecessaryObjects.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
307 >      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
308 >        objectsToGet.push_back(tempInputCollection);
309 >        objectsToCut.push_back(tempInputCollection);
310 >      }
311 >      else{//pair of objects, need to add them both to the things to objectsToGet
312 >        int dashIndex = tempInputCollection.find("-");
313 >        int spaceIndex = tempInputCollection.find(" ");
314 >        int secondWordLength = spaceIndex - dashIndex;
315 >        objectsToGet.push_back(tempInputCollection);
316 >        objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
317 >        objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
318 >        objectsToCut.push_back(tempInputCollection);
319 >        objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
320 >        objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
321  
322        }
323  
# Line 201 | Line 327 | OSUAnalysis::OSUAnalysis (const edm::Par
327        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
328        std::vector<string> cutStringVector = splitString(cutString);
329        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
330 <        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
331 <        exit(0);
330 >        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
331 >        exit(0);
332        }
333        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
334        for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
335 <        int indexOffset = 4 * subcutIndex;
336 <        string currentVariableString = cutStringVector.at(indexOffset);
337 <        if(currentVariableString.find("(")==std::string::npos){
338 <          tempCut.functions.push_back("");//no function was specified
339 <          tempCut.variables.push_back(currentVariableString);// variable to cut on
340 <        }
341 <        else{
342 <          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
343 <          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
344 <          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
345 <        }
346 <        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
347 <        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
348 <        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
335 >        int indexOffset = 4 * subcutIndex;
336 >        string currentVariableString = cutStringVector.at(indexOffset);
337 >        if(currentVariableString.find("(")==std::string::npos){
338 >          tempCut.functions.push_back("");//no function was specified
339 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
340 >        }
341 >        else{
342 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
343 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
344 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
345 >        }
346 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
347 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
348 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
349        }
350  
351        //get number of objects required to pass cut for event to pass
352        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
353        std::vector<string> numberRequiredVector = splitString(numberRequiredString);
354        if(numberRequiredVector.size()!=2){
355 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
355 >        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
356          exit(0);
357        }
358  
# Line 261 | Line 387 | OSUAnalysis::OSUAnalysis (const edm::Par
387    }//end loop over channels
388  
389  
390 <  //make unique vector of objects we need to cut on (so we make sure to get them from the event)
391 <  sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
392 <  allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
390 >  //make unique vector of objects we need to get from the event
391 >  sort( objectsToGet.begin(), objectsToGet.end() );
392 >  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
393 >  //make unique vector of objects we need to cut on
394 >  sort( objectsToCut.begin(), objectsToCut.end() );
395 >  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
396  
397  
398   }
# Line 281 | Line 410 | void
410   OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
411   {
412  
284
413    // Retrieve necessary collections from the event.
414 <  edm::Handle<BNtriggerCollection> triggers;
415 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
414 >
415 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
416      event.getByLabel (triggers_, triggers);
417  
418 <  edm::Handle<BNjetCollection> jets;
291 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())
418 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
419      event.getByLabel (jets_, jets);
420  
421 <  edm::Handle<BNmuonCollection> muons;
295 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())
421 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
422      event.getByLabel (muons_, muons);
423  
424 <  edm::Handle<BNelectronCollection> electrons;
299 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())
424 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
425      event.getByLabel (electrons_, electrons);
426  
427 <  edm::Handle<BNeventCollection> events;
303 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())
427 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
428      event.getByLabel (events_, events);
429  
430 <  edm::Handle<BNtauCollection> taus;
307 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())
430 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
431      event.getByLabel (taus_, taus);
432  
433 <  edm::Handle<BNmetCollection> mets;
311 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())
433 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
434      event.getByLabel (mets_, mets);
435  
436 <  edm::Handle<BNtrackCollection> tracks;
315 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())
436 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
437      event.getByLabel (tracks_, tracks);
438  
439 <  edm::Handle<BNgenjetCollection> genjets;
319 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())
439 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
440      event.getByLabel (genjets_, genjets);
441  
442 <  edm::Handle<BNmcparticleCollection> mcparticles;
323 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())
442 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
443      event.getByLabel (mcparticles_, mcparticles);
444  
445 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
327 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())
445 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
446      event.getByLabel (primaryvertexs_, primaryvertexs);
447  
448 <  edm::Handle<BNbxlumiCollection> bxlumis;
331 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())
448 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
449      event.getByLabel (bxlumis_, bxlumis);
450  
451 <  edm::Handle<BNphotonCollection> photons;
335 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())
451 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
452      event.getByLabel (photons_, photons);
453  
454 <  edm::Handle<BNsuperclusterCollection> superclusters;
339 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())
454 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
455      event.getByLabel (superclusters_, superclusters);
456  
342
457    //get pile-up event weight
458 <  double puScaleFactor = 0;
459 <  if(datasetType_ != "data")
460 <    puScaleFactor = puWeight_->at (events->at (0).numTruePV);
347 <  else
348 <    puScaleFactor = 1.00;
458 >  double scaleFactor = 1.00;
459 >  if(doPileupReweighting_ && datasetType_ != "data")
460 >    scaleFactor = puWeight_->at (events->at (0).numTruePV);
461  
462  
463    //loop over all channels
# Line 354 | Line 466 | OSUAnalysis::analyze (const edm::Event &
466      channel currentChannel = channels.at(currentChannelIndex);
467  
468      flagMap individualFlags;
357    flagMap cumulativeFlags;
469      counterMap passingCounter;
470 +    cumulativeFlags.clear ();
471  
472      bool triggerDecision = true;
473      if(currentChannel.triggers.size() != 0){  //triggers specified
# Line 364 | Line 476 | OSUAnalysis::analyze (const edm::Event &
476      }
477  
478      //loop over all cuts
479 +
480 +
481 +
482      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
483        cut currentCut = currentChannel.cuts.at(currentCutIndex);
484  
485 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
486 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
485 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
486 >        string currentObject = objectsToCut.at(currentObjectIndex);
487  
488 +        //initialize maps to get ready to set cuts
489          individualFlags[currentObject].push_back (vector<bool> ());
490          cumulativeFlags[currentObject].push_back (vector<bool> ());
491  
492 +      }
493 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
494 +        string currentObject = objectsToCut.at(currentObjectIndex);
495 +
496 +        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
497 +
498  
499          if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
500          else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
# Line 388 | Line 510 | OSUAnalysis::analyze (const edm::Event &
510          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
511          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
512  
513 <        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(),"muon-muon pairs");
514 <        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(),"electron-electron pairs");
515 <        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(),"electron-muon pairs");
513 >
514 >        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
515 >                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
516 >                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
517 >                                                                   "muon-muon pairs");
518 >        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
519 >                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
520 >                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
521 >                                                                           "electron-electron pairs");
522 >        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
523 >                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
524 >                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
525 >                                                                       "electron-muon pairs");
526 >
527  
528        }
529  
# Line 399 | Line 532 | OSUAnalysis::analyze (const edm::Event &
532      }//end loop over all cuts
533  
534  
402
535      //use cumulative flags to apply cuts at event level
536  
537      bool eventPassedAllCuts = true;
# Line 408 | Line 540 | OSUAnalysis::analyze (const edm::Event &
540      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
541  
542  
543 +
544      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
545  
546        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 425 | Line 558 | OSUAnalysis::analyze (const edm::Event &
558  
559      }
560  
561 <    cutFlows_.at(currentChannelIndex)->fillCutFlow(puScaleFactor);
561 >    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
562  
563  
564  
565      if(!eventPassedAllCuts)continue;
566  
567  
568 <
569 <
570 <    //set position of primary vertex in event, in order to calculate quantities relative to it
571 <    primaryVertex_ = 0;
439 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back();
440 <    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
441 <      if(!vertexFlags.at(vertexIndex)) continue;
442 <      primaryVertex_ = new BNprimaryvertex (primaryvertexs->at (vertexIndex));
443 <      break;
444 <    }
445 <
446 <
568 >    //if(datasetType_ != "data") {
569 >    //  scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
570 >    //  scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
571 >    //}
572  
573      //filling histograms
574      for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
575        histogram currentHistogram = histograms.at(histogramIndex);
576  
577        if(currentHistogram.inputVariables.size() == 1){
578 <        TH1D* histo;
579 <        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
580 <        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
581 <        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
582 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),\
583 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(),\
584 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
585 <        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
586 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
587 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
588 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
589 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
590 <                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
591 <                                                                                              cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
592 <        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
593 <        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
594 <        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
595 <        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
596 <        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
597 <        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
598 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
599 <        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
600 <        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
601 <        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
578 >        TH1D* histo;
579 >        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
580 >
581 >
582 >
583 >        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
584 >         else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
585 >        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
586 >                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
587 >                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
588 >        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
589 >        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
590 >                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
591 >                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
592 >        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
593 >                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
594 >                                                                                              cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
595 >        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
596 >        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
597 >        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
598 >        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
599 >        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
600 >        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
601 >        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
602 >        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
603 >        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
604 >        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
605        }
606        else if(currentHistogram.inputVariables.size() == 2){
607 <        TH2D* histo;
608 <        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
481 <        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
482 <        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
483 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
484 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
485 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
486 <        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
487 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
488 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
489 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
490 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
491 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
492 <                                                                                               cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
493 <        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
494 <        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
495 <        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
496 <        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
497 <        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
498 <        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
499 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
500 <        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
501 <        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
502 <        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
503 <      }
504 <    }
607 >        TH2D* histo;
608 >        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
609  
610  
611 +
612 +        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
613 +        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
614 +        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
615 +                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
616 +                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
617 +        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
618 +        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
619 +                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
620 +                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
621 +        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
622 +                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
623 +                                                                                               cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
624 +        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
625 +        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
626 +        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
627 +        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
628 +        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
629 +        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
630 +        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
631 +        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
632 +        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
633 +        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
634 +      }
635 +    }
636 +
637      //fills histograms with the sizes of collections
638      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
639        string currentObject = objectsToPlot.at(currentObjectIndex);
640  
641 <      if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
642 <      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
643 <      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
644 <      string tempCurrentObject = currentObject;
641 >      string objectToPlot = "";
642 >
643 >      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
644 >      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
645 >      else if(currentObject == "electron-muon pairs") objectToPlot = "electronMuonPairs";
646 >      else objectToPlot = currentObject;
647 >      string tempCurrentObject = objectToPlot;
648        tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
649        string histoName = "num" + tempCurrentObject;
650  
651  
652 <      if(currentObject == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),puScaleFactor);
653 <      else if(currentObject == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),puScaleFactor);
654 <      else if(currentObject == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,puScaleFactor);
655 <      else if(currentObject == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),puScaleFactor);
656 <      else if(currentObject == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,puScaleFactor);
657 <      else if(currentObject == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),puScaleFactor);
658 <      else if(currentObject == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),puScaleFactor);
659 <      else if(currentObject == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),puScaleFactor);
660 <      else if(currentObject == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),puScaleFactor);
661 <      else if(currentObject == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),puScaleFactor);
662 <      else if(currentObject == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),puScaleFactor);
663 <      else if(currentObject == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),puScaleFactor);
664 <      else if(currentObject == "primaryvertexs"){
665 <        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
666 <        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),puScaleFactor);
667 <      }
668 <      else if(currentObject == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),puScaleFactor);
669 <      else if(currentObject == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),puScaleFactor);
670 <      else if(currentObject == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),puScaleFactor);
652 >
653 >
654 >      //set position of primary vertex in event, in order to calculate quantities relative to it
655 >      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
656 >        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
657 >        int numToPlot = 0;
658 >        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
659 >          if(lastCutFlags.at(currentFlag)) numToPlot++;
660 >        }
661 >        if(objectToPlot == "primaryvertexs"){
662 >          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
663 >          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
664 >        }
665 >        else
666 >          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
667 >      }
668 >      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
669 >      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
670 >      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
671 >      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
672 >      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
673 >      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
674 >      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
675 >      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
676 >      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
677 >      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
678 >      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
679 >      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
680 >      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
681 >      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
682 >      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
683 >      else if(objectToPlot == "primaryvertexs"){
684 >        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
685 >        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
686 >      }
687  
688      }
689 +
690 +
691 +
692 +
693    } //end loop over channel
694  
695 <  masterCutFlow_->fillCutFlow(puScaleFactor);
695 >  masterCutFlow_->fillCutFlow(scaleFactor);
696  
697  
698  
# Line 738 | Line 891 | OSUAnalysis::valueLookup (const BNmuon*
891    else if(variable == "ecalIso") value = object->ecalIso;
892    else if(variable == "hcalIso") value = object->hcalIso;
893    else if(variable == "caloIso") value = object->caloIso;
894 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
894 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
895    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
896    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
897    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 877 | Line 1030 | OSUAnalysis::valueLookup (const BNmuon*
1030    else if(variable == "time_ndof") value = object->time_ndof;
1031  
1032    //user-defined variables
1033 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1034 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1035 <  else if(variable == "detIso") value = (object->trackIso) / object->pt;
1036 <  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1033 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1034 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1035 >  else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1036 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1037    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1038 +  else if(variable == "metMT") {
1039 +    const BNmet *met = chosenMET ();
1040 +    if (met)
1041 +      {
1042 +        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1043 +                       p2 (met->px, met->py, 0.0, met->pt);
1044 +
1045 +        value = (p1 + p2).Mt ();
1046 +      }
1047 +    else
1048 +      value = -999;
1049 +  }
1050 +
1051 +
1052 +
1053 +  else if(variable == "correctedD0VertexInEBPlus"){
1054 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1055 +    else value = -999;
1056 +  }
1057 +  else if(variable == "correctedD0VertexOutEBPlus"){
1058 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1059 +    else value = -999;
1060 +  }
1061 +  else if(variable == "correctedD0VertexEEPlus"){
1062 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1063 +    else value = -999;
1064 +  }
1065 +
1066 +  else if(variable == "correctedD0BeamspotInEBPlus"){
1067 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1068 +    else value = -999;
1069 +  }
1070 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
1071 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1072 +    else value = -999;
1073 +  }
1074 +  else if(variable == "correctedD0BeamspotEEPlus"){
1075 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1076 +    else value = -999;
1077 +  }
1078 +
1079 +  else if(variable == "correctedD0VertexInEBMinus"){
1080 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1081 +    else value = -999;
1082 +  }
1083 +  else if(variable == "correctedD0VertexOutEBMinus"){
1084 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1085 +    else value = -999;
1086 +  }
1087 +  else if(variable == "correctedD0VertexEEMinus"){
1088 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1089 +    else value = -999;
1090 +  }
1091 +
1092 +  else if(variable == "correctedD0BeamspotInEBMinus"){
1093 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1094 +    else value = -999;
1095 +  }
1096 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
1097 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1098 +    else value = -999;
1099 +  }
1100 +  else if(variable == "correctedD0BeamspotEEMinus"){
1101 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1102 +    else value = -999;
1103 +  }
1104 +
1105 +
1106 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1107 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1108 +    else value = -999;
1109 +  }
1110 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1111 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1112 +    else value = -999;
1113 +  }
1114 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
1115 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1116 +    else value = -999;
1117 +  }
1118 +
1119 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1120 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1121 +    else value = -999;
1122 +  }
1123 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1124 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1125 +    else value = -999;
1126 +  }
1127 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1128 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1129 +    else value = -999;
1130 +  }
1131 +
1132 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1133 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1134 +    else value = -999;
1135 +  }
1136 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1137 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1138 +    else value = -999;
1139 +  }
1140 +  else if(variable == "correctedD0VertexEENegativeCharge"){
1141 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1142 +    else value = -999;
1143 +  }
1144 +
1145 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1146 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1147 +    else value = -999;
1148 +  }
1149 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1150 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1151 +    else value = -999;
1152 +  }
1153 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1154 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1155 +    else value = -999;
1156 +  }
1157 +
1158 +
1159    else if(variable == "tightID") {
1160 <    value = object->isGlobalMuon > 0            \
1161 <      && object->isPFMuon > 0                   \
1162 <      && object->normalizedChi2 < 10            \
1163 <      && object->numberOfValidMuonHits > 0      \
1164 <      && object->numberOfMatchedStations > 1    \
1165 <      && fabs(object->correctedD0Vertex) < 0.2  \
1166 <      && fabs(object->correctedDZ) < 0.5        \
1167 <      && object->numberOfValidPixelHits > 0     \
1160 >    value = object->isGlobalMuon > 0                \
1161 >      && object->isPFMuon > 0                        \
1162 >      && object->normalizedChi2 < 10                \
1163 >      && object->numberOfValidMuonHits > 0        \
1164 >      && object->numberOfMatchedStations > 1        \
1165 >      && fabs(object->correctedD0Vertex) < 0.2        \
1166 >      && fabs(object->correctedDZ) < 0.5        \
1167 >      && object->numberOfValidPixelHits > 0                \
1168        && object->numberOfLayersWithMeasurement > 5;
895    
896
1169    }
1170    else if(variable == "tightIDdisplaced"){
1171 <    value = object->isGlobalMuon > 0            \
1172 <      && object->isPFMuon > 0                   \
1173 <      && object->normalizedChi2 < 10            \
1174 <      && object->numberOfValidMuonHits > 0      \
1175 <      && object->numberOfMatchedStations > 1    \
904 <      && object->numberOfValidPixelHits > 0     \
1171 >    value = object->isGlobalMuon > 0                \
1172 >      && object->normalizedChi2 < 10                \
1173 >      && object->numberOfValidMuonHits > 0        \
1174 >      && object->numberOfMatchedStations > 1        \
1175 >      && object->numberOfValidPixelHits > 0        \
1176        && object->numberOfLayersWithMeasurement > 5;
1177    }
1178  
1179 +
1180 +
1181 +  else if(variable == "genMatchedId"){
1182 +    int index = getGenMatchedParticleIndex(object);
1183 +    if(index == -1) value = 0;
1184 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
1185 +  }
1186 +  else if(variable == "genMatchedMotherId"){
1187 +    int index = getGenMatchedParticleIndex(object);
1188 +    if(index == -1) value = 0;
1189 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1190 +  }
1191 +  else if(variable == "genMatchedGrandmotherId"){
1192 +    int index = getGenMatchedParticleIndex(object);
1193 +    if(index == -1) value = 0;
1194 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1195 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1196 +      if(motherIndex == -1) value = 0;
1197 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1198 +    }
1199 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1200 +  }
1201 +
1202 +
1203 +
1204    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1205  
1206    value = applyFunction(function, value);
# Line 1075 | Line 1371 | OSUAnalysis::valueLookup (const BNelectr
1371    else if(variable == "passConvVeto") value = object->passConvVeto;
1372  
1373    //user-defined variables
1374 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1375 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1374 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1375 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1376    else if(variable == "detIso") value = (object->trackIso) / object->pt;
1377    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1378 +  else if(variable == "metMT") {
1379 +    const BNmet *met = chosenMET ();
1380 +    if (met)
1381 +      {
1382 +        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1383 +                       p2 (met->px, met->py, 0.0, met->pt);
1384 +
1385 +        value = (p1 + p2).Mt ();
1386 +      }
1387 +    else
1388 +      value = -999;
1389 +  }
1390 +
1391 +  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
1392 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
1393 +    else value = -999;
1394 +  }
1395 +  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
1396 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
1397 +    else value = -999;
1398 +  }
1399 +
1400 +  else if(variable == "correctedD0VertexInEBPlus"){
1401 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1402 +    else value = -999;
1403 +  }
1404 +  else if(variable == "correctedD0VertexOutEBPlus"){
1405 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1406 +    else value = -999;
1407 +  }
1408 +  else if(variable == "correctedD0VertexEEPlus"){
1409 +    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
1410 +    else value = -999;
1411 +  }
1412 +
1413 +  else if(variable == "correctedD0BeamspotInEBPlus"){
1414 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1415 +    else value = -999;
1416 +  }
1417 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
1418 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1419 +    else value = -999;
1420 +  }
1421 +  else if(variable == "correctedD0BeamspotEEPlus"){
1422 +    if(object->isEE && object->eta > 0) value = object->correctedD0;
1423 +    else value = -999;
1424 +  }
1425 +
1426 +  else if(variable == "correctedD0VertexInEBMinus"){
1427 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1428 +    else value = -999;
1429 +  }
1430 +  else if(variable == "correctedD0VertexOutEBMinus"){
1431 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1432 +    else value = -999;
1433 +  }
1434 +  else if(variable == "correctedD0VertexEEMinus"){
1435 +    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
1436 +    else value = -999;
1437 +  }
1438 +
1439 +  else if(variable == "correctedD0BeamspotInEBMinus"){
1440 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1441 +    else value = -999;
1442 +  }
1443 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
1444 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1445 +    else value = -999;
1446 +  }
1447 +  else if(variable == "correctedD0BeamspotEEMinus"){
1448 +    if(object->isEE && object->eta < 0) value = object->correctedD0;
1449 +    else value = -999;
1450 +  }
1451 +
1452 +  else if(variable == "tightID"){
1453 +    if (object->isEB)
1454 +      {
1455 +        value = fabs(object->delEtaIn) < 0.004 \
1456 +          && fabs (object->delPhiIn) < 0.03 \
1457 +          && object->scSigmaIEtaIEta < 0.01 \
1458 +          && object->hadOverEm < 0.12 \
1459 +          && fabs (object->correctedD0Vertex) < 0.02 \
1460 +          && fabs (object->correctedDZ) < 0.1 \
1461 +          && object->absInvEMinusInvPin < 0.05 \
1462 +          && object->passConvVeto;
1463 +      }
1464 +    else
1465 +      {
1466 +        value = fabs(object->delEtaIn) < 0.005 \
1467 +          && fabs (object->delPhiIn) < 0.02 \
1468 +          && object->scSigmaIEtaIEta < 0.03 \
1469 +          && object->hadOverEm < 0.10 \
1470 +          && fabs (object->correctedD0Vertex) < 0.02 \
1471 +          && fabs (object->correctedDZ) < 0.1 \
1472 +          && object->absInvEMinusInvPin < 0.05 \
1473 +          && object->passConvVeto;
1474 +      }
1475 +  }
1476 +
1477 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1478 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1479 +    else value = -999;
1480 +  }
1481 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1482 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1483 +    else value = -999;
1484 +  }
1485 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
1486 +    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
1487 +    else value = -999;
1488 +  }
1489 +
1490 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1491 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1492 +    else value = -999;
1493 +  }
1494 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1495 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1496 +    else value = -999;
1497 +  }
1498 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1499 +    if(object->isEE && object->charge > 0) value = object->correctedD0;
1500 +    else value = -999;
1501 +  }
1502 +
1503 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1504 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1505 +    else value = -999;
1506 +  }
1507 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1508 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1509 +    else value = -999;
1510 +  }
1511 +  else if(variable == "correctedD0VertexEENegativeCharge"){
1512 +    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
1513 +    else value = -999;
1514 +  }
1515 +
1516 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1517 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1518 +    else value = -999;
1519 +  }
1520 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1521 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1522 +    else value = -999;
1523 +  }
1524 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1525 +    if(object->isEE && object->charge < 0) value = object->correctedD0;
1526 +    else value = -999;
1527 +  }
1528 +
1529 +
1530 +  else if(variable == "tightIDdisplaced"){
1531 +    if (object->isEB)
1532 +      {
1533 +        value = fabs(object->delEtaIn) < 0.004 \
1534 +          && fabs (object->delPhiIn) < 0.03 \
1535 +          && object->scSigmaIEtaIEta < 0.01 \
1536 +          && object->hadOverEm < 0.12 \
1537 +          && object->absInvEMinusInvPin < 0.05;
1538 +      }
1539 +    else
1540 +      {
1541 +        value = fabs (object->delEtaIn) < 0.005 \
1542 +          && fabs (object->delPhiIn) < 0.02 \
1543 +          && object->scSigmaIEtaIEta < 0.03 \
1544 +          && object->hadOverEm < 0.10 \
1545 +          && object->absInvEMinusInvPin < 0.05;
1546 +      }
1547 +  }
1548 +
1549 +  else if(variable == "genMatchedId"){
1550 +    int index = getGenMatchedParticleIndex(object);
1551 +    if(index == -1) value = 0;
1552 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
1553 +  }
1554 +  else if(variable == "genMatchedMotherId"){
1555 +    int index = getGenMatchedParticleIndex(object);
1556 +    if(index == -1) value = 0;
1557 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1558 +  }
1559 +  else if(variable == "genMatchedGrandmotherId"){
1560 +    int index = getGenMatchedParticleIndex(object);
1561 +    if(index == -1) value = 0;
1562 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1563 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1564 +      if(motherIndex == -1) value = 0;
1565 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1566 +    }
1567 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1568 +  }
1569 +
1570  
1571  
1572    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
# Line 1158 | Line 1646 | OSUAnalysis::valueLookup (const BNevent*
1646    else if(variable == "id1") value = object->id1;
1647    else if(variable == "id2") value = object->id2;
1648    else if(variable == "evt") value = object->evt;
1649 +  else if(variable == "puScaleFactor"){
1650 +    if(datasetType_ != "data")
1651 +      value = puWeight_->at (events->at (0).numTruePV);
1652 +    else
1653 +      value = 1.0;
1654 +  }
1655 +  else if(variable == "muonScaleFactor"){
1656 +    if(datasetType_ != "data")
1657 +      value = muonSFWeight_->at (chosenMuon ()->eta);
1658 +    else
1659 +      value = 1.0;
1660 +  }
1661 +  else if(variable == "electronScaleFactor"){
1662 +    if(datasetType_ != "data")
1663 +      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1664 +    else
1665 +      value = 1.0;
1666 +  }
1667  
1668    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1669  
# Line 1212 | Line 1718 | OSUAnalysis::valueLookup (const BNtau* o
1718    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
1719  
1720  
1721 +  else if(variable == "genMatchedId"){
1722 +    int index = getGenMatchedParticleIndex(object);
1723 +    if(index == -1) value = 0;
1724 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
1725 +  }
1726 +  else if(variable == "genMatchedMotherId"){
1727 +    int index = getGenMatchedParticleIndex(object);
1728 +    if(index == -1) value = 0;
1729 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1730 +  }
1731 +  else if(variable == "genMatchedGrandmotherId"){
1732 +    int index = getGenMatchedParticleIndex(object);
1733 +    if(index == -1) value = 0;
1734 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1735 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1736 +      if(motherIndex == -1) value = 0;
1737 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1738 +    }
1739 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1740 +  }
1741 +
1742 +
1743    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1744  
1745    value = applyFunction(function, value);
# Line 1295 | Line 1823 | double
1823   OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
1824  
1825    double value = 0.0;
1826 +  double pMag = sqrt(object->pt * object->pt +
1827 +                         object->pz * object->pz);
1828  
1829    if(variable == "pt") value = object->pt;
1830    else if(variable == "px") value = object->px;
# Line 1315 | Line 1845 | OSUAnalysis::valueLookup (const BNtrack*
1845    else if(variable == "isHighPurity") value = object->isHighPurity;
1846  
1847  
1848 +  //additional BNs info for disappTrks
1849 +  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
1850 +  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
1851 +  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
1852 +  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
1853 +  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
1854 +  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
1855 +  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
1856 +  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
1857 +  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
1858 +  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
1859 +  //user defined variables
1860 +  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;
1861 +  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
1862 +  else if(variable == "caloTotDeltaRp5") value =(object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
1863 +  else if(variable == "caloTotDeltaRp5ByP") value =( (object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
1864 +  else if(variable == "isIso") value = getTrkIsIso(object, tracks.product());
1865 +  else if(variable == "isMatchedDeadEcal") value = getTrkIsMatchedDeadEcal(object);
1866 +  else if(variable == "ptErrorByPt") value = (object->ptError/object->pt);
1867 +  else if(variable == "ptError") value = object->ptError;
1868 +  else if(variable == "ptRes") value = getTrkPtRes(object);
1869 +
1870 +
1871 +  else if(variable == "genMatchedId"){
1872 +    int index = getGenMatchedParticleIndex(object);
1873 +    if(index == -1) value = 0;
1874 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
1875 +  }
1876 +  else if(variable == "genMatchedMotherId"){
1877 +    int index = getGenMatchedParticleIndex(object);
1878 +    if(index == -1) value = 0;
1879 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1880 +  }
1881 +  else if(variable == "genMatchedGrandmotherId"){
1882 +    int index = getGenMatchedParticleIndex(object);
1883 +    if(index == -1) value = 0;
1884 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1885 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1886 +      if(motherIndex == -1) value = 0;
1887 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1888 +    }
1889 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1890 +  }
1891 +
1892 +
1893 +
1894    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1895  
1896    value = applyFunction(function, value);
# Line 1442 | Line 2018 | OSUAnalysis::valueLookup (const BNmcpart
2018  
2019    //user-defined variables
2020    else if (variable == "d0"){
2021 <    double vx = object->vx - primaryVertex_->x,
2022 <      vy = object->vy - primaryVertex_->y,
2021 >    double vx = object->vx - chosenVertex ()->x,
2022 >      vy = object->vy - chosenVertex ()->y,
2023        px = object->px,
2024        py = object->py,
2025        pt = object->pt;
2026      value = (-vx * py + vy * px) / pt;
2027    }
2028    else if (variable == "dz"){
2029 <    double vx = object->vx - primaryVertex_->x,
2030 <      vy = object->vy - primaryVertex_->y,
2031 <      vz = object->vz - primaryVertex_->z,
2029 >    double vx = object->vx - chosenVertex ()->x,
2030 >      vy = object->vy - chosenVertex ()->y,
2031 >      vz = object->vz - chosenVertex ()->z,
2032        px = object->px,
2033        py = object->py,
2034        pz = object->pz,
2035        pt = object->pt;
2036      value = vz - (vx * px + vy * py)/pt * (pz/pt);
2037    }
2038 <
2038 >  else if(variable == "v0"){
2039 >    value = sqrt(object->vx*object->vx + object->vy*object->vy);
2040 >  }
2041 >  else if(variable == "deltaV0"){
2042 >    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
2043 >  }
2044 >  else if (variable == "deltaVx"){
2045 >    value = object->vx - chosenVertex ()->x;
2046 >  }
2047 >  else if (variable == "deltaVy"){
2048 >    value = object->vy - chosenVertex ()->y;
2049 >  }
2050 >  else if (variable == "deltaVz"){
2051 >    value = object->vz - chosenVertex ()->z;
2052 >  }
2053  
2054  
2055    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
# Line 1589 | Line 2179 | OSUAnalysis::valueLookup (const BNphoton
2179    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2180  
2181  
2182 +  else if(variable == "genMatchedId"){
2183 +    int index = getGenMatchedParticleIndex(object);
2184 +    if(index == -1) value = 0;
2185 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
2186 +  }
2187 +  else if(variable == "genMatchedMotherId"){
2188 +    int index = getGenMatchedParticleIndex(object);
2189 +    if(index == -1) value = 0;
2190 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2191 +  }
2192 +  else if(variable == "genMatchedGrandmotherId"){
2193 +    int index = getGenMatchedParticleIndex(object);
2194 +    if(index == -1) value = 0;
2195 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2196 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2197 +      if(motherIndex == -1) value = 0;
2198 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2199 +    }
2200 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2201 +  }
2202 +
2203 +
2204    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2205  
2206    value = applyFunction(function, value);
# Line 1624 | Line 2236 | OSUAnalysis::valueLookup (const BNmuon*
2236  
2237    double value = 0.0;
2238  
2239 <  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
2239 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2240 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2241    else if(variable == "invMass"){
2242      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2243      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2244      value = (fourVector1 + fourVector2).M();
2245    }
2246 <
2246 >  else if(variable == "threeDAngle")
2247 >    {
2248 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2249 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2250 >      value = (threeVector1.Angle(threeVector2));
2251 >    }
2252 >  else if(variable == "alpha")
2253 >    {
2254 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
2255 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2256 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2257 >      value = (pi-threeVector1.Angle(threeVector2));
2258 >    }
2259 >  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2260 >  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2261 >  else if(variable == "d0Sign"){
2262 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2263 >    if(d0Sign < 0) value = -0.5;
2264 >    else if (d0Sign > 0) value = 0.5;
2265 >    else value = -999;
2266 >  }
2267 >  else if(variable == "chargeProduct"){
2268 >    value = object1->charge*object2->charge;
2269 >  }
2270 >  else if(variable == "muon1CorrectedD0Vertex"){
2271 >    value = object1->correctedD0Vertex;
2272 >  }
2273 >  else if(variable == "muon2CorrectedD0Vertex"){
2274 >    value = object2->correctedD0Vertex;
2275 >  }
2276 > else if(variable == "muon1timeAtIpInOut"){
2277 >    value = object1->timeAtIpInOut;
2278 >  }
2279 > else if(variable == "muon2timeAtIpInOut"){
2280 >    value = object2->timeAtIpInOut;
2281 >  }
2282    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2283  
2284    value = applyFunction(function, value);
# Line 1643 | Line 2291 | OSUAnalysis::valueLookup (const BNelectr
2291  
2292    double value = 0.0;
2293  
2294 <  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
2294 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2295 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2296    else if(variable == "invMass"){
2297      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2298      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2299      value = (fourVector1 + fourVector2).M();
2300    }
2301 +  else if(variable == "threeDAngle")
2302 +    {
2303 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2304 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2305 +      value = (threeVector1.Angle(threeVector2));
2306 +    }
2307 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2308 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2309 +  else if(variable == "d0Sign"){
2310 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2311 +    if(d0Sign < 0) value = -0.5;
2312 +    else if (d0Sign > 0) value = 0.5;
2313 +    else value = -999;
2314 +  }
2315 +  else if(variable == "chargeProduct"){
2316 +    value = object1->charge*object2->charge;
2317 +  }
2318 +  else if(variable == "electron1CorrectedD0Vertex"){
2319 +    value = object1->correctedD0Vertex;
2320 +  }
2321 +  else if(variable == "electron2CorrectedD0Vertex"){
2322 +    value = object2->correctedD0Vertex;
2323 +  }
2324  
2325    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2326  
# Line 1662 | Line 2334 | OSUAnalysis::valueLookup (const BNelectr
2334  
2335    double value = 0.0;
2336  
2337 <  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
2337 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2338 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2339    else if(variable == "invMass"){
2340      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2341      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2342      value = (fourVector1 + fourVector2).M();
2343    }
2344 +  else if(variable == "threeDAngle")
2345 +    {
2346 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2347 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2348 +      value = (threeVector1.Angle(threeVector2));
2349 +    }
2350 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2351 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2352 +  else if(variable == "d0Sign"){
2353 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2354 +    if(d0Sign < 0) value = -0.5;
2355 +    else if (d0Sign > 0) value = 0.5;
2356 +    else value = -999;
2357 +  }
2358 +  else if(variable == "chargeProduct"){
2359 +    value = object1->charge*object2->charge;
2360 +  }
2361 +  else if(variable == "electronCorrectedD0Vertex"){
2362 +    value = object1->correctedD0Vertex;
2363 +  }
2364 +  else if(variable == "muonCorrectedD0Vertex"){
2365 +    value = object2->correctedD0Vertex;
2366 +  }
2367 +  else if(variable == "electronCorrectedD0"){
2368 +    value = object1->correctedD0;
2369 +  }
2370 +  else if(variable == "muonCorrectedD0"){
2371 +    value = object2->correctedD0;
2372 +  }
2373 +  else if(variable == "electronDetIso"){
2374 +    value = (object1->trackIso) / object1->pt;
2375 +  }
2376 +  else if(variable == "muonDetIso"){
2377 +    value = (object2->trackIsoDR03) / object2->pt;
2378 +  }
2379 +  else if(variable == "chargeProduct"){
2380 +    value = object1->charge * object2->charge;
2381 +  }
2382 +
2383  
2384    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2385  
# Line 1677 | Line 2389 | OSUAnalysis::valueLookup (const BNelectr
2389   }
2390  
2391  
2392 + // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
2393 + // Return true iff no other tracks are found in this cone.
2394 + int
2395 + OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
2396 +  for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
2397 +    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
2398 +    double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
2399 +    if(deltaRtrk < 0.5) return 0;
2400 +  }
2401 +  return 1;
2402 +
2403 + }
2404 +
2405 +
2406 + double
2407 + OSUAnalysis::getTrkPtRes (const BNtrack* track1){
2408 +
2409 +  double ptTrue = getTrkPtTrue(track1, mcparticles.product());
2410 +  double PtRes = (track1->pt - ptTrue) / ptTrue;
2411 +
2412 +  return PtRes;
2413 +
2414 + }
2415 +
2416 +
2417 + double
2418 + OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
2419 +  double value = -99;
2420 +  double genDeltaRLowest = 999;
2421 +
2422 +  for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
2423 +    double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
2424 +    if (genDeltaRtemp < genDeltaRLowest) {
2425 +      genDeltaRLowest = genDeltaRtemp;
2426 +      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
2427 +        double ptTrue = genPart->pt;
2428 +        value = ptTrue;
2429 +      }
2430 +    }
2431 +  }
2432 +
2433 +  return value;
2434 +
2435 + }
2436 +
2437 + //creates a map of the dead Ecal channels in the barrel and endcap
2438 + //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
2439 + //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
2440 + void
2441 + OSUAnalysis::WriteDeadEcal (){
2442 +  double etaEcal, phiEcal;
2443 +  ifstream DeadEcalFile(deadEcalFile_);
2444 +  if(!DeadEcalFile) {
2445 +    cout << "Error: DeadEcalFile has not been found." << endl;
2446 +    return;
2447 +  }
2448 +  if(DeadEcalVec.size()!= 0){
2449 +    cout << "Error: DeadEcalVec has a nonzero size" << endl;
2450 +    return;
2451 +  }
2452 +  while(!DeadEcalFile.eof())
2453 +    {
2454 +      DeadEcalFile >> etaEcal >> phiEcal;
2455 +      DeadEcal newChan;
2456 +      newChan.etaEcal = etaEcal;
2457 +      newChan.phiEcal = phiEcal;
2458 +      DeadEcalVec.push_back(newChan);
2459 +    }
2460 +  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
2461 + }
2462 +
2463 + //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
2464 + int
2465 + OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
2466 +  double deltaRLowest = 999;
2467 +  int value = 0;
2468 +  if (DeadEcalVec.size() == 0) WriteDeadEcal();
2469 +  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
2470 +    double eta = ecal->etaEcal;
2471 +    double phi = ecal->phiEcal;
2472 +    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
2473 +    if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
2474 +  }
2475 +  if (deltaRLowest<0.05) {value = 1;}
2476 +  else {value = 0;}
2477 +  return value;
2478 + }
2479 +
2480 +
2481 +
2482 +
2483   double
2484   OSUAnalysis::applyFunction(string function, double value){
2485  
2486    if(function == "abs") value = fabs(value);
2487 +  else if(function == "fabs") value = fabs(value);
2488 +  else if(function == "log10") value = log10(value);
2489 +  else if(function == "log") value = log10(value);
2490  
2491 +  else if(function == "") value = value;
2492 +  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
2493  
2494    return value;
2495  
# Line 1691 | Line 2499 | OSUAnalysis::applyFunction(string functi
2499   template <class InputCollection>
2500   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
2501  
2502 +
2503    for (uint object = 0; object != inputCollection->size(); object++){
2504  
2505 +
2506      bool decision = true;//object passes if this cut doesn't cut on that type of object
2507  
2508 +
2509      if(currentCut.inputCollection == inputType){
2510  
2511        vector<bool> subcutDecisions;
2512        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
2513 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
2514 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
2513 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
2514 >        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
2515        }
2516        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
2517        else{
2518 <        bool tempDecision = true;
2519 <        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
2520 <          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
2521 <            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
2522 <          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
2518 >        bool tempDecision = true;
2519 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
2520 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
2521 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
2522 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
2523              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
2524 <        }
2525 <        decision = tempDecision;
2524 >        }
2525 >        decision = tempDecision;
2526        }
2527      }
2528      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
2529  
2530 +
2531      //set flags for objects that pass each cut AND all the previous cuts
2532      bool previousCumulativeFlag = true;
2533      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
# Line 1724 | Line 2536 | void OSUAnalysis::setObjectFlags(cut &cu
2536      }
2537      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
2538  
2539 +
2540    }
2541  
2542   }
# Line 1731 | Line 2544 | void OSUAnalysis::setObjectFlags(cut &cu
2544  
2545   template <class InputCollection1, class InputCollection2>
2546   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
2547 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, string inputType){
2547 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
2548  
2549  
2550    bool sameObjects = false;
2551    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
2552  
2553 <  int counter = 0;  
2553 >
2554 >  int counter = 0;
2555    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
2556      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
2557 <      
2557 >
2558        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
2559  
2560  
# Line 1748 | Line 2562 | void OSUAnalysis::setObjectFlags(cut &cu
2562  
2563        if(currentCut.inputCollection == inputType){
2564  
2565 <        vector<bool> subcutDecisions;
2566 <        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
2567 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
2568 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
2569 <        }
2570 <
2571 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
2572 <        else{
2573 <          bool tempDecision = true;
2574 <          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
2575 <            if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
2576 <              tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
2577 <            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
2578 <              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
2579 <          }
2580 <          decision = tempDecision;
2581 <        }
2565 >        vector<bool> subcutDecisions;
2566 >        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
2567 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
2568 >          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
2569 >        }
2570 >
2571 >        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
2572 >        else{
2573 >          bool tempDecision = subcutDecisions.at(0);
2574 >          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
2575 >            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
2576 >              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
2577 >            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
2578 >              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
2579 >          }
2580 >          decision = tempDecision;
2581 >        }
2582        }
2583        individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
2584 <      
2584 >
2585        //set flags for objects that pass each cut AND all the previous cuts
2586        bool previousCumulativeFlag = true;
2587        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
2588 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
2589 <        else{ previousCumulativeFlag = false; break;}
2588 >        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
2589 >        else{ previousCumulativeFlag = false; break;}
2590        }
2591 <      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
2591 >      //apply flags for the components of the composite object as well
2592 >      bool currentCumulativeFlag = true;
2593 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
2594 >      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
2595 >      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
2596 >      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
2597 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
2598  
2599 <      counter++;      
2599 >      counter++;
2600      }
2601 <    
2601 >
2602    }
2603  
2604  
# Line 1786 | Line 2606 | void OSUAnalysis::setObjectFlags(cut &cu
2606  
2607  
2608   template <class InputCollection>
2609 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
2609 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
2610  
2611    for (uint object = 0; object != inputCollection->size(); object++){
2612  
# Line 1796 | Line 2616 | void OSUAnalysis::fill1DHistogram(TH1* h
2616      string inputVariable = "";
2617      string function = "";
2618      if(currentString.find("(")==std::string::npos){
2619 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
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 ")"                                                                                                    
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  
2627      double value = valueLookup(&inputCollection->at(object), inputVariable, function);
2628 <    histo->Fill(value,puScaleFactor);
2628 >    histo->Fill(value,scaleFactor);
2629  
2630    }
2631  
2632   }
2633  
2634   template <class InputCollection1, class InputCollection2>
2635 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
2635 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
2636  
2637    bool sameObjects = false;
2638    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
2639  
2640 <  int counter = 0;  
2640 >  int pairCounter = 0;
2641    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
2642      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
2643 <      
2643 >
2644        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
2645  
2646        //only take objects which have passed all cuts and pairs which have passed all cuts
2647        if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
2648        if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
2649 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(counter)) continue;
2649 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
2650  
2651        string currentString = parameters.inputVariables.at(0);
2652        string inputVariable = "";
2653        string function = "";
2654        if(currentString.find("(")==std::string::npos){
2655 <        inputVariable = currentString;// variable to cut on                                                                                                          
2655 >        inputVariable = currentString;// variable to cut on
2656        }
2657        else{
2658 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
2659 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
2660 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
2658 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
2659 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
2660 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
2661        }
2662 <      
2662 >
2663        double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
2664 <      histo->Fill(value,puScaleFactor);
2664 >      histo->Fill(value,scaleFactor);
2665  
2666 <      counter++;      
2666 >      pairCounter++;
2667      }
2668    }
2669  
# Line 1851 | Line 2671 | void OSUAnalysis::fill1DHistogram(TH1* h
2671  
2672  
2673   template <class InputCollection>
2674 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
2674 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
2675  
2676    for (uint object = 0; object != inputCollection->size(); object++){
2677  
# Line 1861 | Line 2681 | void OSUAnalysis::fill2DHistogram(TH2* h
2681      string inputVariable = "";
2682      string function = "";
2683      if(currentString.find("(")==std::string::npos){
2684 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
2684 >      inputVariable = currentString;// variable to cut on
2685      }
2686      else{
2687 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
2688 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
2689 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
2687 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
2688 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
2689 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
2690      }
2691      double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
2692  
# Line 1874 | Line 2694 | void OSUAnalysis::fill2DHistogram(TH2* h
2694      inputVariable = "";
2695      function = "";
2696      if(currentString.find("(")==std::string::npos){
2697 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
2697 >      inputVariable = currentString;// variable to cut on
2698      }
2699      else{
2700 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
2701 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
2702 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
2700 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
2701 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
2702 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
2703      }
2704  
2705      double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
2706  
2707 <    histo->Fill(valueX,valueY,puScaleFactor);
2707 >    histo->Fill(valueX,valueY,scaleFactor);
2708  
2709    }
2710  
2711   }
2712  
2713   template <class InputCollection1, class InputCollection2>
2714 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
2714 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
2715  
2716    bool sameObjects = false;
2717    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
2718  
2719 <  int counter = 0;  
2719 >  int pairCounter = 0;
2720    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
2721      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
2722 <      
2722 >
2723        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
2724  
2725        //only take objects which have passed all cuts and pairs which have passed all cuts
2726        if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
2727        if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
2728 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(counter)) continue;
2728 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
2729  
2730        string currentString = parameters.inputVariables.at(0);
2731        string inputVariable = "";
2732        string function = "";
2733        if(currentString.find("(")==std::string::npos){
2734 <        inputVariable = currentString;// variable to cut on                                                                                                          
2734 >        inputVariable = currentString;// variable to cut on
2735        }
2736        else{
2737 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
2738 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
2739 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
2737 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
2738 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
2739 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
2740        }
2741        double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
2742  
# Line 1924 | Line 2744 | void OSUAnalysis::fill2DHistogram(TH2* h
2744        inputVariable = "";
2745        function = "";
2746        if(currentString.find("(")==std::string::npos){
2747 <        inputVariable = currentString;// variable to cut on                                                                                                          
2747 >        inputVariable = currentString;// variable to cut on
2748        }
2749        else{
2750 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
2751 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
2752 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
2750 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
2751 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
2752 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
2753        }
2754        double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
2755  
2756  
2757 <      histo->Fill(valueX,valueY,puScaleFactor);
2757 >      histo->Fill(valueX,valueY,scaleFactor);
2758 >
2759 >      pairCounter++;
2760  
1939      counter++;      
2761      }
2762    }
2763  
2764   }
2765  
2766  
2767 + template <class InputObject>
2768 + int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
2769 +
2770 +  int bestMatchIndex = -1;
2771 +  double bestMatchDeltaR = 999;
2772 +
2773 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
2774 +
2775 +    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
2776 +    if(currentDeltaR > 0.05) continue;
2777 + //     cout << std::setprecision(3) << std::setw(20)
2778 + //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
2779 + //          << std::setw(20)
2780 + //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
2781 + //          << std::setw(20)
2782 + //          << "\tdeltaR = " << currentDeltaR
2783 + //          << std::setprecision(1)
2784 + //          << std::setw(20)
2785 + //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
2786 + //          << std::setw(20)
2787 + //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
2788 + //          << std::setw(20)
2789 + //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
2790 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
2791 +      bestMatchIndex = mcparticle - mcparticles->begin();
2792 +      bestMatchDeltaR = currentDeltaR;
2793 +    }
2794 +
2795 +  }
2796 + //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
2797 + //   else cout << "no match found..." << endl;
2798 +  return bestMatchIndex;
2799 +
2800 + }
2801  
1947 DEFINE_FWK_MODULE(OSUAnalysis);
2802  
2803 + int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
2804 +
2805 +  int bestMatchIndex = -1;
2806 +  double bestMatchDeltaR = 999;
2807 +
2808 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
2809 +
2810 +    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
2811 +
2812 +    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
2813 +    if(currentDeltaR > 0.05) continue;
2814 +
2815 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
2816 +      bestMatchIndex = mcparticle - mcparticles->begin();
2817 +      bestMatchDeltaR = currentDeltaR;
2818 +    }
2819 +
2820 +  }
2821 +
2822 +  return bestMatchIndex;
2823 + }
2824  
2825 +
2826 + // bin      particle type
2827 + // ---      -------------
2828 + //  0        unmatched
2829 + //  1        u
2830 + //  2        d
2831 + //  3        s
2832 + //  4        c
2833 + //  5        b
2834 + //  6        t
2835 + //  7        e
2836 + //  8        mu
2837 + //  9        tau
2838 + // 10        nu
2839 + // 11        g
2840 + // 12        gamma
2841 + // 13        Z
2842 + // 14        W
2843 + // 15        light meson
2844 + // 16        K meson
2845 + // 17        D meson
2846 + // 18        B meson
2847 + // 19        light baryon
2848 + // 20        strange baryon
2849 + // 21        charm baryon
2850 + // 22        bottom baryon
2851 + // 23        other
2852 +
2853 + int OSUAnalysis::getPdgIdBinValue(int pdgId){
2854 +
2855 +  int binValue = -999;
2856 +  int absPdgId = fabs(pdgId);
2857 +  if(pdgId == -1) binValue = 0;
2858 +  else if(absPdgId <= 6 ) binValue = absPdgId;
2859 +  else if(absPdgId == 11 ) binValue = 7;
2860 +  else if(absPdgId == 13 ) binValue = 8;
2861 +  else if(absPdgId == 15 ) binValue = 9;
2862 +  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
2863 +  else if(absPdgId == 21 ) binValue = 11;
2864 +  else if(absPdgId == 22 ) binValue = 12;
2865 +  else if(absPdgId == 23 ) binValue = 13;
2866 +  else if(absPdgId == 24 ) binValue = 14;
2867 +  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
2868 +  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
2869 +  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
2870 +  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
2871 +  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
2872 +  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
2873 +  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
2874 +  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
2875 +
2876 +  else binValue = 23;
2877 +
2878 +  return binValue;
2879 +
2880 + }
2881 +
2882 + const BNprimaryvertex *
2883 + OSUAnalysis::chosenVertex ()
2884 + {
2885 +  const BNprimaryvertex *chosenVertex = 0;
2886 +  if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
2887 +    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
2888 +                               cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
2889 +    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
2890 +      if(!vertexFlags.at(vertexIndex)) continue;
2891 +      chosenVertex = & primaryvertexs->at(vertexIndex);
2892 +      break;
2893 +    }
2894 +  }
2895 +  else {
2896 +    chosenVertex = &primaryvertexs->at(0);
2897 +  }
2898 +
2899 +  return chosenVertex;
2900 + }
2901 +
2902 + const BNmet *
2903 + OSUAnalysis::chosenMET ()
2904 + {
2905 +  const BNmet *chosenMET = 0;
2906 +  if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
2907 +    vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
2908 +                            cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
2909 +    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
2910 +      if(!metFlags.at(metIndex)) continue;
2911 +      chosenMET = & mets->at(metIndex);
2912 +      break;
2913 +    }
2914 +  }
2915 +  else {
2916 +    chosenMET = &mets->at(0);
2917 +  }
2918 +
2919 +  return chosenMET;
2920 + }
2921 +
2922 + const BNelectron *
2923 + OSUAnalysis::chosenElectron ()
2924 + {
2925 +  const BNelectron *chosenElectron = 0;
2926 +  if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
2927 +    vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
2928 +                                 cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
2929 +    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
2930 +      if(!electronFlags.at(electronIndex)) continue;
2931 +      chosenElectron = & electrons->at(electronIndex);
2932 +      break;
2933 +    }
2934 +  }
2935 +  else {
2936 +    chosenElectron = &electrons->at(0);
2937 +  }
2938 +
2939 +  return chosenElectron;
2940 + }
2941 +
2942 + const BNmuon *
2943 + OSUAnalysis::chosenMuon ()
2944 + {
2945 +  const BNmuon *chosenMuon = 0;
2946 +  if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
2947 +    vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
2948 +                             cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
2949 +    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
2950 +      if(!muonFlags.at(muonIndex)) continue;
2951 +      chosenMuon = & muons->at(muonIndex);
2952 +      break;
2953 +    }
2954 +  }
2955 +  else {
2956 +    chosenMuon = &muons->at(0);
2957 +  }
2958 +
2959 +  return chosenMuon;
2960 + }
2961 +
2962 +
2963 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines