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.8 by ahart, Wed Jan 30 22:29:59 2013 UTC vs.
Revision 1.35 by wulsin, Wed Mar 20 20:19:55 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines