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

Comparing UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc (file contents):
Revision 1.8 by ahart, Wed Jan 30 22:29:59 2013 UTC vs.
Revision 1.58 by ahart, Tue May 7 20:35:02 2013 UTC

# Line 11 | Line 11 | OSUAnalysis::OSUAnalysis (const edm::Par
11    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
12    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
13    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
14 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
15    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
16    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
17    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
18    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
19    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
20 <
21 <
22 <  channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels"))
20 >  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
21 >  puFile_ (cfg.getParameter<string> ("puFile")),
22 >  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
23 >  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
24 >  dataPU_ (cfg.getParameter<string> ("dataPU")),
25 >  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
26 >  muonSF_ (cfg.getParameter<string> ("muonSF")),
27 >  dataset_ (cfg.getParameter<string> ("dataset")),
28 >  datasetType_ (cfg.getParameter<string> ("datasetType")),
29 >  channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
30 >  histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
31 >  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
32 >  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
33 >  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
34 >  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
35 >  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
36 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau"))
37  
38   {
39 +
40    TH1::SetDefaultSumw2 ();
41  
42 +  //create pile-up reweighting object, if necessary
43 +  if(datasetType_ != "data") {
44 +    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
45 +    if (applyLeptonSF_){
46 +      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
47 +      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
48 +    }
49 +  }
50 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
51 +    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
52 +
53 +
54    // Construct Cutflow Objects. These store the results of cut decisions and
55    // handle filling cut flow histograms.
56    masterCutFlow_ = new CutFlow (fs_);
57 <  std::vector<TFileDirectory> directories;
57 >  vector<TFileDirectory> directories;
58 >
59 >  //always get vertex collection so we can assign the primary vertex in the event
60 >  objectsToGet.push_back("primaryvertexs");
61 >
62 >  //always make the plot of number of primary vertices (to check pile-up reweighting)
63 >  objectsToPlot.push_back("primaryvertexs");
64 >
65 >  //always get the MC particles to do GEN-matching
66 >  objectsToGet.push_back("mcparticles");
67 >
68 >  //always get the event collection to do pile-up reweighting
69 >  objectsToGet.push_back("events");
70 >
71 >  //parse the histogram definitions
72 >  for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
73 >
74 >    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
75 >    if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
76 >    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
77 >    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
78 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
79 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
80 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
81 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
82 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
83 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
84 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
85 >        int spaceIndex = tempInputCollection.find(" ");
86 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
87 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
88 >      }
89 >      else{
90 >        objectsToGet.push_back(tempInputCollection);
91 >      }
92 >      objectsToPlot.push_back(tempInputCollection);
93 >      objectsToCut.push_back(tempInputCollection);
94 >    }
95 >    else{//pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
96 >      string obj1;
97 >      string obj2;
98 >      getTwoObjs(tempInputCollection, obj1, obj2);
99 >      string obj2ToGet = getObjToGet(obj2);
100 >      objectsToCut.push_back(tempInputCollection);
101 >      objectsToCut.push_back(obj1);
102 >      objectsToCut.push_back(obj2);
103 >      objectsToPlot.push_back(tempInputCollection);
104 >      objectsToPlot.push_back(obj1);
105 >      objectsToPlot.push_back(obj2);
106 >      objectsToGet.push_back(tempInputCollection);
107 >      objectsToGet.push_back(obj1);
108 >      objectsToGet.push_back(obj2ToGet);
109 >
110 >    }
111 >
112 >    vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
113 >
114 >    for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
115 >
116 >      vector<double> defaultValue;
117 >      defaultValue.push_back (-1.0);
118 >
119 >      histogram tempHistogram;
120 >      tempHistogram.inputCollection = tempInputCollection;
121 >      tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
122 >      tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
123 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
124 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
125 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
126 >      tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
127 >
128 >      histograms.push_back(tempHistogram);
129 >
130 >    }
131 >  }
132 >  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
133 >  sort( objectsToPlot.begin(), objectsToPlot.end() );
134 >  objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
135 >
136 >
137 >
138 >  //add histograms with the gen-matched id, mother id, and grandmother id
139 >  for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
140 >
141 >    string currentObject = objectsToPlot.at(currentObjectIndex);
142 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
143 >
144 >    histogram tempIdHisto;
145 >    histogram tempMomIdHisto;
146 >    histogram tempGmaIdHisto;
147 >    histogram tempIdVsMomIdHisto;
148 >    histogram tempIdVsGmaIdHisto;
149 >
150 >    tempIdHisto.inputCollection = currentObject;
151 >    tempMomIdHisto.inputCollection = currentObject;
152 >    tempGmaIdHisto.inputCollection = currentObject;
153 >    tempIdVsMomIdHisto.inputCollection = currentObject;
154 >    tempIdVsGmaIdHisto.inputCollection = currentObject;
155 >
156 >    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
157 >    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
158 >
159 >    currentObject = currentObject.substr(0, currentObject.size()-1);
160 >    tempIdHisto.name = currentObject+"GenMatchId";
161 >    tempMomIdHisto.name = currentObject+"GenMatchMotherId";
162 >    tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
163 >    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
164 >    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
165 >
166 >    currentObject.at(0) = toupper(currentObject.at(0));
167 >    tempIdHisto.title = currentObject+" Gen-matched Particle";
168 >    tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
169 >    tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
170 >    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
171 >    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
172 >
173 >
174 >    int maxNum = 24;
175 >    vector<double> binVector;
176 >    binVector.push_back(maxNum);
177 >    binVector.push_back(0);
178 >    binVector.push_back(maxNum);
179 >
180 >    tempIdHisto.bins = binVector;
181 >    tempIdHisto.inputVariables.push_back("genMatchedId");
182 >    tempMomIdHisto.bins = binVector;
183 >    tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
184 >    tempGmaIdHisto.bins = binVector;
185 >    tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
186 >    binVector.push_back(maxNum);
187 >    binVector.push_back(0);
188 >    binVector.push_back(maxNum);
189 >    tempIdVsMomIdHisto.bins = binVector;
190 >    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
191 >    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
192 >    tempIdVsGmaIdHisto.bins = binVector;
193 >    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
194 >    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
195 >
196 >    histograms.push_back(tempIdHisto);
197 >    histograms.push_back(tempMomIdHisto);
198 >    histograms.push_back(tempGmaIdHisto);
199 >    histograms.push_back(tempIdVsMomIdHisto);
200 >    histograms.push_back(tempIdVsGmaIdHisto);
201 >  }
202  
203  
204    channel tempChannel;
# Line 46 | Line 218 | OSUAnalysis::OSUAnalysis (const edm::Par
218        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
219        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
220          tempChannel.triggers.push_back(triggerNames.at(trigger));
221 <      allNecessaryObjects.push_back("triggers");
221 >      objectsToGet.push_back("triggers");
222      }
223  
224  
225 +
226 +
227      //create cutFlow for this channel
228      cutFlows_.push_back (new CutFlow (fs_, channelName));
229  
230      //book a directory in the output file with the name of the channel
231      TFileDirectory subDir = fs_->mkdir( channelName );
232      directories.push_back(subDir);
59    std::map<std::string, TH1D*> histoMap;
60    oneDHists_.push_back(histoMap);
233  
234 <    //gen histograms
235 <    oneDHists_.at(currentChannel)["genD0"] = directories.at(currentChannel).make<TH1D> ("genD0",channelLabel+" channel: Gen d_{0}; d_{0} [cm] ", 1000, -1, 1);
236 <    oneDHists_.at(currentChannel)["genAbsD0"] = directories.at(currentChannel).make<TH1D> ("genAbsD0",channelLabel+" channel: Gen d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
237 <    oneDHists_.at(currentChannel)["genDZ"] = directories.at(currentChannel).make<TH1D> ("genDZ",channelLabel+" channel: Gen d_{z}; d_{z} [cm] ", 1000, -10, 10);
66 <    oneDHists_.at(currentChannel)["genAbsDZ"] = directories.at(currentChannel).make<TH1D> ("genAbsDZ",channelLabel+" channel: Gen d_{z}; |d_{z}| [cm] ", 1000, 0, 10);
67 <
68 <    //muon histograms
69 <    allNecessaryObjects.push_back("muons");
70 <    oneDHists_.at(currentChannel)["muonPt"]  = directories.at(currentChannel).make<TH1D> ("muonPt",channelLabel+" channel: Muon Transverse Momentum; p_{T} [GeV]", 100, 0, 500);
71 <    oneDHists_.at(currentChannel)["muonEta"] = directories.at(currentChannel).make<TH1D> ("muonEta",channelLabel+" channel: Muon Eta; #eta", 100, -5, 5);
72 <    oneDHists_.at(currentChannel)["muonD0"] = directories.at(currentChannel).make<TH1D> ("muonD0",channelLabel+" channel: Muon d_{0}; d_{0} [cm] ", 1000, -1, 1);
73 <    oneDHists_.at(currentChannel)["muonDz"] = directories.at(currentChannel).make<TH1D> ("muonDz",channelLabel+" channel: Muon d_{z}; d_{z} [cm] ", 1000, -20, 20);
74 <    oneDHists_.at(currentChannel)["muonAbsD0"] = directories.at(currentChannel).make<TH1D> ("muonAbsD0",channelLabel+" channel: Muon d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
75 <    oneDHists_.at(currentChannel)["muonDZ"] = directories.at(currentChannel).make<TH1D> ("muonDZ",channelLabel+" channel: Muon d_{z}; d_{z} [cm] ", 1000, -10, 10);
76 <    oneDHists_.at(currentChannel)["muonAbsDZ"] = directories.at(currentChannel).make<TH1D> ("muonAbsDZ",channelLabel+" channel: Muon d_{z}; |d_{z}| [cm] ", 1000, 0, 10);
77 <    oneDHists_.at(currentChannel)["muonD0Sig"] = directories.at(currentChannel).make<TH1D> ("muonD0Sig",channelLabel+" channel: Muon d_{0} Significance; d_{0} / #sigma_{d_{0}} ", 1000, -10.0, 10.0);
78 <    oneDHists_.at(currentChannel)["muonAbsD0Sig"] = directories.at(currentChannel).make<TH1D> ("muonAbsD0Sig",channelLabel+" channel: Muon d_{0} Significance; |d_{0}| / #sigma_{d_{0}} ", 1000, 0, 10.0);
79 <    oneDHists_.at(currentChannel)["muonIso"] = directories.at(currentChannel).make<TH1D> ("muonIso",channelLabel+" channel: Muon Combined Relative Isolation; rel. iso. ", 1000, 0, 1);
80 <    oneDHists_.at(currentChannel)["numMuons"] = directories.at(currentChannel).make<TH1D> ("numMuons",channelLabel+" channel: Number of Selected Muons; # muons", 10, 0, 10);
81 <
82 <
83 <    //electron histograms
84 <    allNecessaryObjects.push_back("electrons");
85 <    oneDHists_.at(currentChannel)["electronPt"]  = directories.at(currentChannel).make<TH1D> ("electronPt",channelLabel+" channel: Electron Transverse Momentum; p_{T} [GeV]", 100, 0, 500);
86 <    oneDHists_.at(currentChannel)["electronEta"] = directories.at(currentChannel).make<TH1D> ("electronEta",channelLabel+" channel: Electron Eta; #eta", 50, -5, 5);
87 <    oneDHists_.at(currentChannel)["electronD0"] = directories.at(currentChannel).make<TH1D> ("electronD0",channelLabel+" channel: Electron d_{0}; d_{0} [cm] ", 1000, -1, 1);
88 <    oneDHists_.at(currentChannel)["electronDz"] = directories.at(currentChannel).make<TH1D> ("electronDz",channelLabel+" channel: Electron d_{z}; d_{z} [cm] ", 1000, -20, 20);
89 <    oneDHists_.at(currentChannel)["electronAbsD0"] = directories.at(currentChannel).make<TH1D> ("electronAbsD0",channelLabel+" channel: Electron d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
90 <    oneDHists_.at(currentChannel)["electronDZ"] = directories.at(currentChannel).make<TH1D> ("electronDZ",channelLabel+" channel: Electron d_{z}; d_{z} [cm] ", 1000, -10, 10);
91 <    oneDHists_.at(currentChannel)["electronAbsDZ"] = directories.at(currentChannel).make<TH1D> ("electronAbsDZ",channelLabel+" channel: Electron d_{z}; |d_{z}| [cm] ", 1000, 0, 10);
92 <    oneDHists_.at(currentChannel)["electronD0Sig"] = directories.at(currentChannel).make<TH1D> ("electronD0Sig",channelLabel+" channel: Electron d_{0} Significance; d_{0} / #sigma_{d_{0}} ", 1000, -10.0, 10.0);
93 <    oneDHists_.at(currentChannel)["electronAbsD0Sig"] = directories.at(currentChannel).make<TH1D> ("electronAbsD0Sig",channelLabel+" channel: Electron d_{0} Significance; |d_{0}| / #sigma_{d_{0}} ", 1000, 0, 10.0);
94 <    oneDHists_.at(currentChannel)["electronIso"] = directories.at(currentChannel).make<TH1D> ("electronIso",channelLabel+" channel: Electron Combined Relative Isolation; rel. iso. ", 1000, 0, 1);
95 <    oneDHists_.at(currentChannel)["electronFbrem"] = directories.at(currentChannel).make<TH1D> ("electronFbrem",channelLabel+" channel: Electron Brem. Energy Fraction; fbrem", 1000, 0, 2);
96 <    oneDHists_.at(currentChannel)["electronMVATrig"] = directories.at(currentChannel).make<TH1D> ("electronMVATrig",channelLabel+" channel: Electron ID MVA Output", 100, -1, 1);
97 <    oneDHists_.at(currentChannel)["electronMVANonTrig"] = directories.at(currentChannel).make<TH1D> ("electronMVANonTrig",channelLabel+" channel: Electron ID MVA Output", 100, -1, 1);
98 <    oneDHists_.at(currentChannel)["numElectrons"] = directories.at(currentChannel).make<TH1D> ("numElectrons",channelLabel+" channel: Number of Selected Electrons; # electrons", 10, 0, 10);
234 >    map<string, TH1D*> oneDhistoMap;
235 >    oneDHists_.push_back(oneDhistoMap);
236 >    map<string, TH2D*> twoDhistoMap;
237 >    twoDHists_.push_back(twoDhistoMap);
238  
239  
240  
241 <    //get list of cuts for this channel
242 <    vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
241 >    //book all histograms included in the configuration
242 >    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
243 >      histogram currentHistogram = histograms.at(currentHistogramIndex);
244 >      int numBinsElements = currentHistogram.bins.size();
245 >      int numInputVariables = currentHistogram.inputVariables.size();
246 >      int numBinEdgesX = currentHistogram.variableBinsX.size();
247 >      int numBinEdgesY = currentHistogram.variableBinsY.size();
248 >
249 >      if(numBinsElements == 1){
250 >        if(numBinEdgesX > 1){
251 >          if(numBinEdgesY > 1)
252 >            numBinsElements = 6;
253 >          else
254 >            numBinsElements = 3;
255 >        }
256 >      }
257 >      if(numBinsElements != 3 && numBinsElements !=6){
258 >        cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
259 >        exit(0);
260 >      }
261 >      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
262 >        cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
263 >        exit(0);
264 >      }
265 >      else if(numBinsElements == 3){
266 >        if (currentHistogram.bins.size () == 3)
267 >          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));
268 >        else
269 >          {
270 >            oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
271 >          }
272 >      }
273 >      else if(numBinsElements == 6){
274 >        if (currentHistogram.bins.size () == 6)
275 >          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));
276 >        else
277 >          twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data (), numBinEdgesY - 1, currentHistogram.variableBinsY.data ());
278 >      }
279  
105    vector<string> tempInputCollections;
280  
281 +      if(currentHistogram.name.find("GenMatch")==string::npos) continue;
282 +
283 +      // bin      particle type
284 +      // ---      -------------
285 +      //  0        unmatched
286 +      //  1        u
287 +      //  2        d
288 +      //  3        s
289 +      //  4        c
290 +      //  5        b
291 +      //  6        t
292 +      //  7        e
293 +      //  8        mu
294 +      //  9        tau
295 +      // 10        nu
296 +      // 11        g
297 +      // 12        gamma
298 +      // 13        Z
299 +      // 14        W
300 +      // 15        light meson
301 +      // 16        K meson
302 +      // 17        D meson
303 +      // 18        B meson
304 +      // 19        light baryon
305 +      // 20        strange baryon
306 +      // 21        charm baryon
307 +      // 22        bottom baryon
308 +      // 23        other
309 +
310 +      vector<TString> labelArray;
311 +      labelArray.push_back("unmatched");
312 +      labelArray.push_back("u");
313 +      labelArray.push_back("d");
314 +      labelArray.push_back("s");
315 +      labelArray.push_back("c");
316 +      labelArray.push_back("b");
317 +      labelArray.push_back("t");
318 +      labelArray.push_back("e");
319 +      labelArray.push_back("#mu");
320 +      labelArray.push_back("#tau");
321 +      labelArray.push_back("#nu");
322 +      labelArray.push_back("g");
323 +      labelArray.push_back("#gamma");
324 +      labelArray.push_back("Z");
325 +      labelArray.push_back("W");
326 +      labelArray.push_back("light meson");
327 +      labelArray.push_back("K meson");
328 +      labelArray.push_back("D meson");
329 +      labelArray.push_back("B meson");
330 +      labelArray.push_back("light baryon");
331 +      labelArray.push_back("strange baryon");
332 +      labelArray.push_back("charm baryon");
333 +      labelArray.push_back("bottom baryon");
334 +      labelArray.push_back("other");
335 +
336 +      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
337 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
338 +          oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
339 +        }
340 +        else {
341 +          twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
342 +          twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
343 +        }
344 +      }
345 +      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
346 +        twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->CenterTitle();
347 +        twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->CenterTitle();
348 +      }
349 +
350 +    }
351 +
352 +    // Book a histogram for the number of each object type to be plotted.
353 +    // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
354 +    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
355 +      string currentObject = objectsToPlot.at(currentObjectIndex);
356 +      int maxNum = 10;
357 +      if(currentObject == "mcparticles") maxNum = 50;
358 +      else if(currentObject == "primaryvertexs") maxNum = 50;
359 +
360 +      if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
361 +      else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
362 +      else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
363 +      else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
364 +      else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
365 +      else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
366 +      else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
367 +      else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
368 +      else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
369 +      else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
370 +      else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
371 +      else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
372 +      else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
373 +      else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
374 +      else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
375 +      else if(currentObject == "secondary electrons")           currentObject = "secondaryElectrons";
376 +      else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
377 +      else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
378 +
379 +      currentObject.at(0) = toupper(currentObject.at(0));
380 +      string histoName = "num" + currentObject;
381 +
382 +      if(histoName == "numPrimaryvertexs"){
383 +        string newHistoName = histoName + "BeforePileupCorrection";
384 +        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
385 +        newHistoName = histoName + "AfterPileupCorrection";
386 +        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
387 +      }
388 +      else
389 +        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
390 +    }
391 +
392 +
393 +
394 +
395 +    //get list of cuts for this channel
396 +    vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
397  
398      //loop over and parse all cuts
399      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
110
400        cut tempCut;
401 <     //store input collection for cut
402 <      string inputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
403 <      tempCut.inputCollection = inputCollection;
401 >      //store input collection for cut
402 >      string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
403 >      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
404 >      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
405 >      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
406 >      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
407 >      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
408 >      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
409 >      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
410 >      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
411 >      tempCut.inputCollection = tempInputCollection;
412 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
413 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
414 >          int spaceIndex = tempInputCollection.find(" ");
415 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
416 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
417 >        }
418 >        else{
419 >          objectsToGet.push_back(tempInputCollection);
420 >        }
421 >        objectsToCut.push_back(tempInputCollection);
422 >      }
423 >      else{//pair of objects, need to add them both to objectsToGet
424 >        string obj1;
425 >        string obj2;
426 >        getTwoObjs(tempInputCollection, obj1, obj2);
427 >        string obj2ToGet = getObjToGet(obj2);
428 >        objectsToCut.push_back(tempInputCollection);
429 >        objectsToCut.push_back(obj1);
430 >        objectsToCut.push_back(obj2);
431 >        objectsToGet.push_back(tempInputCollection);
432 >        objectsToGet.push_back(obj1);
433 >        objectsToGet.push_back(obj2ToGet);
434 >
435 >      }
436 >
437  
116      tempInputCollections.push_back(inputCollection);
117      allNecessaryObjects.push_back(inputCollection);
438  
439        //split cut string into parts and store them
440        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
441 <      std::vector<string> cutStringVector = splitString(cutString);
442 <      tempCut.variable = cutStringVector.at(0);// variable to cut on
443 <      tempCut.comparativeOperator = cutStringVector.at(1);// comparison to make
444 <      tempCut.cutValue = atof(cutStringVector.at(2).c_str());// threshold value to pass cut
441 >      vector<string> cutStringVector = splitString(cutString);
442 >      if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
443 >        cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
444 >        exit(0);
445 >      }
446 >      tempCut.numSubcuts = (cutStringVector.size()+1)/4;
447 >      for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
448 >        int indexOffset = 4 * subcutIndex;
449 >        string currentVariableString = cutStringVector.at(indexOffset);
450 >        if(currentVariableString.find("(")==string::npos){
451 >          tempCut.functions.push_back("");//no function was specified
452 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
453 >        }
454 >        else{
455 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
456 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
457 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
458 >        }
459 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
460 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
461 >        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
462 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
463 >      }
464  
465        //get number of objects required to pass cut for event to pass
466        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
467 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
467 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
468 >      if(numberRequiredVector.size()!=2){
469 >        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
470 >        exit(0);
471 >      }
472  
130      // determine number required if comparison contains "="
473        int numberRequiredInt = atoi(numberRequiredVector.at(1).c_str());
132      if(numberRequiredVector.at(0) == ">") numberRequiredInt++;
133      else if(numberRequiredVector.at(0) == "<") numberRequiredInt--;
134
474        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
475        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
476  
477 <      if(cuts_.at(currentCut).exists("function")){
139 <        tempCut.function = cuts_.at(currentCut).getParameter<string> ("function");
140 <      }
141 <      else tempCut.function = "";
477 >
478        string tempCutName;
479        if(cuts_.at(currentCut).exists("alias")){
480          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
# Line 146 | Line 482 | OSUAnalysis::OSUAnalysis (const edm::Par
482        else{
483          //construct string for cutflow table
484          bool plural = numberRequiredInt != 1;
485 <        string collectionString = plural ? inputCollection : inputCollection.substr(0, inputCollection.size()-1);
485 >        string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
486          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
487          tempCutName = cutName;
488        }
489        tempCut.name = tempCutName;
490  
155
491        tempChannel.cuts.push_back(tempCut);
492  
493  
494      }//end loop over cuts
495  
161    //make unique vector of all objects that this channel cuts on (so we know to set flags for those)
162    sort( tempInputCollections.begin(), tempInputCollections.end() );
163    tempInputCollections.erase( unique( tempInputCollections.begin(), tempInputCollections.end() ), tempInputCollections.end() );
164    tempChannel.inputCollections = tempInputCollections;
165
496      channels.push_back(tempChannel);
497      tempChannel.cuts.clear();
498  
499    }//end loop over channels
500  
501 <  //make unique vector of objects we need to cut on (so we make sure to get them from the event)
502 <  sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
503 <  allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
501 >
502 >  //make unique vector of objects we need to get from the event
503 >  sort( objectsToGet.begin(), objectsToGet.end() );
504 >  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
505 >  //make unique vector of objects we need to cut on
506 >  sort( objectsToCut.begin(), objectsToCut.end() );
507 >  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
508  
509  
510   }
# Line 188 | Line 522 | void
522   OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
523   {
524  
191
525    // Retrieve necessary collections from the event.
526 <  edm::Handle<BNtriggerCollection> triggers;
527 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
526 >
527 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
528      event.getByLabel (triggers_, triggers);
529  
530 <  edm::Handle<BNjetCollection> jets;
531 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())
530 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
531 >    event.getByLabel (trigobjs_, trigobjs);
532 >
533 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
534      event.getByLabel (jets_, jets);
535  
536 <  edm::Handle<BNmuonCollection> muons;
202 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())
536 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
537      event.getByLabel (muons_, muons);
538  
539 <  edm::Handle<BNelectronCollection> electrons;
206 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())
539 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
540      event.getByLabel (electrons_, electrons);
541  
542 <  edm::Handle<BNeventCollection> events;
210 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())
542 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
543      event.getByLabel (events_, events);
544  
545 <  edm::Handle<BNtauCollection> taus;
214 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())
545 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
546      event.getByLabel (taus_, taus);
547  
548 <  edm::Handle<BNmetCollection> mets;
218 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())
548 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
549      event.getByLabel (mets_, mets);
550  
551 <  edm::Handle<BNtrackCollection> tracks;
222 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())
551 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
552      event.getByLabel (tracks_, tracks);
553  
554 <  edm::Handle<BNgenjetCollection> genjets;
226 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())
554 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
555      event.getByLabel (genjets_, genjets);
556  
557 <  edm::Handle<BNmcparticleCollection> mcparticles;
230 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())
557 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
558      event.getByLabel (mcparticles_, mcparticles);
559  
560 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
234 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())
560 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
561      event.getByLabel (primaryvertexs_, primaryvertexs);
562  
563 <  edm::Handle<BNbxlumiCollection> bxlumis;
238 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())
563 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
564      event.getByLabel (bxlumis_, bxlumis);
565  
566 <  edm::Handle<BNphotonCollection> photons;
242 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())
566 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
567      event.getByLabel (photons_, photons);
568  
569 <  edm::Handle<BNsuperclusterCollection> superclusters;
246 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())
569 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
570      event.getByLabel (superclusters_, superclusters);
571  
572 +  if (datasetType_ == "signalMC"){
573 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
574 +      event.getByLabel (stops_, stops);
575 +  }
576 +
577 +  if (useTrackCaloRhoCorr_) {
578 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
579 +    // This rho collection is not available in all BEANs.
580 +    // For description of rho values for different jet reconstruction algorithms, see
581 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
582 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
583 +  }
584 +
585 +  double masterScaleFactor = 1.0;
586 +
587 +  //get pile-up event weight
588 +  if(doPileupReweighting_ && datasetType_ != "data") masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
589 +
590 +  stopCTauScaleFactor_ = 1.0;
591 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
592 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
593 +  masterScaleFactor *= stopCTauScaleFactor_;
594  
595    //loop over all channels
596  
# Line 253 | Line 598 | OSUAnalysis::analyze (const edm::Event &
598      channel currentChannel = channels.at(currentChannelIndex);
599  
600      flagMap individualFlags;
256    flagMap cumulativeFlags;
601      counterMap passingCounter;
602 +    cumulativeFlags.clear ();
603  
604      bool triggerDecision = true;
605      if(currentChannel.triggers.size() != 0){  //triggers specified
# Line 263 | Line 608 | OSUAnalysis::analyze (const edm::Event &
608      }
609  
610      //loop over all cuts
611 +
612      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
613        cut currentCut = currentChannel.cuts.at(currentCutIndex);
614  
615 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
615 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
616 >        string currentObject = objectsToCut.at(currentObjectIndex);
617  
618 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
618 >        //initialize maps to get ready to set cuts
619          individualFlags[currentObject].push_back (vector<bool> ());
620          cumulativeFlags[currentObject].push_back (vector<bool> ());
621  
622 +      }
623 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
624 +        string currentObject = objectsToCut.at(currentObjectIndex);
625 +
626 +        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
627 +
628 +
629          if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
630 +
631          else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
632 +
633 +        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
634 +        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
635          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
636          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
637          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 285 | Line 643 | OSUAnalysis::analyze (const edm::Event &
643          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
644          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
645          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
646 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
647  
648  
290      }
649  
650 +        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
651 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
652 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
653 +                                                                   "muon-muon pairs");
654 +
655 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
656 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
657 +                                                                   cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
658 +                                                                   "muon-secondary muon pairs");
659 +
660 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
661 +                                                                   cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
662 +                                                                   cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
663 +                                                                   "electron-secondary electron pairs");
664 +
665 +        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
666 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
667 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
668 +                                                                           "electron-electron pairs");
669 +        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
670 +                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
671 +                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
672 +                                                                       "electron-muon pairs");
673 +        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
674 +                                                                           cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
675 +                                                                           cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
676 +                                                                           "jet-jet pairs");
677 +        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
678 +                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
679 +                                                                       cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
680 +                                                                       "electron-jet pairs");
681 +        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
682 +                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
683 +                                                                       cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
684 +                                                                       "muon-jet pairs");
685 +        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
686 +                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
687 +                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
688 +                                                                     "track-event pairs");
689 +        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
690 +                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
691 +                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
692 +                                                                        "electron-track pairs");
693 +        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
694 +                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
695 +                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
696 +                                                                    "muon-track pairs");
697 +        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
698 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
699 +                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
700 +                                                                  "muon-tau pairs");
701 +        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
702 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
703 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
704 +                                                                 "tau-tau pairs");
705 +        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
706 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
707 +                                                                 cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
708 +                                                                 "tau-track pairs");
709 +        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
710 +                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
711 +                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
712 +                                                                          "electron-trigobj pairs");
713 +        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
714 +                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
715 +                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
716 +                                                                      "muon-trigobj pairs");
717  
718 +        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
719 +      }
720  
294    }//end loop over all cuts
721  
722  
723 +    }//end loop over all cuts
724  
725  
726      //use cumulative flags to apply cuts at event level
# Line 310 | Line 737 | OSUAnalysis::analyze (const edm::Event &
737        cut currentCut = currentChannel.cuts.at(currentCutIndex);
738        int numberPassing = 0;
739  
740 <      for (uint object = 0; object != cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).size() ; object++)
741 <          if(cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).at(object)) numberPassing++;
742 <
316 <
740 >      for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
741 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
742 >      }
743        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
744        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
319
745        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
746  
747      }
748  
749 <    cutFlows_.at(currentChannelIndex)->fillCutFlow();
749 >    double scaleFactor = masterScaleFactor;
750  
751 +    if(applyLeptonSF_ && datasetType_ != "data"){
752 +      if (chosenMuon ()) scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
753 +      if (chosenElectron ()) scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
754 +    }
755  
756 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
757  
758      if(!eventPassedAllCuts)continue;
759  
760 <
761 <    TVector3 vertexPosition;
762 <    vector<bool> vertexFlags = cumulativeFlags["primaryvertexs"].back();
763 <
764 <    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
765 <      if(!vertexFlags.at(vertexIndex)) continue;
766 <
337 <      vertexPosition.SetXYZ (primaryvertexs->at(vertexIndex).x,primaryvertexs->at(vertexIndex).y,primaryvertexs->at(vertexIndex).z);
338 <      break;
760 >    if (printEventInfo_) {
761 >      // Write information about event to screen, for testing purposes.
762 >      cout << "Event passed all cuts in channel " <<  currentChannel.name
763 >           << ": run="  << events->at(0).run
764 >           << "  lumi=" << events->at(0).lumi
765 >           << "  event=" << events->at(0).evt
766 >           << endl;
767      }
768  
769 <    vector<bool> mcparticleFlags = cumulativeFlags["mcparticles"].back();
770 <
771 <    for (uint mcparticleIndex = 0; mcparticleIndex != mcparticleFlags.size(); mcparticleIndex++){
772 <      if(!mcparticleFlags.at(mcparticleIndex)) continue;
773 <
774 <      double vx = mcparticles->at(mcparticleIndex).vx - vertexPosition.X (),
775 <             vy = mcparticles->at(mcparticleIndex).vy - vertexPosition.Y (),
776 <             vz = mcparticles->at(mcparticleIndex).vz - vertexPosition.Z (),
777 <             px = mcparticles->at(mcparticleIndex).px,
778 <             py = mcparticles->at(mcparticleIndex).py,
779 <             pt = mcparticles->at(mcparticleIndex).pt,
780 <             d0;
781 <
782 <      d0 = (-vx * py + vy * px) / pt;
783 <      oneDHists_.at(currentChannelIndex)["genD0"]->Fill (d0);
784 <      oneDHists_.at(currentChannelIndex)["genAbsD0"]->Fill (fabs (d0));
785 <      oneDHists_.at(currentChannelIndex)["genDZ"]->Fill (vz);
786 <      oneDHists_.at(currentChannelIndex)["genAbsDZ"]->Fill (fabs (vz));
769 >    //filling histograms
770 >    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
771 >      histogram currentHistogram = histograms.at(histogramIndex);
772 >
773 >      if(currentHistogram.inputVariables.size() == 1){
774 >        TH1D* histo;
775 >        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
776 >
777 >        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
778 >        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
779 >        else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").back(),scaleFactor);
780 >        else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").back(),scaleFactor);
781 >        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
782 >                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
783 >                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
784 >        else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
785 >                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("secondary muons").back(), \
786 >                                                                                       cumulativeFlags.at("muon-secondary muon pairs").back(),scaleFactor);
787 >        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
788 >        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
789 >                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
790 >                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
791 >        else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
792 >                                                                                               cumulativeFlags.at("jets").back(),cumulativeFlags.at("jets").back(),\
793 >                                                                                               cumulativeFlags.at("jet-jet pairs").back(),scaleFactor);
794 >        else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
795 >                                                                                       cumulativeFlags.at("electrons").back(),cumulativeFlags.at("secondary electrons").back(), \
796 >                                                                                       cumulativeFlags.at("electron-secondary electron pairs").back(),scaleFactor);
797 >        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
798 >                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
799 >                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
800 >        else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
801 >                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("jets").back(),
802 >                                                                                           cumulativeFlags.at("electron-jet pairs").back(),scaleFactor);
803 >        else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
804 >                                                                                           cumulativeFlags.at("muons").back(),cumulativeFlags.at("jets").back(),
805 >                                                                                           cumulativeFlags.at("muon-jet pairs").back(),scaleFactor);
806 >        else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
807 >                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),
808 >                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);
809 >        else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
810 >                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),
811 >                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);
812 >        else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
813 >                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),
814 >                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);
815 >        else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
816 >                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),
817 >                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);
818 >        else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
819 >                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("tracks").back(),
820 >                                                                                     cumulativeFlags.at("tau-track pairs").back(),scaleFactor);
821 >        else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
822 >                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("trigobjs").back(),
823 >                                                                                              cumulativeFlags.at("electron-trigobj pairs").back(),scaleFactor);
824 >        else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
825 >                                                                                          cumulativeFlags.at("muons").back(),cumulativeFlags.at("trigobjs").back(),
826 >                                                                                          cumulativeFlags.at("muon-trigobj pairs").back(),scaleFactor);
827 >
828 >        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
829 >        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
830 >        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
831 >        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
832 >        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
833 >        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
834 >        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
835 >        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
836 >        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
837 >        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
838 >        else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").back(),scaleFactor);
839 >        else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").back(),scaleFactor);
840 >      }
841 >      else if(currentHistogram.inputVariables.size() == 2){
842 >        TH2D* histo;
843 >        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
844 >
845 >        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
846 >        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
847 >        else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").back(),scaleFactor);
848 >        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
849 >                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
850 >                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
851 >        else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
852 >                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("secondary muons").back(), \
853 >                                                                                       cumulativeFlags.at("muon-secondary muon pairs").back(),scaleFactor);
854 >        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
855 >        else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").back(),scaleFactor);
856 >        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
857 >                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
858 >                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
859 >        else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
860 >                                                                                               cumulativeFlags.at("jets").back(),cumulativeFlags.at("jets").back(), \
861 >                                                                                               cumulativeFlags.at("jet-jet pairs").back(),scaleFactor);
862 >        else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
863 >                                                                                       cumulativeFlags.at("electrons").back(),cumulativeFlags.at("secondary electrons").back(), \
864 >                                                                                       cumulativeFlags.at("electron-secondary electron pairs").back(),scaleFactor);
865 >        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
866 >                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
867 >                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
868 >        else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
869 >                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("jets").back(), \
870 >                                                                                           cumulativeFlags.at("electron-jet pairs").back(),scaleFactor);
871 >        else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
872 >                                                                                           cumulativeFlags.at("muons").back(),cumulativeFlags.at("jets").back(), \
873 >                                                                                           cumulativeFlags.at("muon-jet pairs").back(),scaleFactor);
874 >        else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
875 >                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),
876 >                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);
877 >        else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
878 >                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),
879 >                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);
880 >        else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
881 >                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),
882 >                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);
883 >        else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
884 >                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),
885 >                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);
886 >        else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
887 >                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("tracks").back(),
888 >                                                                                     cumulativeFlags.at("tau-track pairs").back(),scaleFactor);
889 >        else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
890 >                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("trigobjs").back(),
891 >                                                                                              cumulativeFlags.at("electron-trigobj pairs").back(),scaleFactor);
892 >        else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
893 >                                                                                          cumulativeFlags.at("muons").back(),cumulativeFlags.at("trigobjs").back(),
894 >                                                                                          cumulativeFlags.at("muon-trigobj pairs").back(),scaleFactor);
895 >        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
896 >        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
897 >        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
898 >        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
899 >        else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
900 >                                                                                         cumulativeFlags.at("tracks").back(),cumulativeFlags.at("events").back(),
901 >                                                                                         cumulativeFlags.at("track-event pairs").back(),scaleFactor);
902 >        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
903 >        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
904 >        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
905 >        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
906 >        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
907 >        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
908 >        else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").back(),scaleFactor);
909 >        else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").back(),scaleFactor);
910 >      }
911      }
912  
361    vector<bool> electronFlags = cumulativeFlags["electrons"].back();
362    int electronCounter = 0;
913  
364    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
365      if(!electronFlags.at(electronIndex)) continue;
366
367
368      electronCounter++;
369      oneDHists_.at(currentChannelIndex)["electronPt"]->Fill (electrons->at(electronIndex).pt);
370      oneDHists_.at(currentChannelIndex)["electronEta"]->Fill (electrons->at(electronIndex).eta);
371      oneDHists_.at(currentChannelIndex)["electronD0"]->Fill (electrons->at(electronIndex).correctedD0Vertex);
372      oneDHists_.at(currentChannelIndex)["electronDz"]->Fill (electrons->at(electronIndex).correctedDZ);
373      oneDHists_.at(currentChannelIndex)["electronAbsD0"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex));
374      oneDHists_.at(currentChannelIndex)["electronDZ"]->Fill (electrons->at(electronIndex).correctedDZ);
375      oneDHists_.at(currentChannelIndex)["electronAbsDZ"]->Fill (fabs(electrons->at(electronIndex).correctedDZ));
376      oneDHists_.at(currentChannelIndex)["electronD0Sig"]->Fill (electrons->at(electronIndex).correctedD0Vertex / electrons->at(electronIndex).tkD0err);
377      oneDHists_.at(currentChannelIndex)["electronAbsD0Sig"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex) / electrons->at(electronIndex).tkD0err);
378      oneDHists_.at(currentChannelIndex)["electronIso"]->Fill (electrons->at(electronIndex).puChargedHadronIso / electrons->at(electronIndex).pt);
379      oneDHists_.at(currentChannelIndex)["electronFbrem"]->Fill (electrons->at(electronIndex).fbrem);
380      oneDHists_.at(currentChannelIndex)["electronMVATrig"]->Fill (electrons->at(electronIndex).mvaTrigV0);
381      oneDHists_.at(currentChannelIndex)["electronMVANonTrig"]->Fill (electrons->at(electronIndex).mvaNonTrigV0);
914  
915 <    }
916 <    oneDHists_.at(currentChannelIndex)["numElectrons"]->Fill (electronCounter);
915 >    //fills histograms with the sizes of collections
916 >    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
917  
918 +      string currentObject = objectsToPlot.at(currentObjectIndex);
919  
920 <    vector<bool> muonFlags = cumulativeFlags["muons"].back();
388 <    int muonCounter = 0;
920 >      string objectToPlot = "";
921  
922 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
923 +      if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
924 +      else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
925 +      else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
926 +      else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
927 +      else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
928 +      else if(currentObject == "jet-jet pairs")            objectToPlot = "dijetPairs";
929 +      else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
930 +      else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
931 +      else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
932 +      else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
933 +      else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
934 +      else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
935 +      else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
936 +      else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
937 +      else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
938 +      else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
939 +      else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
940 +      else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
941 +      else objectToPlot = currentObject;
942 +
943 +      string tempCurrentObject = objectToPlot;
944 +      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
945 +      string histoName = "num" + tempCurrentObject;
946 +
947 +      //set position of primary vertex in event, in order to calculate quantities relative to it
948 +      if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
949 +        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
950 +        int numToPlot = 0;
951 +        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
952 +          if(lastCutFlags.at(currentFlag)) numToPlot++;
953 +        }
954 +        if(objectToPlot == "primaryvertexs"){
955 +          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
956 +          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
957 +        }
958 +        else {
959 +          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
960 +        }
961 +      }
962 +      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
963 +      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
964 +      else if(objectToPlot == "secondaryMuons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
965 +      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
966 +      else if(objectToPlot == "muonSecondaryMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
967 +      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
968 +      else if(objectToPlot == "secondaryElectrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
969 +      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
970 +      else if(objectToPlot == "electronSecondaryElectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
971 +      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
972 +      else if(objectToPlot == "electronJetPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*jets->size(),scaleFactor);
973 +      else if(objectToPlot == "muonJetPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*jets->size(),scaleFactor);
974 +      else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
975 +      else if(objectToPlot == "electronTrigobjPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*trigobjs->size(),scaleFactor);
976 +      else if(objectToPlot == "muonTrigobjPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*trigobjs->size(),scaleFactor);
977 +      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
978 +      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
979 +      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
980 +      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
981 +      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
982 +      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
983 +      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
984 +      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
985 +      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
986 +      else if(objectToPlot == "trigobjs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(trigobjs->size(),scaleFactor);
987 +      else if(objectToPlot == "primaryvertexs"){
988 +        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
989 +        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
990 +      }
991 +      if(objectToPlot == "stops" && datasetType_ == "signalMC") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(stops->size(),scaleFactor);
992  
993 <    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
392 <      if(!muonFlags.at(muonIndex)) continue;
393 <      muonCounter++;
993 >    } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
994  
995 <      oneDHists_.at(currentChannelIndex)["muonPt"]->Fill (muons->at(muonIndex).pt);
396 <      oneDHists_.at(currentChannelIndex)["muonEta"]->Fill (muons->at(muonIndex).eta);
397 <      oneDHists_.at(currentChannelIndex)["muonD0"]->Fill (muons->at(muonIndex).correctedD0Vertex);
398 <      oneDHists_.at(currentChannelIndex)["muonDz"]->Fill (muons->at(muonIndex).correctedDZ);
399 <      oneDHists_.at(currentChannelIndex)["muonAbsD0"]->Fill (fabs(muons->at(muonIndex).correctedD0Vertex));
400 <      oneDHists_.at(currentChannelIndex)["muonDZ"]->Fill (muons->at(muonIndex).correctedDZ);
401 <      oneDHists_.at(currentChannelIndex)["muonAbsDZ"]->Fill (fabs(muons->at(muonIndex).correctedDZ));
402 <      oneDHists_.at(currentChannelIndex)["muonD0Sig"]->Fill (muons->at(muonIndex).correctedD0Vertex / muons->at(muonIndex).tkD0err);
403 <      oneDHists_.at(currentChannelIndex)["muonAbsD0Sig"]->Fill (fabs(muons->at(muonIndex).correctedD0Vertex) / muons->at(muonIndex).tkD0err);
404 <      oneDHists_.at(currentChannelIndex)["muonIso"]->Fill (muons->at(muonIndex).puChargedHadronIso / muons->at(muonIndex).pt);
405 <    }
406 <    oneDHists_.at(currentChannelIndex)["numMuons"]->Fill (muonCounter);
995 >  } //end loop over channel
996  
997 +  masterCutFlow_->fillCutFlow(masterScaleFactor);
998  
999 + } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1000  
1001  
1002  
1003 <  } //end loop over channel
1003 > bool
1004 > OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
1005  
414  masterCutFlow_->fillCutFlow();
1006  
1007 +  if(comparison == ">")       return testValue >  cutValue;
1008 +  else if(comparison == ">=") return testValue >= cutValue;
1009 +  else if(comparison == "<")  return testValue <  cutValue;
1010 +  else if(comparison == "<=") return testValue <= cutValue;
1011 +  else if(comparison == "==") return testValue == cutValue;
1012 +  else if(comparison == "=") return testValue == cutValue;
1013 +  else if(comparison == "!=") return testValue != cutValue;
1014 +  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1015  
1016   }
1017  
419
1018   bool
1019 < OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
1019 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1020  
1021  
1022    if(comparison == ">")       return testValue >  cutValue;
# Line 426 | Line 1024 | OSUAnalysis::evaluateComparison (double
1024    else if(comparison == "<")  return testValue <  cutValue;
1025    else if(comparison == "<=") return testValue <= cutValue;
1026    else if(comparison == "==") return testValue == cutValue;
1027 +  else if(comparison == "=") return testValue == cutValue;
1028    else if(comparison == "!=") return testValue != cutValue;
1029 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1029 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1030  
1031   }
1032  
# Line 441 | Line 1040 | OSUAnalysis::evaluateTriggers (vector<st
1040        if(trigger->pass != 1) continue;
1041        for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1042          {
1043 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1043 >          if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos){
1044              triggerDecision = true;
1045            }
1046          }
# Line 450 | Line 1049 | OSUAnalysis::evaluateTriggers (vector<st
1049  
1050   }
1051  
1052 < std::vector<std::string>
1052 > vector<string>
1053   OSUAnalysis::splitString (string inputString){
1054  
1055 <  std::stringstream stringStream(inputString);
1056 <  std::istream_iterator<std::string> begin(stringStream);
1057 <  std::istream_iterator<std::string> end;
1058 <  std::vector<std::string> stringVector(begin, end);
1055 >  stringstream stringStream(inputString);
1056 >  istream_iterator<string> begin(stringStream);
1057 >  istream_iterator<string> end;
1058 >  vector<string> stringVector(begin, end);
1059    return stringVector;
1060  
1061   }
1062  
1063 +
1064 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1065 +  // Set two object strings from the tempInputCollection string,
1066 +  // For example, if tempInputCollection is "electron-muon pairs",
1067 +  // then obj1 = "electrons" and obj2 = "muons".
1068 +  // Note that the objects have an "s" appended.
1069 +
1070 +  int dashIndex = tempInputCollection.find("-");
1071 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1072 +  int secondWordLength = spaceIndex - dashIndex;
1073 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1074 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1075 +
1076 + }
1077 +
1078 +
1079 + string OSUAnalysis::getObjToGet(string obj) {
1080 +  // Return the string corresponding to the object to get for the given obj string.
1081 +  // Right now this only handles the case in which obj contains "secondary",
1082 +  // e.g, "secondary muons".
1083 +  // Note that "s" is NOT appended.
1084 +
1085 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1086 +  int firstSpaceIndex = obj.find_first_of(" ");
1087 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1088 +
1089 + }
1090 +
1091 +
1092 + //!jet valueLookup
1093   double
1094 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1094 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1095  
1096    double value = 0.0;
1097    if(variable == "energy") value = object->energy;
# Line 582 | Line 1211 | OSUAnalysis::valueLookup (const BNjet* o
1211    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1212  
1213  
1214 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1214 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1215  
1216    value = applyFunction(function, value);
1217  
# Line 590 | Line 1219 | OSUAnalysis::valueLookup (const BNjet* o
1219   }
1220  
1221  
1222 <
1222 > //!muon valueLookup
1223   double
1224 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1224 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1225  
1226    double value = 0.0;
1227    if(variable == "energy") value = object->energy;
# Line 608 | Line 1237 | OSUAnalysis::valueLookup (const BNmuon*
1237    else if(variable == "ecalIso") value = object->ecalIso;
1238    else if(variable == "hcalIso") value = object->hcalIso;
1239    else if(variable == "caloIso") value = object->caloIso;
1240 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
1240 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
1241    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
1242    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
1243    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 746 | Line 1375 | OSUAnalysis::valueLookup (const BNmuon*
1375    else if(variable == "numberOfMatchedStations") value = object->numberOfMatchedStations;
1376    else if(variable == "time_ndof") value = object->time_ndof;
1377  
1378 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1378 >  //user-defined variables
1379 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1380 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1381 >  else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1382 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1383 >  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1384 >  else if(variable == "metMT") {
1385 >    const BNmet *met = chosenMET ();
1386 >    if (met)
1387 >      {
1388 >        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1389 >          p2 (met->px, met->py, 0.0, met->pt);
1390 >
1391 >        value = (p1 + p2).Mt ();
1392 >      }
1393 >    else
1394 >      value = -999;
1395 >  }
1396 >
1397 >
1398 >
1399 >  else if(variable == "correctedD0VertexInEBPlus"){
1400 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1401 >    else value = -999;
1402 >  }
1403 >  else if(variable == "correctedD0VertexOutEBPlus"){
1404 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1405 >    else value = -999;
1406 >  }
1407 >  else if(variable == "correctedD0VertexEEPlus"){
1408 >    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1409 >    else value = -999;
1410 >  }
1411 >
1412 >  else if(variable == "correctedD0BeamspotInEBPlus"){
1413 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1414 >    else value = -999;
1415 >  }
1416 >  else if(variable == "correctedD0BeamspotOutEBPlus"){
1417 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1418 >    else value = -999;
1419 >  }
1420 >  else if(variable == "correctedD0BeamspotEEPlus"){
1421 >    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1422 >    else value = -999;
1423 >  }
1424 >
1425 >  else if(variable == "correctedD0VertexInEBMinus"){
1426 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1427 >    else value = -999;
1428 >  }
1429 >  else if(variable == "correctedD0VertexOutEBMinus"){
1430 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1431 >    else value = -999;
1432 >  }
1433 >  else if(variable == "correctedD0VertexEEMinus"){
1434 >    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1435 >    else value = -999;
1436 >  }
1437 >
1438 >  else if(variable == "correctedD0BeamspotInEBMinus"){
1439 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1440 >    else value = -999;
1441 >  }
1442 >  else if(variable == "correctedD0BeamspotOutEBMinus"){
1443 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1444 >    else value = -999;
1445 >  }
1446 >  else if(variable == "correctedD0BeamspotEEMinus"){
1447 >    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1448 >    else value = -999;
1449 >  }
1450 >
1451 >
1452 >  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1453 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1454 >    else value = -999;
1455 >  }
1456 >  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1457 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1458 >    else value = -999;
1459 >  }
1460 >  else if(variable == "correctedD0VertexEEPositiveCharge"){
1461 >    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1462 >    else value = -999;
1463 >  }
1464 >
1465 >  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1466 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1467 >    else value = -999;
1468 >  }
1469 >  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1470 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1471 >    else value = -999;
1472 >  }
1473 >  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1474 >    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1475 >    else value = -999;
1476 >  }
1477 >
1478 >  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1479 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1480 >    else value = -999;
1481 >  }
1482 >  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1483 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1484 >    else value = -999;
1485 >  }
1486 >  else if(variable == "correctedD0VertexEENegativeCharge"){
1487 >    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1488 >    else value = -999;
1489 >  }
1490 >
1491 >  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1492 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1493 >    else value = -999;
1494 >  }
1495 >  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1496 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1497 >    else value = -999;
1498 >  }
1499 >  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1500 >    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1501 >    else value = -999;
1502 >  }
1503 >
1504 >
1505 >  else if(variable == "tightID") {
1506 >    value = object->isGlobalMuon > 0                \
1507 >      && object->isPFMuon > 0                        \
1508 >      && object->normalizedChi2 < 10                \
1509 >                                  && object->numberOfValidMuonHits > 0        \
1510 >      && object->numberOfMatchedStations > 1        \
1511 >      && fabs(object->correctedD0Vertex) < 0.2        \
1512 >      && fabs(object->correctedDZ) < 0.5        \
1513 >      && object->numberOfValidPixelHits > 0                \
1514 >      && object->numberOfLayersWithMeasurement > 5;
1515 >  }
1516 >  else if(variable == "tightIDdisplaced"){
1517 >    value = object->isGlobalMuon > 0                \
1518 >      && object->normalizedChi2 < 10                \
1519 >                                  && object->numberOfValidMuonHits > 0        \
1520 >      && object->numberOfMatchedStations > 1        \
1521 >      && object->numberOfValidPixelHits > 0        \
1522 >      && object->numberOfLayersWithMeasurement > 5;
1523 >  }
1524 >
1525 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1526 >
1527 >  else if(variable == "genMatchedPdgId"){
1528 >    int index = getGenMatchedParticleIndex(object);
1529 >    if(index == -1) value = 0;
1530 >    else value = mcparticles->at(index).id;
1531 >  }
1532 >
1533 >  else if(variable == "genMatchedId"){
1534 >    int index = getGenMatchedParticleIndex(object);
1535 >    if(index == -1) value = 0;
1536 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
1537 >  }
1538 >  else if(variable == "genMatchedMotherId"){
1539 >    int index = getGenMatchedParticleIndex(object);
1540 >    if(index == -1) value = 0;
1541 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1542 >  }
1543 >  else if(variable == "genMatchedMotherIdReverse"){
1544 >    int index = getGenMatchedParticleIndex(object);
1545 >    if(index == -1) value = 23;
1546 >    else value = 23 - getPdgIdBinValue(mcparticles->at(index).motherId);
1547 >  }
1548 >  else if(variable == "genMatchedGrandmotherId"){
1549 >    int index = getGenMatchedParticleIndex(object);
1550 >    if(index == -1) value = 0;
1551 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1552 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1553 >      if(motherIndex == -1) value = 0;
1554 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1555 >    }
1556 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1557 >  }
1558 >  else if(variable == "genMatchedGrandmotherIdReverse"){
1559 >    int index = getGenMatchedParticleIndex(object);
1560 >    if(index == -1) value = 23;
1561 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1562 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1563 >      if(motherIndex == -1) value = 23;
1564 >      else value = 23 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1565 >    }
1566 >    else value = 23 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1567 >  }
1568 >
1569 >
1570 >
1571 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1572  
1573    value = applyFunction(function, value);
1574  
1575    return value;
1576   }
1577  
1578 <
1578 > //!electron valueLookup
1579   double
1580 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1580 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1581  
1582    double value = 0.0;
1583    if(variable == "energy") value = object->energy;
# Line 915 | Line 1737 | OSUAnalysis::valueLookup (const BNelectr
1737    else if(variable == "eidHyperTight4MC") value = object->eidHyperTight4MC;
1738    else if(variable == "passConvVeto") value = object->passConvVeto;
1739  
1740 +  //user-defined variables
1741 +  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1742 +  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1743 +  else if(variable == "detIso") value = (object->trackIso) / object->pt;
1744 +  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1745 +  else if(variable == "metMT") {
1746 +    const BNmet *met = chosenMET ();
1747 +    if (met)
1748 +      {
1749 +        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1750 +          p2 (met->px, met->py, 0.0, met->pt);
1751 +
1752 +        value = (p1 + p2).Mt ();
1753 +      }
1754 +    else
1755 +      value = -999;
1756 +  }
1757 +
1758 +  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
1759 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
1760 +    else value = -999;
1761 +  }
1762 +  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
1763 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
1764 +    else value = -999;
1765 +  }
1766 +
1767 +  else if(variable == "correctedD0VertexInEBPlus"){
1768 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1769 +    else value = -999;
1770 +  }
1771 +  else if(variable == "correctedD0VertexOutEBPlus"){
1772 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1773 +    else value = -999;
1774 +  }
1775 +  else if(variable == "correctedD0VertexEEPlus"){
1776 +    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
1777 +    else value = -999;
1778 +  }
1779 +
1780 +  else if(variable == "correctedD0BeamspotInEBPlus"){
1781 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1782 +    else value = -999;
1783 +  }
1784 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
1785 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1786 +    else value = -999;
1787 +  }
1788 +  else if(variable == "correctedD0BeamspotEEPlus"){
1789 +    if(object->isEE && object->eta > 0) value = object->correctedD0;
1790 +    else value = -999;
1791 +  }
1792 +
1793 +  else if(variable == "correctedD0VertexInEBMinus"){
1794 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1795 +    else value = -999;
1796 +  }
1797 +  else if(variable == "correctedD0VertexOutEBMinus"){
1798 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1799 +    else value = -999;
1800 +  }
1801 +  else if(variable == "correctedD0VertexEEMinus"){
1802 +    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
1803 +    else value = -999;
1804 +  }
1805 +
1806 +  else if(variable == "correctedD0BeamspotInEBMinus"){
1807 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1808 +    else value = -999;
1809 +  }
1810 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
1811 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1812 +    else value = -999;
1813 +  }
1814 +  else if(variable == "correctedD0BeamspotEEMinus"){
1815 +    if(object->isEE && object->eta < 0) value = object->correctedD0;
1816 +    else value = -999;
1817 +  }
1818 +
1819 +  else if(variable == "tightID"){
1820 +    if (object->isEB)
1821 +      {
1822 +        value = fabs(object->delEtaIn) < 0.004 \
1823 +          && fabs (object->delPhiIn) < 0.03 \
1824 +          && object->scSigmaIEtaIEta < 0.01 \
1825 +          && object->hadOverEm < 0.12 \
1826 +          && fabs (object->correctedD0Vertex) < 0.02 \
1827 +          && fabs (object->correctedDZ) < 0.1 \
1828 +          && object->absInvEMinusInvPin < 0.05 \
1829 +          && object->passConvVeto;
1830 +      }
1831 +    else
1832 +      {
1833 +        value = fabs(object->delEtaIn) < 0.005 \
1834 +          && fabs (object->delPhiIn) < 0.02 \
1835 +          && object->scSigmaIEtaIEta < 0.03 \
1836 +          && object->hadOverEm < 0.10 \
1837 +          && fabs (object->correctedD0Vertex) < 0.02 \
1838 +          && fabs (object->correctedDZ) < 0.1 \
1839 +          && object->absInvEMinusInvPin < 0.05 \
1840 +          && object->passConvVeto;
1841 +      }
1842 +  }
1843 +
1844 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1845 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1846 +    else value = -999;
1847 +  }
1848 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1849 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1850 +    else value = -999;
1851 +  }
1852 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
1853 +    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
1854 +    else value = -999;
1855 +  }
1856 +
1857 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1858 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1859 +    else value = -999;
1860 +  }
1861 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1862 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1863 +    else value = -999;
1864 +  }
1865 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1866 +    if(object->isEE && object->charge > 0) value = object->correctedD0;
1867 +    else value = -999;
1868 +  }
1869 +
1870 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1871 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1872 +    else value = -999;
1873 +  }
1874 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1875 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1876 +    else value = -999;
1877 +  }
1878 +  else if(variable == "correctedD0VertexEENegativeCharge"){
1879 +    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
1880 +    else value = -999;
1881 +  }
1882 +
1883 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1884 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1885 +    else value = -999;
1886 +  }
1887 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1888 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1889 +    else value = -999;
1890 +  }
1891 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1892 +    if(object->isEE && object->charge < 0) value = object->correctedD0;
1893 +    else value = -999;
1894 +  }
1895 +
1896 +
1897 +  else if(variable == "tightIDdisplaced"){
1898 +    if (object->isEB)
1899 +      {
1900 +        value = fabs(object->delEtaIn) < 0.004 \
1901 +          && fabs (object->delPhiIn) < 0.03 \
1902 +          && object->scSigmaIEtaIEta < 0.01 \
1903 +          && object->hadOverEm < 0.12 \
1904 +          && object->absInvEMinusInvPin < 0.05;
1905 +      }
1906 +    else
1907 +      {
1908 +        value = fabs (object->delEtaIn) < 0.005 \
1909 +          && fabs (object->delPhiIn) < 0.02 \
1910 +          && object->scSigmaIEtaIEta < 0.03 \
1911 +          && object->hadOverEm < 0.10 \
1912 +          && object->absInvEMinusInvPin < 0.05;
1913 +      }
1914 +  }
1915  
1916 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1916 >
1917 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1918 >
1919 >  else if(variable == "genMatchedPdgId"){
1920 >    int index = getGenMatchedParticleIndex(object);
1921 >    if(index == -1) value = 0;
1922 >    else value = mcparticles->at(index).id;
1923 >  }
1924 >
1925 >
1926 >  else if(variable == "genMatchedId"){
1927 >    int index = getGenMatchedParticleIndex(object);
1928 >    if(index == -1) value = 0;
1929 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
1930 >  }
1931 >  else if(variable == "genMatchedMotherId"){
1932 >    int index = getGenMatchedParticleIndex(object);
1933 >    if(index == -1) value = 0;
1934 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1935 >  }
1936 >  else if(variable == "genMatchedMotherIdReverse"){
1937 >    int index = getGenMatchedParticleIndex(object);
1938 >    if(index == -1) value = 23;
1939 >    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1940 >  }
1941 >  else if(variable == "genMatchedGrandmotherId"){
1942 >    int index = getGenMatchedParticleIndex(object);
1943 >    if(index == -1) value = 0;
1944 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1945 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1946 >      if(motherIndex == -1) value = 0;
1947 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1948 >    }
1949 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1950 >  }
1951 >  else if(variable == "genMatchedGrandmotherIdReverse"){
1952 >    int index = getGenMatchedParticleIndex(object);
1953 >    if(index == -1) value = 23;
1954 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1955 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1956 >      if(motherIndex == -1) value = 23;
1957 >      else value = 23 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1958 >    }
1959 >    else value = 23 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1960 >  }
1961 >
1962 >
1963 >
1964 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1965  
1966    value = applyFunction(function, value);
1967  
1968    return value;
1969   }
1970  
1971 <
1971 > //!event valueLookup
1972   double
1973 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
1973 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
1974  
1975    double value = 0.0;
1976  
# Line 993 | Line 2038 | OSUAnalysis::valueLookup (const BNevent*
2038    else if(variable == "id1") value = object->id1;
2039    else if(variable == "id2") value = object->id2;
2040    else if(variable == "evt") value = object->evt;
2041 +  else if(variable == "puScaleFactor"){
2042 +    if(datasetType_ != "data")
2043 +      value = puWeight_->at (events->at (0).numTruePV);
2044 +    else
2045 +      value = 1.0;
2046 +  }
2047 +  else if(variable == "muonScaleFactor"){
2048 +    if(datasetType_ != "data" && applyLeptonSF_)
2049 +      value = muonSFWeight_->at (chosenMuon ()->eta);
2050 +    else
2051 +      value = 1.0;
2052 +  }
2053 +  else if(variable == "electronScaleFactor"){
2054 +    if(datasetType_ != "data" && applyLeptonSF_)
2055 +      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
2056 +    else
2057 +      value = 1.0;
2058 +  }
2059 +  else if(variable == "stopCTauScaleFactor")
2060 +    value = stopCTauScaleFactor_;
2061  
2062 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2062 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2063  
2064    value = applyFunction(function, value);
2065  
2066    return value;
2067   }
2068  
2069 + //!tau valueLookup
2070   double
2071 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2071 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2072  
2073    double value = 0.0;
2074  
# Line 1047 | Line 2113 | OSUAnalysis::valueLookup (const BNtau* o
2113    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2114  
2115  
2116 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2116 >
2117 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2118 >
2119 >  else if(variable == "genMatchedPdgId"){
2120 >    int index = getGenMatchedParticleIndex(object);
2121 >    if(index == -1) value = 0;
2122 >    else value = mcparticles->at(index).id;
2123 >  }
2124 >
2125 >  else if(variable == "genMatchedId"){
2126 >    int index = getGenMatchedParticleIndex(object);
2127 >    if(index == -1) value = 0;
2128 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2129 >  }
2130 >  else if(variable == "genMatchedMotherId"){
2131 >    int index = getGenMatchedParticleIndex(object);
2132 >    if(index == -1) value = 0;
2133 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2134 >  }
2135 >  else if(variable == "genMatchedMotherIdReverse"){
2136 >    int index = getGenMatchedParticleIndex(object);
2137 >    if(index == -1) value = 23;
2138 >    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2139 >  }
2140 >  else if(variable == "genMatchedGrandmotherId"){
2141 >    int index = getGenMatchedParticleIndex(object);
2142 >    if(index == -1) value = 0;
2143 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2144 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2145 >      if(motherIndex == -1) value = 0;
2146 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2147 >    }
2148 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2149 >  }
2150 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2151 >    int index = getGenMatchedParticleIndex(object);
2152 >    if(index == -1) value = 23;
2153 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2154 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2155 >      if(motherIndex == -1) value = 23;
2156 >      else value = 23 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2157 >    }
2158 >    else value = 23 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2159 >  }
2160 >
2161 >
2162 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2163  
2164    value = applyFunction(function, value);
2165  
2166    return value;
2167   }
2168  
2169 + //!met valueLookup
2170   double
2171 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2171 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2172  
2173    double value = 0.0;
2174  
# Line 1119 | Line 2232 | OSUAnalysis::valueLookup (const BNmet* o
2232    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2233    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2234  
2235 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2235 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2236  
2237    value = applyFunction(function, value);
2238  
2239    return value;
2240   }
2241  
2242 + //!track valueLookup
2243   double
2244 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2244 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2245  
2246    double value = 0.0;
2247 +  double pMag = sqrt(object->pt * object->pt +
2248 +                     object->pz * object->pz);
2249  
2250    if(variable == "pt") value = object->pt;
2251    else if(variable == "px") value = object->px;
# Line 1150 | Line 2266 | OSUAnalysis::valueLookup (const BNtrack*
2266    else if(variable == "isHighPurity") value = object->isHighPurity;
2267  
2268  
2269 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2269 >  //additional BNs info for disappTrks
2270 >  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2271 >  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2272 >  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2273 >  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2274 >  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2275 >  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2276 >  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2277 >  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2278 >  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2279 >
2280 >
2281 >  //user defined variables
2282 >  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;
2283 >  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2284 >  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2285 >  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2286 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2287 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2288 >  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2289 >  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2290 >  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2291 >  else if(variable == "ptError")                    value = object->ptError;
2292 >  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2293 >  else if (variable == "d0wrtPV"){
2294 >    double vx = object->vx - chosenVertex ()->x,
2295 >      vy = object->vy - chosenVertex ()->y,
2296 >      px = object->px,
2297 >      py = object->py,
2298 >      pt = object->pt;
2299 >    value = (-vx * py + vy * px) / pt;
2300 >  }
2301 >  else if (variable == "dZwrtPV"){
2302 >    double vx = object->vx - chosenVertex ()->x,
2303 >      vy = object->vy - chosenVertex ()->y,
2304 >      vz = object->vz - chosenVertex ()->z,
2305 >      px = object->px,
2306 >      py = object->py,
2307 >      pz = object->pz,
2308 >      pt = object->pt;
2309 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2310 >  }
2311 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2312 >
2313 >  else if(variable == "genMatchedPdgId"){
2314 >    int index = getGenMatchedParticleIndex(object);
2315 >    if(index == -1) value = 0;
2316 >    else value = mcparticles->at(index).id;
2317 >  }
2318 >
2319 >
2320 >  else if(variable == "genMatchedId"){
2321 >    int index = getGenMatchedParticleIndex(object);
2322 >    if(index == -1) value = 0;
2323 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2324 >  }
2325 >  else if(variable == "genMatchedMotherId"){
2326 >    int index = getGenMatchedParticleIndex(object);
2327 >    if(index == -1) value = 0;
2328 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2329 >  }
2330 >  else if(variable == "genMatchedMotherIdReverse"){
2331 >    int index = getGenMatchedParticleIndex(object);
2332 >    if(index == -1) value = 23;
2333 >    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2334 >  }
2335 >  else if(variable == "genMatchedGrandmotherId"){
2336 >    int index = getGenMatchedParticleIndex(object);
2337 >    if(index == -1) value = 0;
2338 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2339 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2340 >      if(motherIndex == -1) value = 0;
2341 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2342 >    }
2343 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2344 >  }
2345 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2346 >    int index = getGenMatchedParticleIndex(object);
2347 >    if(index == -1) value = 23;
2348 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2349 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2350 >      if(motherIndex == -1) value = 23;
2351 >      else value = 23 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2352 >    }
2353 >    else value = 23 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2354 >  }
2355 >
2356 >
2357 >
2358 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2359  
2360    value = applyFunction(function, value);
2361  
2362    return value;
2363   }
2364  
2365 + //!genjet valueLookup
2366   double
2367 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2367 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2368  
2369    double value = 0.0;
2370  
# Line 1178 | Line 2384 | OSUAnalysis::valueLookup (const BNgenjet
2384    else if(variable == "charge") value = object->charge;
2385  
2386  
2387 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2387 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2388  
2389    value = applyFunction(function, value);
2390  
2391    return value;
2392   }
2393  
2394 + //!mcparticle valueLookup
2395   double
2396 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2396 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2397  
2398    double value = 0.0;
2399  
# Line 1275 | Line 2482 | OSUAnalysis::valueLookup (const BNmcpart
2482    else if(variable == "grandMother11Status") value = object->grandMother11Status;
2483    else if(variable == "grandMother11Charge") value = object->grandMother11Charge;
2484  
2485 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2485 >  //user-defined variables
2486 >  else if (variable == "d0"){
2487 >    double vx = object->vx - chosenVertex ()->x,
2488 >      vy = object->vy - chosenVertex ()->y,
2489 >      px = object->px,
2490 >      py = object->py,
2491 >      pt = object->pt;
2492 >    value = (-vx * py + vy * px) / pt;
2493 >  }
2494 >  else if (variable == "dz"){
2495 >    double vx = object->vx - chosenVertex ()->x,
2496 >      vy = object->vy - chosenVertex ()->y,
2497 >      vz = object->vz - chosenVertex ()->z,
2498 >      px = object->px,
2499 >      py = object->py,
2500 >      pz = object->pz,
2501 >      pt = object->pt;
2502 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2503 >  }
2504 >  else if(variable == "v0"){
2505 >    value = sqrt(object->vx*object->vx + object->vy*object->vy);
2506 >  }
2507 >  else if(variable == "deltaV0"){
2508 >    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
2509 >  }
2510 >  else if (variable == "deltaVx"){
2511 >    value = object->vx - chosenVertex ()->x;
2512 >  }
2513 >  else if (variable == "deltaVy"){
2514 >    value = object->vy - chosenVertex ()->y;
2515 >  }
2516 >  else if (variable == "deltaVz"){
2517 >    value = object->vz - chosenVertex ()->z;
2518 >  }
2519 >
2520 >
2521 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2522  
2523    value = applyFunction(function, value);
2524  
2525    return value;
2526   }
2527  
2528 + //!primaryvertex valueLookup
2529   double
2530 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2530 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2531  
2532    double value = 0.0;
2533  
# Line 1302 | Line 2546 | OSUAnalysis::valueLookup (const BNprimar
2546    else if(variable == "isGood") value = object->isGood;
2547  
2548  
2549 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2549 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2550  
2551    value = applyFunction(function, value);
2552  
2553    return value;
2554   }
2555  
2556 + //!bxlumi valueLookup
2557   double
2558 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2558 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2559  
2560    double value = 0.0;
2561  
# Line 1319 | Line 2564 | OSUAnalysis::valueLookup (const BNbxlumi
2564    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2565  
2566  
2567 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2567 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2568  
2569    value = applyFunction(function, value);
2570  
2571    return value;
2572   }
2573  
2574 + //!photon valueLookup
2575   double
2576 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2576 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2577  
2578    double value = 0.0;
2579  
# Line 1402 | Line 2648 | OSUAnalysis::valueLookup (const BNphoton
2648    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2649  
2650  
2651 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2651 >
2652 >
2653 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2654 >
2655 >  else if(variable == "genMatchedPdgId"){
2656 >    int index = getGenMatchedParticleIndex(object);
2657 >    if(index == -1) value = 0;
2658 >    else value = mcparticles->at(index).id;
2659 >  }
2660 >
2661 >
2662 >
2663 >  else if(variable == "genMatchedId"){
2664 >    int index = getGenMatchedParticleIndex(object);
2665 >    if(index == -1) value = 0;
2666 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2667 >  }
2668 >  else if(variable == "genMatchedMotherId"){
2669 >    int index = getGenMatchedParticleIndex(object);
2670 >    if(index == -1) value = 0;
2671 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2672 >  }
2673 >  else if(variable == "genMatchedMotherIdReverse"){
2674 >    int index = getGenMatchedParticleIndex(object);
2675 >    if(index == -1) value = 23;
2676 >    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2677 >  }
2678 >  else if(variable == "genMatchedGrandmotherId"){
2679 >    int index = getGenMatchedParticleIndex(object);
2680 >    if(index == -1) value = 0;
2681 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2682 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2683 >      if(motherIndex == -1) value = 0;
2684 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2685 >    }
2686 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2687 >  }
2688 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2689 >    int index = getGenMatchedParticleIndex(object);
2690 >    if(index == -1) value = 23;
2691 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2692 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2693 >      if(motherIndex == -1) value = 23;
2694 >      else value = 23 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2695 >    }
2696 >    else value = 23 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2697 >  }
2698 >
2699 >
2700 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2701  
2702    value = applyFunction(function, value);
2703  
2704    return value;
2705   }
2706  
2707 + //!supercluster valueLookup
2708   double
2709 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
2709 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
2710  
2711    double value = 0.0;
2712  
# Line 1424 | Line 2720 | OSUAnalysis::valueLookup (const BNsuperc
2720    else if(variable == "theta") value = object->theta;
2721  
2722  
2723 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2723 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2724 >
2725 >  value = applyFunction(function, value);
2726 >
2727 >  return value;
2728 > }
2729 >
2730 > //!trigobj valueLookup
2731 > double
2732 > OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
2733 >
2734 >  double value = 0.0;
2735 >
2736 >  if(variable == "pt") value = object->pt;
2737 >  else if(variable == "eta") value = object->eta;
2738 >  else if(variable == "phi") value = object->phi;
2739 >  else if(variable == "px") value = object->px;
2740 >  else if(variable == "py") value = object->py;
2741 >  else if(variable == "pz") value = object->pz;
2742 >  else if(variable == "et") value = object->et;
2743 >  else if(variable == "energy") value = object->energy;
2744 >  else if(variable == "etTotal") value = object->etTotal;
2745 >  else if(variable == "id") value = object->id;
2746 >  else if(variable == "charge") value = object->charge;
2747 >  else if(variable == "isIsolated") value = object->isIsolated;
2748 >  else if(variable == "isMip") value = object->isMip;
2749 >  else if(variable == "isForward") value = object->isForward;
2750 >  else if(variable == "isRPC") value = object->isRPC;
2751 >  else if(variable == "bx") value = object->bx;
2752 >  else if(variable == "filter") {
2753 >    if ((stringValue = object->filter) == "")
2754 >      stringValue = "none";  // stringValue should only be empty if value is filled
2755 >  }
2756 >
2757 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2758 >
2759 >  value = applyFunction(function, value);
2760 >
2761 >  return value;
2762 > }
2763 >
2764 > //!muon-muon pair valueLookup
2765 > double
2766 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
2767 >
2768 >  double value = 0.0;
2769 >
2770 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2771 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2772 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2773 >  else if(variable == "invMass"){
2774 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2775 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2776 >    value = (fourVector1 + fourVector2).M();
2777 >  }
2778 >  else if(variable == "pt"){
2779 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2780 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2781 >    value = (fourVector1 + fourVector2).Pt();
2782 >  }
2783 >  else if(variable == "threeDAngle")
2784 >    {
2785 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2786 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2787 >      value = (threeVector1.Angle(threeVector2));
2788 >    }
2789 >  else if(variable == "alpha")
2790 >    {
2791 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
2792 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2793 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2794 >      value = (pi-threeVector1.Angle(threeVector2));
2795 >    }
2796 >  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2797 >  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2798 >  else if(variable == "d0Sign"){
2799 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2800 >    if(d0Sign < 0) value = -0.5;
2801 >    else if (d0Sign > 0) value = 0.5;
2802 >    else value = -999;
2803 >  }
2804 >  else if(variable == "chargeProduct"){
2805 >    value = object1->charge*object2->charge;
2806 >  }
2807 >  else if(variable == "muon1CorrectedD0Vertex"){
2808 >    value = object1->correctedD0Vertex;
2809 >  }
2810 >  else if(variable == "muon2CorrectedD0Vertex"){
2811 >    value = object2->correctedD0Vertex;
2812 >  }
2813 >  else if(variable == "muon1timeAtIpInOut"){
2814 >    value = object1->timeAtIpInOut;
2815 >  }
2816 >  else if(variable == "muon2timeAtIpInOut"){
2817 >    value = object2->timeAtIpInOut;
2818 >  }
2819 >  else if(variable == "muon1correctedD0")
2820 >    {
2821 >      value = object1->correctedD0;
2822 >    }
2823 >  else if(variable == "muon2correctedD0")
2824 >    {
2825 >      value = object2->correctedD0;
2826 >    }
2827 >
2828 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2829  
2830    value = applyFunction(function, value);
2831  
2832    return value;
2833   }
2834  
2835 + //!electron-electron pair valueLookup
2836 + double
2837 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
2838 +
2839 +  double value = 0.0;
2840 +
2841 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2842 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2843 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2844 +  else if(variable == "invMass"){
2845 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2846 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2847 +    value = (fourVector1 + fourVector2).M();
2848 +  }
2849 +  else if(variable == "pt"){
2850 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2851 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2852 +    value = (fourVector1 + fourVector2).Pt();
2853 +  }
2854 +  else if(variable == "threeDAngle")
2855 +    {
2856 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2857 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2858 +      value = (threeVector1.Angle(threeVector2));
2859 +    }
2860 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2861 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2862 +  else if(variable == "d0Sign"){
2863 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2864 +    if(d0Sign < 0) value = -0.5;
2865 +    else if (d0Sign > 0) value = 0.5;
2866 +    else value = -999;
2867 +  }
2868 +  else if(variable == "chargeProduct"){
2869 +    value = object1->charge*object2->charge;
2870 +  }
2871 +  else if(variable == "electron1CorrectedD0Vertex"){
2872 +    value = object1->correctedD0Vertex;
2873 +  }
2874 +  else if(variable == "electron2CorrectedD0Vertex"){
2875 +    value = object2->correctedD0Vertex;
2876 +  }
2877 +  else if(variable == "electron1CorrectedD0"){
2878 +    value = object1->correctedD0;
2879 +  }
2880 +  else if(variable == "electron2CorrectedD0"){
2881 +    value = object2->correctedD0;
2882 +  }
2883 +
2884 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2885 +
2886 +  value = applyFunction(function, value);
2887 +
2888 +  return value;
2889 + }
2890 + //!electron-muon pair valueLookup
2891 + double
2892 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
2893 +
2894 +  double value = 0.0;
2895 +
2896 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2897 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2898 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2899 +  else if(variable == "invMass"){
2900 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2901 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2902 +    value = (fourVector1 + fourVector2).M();
2903 +  }
2904 +  else if(variable == "pt"){
2905 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2906 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2907 +    value = (fourVector1 + fourVector2).Pt();
2908 +  }
2909 +  else if(variable == "threeDAngle")
2910 +    {
2911 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2912 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2913 +      value = (threeVector1.Angle(threeVector2));
2914 +    }
2915 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2916 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2917 +  else if(variable == "d0Sign"){
2918 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2919 +    if(d0Sign < 0) value = -0.5;
2920 +    else if (d0Sign > 0) value = 0.5;
2921 +    else value = -999;
2922 +  }
2923 +  else if(variable == "chargeProduct"){
2924 +    value = object1->charge*object2->charge;
2925 +  }
2926 +  else if(variable == "electronCorrectedD0Vertex"){
2927 +    value = object1->correctedD0Vertex;
2928 +  }
2929 +  else if(variable == "muonCorrectedD0Vertex"){
2930 +    value = object2->correctedD0Vertex;
2931 +  }
2932 +  else if(variable == "electronCorrectedD0"){
2933 +    value = object1->correctedD0;
2934 +  }
2935 +  else if(variable == "muonCorrectedD0"){
2936 +    value = object2->correctedD0;
2937 +  }
2938 +  else if(variable == "electronDetIso"){
2939 +    value = (object1->trackIso) / object1->pt;
2940 +  }
2941 +  else if(variable == "muonDetIso"){
2942 +    value = (object2->trackIsoDR03) / object2->pt;
2943 +  }
2944 +  else if(variable == "electronRelPFrhoIso"){
2945 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
2946 +  }
2947 +  else if(variable == "muonRelPFdBetaIso"){
2948 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
2949 +  }
2950 +
2951 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2952 +
2953 +  value = applyFunction(function, value);
2954 +
2955 +  return value;
2956 + }
2957 +
2958 + //!electron-jet pair valueLookup
2959 + double
2960 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
2961 +
2962 +  double value = 0.0;
2963 +
2964 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2965 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2966 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2967 +  else if(variable == "invMass"){
2968 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2969 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2970 +    value = (fourVector1 + fourVector2).M();
2971 +  }
2972 +  else if(variable == "pt"){
2973 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2974 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2975 +    value = (fourVector1 + fourVector2).Pt();
2976 +  }
2977 +  else if(variable == "threeDAngle")
2978 +    {
2979 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2980 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2981 +      value = (threeVector1.Angle(threeVector2));
2982 +    }
2983 +  else if(variable == "chargeProduct"){
2984 +    value = object1->charge*object2->charge;
2985 +  }
2986 +
2987 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2988 +
2989 +  value = applyFunction(function, value);
2990 +
2991 +  return value;
2992 + }
2993 +
2994 + //!muon-jet pair valueLookup
2995 + double
2996 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
2997 +
2998 +  double value = 0.0;
2999 +
3000 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3001 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3002 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3003 +  else if(variable == "invMass"){
3004 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3005 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3006 +    value = (fourVector1 + fourVector2).M();
3007 +  }
3008 +  else if(variable == "pt"){
3009 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3010 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3011 +    value = (fourVector1 + fourVector2).Pt();
3012 +  }
3013 +  else if(variable == "threeDAngle")
3014 +    {
3015 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3016 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3017 +      value = (threeVector1.Angle(threeVector2));
3018 +    }
3019 +  else if(variable == "chargeProduct"){
3020 +    value = object1->charge*object2->charge;
3021 +  }
3022 +
3023 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3024 +
3025 +  value = applyFunction(function, value);
3026 +
3027 +  return value;
3028 + }
3029 +
3030 + //!jet-jet pair valueLookup
3031 + double
3032 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3033 +
3034 +  double value = 0.0;
3035 +
3036 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3037 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3038 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3039 +  else if(variable == "invMass"){
3040 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3041 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3042 +    value = (fourVector1 + fourVector2).M();
3043 +  }
3044 +  else if(variable == "pt"){
3045 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3046 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3047 +    value = (fourVector1 + fourVector2).Pt();
3048 +  }
3049 +  else if(variable == "threeDAngle")
3050 +    {
3051 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3052 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3053 +      value = (threeVector1.Angle(threeVector2));
3054 +    }
3055 +  else if(variable == "chargeProduct"){
3056 +    value = object1->charge*object2->charge;
3057 +  }
3058 +
3059 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3060 +
3061 +  value = applyFunction(function, value);
3062 +
3063 +  return value;
3064 + }
3065 + //!electron-track pair valueLookup
3066 + double
3067 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3068 +  double electronMass = 0.000511;
3069 +  double value = 0.0;
3070 +  TLorentzVector fourVector1(0, 0, 0, 0);
3071 +  TLorentzVector fourVector2(0, 0, 0, 0);
3072 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3073 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3074 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3075 +  else if(variable == "invMass"){
3076 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3077 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3078 +
3079 +    value = (fourVector1 + fourVector2).M();
3080 +  }
3081 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3082 +  value = applyFunction(function, value);
3083 +  return value;
3084 + }
3085 +
3086 +
3087 + //!muon-track pair valueLookup
3088 + double
3089 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3090 +  double pionMass = 0.140;
3091 +  double muonMass = 0.106;
3092 +  double value = 0.0;
3093 +  TLorentzVector fourVector1(0, 0, 0, 0);
3094 +  TLorentzVector fourVector2(0, 0, 0, 0);
3095 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3096 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3097 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3098 +  else if(variable == "invMass"){
3099 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3100 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3101 +
3102 +    value = (fourVector1 + fourVector2).M();
3103 +  }
3104 +
3105 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3106 +  value = applyFunction(function, value);
3107 +  return value;
3108 + }
3109 +
3110 + //!tau-tau pair valueLookup
3111 + double
3112 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3113 +  double value = 0.0;
3114 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3115 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3116 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3117 +  else if(variable == "invMass"){
3118 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3119 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3120 +    value = (fourVector1 + fourVector2).M();
3121 +  }
3122 +
3123 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3124 +  value = applyFunction(function, value);
3125 +  return value;
3126 + }
3127 +
3128 + //!muon-tau pair valueLookup
3129 + double
3130 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3131 +  double value = 0.0;
3132 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3133 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3134 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3135 +  else if(variable == "invMass"){
3136 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3137 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3138 +    value = (fourVector1 + fourVector2).M();
3139 +  }
3140 +
3141 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3142 +  value = applyFunction(function, value);
3143 +  return value;
3144 + }
3145 +
3146 + //!tau-track pair valueLookup
3147 + double
3148 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3149 +  double value = 0.0;
3150 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3151 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3152 +
3153 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3154 +  value = applyFunction(function, value);
3155 +  return value;
3156 + }
3157 +
3158 +
3159 + //!track-event pair valueLookup
3160 + double
3161 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3162 +
3163 +  double value = 0.0;
3164 +  double pMag = sqrt(object1->pt * object1->pt +
3165 +                     object1->pz * object1->pz);
3166 +
3167 +  if      (variable == "numPV")                      value = object2->numPV;
3168 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3169 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3170 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3171 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3172 +
3173 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3174 +
3175 +  value = applyFunction(function, value);
3176 +
3177 +  return value;
3178 +
3179 + }
3180 +
3181 + //!electron-trigobj pair valueLookup
3182 + double
3183 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3184 +
3185 +  double value = 0.0;
3186 +
3187 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3188 +
3189 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3190 +
3191 +  value = applyFunction(function, value);
3192 +
3193 +  return value;
3194 +
3195 + }
3196 +
3197 + //!muon-trigobj pair valueLookup
3198 + double
3199 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3200 +
3201 +  double value = 0.0;
3202 +
3203 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3204 +
3205 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3206 +
3207 +  value = applyFunction(function, value);
3208 +
3209 +  return value;
3210 +
3211 + }
3212 +
3213 + //!stop valueLookup
3214 + double
3215 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3216 +
3217 +
3218 +  double value = 0.0;
3219 +
3220 +  if(variable == "ctau") value = object->ctau;
3221 +
3222 +  else if (variable == "d0"){
3223 +    double vx = object->vx - chosenVertex ()->x,
3224 +      vy = object->vy - chosenVertex ()->y,
3225 +      px = object->px,
3226 +      py = object->py,
3227 +      pt = object->pt;
3228 +    value = (-vx * py + vy * px) / pt;
3229 +  }
3230 +
3231 +  else if (variable == "dz"){
3232 +    double vx = object->vx - chosenVertex ()->x,
3233 +      vy = object->vy - chosenVertex ()->y,
3234 +      vz = object->vz - chosenVertex ()->z,
3235 +      px = object->px,
3236 +      py = object->py,
3237 +      pz = object->pz,
3238 +      pt = object->pt;
3239 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3240 +  }
3241 +
3242 +  else if (variable == "minD0"){
3243 +    double minD0=999;
3244 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3245 +      double vx = object->vx - vertex->x,
3246 +        vy = object->vy - vertex->y,
3247 +        px = object->px,
3248 +        py = object->py,
3249 +        pt = object->pt;
3250 +      value = (-vx * py + vy * px) / pt;
3251 +      if(abs(value) < abs(minD0)) minD0 = value;
3252 +    }
3253 +    value = minD0;
3254 +  }
3255 +  else if (variable == "minDz"){
3256 +    double minDz=999;
3257 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3258 +      double vx = object->vx - vertex->x,
3259 +        vy = object->vy - vertex->y,
3260 +        vz = object->vz - vertex->z,
3261 +        px = object->px,
3262 +        py = object->py,
3263 +        pz = object->pz,
3264 +        pt = object->pt;
3265 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3266 +      if(abs(value) < abs(minDz)) minDz = value;
3267 +    }
3268 +    value = minDz;
3269 +  }
3270 +  else if(variable == "distToVertex"){
3271 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3272 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3273 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3274 +  }
3275 +  else if (variable == "minDistToVertex"){
3276 +    double minDistToVertex=999;
3277 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3278 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3279 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3280 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3281 +
3282 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3283 +    }
3284 +    value = minDistToVertex;
3285 +  }
3286 +  else if (variable == "distToVertexDifference"){
3287 +    double minDistToVertex=999;
3288 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3289 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3290 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3291 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3292 +
3293 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3294 +    }
3295 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3296 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3297 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3298 +
3299 +    value = distToChosenVertex - minDistToVertex;
3300 +  }
3301 +
3302 +  else if (variable == "closestVertexRank"){
3303 +    double minDistToVertex=999;
3304 +    int vertex_rank = 0;
3305 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3306 +      vertex_rank++;
3307 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3308 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3309 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3310 +
3311 +      if(abs(dist) < abs(minDistToVertex)){
3312 +        value = vertex_rank;
3313 +        minDistToVertex = dist;
3314 +      }
3315 +    }
3316 +  }
3317 +
3318 +
3319 +
3320 +
3321 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3322 +
3323 +  value = applyFunction(function, value);
3324 +
3325 +  return value;
3326 +
3327 + }
3328 +
3329 +
3330 +
3331 +
3332 + // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3333 + // Return true iff no other tracks are found in this cone.
3334 + int
3335 + OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
3336 +  for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
3337 +    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
3338 +    double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
3339 +    if(deltaRtrk < 0.5) return 0;
3340 +  }
3341 +  return 1;
3342 +
3343 + }
3344 +
3345 +
3346 + double
3347 + OSUAnalysis::getTrkPtRes (const BNtrack* track1){
3348 +
3349 +  double ptTrue = getTrkPtTrue(track1, mcparticles.product());
3350 +  double PtRes = (track1->pt - ptTrue) / ptTrue;
3351 +
3352 +  return PtRes;
3353 +
3354 + }
3355 +
3356 +
3357 + double
3358 + OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
3359 +  double value = -99;
3360 +  double genDeltaRLowest = 999;
3361 +
3362 +  for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
3363 +    double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
3364 +    if (genDeltaRtemp < genDeltaRLowest) {
3365 +      genDeltaRLowest = genDeltaRtemp;
3366 +      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
3367 +        double ptTrue = genPart->pt;
3368 +        value = ptTrue;
3369 +      }
3370 +    }
3371 +  }
3372 +
3373 +  return value;
3374 +
3375 + }
3376 +
3377 + double
3378 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3379 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3380 +  if (!useTrackCaloRhoCorr_) return -99;
3381 +  // if (!rhokt6CaloJetsHandle_) {
3382 +  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3383 +  //   return -99;
3384 +  // }
3385 +  double radDeltaRCone = 0.5;
3386 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3387 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3388 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3389 +  return caloTotRhoCorrCalo;
3390 +
3391 + }
3392 +
3393 +
3394 +
3395 +
3396 + //creates a map of the dead Ecal channels in the barrel and endcap
3397 + //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
3398 + //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
3399 + void
3400 + OSUAnalysis::WriteDeadEcal (){
3401 +  double etaEcal, phiEcal;
3402 +  ifstream DeadEcalFile(deadEcalFile_);
3403 +  if(!DeadEcalFile) {
3404 +    cout << "Error: DeadEcalFile has not been found." << endl;
3405 +    return;
3406 +  }
3407 +  if(DeadEcalVec.size()!= 0){
3408 +    cout << "Error: DeadEcalVec has a nonzero size" << endl;
3409 +    return;
3410 +  }
3411 +  while(!DeadEcalFile.eof())
3412 +    {
3413 +      DeadEcalFile >> etaEcal >> phiEcal;
3414 +      DeadEcal newChan;
3415 +      newChan.etaEcal = etaEcal;
3416 +      newChan.phiEcal = phiEcal;
3417 +      DeadEcalVec.push_back(newChan);
3418 +    }
3419 +  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
3420 + }
3421 +
3422 + //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
3423 + int
3424 + OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
3425 +  double deltaRLowest = 999;
3426 +  int value = 0;
3427 +  if (DeadEcalVec.size() == 0) WriteDeadEcal();
3428 +  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3429 +    double eta = ecal->etaEcal;
3430 +    double phi = ecal->phiEcal;
3431 +    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
3432 +    if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3433 +  }
3434 +  if (deltaRLowest<0.05) {value = 1;}
3435 +  else {value = 0;}
3436 +  return value;
3437 + }
3438 +
3439 + // Returns the smallest DeltaR between the object and any generated true particle in the event.
3440 + template <class InputObject>
3441 + double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3442 +  double genDeltaRLowest = 999.;
3443 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3444 +    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
3445 +    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
3446 +  }
3447 +  return genDeltaRLowest;
3448 + }
3449  
3450   double
3451   OSUAnalysis::applyFunction(string function, double value){
3452  
3453 <  if(function == "abs") value = abs(value);
3453 >  if(function == "abs") value = fabs(value);
3454 >  else if(function == "fabs") value = fabs(value);
3455 >  else if(function == "log10") value = log10(value);
3456 >  else if(function == "log") value = log10(value);
3457  
3458 +  else if(function == "") value = value;
3459 +  else{cout << "WARNING: invalid function '" << function << "'\n";}
3460  
3461    return value;
3462  
# Line 1446 | Line 3466 | OSUAnalysis::applyFunction(string functi
3466   template <class InputCollection>
3467   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
3468  
3469 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
3470 +    string obj1, obj2;
3471 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
3472 +    if (inputType==obj1 ||
3473 +          inputType==obj2) {
3474 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
3475 +      // and the inputType is a member of the pair.
3476 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
3477 +      // For example, if currentCut.inputCollection==electron-muon pairs,
3478 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
3479 +      return;
3480 +    }
3481 +  }
3482  
3483    for (uint object = 0; object != inputCollection->size(); object++){
3484  
# Line 1453 | Line 3486 | void OSUAnalysis::setObjectFlags(cut &cu
3486  
3487      if(currentCut.inputCollection == inputType){
3488  
3489 <      double value = valueLookup(&inputCollection->at(object), currentCut.variable, currentCut.function);
3489 >      vector<bool> subcutDecisions;
3490 >      for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3491 >        string stringValue = "";
3492 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3493 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3494 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3495  
3496 <      decision = evaluateComparison(value,currentCut.comparativeOperator,currentCut.cutValue);
3496 >      }
3497 >      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3498 >      else{
3499 >        bool tempDecision = true;
3500 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
3501 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
3502 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
3503 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
3504 >            tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
3505 >        }
3506 >        decision = tempDecision;
3507 >      }
3508      }
1460    individualFlags[inputType].at(currentCutIndex).push_back(decision);
3509  
3510 +    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3511  
3512      //set flags for objects that pass each cut AND all the previous cuts
3513      bool previousCumulativeFlag = true;
3514      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3515 <      if(previousCumulativeFlag && individualFlags[inputType].at(previousCutIndex).at(object)) previousCumulativeFlag = true;
3515 >      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
3516        else{ previousCumulativeFlag = false; break;}
3517      }
3518 <    cumulativeFlags[inputType].at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3518 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3519  
3520    }
3521  
3522   }
3523  
3524  
3525 + template <class InputCollection1, class InputCollection2>
3526 + void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
3527 +                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
3528 +
3529 +
3530 +  bool sameObjects = false;
3531 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3532 +
3533 +  // Get the strings for the two objects that make up the pair.
3534 +  string obj1Type, obj2Type;
3535 +  getTwoObjs(inputType, obj1Type, obj2Type);
3536 +  bool isTwoTypesOfObject = true;
3537 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
3538 +
3539 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
3540 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
3541 +  if (currentCut.inputCollection == inputType) {
3542 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
3543 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3544 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3545 +    }
3546 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
3547 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
3548 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3549 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3550 +      }
3551 +    }
3552 +  }
3553 +
3554 +  int counter = 0;
3555 +
3556 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3557 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3558  
3559 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3560  
3561  
3562 < DEFINE_FWK_MODULE(OSUAnalysis);
3562 >      bool decision = true;//object passes if this cut doesn't cut on that type of object
3563 >
3564 >      if(currentCut.inputCollection == inputType){
3565 >
3566 >        vector<bool> subcutDecisions;
3567 >        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3568 >          string stringValue = "";
3569 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3570 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3571 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3572 >        }
3573 >
3574 >        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3575 >        else{
3576 >          bool tempDecision = subcutDecisions.at(0);
3577 >          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
3578 >            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
3579 >              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
3580 >            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
3581 >              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
3582 >          }
3583 >          decision = tempDecision;
3584 >        }
3585 >      }
3586 >      // if (decision) isPassObj1.at(object1) = true;
3587 >      // if (decision) isPassObj2.at(object2) = true;
3588 >      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3589 >      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3590 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;
3591 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;
3592 >      }
3593 >
3594 >      //set flags for objects that pass each cut AND all the previous cuts
3595 >      bool previousCumulativeFlag = true;
3596 >      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3597 >        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
3598 >        else{ previousCumulativeFlag = false; break;}
3599 >      }
3600 >      //apply flags for the components of the composite object as well
3601 >      bool currentCumulativeFlag = true;
3602 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
3603 >      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
3604 >      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
3605 >      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
3606 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
3607 >      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3608 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);
3609 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);
3610 >      }
3611 >      counter++;
3612 >
3613 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
3614 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
3615 >
3616 > }
3617 >
3618 >
3619 > bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
3620 >  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
3621 >  // all cuts up to currentCutIndex
3622 >  bool previousCumulativeFlag = true;
3623 >  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
3624 >    if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
3625 >    else {
3626 >      previousCumulativeFlag = false; break;
3627 >    }
3628 >  }
3629 >  return previousCumulativeFlag;
3630 > }
3631 >
3632 >
3633 > template <class InputCollection>
3634 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3635 >
3636 >  for (uint object = 0; object != inputCollection->size(); object++){
3637 >
3638 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3639 >
3640 >    string currentString = parameters.inputVariables.at(0);
3641 >    string inputVariable = "";
3642 >    string function = "";
3643 >    if(currentString.find("(")==string::npos){
3644 >      inputVariable = currentString;// variable to cut on
3645 >    }
3646 >    else{
3647 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3648 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3649 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3650 >    }
3651 >
3652 >    string stringValue = "";
3653 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3654 >    histo->Fill(value,scaleFactor);
3655 >
3656 >    if (printEventInfo_) {
3657 >      // Write information about event to screen, for testing purposes.
3658 >      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
3659 >    }
3660 >
3661 >  }
3662 > }
3663 >
3664 > template <class InputCollection1, class InputCollection2>
3665 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3666 >
3667 >  bool sameObjects = false;
3668 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3669 >
3670 >  int pairCounter = -1;
3671 >  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3672 >    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3673 >
3674 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3675 >
3676 >      pairCounter++;
3677 >      //only take objects which have passed all cuts and pairs which have passed all cuts
3678 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3679 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3680 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3681 >
3682 >      string currentString = parameters.inputVariables.at(0);
3683 >      string inputVariable = "";
3684 >      string function = "";
3685 >      if(currentString.find("(")==string::npos){
3686 >        inputVariable = currentString;// variable to cut on
3687 >      }
3688 >      else{
3689 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3690 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3691 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3692 >      }
3693 >
3694 >      string stringValue = "";
3695 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3696 >      histo->Fill(value,scaleFactor);
3697 >
3698 >    }
3699 >  }
3700 >
3701 > }
3702 >
3703 >
3704 > template <class InputCollection>
3705 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3706 >
3707 >  for (uint object = 0; object != inputCollection->size(); object++){
3708 >
3709 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3710 >
3711 >    string stringValue = "";
3712 >    string currentString = parameters.inputVariables.at(0);
3713 >    string inputVariable = "";
3714 >    string function = "";
3715 >    if(currentString.find("(")==string::npos){
3716 >      inputVariable = currentString;// variable to cut on
3717 >    }
3718 >    else{
3719 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3720 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3721 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3722 >    }
3723 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3724 >
3725 >    currentString = parameters.inputVariables.at(1);
3726 >    inputVariable = "";
3727 >    function = "";
3728 >    if(currentString.find("(")==string::npos){
3729 >      inputVariable = currentString;// variable to cut on
3730 >    }
3731 >    else{
3732 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3733 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3734 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3735 >    }
3736 >
3737 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3738 >
3739 >    histo->Fill(valueX,valueY,scaleFactor);
3740 >
3741 >  }
3742 >
3743 > }
3744 >
3745 > template <class InputCollection1, class InputCollection2>
3746 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3747 >
3748 >  bool sameObjects = false;
3749 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3750 >
3751 >  int pairCounter = -1;
3752 >  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3753 >    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3754 >
3755 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3756 >
3757 >      pairCounter++;
3758 >
3759 >      //only take objects which have passed all cuts and pairs which have passed all cuts
3760 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3761 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3762 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3763 >
3764 >      string stringValue = "";
3765 >      string currentString = parameters.inputVariables.at(0);
3766 >      string inputVariable = "";
3767 >      string function = "";
3768 >      if(currentString.find("(")==string::npos){
3769 >        inputVariable = currentString;// variable to cut on
3770 >      }
3771 >      else{
3772 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3773 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3774 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3775 >      }
3776 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3777 >
3778 >      currentString = parameters.inputVariables.at(1);
3779 >      inputVariable = "";
3780 >      function = "";
3781 >      if(currentString.find("(")==string::npos){
3782 >        inputVariable = currentString;// variable to cut on
3783 >      }
3784 >      else{
3785 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3786 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3787 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3788 >      }
3789 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3790 >
3791 >
3792 >      histo->Fill(valueX,valueY,scaleFactor);
3793 >
3794 >    }
3795 >  }
3796 >
3797 > }
3798 >
3799 >
3800 > template <class InputObject>
3801 > int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
3802 >
3803 >  int bestMatchIndex = -1;
3804 >  double bestMatchDeltaR = 999;
3805 >
3806 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3807 >
3808 >    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
3809 >    if(currentDeltaR > 0.05) continue;
3810 >    //     cout << setprecision(3) << setw(20)
3811 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
3812 >    //          << setw(20)
3813 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
3814 >    //          << setw(20)
3815 >    //          << "\tdeltaR = " << currentDeltaR
3816 >    //          << setprecision(1)
3817 >    //          << setw(20)
3818 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
3819 >    //          << setw(20)
3820 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
3821 >    //          << setw(20)
3822 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
3823 >    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
3824 >      bestMatchIndex = mcparticle - mcparticles->begin();
3825 >      bestMatchDeltaR = currentDeltaR;
3826 >    }
3827 >
3828 >  }
3829 >  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
3830 >  //   else cout << "no match found..." << endl;
3831 >  return bestMatchIndex;
3832 >
3833 > }
3834 >
3835 >
3836 > int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
3837 >
3838 >  int bestMatchIndex = -1;
3839 >  double bestMatchDeltaR = 999;
3840 >
3841 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3842 >
3843 >    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
3844 >
3845 >    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
3846 >    if(currentDeltaR > 0.05) continue;
3847 >
3848 >    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
3849 >      bestMatchIndex = mcparticle - mcparticles->begin();
3850 >      bestMatchDeltaR = currentDeltaR;
3851 >    }
3852 >
3853 >  }
3854 >
3855 >  return bestMatchIndex;
3856 > }
3857 >
3858 >
3859 > // bin      particle type
3860 > // ---      -------------
3861 > //  0        unmatched
3862 > //  1        u
3863 > //  2        d
3864 > //  3        s
3865 > //  4        c
3866 > //  5        b
3867 > //  6        t
3868 > //  7        e
3869 > //  8        mu
3870 > //  9        tau
3871 > // 10        nu
3872 > // 11        g
3873 > // 12        gamma
3874 > // 13        Z
3875 > // 14        W
3876 > // 15        light meson
3877 > // 16        K meson
3878 > // 17        D meson
3879 > // 18        B meson
3880 > // 19        light baryon
3881 > // 20        strange baryon
3882 > // 21        charm baryon
3883 > // 22        bottom baryon
3884 > // 23        other
3885 >
3886 > int OSUAnalysis::getPdgIdBinValue(int pdgId){
3887 >
3888 >  int binValue = -999;
3889 >  int absPdgId = fabs(pdgId);
3890 >  if(pdgId == -1) binValue = 0;
3891 >  else if(absPdgId <= 6 ) binValue = absPdgId;
3892 >  else if(absPdgId == 11 ) binValue = 7;
3893 >  else if(absPdgId == 13 ) binValue = 8;
3894 >  else if(absPdgId == 15 ) binValue = 9;
3895 >  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
3896 >  else if(absPdgId == 21 ) binValue = 11;
3897 >  else if(absPdgId == 22 ) binValue = 12;
3898 >  else if(absPdgId == 23 ) binValue = 13;
3899 >  else if(absPdgId == 24 ) binValue = 14;
3900 >  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
3901 >  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
3902 >  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
3903 >  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
3904 >  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
3905 >  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
3906 >  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
3907 >  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
3908 >
3909 >  else binValue = 23;
3910  
3911 +  return binValue;
3912  
3913 + }
3914 +
3915 + const BNprimaryvertex *
3916 + OSUAnalysis::chosenVertex ()
3917 + {
3918 +  const BNprimaryvertex *chosenVertex = 0;
3919 +  if(find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
3920 +    vector<bool> vertexFlags;
3921 +    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
3922 +      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
3923 +        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
3924 +        break;
3925 +      }
3926 +    }
3927 +    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
3928 +      if(!vertexFlags.at(vertexIndex)) continue;
3929 +      chosenVertex = & primaryvertexs->at(vertexIndex);
3930 +      break;
3931 +    }
3932 +  }
3933 +  else {
3934 +    chosenVertex = &primaryvertexs->at(0);
3935 +  }
3936 +
3937 +  return chosenVertex;
3938 + }
3939 +
3940 + const BNmet *
3941 + OSUAnalysis::chosenMET ()
3942 + {
3943 +  const BNmet *chosenMET = 0;
3944 +  if(find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
3945 +    vector<bool> metFlags;
3946 +    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
3947 +      if (cumulativeFlags.at("mets").at(i).size()){
3948 +        metFlags = cumulativeFlags.at("mets").at(i);
3949 +        break;
3950 +      }
3951 +    }
3952 +    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
3953 +      if(!metFlags.at(metIndex)) continue;
3954 +      chosenMET = & mets->at(metIndex);
3955 +      break;
3956 +    }
3957 +  }
3958 +  else {
3959 +    chosenMET = &mets->at(0);
3960 +  }
3961 +
3962 +  return chosenMET;
3963 + }
3964 +
3965 + const BNelectron *
3966 + OSUAnalysis::chosenElectron ()
3967 + {
3968 +  const BNelectron *chosenElectron = 0;
3969 +  if(find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
3970 +    vector<bool> electronFlags;
3971 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
3972 +      if (cumulativeFlags.at("electrons").at(i).size()){
3973 +        electronFlags = cumulativeFlags.at("electrons").at(i);
3974 +        break;
3975 +      }
3976 +    }
3977 +    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
3978 +      if(!electronFlags.at(electronIndex)) continue;
3979 +      chosenElectron = & electrons->at(electronIndex);
3980 +      break;
3981 +    }
3982 +  }
3983 +  else {
3984 +    chosenElectron = &electrons->at(0);
3985 +  }
3986 +
3987 +  return chosenElectron;
3988 + }
3989 +
3990 + const BNmuon *
3991 + OSUAnalysis::chosenMuon ()
3992 + {
3993 +  const BNmuon *chosenMuon = 0;
3994 +  if(find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
3995 +    vector<bool> muonFlags;
3996 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
3997 +      if (cumulativeFlags.at("muons").at(i).size()){
3998 +        muonFlags = cumulativeFlags.at("muons").at(i);
3999 +        break;
4000 +      }
4001 +    }
4002 +    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4003 +      if(!muonFlags.at(muonIndex)) continue;
4004 +      chosenMuon = & muons->at(muonIndex);
4005 +      break;
4006 +    }
4007 +  }
4008 +  else {
4009 +    chosenMuon = &muons->at(0);
4010 +  }
4011 +
4012 +  return chosenMuon;
4013 + }
4014 +
4015 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines