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.2 by lantonel, Tue Jan 22 13:50:22 2013 UTC vs.
Revision 1.42 by wulsin, Wed Mar 27 22:38:08 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines