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.55 by ahart, Fri May 3 20:10:39 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 >  puFile_ (cfg.getParameter<std::string> ("puFile")),
21 >  deadEcalFile_ (cfg.getParameter<std::string> ("deadEcalFile")),
22 >  muonSFFile_ (cfg.getParameter<std::string> ("muonSFFile")),
23 >  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
24 >  electronSFID_ (cfg.getParameter<std::string> ("electronSFID")),
25 >  muonSF_ (cfg.getParameter<std::string> ("muonSF")),
26 >  dataset_ (cfg.getParameter<std::string> ("dataset")),
27 >  datasetType_ (cfg.getParameter<std::string> ("datasetType")),
28 >  channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
29 >  histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
30 >  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
31 >  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
32 >  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
33 >  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
34 >  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
35 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau"))
36  
37   {
38 +
39    TH1::SetDefaultSumw2 ();
40  
41 +  //create pile-up reweighting object, if necessary
42 +  if(datasetType_ != "data") {
43 +    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
44 +    if (applyLeptonSF_){
45 +      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
46 +      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
47 +    }
48 +  }
49 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
50 +    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
51 +
52 +
53    // Construct Cutflow Objects. These store the results of cut decisions and
54    // handle filling cut flow histograms.
55    masterCutFlow_ = new CutFlow (fs_);
56    std::vector<TFileDirectory> directories;
57  
58 +  //always get vertex collection so we can assign the primary vertex in the event
59 +  objectsToGet.push_back("primaryvertexs");
60 +
61 +  //always make the plot of number of primary vertices (to check pile-up reweighting)
62 +  objectsToPlot.push_back("primaryvertexs");
63 +
64 +  //always get the MC particles to do GEN-matching
65 +  objectsToGet.push_back("mcparticles");
66 +
67 +  //always get the event collection to do pile-up reweighting
68 +  objectsToGet.push_back("events");
69 +
70 +  //parse the histogram definitions
71 +  for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
72 +
73 +    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
74 +    if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
75 +    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
76 +    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
77 +    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
78 +    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
79 +    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
80 +    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
81 +      if(tempInputCollection.find("secondary")!=std::string::npos){//secondary object
82 +        int spaceIndex = tempInputCollection.find(" ");
83 +        int secondWordLength = tempInputCollection.size() - spaceIndex;
84 +        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
85 +      }
86 +      else{
87 +        objectsToGet.push_back(tempInputCollection);
88 +      }
89 +      objectsToPlot.push_back(tempInputCollection);
90 +      objectsToCut.push_back(tempInputCollection);
91 +    }
92 +    else{//pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
93 +      string obj1;
94 +      string obj2;
95 +      getTwoObjs(tempInputCollection, obj1, obj2);
96 +      string obj2ToGet = getObjToGet(obj2);  
97 +      objectsToCut.push_back(tempInputCollection);
98 +      objectsToCut.push_back(obj1);
99 +      objectsToCut.push_back(obj2);  
100 +      objectsToPlot.push_back(tempInputCollection);
101 +      objectsToPlot.push_back(obj1);
102 +      objectsToPlot.push_back(obj2);  
103 +      objectsToGet.push_back(tempInputCollection);
104 +      objectsToGet.push_back(obj1);
105 +      objectsToGet.push_back(obj2ToGet);
106 +
107 +    }
108 +
109 +    vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
110 +
111 +    for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
112 +
113 +      histogram tempHistogram;
114 +      tempHistogram.inputCollection = tempInputCollection;
115 +      tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
116 +      tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
117 +      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
118 +      tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
119 +
120 +      histograms.push_back(tempHistogram);
121 +
122 +    }
123 +  }
124 +  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
125 +  sort( objectsToPlot.begin(), objectsToPlot.end() );
126 +  objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
127 +
128 +
129 +
130 +  //add histograms with the gen-matched id, mother id, and grandmother id
131 +  for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
132 +
133 +    string currentObject = objectsToPlot.at(currentObjectIndex);
134 +    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
135 +
136 +    histogram tempIdHisto;
137 +    histogram tempMomIdHisto;
138 +    histogram tempGmaIdHisto;
139 +    histogram tempIdVsMomIdHisto;
140 +    histogram tempIdVsGmaIdHisto;
141 +
142 +    tempIdHisto.inputCollection = currentObject;
143 +    tempMomIdHisto.inputCollection = currentObject;
144 +    tempGmaIdHisto.inputCollection = currentObject;
145 +    tempIdVsMomIdHisto.inputCollection = currentObject;
146 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
147 +
148 +    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
149 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
150 +
151 +    currentObject = currentObject.substr(0, currentObject.size()-1);
152 +    tempIdHisto.name = currentObject+"GenMatchId";
153 +    tempMomIdHisto.name = currentObject+"GenMatchMotherId";
154 +    tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
155 +    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
156 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
157 +
158 +    currentObject.at(0) = toupper(currentObject.at(0));
159 +    tempIdHisto.title = currentObject+" Gen-matched Particle";
160 +    tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
161 +    tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
162 +    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
163 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
164 +
165 +
166 +    int maxNum = 24;
167 +    vector<double> binVector;
168 +    binVector.push_back(maxNum);
169 +    binVector.push_back(0);
170 +    binVector.push_back(maxNum);
171 +
172 +    tempIdHisto.bins = binVector;
173 +    tempIdHisto.inputVariables.push_back("genMatchedId");
174 +    tempMomIdHisto.bins = binVector;
175 +    tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
176 +    tempGmaIdHisto.bins = binVector;
177 +    tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
178 +    binVector.push_back(maxNum);
179 +    binVector.push_back(0);
180 +    binVector.push_back(maxNum);
181 +    tempIdVsMomIdHisto.bins = binVector;
182 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
183 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
184 +    tempIdVsGmaIdHisto.bins = binVector;
185 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
186 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
187 +
188 +    histograms.push_back(tempIdHisto);
189 +    histograms.push_back(tempMomIdHisto);
190 +    histograms.push_back(tempGmaIdHisto);
191 +    histograms.push_back(tempIdVsMomIdHisto);
192 +    histograms.push_back(tempIdVsGmaIdHisto);
193 +  }
194 +
195  
196    channel tempChannel;
197    //loop over all channels (event selections)
# Line 46 | Line 210 | OSUAnalysis::OSUAnalysis (const edm::Par
210        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
211        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
212          tempChannel.triggers.push_back(triggerNames.at(trigger));
213 <      allNecessaryObjects.push_back("triggers");
213 >      objectsToGet.push_back("triggers");
214      }
215  
216  
217 +
218 +
219      //create cutFlow for this channel
220      cutFlows_.push_back (new CutFlow (fs_, channelName));
221  
222      //book a directory in the output file with the name of the channel
223      TFileDirectory subDir = fs_->mkdir( channelName );
224      directories.push_back(subDir);
59    std::map<std::string, TH1D*> histoMap;
60    oneDHists_.push_back(histoMap);
225  
226 <    //gen histograms
227 <    oneDHists_.at(currentChannel)["genD0"] = directories.at(currentChannel).make<TH1D> ("genD0",channelLabel+" channel: Gen d_{0}; d_{0} [cm] ", 1000, -1, 1);
228 <    oneDHists_.at(currentChannel)["genAbsD0"] = directories.at(currentChannel).make<TH1D> ("genAbsD0",channelLabel+" channel: Gen d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
229 <    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);
226 >    std::map<std::string, TH1D*> oneDhistoMap;
227 >    oneDHists_.push_back(oneDhistoMap);
228 >    std::map<std::string, TH2D*> twoDhistoMap;
229 >    twoDHists_.push_back(twoDhistoMap);
230  
231  
232  
233 <    //get list of cuts for this channel
234 <    vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
233 >    //book all histograms included in the configuration
234 >    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
235 >      histogram currentHistogram = histograms.at(currentHistogramIndex);
236 >      int numBinsElements = currentHistogram.bins.size();
237 >      int numInputVariables = currentHistogram.inputVariables.size();
238 >
239 >      if(numBinsElements != 3 && numBinsElements !=6) {
240 >        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
241 >        exit(0);
242 >      }
243 >      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
244 >        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
245 >        exit(0);
246 >      }
247 >      else if(numBinsElements == 3){
248 >        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));
249 >      }
250 >      else if(numBinsElements == 6){
251 >        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));
252 >
253 >      }
254 >
255 >
256 >      if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
257 >
258 >      // bin      particle type
259 >      // ---      -------------
260 >      //  0        unmatched
261 >      //  1        u
262 >      //  2        d
263 >      //  3        s
264 >      //  4        c
265 >      //  5        b
266 >      //  6        t
267 >      //  7        e
268 >      //  8        mu
269 >      //  9        tau
270 >      // 10        nu
271 >      // 11        g
272 >      // 12        gamma
273 >      // 13        Z
274 >      // 14        W
275 >      // 15        light meson
276 >      // 16        K meson
277 >      // 17        D meson
278 >      // 18        B meson
279 >      // 19        light baryon
280 >      // 20        strange baryon
281 >      // 21        charm baryon
282 >      // 22        bottom baryon
283 >      // 23        other
284 >
285 >      vector<TString> labelArray;
286 >      labelArray.push_back("unmatched");
287 >      labelArray.push_back("u");
288 >      labelArray.push_back("d");
289 >      labelArray.push_back("s");
290 >      labelArray.push_back("c");
291 >      labelArray.push_back("b");
292 >      labelArray.push_back("t");
293 >      labelArray.push_back("e");
294 >      labelArray.push_back("#mu");
295 >      labelArray.push_back("#tau");
296 >      labelArray.push_back("#nu");
297 >      labelArray.push_back("g");
298 >      labelArray.push_back("#gamma");
299 >      labelArray.push_back("Z");
300 >      labelArray.push_back("W");
301 >      labelArray.push_back("light meson");
302 >      labelArray.push_back("K meson");
303 >      labelArray.push_back("D meson");
304 >      labelArray.push_back("B meson");
305 >      labelArray.push_back("light baryon");
306 >      labelArray.push_back("strange baryon");
307 >      labelArray.push_back("charm baryon");
308 >      labelArray.push_back("bottom baryon");
309 >      labelArray.push_back("other");
310 >
311 >      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
312 >        if(currentHistogram.name.find("GenMatchIdVsMotherId")==std::string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==std::string::npos) {
313 >          oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
314 >        }
315 >        else {
316 >          twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
317 >          twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
318 >        }
319 >      }
320 >      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=std::string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=std::string::npos) {
321 >        twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->CenterTitle();
322 >        twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->CenterTitle();
323 >      }
324 >
325 >    }
326 >
327 >    // Book a histogram for the number of each object type to be plotted.  
328 >    // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().  
329 >    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
330 >      string currentObject = objectsToPlot.at(currentObjectIndex);
331 >      int maxNum = 10;
332 >      if(currentObject == "mcparticles") maxNum = 50;
333 >      else if(currentObject == "primaryvertexs") maxNum = 50;
334 >
335 >      if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
336 >      else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
337 >      else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
338 >      else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
339 >      else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
340 >      else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
341 >      else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
342 >      else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";        
343 >      else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";    
344 >      else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";      
345 >      else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
346 >      else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
347 >      else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
348 >      else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
349 >      else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
350 >      else if(currentObject == "secondary electrons")           currentObject = "secondaryElectrons";
351 >
352 >      currentObject.at(0) = toupper(currentObject.at(0));  
353 >      string histoName = "num" + currentObject;
354 >
355 >      if(histoName == "numPrimaryvertexs"){
356 >        string newHistoName = histoName + "BeforePileupCorrection";
357 >        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
358 >        newHistoName = histoName + "AfterPileupCorrection";
359 >        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
360 >      }
361 >      else
362 >        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
363 >    }
364 >
365  
105    vector<string> tempInputCollections;
366  
367  
368 +    //get list of cuts for this channel
369 +    vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
370 +
371      //loop over and parse all cuts
372      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
110
373        cut tempCut;
374 <     //store input collection for cut
375 <      string inputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
376 <      tempCut.inputCollection = inputCollection;
374 >      //store input collection for cut
375 >      string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
376 >      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
377 >      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
378 >      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
379 >      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
380 >      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
381 >      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
382 >      tempCut.inputCollection = tempInputCollection;
383 >      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
384 >        if(tempInputCollection.find("secondary")!=std::string::npos){//secondary object
385 >          int spaceIndex = tempInputCollection.find(" ");
386 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
387 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
388 >        }
389 >        else{
390 >          objectsToGet.push_back(tempInputCollection);
391 >        }
392 >        objectsToCut.push_back(tempInputCollection);
393 >      }
394 >      else{//pair of objects, need to add them both to objectsToGet
395 >        string obj1;
396 >        string obj2;
397 >        getTwoObjs(tempInputCollection, obj1, obj2);
398 >        string obj2ToGet = getObjToGet(obj2);  
399 >        objectsToCut.push_back(tempInputCollection);
400 >        objectsToCut.push_back(obj1);
401 >        objectsToCut.push_back(obj2);  
402 >        objectsToGet.push_back(tempInputCollection);
403 >        objectsToGet.push_back(obj1);
404 >        objectsToGet.push_back(obj2ToGet);
405 >
406 >      }
407 >
408  
116      tempInputCollections.push_back(inputCollection);
117      allNecessaryObjects.push_back(inputCollection);
409  
410        //split cut string into parts and store them
411        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
412        std::vector<string> cutStringVector = splitString(cutString);
413 <      tempCut.variable = cutStringVector.at(0);// variable to cut on
414 <      tempCut.comparativeOperator = cutStringVector.at(1);// comparison to make
415 <      tempCut.cutValue = atof(cutStringVector.at(2).c_str());// threshold value to pass cut
413 >      if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
414 >        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
415 >        exit(0);
416 >      }
417 >      tempCut.numSubcuts = (cutStringVector.size()+1)/4;
418 >      for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
419 >        int indexOffset = 4 * subcutIndex;
420 >        string currentVariableString = cutStringVector.at(indexOffset);
421 >        if(currentVariableString.find("(")==std::string::npos){
422 >          tempCut.functions.push_back("");//no function was specified
423 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
424 >        }
425 >        else{
426 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
427 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
428 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
429 >        }
430 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
431 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
432 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
433 >      }
434  
435        //get number of objects required to pass cut for event to pass
436        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
437        std::vector<string> numberRequiredVector = splitString(numberRequiredString);
438 +      if(numberRequiredVector.size()!=2){
439 +        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
440 +        exit(0);
441 +      }
442  
130      // determine number required if comparison contains "="
443        int numberRequiredInt = atoi(numberRequiredVector.at(1).c_str());
132      if(numberRequiredVector.at(0) == ">") numberRequiredInt++;
133      else if(numberRequiredVector.at(0) == "<") numberRequiredInt--;
134
444        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
445        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
446  
447 <      if(cuts_.at(currentCut).exists("function")){
139 <        tempCut.function = cuts_.at(currentCut).getParameter<string> ("function");
140 <      }
141 <      else tempCut.function = "";
447 >
448        string tempCutName;
449        if(cuts_.at(currentCut).exists("alias")){
450          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
# Line 146 | Line 452 | OSUAnalysis::OSUAnalysis (const edm::Par
452        else{
453          //construct string for cutflow table
454          bool plural = numberRequiredInt != 1;
455 <        string collectionString = plural ? inputCollection : inputCollection.substr(0, inputCollection.size()-1);
455 >        string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
456          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
457          tempCutName = cutName;
458        }
459        tempCut.name = tempCutName;
460  
155
461        tempChannel.cuts.push_back(tempCut);
462  
463  
464      }//end loop over cuts
465  
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
466      channels.push_back(tempChannel);
467      tempChannel.cuts.clear();
468  
469    }//end loop over channels
470  
471 <  //make unique vector of objects we need to cut on (so we make sure to get them from the event)
472 <  sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
473 <  allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
471 >
472 >  //make unique vector of objects we need to get from the event
473 >  sort( objectsToGet.begin(), objectsToGet.end() );
474 >  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
475 >  //make unique vector of objects we need to cut on
476 >  sort( objectsToCut.begin(), objectsToCut.end() );
477 >  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
478  
479  
480   }
# Line 188 | Line 492 | void
492   OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
493   {
494  
191
495    // Retrieve necessary collections from the event.
496 <  edm::Handle<BNtriggerCollection> triggers;
497 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
496 >
497 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
498      event.getByLabel (triggers_, triggers);
499  
500 <  edm::Handle<BNjetCollection> jets;
198 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())
500 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
501      event.getByLabel (jets_, jets);
502  
503 <  edm::Handle<BNmuonCollection> muons;
202 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())
503 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
504      event.getByLabel (muons_, muons);
505  
506 <  edm::Handle<BNelectronCollection> electrons;
206 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())
506 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
507      event.getByLabel (electrons_, electrons);
508  
509 <  edm::Handle<BNeventCollection> events;
210 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())
509 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
510      event.getByLabel (events_, events);
511  
512 <  edm::Handle<BNtauCollection> taus;
214 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())
512 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
513      event.getByLabel (taus_, taus);
514  
515 <  edm::Handle<BNmetCollection> mets;
218 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())
515 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
516      event.getByLabel (mets_, mets);
517  
518 <  edm::Handle<BNtrackCollection> tracks;
222 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())
518 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
519      event.getByLabel (tracks_, tracks);
520  
521 <  edm::Handle<BNgenjetCollection> genjets;
226 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())
521 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
522      event.getByLabel (genjets_, genjets);
523  
524 <  edm::Handle<BNmcparticleCollection> mcparticles;
230 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())
524 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
525      event.getByLabel (mcparticles_, mcparticles);
526  
527 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
234 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())
527 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
528      event.getByLabel (primaryvertexs_, primaryvertexs);
529  
530 <  edm::Handle<BNbxlumiCollection> bxlumis;
238 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())
530 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
531      event.getByLabel (bxlumis_, bxlumis);
532  
533 <  edm::Handle<BNphotonCollection> photons;
242 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())
533 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
534      event.getByLabel (photons_, photons);
535  
536 <  edm::Handle<BNsuperclusterCollection> superclusters;
246 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())
536 >  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
537      event.getByLabel (superclusters_, superclusters);
538  
539 +  if (datasetType_ == "signalMC"){
540 +    if (std::find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
541 +      event.getByLabel (stops_, stops);
542 +  }
543 +
544 +  if (useTrackCaloRhoCorr_) {  
545 +    // Used only for pile-up correction of by-hand calculation of isolation energy.  
546 +    // This rho collection is not available in all BEANs.  
547 +    // For description of rho values for different jet reconstruction algorithms, see
548 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms  
549 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
550 +  }
551 +
552 +  double scaleFactor = 1.0;
553  
554    //loop over all channels
555  
# Line 253 | Line 557 | OSUAnalysis::analyze (const edm::Event &
557      channel currentChannel = channels.at(currentChannelIndex);
558  
559      flagMap individualFlags;
256    flagMap cumulativeFlags;
560      counterMap passingCounter;
561 +    cumulativeFlags.clear ();
562  
563      bool triggerDecision = true;
564      if(currentChannel.triggers.size() != 0){  //triggers specified
# Line 263 | Line 567 | OSUAnalysis::analyze (const edm::Event &
567      }
568  
569      //loop over all cuts
570 +
571      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
572        cut currentCut = currentChannel.cuts.at(currentCutIndex);
573  
574 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
574 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
575 >        string currentObject = objectsToCut.at(currentObjectIndex);
576  
577 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
577 >        //initialize maps to get ready to set cuts
578          individualFlags[currentObject].push_back (vector<bool> ());
579          cumulativeFlags[currentObject].push_back (vector<bool> ());
580  
581 +      }
582 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
583 +        string currentObject = objectsToCut.at(currentObjectIndex);
584 +
585 +        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
586 +
587 +
588          if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
589 +
590          else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
591 +
592 +        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
593 +        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
594          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
595          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
596          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 287 | Line 604 | OSUAnalysis::analyze (const edm::Event &
604          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
605  
606  
290      }
607  
608 +        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
609 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
610 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
611 +                                                                   "muon-muon pairs");
612 +
613 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
614 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
615 +                                                                   cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
616 +                                                                   "muon-secondary muon pairs");
617 +
618 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
619 +                                                                   cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
620 +                                                                   cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
621 +                                                                   "electron-secondary electron pairs");
622 +
623 +        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
624 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
625 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
626 +                                                                           "electron-electron pairs");
627 +        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
628 +                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
629 +                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
630 +                                                                       "electron-muon pairs");
631 +        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
632 +                                                                           cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
633 +                                                                           cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
634 +                                                                           "jet-jet pairs");
635 +        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
636 +                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
637 +                                                                       cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
638 +                                                                       "electron-jet pairs");
639 +        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
640 +                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
641 +                                                                       cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
642 +                                                                       "muon-jet pairs");
643 +        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
644 +                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
645 +                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
646 +                                                                     "track-event pairs");
647 +        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
648 +                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
649 +                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
650 +                                                                        "electron-track pairs");
651 +        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
652 +                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
653 +                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
654 +                                                                    "muon-track pairs");
655 +        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
656 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
657 +                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
658 +                                                                  "muon-tau pairs");
659 +        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
660 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
661 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
662 +                                                                 "tau-tau pairs");
663 +        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
664 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
665 +                                                                 cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
666 +                                                                 "tau-track pairs");
667  
668 +        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
669 +      }
670  
294    }//end loop over all cuts
671  
672  
673 +    }//end loop over all cuts
674  
675  
676      //use cumulative flags to apply cuts at event level
# Line 310 | Line 687 | OSUAnalysis::analyze (const edm::Event &
687        cut currentCut = currentChannel.cuts.at(currentCutIndex);
688        int numberPassing = 0;
689  
690 <      for (uint object = 0; object != cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).size() ; object++)
691 <          if(cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).at(object)) numberPassing++;
692 <
316 <
690 >      for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
691 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
692 >      }
693        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
694        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
319
695        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
696  
697      }
698  
699 <    cutFlows_.at(currentChannelIndex)->fillCutFlow();
699 >  //get pile-up event weight
700 >  if (datasetType_ != "data"){
701 >    if(doPileupReweighting_) scaleFactor *= puWeight_->at (events->at (0).numTruePV);
702 >    if(applyLeptonSF_){
703 >      if (chosenMuon ()) scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
704 >      if (chosenElectron ()) scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
705 >    }
706 >  }
707  
708 +  stopCTauScaleFactor_ = 1.0;
709 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
710 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
711 +  scaleFactor *= stopCTauScaleFactor_;
712  
713 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
714  
715      if(!eventPassedAllCuts)continue;
716  
717 <
718 <    TVector3 vertexPosition;
719 <    vector<bool> vertexFlags = cumulativeFlags["primaryvertexs"].back();
720 <
721 <    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
722 <      if(!vertexFlags.at(vertexIndex)) continue;
723 <
337 <      vertexPosition.SetXYZ (primaryvertexs->at(vertexIndex).x,primaryvertexs->at(vertexIndex).y,primaryvertexs->at(vertexIndex).z);
338 <      break;
339 <    }
340 <
341 <    vector<bool> mcparticleFlags = cumulativeFlags["mcparticles"].back();
342 <
343 <    for (uint mcparticleIndex = 0; mcparticleIndex != mcparticleFlags.size(); mcparticleIndex++){
344 <      if(!mcparticleFlags.at(mcparticleIndex)) continue;
345 <
346 <      double vx = mcparticles->at(mcparticleIndex).vx - vertexPosition.X (),
347 <             vy = mcparticles->at(mcparticleIndex).vy - vertexPosition.Y (),
348 <             vz = mcparticles->at(mcparticleIndex).vz - vertexPosition.Z (),
349 <             px = mcparticles->at(mcparticleIndex).px,
350 <             py = mcparticles->at(mcparticleIndex).py,
351 <             pt = mcparticles->at(mcparticleIndex).pt,
352 <             d0;
353 <
354 <      d0 = (-vx * py + vy * px) / pt;
355 <      oneDHists_.at(currentChannelIndex)["genD0"]->Fill (d0);
356 <      oneDHists_.at(currentChannelIndex)["genAbsD0"]->Fill (fabs (d0));
357 <      oneDHists_.at(currentChannelIndex)["genDZ"]->Fill (vz);
358 <      oneDHists_.at(currentChannelIndex)["genAbsDZ"]->Fill (fabs (vz));
717 >    if (printEventInfo_) {
718 >      // Write information about event to screen, for testing purposes.  
719 >      cout << "Event passed all cuts in channel " <<  currentChannel.name
720 >           << ": run="  << events->at(0).run
721 >           << "  lumi=" << events->at(0).lumi
722 >           << "  event=" << events->at(0).evt
723 >           << endl;  
724      }
725  
726 <    vector<bool> electronFlags = cumulativeFlags["electrons"].back();
727 <    int electronCounter = 0;
728 <
729 <    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
730 <      if(!electronFlags.at(electronIndex)) continue;
731 <
732 <
733 <      electronCounter++;
734 <      oneDHists_.at(currentChannelIndex)["electronPt"]->Fill (electrons->at(electronIndex).pt);
735 <      oneDHists_.at(currentChannelIndex)["electronEta"]->Fill (electrons->at(electronIndex).eta);
736 <      oneDHists_.at(currentChannelIndex)["electronD0"]->Fill (electrons->at(electronIndex).correctedD0Vertex);
737 <      oneDHists_.at(currentChannelIndex)["electronDz"]->Fill (electrons->at(electronIndex).correctedDZ);
738 <      oneDHists_.at(currentChannelIndex)["electronAbsD0"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex));
739 <      oneDHists_.at(currentChannelIndex)["electronDZ"]->Fill (electrons->at(electronIndex).correctedDZ);
740 <      oneDHists_.at(currentChannelIndex)["electronAbsDZ"]->Fill (fabs(electrons->at(electronIndex).correctedDZ));
741 <      oneDHists_.at(currentChannelIndex)["electronD0Sig"]->Fill (electrons->at(electronIndex).correctedD0Vertex / electrons->at(electronIndex).tkD0err);
742 <      oneDHists_.at(currentChannelIndex)["electronAbsD0Sig"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex) / electrons->at(electronIndex).tkD0err);
743 <      oneDHists_.at(currentChannelIndex)["electronIso"]->Fill (electrons->at(electronIndex).puChargedHadronIso / electrons->at(electronIndex).pt);
744 <      oneDHists_.at(currentChannelIndex)["electronFbrem"]->Fill (electrons->at(electronIndex).fbrem);
745 <      oneDHists_.at(currentChannelIndex)["electronMVATrig"]->Fill (electrons->at(electronIndex).mvaTrigV0);
746 <      oneDHists_.at(currentChannelIndex)["electronMVANonTrig"]->Fill (electrons->at(electronIndex).mvaNonTrigV0);
726 >    //filling histograms
727 >    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
728 >      histogram currentHistogram = histograms.at(histogramIndex);
729 >
730 >      if(currentHistogram.inputVariables.size() == 1){
731 >        TH1D* histo;
732 >        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
733 >
734 >        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
735 >        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
736 >        else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").back(),scaleFactor);
737 >        else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").back(),scaleFactor);
738 >        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
739 >                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
740 >                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
741 >        else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
742 >                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("secondary muons").back(), \
743 >                                                                                       cumulativeFlags.at("muon-secondary muon pairs").back(),scaleFactor);
744 >        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
745 >        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
746 >                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
747 >                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
748 >        else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
749 >                                                                                               cumulativeFlags.at("jets").back(),cumulativeFlags.at("jets").back(),\
750 >                                                                                               cumulativeFlags.at("jet-jet pairs").back(),scaleFactor);
751 >        else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
752 >                                                                                       cumulativeFlags.at("electrons").back(),cumulativeFlags.at("secondary electrons").back(), \
753 >                                                                                       cumulativeFlags.at("electron-secondary electron pairs").back(),scaleFactor);
754 >        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
755 >                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
756 >                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
757 >        else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
758 >                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("jets").back(),
759 >                                                                                           cumulativeFlags.at("electron-jet pairs").back(),scaleFactor);
760 >        else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
761 >                                                                                           cumulativeFlags.at("muons").back(),cumulativeFlags.at("jets").back(),
762 >                                                                                           cumulativeFlags.at("muon-jet pairs").back(),scaleFactor);
763 >        else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),        
764 >                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),  
765 >                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);      
766 >        else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),        
767 >                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),  
768 >                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);      
769 >        else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),    
770 >                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),      
771 >                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);  
772 >        else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),      
773 >                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),        
774 >                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);    
775 >        else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
776 >                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("tracks").back(),
777 >                                                                                     cumulativeFlags.at("tau-track pairs").back(),scaleFactor);
778 >
779 >        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
780 >        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
781 >        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
782 >        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
783 >        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
784 >        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
785 >        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
786 >        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
787 >        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
788 >        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
789  
790 +        if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").back(),scaleFactor);
791 +      }
792 +      else if(currentHistogram.inputVariables.size() == 2){
793 +        TH2D* histo;
794 +        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
795 +
796 +        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
797 +        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
798 +        else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").back(),scaleFactor);
799 +        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
800 +                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
801 +                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
802 +        else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
803 +                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("secondary muons").back(), \
804 +                                                                                       cumulativeFlags.at("muon-secondary muon pairs").back(),scaleFactor);
805 +        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
806 +        else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").back(),scaleFactor);
807 +        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
808 +                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
809 +                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
810 +        else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
811 +                                                                                               cumulativeFlags.at("jets").back(),cumulativeFlags.at("jets").back(), \
812 +                                                                                               cumulativeFlags.at("jet-jet pairs").back(),scaleFactor);
813 +        else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
814 +                                                                                       cumulativeFlags.at("electrons").back(),cumulativeFlags.at("secondary electrons").back(), \
815 +                                                                                       cumulativeFlags.at("electron-secondary electron pairs").back(),scaleFactor);
816 +        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
817 +                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
818 +                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
819 +        else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
820 +                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("jets").back(), \
821 +                                                                                           cumulativeFlags.at("electron-jet pairs").back(),scaleFactor);
822 +        else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
823 +                                                                                           cumulativeFlags.at("muons").back(),cumulativeFlags.at("jets").back(), \
824 +                                                                                           cumulativeFlags.at("muon-jet pairs").back(),scaleFactor);
825 +        else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),        
826 +                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),          
827 +                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);      
828 +        else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),        
829 +                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),          
830 +                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);      
831 +        else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),    
832 +                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),      
833 +                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);  
834 +        else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),      
835 +                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),        
836 +                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);    
837 +        else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
838 +                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("tracks").back(),
839 +                                                                                     cumulativeFlags.at("tau-track pairs").back(),scaleFactor);
840 +        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
841 +        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
842 +        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
843 +        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
844 +        else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
845 +                                                                                         cumulativeFlags.at("tracks").back(),cumulativeFlags.at("events").back(),
846 +                                                                                         cumulativeFlags.at("track-event pairs").back(),scaleFactor);  
847 +        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
848 +        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
849 +        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
850 +        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
851 +        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
852 +        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
853 +        else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").back(),scaleFactor);
854 +      }
855      }
384    oneDHists_.at(currentChannelIndex)["numElectrons"]->Fill (electronCounter);
856  
857  
387    vector<bool> muonFlags = cumulativeFlags["muons"].back();
388    int muonCounter = 0;
858  
859 +    //fills histograms with the sizes of collections
860 +    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
861  
862 <    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
392 <      if(!muonFlags.at(muonIndex)) continue;
393 <      muonCounter++;
394 <
395 <      oneDHists_.at(currentChannelIndex)["muonPt"]->Fill (muons->at(muonIndex).pt);
396 <      oneDHists_.at(currentChannelIndex)["muonEta"]->Fill (muons->at(muonIndex).eta);
397 <      oneDHists_.at(currentChannelIndex)["muonD0"]->Fill (muons->at(muonIndex).correctedD0Vertex);
398 <      oneDHists_.at(currentChannelIndex)["muonDz"]->Fill (muons->at(muonIndex).correctedDZ);
399 <      oneDHists_.at(currentChannelIndex)["muonAbsD0"]->Fill (fabs(muons->at(muonIndex).correctedD0Vertex));
400 <      oneDHists_.at(currentChannelIndex)["muonDZ"]->Fill (muons->at(muonIndex).correctedDZ);
401 <      oneDHists_.at(currentChannelIndex)["muonAbsDZ"]->Fill (fabs(muons->at(muonIndex).correctedDZ));
402 <      oneDHists_.at(currentChannelIndex)["muonD0Sig"]->Fill (muons->at(muonIndex).correctedD0Vertex / muons->at(muonIndex).tkD0err);
403 <      oneDHists_.at(currentChannelIndex)["muonAbsD0Sig"]->Fill (fabs(muons->at(muonIndex).correctedD0Vertex) / muons->at(muonIndex).tkD0err);
404 <      oneDHists_.at(currentChannelIndex)["muonIso"]->Fill (muons->at(muonIndex).puChargedHadronIso / muons->at(muonIndex).pt);
405 <    }
406 <    oneDHists_.at(currentChannelIndex)["numMuons"]->Fill (muonCounter);
407 <
862 >      string currentObject = objectsToPlot.at(currentObjectIndex);
863  
864 +      string objectToPlot = "";  
865  
866 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().  
867 +      if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
868 +      else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
869 +      else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
870 +      else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
871 +      else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
872 +      else if(currentObject == "jet-jet pairs")            objectToPlot = "dijetPairs";
873 +      else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
874 +      else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";    
875 +      else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";      
876 +      else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
877 +      else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
878 +      else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";  
879 +      else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";  
880 +      else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";  
881 +      else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";  
882 +      else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";  
883 +      else objectToPlot = currentObject;
884 +
885 +      string tempCurrentObject = objectToPlot;
886 +      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));  
887 +      string histoName = "num" + tempCurrentObject;
888 +
889 +      //set position of primary vertex in event, in order to calculate quantities relative to it
890 +      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
891 +        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
892 +        int numToPlot = 0;
893 +        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
894 +          if(lastCutFlags.at(currentFlag)) numToPlot++;
895 +        }
896 +        if(objectToPlot == "primaryvertexs"){
897 +          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
898 +          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
899 +        }
900 +        else {
901 +          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
902 +        }
903 +      }
904 +      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
905 +      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
906 +      else if(objectToPlot == "secondaryMuons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
907 +      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
908 +      else if(objectToPlot == "muonSecondaryMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
909 +      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
910 +      else if(objectToPlot == "secondaryElectrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
911 +      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
912 +      else if(objectToPlot == "electronSecondaryElectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
913 +      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
914 +      else if(objectToPlot == "electronJetPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*jets->size(),scaleFactor);
915 +      else if(objectToPlot == "muonJetPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*jets->size(),scaleFactor);
916 +      else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
917 +      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
918 +      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
919 +      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
920 +      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
921 +      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
922 +      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
923 +      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
924 +      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
925 +      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
926 +      else if(objectToPlot == "primaryvertexs"){
927 +        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
928 +        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
929 +      }
930 +      if(objectToPlot == "stops" && datasetType_ == "signalMC") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(stops->size(),scaleFactor);
931  
932 +    } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
933  
934    } //end loop over channel
935  
936 <  masterCutFlow_->fillCutFlow();
936 >  masterCutFlow_->fillCutFlow(scaleFactor);
937  
938 + } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
939  
417 }
940  
941  
942   bool
# Line 426 | Line 948 | OSUAnalysis::evaluateComparison (double
948    else if(comparison == "<")  return testValue <  cutValue;
949    else if(comparison == "<=") return testValue <= cutValue;
950    else if(comparison == "==") return testValue == cutValue;
951 +  else if(comparison == "=") return testValue == cutValue;
952    else if(comparison == "!=") return testValue != cutValue;
953    else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
954  
# Line 461 | Line 984 | OSUAnalysis::splitString (string inputSt
984  
985   }
986  
987 +
988 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
989 +  // Set two object strings from the tempInputCollection string,
990 +  // For example, if tempInputCollection is "electron-muon pairs",
991 +  // then obj1 = "electrons" and obj2 = "muons".  
992 +  // Note that the objects have an "s" appended.  
993 +
994 +  int dashIndex = tempInputCollection.find("-");
995 +  int spaceIndex = tempInputCollection.find_last_of(" ");
996 +  int secondWordLength = spaceIndex - dashIndex;
997 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";  
998 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
999 +  
1000 + }
1001 +
1002 +
1003 + string OSUAnalysis::getObjToGet(string obj) {
1004 +  // Return the string corresponding to the object to get for the given obj string.
1005 +  // Right now this only handles the case in which obj contains "secondary",
1006 +  // e.g, "secondary muons".  
1007 +  // Note that "s" is NOT appended.  
1008 +  
1009 +  if (obj.find("secondary")==std::string::npos) return obj;  // "secondary" is not found  
1010 +  int firstSpaceIndex = obj.find_first_of(" ");  
1011 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1012 +
1013 + }  
1014 +
1015 +
1016 + //!jet valueLookup
1017   double
1018   OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1019  
# Line 590 | Line 1143 | OSUAnalysis::valueLookup (const BNjet* o
1143   }
1144  
1145  
1146 <
1146 > //!muon valueLookup
1147   double
1148   OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1149  
# Line 608 | Line 1161 | OSUAnalysis::valueLookup (const BNmuon*
1161    else if(variable == "ecalIso") value = object->ecalIso;
1162    else if(variable == "hcalIso") value = object->hcalIso;
1163    else if(variable == "caloIso") value = object->caloIso;
1164 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
1164 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
1165    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
1166    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
1167    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 746 | Line 1299 | OSUAnalysis::valueLookup (const BNmuon*
1299    else if(variable == "numberOfMatchedStations") value = object->numberOfMatchedStations;
1300    else if(variable == "time_ndof") value = object->time_ndof;
1301  
1302 +  //user-defined variables
1303 +  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1304 +  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1305 +  else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1306 +  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1307 +  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1308 +  else if(variable == "metMT") {
1309 +    const BNmet *met = chosenMET ();
1310 +    if (met)
1311 +      {
1312 +        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1313 +          p2 (met->px, met->py, 0.0, met->pt);
1314 +
1315 +        value = (p1 + p2).Mt ();
1316 +      }
1317 +    else
1318 +      value = -999;
1319 +  }
1320 +
1321 +
1322 +
1323 +  else if(variable == "correctedD0VertexInEBPlus"){
1324 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1325 +    else value = -999;
1326 +  }
1327 +  else if(variable == "correctedD0VertexOutEBPlus"){
1328 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1329 +    else value = -999;
1330 +  }
1331 +  else if(variable == "correctedD0VertexEEPlus"){
1332 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1333 +    else value = -999;
1334 +  }
1335 +
1336 +  else if(variable == "correctedD0BeamspotInEBPlus"){
1337 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1338 +    else value = -999;
1339 +  }
1340 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
1341 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1342 +    else value = -999;
1343 +  }
1344 +  else if(variable == "correctedD0BeamspotEEPlus"){
1345 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1346 +    else value = -999;
1347 +  }
1348 +
1349 +  else if(variable == "correctedD0VertexInEBMinus"){
1350 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1351 +    else value = -999;
1352 +  }
1353 +  else if(variable == "correctedD0VertexOutEBMinus"){
1354 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1355 +    else value = -999;
1356 +  }
1357 +  else if(variable == "correctedD0VertexEEMinus"){
1358 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1359 +    else value = -999;
1360 +  }
1361 +
1362 +  else if(variable == "correctedD0BeamspotInEBMinus"){
1363 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1364 +    else value = -999;
1365 +  }
1366 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
1367 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1368 +    else value = -999;
1369 +  }
1370 +  else if(variable == "correctedD0BeamspotEEMinus"){
1371 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1372 +    else value = -999;
1373 +  }
1374 +
1375 +
1376 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1377 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1378 +    else value = -999;
1379 +  }
1380 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1381 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1382 +    else value = -999;
1383 +  }
1384 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
1385 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1386 +    else value = -999;
1387 +  }
1388 +
1389 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1390 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1391 +    else value = -999;
1392 +  }
1393 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1394 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1395 +    else value = -999;
1396 +  }
1397 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1398 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1399 +    else value = -999;
1400 +  }
1401 +
1402 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1403 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1404 +    else value = -999;
1405 +  }
1406 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1407 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1408 +    else value = -999;
1409 +  }
1410 +  else if(variable == "correctedD0VertexEENegativeCharge"){
1411 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1412 +    else value = -999;
1413 +  }
1414 +
1415 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1416 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1417 +    else value = -999;
1418 +  }
1419 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1420 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1421 +    else value = -999;
1422 +  }
1423 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1424 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1425 +    else value = -999;
1426 +  }
1427 +
1428 +
1429 +  else if(variable == "tightID") {
1430 +    value = object->isGlobalMuon > 0                \
1431 +      && object->isPFMuon > 0                        \
1432 +      && object->normalizedChi2 < 10                \
1433 +                                  && object->numberOfValidMuonHits > 0        \
1434 +      && object->numberOfMatchedStations > 1        \
1435 +      && fabs(object->correctedD0Vertex) < 0.2        \
1436 +      && fabs(object->correctedDZ) < 0.5        \
1437 +      && object->numberOfValidPixelHits > 0                \
1438 +      && object->numberOfLayersWithMeasurement > 5;
1439 +  }
1440 +  else if(variable == "tightIDdisplaced"){
1441 +    value = object->isGlobalMuon > 0                \
1442 +      && object->normalizedChi2 < 10                \
1443 +                                  && object->numberOfValidMuonHits > 0        \
1444 +      && object->numberOfMatchedStations > 1        \
1445 +      && object->numberOfValidPixelHits > 0        \
1446 +      && object->numberOfLayersWithMeasurement > 5;
1447 +  }
1448 +
1449 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1450 +
1451 +  else if(variable == "genMatchedPdgId"){
1452 +    int index = getGenMatchedParticleIndex(object);
1453 +    if(index == -1) value = 0;
1454 +    else value = mcparticles->at(index).id;
1455 +  }
1456 +
1457 +  else if(variable == "genMatchedId"){
1458 +    int index = getGenMatchedParticleIndex(object);
1459 +    if(index == -1) value = 0;
1460 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
1461 +  }
1462 +  else if(variable == "genMatchedMotherId"){
1463 +    int index = getGenMatchedParticleIndex(object);
1464 +    if(index == -1) value = 0;
1465 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1466 +  }
1467 +  else if(variable == "genMatchedMotherIdReverse"){
1468 +    int index = getGenMatchedParticleIndex(object);
1469 +    if(index == -1) value = 23;
1470 +    else value = 23 - getPdgIdBinValue(mcparticles->at(index).motherId);
1471 +  }
1472 +  else if(variable == "genMatchedGrandmotherId"){
1473 +    int index = getGenMatchedParticleIndex(object);
1474 +    if(index == -1) value = 0;
1475 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1476 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1477 +      if(motherIndex == -1) value = 0;
1478 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1479 +    }
1480 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1481 +  }
1482 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1483 +    int index = getGenMatchedParticleIndex(object);
1484 +    if(index == -1) value = 23;
1485 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1486 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1487 +      if(motherIndex == -1) value = 23;
1488 +      else value = 23 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1489 +    }
1490 +    else value = 23 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1491 +  }
1492 +
1493 +
1494 +
1495    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1496  
1497    value = applyFunction(function, value);
# Line 753 | Line 1499 | OSUAnalysis::valueLookup (const BNmuon*
1499    return value;
1500   }
1501  
1502 <
1502 > //!electron valueLookup
1503   double
1504   OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1505  
# Line 915 | Line 1661 | OSUAnalysis::valueLookup (const BNelectr
1661    else if(variable == "eidHyperTight4MC") value = object->eidHyperTight4MC;
1662    else if(variable == "passConvVeto") value = object->passConvVeto;
1663  
1664 +  //user-defined variables
1665 +  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1666 +  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1667 +  else if(variable == "detIso") value = (object->trackIso) / object->pt;
1668 +  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1669 +  else if(variable == "metMT") {
1670 +    const BNmet *met = chosenMET ();
1671 +    if (met)
1672 +      {
1673 +        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1674 +          p2 (met->px, met->py, 0.0, met->pt);
1675 +
1676 +        value = (p1 + p2).Mt ();
1677 +      }
1678 +    else
1679 +      value = -999;
1680 +  }
1681 +
1682 +  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
1683 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
1684 +    else value = -999;
1685 +  }
1686 +  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
1687 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
1688 +    else value = -999;
1689 +  }
1690 +
1691 +  else if(variable == "correctedD0VertexInEBPlus"){
1692 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1693 +    else value = -999;
1694 +  }
1695 +  else if(variable == "correctedD0VertexOutEBPlus"){
1696 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1697 +    else value = -999;
1698 +  }
1699 +  else if(variable == "correctedD0VertexEEPlus"){
1700 +    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
1701 +    else value = -999;
1702 +  }
1703 +
1704 +  else if(variable == "correctedD0BeamspotInEBPlus"){
1705 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1706 +    else value = -999;
1707 +  }
1708 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
1709 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1710 +    else value = -999;
1711 +  }
1712 +  else if(variable == "correctedD0BeamspotEEPlus"){
1713 +    if(object->isEE && object->eta > 0) value = object->correctedD0;
1714 +    else value = -999;
1715 +  }
1716 +
1717 +  else if(variable == "correctedD0VertexInEBMinus"){
1718 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1719 +    else value = -999;
1720 +  }
1721 +  else if(variable == "correctedD0VertexOutEBMinus"){
1722 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1723 +    else value = -999;
1724 +  }
1725 +  else if(variable == "correctedD0VertexEEMinus"){
1726 +    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
1727 +    else value = -999;
1728 +  }
1729 +
1730 +  else if(variable == "correctedD0BeamspotInEBMinus"){
1731 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1732 +    else value = -999;
1733 +  }
1734 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
1735 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1736 +    else value = -999;
1737 +  }
1738 +  else if(variable == "correctedD0BeamspotEEMinus"){
1739 +    if(object->isEE && object->eta < 0) value = object->correctedD0;
1740 +    else value = -999;
1741 +  }
1742 +
1743 +  else if(variable == "tightID"){
1744 +    if (object->isEB)
1745 +      {
1746 +        value = fabs(object->delEtaIn) < 0.004 \
1747 +          && fabs (object->delPhiIn) < 0.03 \
1748 +          && object->scSigmaIEtaIEta < 0.01 \
1749 +          && object->hadOverEm < 0.12 \
1750 +          && fabs (object->correctedD0Vertex) < 0.02 \
1751 +          && fabs (object->correctedDZ) < 0.1 \
1752 +          && object->absInvEMinusInvPin < 0.05 \
1753 +          && object->passConvVeto;
1754 +      }
1755 +    else
1756 +      {
1757 +        value = fabs(object->delEtaIn) < 0.005 \
1758 +          && fabs (object->delPhiIn) < 0.02 \
1759 +          && object->scSigmaIEtaIEta < 0.03 \
1760 +          && object->hadOverEm < 0.10 \
1761 +          && fabs (object->correctedD0Vertex) < 0.02 \
1762 +          && fabs (object->correctedDZ) < 0.1 \
1763 +          && object->absInvEMinusInvPin < 0.05 \
1764 +          && object->passConvVeto;
1765 +      }
1766 +  }
1767 +
1768 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1769 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1770 +    else value = -999;
1771 +  }
1772 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1773 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1774 +    else value = -999;
1775 +  }
1776 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
1777 +    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
1778 +    else value = -999;
1779 +  }
1780 +
1781 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1782 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1783 +    else value = -999;
1784 +  }
1785 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1786 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1787 +    else value = -999;
1788 +  }
1789 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1790 +    if(object->isEE && object->charge > 0) value = object->correctedD0;
1791 +    else value = -999;
1792 +  }
1793 +
1794 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1795 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1796 +    else value = -999;
1797 +  }
1798 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1799 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1800 +    else value = -999;
1801 +  }
1802 +  else if(variable == "correctedD0VertexEENegativeCharge"){
1803 +    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
1804 +    else value = -999;
1805 +  }
1806 +
1807 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1808 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1809 +    else value = -999;
1810 +  }
1811 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1812 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1813 +    else value = -999;
1814 +  }
1815 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1816 +    if(object->isEE && object->charge < 0) value = object->correctedD0;
1817 +    else value = -999;
1818 +  }
1819 +
1820 +
1821 +  else if(variable == "tightIDdisplaced"){
1822 +    if (object->isEB)
1823 +      {
1824 +        value = fabs(object->delEtaIn) < 0.004 \
1825 +          && fabs (object->delPhiIn) < 0.03 \
1826 +          && object->scSigmaIEtaIEta < 0.01 \
1827 +          && object->hadOverEm < 0.12 \
1828 +          && object->absInvEMinusInvPin < 0.05;
1829 +      }
1830 +    else
1831 +      {
1832 +        value = fabs (object->delEtaIn) < 0.005 \
1833 +          && fabs (object->delPhiIn) < 0.02 \
1834 +          && object->scSigmaIEtaIEta < 0.03 \
1835 +          && object->hadOverEm < 0.10 \
1836 +          && object->absInvEMinusInvPin < 0.05;
1837 +      }
1838 +  }
1839 +
1840 +
1841 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1842 +
1843 +  else if(variable == "genMatchedPdgId"){
1844 +    int index = getGenMatchedParticleIndex(object);
1845 +    if(index == -1) value = 0;
1846 +    else value = mcparticles->at(index).id;
1847 +  }
1848 +
1849 +
1850 +  else if(variable == "genMatchedId"){
1851 +    int index = getGenMatchedParticleIndex(object);
1852 +    if(index == -1) value = 0;
1853 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
1854 +  }
1855 +  else if(variable == "genMatchedMotherId"){
1856 +    int index = getGenMatchedParticleIndex(object);
1857 +    if(index == -1) value = 0;
1858 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1859 +  }
1860 +  else if(variable == "genMatchedMotherIdReverse"){
1861 +    int index = getGenMatchedParticleIndex(object);
1862 +    if(index == -1) value = 23;
1863 +    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1864 +  }
1865 +  else if(variable == "genMatchedGrandmotherId"){
1866 +    int index = getGenMatchedParticleIndex(object);
1867 +    if(index == -1) value = 0;
1868 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1869 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1870 +      if(motherIndex == -1) value = 0;
1871 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1872 +    }
1873 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1874 +  }
1875 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1876 +    int index = getGenMatchedParticleIndex(object);
1877 +    if(index == -1) value = 23;
1878 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1879 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1880 +      if(motherIndex == -1) value = 23;
1881 +      else value = 23 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1882 +    }
1883 +    else value = 23 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1884 +  }
1885 +
1886 +
1887  
1888    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1889  
# Line 923 | Line 1892 | OSUAnalysis::valueLookup (const BNelectr
1892    return value;
1893   }
1894  
1895 <
1895 > //!event valueLookup
1896   double
1897   OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
1898  
# Line 993 | Line 1962 | OSUAnalysis::valueLookup (const BNevent*
1962    else if(variable == "id1") value = object->id1;
1963    else if(variable == "id2") value = object->id2;
1964    else if(variable == "evt") value = object->evt;
1965 +  else if(variable == "puScaleFactor"){
1966 +    if(datasetType_ != "data")
1967 +      value = puWeight_->at (events->at (0).numTruePV);
1968 +    else
1969 +      value = 1.0;
1970 +  }
1971 +  else if(variable == "muonScaleFactor"){
1972 +    if(datasetType_ != "data")
1973 +      value = muonSFWeight_->at (chosenMuon ()->eta);
1974 +    else
1975 +      value = 1.0;
1976 +  }
1977 +  else if(variable == "electronScaleFactor"){
1978 +    if(datasetType_ != "data")
1979 +      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1980 +    else
1981 +      value = 1.0;
1982 +  }
1983 +  else if(variable == "stopCTauScaleFactor")
1984 +    value = stopCTauScaleFactor_;
1985  
1986    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1987  
# Line 1001 | Line 1990 | OSUAnalysis::valueLookup (const BNevent*
1990    return value;
1991   }
1992  
1993 + //!tau valueLookup
1994   double
1995   OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
1996  
# Line 1047 | Line 2037 | OSUAnalysis::valueLookup (const BNtau* o
2037    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2038  
2039  
2040 +
2041 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2042 +
2043 +  else if(variable == "genMatchedPdgId"){
2044 +    int index = getGenMatchedParticleIndex(object);
2045 +    if(index == -1) value = 0;
2046 +    else value = mcparticles->at(index).id;
2047 +  }
2048 +
2049 +  else if(variable == "genMatchedId"){
2050 +    int index = getGenMatchedParticleIndex(object);
2051 +    if(index == -1) value = 0;
2052 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
2053 +  }
2054 +  else if(variable == "genMatchedMotherId"){
2055 +    int index = getGenMatchedParticleIndex(object);
2056 +    if(index == -1) value = 0;
2057 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2058 +  }
2059 +  else if(variable == "genMatchedMotherIdReverse"){
2060 +    int index = getGenMatchedParticleIndex(object);
2061 +    if(index == -1) value = 23;
2062 +    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2063 +  }
2064 +  else if(variable == "genMatchedGrandmotherId"){
2065 +    int index = getGenMatchedParticleIndex(object);
2066 +    if(index == -1) value = 0;
2067 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2068 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2069 +      if(motherIndex == -1) value = 0;
2070 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2071 +    }
2072 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2073 +  }
2074 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2075 +    int index = getGenMatchedParticleIndex(object);
2076 +    if(index == -1) value = 23;
2077 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2078 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2079 +      if(motherIndex == -1) value = 23;
2080 +      else value = 23 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2081 +    }
2082 +    else value = 23 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2083 +  }
2084 +
2085 +
2086    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2087  
2088    value = applyFunction(function, value);
# Line 1054 | Line 2090 | OSUAnalysis::valueLookup (const BNtau* o
2090    return value;
2091   }
2092  
2093 + //!met valueLookup
2094   double
2095   OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2096  
# Line 1126 | Line 2163 | OSUAnalysis::valueLookup (const BNmet* o
2163    return value;
2164   }
2165  
2166 + //!track valueLookup
2167   double
2168   OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2169  
2170    double value = 0.0;
2171 <
2171 >  double pMag = sqrt(object->pt * object->pt +
2172 >                     object->pz * object->pz);
2173 >  
2174    if(variable == "pt") value = object->pt;
2175    else if(variable == "px") value = object->px;
2176    else if(variable == "py") value = object->py;
# Line 1150 | Line 2190 | OSUAnalysis::valueLookup (const BNtrack*
2190    else if(variable == "isHighPurity") value = object->isHighPurity;
2191  
2192  
2193 +  //additional BNs info for disappTrks
2194 +  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2195 +  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2196 +  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2197 +  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2198 +  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2199 +  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2200 +  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2201 +  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2202 +  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2203 +  
2204 +
2205 +  //user defined variables
2206 +  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;
2207 +  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2208 +  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2209 +  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2210 +  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);  
2211 +  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;  
2212 +  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2213 +  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2214 +  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2215 +  else if(variable == "ptError")                    value = object->ptError;
2216 +  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2217 +  else if (variable == "d0wrtPV"){      
2218 +    double vx = object->vx - chosenVertex ()->x,        
2219 +      vy = object->vy - chosenVertex ()->y,      
2220 +      px = object->px,  
2221 +      py = object->py,  
2222 +      pt = object->pt;  
2223 +    value = (-vx * py + vy * px) / pt;  
2224 +  }      
2225 +  else if (variable == "dZwrtPV"){      
2226 +    double vx = object->vx - chosenVertex ()->x,        
2227 +      vy = object->vy - chosenVertex ()->y,      
2228 +      vz = object->vz - chosenVertex ()->z,      
2229 +      px = object->px,  
2230 +      py = object->py,  
2231 +      pz = object->pz,  
2232 +      pt = object->pt;  
2233 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);      
2234 +  }    
2235 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2236 +
2237 +  else if(variable == "genMatchedPdgId"){
2238 +    int index = getGenMatchedParticleIndex(object);
2239 +    if(index == -1) value = 0;
2240 +    else value = mcparticles->at(index).id;
2241 +  }
2242 +
2243 +
2244 +  else if(variable == "genMatchedId"){
2245 +    int index = getGenMatchedParticleIndex(object);
2246 +    if(index == -1) value = 0;
2247 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
2248 +  }
2249 +  else if(variable == "genMatchedMotherId"){
2250 +    int index = getGenMatchedParticleIndex(object);
2251 +    if(index == -1) value = 0;
2252 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2253 +  }
2254 +  else if(variable == "genMatchedMotherIdReverse"){
2255 +    int index = getGenMatchedParticleIndex(object);
2256 +    if(index == -1) value = 23;
2257 +    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2258 +  }
2259 +  else if(variable == "genMatchedGrandmotherId"){
2260 +    int index = getGenMatchedParticleIndex(object);
2261 +    if(index == -1) value = 0;
2262 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2263 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2264 +      if(motherIndex == -1) value = 0;
2265 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2266 +    }
2267 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2268 +  }
2269 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2270 +    int index = getGenMatchedParticleIndex(object);
2271 +    if(index == -1) value = 23;
2272 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2273 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2274 +      if(motherIndex == -1) value = 23;
2275 +      else value = 23 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2276 +    }
2277 +    else value = 23 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2278 +  }
2279 +
2280 +
2281 +
2282    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2283  
2284    value = applyFunction(function, value);
# Line 1157 | Line 2286 | OSUAnalysis::valueLookup (const BNtrack*
2286    return value;
2287   }
2288  
2289 + //!genjet valueLookup
2290   double
2291   OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2292  
# Line 1185 | Line 2315 | OSUAnalysis::valueLookup (const BNgenjet
2315    return value;
2316   }
2317  
2318 + //!mcparticle valueLookup
2319   double
2320   OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2321  
# Line 1275 | Line 2406 | OSUAnalysis::valueLookup (const BNmcpart
2406    else if(variable == "grandMother11Status") value = object->grandMother11Status;
2407    else if(variable == "grandMother11Charge") value = object->grandMother11Charge;
2408  
2409 +  //user-defined variables
2410 +  else if (variable == "d0"){
2411 +    double vx = object->vx - chosenVertex ()->x,
2412 +      vy = object->vy - chosenVertex ()->y,
2413 +      px = object->px,
2414 +      py = object->py,
2415 +      pt = object->pt;
2416 +    value = (-vx * py + vy * px) / pt;
2417 +  }
2418 +  else if (variable == "dz"){
2419 +    double vx = object->vx - chosenVertex ()->x,
2420 +      vy = object->vy - chosenVertex ()->y,
2421 +      vz = object->vz - chosenVertex ()->z,
2422 +      px = object->px,
2423 +      py = object->py,
2424 +      pz = object->pz,
2425 +      pt = object->pt;
2426 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2427 +  }
2428 +  else if(variable == "v0"){
2429 +    value = sqrt(object->vx*object->vx + object->vy*object->vy);
2430 +  }
2431 +  else if(variable == "deltaV0"){
2432 +    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
2433 +  }
2434 +  else if (variable == "deltaVx"){
2435 +    value = object->vx - chosenVertex ()->x;
2436 +  }
2437 +  else if (variable == "deltaVy"){
2438 +    value = object->vy - chosenVertex ()->y;
2439 +  }
2440 +  else if (variable == "deltaVz"){
2441 +    value = object->vz - chosenVertex ()->z;
2442 +  }
2443 +
2444 +
2445    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2446  
2447    value = applyFunction(function, value);
# Line 1282 | Line 2449 | OSUAnalysis::valueLookup (const BNmcpart
2449    return value;
2450   }
2451  
2452 + //!primaryvertex valueLookup
2453   double
2454   OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2455  
# Line 1309 | Line 2477 | OSUAnalysis::valueLookup (const BNprimar
2477    return value;
2478   }
2479  
2480 + //!bxlumi valueLookup
2481   double
2482   OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2483  
# Line 1326 | Line 2495 | OSUAnalysis::valueLookup (const BNbxlumi
2495    return value;
2496   }
2497  
2498 + //!photon valueLookup
2499   double
2500   OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2501  
# Line 1402 | Line 2572 | OSUAnalysis::valueLookup (const BNphoton
2572    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2573  
2574  
2575 +
2576 +
2577 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2578 +
2579 +  else if(variable == "genMatchedPdgId"){
2580 +    int index = getGenMatchedParticleIndex(object);
2581 +    if(index == -1) value = 0;
2582 +    else value = mcparticles->at(index).id;
2583 +  }
2584 +
2585 +
2586 +
2587 +  else if(variable == "genMatchedId"){
2588 +    int index = getGenMatchedParticleIndex(object);
2589 +    if(index == -1) value = 0;
2590 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
2591 +  }
2592 +  else if(variable == "genMatchedMotherId"){
2593 +    int index = getGenMatchedParticleIndex(object);
2594 +    if(index == -1) value = 0;
2595 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2596 +  }
2597 +  else if(variable == "genMatchedMotherIdReverse"){
2598 +    int index = getGenMatchedParticleIndex(object);
2599 +    if(index == -1) value = 23;
2600 +    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2601 +  }
2602 +  else if(variable == "genMatchedGrandmotherId"){
2603 +    int index = getGenMatchedParticleIndex(object);
2604 +    if(index == -1) value = 0;
2605 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2606 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2607 +      if(motherIndex == -1) value = 0;
2608 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2609 +    }
2610 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2611 +  }
2612 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2613 +    int index = getGenMatchedParticleIndex(object);
2614 +    if(index == -1) value = 23;
2615 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2616 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2617 +      if(motherIndex == -1) value = 23;
2618 +      else value = 23 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2619 +    }
2620 +    else value = 23 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2621 +  }
2622 +
2623 +
2624    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2625  
2626    value = applyFunction(function, value);
# Line 1409 | Line 2628 | OSUAnalysis::valueLookup (const BNphoton
2628    return value;
2629   }
2630  
2631 + //!supercluster valueLookup
2632   double
2633   OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
2634  
# Line 1431 | Line 2651 | OSUAnalysis::valueLookup (const BNsuperc
2651    return value;
2652   }
2653  
2654 + //!muon-muon pair valueLookup
2655 + double
2656 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
2657 +
2658 +  double value = 0.0;
2659 +
2660 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2661 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2662 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2663 +  else if(variable == "invMass"){
2664 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2665 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2666 +    value = (fourVector1 + fourVector2).M();
2667 +  }
2668 +  else if(variable == "pt"){
2669 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2670 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2671 +    value = (fourVector1 + fourVector2).Pt();
2672 +  }
2673 +  else if(variable == "threeDAngle")
2674 +    {
2675 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2676 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2677 +      value = (threeVector1.Angle(threeVector2));
2678 +    }
2679 +  else if(variable == "alpha")
2680 +    {
2681 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
2682 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2683 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2684 +      value = (pi-threeVector1.Angle(threeVector2));
2685 +    }
2686 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2687 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2688 +  else if(variable == "d0Sign"){
2689 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2690 +    if(d0Sign < 0) value = -0.5;
2691 +    else if (d0Sign > 0) value = 0.5;
2692 +    else value = -999;
2693 +  }
2694 +  else if(variable == "chargeProduct"){
2695 +    value = object1->charge*object2->charge;
2696 +  }
2697 +  else if(variable == "muon1CorrectedD0Vertex"){
2698 +    value = object1->correctedD0Vertex;
2699 +  }
2700 +  else if(variable == "muon2CorrectedD0Vertex"){
2701 +    value = object2->correctedD0Vertex;
2702 +  }
2703 +  else if(variable == "muon1timeAtIpInOut"){
2704 +    value = object1->timeAtIpInOut;
2705 +  }
2706 +  else if(variable == "muon2timeAtIpInOut"){
2707 +    value = object2->timeAtIpInOut;
2708 +  }
2709 +  else if(variable == "muon1correctedD0")
2710 +    {
2711 +      value = object1->correctedD0;
2712 +    }
2713 +  else if(variable == "muon2correctedD0")
2714 +    {
2715 +      value = object2->correctedD0;
2716 +    }
2717 +
2718 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2719 +
2720 +  value = applyFunction(function, value);
2721 +
2722 +  return value;
2723 + }
2724 +
2725 + //!electron-electron pair valueLookup
2726 + double
2727 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
2728 +
2729 +  double value = 0.0;
2730 +
2731 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2732 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2733 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2734 +  else if(variable == "invMass"){
2735 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2736 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2737 +    value = (fourVector1 + fourVector2).M();
2738 +  }
2739 +  else if(variable == "pt"){
2740 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2741 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2742 +    value = (fourVector1 + fourVector2).Pt();
2743 +  }
2744 +  else if(variable == "threeDAngle")
2745 +    {
2746 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2747 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2748 +      value = (threeVector1.Angle(threeVector2));
2749 +    }
2750 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2751 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2752 +  else if(variable == "d0Sign"){
2753 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2754 +    if(d0Sign < 0) value = -0.5;
2755 +    else if (d0Sign > 0) value = 0.5;
2756 +    else value = -999;
2757 +  }
2758 +  else if(variable == "chargeProduct"){
2759 +    value = object1->charge*object2->charge;
2760 +  }
2761 +  else if(variable == "electron1CorrectedD0Vertex"){
2762 +    value = object1->correctedD0Vertex;
2763 +  }
2764 +  else if(variable == "electron2CorrectedD0Vertex"){
2765 +    value = object2->correctedD0Vertex;
2766 +  }
2767 +  else if(variable == "electron1CorrectedD0"){
2768 +    value = object1->correctedD0;
2769 +  }
2770 +  else if(variable == "electron2CorrectedD0"){
2771 +    value = object2->correctedD0;
2772 +  }
2773 +
2774 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2775 +
2776 +  value = applyFunction(function, value);
2777 +
2778 +  return value;
2779 + }
2780 + //!electron-muon pair valueLookup
2781 + double
2782 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
2783 +
2784 +  double value = 0.0;
2785 +
2786 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2787 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2788 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2789 +  else if(variable == "invMass"){
2790 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2791 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2792 +    value = (fourVector1 + fourVector2).M();
2793 +  }
2794 +  else if(variable == "pt"){
2795 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2796 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2797 +    value = (fourVector1 + fourVector2).Pt();
2798 +  }
2799 +  else if(variable == "threeDAngle")
2800 +    {
2801 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2802 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2803 +      value = (threeVector1.Angle(threeVector2));
2804 +    }
2805 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2806 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2807 +  else if(variable == "d0Sign"){
2808 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2809 +    if(d0Sign < 0) value = -0.5;
2810 +    else if (d0Sign > 0) value = 0.5;
2811 +    else value = -999;
2812 +  }
2813 +  else if(variable == "chargeProduct"){
2814 +    value = object1->charge*object2->charge;
2815 +  }
2816 +  else if(variable == "electronCorrectedD0Vertex"){
2817 +    value = object1->correctedD0Vertex;
2818 +  }
2819 +  else if(variable == "muonCorrectedD0Vertex"){
2820 +    value = object2->correctedD0Vertex;
2821 +  }
2822 +  else if(variable == "electronCorrectedD0"){
2823 +    value = object1->correctedD0;
2824 +  }
2825 +  else if(variable == "muonCorrectedD0"){
2826 +    value = object2->correctedD0;
2827 +  }
2828 +  else if(variable == "electronDetIso"){
2829 +    value = (object1->trackIso) / object1->pt;
2830 +  }
2831 +  else if(variable == "muonDetIso"){
2832 +    value = (object2->trackIsoDR03) / object2->pt;
2833 +  }
2834 +  else if(variable == "electronRelPFrhoIso"){
2835 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
2836 +  }
2837 +  else if(variable == "muonRelPFdBetaIso"){
2838 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
2839 +  }
2840 +
2841 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2842 +
2843 +  value = applyFunction(function, value);
2844 +
2845 +  return value;
2846 + }
2847 +
2848 + //!electron-jet pair valueLookup
2849 + double
2850 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function){
2851 +
2852 +  double value = 0.0;
2853 +
2854 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2855 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2856 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2857 +  else if(variable == "invMass"){
2858 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2859 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2860 +    value = (fourVector1 + fourVector2).M();
2861 +  }
2862 +  else if(variable == "pt"){
2863 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2864 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2865 +    value = (fourVector1 + fourVector2).Pt();
2866 +  }
2867 +  else if(variable == "threeDAngle")
2868 +    {
2869 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2870 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2871 +      value = (threeVector1.Angle(threeVector2));
2872 +    }
2873 +  else if(variable == "chargeProduct"){
2874 +    value = object1->charge*object2->charge;
2875 +  }
2876 +
2877 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2878 +
2879 +  value = applyFunction(function, value);
2880 +
2881 +  return value;
2882 + }
2883 +
2884 + //!muon-jet pair valueLookup
2885 + double
2886 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function){
2887 +
2888 +  double value = 0.0;
2889 +
2890 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2891 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2892 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2893 +  else if(variable == "invMass"){
2894 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2895 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2896 +    value = (fourVector1 + fourVector2).M();
2897 +  }
2898 +  else if(variable == "pt"){
2899 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2900 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2901 +    value = (fourVector1 + fourVector2).Pt();
2902 +  }
2903 +  else if(variable == "threeDAngle")
2904 +    {
2905 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2906 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2907 +      value = (threeVector1.Angle(threeVector2));
2908 +    }
2909 +  else if(variable == "chargeProduct"){
2910 +    value = object1->charge*object2->charge;
2911 +  }
2912 +
2913 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2914 +
2915 +  value = applyFunction(function, value);
2916 +
2917 +  return value;
2918 + }
2919 +
2920 + //!jet-jet pair valueLookup
2921 + double
2922 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function){
2923 +
2924 +  double value = 0.0;
2925 +
2926 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2927 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2928 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2929 +  else if(variable == "invMass"){
2930 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2931 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2932 +    value = (fourVector1 + fourVector2).M();
2933 +  }
2934 +  else if(variable == "pt"){
2935 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2936 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2937 +    value = (fourVector1 + fourVector2).Pt();
2938 +  }
2939 +  else if(variable == "threeDAngle")
2940 +    {
2941 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2942 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2943 +      value = (threeVector1.Angle(threeVector2));
2944 +    }
2945 +  else if(variable == "chargeProduct"){
2946 +    value = object1->charge*object2->charge;
2947 +  }
2948 +  
2949 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2950 +
2951 +  value = applyFunction(function, value);
2952 +
2953 +  return value;
2954 + }
2955 + //!electron-track pair valueLookup
2956 + double  
2957 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function){  
2958 +  double electronMass = 0.000511;        
2959 +  double value = 0.0;    
2960 +  TLorentzVector fourVector1(0, 0, 0, 0);        
2961 +  TLorentzVector fourVector2(0, 0, 0, 0);        
2962 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));  
2963 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2964 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);    
2965 +  else if(variable == "invMass"){        
2966 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);    
2967 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );    
2968 +        
2969 +    value = (fourVector1 + fourVector2).M();    
2970 +  }
2971 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}  
2972 +  value = applyFunction(function, value);        
2973 +  return value;  
2974 + }
2975 +
2976 +
2977 + //!muon-track pair valueLookup
2978 + double
2979 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function){
2980 +  double pionMass = 0.140;
2981 +  double muonMass = 0.106;
2982 +  double value = 0.0;
2983 +  TLorentzVector fourVector1(0, 0, 0, 0);
2984 +  TLorentzVector fourVector2(0, 0, 0, 0);
2985 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2986 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2987 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2988 +  else if(variable == "invMass"){
2989 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
2990 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
2991 +
2992 +    value = (fourVector1 + fourVector2).M();
2993 +  }
2994 +
2995 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2996 +  value = applyFunction(function, value);
2997 +  return value;
2998 + }
2999 +
3000 + //!tau-tau pair valueLookup
3001 + double
3002 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function){
3003 +  double value = 0.0;
3004 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3005 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3006 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3007 +  else if(variable == "invMass"){
3008 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3009 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3010 +    value = (fourVector1 + fourVector2).M();
3011 +  }
3012 +
3013 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3014 +  value = applyFunction(function, value);
3015 +  return value;
3016 + }
3017 +
3018 + //!muon-tau pair valueLookup
3019 + double
3020 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function){
3021 +  double value = 0.0;
3022 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3023 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3024 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3025 +  else if(variable == "invMass"){
3026 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3027 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3028 +    value = (fourVector1 + fourVector2).M();
3029 +  }
3030 +
3031 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3032 +  value = applyFunction(function, value);
3033 +  return value;
3034 + }
3035 +
3036 + //!tau-track pair valueLookup
3037 + double
3038 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function){
3039 +  double value = 0.0;
3040 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3041 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3042 +
3043 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3044 +  value = applyFunction(function, value);
3045 +  return value;
3046 + }
3047 +
3048 +
3049 + //!track-event pair valueLookup
3050 + double
3051 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function){
3052 +
3053 +  double value = 0.0;
3054 +  double pMag = sqrt(object1->pt * object1->pt +
3055 +                     object1->pz * object1->pz);  
3056 +
3057 +  if      (variable == "numPV")                      value = object2->numPV;
3058 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3059 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3060 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);  
3061 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;  
3062 +
3063 +  else { std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3064 +
3065 +  value = applyFunction(function, value);
3066 +
3067 +  return value;
3068 +
3069 + }
3070 +
3071 + //!stop valueLookup
3072 + double
3073 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function){
3074 +
3075 +
3076 +  double value = 0.0;
3077 +
3078 +  if(variable == "ctau") value = object->ctau;
3079 +
3080 +  else if (variable == "d0"){
3081 +    double vx = object->vx - chosenVertex ()->x,
3082 +      vy = object->vy - chosenVertex ()->y,
3083 +      px = object->px,
3084 +      py = object->py,
3085 +      pt = object->pt;
3086 +    value = (-vx * py + vy * px) / pt;
3087 +  }
3088 +
3089 +  else if (variable == "dz"){
3090 +    double vx = object->vx - chosenVertex ()->x,
3091 +      vy = object->vy - chosenVertex ()->y,
3092 +      vz = object->vz - chosenVertex ()->z,
3093 +      px = object->px,
3094 +      py = object->py,
3095 +      pz = object->pz,
3096 +      pt = object->pt;
3097 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3098 +  }
3099 +
3100 +  else if (variable == "minD0"){
3101 +    double minD0=999;
3102 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3103 +      double vx = object->vx - vertex->x,
3104 +        vy = object->vy - vertex->y,
3105 +        px = object->px,
3106 +        py = object->py,
3107 +        pt = object->pt;
3108 +      value = (-vx * py + vy * px) / pt;
3109 +      if(abs(value) < abs(minD0)) minD0 = value;
3110 +    }
3111 +    value = minD0;
3112 +  }
3113 +  else if (variable == "minDz"){
3114 +    double minDz=999;
3115 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3116 +      double vx = object->vx - vertex->x,
3117 +        vy = object->vy - vertex->y,
3118 +        vz = object->vz - vertex->z,
3119 +        px = object->px,
3120 +        py = object->py,
3121 +        pz = object->pz,
3122 +        pt = object->pt;
3123 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3124 +      if(abs(value) < abs(minDz)) minDz = value;
3125 +    }
3126 +    value = minDz;
3127 +  }
3128 +  else if(variable == "distToVertex"){
3129 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3130 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3131 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3132 +  }
3133 +  else if (variable == "minDistToVertex"){
3134 +    double minDistToVertex=999;
3135 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3136 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3137 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3138 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3139 +      
3140 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3141 +    }
3142 +    value = minDistToVertex;
3143 +  }
3144 +  else if (variable == "distToVertexDifference"){
3145 +    double minDistToVertex=999;
3146 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3147 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3148 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3149 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3150 +      
3151 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3152 +    }
3153 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3154 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3155 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3156 +
3157 +    value = distToChosenVertex - minDistToVertex;
3158 +  }
3159 +
3160 +  else if (variable == "closestVertexRank"){
3161 +    double minDistToVertex=999;
3162 +    int vertex_rank = 0;
3163 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3164 +      vertex_rank++;
3165 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3166 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3167 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3168 +      
3169 +      if(abs(dist) < abs(minDistToVertex)){
3170 +        value = vertex_rank;
3171 +        minDistToVertex = dist;
3172 +      }
3173 +    }
3174 +  }
3175 +
3176 +
3177 +
3178 +
3179 +  else { std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3180 +
3181 +  value = applyFunction(function, value);
3182 +
3183 +  return value;
3184 +
3185 + }  
3186 +
3187 +
3188 +
3189 +
3190 + // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3191 + // Return true iff no other tracks are found in this cone.
3192 + int
3193 + OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
3194 +  for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
3195 +    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
3196 +    double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
3197 +    if(deltaRtrk < 0.5) return 0;
3198 +  }
3199 +  return 1;
3200 +
3201 + }
3202 +
3203 +
3204 + double
3205 + OSUAnalysis::getTrkPtRes (const BNtrack* track1){
3206 +
3207 +  double ptTrue = getTrkPtTrue(track1, mcparticles.product());
3208 +  double PtRes = (track1->pt - ptTrue) / ptTrue;
3209 +
3210 +  return PtRes;
3211 +
3212 + }
3213 +
3214 +
3215 + double
3216 + OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
3217 +  double value = -99;
3218 +  double genDeltaRLowest = 999;
3219 +
3220 +  for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
3221 +    double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
3222 +    if (genDeltaRtemp < genDeltaRLowest) {
3223 +      genDeltaRLowest = genDeltaRtemp;
3224 +      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
3225 +        double ptTrue = genPart->pt;
3226 +        value = ptTrue;
3227 +      }
3228 +    }
3229 +  }
3230 +
3231 +  return value;
3232 +
3233 + }
3234 +
3235 + double
3236 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3237 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.  
3238 +  if (!useTrackCaloRhoCorr_) return -99;  
3239 +  // if (!rhokt6CaloJetsHandle_) {
3240 +  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;  
3241 +  //   return -99;  
3242 +  // }
3243 +  double radDeltaRCone = 0.5;  
3244 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.  
3245 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;  
3246 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);  
3247 +  return caloTotRhoCorrCalo;  
3248 +
3249 + }
3250 +
3251 +
3252 +
3253 +
3254 + //creates a map of the dead Ecal channels in the barrel and endcap
3255 + //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
3256 + //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
3257 + void
3258 + OSUAnalysis::WriteDeadEcal (){
3259 +  double etaEcal, phiEcal;
3260 +  ifstream DeadEcalFile(deadEcalFile_);
3261 +  if(!DeadEcalFile) {
3262 +    cout << "Error: DeadEcalFile has not been found." << endl;
3263 +    return;
3264 +  }
3265 +  if(DeadEcalVec.size()!= 0){
3266 +    cout << "Error: DeadEcalVec has a nonzero size" << endl;
3267 +    return;
3268 +  }
3269 +  while(!DeadEcalFile.eof())
3270 +    {
3271 +      DeadEcalFile >> etaEcal >> phiEcal;
3272 +      DeadEcal newChan;
3273 +      newChan.etaEcal = etaEcal;
3274 +      newChan.phiEcal = phiEcal;
3275 +      DeadEcalVec.push_back(newChan);
3276 +    }
3277 +  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
3278 + }
3279 +
3280 + //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
3281 + int
3282 + OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
3283 +  double deltaRLowest = 999;
3284 +  int value = 0;
3285 +  if (DeadEcalVec.size() == 0) WriteDeadEcal();
3286 +  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3287 +    double eta = ecal->etaEcal;
3288 +    double phi = ecal->phiEcal;
3289 +    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
3290 +    if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3291 +  }
3292 +  if (deltaRLowest<0.05) {value = 1;}
3293 +  else {value = 0;}
3294 +  return value;
3295 + }
3296 +
3297 + // Returns the smallest DeltaR between the object and any generated true particle in the event.  
3298 + template <class InputObject>
3299 + double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3300 +  double genDeltaRLowest = 999.;
3301 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3302 +    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
3303 +    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
3304 +  }
3305 +  return genDeltaRLowest;
3306 + }
3307  
3308   double
3309   OSUAnalysis::applyFunction(string function, double value){
3310  
3311 <  if(function == "abs") value = abs(value);
3311 >  if(function == "abs") value = fabs(value);
3312 >  else if(function == "fabs") value = fabs(value);
3313 >  else if(function == "log10") value = log10(value);
3314 >  else if(function == "log") value = log10(value);
3315  
3316 +  else if(function == "") value = value;
3317 +  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
3318  
3319    return value;
3320  
# Line 1445 | Line 3323 | OSUAnalysis::applyFunction(string functi
3323  
3324   template <class InputCollection>
3325   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
3326 <
3326 >
3327 >  if (currentCut.inputCollection.find("pair")!=std::string::npos)  {
3328 >    string obj1, obj2;
3329 >    getTwoObjs(currentCut.inputCollection, obj1, obj2);
3330 >    if (inputType==obj1 ||
3331 >        inputType==obj2) {
3332 >      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
3333 >      // and the inputType is a member of the pair.  
3334 >      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.  
3335 >      // For example, if currentCut.inputCollection==electron-muon pairs,
3336 >      // then the flags should not be set here when inputType==muons or inputType==electrons.  
3337 >      return;
3338 >    }  
3339 >  }    
3340  
3341    for (uint object = 0; object != inputCollection->size(); object++){
3342  
# Line 1453 | Line 3344 | void OSUAnalysis::setObjectFlags(cut &cu
3344  
3345      if(currentCut.inputCollection == inputType){
3346  
3347 <      double value = valueLookup(&inputCollection->at(object), currentCut.variable, currentCut.function);
3347 >      vector<bool> subcutDecisions;
3348 >      for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3349 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3350 >        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3351  
3352 <      decision = evaluateComparison(value,currentCut.comparativeOperator,currentCut.cutValue);
3352 >      }
3353 >      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3354 >      else{
3355 >        bool tempDecision = true;
3356 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
3357 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
3358 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
3359 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
3360 >            tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
3361 >        }
3362 >        decision = tempDecision;
3363 >      }
3364      }
1460    individualFlags[inputType].at(currentCutIndex).push_back(decision);
3365  
3366 +    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3367  
3368      //set flags for objects that pass each cut AND all the previous cuts
3369      bool previousCumulativeFlag = true;
3370      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3371 <      if(previousCumulativeFlag && individualFlags[inputType].at(previousCutIndex).at(object)) previousCumulativeFlag = true;
3371 >      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
3372        else{ previousCumulativeFlag = false; break;}
3373      }
3374 <    cumulativeFlags[inputType].at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3374 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3375  
3376    }
3377  
3378   }
3379  
3380  
3381 + template <class InputCollection1, class InputCollection2>
3382 + void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
3383 +                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
3384 +
3385 +
3386 +  bool sameObjects = false;
3387 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3388 +
3389 +  // Get the strings for the two objects that make up the pair.  
3390 +  string obj1Type, obj2Type;
3391 +  getTwoObjs(inputType, obj1Type, obj2Type);
3392 +  bool isTwoTypesOfObject = true;
3393 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;  
3394 +
3395 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.  
3396 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).  
3397 +  if (currentCut.inputCollection == inputType) {    
3398 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
3399 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3400 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3401 +    }
3402 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.  
3403 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
3404 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3405 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3406 +      }
3407 +    }
3408 +  }
3409 +  
3410 +  int counter = 0;
3411  
3412 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3413 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3414  
3415 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3416  
3417 < DEFINE_FWK_MODULE(OSUAnalysis);
3417 >
3418 >      bool decision = true;//object passes if this cut doesn't cut on that type of object
3419 >
3420 >      if(currentCut.inputCollection == inputType){
3421 >
3422 >        vector<bool> subcutDecisions;
3423 >        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3424 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3425 >          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3426 >        }
3427 >
3428 >        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3429 >        else{
3430 >          bool tempDecision = subcutDecisions.at(0);
3431 >          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
3432 >            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
3433 >              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
3434 >            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
3435 >              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
3436 >          }
3437 >          decision = tempDecision;
3438 >        }
3439 >      }
3440 >      // if (decision) isPassObj1.at(object1) = true;
3441 >      // if (decision) isPassObj2.at(object2) = true;
3442 >      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);  
3443 >      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on  
3444 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;  
3445 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;  
3446 >      }  
3447 >
3448 >      //set flags for objects that pass each cut AND all the previous cuts
3449 >      bool previousCumulativeFlag = true;
3450 >      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3451 >        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
3452 >        else{ previousCumulativeFlag = false; break;}
3453 >      }
3454 >      //apply flags for the components of the composite object as well
3455 >      bool currentCumulativeFlag = true;
3456 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
3457 >      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
3458 >      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
3459 >      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
3460 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
3461 >      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on  
3462 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);  
3463 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);  
3464 >      }
3465 >      counter++;
3466 >
3467 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
3468 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
3469 >
3470 > }
3471  
3472  
3473 + bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
3474 +  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
3475 +  // all cuts up to currentCutIndex  
3476 +  bool previousCumulativeFlag = true;  
3477 +  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {  
3478 +    if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
3479 +    else {  
3480 +      previousCumulativeFlag = false; break;  
3481 +    }
3482 +  }
3483 +  return previousCumulativeFlag;  
3484 + }  
3485 +
3486 +
3487 + template <class InputCollection>
3488 + void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3489 +
3490 +  for (uint object = 0; object != inputCollection->size(); object++){
3491 +
3492 +    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3493 +
3494 +    string currentString = parameters.inputVariables.at(0);
3495 +    string inputVariable = "";
3496 +    string function = "";
3497 +    if(currentString.find("(")==std::string::npos){
3498 +      inputVariable = currentString;// variable to cut on
3499 +    }
3500 +    else{
3501 +      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3502 +      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3503 +      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3504 +    }
3505 +
3506 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
3507 +    histo->Fill(value,scaleFactor);
3508 +
3509 +    if (printEventInfo_) {
3510 +      // Write information about event to screen, for testing purposes.  
3511 +      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;  
3512 +    }
3513 +    
3514 +  }
3515 + }
3516 +
3517 + template <class InputCollection1, class InputCollection2>
3518 + void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3519 +
3520 +  bool sameObjects = false;
3521 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3522 +
3523 +  int pairCounter = -1;
3524 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3525 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3526 +
3527 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3528 +
3529 +      pairCounter++;
3530 +      //only take objects which have passed all cuts and pairs which have passed all cuts
3531 +      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3532 +      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3533 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3534 +
3535 +      string currentString = parameters.inputVariables.at(0);
3536 +      string inputVariable = "";
3537 +      string function = "";
3538 +      if(currentString.find("(")==std::string::npos){
3539 +        inputVariable = currentString;// variable to cut on
3540 +      }
3541 +      else{
3542 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3543 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3544 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3545 +      }
3546 +
3547 +      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3548 +      histo->Fill(value,scaleFactor);
3549 +
3550 +    }
3551 +  }
3552 +
3553 + }
3554 +
3555 +
3556 + template <class InputCollection>
3557 + void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3558 +
3559 +  for (uint object = 0; object != inputCollection->size(); object++){
3560 +
3561 +    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3562 +
3563 +    string currentString = parameters.inputVariables.at(0);
3564 +    string inputVariable = "";
3565 +    string function = "";
3566 +    if(currentString.find("(")==std::string::npos){
3567 +      inputVariable = currentString;// variable to cut on
3568 +    }
3569 +    else{
3570 +      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3571 +      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3572 +      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3573 +    }
3574 +    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
3575 +
3576 +    currentString = parameters.inputVariables.at(1);
3577 +    inputVariable = "";
3578 +    function = "";
3579 +    if(currentString.find("(")==std::string::npos){
3580 +      inputVariable = currentString;// variable to cut on
3581 +    }
3582 +    else{
3583 +      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3584 +      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3585 +      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3586 +    }
3587 +
3588 +    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
3589 +
3590 +    histo->Fill(valueX,valueY,scaleFactor);
3591 +
3592 +  }
3593 +
3594 + }
3595 +
3596 + template <class InputCollection1, class InputCollection2>
3597 + void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3598 +
3599 +  bool sameObjects = false;
3600 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3601 +
3602 +  int pairCounter = -1;
3603 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3604 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3605 +
3606 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3607 +
3608 +      pairCounter++;
3609 +
3610 +      //only take objects which have passed all cuts and pairs which have passed all cuts
3611 +      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3612 +      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3613 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3614 +
3615 +      string currentString = parameters.inputVariables.at(0);
3616 +      string inputVariable = "";
3617 +      string function = "";
3618 +      if(currentString.find("(")==std::string::npos){
3619 +        inputVariable = currentString;// variable to cut on
3620 +      }
3621 +      else{
3622 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3623 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3624 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3625 +      }
3626 +      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3627 +
3628 +      currentString = parameters.inputVariables.at(1);
3629 +      inputVariable = "";
3630 +      function = "";
3631 +      if(currentString.find("(")==std::string::npos){
3632 +        inputVariable = currentString;// variable to cut on
3633 +      }
3634 +      else{
3635 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3636 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3637 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3638 +      }
3639 +      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3640 +
3641 +
3642 +      histo->Fill(valueX,valueY,scaleFactor);
3643 +
3644 +    }
3645 +  }
3646 +
3647 + }
3648 +
3649 +
3650 + template <class InputObject>
3651 + int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
3652 +
3653 +  int bestMatchIndex = -1;
3654 +  double bestMatchDeltaR = 999;
3655 +
3656 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3657 +
3658 +    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
3659 +    if(currentDeltaR > 0.05) continue;
3660 +    //     cout << std::setprecision(3) << std::setw(20)
3661 +    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
3662 +    //          << std::setw(20)
3663 +    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
3664 +    //          << std::setw(20)
3665 +    //          << "\tdeltaR = " << currentDeltaR
3666 +    //          << std::setprecision(1)
3667 +    //          << std::setw(20)
3668 +    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
3669 +    //          << std::setw(20)
3670 +    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
3671 +    //          << std::setw(20)
3672 +    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
3673 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
3674 +      bestMatchIndex = mcparticle - mcparticles->begin();
3675 +      bestMatchDeltaR = currentDeltaR;
3676 +    }
3677 +
3678 +  }
3679 +  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
3680 +  //   else cout << "no match found..." << endl;
3681 +  return bestMatchIndex;
3682 +
3683 + }
3684 +
3685 +
3686 + int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
3687 +
3688 +  int bestMatchIndex = -1;
3689 +  double bestMatchDeltaR = 999;
3690 +
3691 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3692 +
3693 +    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
3694 +
3695 +    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
3696 +    if(currentDeltaR > 0.05) continue;
3697 +
3698 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
3699 +      bestMatchIndex = mcparticle - mcparticles->begin();
3700 +      bestMatchDeltaR = currentDeltaR;
3701 +    }
3702 +
3703 +  }
3704 +
3705 +  return bestMatchIndex;
3706 + }
3707 +
3708 +
3709 + // bin      particle type
3710 + // ---      -------------
3711 + //  0        unmatched
3712 + //  1        u
3713 + //  2        d
3714 + //  3        s
3715 + //  4        c
3716 + //  5        b
3717 + //  6        t
3718 + //  7        e
3719 + //  8        mu
3720 + //  9        tau
3721 + // 10        nu
3722 + // 11        g
3723 + // 12        gamma
3724 + // 13        Z
3725 + // 14        W
3726 + // 15        light meson
3727 + // 16        K meson
3728 + // 17        D meson
3729 + // 18        B meson
3730 + // 19        light baryon
3731 + // 20        strange baryon
3732 + // 21        charm baryon
3733 + // 22        bottom baryon
3734 + // 23        other
3735 +
3736 + int OSUAnalysis::getPdgIdBinValue(int pdgId){
3737 +
3738 +  int binValue = -999;
3739 +  int absPdgId = fabs(pdgId);
3740 +  if(pdgId == -1) binValue = 0;
3741 +  else if(absPdgId <= 6 ) binValue = absPdgId;
3742 +  else if(absPdgId == 11 ) binValue = 7;
3743 +  else if(absPdgId == 13 ) binValue = 8;
3744 +  else if(absPdgId == 15 ) binValue = 9;
3745 +  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
3746 +  else if(absPdgId == 21 ) binValue = 11;
3747 +  else if(absPdgId == 22 ) binValue = 12;
3748 +  else if(absPdgId == 23 ) binValue = 13;
3749 +  else if(absPdgId == 24 ) binValue = 14;
3750 +  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
3751 +  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
3752 +  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
3753 +  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
3754 +  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
3755 +  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
3756 +  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
3757 +  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
3758 +
3759 +  else binValue = 23;
3760 +
3761 +  return binValue;
3762 +
3763 + }
3764 +
3765 + const BNprimaryvertex *
3766 + OSUAnalysis::chosenVertex ()
3767 + {
3768 +  const BNprimaryvertex *chosenVertex = 0;
3769 +  if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
3770 +    vector<bool> vertexFlags;
3771 +    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
3772 +      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
3773 +        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
3774 +        break;
3775 +      }
3776 +    }
3777 +    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
3778 +      if(!vertexFlags.at(vertexIndex)) continue;
3779 +      chosenVertex = & primaryvertexs->at(vertexIndex);
3780 +      break;
3781 +    }
3782 +  }
3783 +  else {
3784 +    chosenVertex = &primaryvertexs->at(0);
3785 +  }
3786 +
3787 +  return chosenVertex;
3788 + }
3789 +
3790 + const BNmet *
3791 + OSUAnalysis::chosenMET ()
3792 + {
3793 +  const BNmet *chosenMET = 0;
3794 +  if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
3795 +    vector<bool> metFlags;
3796 +    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
3797 +      if (cumulativeFlags.at("mets").at(i).size()){
3798 +        metFlags = cumulativeFlags.at("mets").at(i);
3799 +        break;
3800 +      }
3801 +    }
3802 +    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
3803 +      if(!metFlags.at(metIndex)) continue;
3804 +      chosenMET = & mets->at(metIndex);
3805 +      break;
3806 +    }
3807 +  }
3808 +  else {
3809 +    chosenMET = &mets->at(0);
3810 +  }
3811 +
3812 +  return chosenMET;
3813 + }
3814 +
3815 + const BNelectron *
3816 + OSUAnalysis::chosenElectron ()
3817 + {
3818 +  const BNelectron *chosenElectron = 0;
3819 +  if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
3820 +    vector<bool> electronFlags;
3821 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
3822 +      if (cumulativeFlags.at("electrons").at(i).size()){
3823 +        electronFlags = cumulativeFlags.at("electrons").at(i);
3824 +        break;
3825 +      }
3826 +    }
3827 +    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
3828 +      if(!electronFlags.at(electronIndex)) continue;
3829 +      chosenElectron = & electrons->at(electronIndex);
3830 +      break;
3831 +    }
3832 +  }
3833 +  else {
3834 +    chosenElectron = &electrons->at(0);
3835 +  }
3836 +
3837 +  return chosenElectron;
3838 + }
3839 +
3840 + const BNmuon *
3841 + OSUAnalysis::chosenMuon ()
3842 + {
3843 +  const BNmuon *chosenMuon = 0;
3844 +  if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
3845 +    vector<bool> muonFlags;
3846 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
3847 +      if (cumulativeFlags.at("muons").at(i).size()){
3848 +        muonFlags = cumulativeFlags.at("muons").at(i);
3849 +        break;
3850 +      }
3851 +    }
3852 +    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
3853 +      if(!muonFlags.at(muonIndex)) continue;
3854 +      chosenMuon = & muons->at(muonIndex);
3855 +      break;
3856 +    }
3857 +  }
3858 +  else {
3859 +    chosenMuon = &muons->at(0);
3860 +  }
3861 +
3862 +  return chosenMuon;
3863 + }
3864 +
3865 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines