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.42 by wulsin, Wed Mar 27 22:38:08 2013 UTC vs.
Revision 1.104 by wulsin, Mon Jul 22 15:39:13 2013 UTC

# Line 1 | Line 1
1   #include "OSUT3Analysis/AnaTools/plugins/OSUAnalysis.h"
2
2   OSUAnalysis::OSUAnalysis (const edm::ParameterSet &cfg) :
3    // Retrieve parameters from the configuration file.
4    jets_ (cfg.getParameter<edm::InputTag> ("jets")),
# Line 11 | Line 10 | OSUAnalysis::OSUAnalysis (const edm::Par
10    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
11    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
12    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
13 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
14    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
15    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
16    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
17    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
18    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
19 <  puFile_ (cfg.getParameter<std::string> ("puFile")),
20 <  deadEcalFile_ (cfg.getParameter<std::string> ("deadEcalFile")),
21 <  muonSFFile_ (cfg.getParameter<std::string> ("muonSFFile")),
22 <  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
23 <  electronSFID_ (cfg.getParameter<std::string> ("electronSFID")),
24 <  muonSF_ (cfg.getParameter<std::string> ("muonSF")),
25 <  dataset_ (cfg.getParameter<std::string> ("dataset")),
26 <  datasetType_ (cfg.getParameter<std::string> ("datasetType")),
19 >  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
20 >  puFile_ (cfg.getParameter<string> ("puFile")),
21 >  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
22 >  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
23 >  dataPU_ (cfg.getParameter<string> ("dataPU")),
24 >  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
25 >  muonSF_ (cfg.getParameter<string> ("muonSF")),
26 >  dataset_ (cfg.getParameter<string> ("dataset")),
27 >  datasetType_ (cfg.getParameter<string> ("datasetType")),
28    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
29    histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
30 +  useEDMFormat_   (cfg.getParameter<bool>("useEDMFormat")),
31 +  treeBranchSets_   (cfg.getParameter<vector<edm::ParameterSet> >("treeBranchSets")),
32    plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
33    doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
34 <  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
35 <  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr"))
36 <
37 < {
34 >  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
35 >  applyBtagSF_ (cfg.getParameter<bool> ("applyBtagSF")),
36 >  minBtag_ (cfg.getParameter<int> ("minBtag")),
37 >  printEventInfo_      (cfg.getParameter<bool> ("printEventInfo")),
38 >  printAllTriggers_    (cfg.getParameter<bool> ("printAllTriggers")),
39 >  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
40 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
41 >  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
42 > {
43  
44    TH1::SetDefaultSumw2 ();
45  
46    //create pile-up reweighting object, if necessary
47    if(datasetType_ != "data") {
48      if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
49 <    //    muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
50 <    //    electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
49 >    if (applyLeptonSF_){
50 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
51 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
52 >    }
53 >    if (applyBtagSF_){
54 >      bTagSFWeight_ = new BtagSFWeight;
55 >    }
56    }
57 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
58 +    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
59  
60  
61    // Construct Cutflow Objects. These store the results of cut decisions and
62    // handle filling cut flow histograms.
63    masterCutFlow_ = new CutFlow (fs_);
49  std::vector<TFileDirectory> directories;
64  
65    //always get vertex collection so we can assign the primary vertex in the event
66    objectsToGet.push_back("primaryvertexs");
53
54  //always make the plot of number of primary verticex (to check pile-up reweighting)
67    objectsToPlot.push_back("primaryvertexs");
68 +  objectsToFlag.push_back("primaryvertexs");
69 +
70  
71    //always get the MC particles to do GEN-matching
72    objectsToGet.push_back("mcparticles");
# Line 60 | Line 74 | OSUAnalysis::OSUAnalysis (const edm::Par
74    //always get the event collection to do pile-up reweighting
75    objectsToGet.push_back("events");
76  
77 +
78 +  // Parse the tree variable definitions.
79 +  for (uint iBranchSet = 0; !useEDMFormat_ && iBranchSet<treeBranchSets_.size(); iBranchSet++) {
80 +    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
81 +    if(tempInputCollection.find("pairs")!=string::npos) { clog << "Warning:  tree filling is not configured for pairs of objects, so will not work for collection: " << tempInputCollection << endl; }
82 +    objectsToGet.push_back(tempInputCollection);
83 +    objectsToFlag.push_back(tempInputCollection);
84 +
85 +    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
86 +
87 +    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
88 +      BranchSpecs br;
89 +      br.inputCollection = tempInputCollection;
90 +      br.inputVariable = branchList.at(iBranch);
91 +      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);
92 +      br.name = string(newName.Data());
93 +      treeBranches_.push_back(br);
94 +    }
95 +
96 +  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++)
97 +
98 +
99    //parse the histogram definitions
100    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
101  
102      string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
103      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
104 +    if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
105 +    if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
106 +    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
107 +    if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
108 +    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
109 +    if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
110 +    if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
111 +    if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
112      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
113 <    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
114 <      objectsToGet.push_back(tempInputCollection);
113 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
114 >    if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
115 >    if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
116 >    if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
117 >    if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
118 >    if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
119 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
120 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
121 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
122 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
123 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
124 >        int spaceIndex = tempInputCollection.find(" ");
125 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
126 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
127 >      }
128 >      else{
129 >        objectsToGet.push_back(tempInputCollection);
130 >      }
131        objectsToPlot.push_back(tempInputCollection);
132 <      objectsToCut.push_back(tempInputCollection);
133 <    }
134 <    else{//pair of objects, need to add them both to the things to objectsToGet
135 <      int dashIndex = tempInputCollection.find("-");
136 <      int spaceIndex = tempInputCollection.find(" ");
137 <      int secondWordLength = spaceIndex - dashIndex;
138 <      objectsToGet.push_back(tempInputCollection);
139 <      objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
140 <      objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
132 >      objectsToFlag.push_back(tempInputCollection);
133 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
134 >      string obj1;
135 >      string obj2;
136 >      getTwoObjs(tempInputCollection, obj1, obj2);
137 >      string obj2ToGet = getObjToGet(obj2);
138 >      objectsToFlag.push_back(tempInputCollection);
139 >      objectsToFlag.push_back(obj1);
140 >      objectsToFlag.push_back(obj2);
141        objectsToPlot.push_back(tempInputCollection);
142 <      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
143 <      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
144 <      objectsToCut.push_back(tempInputCollection);
145 <      objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
146 <      objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
142 >      objectsToPlot.push_back(obj1);
143 >      objectsToPlot.push_back(obj2);
144 >      objectsToGet.push_back(tempInputCollection);
145 >      objectsToGet.push_back(obj1);
146 >      objectsToGet.push_back(obj2ToGet);
147 >    } // end else
148 >      if (find(objectsToPlot.begin(), objectsToPlot.end(), "events") != objectsToPlot.end())
149 >        objectsToGet.push_back("jets");
150  
88      }
151  
152      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
153  
154      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
155  
156 +      vector<double> defaultValue;
157 +      defaultValue.push_back (-1.0);
158 +
159        histogram tempHistogram;
160        tempHistogram.inputCollection = tempInputCollection;
161        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
162        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
163 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
163 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
164 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
165 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
166        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
167  
168        histograms.push_back(tempHistogram);
169  
170      }
171 <  }
171 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
172 >
173    //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
174    sort( objectsToPlot.begin(), objectsToPlot.end() );
175    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
# Line 112 | Line 180 | OSUAnalysis::OSUAnalysis (const edm::Par
180    for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
181  
182      string currentObject = objectsToPlot.at(currentObjectIndex);
183 <    if(currentObject != "muons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
183 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "secondary photons"&& currentObject != "superclusters") continue;
184  
185      histogram tempIdHisto;
186      histogram tempMomIdHisto;
187      histogram tempGmaIdHisto;
188      histogram tempIdVsMomIdHisto;
189 +    histogram tempIdVsGmaIdHisto;
190  
191      tempIdHisto.inputCollection = currentObject;
192      tempMomIdHisto.inputCollection = currentObject;
193      tempGmaIdHisto.inputCollection = currentObject;
194      tempIdVsMomIdHisto.inputCollection = currentObject;
195 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
196 +
197 +    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
198 +    if(currentObject == "secondary photons") currentObject = "secondaryPhotons";
199 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
200  
201      currentObject = currentObject.substr(0, currentObject.size()-1);
202      tempIdHisto.name = currentObject+"GenMatchId";
203      tempMomIdHisto.name = currentObject+"GenMatchMotherId";
204      tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
205      tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
206 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
207  
208      currentObject.at(0) = toupper(currentObject.at(0));
209      tempIdHisto.title = currentObject+" Gen-matched Particle";
210      tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
211      tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
212      tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
213 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
214 +
215  
216 <    int maxNum = 24;
216 >    int maxNum = 25;
217      vector<double> binVector;
218      binVector.push_back(maxNum);
219      binVector.push_back(0);
# Line 154 | Line 231 | OSUAnalysis::OSUAnalysis (const edm::Par
231      tempIdVsMomIdHisto.bins = binVector;
232      tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
233      tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
234 +    tempIdVsGmaIdHisto.bins = binVector;
235 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
236 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
237  
238      histograms.push_back(tempIdHisto);
239      histograms.push_back(tempMomIdHisto);
240      histograms.push_back(tempGmaIdHisto);
241      histograms.push_back(tempIdVsMomIdHisto);
242 +    histograms.push_back(tempIdVsGmaIdHisto);
243    }
244  
245  
# Line 174 | Line 255 | OSUAnalysis::OSUAnalysis (const edm::Par
255      //set triggers for this channel
256      vector<string> triggerNames;
257      triggerNames.clear();
258 +    vector<string> triggerToVetoNames;
259 +    triggerToVetoNames.clear();
260 +
261      tempChannel.triggers.clear();
262 +    tempChannel.triggersToVeto.clear();
263      if(channels_.at(currentChannel).exists("triggers")){
264        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
265        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
266          tempChannel.triggers.push_back(triggerNames.at(trigger));
267        objectsToGet.push_back("triggers");
268      }
269 <
269 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
270 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
271 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
272 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
273 >      objectsToGet.push_back("triggers");
274 >    }
275  
276  
277  
278      //create cutFlow for this channel
279      cutFlows_.push_back (new CutFlow (fs_, channelName));
280 <
281 <    //book a directory in the output file with the name of the channel
282 <    TFileDirectory subDir = fs_->mkdir( channelName );
193 <    directories.push_back(subDir);
194 <
195 <    std::map<std::string, TH1D*> oneDhistoMap;
196 <    oneDHists_.push_back(oneDhistoMap);
197 <    std::map<std::string, TH2D*> twoDhistoMap;
198 <    twoDHists_.push_back(twoDhistoMap);
199 <
200 <
201 <
202 <    //book all histograms included in the configuration
203 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
204 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
205 <      int numBinsElements = currentHistogram.bins.size();
206 <      int numInputVariables = currentHistogram.inputVariables.size();
207 <
208 <      if(numBinsElements != 3 && numBinsElements !=6) {
209 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
210 <        exit(0);
211 <      }
212 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
213 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
214 <        exit(0);
215 <      }
216 <      else if(numBinsElements == 3){
217 <        oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
218 <      }
219 <      else if(numBinsElements == 6){
220 <        twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2),currentHistogram.bins.at(3),currentHistogram.bins.at(4),currentHistogram.bins.at(5));
221 <
222 <      }
223 <
224 <
225 <      if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
226 <
227 < // bin      particle type
228 < // ---      -------------
229 < //  0        unmatched
230 < //  1        u
231 < //  2        d
232 < //  3        s
233 < //  4        c
234 < //  5        b
235 < //  6        t
236 < //  7        e
237 < //  8        mu
238 < //  9        tau
239 < // 10        nu
240 < // 11        g
241 < // 12        gamma
242 < // 13        Z
243 < // 14        W
244 < // 15        light meson
245 < // 16        K meson
246 < // 17        D meson
247 < // 18        B meson
248 < // 19        light baryon
249 < // 20        strange baryon
250 < // 21        charm baryon
251 < // 22        bottom baryon
252 < // 23        other
253 <
254 <      vector<TString> labelArray;
255 <      labelArray.push_back("unmatched");
256 <      labelArray.push_back("u");
257 <      labelArray.push_back("d");
258 <      labelArray.push_back("s");
259 <      labelArray.push_back("c");
260 <      labelArray.push_back("b");
261 <      labelArray.push_back("t");
262 <      labelArray.push_back("e");
263 <      labelArray.push_back("#mu");
264 <      labelArray.push_back("#tau");
265 <      labelArray.push_back("#nu");
266 <      labelArray.push_back("g");
267 <      labelArray.push_back("#gamma");
268 <      labelArray.push_back("Z");
269 <      labelArray.push_back("W");
270 <      labelArray.push_back("light meson");
271 <      labelArray.push_back("K meson");
272 <      labelArray.push_back("D meson");
273 <      labelArray.push_back("B meson");
274 <      labelArray.push_back("light baryon");
275 <      labelArray.push_back("strange baryon");
276 <      labelArray.push_back("charm baryon");
277 <      labelArray.push_back("bottom baryon");
278 <      labelArray.push_back("other");
279 <
280 <      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
281 <        if(currentHistogram.name.find("GenMatchIdVsMotherId")==std::string::npos) {
282 <          oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
283 <        }
284 <        else {
285 <          twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
286 <          twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
287 <        }
288 <      }
289 <      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=std::string::npos) {
290 <        twoDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->CenterTitle();
291 <        twoDHists_.at(currentChannel)[currentHistogram.name]->GetYaxis()->CenterTitle();
292 <      }
293 <
294 <    }
295 <
296 <    // Book a histogram for the number of each object type to be plotted.  
297 <    // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().  
298 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
299 <      string currentObject = objectsToPlot.at(currentObjectIndex);
300 <      int maxNum = 10;
301 <      if(currentObject == "mcparticles") maxNum = 50;
302 <      else if(currentObject == "primaryvertexs") maxNum = 50;
303 <      else if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
304 <      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
305 <      else if(currentObject == "electron-muon pairs")     currentObject = "electronMuonPairs";
306 <      else if(currentObject == "track-event pairs")       currentObject = "trackEventPairs";
307 <
308 <      currentObject.at(0) = toupper(currentObject.at(0));
309 <      string histoName = "num" + currentObject;
310 <
311 <      if(histoName == "numPrimaryvertexs"){
312 <        string newHistoName = histoName + "BeforePileupCorrection";
313 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
314 <        newHistoName = histoName + "AfterPileupCorrection";
315 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
316 <      }
317 <      else
318 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
319 <    }
320 <
321 <
322 <
323 <
280 >    vector<TFileDirectory> directories; //vector of directories in the output file.
281 >    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
282 >    vector<string> subSubDirNames;//subdirectories in each channel.
283      //get list of cuts for this channel
284      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
285  
286 +
287      //loop over and parse all cuts
288      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
289        cut tempCut;
290        //store input collection for cut
291        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
292 +      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
293 +      if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
294 +      if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
295 +      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
296 +      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
297 +      if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
298 +      if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
299 +      if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
300 +      if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
301 +      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
302 +      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
303 +      if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
304 +      if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
305 +      if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
306 +      if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
307 +      if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
308 +      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
309 +      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
310 +      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
311        tempCut.inputCollection = tempInputCollection;
312 <      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
313 <        objectsToGet.push_back(tempInputCollection);
312 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
313 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
314 >          int spaceIndex = tempInputCollection.find(" ");
315 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
316 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
317 >        }
318 >        else{
319 >          objectsToGet.push_back(tempInputCollection);
320 >        }
321          objectsToCut.push_back(tempInputCollection);
322 +        objectsToFlag.push_back(tempInputCollection);
323        }
324 <      else{//pair of objects, need to add them both to the things to objectsToGet
325 <        int dashIndex = tempInputCollection.find("-");
326 <        int spaceIndex = tempInputCollection.find(" ");
327 <        int secondWordLength = spaceIndex - dashIndex;
328 <        objectsToGet.push_back(tempInputCollection);
342 <        objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
343 <        objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
324 >      else{//pair of objects, need to add them both to objectsToGet
325 >        string obj1;
326 >        string obj2;
327 >        getTwoObjs(tempInputCollection, obj1, obj2);
328 >        string obj2ToGet = getObjToGet(obj2);
329          objectsToCut.push_back(tempInputCollection);
330 <        objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
331 <        objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
330 >        objectsToCut.push_back(obj1);
331 >        objectsToCut.push_back(obj2);
332 >        objectsToFlag.push_back(tempInputCollection);
333 >        objectsToFlag.push_back(obj1);
334 >        objectsToFlag.push_back(obj2);
335 >        objectsToGet.push_back(tempInputCollection);
336 >        objectsToGet.push_back(obj1);
337 >        objectsToGet.push_back(obj2ToGet);
338  
339        }
340  
# Line 351 | Line 342 | OSUAnalysis::OSUAnalysis (const edm::Par
342  
343        //split cut string into parts and store them
344        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
345 <      std::vector<string> cutStringVector = splitString(cutString);
345 >      vector<string> cutStringVector = splitString(cutString);
346        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
347 <        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
347 >        clog << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
348          exit(0);
349        }
350        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
351        for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
352          int indexOffset = 4 * subcutIndex;
353          string currentVariableString = cutStringVector.at(indexOffset);
354 <        if(currentVariableString.find("(")==std::string::npos){
354 >        if(currentVariableString.find("(")==string::npos){
355            tempCut.functions.push_back("");//no function was specified
356            tempCut.variables.push_back(currentVariableString);// variable to cut on
357          }
# Line 371 | Line 362 | OSUAnalysis::OSUAnalysis (const edm::Par
362          }
363          tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
364          tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
365 +        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
366          if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
367        }
368  
369        //get number of objects required to pass cut for event to pass
370        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
371 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
371 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
372        if(numberRequiredVector.size()!=2){
373 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
373 >        clog << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
374          exit(0);
375        }
376  
# Line 386 | Line 378 | OSUAnalysis::OSUAnalysis (const edm::Par
378        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
379        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
380  
381 <
381 >      //Set up vectors to store the directories and subDirectories for each channel.
382 >      string subSubDirName;
383        string tempCutName;
384        if(cuts_.at(currentCut).exists("alias")){
385          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
386 +        subSubDirName = "After " + tempCutName + " Cut Applied";
387        }
388        else{
389          //construct string for cutflow table
# Line 397 | Line 391 | OSUAnalysis::OSUAnalysis (const edm::Par
391          string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
392          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
393          tempCutName = cutName;
394 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
395        }
401      tempCut.name = tempCutName;
396  
397 +      tempCut.isVeto = false;
398 +      if(cuts_.at(currentCut).exists("isVeto")){
399 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
400 +        if (isVeto == true) tempCut.isVeto = true;
401 +      }
402 +      subSubDirNames.push_back(subSubDirName);
403 +      tempCut.name = tempCutName;
404  
405        tempChannel.cuts.push_back(tempCut);
406  
407  
407
408      }//end loop over cuts
409  
410 +    vector<map<string, TH1D*>> oneDHistsTmp;
411 +    vector<map<string, TH2D*>> twoDHistsTmp;
412 +    //book a directory in the output file with the name of the channel
413 +    TFileDirectory subDir = fs_->mkdir( channelName );
414 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
415 +    if(GetPlotsAfterEachCut_){
416 +      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
417 +        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
418 +        directories.push_back(subSubDir);
419 +        map<string, TH1D*> oneDhistoMap;
420 +        oneDHistsTmp.push_back(oneDhistoMap);
421 +        map<string, TH2D*> twoDhistoMap;
422 +        twoDHistsTmp.push_back(twoDhistoMap);
423 +      }
424 +      treeDirectories.push_back(subDir);
425 +      oneDHists_.push_back(oneDHistsTmp);
426 +      twoDHists_.push_back(twoDHistsTmp);
427 +    }
428 +    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
429 +    else{
430 +      map<string, TH1D*> oneDhistoMap;
431 +      oneDHistsTmp.push_back(oneDhistoMap);
432 +      map<string, TH2D*> twoDhistoMap;
433 +      twoDHistsTmp.push_back(twoDhistoMap);
434 +      oneDHists_.push_back(oneDHistsTmp);
435 +      twoDHists_.push_back(twoDHistsTmp);
436 +      directories.push_back(subDir);
437 +      treeDirectories.push_back(subDir);
438 +
439 +    }
440 +
441 +    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
442 +      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
443 +      BNTrees_.push_back(newTree);
444 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
445 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
446 +        vector<float> newVec;
447 +        BNTreeBranchVals_[currentVar.name] = newVec;
448 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
449 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
450 +    }
451 +
452 +    //book all histograms included in the configuration
453 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
454 +
455 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
456 +
457 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
458 +        int numBinsElements = currentHistogram.bins.size();
459 +        int numInputVariables = currentHistogram.inputVariables.size();
460 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
461 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
462 +
463 +        if(numBinsElements == 1){
464 +          if(numBinEdgesX > 1){
465 +            if(numBinEdgesY > 1)
466 +              numBinsElements = 6;
467 +            else
468 +              numBinsElements = 3;
469 +          }
470 +        }
471 +        if(numBinsElements != 3 && numBinsElements !=6){
472 +          clog << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
473 +          exit(0);
474 +        }
475 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
476 +          clog << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
477 +          exit(0);
478 +        }
479 +        else if(numBinsElements == 3){
480 +          if (currentHistogram.bins.size () == 3)
481 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
482 +          else
483 +            {
484 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
485 +            }
486 +        }
487 +        else if(numBinsElements == 6){
488 +          if (currentHistogram.bins.size () == 6)
489 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).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));
490 +          else
491 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data (), numBinEdgesY - 1, currentHistogram.variableBinsY.data ());
492 +        }
493 +
494 +
495 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
496 +
497 +        // bin      particle type
498 +        // ---      -------------
499 +        //  0        unmatched
500 +        //  1        u
501 +        //  2        d
502 +        //  3        s
503 +        //  4        c
504 +        //  5        b
505 +        //  6        t
506 +        //  7        e
507 +        //  8        mu
508 +        //  9        tau
509 +        // 10        nu
510 +        // 11        g
511 +        // 12        gamma
512 +        // 13        Z
513 +        // 14        W
514 +        // 15        light meson
515 +        // 16        K meson
516 +        // 17        D meson
517 +        // 18        B meson
518 +        // 19        light baryon
519 +        // 20        strange baryon
520 +        // 21        charm baryon
521 +        // 22        bottom baryon
522 +        // 23        QCD string
523 +        // 24        other
524 +
525 +        vector<TString> labelArray;
526 +        labelArray.push_back("unmatched");
527 +        labelArray.push_back("u");
528 +        labelArray.push_back("d");
529 +        labelArray.push_back("s");
530 +        labelArray.push_back("c");
531 +        labelArray.push_back("b");
532 +        labelArray.push_back("t");
533 +        labelArray.push_back("e");
534 +        labelArray.push_back("#mu");
535 +        labelArray.push_back("#tau");
536 +        labelArray.push_back("#nu");
537 +        labelArray.push_back("g");
538 +        labelArray.push_back("#gamma");
539 +        labelArray.push_back("Z");
540 +        labelArray.push_back("W");
541 +        labelArray.push_back("light meson");
542 +        labelArray.push_back("K meson");
543 +        labelArray.push_back("D meson");
544 +        labelArray.push_back("B meson");
545 +        labelArray.push_back("light baryon");
546 +        labelArray.push_back("strange baryon");
547 +        labelArray.push_back("charm baryon");
548 +        labelArray.push_back("bottom baryon");
549 +        labelArray.push_back("QCD string");
550 +        labelArray.push_back("other");
551 +
552 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
553 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
554 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
555 +          }
556 +          else {
557 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
558 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
559 +          }
560 +        }
561 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
562 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
563 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
564 +        }
565 +
566 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
567 +
568 +
569 +      // Book a histogram for the number of each object type to be plotted.
570 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
571 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
572 +        string currentObject = objectsToPlot.at(currentObjectIndex);
573 +        int maxNum = 10;
574 +        if(currentObject == "mcparticles") maxNum = 50;
575 +        else if(currentObject == "primaryvertexs") maxNum = 50;
576 +
577 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
578 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
579 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
580 +        else if(currentObject == "electron-photon pairs")     currentObject = "electronPhotonPairs";
581 +        else if(currentObject == "muon-photon pairs")         currentObject = "muonPhotonPairs";
582 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
583 +        else if(currentObject == "secondary photons")            currentObject = "secondaryPhotons";
584 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
585 +        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
586 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
587 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
588 +        else if(currentObject == "muon-event pairs")            currentObject = "muonEventPairs";
589 +        else if(currentObject == "photon-jet pairs")            currentObject = "photonJetPairs";
590 +        else if(currentObject == "met-jet pairs")             currentObject = "metJetPairs";
591 +        else if(currentObject == "track-jet pairs")           currentObject = "trackJetPairs";
592 +        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
593 +        else if(currentObject == "muon-secondary photon pairs")  currentObject = "muonSecondaryPhotonPairs";
594 +        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
595 +        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
596 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
597 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
598 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
599 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
600 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
601 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
602 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
603 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
604 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
605 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
606 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
607 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
608 +
609 +        currentObject.at(0) = toupper(currentObject.at(0));
610 +        string histoName = "num" + currentObject;
611 +
612 +        if(histoName == "numPrimaryvertexs"){
613 +          string newHistoName = histoName + "BeforePileupCorrection";
614 +          oneDHists_.at(currentChannel).at(currentDir)[newHistoName] = directories.at(currentDir).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
615 +          newHistoName = histoName + "AfterPileupCorrection";
616 +          oneDHists_.at(currentChannel).at(currentDir)[newHistoName] = directories.at(currentDir).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
617 +        }
618 +        else
619 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
620 +      }
621 +    }//end of loop over directories
622      channels.push_back(tempChannel);
623      tempChannel.cuts.clear();
412
624    }//end loop over channels
625  
626  
# Line 419 | Line 630 | OSUAnalysis::OSUAnalysis (const edm::Par
630    //make unique vector of objects we need to cut on
631    sort( objectsToCut.begin(), objectsToCut.end() );
632    objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
633 +  //make unique vector of objects we need to set flags for
634 +  sort( objectsToFlag.begin(), objectsToFlag.end() );
635 +  objectsToFlag.erase( unique( objectsToFlag.begin(), objectsToFlag.end() ), objectsToFlag.end() );
636  
637 +  produces<map<string, bool> > ("channelDecisions");
638 +
639 +  if (printEventInfo_) {
640 +    findEventsLog = new ofstream();  
641 +    findEventsLog->open("findEvents.txt");  
642 +    clog << "Listing run:lumi:event in file findEvents.txt for events that pass full selection (of any channel)." << endl;  
643 +  }
644 +
645 +  isFirstEvent_ = true;  
646 +
647 + } // end constructor OSUAnalysis::OSUAnalysis()
648  
424 }
649  
650   OSUAnalysis::~OSUAnalysis ()
651   {
652 +
653    // Destroying the CutFlow objects causes the cut flow numbers and time
654    // information to be printed to standard output.
655    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
656      delete cutFlows_.at(currentChannel);
657    }
658 +
659 +  if (findEventsLog) findEventsLog->close();  
660 +
661 +  clog << "=============================================" << endl;  
662 +  clog << "Successfully completed OSUAnalysis." << endl;  
663 +  clog << "=============================================" << endl;  
664 +
665   }
666  
667   void
668 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
668 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
669   {
438
670    // Retrieve necessary collections from the event.
671  
672 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
672 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
673      event.getByLabel (triggers_, triggers);
674  
675 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
675 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
676 >    event.getByLabel (trigobjs_, trigobjs);
677 >
678 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
679      event.getByLabel (jets_, jets);
680  
681 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
681 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
682      event.getByLabel (muons_, muons);
683  
684 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
684 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
685      event.getByLabel (electrons_, electrons);
686  
687 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
687 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
688      event.getByLabel (events_, events);
689  
690 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
690 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
691      event.getByLabel (taus_, taus);
692  
693 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
693 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
694      event.getByLabel (mets_, mets);
695  
696 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
696 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
697      event.getByLabel (tracks_, tracks);
698  
699 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
699 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
700      event.getByLabel (genjets_, genjets);
701  
702 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
702 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
703      event.getByLabel (mcparticles_, mcparticles);
704  
705 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
705 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
706      event.getByLabel (primaryvertexs_, primaryvertexs);
707  
708 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
708 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
709      event.getByLabel (bxlumis_, bxlumis);
710  
711 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
711 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
712      event.getByLabel (photons_, photons);
713  
714 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
714 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
715      event.getByLabel (superclusters_, superclusters);
716  
717 <  if (useTrackCaloRhoCorr_) {  
718 <    // Used only for pile-up correction of by-hand calculation of isolation energy.  
719 <    // This rho collection is not available in all BEANs.  
717 >  if (datasetType_ == "signalMC"){
718 >    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
719 >      event.getByLabel (stops_, stops);
720 >  }
721 >
722 >  if (useTrackCaloRhoCorr_) {
723 >    // Used only for pile-up correction of by-hand calculation of isolation energy.
724 >    // This rho collection is not available in all BEANs.
725      // For description of rho values for different jet reconstruction algorithms, see
726 <    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms  
727 <    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
726 >    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
727 >    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
728    }
729  
730 +  double masterScaleFactor = 1.0;
731  
732    //get pile-up event weight
733 <  double scaleFactor = 1.00;
734 <  if(doPileupReweighting_ && datasetType_ != "data")
735 <    scaleFactor = puWeight_->at (events->at (0).numTruePV);
733 >  if (doPileupReweighting_ && datasetType_ != "data") {
734 >    //for "data" datasets, the numTruePV is always set to -1
735 >    if (events->at(0).numTruePV < 0 && isFirstEvent_) clog << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
736 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
737 >  }
738  
739 +  stopCTauScaleFactor_ = 1.0;
740 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
741 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
742 +  masterScaleFactor *= stopCTauScaleFactor_;
743  
744    //loop over all channels
745  
746 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
747    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
748      channel currentChannel = channels.at(currentChannelIndex);
749  
# Line 504 | Line 751 | OSUAnalysis::analyze (const edm::Event &
751      counterMap passingCounter;
752      cumulativeFlags.clear ();
753  
754 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
755 +         iter != BNTreeBranchVals_.end(); iter++) {
756 +      iter->second.clear();  // clear array
757 +    }
758 +
759      bool triggerDecision = true;
760 <    if(currentChannel.triggers.size() != 0){  //triggers specified
761 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
760 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
761 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
762        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
763      }
764  
765      //loop over all cuts
514
515
516
766      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
767        cut currentCut = currentChannel.cuts.at(currentCutIndex);
768  
769 <      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
770 <        string currentObject = objectsToCut.at(currentObjectIndex);
769 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
770 >        string currentObject = objectsToFlag.at(currentObjectIndex);
771  
772          //initialize maps to get ready to set cuts
773 <        individualFlags[currentObject].push_back (vector<bool> ());
774 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
773 >        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
774 >        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
775  
776        }
777 <      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
778 <        string currentObject = objectsToCut.at(currentObjectIndex);
777 >
778 >      //set flags for all relevant objects
779 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
780 >        string currentObject = objectsToFlag.at(currentObjectIndex);
781  
782          int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
783  
784  
785 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
786 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
785 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
786 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
787 >        else if(currentObject == "secondary photons")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"secondary photons");
788 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
789 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
790 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
791          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
792          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
793          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 544 | Line 799 | OSUAnalysis::analyze (const edm::Event &
799          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
800          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
801          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
802 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
803 +
804  
805  
806          else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
807                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
808                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
809                                                                     "muon-muon pairs");
810 +
811 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
812 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
813 +                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
814 +                                                                             "muon-secondary muon pairs");
815 +
816 +        else if(currentObject == "muon-secondary photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
817 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
818 +                                                                             cumulativeFlags.at("secondary photons").at(flagsForPairCutsIndex), \
819 +                                                                             "muon-secondary photon pairs");
820 +        else if(currentObject == "muon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
821 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
822 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
823 +                                                                             "muon-secondary jet pairs");
824 +        else if(currentObject == "photon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
825 +                                                                             cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
826 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
827 +                                                                             "photon-secondary jet pairs");
828 +
829 +        else if(currentObject == "electron-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
830 +                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
831 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
832 +                                                                             "electron-secondary jet pairs");
833 +
834 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
835 +                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
836 +                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
837 +                                                                                     "electron-secondary electron pairs");
838 +
839          else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
840                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
841                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
# Line 558 | Line 844 | OSUAnalysis::analyze (const edm::Event &
844                                                                         cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
845                                                                         cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
846                                                                         "electron-muon pairs");
847 <        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
848 <                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
849 <                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
850 <                                                                     "track-event pairs");
851 <        
847 >        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
848 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
849 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
850 >                                                                 "jet-jet pairs");
851 >        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
852 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
853 >                                                                 cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex),\
854 >                                                                 "jet-secondary jet pairs");
855 >        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
856 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
857 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
858 >                                                                      "electron-jet pairs");
859 >        else if(currentObject == "electron-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), \
860 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
861 >                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
862 >                                                                      "electron-photon pairs");
863 >        else if(currentObject == "photon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
864 >                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
865 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
866 >                                                                      "photon-jet pairs");
867 >        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
868 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
869 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
870 >                                                                  "muon-jet pairs");
871 >        else if(currentObject == "muon-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),events.product(), \
872 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
873 >                                                                  cumulativeFlags.at("events").at(flagsForPairCutsIndex), \
874 >                                                                  "muon-event pairs");
875 >        else if(currentObject == "met-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),jets.product(), \
876 >                                                                  cumulativeFlags.at("mets").at(flagsForPairCutsIndex), \
877 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
878 >                                                                  "met-jet pairs");
879 >        else if(currentObject == "track-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),jets.product(), \
880 >                                                                 cumulativeFlags.at("tracks").at(flagsForPairCutsIndex), \
881 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
882 >                                                                 "track-jet pairs");
883 >        else if(currentObject == "muon-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
884 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
885 >                                                                  cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
886 >                                                                  "muon-photon pairs");
887 >        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
888 >                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
889 >                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
890 >                                                                     "track-event pairs");
891 >        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
892 >                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
893 >                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
894 >                                                                        "electron-track pairs");
895 >        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
896 >                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
897 >                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
898 >                                                                    "muon-track pairs");
899 >        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
900 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
901 >                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
902 >                                                                  "muon-tau pairs");
903 >        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
904 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
905 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
906 >                                                                 "tau-tau pairs");
907 >        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
908 >                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
909 >                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
910 >                                                                   "tau-track pairs");
911 >        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
912 >                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
913 >                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
914 >                                                                          "electron-trigobj pairs");
915 >        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
916 >                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
917 >                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
918 >                                                                      "muon-trigobj pairs");
919  
920 +        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
921        }
922  
923  
924  
925      }//end loop over all cuts
572
573
926      //use cumulative flags to apply cuts at event level
927  
928 +    //a vector to store cumulative cut descisions after each cut.
929 +    vector<bool> eventPassedPreviousCuts;
930      bool eventPassedAllCuts = true;
577
931      //apply trigger (true if none were specified)
932      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
933  
581
582
934      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
935  
936        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 587 | Line 938 | OSUAnalysis::analyze (const edm::Event &
938        int numberPassing = 0;
939  
940        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
941 <          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
941 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
942        }
592
943        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
944        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
595
945        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
946 +      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
947 +    }
948 +    //applying all appropriate scale factors
949 +    double scaleFactor = masterScaleFactor;
950 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
951 +
952 +    if(applyLeptonSF_ && datasetType_ != "data"){
953 +      //only apply SFs if we've cut on this object
954 +      if(find(objectsToCut.begin(),objectsToCut.end(),"muons") != objectsToCut.end ()){
955 +        flagPair muonFlags;
956 +        //get the last valid flags in the flag map
957 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
958 +          if (cumulativeFlags.at("muons").at(i).size()){
959 +            muonFlags = cumulativeFlags.at("muons").at(i);
960 +            break;
961 +          }
962 +        }
963 +        //apply the weight for each of those objects
964 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
965 +          if(!muonFlags.at(muonIndex).second) continue;
966 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
967 +        }
968 +      }
969 +      //only apply SFs if we've cut on this object
970 +      if(find(objectsToCut.begin(),objectsToCut.end(),"electrons") != objectsToCut.end ()){
971 +        flagPair electronFlags;
972 +        //get the last valid flags in the flag map
973 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
974 +          if (cumulativeFlags.at("electrons").at(i).size()){
975 +            electronFlags = cumulativeFlags.at("electrons").at(i);
976 +            break;
977 +          }
978 +        }
979 +        //apply the weight for each of those objects
980 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
981 +          if(!electronFlags.at(electronIndex).second) continue;
982 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
983 +        }
984 +      }
985 +    }
986 +    if(applyBtagSF_ && datasetType_ != "data"){
987 +      //only apply SFs if we've cut on this object
988 +      if(find(objectsToCut.begin(),objectsToCut.end(),"jets") != objectsToCut.end ()){
989 +        flagPair jetFlags;
990 +        vector<double> jetSFs;
991 +        //get the last valid flags in the flag map
992 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
993 +          if (cumulativeFlags.at("jets").at(i).size()){
994 +            jetFlags = cumulativeFlags.at("jets").at(i);
995 +            break;
996 +          }
997 +        }
998 +        //apply the weight for each of those objects
999 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
1000 +          if(!jetFlags.at(jetIndex).second) continue;
1001 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour, jets->at(jetIndex).eta);
1002 +          jetSFs.push_back(jetSFTmp);
1003 +        }
1004 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_);
1005 +      }
1006 +    }
1007 +    scaleFactor *= muonScaleFactor_;
1008 +    scaleFactor *= electronScaleFactor_;
1009 +    scaleFactor *= bTagScaleFactor_;
1010 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
1011 +
1012 +    if (printEventInfo_ && eventPassedAllCuts) {
1013 +      // Write information about event to screen, for testing purposes.
1014 +      clog << "Event passed all cuts in channel " <<  currentChannel.name
1015 +           << ":  run:lumi:evt=  "  << events->at(0).run
1016 +           << ":" << events->at(0).lumi
1017 +           << ":" << events->at(0).evt
1018 +           << endl;
1019 +      if (findEventsLog) {
1020 +        (*findEventsLog) << events->at(0).run
1021 +                         << ":" << events->at(0).lumi
1022 +                         << ":" << events->at(0).evt << endl;
1023 +      }
1024  
1025      }
1026  
600    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
1027  
1028 +    //filling histograms
1029 +    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
1030 +      uint currentDir;
1031 +      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
1032 +      else{
1033 +        currentDir = currentCut;
1034 +      }
1035  
1036  
1037 <    if(!eventPassedAllCuts)continue;
1037 >      if(eventPassedPreviousCuts.at(currentDir)){
1038  
1039 <    if (printEventInfo_) {
1040 <      // Write information about event to screen, for testing purposes.  
608 <      cout << "Event passed all cuts in channel " <<  currentChannel.name
609 <           << ": run="  << events->at(0).run
610 <           << "  lumi=" << events->at(0).lumi
611 <           << "  event=" << events->at(0).evt
612 <           << endl;  
613 <    }
1039 >        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1040 >          histogram currentHistogram = histograms.at(histogramIndex);
1041  
1042 +          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) clog << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
1043  
1044 < //     if(datasetType_ != "data") {
1045 < //       scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
1046 < //       scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1047 < //     }
1044 >          if(currentHistogram.inputVariables.size() == 1){
1045 >            TH1D* histo;
1046 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1047 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1048 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1049 >            else if(currentHistogram.inputCollection == "secondary photons")  fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1050 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1051 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1052 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1053 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1054 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1055 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1056 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1057 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1058 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1059 >             else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1060 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary photons").at(currentDir), \
1061 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1062 >             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1063 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1064 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1065 >             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1066 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1067 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1068 >             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1069 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1070 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1071 >
1072 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1073 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
1074 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
1075 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1076 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
1077 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
1078 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1079 >             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1080 >                                                                                                     cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1081 >                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1082 >
1083 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1084 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1085 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1086 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
1087 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
1088 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1089 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
1090 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1091 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1092 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(), \
1093 >                                                                                              cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1094 >                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1095 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
1096 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1097 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1098 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill1DHistogram(histo,currentHistogram, muons.product(),events.product(), \
1099 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1100 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1101 >            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, mets.product(),jets.product(), \
1102 >                                                                                          cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1103 >                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1104 >            else if(currentHistogram.inputCollection == "track-jet pairs")  fill1DHistogram(histo,currentHistogram,tracks.product(),jets.product(), \
1105 >                                                                                          cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1106 >                                                                                          cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1107 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(), \
1108 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1109 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1110 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(), \
1111 >                                                                                          cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1112 >                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1113 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1114 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1115 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1116 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1117 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1118 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1119 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1120 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1121 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1122 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1123 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1124 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1125 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1126 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1127 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1128 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1129 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1130 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1131 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1132 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1133 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1134 >
1135 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1136 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1137 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1138 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1139 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1140 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1141 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1142 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1143 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1144 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1145 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1146 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1147 >          }
1148 >          else if(currentHistogram.inputVariables.size() == 2){
1149 >            TH2D* histo;
1150 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1151 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1152 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1153 >            else if(currentHistogram.inputCollection == "secondary photons")  fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1154 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1155 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1156 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1157 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1158 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1159 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1160 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1161 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1162 >            else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1163 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary photons").at(currentDir), \
1164 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1165 >            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1166 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1167 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1168 >            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1169 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1170 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1171 >            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1172 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1173 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1174 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1175 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1176 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1177 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1178 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1179 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1180 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1181 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1182 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1183 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1184 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1185 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1186 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1187 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1188 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1189 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1190 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1191 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(), \
1192 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1193 >                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1194 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1195 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1196 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1197 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill2DHistogram(histo,currentHistogram,muons.product(),events.product(), \
1198 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("events").at(currentDir), \
1199 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1200 >            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,mets.product(),jets.product(), \
1201 >                                                                                         cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1202 >                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1203 >            else if(currentHistogram.inputCollection == "track-jet pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1204 >                                                                                         cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1205 >                                                                                         cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1206 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1207 >                                                                                          cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1208 >                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1209 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1210 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1211 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1212 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1213 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1214 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1215 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1216 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1217 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1218 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1219 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1220 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1221 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1222 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1223 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1224 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1225 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1226 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1227 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1228 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1229 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1230 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1231 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1232 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1233 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1234 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1235 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1236 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1237 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1238 >                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1239 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1240 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1241 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1242 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1243 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1244 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1245 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1246 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1247 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1248 >          }
1249  
1250 <    //filling histograms
622 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
623 <      histogram currentHistogram = histograms.at(histogramIndex);
1250 >        }
1251  
625      if(currentHistogram.inputVariables.size() == 1){
626        TH1D* histo;
627        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
628
629
630
631        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
632         else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
633        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
634                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
635                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
636        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
637        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
638                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
639                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
640        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
641                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
642                                                                                              cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
643        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
644        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
645        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
646        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
647        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
648        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
649        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
650        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
651        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
652        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
653      }
654      else if(currentHistogram.inputVariables.size() == 2){
655        TH2D* histo;
656        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
657
658
659
660        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
661        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
662        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
663                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
664                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
665        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
666        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
667                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
668                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
669        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
670                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
671                                                                                               cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
672        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
673        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
674        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
675        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
676        else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
677                                                                                         cumulativeFlags.at("tracks").back(),cumulativeFlags.at("events").back(),
678                                                                                         cumulativeFlags.at("track-event pairs").back(),scaleFactor);  
679        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
680        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
681        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
682        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
683        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
684        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
685      }
686    }
687
688    //fills histograms with the sizes of collections
689    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
690
691      string currentObject = objectsToPlot.at(currentObjectIndex);
692
693      string objectToPlot = "";  
694
695      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().  
696      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
697      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
698      else if(currentObject == "electron-muon pairs")     objectToPlot = "electronMuonPairs";
699      else if(currentObject == "track-event pairs")       objectToPlot = "trackEventPairs";  
700      else objectToPlot = currentObject;
701      string tempCurrentObject = objectToPlot;
702      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));  // Capitalize the first letter.  
703      string histoName = "num" + tempCurrentObject;
704
705
706      //set position of primary vertex in event, in order to calculate quantities relative to it
707      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
708        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
709        int numToPlot = 0;
710        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
711          if(lastCutFlags.at(currentFlag)) numToPlot++;
712        }
713        if(objectToPlot == "primaryvertexs"){
714          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
715          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
716        }
717        else {
718          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
719        }
720      }
721      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
722      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
723      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
724      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
725      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
726      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
727      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
728      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
729      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
730      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
731      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
732      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
733      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
734      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
735      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
736      else if(objectToPlot == "primaryvertexs"){
737        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
738        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
739      }
1252  
1253 <    } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1253 >        //fills histograms with the sizes of collections
1254 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1255  
1256 <  } //end loop over channel
1256 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1257 >          string objectToPlot = "";
1258  
1259 <  masterCutFlow_->fillCutFlow(scaleFactor);
1259 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1260 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1261 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1262 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1263 >          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1264 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1265 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1266 >          else if(currentObject == "muon-event pairs")                     objectToPlot = "muonEventPairs";
1267 >          else if(currentObject == "muon-photon pairs")                     objectToPlot = "muonPhotonPairs";
1268 >          else if(currentObject == "photon-jet pairs")                     objectToPlot = "photonJetPairs";
1269 >          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1270 >          else if(currentObject == "track-jet pairs")                    objectToPlot = "trackJetPairs";
1271 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1272 >          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1273 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1274 >          else if(currentObject == "secondary photons")                     objectToPlot = "secondaryPhotons";
1275 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1276 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1277 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1278 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1279 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1280 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1281 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1282 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1283 >          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1284 >          else if(currentObject == "muon-secondary photon pairs")           objectToPlot = "muonSecondaryJetPairs";
1285 >          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1286 >          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1287 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1288 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1289 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1290 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1291 >          else objectToPlot = currentObject;
1292 >
1293 >          string tempCurrentObject = objectToPlot;
1294 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1295 >          string histoName = "num" + tempCurrentObject;
1296 >
1297 >
1298 >          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1299 >            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1300 >            int numToPlot = 0;
1301 >            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1302 >              if(lastCutFlags.at(currentFlag).second) numToPlot++;
1303 >            }
1304 >
1305 >            if(objectToPlot == "primaryvertexs"){
1306 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1307 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1308 >            }
1309 >            else {
1310 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1311 >            }
1312 >          }
1313 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1314  
1315 < } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1315 >
1316 >      } // end if(eventPassedPreviousCuts.at(currentDir))
1317 >    } // end loop over cuts
1318 >
1319 >    if (!useEDMFormat_ && eventPassedAllCuts){
1320 >      // Assign BNTree variables
1321 >      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1322 >        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1323 >        string coll = brSpecs.inputCollection;
1324 >        if (cumulativeFlags.count(coll) == 0) clog << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1325 >
1326 >        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1327 >        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1328 >        else if(coll == "secondary photons")      assignTreeBranch(brSpecs,photons.product(),          cumulativeFlags.at(coll).back());
1329 >        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1330 >        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1331 >        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1332 >        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1333 >        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1334 >        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1335 >        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1336 >        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1337 >        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1338 >        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1339 >        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1340 >        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1341 >        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1342 >        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1343 >        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1344 >        else if(coll == "stops"
1345 >                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1346 >      } // end loop over branches
1347 >
1348 >      if (!BNTrees_.at(currentChannelIndex)) { clog << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1349 >      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1350 >    }
1351 >
1352 >    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1353 >
1354 >  } // end loop over channel
1355 >
1356 >  masterCutFlow_->fillCutFlow(masterScaleFactor);
1357 >
1358 >  event.put (channelDecisions, "channelDecisions");
1359 >
1360 >  isFirstEvent_ = false;  
1361 >
1362 > } // end void OSUAnalysis::produce (const edm::Event &event, const edm::EventSetup &setup)
1363  
1364  
1365  
# Line 759 | Line 1374 | OSUAnalysis::evaluateComparison (double
1374    else if(comparison == "==") return testValue == cutValue;
1375    else if(comparison == "=") return testValue == cutValue;
1376    else if(comparison == "!=") return testValue != cutValue;
1377 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1377 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1378 >
1379 > }
1380 >
1381 > bool
1382 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1383 >
1384 >
1385 >  if(comparison == ">")       return testValue >  cutValue;
1386 >  else if(comparison == ">=") return testValue >= cutValue;
1387 >  else if(comparison == "<")  return testValue <  cutValue;
1388 >  else if(comparison == "<=") return testValue <= cutValue;
1389 >  else if(comparison == "==") return testValue == cutValue;
1390 >  else if(comparison == "=") return testValue == cutValue;
1391 >  else if(comparison == "!=") return testValue != cutValue;
1392 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1393  
1394   }
1395  
1396   bool
1397 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1397 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1398  
1399 +  //initialize to false until a chosen trigger is passed
1400    bool triggerDecision = false;
1401  
1402 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1403 <    {
1404 <      if(trigger->pass != 1) continue;
1405 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1406 <        {
1407 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1408 <            triggerDecision = true;
1409 <          }
1410 <        }
1402 >  if (printAllTriggers_) clog << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1403 >  //loop over all triggers defined in the event
1404 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1405 >
1406 >    if (printAllTriggers_) clog << "   " << trigger->name << endl;
1407 >
1408 >    //we're only interested in triggers that actually passed
1409 >    if(trigger->pass != 1) continue;
1410 >
1411 >    //if the event passes one of the veto triggers, exit and return false
1412 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1413 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1414 >    }
1415 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1416 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1417 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1418      }
1419 <  return triggerDecision;
1419 >  }
1420 >
1421 >  printAllTriggers_ = false;  // only print triggers once, not every event
1422  
1423 +  //if none of the veto triggers fired:
1424 +  //return the OR of all the chosen triggers
1425 +  if (triggersToTest.size() != 0) return triggerDecision;
1426 +  //or if no triggers were defined return true
1427 +  else return true;
1428   }
1429  
1430 < std::vector<std::string>
1430 >
1431 > vector<string>
1432   OSUAnalysis::splitString (string inputString){
1433  
1434 <  std::stringstream stringStream(inputString);
1435 <  std::istream_iterator<std::string> begin(stringStream);
1436 <  std::istream_iterator<std::string> end;
1437 <  std::vector<std::string> stringVector(begin, end);
1434 >  stringstream stringStream(inputString);
1435 >  istream_iterator<string> begin(stringStream);
1436 >  istream_iterator<string> end;
1437 >  vector<string> stringVector(begin, end);
1438    return stringVector;
1439  
1440   }
1441  
1442 +
1443 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1444 +  // Set two object strings from the tempInputCollection string,
1445 +  // For example, if tempInputCollection is "electron-muon pairs",
1446 +  // then obj1 = "electrons" and obj2 = "muons".
1447 +  // Note that the objects have an "s" appended.
1448 +
1449 +  int dashIndex = tempInputCollection.find("-");
1450 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1451 +  int secondWordLength = spaceIndex - dashIndex;
1452 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1453 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1454 +
1455 + }
1456 +
1457 +
1458 + string OSUAnalysis::getObjToGet(string obj) {
1459 +  // Return the string corresponding to the object to get for the given obj string.
1460 +  // Right now this only handles the case in which obj contains "secondary",
1461 +  // e.g, "secondary muons".
1462 +  // Note that "s" is NOT appended.
1463 +
1464 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1465 +  int firstSpaceIndex = obj.find_first_of(" ");
1466 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1467 +
1468 + }
1469 +
1470 +
1471 + //!jet valueLookup
1472   double
1473 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1473 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1474  
1475    double value = 0.0;
1476    if(variable == "energy") value = object->energy;
# Line 913 | Line 1589 | OSUAnalysis::valueLookup (const BNjet* o
1589    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1590    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1591  
1592 +  //user defined variable
1593 +  else if(variable == "disappTrkLeadingJetID") {
1594 +    value = object->pt > 110
1595 +      && fabs(object->eta) < 2.4
1596 +      && object->chargedHadronEnergyFraction > 0.2
1597 +      && object->neutralHadronEnergyFraction < 0.7
1598 +      && object->chargedEmEnergyFraction < 0.5
1599 +      && object->neutralEmEnergyFraction < 0.7;
1600 +  }
1601 +
1602 +  else if(variable == "disappTrkSubLeadingJetID") {
1603 +    value = object->pt > 30
1604 +      && fabs(object->eta) < 4.5
1605 +      && object->neutralHadronEnergyFraction < 0.7
1606 +      && object->chargedEmEnergyFraction < 0.5;
1607 +  }
1608  
1609 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1609 >  else if(variable == "dPhiMet") {
1610 >    if (const BNmet *met = chosenMET ()) {
1611 >      value = deltaPhi (object->phi, met->phi);
1612 >    } else value = -999;
1613 >  }
1614 >
1615 >
1616 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1617  
1618    value = applyFunction(function, value);
1619  
1620    return value;
1621 < }
923 <
1621 > } // end jet valueLookup
1622  
1623  
1624 + //!muon valueLookup
1625   double
1626 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1626 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1627  
1628    double value = 0.0;
1629    if(variable == "energy") value = object->energy;
# Line 1016 | Line 1715 | OSUAnalysis::valueLookup (const BNmuon*
1715    else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1716    else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1717    else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1718 +  else if(variable == "chargedHadronIsoDR04") value = object->chargedHadronIsoDR04;
1719 +  else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1720 +  else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1721 +  else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1722    else if(variable == "rhoPrime") value = object->rhoPrime;
1723    else if(variable == "AEffDr03") value = object->AEffDr03;
1724    else if(variable == "AEffDr04") value = object->AEffDr04;
# Line 1023 | Line 1726 | OSUAnalysis::valueLookup (const BNmuon*
1726    else if(variable == "pfIsoR03SumNeutralHadronEt") value = object->pfIsoR03SumNeutralHadronEt;
1727    else if(variable == "pfIsoR03SumPhotonEt") value = object->pfIsoR03SumPhotonEt;
1728    else if(variable == "pfIsoR03SumPUPt") value = object->pfIsoR03SumPUPt;
1729 +  else if(variable == "relpfIsoR04SumExceptChargedHad") value = (object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)/ object->pt;
1730 +  else if(variable == "relpfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt/object->pt;
1731 +  else if(variable == "relpfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt/object->pt;
1732 +  else if(variable == "relpfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt/object->pt;
1733 +  else if(variable == "relpfIsoR04SumPUPt") value = object->pfIsoR04SumPUPt/object->pt;
1734    else if(variable == "pfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt;
1735    else if(variable == "pfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt;
1736    else if(variable == "pfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt;
# Line 1079 | Line 1787 | OSUAnalysis::valueLookup (const BNmuon*
1787    else if(variable == "time_ndof") value = object->time_ndof;
1788  
1789    //user-defined variables
1790 +  else if(variable == "looseID") {
1791 +    value = object->pt > 10 &&
1792 +      (object->isGlobalMuon  > 0 ||
1793 +       object->isTrackerMuon > 0);
1794 +  }
1795    else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1796    else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1797    else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1798    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1799 +  else if(variable == "relPFdBetaIsoPseudo") value = (object->pfIsoR04SumChargedHadronPt + object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt) / object->pt;
1800    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1801    else if(variable == "metMT") {
1802 <    const BNmet *met = chosenMET ();
1089 <    if (met)
1802 >    if (const BNmet *met = chosenMET ())
1803        {
1804 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1805 <                       p2 (met->px, met->py, 0.0, met->pt);
1093 <
1094 <        value = (p1 + p2).Mt ();
1804 >        double dPhi = deltaPhi (object->phi, met->phi);
1805 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1806        }
1807      else
1808        value = -999;
# Line 1218 | Line 1929 | OSUAnalysis::valueLookup (const BNmuon*
1929    }
1930    else if(variable == "tightIDdisplaced"){
1931      value = object->isGlobalMuon > 0                \
1932 +      && object->isPFMuon > 0                        \
1933        && object->normalizedChi2 < 10                \
1934        && object->numberOfValidMuonHits > 0        \
1935        && object->numberOfMatchedStations > 1        \
# Line 1225 | Line 1937 | OSUAnalysis::valueLookup (const BNmuon*
1937        && object->numberOfLayersWithMeasurement > 5;
1938    }
1939  
1940 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1940 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1941  
1942    else if(variable == "genMatchedPdgId"){
1943      int index = getGenMatchedParticleIndex(object);
# Line 1245 | Line 1957 | OSUAnalysis::valueLookup (const BNmuon*
1957    }
1958    else if(variable == "genMatchedMotherIdReverse"){
1959      int index = getGenMatchedParticleIndex(object);
1960 <    if(index == -1) value = 23;
1961 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1960 >    if(index == -1) value = 24;
1961 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1962    }
1963    else if(variable == "genMatchedGrandmotherId"){
1964      int index = getGenMatchedParticleIndex(object);
# Line 1258 | Line 1970 | OSUAnalysis::valueLookup (const BNmuon*
1970      }
1971      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1972    }
1973 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1974 +    int index = getGenMatchedParticleIndex(object);
1975 +    if(index == -1) value = 24;
1976 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1977 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1978 +      if(motherIndex == -1) value = 24;
1979 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1980 +    }
1981 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1982 +  }
1983 +  else if(variable == "pfMuonsFromVertex"){
1984 +    double d0Error, dzError;
1985 +
1986 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1987 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1988 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1989 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1990 +      || fabs (object->correctedDZ / dzError) > 99.0;
1991 +    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1992 +  }
1993  
1994  
1995  
1996 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1996 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1997  
1998    value = applyFunction(function, value);
1999  
2000    return value;
2001 < }
2001 > } // end muon valueLookup
2002  
2003  
2004 + //!electron valueLookup
2005   double
2006 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
2006 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
2007  
2008    double value = 0.0;
2009    if(variable == "energy") value = object->energy;
# Line 1435 | Line 2168 | OSUAnalysis::valueLookup (const BNelectr
2168    else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2169    else if(variable == "detIso") value = (object->trackIso) / object->pt;
2170    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2171 +  else if(variable == "relPFrhoIsoEB") value = object->isEB ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2172 +  else if(variable == "relPFrhoIsoEE") value = object->isEE ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2173    else if(variable == "metMT") {
2174 <    const BNmet *met = chosenMET ();
1440 <    if (met)
2174 >    if (const BNmet *met = chosenMET ())
2175        {
2176 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
2177 <                       p2 (met->px, met->py, 0.0, met->pt);
1444 <
1445 <        value = (p1 + p2).Mt ();
2176 >        double dPhi = deltaPhi (object->phi, met->phi);
2177 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2178        }
2179      else
2180        value = -999;
# Line 1509 | Line 2241 | OSUAnalysis::valueLookup (const BNelectr
2241      else value = -999;
2242    }
2243  
2244 +  else if(variable == "looseID"){
2245 +    if (object->isEB)
2246 +      {
2247 +        value = fabs(object->delEtaIn) < 0.007 \
2248 +          && fabs (object->delPhiIn) < 0.15 \
2249 +          && object->scSigmaIEtaIEta < 0.01 \
2250 +          && object->hadOverEm < 0.12 \
2251 +          && fabs (object->correctedD0Vertex) < 0.02 \
2252 +          && fabs (object->correctedDZ) < 0.2 \
2253 +          && object->absInvEMinusInvPin < 0.05 \
2254 +          && object->passConvVeto;
2255 +      }
2256 +    else
2257 +      {
2258 +        value = fabs(object->delEtaIn) < 0.009 \
2259 +          && fabs (object->delPhiIn) < 0.10 \
2260 +          && object->scSigmaIEtaIEta < 0.03 \
2261 +          && object->hadOverEm < 0.10 \
2262 +          && fabs (object->correctedD0Vertex) < 0.02 \
2263 +          && fabs (object->correctedDZ) < 0.2 \
2264 +          && object->absInvEMinusInvPin < 0.05 \
2265 +          && object->passConvVeto;
2266 +      }
2267 +  }
2268 +
2269    else if(variable == "tightID"){
2270      if (object->isEB)
2271        {
# Line 1534 | Line 2291 | OSUAnalysis::valueLookup (const BNelectr
2291        }
2292    }
2293  
2294 +  else if(variable == "looseID_MVA"){
2295 +    value = object->pt > 10
2296 +      && object->mvaNonTrigV0 > 0;
2297 +      }
2298    else if(variable == "correctedD0VertexInEBPositiveCharge"){
2299      if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2300      else value = -999;
# Line 1607 | Line 2368 | OSUAnalysis::valueLookup (const BNelectr
2368    }
2369  
2370  
2371 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2371 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2372  
2373    else if(variable == "genMatchedPdgId"){
2374      int index = getGenMatchedParticleIndex(object);
# Line 1628 | Line 2389 | OSUAnalysis::valueLookup (const BNelectr
2389    }
2390    else if(variable == "genMatchedMotherIdReverse"){
2391      int index = getGenMatchedParticleIndex(object);
2392 <    if(index == -1) value = 23;
2393 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2392 >    if(index == -1) value = 24;
2393 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2394    }
2395    else if(variable == "genMatchedGrandmotherId"){
2396      int index = getGenMatchedParticleIndex(object);
# Line 1641 | Line 2402 | OSUAnalysis::valueLookup (const BNelectr
2402      }
2403      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2404    }
2405 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2406 +    int index = getGenMatchedParticleIndex(object);
2407 +    if(index == -1) value = 24;
2408 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2409 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2410 +      if(motherIndex == -1) value = 24;
2411 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2412 +    }
2413 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2414 +  }
2415 +  else if(variable == "pfElectronsFromVertex"){
2416 +    double d0Error, dzError;
2417 +
2418 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2419 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2420 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2421 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2422 +      || fabs (object->correctedDZ / dzError) > 99.0;
2423 +    value = !value;
2424 +  }
2425  
2426  
2427  
2428 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2428 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2429  
2430    value = applyFunction(function, value);
2431  
2432    return value;
2433 < }
2433 > } // end electron valueLookup
2434  
2435  
2436 + //!event valueLookup
2437   double
2438 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2438 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2439  
2440    double value = 0.0;
2441  
# Line 1661 | Line 2443 | OSUAnalysis::valueLookup (const BNevent*
2443    else if(variable == "pthat") value = object->pthat;
2444    else if(variable == "qScale") value = object->qScale;
2445    else if(variable == "alphaQCD") value = object->alphaQCD;
2446 +  else if(variable == "Ht") value = getHt(jets.product());
2447    else if(variable == "alphaQED") value = object->alphaQED;
2448    else if(variable == "scalePDF") value = object->scalePDF;
2449    else if(variable == "x1") value = object->x1;
# Line 1722 | Line 2505 | OSUAnalysis::valueLookup (const BNevent*
2505    else if(variable == "id2") value = object->id2;
2506    else if(variable == "evt") value = object->evt;
2507    else if(variable == "puScaleFactor"){
2508 <    if(datasetType_ != "data")
2508 >    if(doPileupReweighting_ && datasetType_ != "data")
2509        value = puWeight_->at (events->at (0).numTruePV);
2510      else
2511        value = 1.0;
2512    }
2513 <  else if(variable == "muonScaleFactor"){
2514 <    if(datasetType_ != "data")
2515 <      //      value = muonSFWeight_->at (chosenMuon ()->eta);
2516 <    value = 1.0;
2517 <    else
2518 <      value = 1.0;
2513 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2514 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2515 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2516 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2517 >  else if(variable == "ht") value = chosenHT ();
2518 >  else if(variable == "leadMuPairInvMass"){
2519 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2520 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2521 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2522 >    value = (p0 + p1).M ();
2523 >  }
2524 >  else if(variable == "leadMuPairPt"){
2525 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2526 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2527 >             pt1 (muPair.second->px, muPair.second->py);
2528 >    pt0 += pt1;
2529 >    value = pt0.Mod ();
2530 >  }
2531 >  else if(variable == "leadElPairInvMass"){
2532 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2533 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2534 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2535 >    value = (p0 + p1).M ();
2536 >  }
2537 >  else if(variable == "leadElPairPt"){
2538 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2539 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2540 >             pt1 (muPair.second->px, muPair.second->py);
2541 >    pt0 += pt1;
2542 >    value = pt0.Mod ();
2543    }
2544 <  else if(variable == "electronScaleFactor"){
1738 <    if(datasetType_ != "data")
1739 <      //      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1740 <    value = 1.0;
1741 <    else
1742 <      value = 1.0;
1743 <  }
1744 <
1745 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2544 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2545  
2546    value = applyFunction(function, value);
2547  
2548    return value;
2549 < }
2549 > } // end event valueLookup
2550 >
2551  
2552 + //!tau valueLookup
2553   double
2554 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2554 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2555  
2556    double value = 0.0;
2557  
# Line 1794 | Line 2595 | OSUAnalysis::valueLookup (const BNtau* o
2595    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2596    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2597  
2598 +  else if (variable == "looseHadronicID") {
2599 +    value = object->pt > 10
2600 +      && object->eta < 2.3
2601 +      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2602 +      && object->HPSdecayModeFinding > 0
2603 +      && object->HPSagainstElectronLoose > 0
2604 +      && object->HPSagainstMuonTight > 0;
2605 +  }
2606  
2607 <
1799 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2607 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2608  
2609    else if(variable == "genMatchedPdgId"){
2610      int index = getGenMatchedParticleIndex(object);
# Line 1816 | Line 2624 | OSUAnalysis::valueLookup (const BNtau* o
2624    }
2625    else if(variable == "genMatchedMotherIdReverse"){
2626      int index = getGenMatchedParticleIndex(object);
2627 <    if(index == -1) value = 23;
2628 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2627 >    if(index == -1) value = 24;
2628 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2629    }
2630    else if(variable == "genMatchedGrandmotherId"){
2631      int index = getGenMatchedParticleIndex(object);
# Line 1829 | Line 2637 | OSUAnalysis::valueLookup (const BNtau* o
2637      }
2638      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2639    }
2640 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2641 +    int index = getGenMatchedParticleIndex(object);
2642 +    if(index == -1) value = 24;
2643 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2644 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2645 +      if(motherIndex == -1) value = 24;
2646 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2647 +    }
2648 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2649 +  }
2650  
2651  
2652 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2652 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2653  
2654    value = applyFunction(function, value);
2655  
2656    return value;
2657 < }
2657 > } // end tau valueLookup
2658 >
2659  
2660 + //!met valueLookup
2661   double
2662 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2662 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2663  
2664    double value = 0.0;
2665  
# Line 1903 | Line 2723 | OSUAnalysis::valueLookup (const BNmet* o
2723    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2724    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2725  
2726 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2726 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2727  
2728    value = applyFunction(function, value);
2729  
2730    return value;
2731 < }
2731 > } // end met valueLookup
2732 >
2733  
2734 + //!track valueLookup
2735   double
2736 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2736 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2737  
2738    double value = 0.0;
2739    double pMag = sqrt(object->pt * object->pt +
2740 <                     object->pz * object->pz);
2741 <  
2740 >                     object->pz * object->pz);
2741 >
2742    if(variable == "pt") value = object->pt;
2743    else if(variable == "px") value = object->px;
2744    else if(variable == "py") value = object->py;
# Line 1935 | Line 2757 | OSUAnalysis::valueLookup (const BNtrack*
2757    else if(variable == "numValidHits") value = object->numValidHits;
2758    else if(variable == "isHighPurity") value = object->isHighPurity;
2759  
1938
2760    //additional BNs info for disappTrks
2761 <  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2762 <  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2763 <  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2764 <  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2765 <  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2766 <  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2767 <  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2768 <  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
1948 <  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2761 >  else if(variable == "caloEMDeltaRp3")     value = object->caloEMDeltaRp3;
2762 >  else if(variable == "caloHadDeltaRp3")    value = object->caloHadDeltaRp3;
2763 >  else if(variable == "caloEMDeltaRp4")     value = object->caloEMDeltaRp4;
2764 >  else if(variable == "caloHadDeltaRp4")    value = object->caloHadDeltaRp4;
2765 >  else if(variable == "caloEMDeltaRp5")     value = object->caloEMDeltaRp5;
2766 >  else if(variable == "caloHadDeltaRp5")    value = object->caloHadDeltaRp5;
2767 >  else if(variable == "nHitsMissingOuter")  value = object->nHitsMissingOuter;
2768 >  else if(variable == "nHitsMissingInner")  value = object->nHitsMissingInner;
2769    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2770 <  
2770 >  else if(variable == "depTrkRp3")          value = object->depTrkRp3;
2771 >  else if(variable == "trkRelIsoRp3")       value = (object->depTrkRp3 - object->pt) / object->pt;
2772 >  else if(variable == "trkRelIsoRp5")       value = (object->depTrkRp5 - object->pt) / object->pt;
2773 >  else if(variable == "depEcalRp3")         value = object->depEcalRp3;
2774 >  else if(variable == "depHcalRp3")         value = object->depHcalRp3;
2775 >  else if(variable == "depHoRp3")           value = object->depHoRp3;
2776 >  else if(variable == "nTracksRp3")         value = object->nTracksRp3;
2777 >  else if(variable == "trackerVetoPtRp3")   value = object->trackerVetoPtRp3;
2778 >  else if(variable == "emVetoEtRp3")        value = object->emVetoEtRp3;
2779 >  else if(variable == "hadVetoEtRp3")       value = object->hadVetoEtRp3;
2780 >  else if(variable == "hoVetoEtRp3")        value = object->hoVetoEtRp3;
2781 >  else if(variable == "depTrkRp5")          value = object->depTrkRp5;
2782 >  else if(variable == "depEcalRp5")         value = object->depEcalRp5;
2783 >  else if(variable == "depHcalRp5")         value = object->depHcalRp5;
2784 >  else if(variable == "depHoRp5")           value = object->depHoRp5;
2785 >  else if(variable == "nTracksRp5")         value = object->nTracksRp5;
2786 >  else if(variable == "trackerVetoPtRp5")   value = object->trackerVetoPtRp5;
2787 >  else if(variable == "emVetoEtRp5")        value = object->emVetoEtRp5;
2788 >  else if(variable == "hadVetoEtRp5")       value = object->hadVetoEtRp5;
2789 >  else if(variable == "hoVetoEtRp5")        value = object->hoVetoEtRp5;
2790  
2791    //user defined variables
2792    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;
2793    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2794 +  else if(variable == "depTrkRp5MinusPt"){
2795 +    if ( (object->depTrkRp5 - object->pt) < 0 ) {
2796 +           value = 0;
2797 +         }
2798 +         else value =  (object->depTrkRp5 - object->pt);
2799 +  }
2800 +  else if(variable == "depTrkRp3MinusPt"){
2801 +    if ( (object->depTrkRp3 - object->pt) < 0 ) {
2802 +      value = 0;
2803 +    }
2804 +    else value =  (object->depTrkRp3 - object->pt);
2805 +  }
2806 +
2807 +  else if(variable == "dPhiMet") {
2808 +    if (const BNmet *met = chosenMET ()) {
2809 +      value = deltaPhi (object->phi, met->phi);
2810 +    } else value = -999;
2811 +  }
2812 +  
2813 +  
2814    else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2815    else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2816 <  else if(variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object);  
2817 <  else if(variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object) / pMag;  
2816 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2817 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2818    else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2819    else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2820    else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2821    else if(variable == "ptError")                    value = object->ptError;
2822    else if(variable == "ptRes")                      value = getTrkPtRes(object);
2823 +  else if (variable == "d0wrtPV"){
2824 +    double vx = object->vx - chosenVertex ()->x,
2825 +      vy = object->vy - chosenVertex ()->y,
2826 +      px = object->px,
2827 +      py = object->py,
2828 +      pt = object->pt;
2829 +    value = (-vx * py + vy * px) / pt;
2830 +  }
2831 +  else if (variable == "dZwrtPV"){
2832 +    double vx = object->vx - chosenVertex ()->x,
2833 +      vy = object->vy - chosenVertex ()->y,
2834 +      vz = object->vz - chosenVertex ()->z,
2835 +      px = object->px,
2836 +      py = object->py,
2837 +      pz = object->pz,
2838 +      pt = object->pt;
2839 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2840 +  }
2841  
2842 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2842 >
2843 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2844  
2845    else if(variable == "genMatchedPdgId"){
2846      int index = getGenMatchedParticleIndex(object);
# Line 1983 | Line 2861 | OSUAnalysis::valueLookup (const BNtrack*
2861    }
2862    else if(variable == "genMatchedMotherIdReverse"){
2863      int index = getGenMatchedParticleIndex(object);
2864 <    if(index == -1) value = 23;
2865 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2864 >    if(index == -1) value = 24;
2865 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2866    }
2867    else if(variable == "genMatchedGrandmotherId"){
2868      int index = getGenMatchedParticleIndex(object);
# Line 1996 | Line 2874 | OSUAnalysis::valueLookup (const BNtrack*
2874      }
2875      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2876    }
2877 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2878 +    int index = getGenMatchedParticleIndex(object);
2879 +    if(index == -1) value = 24;
2880 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2881 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2882 +      if(motherIndex == -1) value = 24;
2883 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2884 +    }
2885 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2886 +  }
2887  
2888  
2889  
2890 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2890 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2891  
2892    value = applyFunction(function, value);
2893  
2894    return value;
2895 < }
2895 > } // end track valueLookup
2896  
2897 +
2898 + //!genjet valueLookup
2899   double
2900 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2900 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2901  
2902    double value = 0.0;
2903  
# Line 2027 | Line 2917 | OSUAnalysis::valueLookup (const BNgenjet
2917    else if(variable == "charge") value = object->charge;
2918  
2919  
2920 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2920 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2921  
2922    value = applyFunction(function, value);
2923  
2924    return value;
2925   }
2926  
2927 + //!mcparticle valueLookup
2928   double
2929 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2929 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2930  
2931    double value = 0.0;
2932  
# Line 2160 | Line 3051 | OSUAnalysis::valueLookup (const BNmcpart
3051    }
3052  
3053  
3054 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3054 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3055  
3056    value = applyFunction(function, value);
3057  
3058    return value;
3059 < }
3059 > } // end mcparticle valueLookup
3060 >
3061  
3062 + //!primaryvertex valueLookup
3063   double
3064 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
3064 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
3065  
3066    double value = 0.0;
3067  
# Line 2187 | Line 3080 | OSUAnalysis::valueLookup (const BNprimar
3080    else if(variable == "isGood") value = object->isGood;
3081  
3082  
3083 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3083 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3084  
3085    value = applyFunction(function, value);
3086  
3087    return value;
3088   }
3089  
3090 + //!bxlumi valueLookup
3091   double
3092 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
3092 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
3093  
3094    double value = 0.0;
3095  
# Line 2204 | Line 3098 | OSUAnalysis::valueLookup (const BNbxlumi
3098    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
3099  
3100  
3101 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3101 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3102  
3103    value = applyFunction(function, value);
3104  
3105    return value;
3106   }
3107  
3108 + //!photon valueLookup
3109   double
3110 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
3110 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
3111  
3112    double value = 0.0;
3113  
# Line 2287 | Line 3182 | OSUAnalysis::valueLookup (const BNphoton
3182    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
3183  
3184  
2290
3185  
3186 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3186 >
3187 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3188  
3189    else if(variable == "genMatchedPdgId"){
3190      int index = getGenMatchedParticleIndex(object);
# Line 2311 | Line 3206 | OSUAnalysis::valueLookup (const BNphoton
3206    }
3207    else if(variable == "genMatchedMotherIdReverse"){
3208      int index = getGenMatchedParticleIndex(object);
3209 <    if(index == -1) value = 23;
3210 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
3209 >    if(index == -1) value = 24;
3210 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
3211    }
3212    else if(variable == "genMatchedGrandmotherId"){
3213      int index = getGenMatchedParticleIndex(object);
# Line 2324 | Line 3219 | OSUAnalysis::valueLookup (const BNphoton
3219      }
3220      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3221    }
3222 +  else if(variable == "genMatchedGrandmotherIdReverse"){
3223 +    int index = getGenMatchedParticleIndex(object);
3224 +    if(index == -1) value = 24;
3225 +    else if(fabs(mcparticles->at(index).motherId) == 15){
3226 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3227 +      if(motherIndex == -1) value = 24;
3228 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3229 +    }
3230 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3231 +  }
3232  
3233  
3234 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3234 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3235  
3236    value = applyFunction(function, value);
3237  
3238    return value;
3239 < }
3239 > } // end photon valueLookup
3240  
3241 +
3242 + //!supercluster valueLookup
3243   double
3244 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
3244 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
3245  
3246    double value = 0.0;
3247  
# Line 2348 | Line 3255 | OSUAnalysis::valueLookup (const BNsuperc
3255    else if(variable == "theta") value = object->theta;
3256  
3257  
3258 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3258 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3259  
3260    value = applyFunction(function, value);
3261  
3262    return value;
3263   }
3264  
3265 + //!trigobj valueLookup
3266 + double
3267 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3268 +
3269 +  double value = 0.0;
3270  
3271 +  if(variable == "pt") value = object->pt;
3272 +  else if(variable == "eta") value = object->eta;
3273 +  else if(variable == "phi") value = object->phi;
3274 +  else if(variable == "px") value = object->px;
3275 +  else if(variable == "py") value = object->py;
3276 +  else if(variable == "pz") value = object->pz;
3277 +  else if(variable == "et") value = object->et;
3278 +  else if(variable == "energy") value = object->energy;
3279 +  else if(variable == "etTotal") value = object->etTotal;
3280 +  else if(variable == "id") value = object->id;
3281 +  else if(variable == "charge") value = object->charge;
3282 +  else if(variable == "isIsolated") value = object->isIsolated;
3283 +  else if(variable == "isMip") value = object->isMip;
3284 +  else if(variable == "isForward") value = object->isForward;
3285 +  else if(variable == "isRPC") value = object->isRPC;
3286 +  else if(variable == "bx") value = object->bx;
3287 +  else if(variable == "filter") {
3288 +    if ((stringValue = object->filter) == "")
3289 +      stringValue = "none";  // stringValue should only be empty if value is filled
3290 +  }
3291 +
3292 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3293 +
3294 +  value = applyFunction(function, value);
3295 +
3296 +  return value;
3297 + }
3298 +
3299 + //!muon-muon pair valueLookup
3300   double
3301 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
3301 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3302  
3303    double value = 0.0;
3304  
3305    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3306 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3307    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3308    else if(variable == "invMass"){
3309      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2403 | Line 3345 | OSUAnalysis::valueLookup (const BNmuon*
3345    else if(variable == "muon2CorrectedD0Vertex"){
3346      value = object2->correctedD0Vertex;
3347    }
3348 < else if(variable == "muon1timeAtIpInOut"){
3348 >  else if(variable == "muon1timeAtIpInOut"){
3349      value = object1->timeAtIpInOut;
3350    }
3351 < else if(variable == "muon2timeAtIpInOut"){
3351 >  else if(variable == "muon2timeAtIpInOut"){
3352      value = object2->timeAtIpInOut;
3353    }
3354 < else if(variable == "muon1correctedD0")
3355 <   {
3356 <     value = object1->correctedD0;
3357 <   }
3358 < else if(variable == "muon2correctedD0")
3359 <   {
3360 <     value = object2->correctedD0;
3361 <   }
3354 >  else if(variable == "muon1correctedD0")
3355 >    {
3356 >      value = object1->correctedD0;
3357 >    }
3358 >  else if(variable == "muon2correctedD0")
3359 >    {
3360 >      value = object2->correctedD0;
3361 >    }
3362 >
3363 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3364 >
3365 >  value = applyFunction(function, value);
3366 >
3367 >  return value;
3368 > } // end muon-muon pair valueLookup
3369 >
3370 >
3371 > //!muon-photon pair valueLookup
3372 > double
3373 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3374 >
3375 >  double value = 0.0;
3376 >
3377 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3378 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3379 >  else if(variable == "photonEta") value = object2->eta;
3380 >  else if(variable == "photonPt") value = object2->pt;
3381 >  else if(variable == "muonEta") value = object1->eta;
3382 >  else if(variable == "photonPhi") value = object2->phi;
3383 >  else if(variable == "muonPhi") value = object1->phi;
3384 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3385 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3386 >  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3387 >  else if(variable == "invMass"){
3388 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3389 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3390 >    value = (fourVector1 + fourVector2).M();
3391 >  }
3392 >  else if(variable == "pt"){
3393 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3394 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3395 >    value = (fourVector1 + fourVector2).Pt();
3396 >  }
3397 >  else if(variable == "threeDAngle")
3398 >    {
3399 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3400 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3401 >      value = (threeVector1.Angle(threeVector2));
3402 >    }
3403 >  else if(variable == "alpha")
3404 >    {
3405 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3406 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3407 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3408 >      value = (pi-threeVector1.Angle(threeVector2));
3409 >    }
3410 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3411  
3412 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3412 >  value = applyFunction(function, value);
3413 >
3414 >  return value;
3415 > }
3416 >
3417 > //!electron-photon pair valueLookup
3418 > double
3419 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3420 >
3421 >  double value = 0.0;
3422 >
3423 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3424 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3425 >  else if(variable == "photonEta") value = object2->eta;
3426 >  else if(variable == "photonPt") value = object2->pt;
3427 >  else if(variable == "electronEta") value = object1->eta;
3428 >  else if(variable == "photonPhi") value = object2->phi;
3429 >  else if(variable == "electronPhi") value = object1->phi;
3430 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3431 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3432 >  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3433 >  else if(variable == "invMass"){
3434 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3435 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3436 >    value = (fourVector1 + fourVector2).M();
3437 >  }
3438 >  else if(variable == "pt"){
3439 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3440 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3441 >    value = (fourVector1 + fourVector2).Pt();
3442 >  }
3443 >  else if(variable == "threeDAngle")
3444 >    {
3445 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3446 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3447 >      value = (threeVector1.Angle(threeVector2));
3448 >    }
3449 >  else if(variable == "alpha")
3450 >    {
3451 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3452 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3453 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3454 >      value = (pi-threeVector1.Angle(threeVector2));
3455 >    }
3456 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3457  
3458    value = applyFunction(function, value);
3459  
3460    return value;
3461   }
3462  
3463 + //!electron-electron pair valueLookup
3464   double
3465 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
3465 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3466  
3467    double value = 0.0;
3468  
3469    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3470 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3471    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3472    else if(variable == "invMass"){
3473      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2472 | Line 3509 | OSUAnalysis::valueLookup (const BNelectr
3509      value = object2->correctedD0;
3510    }
3511  
3512 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3512 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3513  
3514    value = applyFunction(function, value);
3515  
3516    return value;
3517   }
3518  
3519 + //!electron-muon pair valueLookup
3520   double
3521 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3521 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3522  
3523    double value = 0.0;
3524  
3525    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3526 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3527    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3528    else if(variable == "invMass"){
3529      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2531 | Line 3570 | OSUAnalysis::valueLookup (const BNelectr
3570    else if(variable == "muonDetIso"){
3571      value = (object2->trackIsoDR03) / object2->pt;
3572    }
3573 +  else if(variable == "electronRelPFrhoIso"){
3574 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3575 +  }
3576 +  else if(variable == "muonRelPFdBetaIso"){
3577 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3578 +  }
3579 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3580 +  value = applyFunction(function, value);
3581  
3582 +  return value;
3583 + } // end electron-muon pair valueLookup
3584 +
3585 +
3586 + //!electron-jet pair valueLookup
3587 + double
3588 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3589  
3590 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3590 >  double value = 0.0;
3591 >
3592 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3593 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3594 >  else if(variable == "jetEta") value = object2->eta;
3595 >  else if(variable == "jetPhi") value = object2->phi;
3596 >  else if(variable == "electronEta") value = object1->eta;
3597 >  else if(variable == "electronPhi") value = object1->phi;
3598 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3599 >  else if(variable == "invMass"){
3600 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3601 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3602 >    value = (fourVector1 + fourVector2).M();
3603 >  }
3604 >  else if(variable == "pt"){
3605 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3606 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3607 >    value = (fourVector1 + fourVector2).Pt();
3608 >  }
3609 >  else if(variable == "threeDAngle")
3610 >    {
3611 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3612 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3613 >      value = (threeVector1.Angle(threeVector2));
3614 >    }
3615 >  else if(variable == "chargeProduct"){
3616 >    value = object1->charge*object2->charge;
3617 >  }
3618  
3619 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3620    value = applyFunction(function, value);
3621  
3622    return value;
3623   }
3624  
3625 + //!photon-jet pair valueLookup
3626 + double
3627 + OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3628  
3629 +  double value = 0.0;
3630  
3631 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3632 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3633 +  else if(variable == "jetEta") value = object2->eta;
3634 +  else if(variable == "jetPhi") value = object2->phi;
3635 +  else if(variable == "photonEta") value = object1->eta;
3636 +  else if(variable == "photonPhi") value = object1->phi;
3637 +  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3638 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3639 +  else if(variable == "invMass"){
3640 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3641 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3642 +    value = (fourVector1 + fourVector2).M();
3643 +  }
3644 +  else if(variable == "pt"){
3645 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3646 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3647 +    value = (fourVector1 + fourVector2).Pt();
3648 +  }
3649 +  else if(variable == "threeDAngle")
3650 +    {
3651 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3652 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3653 +      value = (threeVector1.Angle(threeVector2));
3654 +    }
3655 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3656 +  value = applyFunction(function, value);
3657 +
3658 +  return value;
3659 + }
3660  
3661 + // track-jet pair valueLookup
3662   double
3663 < OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function){
3663 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNjet* object2, string variable, string function, string &stringValue){
3664 >
3665 >  double value = 0.0;
3666 >
3667 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3668 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3669 >
3670 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3671 >  value = applyFunction(function, value);
3672 >
3673 >  return value;
3674 >
3675 > }
3676 >
3677 >
3678 >
3679 > // met-jet pair valueLookup
3680 > double
3681 > OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3682 >
3683 >  double value = 0.0;
3684 >
3685 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3686 >
3687 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3688 >  value = applyFunction(function, value);
3689 >
3690 >  return value;
3691 >
3692 > }  
3693 >
3694 >
3695 >
3696 > //!muon-jet pair valueLookup
3697 > double
3698 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3699 >
3700 >  double value = 0.0;
3701 >
3702 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3703 >  else if(variable == "jetEta") value = object2->eta;
3704 >  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3705 >  else if(variable == "jetPt") value = object2->pt;
3706 >  else if(variable == "jetPhi") value = object2->phi;
3707 >  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3708 >  else if(variable == "muonEta") value = object1->eta;
3709 >  else if(variable == "muonPt") value = object1->pt;
3710 >  else if(variable == "muonPhi") value = object1->phi;
3711 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3712 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3713 >  else if(variable == "invMass"){
3714 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3715 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3716 >    value = (fourVector1 + fourVector2).M();
3717 >  }
3718 >  else if(variable == "pt"){
3719 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3720 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3721 >    value = (fourVector1 + fourVector2).Pt();
3722 >  }
3723 >  else if(variable == "threeDAngle")
3724 >    {
3725 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3726 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3727 >      value = (threeVector1.Angle(threeVector2));
3728 >    }
3729 >  else if(variable == "chargeProduct"){
3730 >    value = object1->charge*object2->charge;
3731 >  }
3732 >
3733 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3734 >  value = applyFunction(function, value);
3735 >
3736 >  return value;
3737 > }
3738 >
3739 > //!muon-event valueLookup
3740 > double
3741 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNevent* object2, string variable, string function, string &stringValue){
3742 >
3743 >  double value = 0.0;
3744 >
3745 >  if(variable == "muonEta") value = object1->eta;
3746 >  else if(variable == "muonPt") value = object1->pt;
3747 >  else if(variable == "muonPhi") value = object1->phi;
3748 >  else if(variable == "Ht") value = getHt(jets.product());
3749 >  else if(variable == "pthat")   value = object2->pthat;
3750 >  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3751 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3752 >  value = applyFunction(function, value);
3753 >
3754 >  return value;
3755 > }
3756 > //!jet-jet pair valueLookup
3757 > double
3758 > OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3759 >
3760 >  double value = 0.0;
3761 >
3762 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3763 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3764 >  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3765 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3766 >  else if(variable == "invMass"){
3767 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3768 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3769 >    value = (fourVector1 + fourVector2).M();
3770 >  }
3771 >  else if(variable == "pt"){
3772 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3773 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3774 >    value = (fourVector1 + fourVector2).Pt();
3775 >  }
3776 >  else if(variable == "threeDAngle")
3777 >    {
3778 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3779 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3780 >      value = (threeVector1.Angle(threeVector2));
3781 >    }
3782 >  else if(variable == "chargeProduct"){
3783 >    value = object1->charge*object2->charge;
3784 >  }
3785 >
3786 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3787 >  value = applyFunction(function, value);
3788 >
3789 >  return value;
3790 > }
3791 >
3792 > //!electron-track pair valueLookup
3793 > double
3794 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3795 >  double electronMass = 0.000511;
3796 >  double value = 0.0;
3797 >  TLorentzVector fourVector1(0, 0, 0, 0);
3798 >  TLorentzVector fourVector2(0, 0, 0, 0);
3799 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3800 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3801 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3802 >  else if(variable == "invMass"){
3803 >    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3804 >    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3805 >
3806 >    value = (fourVector1 + fourVector2).M();
3807 >  }
3808 >  else if(variable == "chargeProduct"){
3809 >    value = object1->charge*object2->charge;
3810 >  }
3811 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3812 >  value = applyFunction(function, value);
3813 >  return value;
3814 >
3815 > }
3816 >
3817 >
3818 > //!muon-track pair valueLookup
3819 > double
3820 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3821 >  double pionMass = 0.140;
3822 >  double muonMass = 0.106;
3823 >  double value = 0.0;
3824 >  TLorentzVector fourVector1(0, 0, 0, 0);
3825 >  TLorentzVector fourVector2(0, 0, 0, 0);
3826 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3827 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3828 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3829 >  else if(variable == "invMass"){
3830 >    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3831 >    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3832 >
3833 >    value = (fourVector1 + fourVector2).M();
3834 >  }
3835 >  else if(variable == "chargeProduct"){
3836 >    value = object1->charge*object2->charge;
3837 >  }
3838 >
3839 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3840 >  value = applyFunction(function, value);
3841 >  return value;
3842 > }
3843 >
3844 > //!tau-tau pair valueLookup
3845 > double
3846 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3847 >  double value = 0.0;
3848 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3849 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3850 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3851 >  else if(variable == "invMass"){
3852 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3853 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3854 >    value = (fourVector1 + fourVector2).M();
3855 >  }
3856 >
3857 >  else if(variable == "chargeProduct"){
3858 >    value = object1->charge*object2->charge;
3859 >  }
3860 >
3861 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3862 >  value = applyFunction(function, value);
3863 >  return value;
3864 > }
3865 >
3866 > //!muon-tau pair valueLookup
3867 > double
3868 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3869 >  double value = 0.0;
3870 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3871 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3872 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3873 >  else if(variable == "invMass"){
3874 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3875 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3876 >    value = (fourVector1 + fourVector2).M();
3877 >  }
3878 >
3879 >  else if(variable == "chargeProduct"){
3880 >    value = object1->charge*object2->charge;
3881 >  }
3882 >
3883 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3884 >  value = applyFunction(function, value);
3885 >  return value;
3886 > }
3887 >
3888 > //!tau-track pair valueLookup
3889 > double
3890 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3891 >  double value = 0.0;
3892 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3893 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3894 >  else if(variable == "chargeProduct"){
3895 >    value = object1->charge*object2->charge;
3896 >  }
3897 >
3898 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3899 >  value = applyFunction(function, value);
3900 >  return value;
3901 > }
3902 >
3903 >
3904 > //!track-event pair valueLookup
3905 > double
3906 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3907  
3908    double value = 0.0;
3909    double pMag = sqrt(object1->pt * object1->pt +
3910 <                     object1->pz * object1->pz);  
3910 >                     object1->pz * object1->pz);
3911  
3912    if      (variable == "numPV")                      value = object2->numPV;
3913    else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3914    else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3915 <  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);  
3916 <  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;  
3915 >  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3916 >  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3917  
3918 <  else { std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3918 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3919  
3920    value = applyFunction(function, value);
3921  
3922    return value;
3923  
3924 < }  
3924 > }
3925 >
3926 > //!electron-trigobj pair valueLookup
3927 > double
3928 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3929 >
3930 >  double value = 0.0;
3931 >
3932 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3933 >  else if (variable == "match"){
3934 >    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3935 >      stringValue = object2->filter;
3936 >    else
3937 >      stringValue = "none";
3938 >  }
3939 >
3940 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3941 >
3942 >  value = applyFunction(function, value);
3943 >
3944 >  return value;
3945 >
3946 > }
3947 >
3948 > //!muon-trigobj pair valueLookup
3949 > double
3950 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3951 >
3952 >  double value = 0.0;
3953 >
3954 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3955 >
3956 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3957 >
3958 >  value = applyFunction(function, value);
3959 >
3960 >  return value;
3961 >
3962 > }
3963 >
3964 > //!stop valueLookup
3965 > double
3966 > OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3967 >
3968 >
3969 >  double value = 0.0;
3970 >
3971 >  if(variable == "ctau") value = object->ctau;
3972 >
3973 >  else if (variable == "d0"){
3974 >    double vx = object->vx - chosenVertex ()->x,
3975 >      vy = object->vy - chosenVertex ()->y,
3976 >      px = object->px,
3977 >      py = object->py,
3978 >      pt = object->pt;
3979 >    value = (-vx * py + vy * px) / pt;
3980 >  }
3981 >
3982 >  else if (variable == "dz"){
3983 >    double vx = object->vx - chosenVertex ()->x,
3984 >      vy = object->vy - chosenVertex ()->y,
3985 >      vz = object->vz - chosenVertex ()->z,
3986 >      px = object->px,
3987 >      py = object->py,
3988 >      pz = object->pz,
3989 >      pt = object->pt;
3990 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3991 >  }
3992 >
3993 >  else if (variable == "minD0"){
3994 >    double minD0=999;
3995 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3996 >      double vx = object->vx - vertex->x,
3997 >        vy = object->vy - vertex->y,
3998 >        px = object->px,
3999 >        py = object->py,
4000 >        pt = object->pt;
4001 >      value = (-vx * py + vy * px) / pt;
4002 >      if(abs(value) < abs(minD0)) minD0 = value;
4003 >    }
4004 >    value = minD0;
4005 >  }
4006 >  else if (variable == "minDz"){
4007 >    double minDz=999;
4008 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4009 >      double vx = object->vx - vertex->x,
4010 >        vy = object->vy - vertex->y,
4011 >        vz = object->vz - vertex->z,
4012 >        px = object->px,
4013 >        py = object->py,
4014 >        pz = object->pz,
4015 >        pt = object->pt;
4016 >      value = vz - (vx * px + vy * py)/pt * (pz/pt);
4017 >      if(abs(value) < abs(minDz)) minDz = value;
4018 >    }
4019 >    value = minDz;
4020 >  }
4021 >  else if(variable == "distToVertex"){
4022 >    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4023 >                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4024 >                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4025 >  }
4026 >  else if (variable == "minDistToVertex"){
4027 >    double minDistToVertex=999;
4028 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4029 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4030 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4031 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
4032 >
4033 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4034 >    }
4035 >    value = minDistToVertex;
4036 >  }
4037 >  else if (variable == "distToVertexDifference"){
4038 >    double minDistToVertex=999;
4039 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4040 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4041 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4042 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
4043 >
4044 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4045 >    }
4046 >    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4047 >                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4048 >                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4049 >
4050 >    value = distToChosenVertex - minDistToVertex;
4051 >  }
4052 >
4053 >  else if (variable == "closestVertexRank"){
4054 >    double minDistToVertex=999;
4055 >    int vertex_rank = 0;
4056 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4057 >      vertex_rank++;
4058 >      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4059 >                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
4060 >                      (object->vz-vertex->z)*(object->vz-vertex->z));
4061 >
4062 >      if(abs(dist) < abs(minDistToVertex)){
4063 >        value = vertex_rank;
4064 >        minDistToVertex = dist;
4065 >      }
4066 >    }
4067 >  }
4068 >
4069 >  else if (variable == "decaysToTau"){
4070 >    value = abs (object->daughter0Id) == 15 || abs (object->daughter1Id) == 15;
4071 >  }
4072 >
4073 >
4074 >
4075 >
4076 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4077 >
4078 >  value = applyFunction(function, value);
4079 >
4080 >  return value;
4081 >
4082 > } // end stop valueLookup
4083 >
4084 >
4085 >
4086 >
4087  
4088   // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
4089   // Return true iff no other tracks are found in this cone.
# Line 2577 | Line 4098 | OSUAnalysis::getTrkIsIso (const BNtrack*
4098  
4099   }
4100  
4101 + //calculate the scalar sum of Jet Pt in the event.
4102 + double
4103 + OSUAnalysis::getHt (const BNjetCollection* jetColl){
4104 +  double Ht = 0;
4105 +  for(BNjetCollection::const_iterator jet = jetColl->begin(); jet !=jetColl->end(); jet++){
4106 +    Ht += abs(jet->pt);
4107 +  }
4108 +  return Ht;
4109 + }
4110  
4111   double
4112   OSUAnalysis::getTrkPtRes (const BNtrack* track1){
# Line 2611 | Line 4141 | OSUAnalysis::getTrkPtTrue (const BNtrack
4141  
4142   double
4143   OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
4144 <  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.  
4145 <  if (!useTrackCaloRhoCorr_) return -99;  
4146 <  // if (!rhokt6CaloJetsHandle_) {
4147 <  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;  
4148 <  //   return -99;  
4144 >  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
4145 >  if (!useTrackCaloRhoCorr_) return -99;
4146 >  // if (!rhokt6CaloJetsHandle_) {
4147 >  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
4148 >  //   return -99;
4149    // }
4150 <  double radDeltaRCone = 0.5;  
4151 <  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.  
4152 <  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;  
4153 <  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);  
4154 <  return caloTotRhoCorrCalo;  
4155 <
4150 >  double radDeltaRCone = 0.5;
4151 >  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
4152 >  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
4153 >  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
4154 >  return caloTotRhoCorrCalo;
4155 >
4156   }
4157  
4158  
# Line 2636 | Line 4166 | OSUAnalysis::WriteDeadEcal (){
4166    double etaEcal, phiEcal;
4167    ifstream DeadEcalFile(deadEcalFile_);
4168    if(!DeadEcalFile) {
4169 <    cout << "Error: DeadEcalFile has not been found." << endl;
4169 >    clog << "Error: DeadEcalFile has not been found." << endl;
4170      return;
4171    }
4172    if(DeadEcalVec.size()!= 0){
4173 <    cout << "Error: DeadEcalVec has a nonzero size" << endl;
4173 >    clog << "Error: DeadEcalVec has a nonzero size" << endl;
4174      return;
4175    }
4176    while(!DeadEcalFile.eof())
# Line 2651 | Line 4181 | OSUAnalysis::WriteDeadEcal (){
4181        newChan.phiEcal = phiEcal;
4182        DeadEcalVec.push_back(newChan);
4183      }
4184 <  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
4184 >  if(DeadEcalVec.size() == 0) clog << "Warning: No dead Ecal channels have been found." << endl;
4185   }
4186  
4187   //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
# Line 2660 | Line 4190 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
4190    double deltaRLowest = 999;
4191    int value = 0;
4192    if (DeadEcalVec.size() == 0) WriteDeadEcal();
4193 <  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4193 >  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4194      double eta = ecal->etaEcal;
4195      double phi = ecal->phiEcal;
4196 <    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
4196 >    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
4197      if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
4198    }
4199    if (deltaRLowest<0.05) {value = 1;}
# Line 2671 | Line 4201 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
4201    return value;
4202   }
4203  
4204 < // Returns the smallest DeltaR between the object and any generated true particle in the event.  
4204 > // Returns the smallest DeltaR between the object and any generated true particle in the event.
4205   template <class InputObject>
4206   double OSUAnalysis::getGenDeltaRLowest(InputObject object){
4207    double genDeltaRLowest = 999.;
4208    for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4209      double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
4210      if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
4211 < }
4211 >  }
4212    return genDeltaRLowest;
4213   }
4214  
# Line 2691 | Line 4221 | OSUAnalysis::applyFunction(string functi
4221    else if(function == "log") value = log10(value);
4222  
4223    else if(function == "") value = value;
4224 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
4224 >  else{clog << "WARNING: invalid function '" << function << "'\n";}
4225  
4226    return value;
4227  
# Line 2701 | Line 4231 | OSUAnalysis::applyFunction(string functi
4231   template <class InputCollection>
4232   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
4233  
4234 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
4235 +    string obj1, obj2;
4236 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
4237 +    if (inputType==obj1 ||
4238 +        inputType==obj2) {
4239 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
4240 +      // and the inputType is a member of the pair.
4241 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
4242 +      // For example, if currentCut.inputCollection==electron-muon pairs,
4243 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
4244 +      return;
4245 +    }
4246 +  }
4247  
4248    for (uint object = 0; object != inputCollection->size(); object++){
4249  
4250 <
4251 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
2709 <
4250 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4251 >    bool plotDecision = true;
4252  
4253      if(currentCut.inputCollection == inputType){
4254  
4255        vector<bool> subcutDecisions;
4256        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4257 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4258 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4257 >        string stringValue = "";
4258 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4259 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4260 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4261 >
4262        }
4263 <      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4263 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4264        else{
4265          bool tempDecision = true;
4266          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
# Line 2724 | Line 4269 | void OSUAnalysis::setObjectFlags(cut &cu
4269            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4270              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4271          }
4272 <        decision = tempDecision;
4272 >        cutDecision = tempDecision;
4273        }
4274 +      //invert the cut for plotting if this cut is a veto
4275 +      if(currentCut.isVeto) plotDecision = !cutDecision;
4276 +      else plotDecision = cutDecision;
4277      }
2730    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4278  
4279 +    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4280  
4281 <    //set flags for objects that pass each cut AND all the previous cuts
4282 <    bool previousCumulativeFlag = true;
4281 >    //set flags for objects that pass this cut AND all the previous cuts
4282 >    bool previousCumulativeCutFlag = true;
4283 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4284 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4285 >      else{ previousCumulativeCutFlag = false; break;}
4286 >    }
4287 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4288 >    bool previousCumulativePlotFlag = true;
4289      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4290 <      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4291 <      else{ previousCumulativeFlag = false; break;}
4290 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4291 >      else{ previousCumulativePlotFlag = false; break;}
4292      }
4293 <    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4293 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4294  
4295 +    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4296  
4297    }
4298  
# Line 2746 | Line 4301 | void OSUAnalysis::setObjectFlags(cut &cu
4301  
4302   template <class InputCollection1, class InputCollection2>
4303   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
4304 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
4304 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, string inputType){
4305  
4306  
4307    bool sameObjects = false;
4308    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4309  
4310 +  // Get the strings for the two objects that make up the pair.
4311 +  string obj1Type, obj2Type;
4312 +  getTwoObjs(inputType, obj1Type, obj2Type);
4313 +  bool isTwoTypesOfObject = true;
4314 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
4315 +
4316 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
4317 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4318 +  if (currentCut.inputCollection == inputType) {
4319 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4320 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4321 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4322 +    }
4323 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4324 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4325 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4326 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4327 +      }
4328 +    }
4329 +  }
4330  
4331    int counter = 0;
4332 +
4333    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4334      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4335  
4336        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4337  
4338  
4339 <      bool decision = true;//object passes if this cut doesn't cut on that type of object
4339 >      bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4340 >      bool plotDecision = true;
4341  
4342        if(currentCut.inputCollection == inputType){
4343  
4344          vector<bool> subcutDecisions;
4345          for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4346 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4347 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4346 >          string stringValue = "";
4347 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4348 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4349 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4350          }
4351  
4352 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4352 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4353          else{
4354            bool tempDecision = subcutDecisions.at(0);
4355            for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
# Line 2779 | Line 4358 | void OSUAnalysis::setObjectFlags(cut &cu
4358              else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4359                tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4360            }
4361 <          decision = tempDecision;
4361 >          cutDecision = tempDecision;
4362          }
4363 +        //invert the cut for plotting if this cut is a veto
4364 +        if(currentCut.isVeto) plotDecision = !cutDecision;
4365 +        else plotDecision = cutDecision;
4366 +      }
4367 +      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4368 +      if (cutDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4369 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4370 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4371        }
4372 <      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4372 >      if (plotDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4373 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4374 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4375 >      }
4376 >
4377 >      //set flags for objects that pass this cut AND all the previous cuts
4378 >      bool previousCumulativeCutFlag = true;
4379 >      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4380 >        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4381 >        else{ previousCumulativeCutFlag = false; break;}
4382 >      }
4383 >      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4384  
4385 <      //set flags for objects that pass each cut AND all the previous cuts
2788 <      bool previousCumulativeFlag = true;
4385 >      bool previousCumulativePlotFlag = true;
4386        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4387 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
4388 <        else{ previousCumulativeFlag = false; break;}
4387 >        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4388 >        else{ previousCumulativePlotFlag = false; break;}
4389        }
4390 +      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4391 +      
4392        //apply flags for the components of the composite object as well
4393 <      bool currentCumulativeFlag = true;
4394 <      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
4395 <      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
4396 <      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
4397 <      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
4398 <      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
4393 >      bool currentCumulativeCutFlag = true;
4394 >      bool currentCumulativePlotFlag = true;
4395 >
4396 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4397 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4398 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4399 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4400 >
4401 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4402 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4403 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4404 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4405 >
4406 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));
4407 >
4408 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4409 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4410 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4411 >      }
4412 >
4413 >      if (currentCumulativePlotFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4414 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4415 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4416 >      }
4417  
4418        counter++;
2802    }
4419  
4420 +    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4421 +  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4422 +
4423 + }
4424 +
4425 +
4426 + bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4427 +  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4428 +  // all cuts up to currentCutIndex
4429 +  bool previousCumulativeFlag = true;
4430 +  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4431 +    bool tempFlag = false;
4432 +    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4433 +    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4434 +
4435 +    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4436 +    else {
4437 +      previousCumulativeFlag = false; break;
4438 +    }
4439    }
4440 +  return previousCumulativeFlag;
4441 + }
4442 +
4443  
4444  
4445 +
4446 + template <class InputCollection>
4447 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4448 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4449 +
4450 +  if (BNTreeBranchVals_.count(parameters.name)==0) clog << "Error[assignTreeBranch]:  trying to assign value to " << parameters.name << " that does not have a branch set up.  Will likely seg fault." << endl;
4451 +  for (uint object = 0; object != inputCollection->size(); object++) {
4452 +
4453 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4454 +
4455 +    string inputVariable = parameters.inputVariable;
4456 +    string function = "";
4457 +    string stringValue = "";
4458 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4459 +    BNTreeBranchVals_.at(parameters.name).push_back(value);
4460 +
4461 +  }
4462   }
4463  
4464  
4465   template <class InputCollection>
4466 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4466 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4467 >
4468  
4469    for (uint object = 0; object != inputCollection->size(); object++){
4470  
4471 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4471 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4472  
4473      string currentString = parameters.inputVariables.at(0);
4474      string inputVariable = "";
4475      string function = "";
4476 <    if(currentString.find("(")==std::string::npos){
4476 >    if(currentString.find("(")==string::npos){
4477        inputVariable = currentString;// variable to cut on
4478      }
4479      else{
# Line 2826 | Line 4482 | void OSUAnalysis::fill1DHistogram(TH1* h
4482        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4483      }
4484  
4485 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
4485 >    string stringValue = "";
4486 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4487      histo->Fill(value,scaleFactor);
4488  
4489      if (printEventInfo_) {
4490 <      // Write information about event to screen, for testing purposes.  
4491 <      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;  
4490 >      // Write information about event to screen, for testing purposes.
4491 >      clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
4492      }
4493 <    
4493 >
4494    }
4495   }
4496  
4497   template <class InputCollection1, class InputCollection2>
4498 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4498 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4499  
4500    bool sameObjects = false;
4501    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4502  
4503 <  int pairCounter = 0;
4503 >  int pairCounter = -1;
4504    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4505      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4506  
4507        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4508  
4509 +      pairCounter++;
4510        //only take objects which have passed all cuts and pairs which have passed all cuts
4511 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4512 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4513 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4511 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4512 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4513 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4514  
4515        string currentString = parameters.inputVariables.at(0);
4516        string inputVariable = "";
4517        string function = "";
4518 <      if(currentString.find("(")==std::string::npos){
4518 >      if(currentString.find("(")==string::npos){
4519          inputVariable = currentString;// variable to cut on
4520        }
4521        else{
# Line 2866 | Line 4524 | void OSUAnalysis::fill1DHistogram(TH1* h
4524          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4525        }
4526  
4527 <      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4527 >      string stringValue = "";
4528 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4529        histo->Fill(value,scaleFactor);
4530  
2872      pairCounter++;
4531      }
4532    }
4533  
# Line 2877 | Line 4535 | void OSUAnalysis::fill1DHistogram(TH1* h
4535  
4536  
4537   template <class InputCollection>
4538 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4538 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4539  
4540    for (uint object = 0; object != inputCollection->size(); object++){
4541  
4542 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4542 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4543  
4544 +    string stringValue = "";
4545      string currentString = parameters.inputVariables.at(0);
4546      string inputVariable = "";
4547      string function = "";
4548 <    if(currentString.find("(")==std::string::npos){
4548 >    if(currentString.find("(")==string::npos){
4549        inputVariable = currentString;// variable to cut on
4550      }
4551      else{
# Line 2894 | Line 4553 | void OSUAnalysis::fill2DHistogram(TH2* h
4553        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4554        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4555      }
4556 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
4556 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4557  
4558      currentString = parameters.inputVariables.at(1);
4559      inputVariable = "";
4560      function = "";
4561 <    if(currentString.find("(")==std::string::npos){
4561 >    if(currentString.find("(")==string::npos){
4562        inputVariable = currentString;// variable to cut on
4563      }
4564      else{
# Line 2908 | Line 4567 | void OSUAnalysis::fill2DHistogram(TH2* h
4567        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4568      }
4569  
4570 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
4570 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4571  
4572      histo->Fill(valueX,valueY,scaleFactor);
4573  
# Line 2917 | Line 4576 | void OSUAnalysis::fill2DHistogram(TH2* h
4576   }
4577  
4578   template <class InputCollection1, class InputCollection2>
4579 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4579 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4580  
4581    bool sameObjects = false;
4582    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4583  
4584 <  int pairCounter = 0;
4584 >  int pairCounter = -1;
4585    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4586      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4587  
4588        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4589  
4590 +      pairCounter++;
4591 +
4592        //only take objects which have passed all cuts and pairs which have passed all cuts
4593 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4594 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4595 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4593 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4594 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4595 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4596  
4597 +      string stringValue = "";
4598        string currentString = parameters.inputVariables.at(0);
4599        string inputVariable = "";
4600        string function = "";
4601 <      if(currentString.find("(")==std::string::npos){
4601 >      if(currentString.find("(")==string::npos){
4602          inputVariable = currentString;// variable to cut on
4603        }
4604        else{
# Line 2944 | Line 4606 | void OSUAnalysis::fill2DHistogram(TH2* h
4606          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4607          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4608        }
4609 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4609 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4610  
4611        currentString = parameters.inputVariables.at(1);
4612        inputVariable = "";
4613        function = "";
4614 <      if(currentString.find("(")==std::string::npos){
4614 >      if(currentString.find("(")==string::npos){
4615          inputVariable = currentString;// variable to cut on
4616        }
4617        else{
# Line 2957 | Line 4619 | void OSUAnalysis::fill2DHistogram(TH2* h
4619          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4620          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4621        }
4622 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4622 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4623  
4624  
4625        histo->Fill(valueX,valueY,scaleFactor);
4626  
2965      pairCounter++;
2966
4627      }
4628    }
4629  
# Line 2980 | Line 4640 | int OSUAnalysis::getGenMatchedParticleIn
4640  
4641      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4642      if(currentDeltaR > 0.05) continue;
4643 < //     cout << std::setprecision(3) << std::setw(20)
4644 < //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4645 < //          << std::setw(20)
4646 < //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4647 < //          << std::setw(20)
4648 < //          << "\tdeltaR = " << currentDeltaR
4649 < //          << std::setprecision(1)
4650 < //          << std::setw(20)
4651 < //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4652 < //          << std::setw(20)
4653 < //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4654 < //          << std::setw(20)
4655 < //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4643 >    //     clog << setprecision(3) << setw(20)
4644 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4645 >    //          << setw(20)
4646 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4647 >    //          << setw(20)
4648 >    //          << "\tdeltaR = " << currentDeltaR
4649 >    //          << setprecision(1)
4650 >    //          << setw(20)
4651 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4652 >    //          << setw(20)
4653 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4654 >    //          << setw(20)
4655 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4656      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4657        bestMatchIndex = mcparticle - mcparticles->begin();
4658        bestMatchDeltaR = currentDeltaR;
4659      }
4660  
4661    }
4662 < //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4663 < //   else cout << "no match found..." << endl;
4662 >  //   if(bestMatchDeltaR != 999)  clog << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4663 >  //   else clog << "no match found..." << endl;
4664    return bestMatchIndex;
4665  
4666   }
# Line 3054 | Line 4714 | int OSUAnalysis::findTauMotherIndex(cons
4714   // 20        strange baryon
4715   // 21        charm baryon
4716   // 22        bottom baryon
4717 < // 23        other
4717 > // 23        QCD string
4718 > // 24        other
4719  
4720   int OSUAnalysis::getPdgIdBinValue(int pdgId){
4721  
# Line 3078 | Line 4739 | int OSUAnalysis::getPdgIdBinValue(int pd
4739    else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4740    else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4741    else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4742 +  else if(absPdgId == 92  ) binValue = 23;
4743  
4744 <  else binValue = 23;
4744 >  else binValue = 24;
4745  
4746    return binValue;
4747  
# Line 3089 | Line 4751 | const BNprimaryvertex *
4751   OSUAnalysis::chosenVertex ()
4752   {
4753    const BNprimaryvertex *chosenVertex = 0;
4754 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
4755 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
4756 <                               cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
4754 >  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4755 >    flagPair vertexFlags;
4756 >    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4757 >      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4758 >        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4759 >        break;
4760 >      }
4761 >    }
4762      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4763 <      if(!vertexFlags.at(vertexIndex)) continue;
4763 >      if(!vertexFlags.at(vertexIndex).first) continue;
4764        chosenVertex = & primaryvertexs->at(vertexIndex);
4765        break;
4766      }
4767    }
4768 <  else {
4769 <    chosenVertex = &primaryvertexs->at(0);
3103 <  }
4768 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4769 >    chosenVertex = & primaryvertexs->at (0);
4770  
4771    return chosenVertex;
4772   }
# Line 3109 | Line 4775 | const BNmet *
4775   OSUAnalysis::chosenMET ()
4776   {
4777    const BNmet *chosenMET = 0;
4778 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
4779 <    vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
4780 <                            cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
4778 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4779 >    flagPair metFlags;
4780 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4781 >      if (cumulativeFlags.at("mets").at(i).size()){
4782 >        metFlags = cumulativeFlags.at("mets").at(i);
4783 >        break;
4784 >      }
4785 >    }
4786      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4787 <      if(!metFlags.at(metIndex)) continue;
4787 >      if(!metFlags.at(metIndex).first) continue;
4788        chosenMET = & mets->at(metIndex);
4789        break;
4790      }
4791    }
4792 <  else {
4793 <    chosenMET = &mets->at(0);
3123 <  }
4792 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4793 >    chosenMET = & mets->at (0);
4794  
4795    return chosenMET;
4796   }
# Line 3129 | Line 4799 | const BNelectron *
4799   OSUAnalysis::chosenElectron ()
4800   {
4801    const BNelectron *chosenElectron = 0;
4802 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
4803 <    vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
4804 <                                 cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
4802 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4803 >    flagPair electronFlags;
4804 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4805 >      if (cumulativeFlags.at("electrons").at(i).size()){
4806 >        electronFlags = cumulativeFlags.at("electrons").at(i);
4807 >        break;
4808 >      }
4809 >    }
4810      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4811 <      if(!electronFlags.at(electronIndex)) continue;
4811 >      if(!electronFlags.at(electronIndex).first) continue;
4812        chosenElectron = & electrons->at(electronIndex);
4813        break;
4814      }
4815    }
4816 <  else {
4817 <    chosenElectron = &electrons->at(0);
3143 <  }
4816 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4817 >    chosenElectron = & electrons->at (0);
4818  
4819    return chosenElectron;
4820   }
4821  
4822 +
4823   const BNmuon *
4824   OSUAnalysis::chosenMuon ()
4825   {
4826    const BNmuon *chosenMuon = 0;
4827 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
4828 <    vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
4829 <                             cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
4827 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4828 >    flagPair muonFlags;
4829 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4830 >      if (cumulativeFlags.at("muons").at(i).size()){
4831 >        muonFlags = cumulativeFlags.at("muons").at(i);
4832 >        break;
4833 >      }
4834 >    }
4835      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4836 <      if(!muonFlags.at(muonIndex)) continue;
4836 >      if(!muonFlags.at(muonIndex).first) continue;
4837        chosenMuon = & muons->at(muonIndex);
4838        break;
4839      }
4840    }
4841 <  else {
4842 <    chosenMuon = &muons->at(0);
3163 <  }
4841 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4842 >    chosenMuon = & muons->at (0);
4843  
4844    return chosenMuon;
4845   }
4846  
4847 + double
4848 + OSUAnalysis::chosenHT ()
4849 + {
4850 +  double chosenHT = 0.0;
4851 +  if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
4852 +    flagPair jetFlags;
4853 +    for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
4854 +      if (cumulativeFlags.at("jets").at(i).size()){
4855 +        jetFlags = cumulativeFlags.at("jets").at(i);
4856 +        break;
4857 +      }
4858 +    }
4859 +    for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
4860 +      if(!jetFlags.at(jetIndex).first) continue;
4861 +      chosenHT += jets->at(jetIndex).pt;
4862 +    }
4863 +  }
4864 +
4865 +  return chosenHT;
4866 + }
4867 +
4868 + pair<const BNmuon *, const BNmuon *>
4869 + OSUAnalysis::leadMuonPair ()
4870 + {
4871 +  pair<const BNmuon *, const BNmuon *> leadMuonPair;
4872 +  leadMuonPair.first = leadMuonPair.second = 0;
4873 +
4874 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4875 +    flagPair muonFlags;
4876 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4877 +      if (cumulativeFlags.at("muons").at(i).size()){
4878 +        muonFlags = cumulativeFlags.at("muons").at(i);
4879 +        break;
4880 +      }
4881 +    }
4882 +    for (uint muonIndex0 = 0; muonIndex0 != muonFlags.size(); muonIndex0++){
4883 +      if(!muonFlags.at(muonIndex0).first) continue;
4884 +      for (uint muonIndex1 = muonIndex0 + 1; muonIndex1 < muonFlags.size(); muonIndex1++){
4885 +        if(!muonFlags.at(muonIndex1).first) continue;
4886 +        const BNmuon *mu0 = & muons->at(muonIndex0);
4887 +        const BNmuon *mu1 = & muons->at(muonIndex1);
4888 +        if(leadMuonPair.first == 0 || leadMuonPair.second == 0){
4889 +          leadMuonPair.first = mu0;
4890 +          leadMuonPair.second = mu1;
4891 +        }
4892 +        else{
4893 +          TVector2 newPt0 (mu0->px, mu0->py),
4894 +                   newPt1 (mu1->px, mu1->py),
4895 +                   oldPt0 (leadMuonPair.first->px, leadMuonPair.first->py),
4896 +                   oldPt1 (leadMuonPair.second->px, leadMuonPair.second->py);
4897 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
4898 +            {
4899 +              leadMuonPair.first = mu0;
4900 +              leadMuonPair.second = mu1;
4901 +            }
4902 +        }
4903 +      }
4904 +    }
4905 +  }
4906 +
4907 +  return leadMuonPair;
4908 + }
4909 +
4910 + pair<const BNelectron *, const BNelectron *>
4911 + OSUAnalysis::leadElectronPair ()
4912 + {
4913 +  pair<const BNelectron *, const BNelectron *> leadElectronPair;
4914 +  leadElectronPair.first = leadElectronPair.second = 0;
4915 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4916 +    flagPair electronFlags;
4917 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4918 +      if (cumulativeFlags.at("electrons").at(i).size()){
4919 +        electronFlags = cumulativeFlags.at("electrons").at(i);
4920 +        break;
4921 +      }
4922 +    }
4923 +    for (uint electronIndex0 = 0; electronIndex0 != electronFlags.size(); electronIndex0++){
4924 +      if(!electronFlags.at(electronIndex0).first) continue;
4925 +      for (uint electronIndex1 = electronIndex0 + 1; electronIndex1 < electronFlags.size(); electronIndex1++){
4926 +        if(!electronFlags.at(electronIndex1).first) continue;
4927 +        const BNelectron *el0 = & electrons->at(electronIndex0);
4928 +        const BNelectron *el1 = & electrons->at(electronIndex1);
4929 +        if(leadElectronPair.first == 0 || leadElectronPair.second == 0){
4930 +          leadElectronPair.first = el0;
4931 +          leadElectronPair.second = el1;
4932 +        }
4933 +        else{
4934 +          TVector2 newPt0 (el0->px, el0->py),
4935 +                   newPt1 (el1->px, el1->py),
4936 +                   oldPt0 (leadElectronPair.first->px, leadElectronPair.first->py),
4937 +                   oldPt1 (leadElectronPair.second->px, leadElectronPair.second->py);
4938 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
4939 +            {
4940 +              leadElectronPair.first = el0;
4941 +              leadElectronPair.second = el1;
4942 +            }
4943 +        }
4944 +      }
4945 +    }
4946 +  }
4947 +
4948 +  return leadElectronPair;
4949 + }
4950  
4951   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines