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.43 by wulsin, Thu Mar 28 10:17:32 2013 UTC vs.
Revision 1.84 by ahart, Thu Jun 6 11:44:32 2013 UTC

# Line 11 | Line 11 | OSUAnalysis::OSUAnalysis (const edm::Par
11    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
12    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
13    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
14 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
15    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
16    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
17    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
18    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
19    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
20 <  puFile_ (cfg.getParameter<std::string> ("puFile")),
21 <  deadEcalFile_ (cfg.getParameter<std::string> ("deadEcalFile")),
22 <  muonSFFile_ (cfg.getParameter<std::string> ("muonSFFile")),
23 <  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
24 <  electronSFID_ (cfg.getParameter<std::string> ("electronSFID")),
25 <  muonSF_ (cfg.getParameter<std::string> ("muonSF")),
26 <  dataset_ (cfg.getParameter<std::string> ("dataset")),
27 <  datasetType_ (cfg.getParameter<std::string> ("datasetType")),
20 >  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
21 >  puFile_ (cfg.getParameter<string> ("puFile")),
22 >  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
23 >  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
24 >  dataPU_ (cfg.getParameter<string> ("dataPU")),
25 >  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
26 >  muonSF_ (cfg.getParameter<string> ("muonSF")),
27 >  dataset_ (cfg.getParameter<string> ("dataset")),
28 >  datasetType_ (cfg.getParameter<string> ("datasetType")),
29    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
30    histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
31 +  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 >  maxBtag_ (cfg.getParameter<int> ("maxBtag")),
38 >  printEventInfo_      (cfg.getParameter<bool> ("printEventInfo")),
39 >  printAllTriggers_    (cfg.getParameter<bool> ("printAllTriggers")),
40 >  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
41 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
42 >  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
43 > {
44  
45    TH1::SetDefaultSumw2 ();
46  
47    //create pile-up reweighting object, if necessary
48    if(datasetType_ != "data") {
49      if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
50 <    //    muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
51 <    //    electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
50 >    if (applyLeptonSF_){
51 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
52 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
53 >    }
54 >    if (applyBtagSF_){
55 >      bTagSFWeight_ = new BtagSFWeight;
56 >    }
57    }
58 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
59 +    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
60  
61  
62    // Construct Cutflow Objects. These store the results of cut decisions and
63    // handle filling cut flow histograms.
64    masterCutFlow_ = new CutFlow (fs_);
49  std::vector<TFileDirectory> directories;
65  
66    //always get vertex collection so we can assign the primary vertex in the event
67    objectsToGet.push_back("primaryvertexs");
53
54  //always make the plot of number of primary verticex (to check pile-up reweighting)
68    objectsToPlot.push_back("primaryvertexs");
69 +  objectsToCut.push_back("primaryvertexs");
70 +
71  
72    //always get the MC particles to do GEN-matching
73    objectsToGet.push_back("mcparticles");
# Line 60 | Line 75 | OSUAnalysis::OSUAnalysis (const edm::Par
75    //always get the event collection to do pile-up reweighting
76    objectsToGet.push_back("events");
77  
78 +
79 +  // Parse the tree variable definitions.
80 +  for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++) {
81 +    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
82 +    if(tempInputCollection.find("pairs")!=string::npos) { cout << "Warning:  tree filling is not configured for pairs of objects, so will not work for collection: " << tempInputCollection << endl; }
83 +    objectsToGet.push_back(tempInputCollection);
84 +    objectsToCut.push_back(tempInputCollection);
85 +
86 +    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
87 +
88 +    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
89 +      BranchSpecs br;
90 +      br.inputCollection = tempInputCollection;
91 +      br.inputVariable = branchList.at(iBranch);
92 +      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);
93 +      br.name = string(newName.Data());
94 +      treeBranches_.push_back(br);
95 +    }
96 +
97 +  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++)
98 +
99 +
100    //parse the histogram definitions
101    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
102  
103      string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
104      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
105 +    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
106 +    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
107      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
108 <    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
109 <      objectsToGet.push_back(tempInputCollection);
108 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
109 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
110 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
111 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
112 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
113 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
114 >        int spaceIndex = tempInputCollection.find(" ");
115 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
116 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
117 >      }
118 >      else{
119 >        objectsToGet.push_back(tempInputCollection);
120 >      }
121        objectsToPlot.push_back(tempInputCollection);
122        objectsToCut.push_back(tempInputCollection);
123 <    }
124 <    else{//pair of objects, need to add them both to the things to objectsToGet
125 <      int dashIndex = tempInputCollection.find("-");
126 <      int spaceIndex = tempInputCollection.find(" ");
127 <      int secondWordLength = spaceIndex - dashIndex;
78 <      objectsToGet.push_back(tempInputCollection);
79 <      objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
80 <      objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
81 <      objectsToPlot.push_back(tempInputCollection);
82 <      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
83 <      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
123 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
124 >      string obj1;
125 >      string obj2;
126 >      getTwoObjs(tempInputCollection, obj1, obj2);
127 >      string obj2ToGet = getObjToGet(obj2);
128        objectsToCut.push_back(tempInputCollection);
129 <      objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
130 <      objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
129 >      objectsToCut.push_back(obj1);
130 >      objectsToCut.push_back(obj2);
131 >      objectsToPlot.push_back(tempInputCollection);
132 >      objectsToPlot.push_back(obj1);
133 >      objectsToPlot.push_back(obj2);
134 >      objectsToGet.push_back(tempInputCollection);
135 >      objectsToGet.push_back(obj1);
136 >      objectsToGet.push_back(obj2ToGet);
137 >    } // end else
138 >
139  
88    }
140  
141      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
142  
143      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
144  
145 +      vector<double> defaultValue;
146 +      defaultValue.push_back (-1.0);
147 +
148        histogram tempHistogram;
149        tempHistogram.inputCollection = tempInputCollection;
150        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
151        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
152 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
152 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
153 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
154 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
155        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
156  
157        histograms.push_back(tempHistogram);
158  
159      }
160 <  }
160 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
161 >
162    //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
163    sort( objectsToPlot.begin(), objectsToPlot.end() );
164    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
# Line 112 | Line 169 | OSUAnalysis::OSUAnalysis (const edm::Par
169    for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
170  
171      string currentObject = objectsToPlot.at(currentObjectIndex);
172 <    if(currentObject != "muons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
172 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
173  
174      histogram tempIdHisto;
175      histogram tempMomIdHisto;
176      histogram tempGmaIdHisto;
177      histogram tempIdVsMomIdHisto;
178 +    histogram tempIdVsGmaIdHisto;
179  
180      tempIdHisto.inputCollection = currentObject;
181      tempMomIdHisto.inputCollection = currentObject;
182      tempGmaIdHisto.inputCollection = currentObject;
183      tempIdVsMomIdHisto.inputCollection = currentObject;
184 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
185 +
186 +    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
187 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
188  
189      currentObject = currentObject.substr(0, currentObject.size()-1);
190      tempIdHisto.name = currentObject+"GenMatchId";
191      tempMomIdHisto.name = currentObject+"GenMatchMotherId";
192      tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
193      tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
194 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
195  
196      currentObject.at(0) = toupper(currentObject.at(0));
197      tempIdHisto.title = currentObject+" Gen-matched Particle";
198      tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
199      tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
200      tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
201 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
202 +
203  
204 <    int maxNum = 24;
204 >    int maxNum = 25;
205      vector<double> binVector;
206      binVector.push_back(maxNum);
207      binVector.push_back(0);
# Line 154 | Line 219 | OSUAnalysis::OSUAnalysis (const edm::Par
219      tempIdVsMomIdHisto.bins = binVector;
220      tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
221      tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
222 +    tempIdVsGmaIdHisto.bins = binVector;
223 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
224 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
225  
226      histograms.push_back(tempIdHisto);
227      histograms.push_back(tempMomIdHisto);
228      histograms.push_back(tempGmaIdHisto);
229      histograms.push_back(tempIdVsMomIdHisto);
230 +    histograms.push_back(tempIdVsGmaIdHisto);
231    }
232  
233  
# Line 174 | Line 243 | OSUAnalysis::OSUAnalysis (const edm::Par
243      //set triggers for this channel
244      vector<string> triggerNames;
245      triggerNames.clear();
246 +    vector<string> triggerToVetoNames;
247 +    triggerToVetoNames.clear();
248 +
249      tempChannel.triggers.clear();
250 +    tempChannel.triggersToVeto.clear();
251      if(channels_.at(currentChannel).exists("triggers")){
252        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
253        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
254          tempChannel.triggers.push_back(triggerNames.at(trigger));
255        objectsToGet.push_back("triggers");
256      }
257 <
257 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
258 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
259 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
260 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
261 >      objectsToGet.push_back("triggers");
262 >    }
263  
264  
265  
266      //create cutFlow for this channel
267      cutFlows_.push_back (new CutFlow (fs_, channelName));
268 <
269 <    //book a directory in the output file with the name of the channel
270 <    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 <      else if(currentObject == "electron-track pairs")    currentObject = "electronTrackPairs";  
308 <      else if(currentObject == "muon-track pairs")        currentObject = "muonTrackPairs";      
309 <      else if(currentObject == "muon-tau pairs")          currentObject = "muonTauPairs";        
310 <      else if(currentObject == "tau-tau pairs")           currentObject = "ditauPairs";
311 <      currentObject.at(0) = toupper(currentObject.at(0));  
312 <      string histoName = "num" + currentObject;
313 <
314 <      if(histoName == "numPrimaryvertexs"){
315 <        string newHistoName = histoName + "BeforePileupCorrection";
316 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
317 <        newHistoName = histoName + "AfterPileupCorrection";
318 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
319 <      }
320 <      else
321 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
322 <    }
323 <
324 <
325 <
326 <
268 >    vector<TFileDirectory> directories; //vector of directories in the output file.
269 >    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
270 >    vector<string> subSubDirNames;//subdirectories in each channel.
271      //get list of cuts for this channel
272      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
273  
274 +
275      //loop over and parse all cuts
276      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
277        cut tempCut;
278        //store input collection for cut
279        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
280 +      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
281 +      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
282 +      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
283 +      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
284 +      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
285 +      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
286 +      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
287 +      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
288        tempCut.inputCollection = tempInputCollection;
289 <      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
290 <        objectsToGet.push_back(tempInputCollection);
289 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
290 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
291 >          int spaceIndex = tempInputCollection.find(" ");
292 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
293 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
294 >        }
295 >        else{
296 >          objectsToGet.push_back(tempInputCollection);
297 >        }
298          objectsToCut.push_back(tempInputCollection);
299        }
300 <      else{//pair of objects, need to add them both to the things to objectsToGet
301 <        int dashIndex = tempInputCollection.find("-");
302 <        int spaceIndex = tempInputCollection.find(" ");
303 <        int secondWordLength = spaceIndex - dashIndex;
304 <        objectsToGet.push_back(tempInputCollection);
345 <        objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
346 <        objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
300 >      else{//pair of objects, need to add them both to objectsToGet
301 >        string obj1;
302 >        string obj2;
303 >        getTwoObjs(tempInputCollection, obj1, obj2);
304 >        string obj2ToGet = getObjToGet(obj2);
305          objectsToCut.push_back(tempInputCollection);
306 <        objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
307 <        objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
306 >        objectsToCut.push_back(obj1);
307 >        objectsToCut.push_back(obj2);
308 >        objectsToGet.push_back(tempInputCollection);
309 >        objectsToGet.push_back(obj1);
310 >        objectsToGet.push_back(obj2ToGet);
311  
312        }
313  
# Line 354 | Line 315 | OSUAnalysis::OSUAnalysis (const edm::Par
315  
316        //split cut string into parts and store them
317        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
318 <      std::vector<string> cutStringVector = splitString(cutString);
318 >      vector<string> cutStringVector = splitString(cutString);
319        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
320 <        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
320 >        cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
321          exit(0);
322        }
323        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
324        for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
325          int indexOffset = 4 * subcutIndex;
326          string currentVariableString = cutStringVector.at(indexOffset);
327 <        if(currentVariableString.find("(")==std::string::npos){
327 >        if(currentVariableString.find("(")==string::npos){
328            tempCut.functions.push_back("");//no function was specified
329            tempCut.variables.push_back(currentVariableString);// variable to cut on
330          }
# Line 374 | Line 335 | OSUAnalysis::OSUAnalysis (const edm::Par
335          }
336          tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
337          tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
338 +        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
339          if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
340        }
341  
342        //get number of objects required to pass cut for event to pass
343        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
344 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
344 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
345        if(numberRequiredVector.size()!=2){
346 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
346 >        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
347          exit(0);
348        }
349  
# Line 389 | Line 351 | OSUAnalysis::OSUAnalysis (const edm::Par
351        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
352        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
353  
354 <
354 >      //Set up vectors to store the directories and subDIrectories for each channel.
355 >      string subSubDirName;
356        string tempCutName;
357        if(cuts_.at(currentCut).exists("alias")){
358          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
359 +        subSubDirName = "After " + cuts_.at(currentCut).getParameter<string> ("alias") + " Cut Applied";
360        }
361        else{
362          //construct string for cutflow table
# Line 400 | Line 364 | OSUAnalysis::OSUAnalysis (const edm::Par
364          string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
365          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
366          tempCutName = cutName;
367 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
368        }
404      tempCut.name = tempCutName;
369  
370 +      subSubDirNames.push_back(subSubDirName);
371 +      tempCut.name = tempCutName;
372  
373        tempChannel.cuts.push_back(tempCut);
374  
375  
410
376      }//end loop over cuts
377  
378 +    vector<map<string, TH1D*>> oneDHistsTmp;
379 +    vector<map<string, TH2D*>> twoDHistsTmp;
380 +    //book a directory in the output file with the name of the channel
381 +    TFileDirectory subDir = fs_->mkdir( channelName );
382 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
383 +    if(GetPlotsAfterEachCut_){
384 +      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
385 +        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
386 +        directories.push_back(subSubDir);
387 +        map<string, TH1D*> oneDhistoMap;
388 +        oneDHistsTmp.push_back(oneDhistoMap);
389 +        map<string, TH2D*> twoDhistoMap;
390 +        twoDHistsTmp.push_back(twoDhistoMap);
391 +      }
392 +      treeDirectories.push_back(subDir);
393 +      oneDHists_.push_back(oneDHistsTmp);
394 +      twoDHists_.push_back(twoDHistsTmp);
395 +    }
396 +    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
397 +    else{
398 +      map<string, TH1D*> oneDhistoMap;
399 +      oneDHistsTmp.push_back(oneDhistoMap);
400 +      map<string, TH2D*> twoDhistoMap;
401 +      twoDHistsTmp.push_back(twoDhistoMap);
402 +      oneDHists_.push_back(oneDHistsTmp);
403 +      twoDHists_.push_back(twoDHistsTmp);
404 +      directories.push_back(subDir);
405 +      treeDirectories.push_back(subDir);
406 +
407 +    }
408 +
409 +    for(uint currentDir = 0; currentDir != treeDirectories.size(); currentDir++){
410 +      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
411 +      BNTrees_.push_back(newTree);
412 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
413 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
414 +        vector<float> newVec;
415 +        BNTreeBranchVals_[currentVar.name] = newVec;
416 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
417 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
418 +    }
419 +
420 +    //book all histograms included in the configuration
421 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
422 +
423 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
424 +
425 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
426 +        int numBinsElements = currentHistogram.bins.size();
427 +        int numInputVariables = currentHistogram.inputVariables.size();
428 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
429 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
430 +
431 +        if(numBinsElements == 1){
432 +          if(numBinEdgesX > 1){
433 +            if(numBinEdgesY > 1)
434 +              numBinsElements = 6;
435 +            else
436 +              numBinsElements = 3;
437 +          }
438 +        }
439 +        if(numBinsElements != 3 && numBinsElements !=6){
440 +          cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
441 +          exit(0);
442 +        }
443 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
444 +          cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
445 +          exit(0);
446 +        }
447 +        else if(numBinsElements == 3){
448 +          if (currentHistogram.bins.size () == 3)
449 +            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));
450 +          else
451 +            {
452 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
453 +            }
454 +        }
455 +        else if(numBinsElements == 6){
456 +          if (currentHistogram.bins.size () == 6)
457 +            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));
458 +          else
459 +            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 ());
460 +        }
461 +
462 +
463 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
464 +
465 +        // bin      particle type
466 +        // ---      -------------
467 +        //  0        unmatched
468 +        //  1        u
469 +        //  2        d
470 +        //  3        s
471 +        //  4        c
472 +        //  5        b
473 +        //  6        t
474 +        //  7        e
475 +        //  8        mu
476 +        //  9        tau
477 +        // 10        nu
478 +        // 11        g
479 +        // 12        gamma
480 +        // 13        Z
481 +        // 14        W
482 +        // 15        light meson
483 +        // 16        K meson
484 +        // 17        D meson
485 +        // 18        B meson
486 +        // 19        light baryon
487 +        // 20        strange baryon
488 +        // 21        charm baryon
489 +        // 22        bottom baryon
490 +        // 23        QCD string
491 +        // 24        other
492 +
493 +        vector<TString> labelArray;
494 +        labelArray.push_back("unmatched");
495 +        labelArray.push_back("u");
496 +        labelArray.push_back("d");
497 +        labelArray.push_back("s");
498 +        labelArray.push_back("c");
499 +        labelArray.push_back("b");
500 +        labelArray.push_back("t");
501 +        labelArray.push_back("e");
502 +        labelArray.push_back("#mu");
503 +        labelArray.push_back("#tau");
504 +        labelArray.push_back("#nu");
505 +        labelArray.push_back("g");
506 +        labelArray.push_back("#gamma");
507 +        labelArray.push_back("Z");
508 +        labelArray.push_back("W");
509 +        labelArray.push_back("light meson");
510 +        labelArray.push_back("K meson");
511 +        labelArray.push_back("D meson");
512 +        labelArray.push_back("B meson");
513 +        labelArray.push_back("light baryon");
514 +        labelArray.push_back("strange baryon");
515 +        labelArray.push_back("charm baryon");
516 +        labelArray.push_back("bottom baryon");
517 +        labelArray.push_back("QCD string");
518 +        labelArray.push_back("other");
519 +
520 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
521 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
522 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
523 +          }
524 +          else {
525 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
526 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
527 +          }
528 +        }
529 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
530 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
531 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
532 +        }
533 +
534 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
535 +
536 +
537 +      // Book a histogram for the number of each object type to be plotted.
538 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
539 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
540 +        string currentObject = objectsToPlot.at(currentObjectIndex);
541 +        int maxNum = 10;
542 +        if(currentObject == "mcparticles") maxNum = 50;
543 +        else if(currentObject == "primaryvertexs") maxNum = 50;
544 +
545 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
546 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
547 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
548 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
549 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
550 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
551 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
552 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
553 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
554 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
555 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
556 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
557 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
558 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
559 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
560 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
561 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
562 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
563 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
564 +
565 +        currentObject.at(0) = toupper(currentObject.at(0));
566 +        string histoName = "num" + currentObject;
567 +
568 +        if(histoName == "numPrimaryvertexs"){
569 +          string newHistoName = histoName + "BeforePileupCorrection";
570 +          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);
571 +          newHistoName = histoName + "AfterPileupCorrection";
572 +          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);
573 +        }
574 +        else
575 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
576 +      }
577 +    }//end of loop over directories
578      channels.push_back(tempChannel);
579      tempChannel.cuts.clear();
415
580    }//end loop over channels
581  
582  
# Line 424 | Line 588 | OSUAnalysis::OSUAnalysis (const edm::Par
588    objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
589  
590  
591 < }
591 > } // end constructor OSUAnalysis::OSUAnalysis()
592 >
593  
594   OSUAnalysis::~OSUAnalysis ()
595   {
596 +
597    // Destroying the CutFlow objects causes the cut flow numbers and time
598    // information to be printed to standard output.
599    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
# Line 441 | Line 607 | OSUAnalysis::analyze (const edm::Event &
607  
608    // Retrieve necessary collections from the event.
609  
610 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
610 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
611      event.getByLabel (triggers_, triggers);
612  
613 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
613 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
614 >    event.getByLabel (trigobjs_, trigobjs);
615 >
616 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
617      event.getByLabel (jets_, jets);
618  
619 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
619 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
620      event.getByLabel (muons_, muons);
621  
622 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
622 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
623      event.getByLabel (electrons_, electrons);
624  
625 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
625 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
626      event.getByLabel (events_, events);
627  
628 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
628 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
629      event.getByLabel (taus_, taus);
630  
631 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
631 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
632      event.getByLabel (mets_, mets);
633  
634 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
634 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
635      event.getByLabel (tracks_, tracks);
636  
637 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
637 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
638      event.getByLabel (genjets_, genjets);
639  
640 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
640 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
641      event.getByLabel (mcparticles_, mcparticles);
642  
643 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
643 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
644      event.getByLabel (primaryvertexs_, primaryvertexs);
645  
646 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
646 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
647      event.getByLabel (bxlumis_, bxlumis);
648  
649 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
649 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
650      event.getByLabel (photons_, photons);
651  
652 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
652 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
653      event.getByLabel (superclusters_, superclusters);
654  
655 <  if (useTrackCaloRhoCorr_) {  
656 <    // Used only for pile-up correction of by-hand calculation of isolation energy.  
657 <    // This rho collection is not available in all BEANs.  
655 >  if (datasetType_ == "signalMC"){
656 >    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
657 >      event.getByLabel (stops_, stops);
658 >  }
659 >
660 >  if (useTrackCaloRhoCorr_) {
661 >    // Used only for pile-up correction of by-hand calculation of isolation energy.
662 >    // This rho collection is not available in all BEANs.
663      // For description of rho values for different jet reconstruction algorithms, see
664 <    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms  
665 <    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
664 >    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
665 >    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
666    }
667  
668 +  double masterScaleFactor = 1.0;
669  
670    //get pile-up event weight
671 <  double scaleFactor = 1.00;
672 <  if(doPileupReweighting_ && datasetType_ != "data")
673 <    scaleFactor = puWeight_->at (events->at (0).numTruePV);
671 >  if (doPileupReweighting_ && datasetType_ != "data") {
672 >    //for "data" datasets, the numTruePV is always set to -1
673 >    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
674 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
675 >  }
676  
677 +  stopCTauScaleFactor_ = 1.0;
678 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
679 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
680 +  masterScaleFactor *= stopCTauScaleFactor_;
681  
682    //loop over all channels
683  
# Line 507 | Line 688 | OSUAnalysis::analyze (const edm::Event &
688      counterMap passingCounter;
689      cumulativeFlags.clear ();
690  
691 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
692 +         iter != BNTreeBranchVals_.end(); iter++) {
693 +      iter->second.clear();  // clear array
694 +    }
695 +
696      bool triggerDecision = true;
697 <    if(currentChannel.triggers.size() != 0){  //triggers specified
698 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
697 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
698 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
699        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
700      }
701  
702      //loop over all cuts
517
518
519
703      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
704        cut currentCut = currentChannel.cuts.at(currentCutIndex);
522
705        for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
706          string currentObject = objectsToCut.at(currentObjectIndex);
707  
# Line 534 | Line 716 | OSUAnalysis::analyze (const edm::Event &
716          int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
717  
718  
719 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
720 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
719 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
720 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
721 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
722 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
723 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
724          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
725          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
726          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 547 | Line 732 | OSUAnalysis::analyze (const edm::Event &
732          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
733          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
734          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
735 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
736 +
737  
738  
739          else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
740                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
741                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
742                                                                     "muon-muon pairs");
743 +
744 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
745 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
746 +                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
747 +                                                                             "muon-secondary muon pairs");
748 +
749 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
750 +                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
751 +                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
752 +                                                                                     "electron-secondary electron pairs");
753 +
754          else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
755                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
756                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
# Line 561 | Line 759 | OSUAnalysis::analyze (const edm::Event &
759                                                                         cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
760                                                                         cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
761                                                                         "electron-muon pairs");
762 <        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
763 <                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
764 <                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
765 <                                                                     "track-event pairs");
766 <        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
767 <                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
768 <                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
769 <                                                                        "electron-track pairs");
770 <        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
771 <                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
772 <                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
773 <                                                                    "muon-track pairs");
774 <        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
775 <                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
776 <                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
777 <                                                                  "muon-tau pairs");
778 <        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),taus.product(),
779 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
780 <                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
781 <                                                                 "tau-tau pairs");
782 <        
783 <        
762 >        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
763 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
764 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
765 >                                                                 "jet-jet pairs");
766 >        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
767 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
768 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
769 >                                                                      "electron-jet pairs");
770 >        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
771 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
772 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
773 >                                                                  "muon-jet pairs");
774 >        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
775 >                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
776 >                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
777 >                                                                     "track-event pairs");
778 >        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
779 >                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
780 >                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
781 >                                                                        "electron-track pairs");
782 >        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
783 >                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
784 >                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
785 >                                                                    "muon-track pairs");
786 >        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
787 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
788 >                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
789 >                                                                  "muon-tau pairs");
790 >        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
791 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
792 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
793 >                                                                 "tau-tau pairs");
794 >        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
795 >                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
796 >                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
797 >                                                                   "tau-track pairs");
798 >        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
799 >                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
800 >                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
801 >                                                                          "electron-trigobj pairs");
802 >        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
803 >                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
804 >                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
805 >                                                                      "muon-trigobj pairs");
806 >
807 >        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
808        }
809  
810  
811  
812      }//end loop over all cuts
591
592
813      //use cumulative flags to apply cuts at event level
814  
815      bool eventPassedAllCuts = true;
816 <
816 >    //a vector to store cumulative cut descisions after each cut.
817 >    vector<bool> eventPassedPreviousCuts;
818      //apply trigger (true if none were specified)
819      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
820  
600
601
821      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
822  
823        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 606 | Line 825 | OSUAnalysis::analyze (const edm::Event &
825        int numberPassing = 0;
826  
827        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
828 <        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
828 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
829        }
611
830        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
831        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
614
832        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
833 <
833 >      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
834      }
835 +    double scaleFactor = masterScaleFactor;
836  
837 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
838 +    if(applyLeptonSF_ && datasetType_ != "data"){
839 +      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
840 +        vector<bool> muonFlags;
841 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
842 +          if (cumulativeFlags.at("muons").at(i).size()){
843 +            muonFlags = cumulativeFlags.at("muons").at(i);
844 +            break;
845 +          }
846 +        }
847 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
848 +          if(!muonFlags.at(muonIndex)) continue;
849 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
850 +        }
851 +      }
852 +      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
853 +        vector<bool> electronFlags;
854 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
855 +          if (cumulativeFlags.at("electrons").at(i).size()){
856 +            electronFlags = cumulativeFlags.at("electrons").at(i);
857 +            break;
858 +          }
859 +        }
860 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
861 +          if(!electronFlags.at(electronIndex)) continue;
862 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
863 +        }
864 +      }
865 +    }
866 +    if(applyBtagSF_ && datasetType_ != "data"){
867 +     if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
868 +        vector<bool> jetFlags;
869 +        vector<double> jetSFs;
870 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
871 +          if (cumulativeFlags.at("jets").at(i).size()){
872 +            jetFlags = cumulativeFlags.at("jets").at(i);
873 +            break;
874 +          }
875 +        }
876 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
877 +          if(!jetFlags.at(jetIndex)) continue;
878 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt);
879 +          jetSFs.push_back(jetSFTmp);
880 +        }
881 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_, maxBtag_ );
882 +      }
883 +    }
884 +    scaleFactor *= muonScaleFactor_;
885 +    scaleFactor *= electronScaleFactor_;
886 +    scaleFactor *= bTagScaleFactor_;
887      cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
888  
889 +    if (printEventInfo_) {
890 +      // Write information about event to screen, for testing purposes.
891 +      cout << "Event passed all cuts in channel " <<  currentChannel.name
892 +           << ": run="  << events->at(0).run
893 +           << "  lumi=" << events->at(0).lumi
894 +           << "  event=" << events->at(0).evt
895 +           << endl;
896 +    }
897  
898  
899 <    if(!eventPassedAllCuts)continue;
899 >    //filling histograms
900 >    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
901 >      uint currentDir;
902 >      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
903 >      else{
904 >        currentDir = currentCut;
905 >      }
906  
625    if (printEventInfo_) {
626      // Write information about event to screen, for testing purposes.  
627      cout << "Event passed all cuts in channel " <<  currentChannel.name
628           << ": run="  << events->at(0).run
629           << "  lumi=" << events->at(0).lumi
630           << "  event=" << events->at(0).evt
631           << endl;  
632    }
907  
908 +      if(eventPassedPreviousCuts.at(currentDir)){
909  
910 <    //     if(datasetType_ != "data") {
911 <    //       scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
637 <    //       scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
638 <    //     }
910 >        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
911 >          histogram currentHistogram = histograms.at(histogramIndex);
912  
913 <    //filling histograms
641 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
642 <      histogram currentHistogram = histograms.at(histogramIndex);
913 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) cout << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
914  
915 <      if(currentHistogram.inputVariables.size() == 1){
916 <        TH1D* histo;
917 <        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
918 <
919 <
920 <
921 <        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
922 <        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
923 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
924 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
925 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
926 <        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
927 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
928 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
929 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
930 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
931 <                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
932 <                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
933 <        else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),        
934 <                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),  
935 <                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);      
936 <        else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),        
937 <                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),  
938 <                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);      
939 <        else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),    
940 <                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),      
941 <                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);  
942 <        else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),      
943 <                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),        
944 <                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);    
945 <        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
946 <        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
947 <        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
948 <        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
949 <        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
950 <        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
951 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
952 <        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
953 <        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
954 <        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
955 <      }
956 <      else if(currentHistogram.inputVariables.size() == 2){
957 <        TH2D* histo;
958 <        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
959 <
960 <
961 <
962 <        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
963 <        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
964 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
965 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
966 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
967 <        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
968 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
969 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
970 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
971 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
972 <                                                                                           cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
973 <                                                                                           cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
974 <        else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),        
975 <                                                                                            cumulativeFlags.at("electrons").back(),cumulativeFlags.at("tracks").back(),          
976 <                                                                                            cumulativeFlags.at("electron-track pairs").back(),scaleFactor);      
977 <        else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),        
978 <                                                                                        cumulativeFlags.at("muons").back(),cumulativeFlags.at("tracks").back(),          
979 <                                                                                        cumulativeFlags.at("muon-track pairs").back(),scaleFactor);      
980 <        else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),    
981 <                                                                                      cumulativeFlags.at("muons").back(),cumulativeFlags.at("taus").back(),      
982 <                                                                                      cumulativeFlags.at("muon-tau pairs").back(),scaleFactor);  
983 <        else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),      
984 <                                                                                     cumulativeFlags.at("taus").back(),cumulativeFlags.at("taus").back(),        
985 <                                                                                     cumulativeFlags.at("tau-tau pairs").back(),scaleFactor);    
986 <        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
987 <        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
988 <        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
989 <        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
990 <        else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
991 <                                                                                         cumulativeFlags.at("tracks").back(),cumulativeFlags.at("events").back(),
992 <                                                                                         cumulativeFlags.at("track-event pairs").back(),scaleFactor);  
993 <        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
994 <        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
995 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
996 <        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
997 <        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
998 <        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
999 <      }
1000 <    }
1001 <
1002 <    //fills histograms with the sizes of collections
1003 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1004 <
1005 <      string currentObject = objectsToPlot.at(currentObjectIndex);
1006 <
1007 <      string objectToPlot = "";  
1008 <
1009 <      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().  
1010 <      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
1011 <      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
1012 <      else if(currentObject == "electron-muon pairs")     objectToPlot = "electronMuonPairs";
1013 <      else if(currentObject == "electron-track pairs")    objectToPlot = "electronTrackPairs";
1014 <      else if(currentObject == "muon-track pairs")        objectToPlot = "muonTrackPairs";      
1015 <      else if(currentObject == "muon-tau pairs")          objectToPlot = "muonTauPairs";        
1016 <      else if(currentObject == "tau-tau pairs")           objectToPlot = "ditauPairs";
1017 <      else if(currentObject == "track-event pairs")       objectToPlot = "trackEventPairs";  
1018 <      else objectToPlot = currentObject;
1019 <      string tempCurrentObject = objectToPlot;
1020 <      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));  
1021 <      string histoName = "num" + tempCurrentObject;
1022 <
1023 <
1024 <      //set position of primary vertex in event, in order to calculate quantities relative to it
1025 <      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1026 <        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
1027 <        int numToPlot = 0;
1028 <        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1029 <          if(lastCutFlags.at(currentFlag)) numToPlot++;
1030 <        }
1031 <        if(objectToPlot == "primaryvertexs"){
1032 <          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1033 <          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1034 <        }
1035 <        else {
1036 <          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
1037 <        }
1038 <      }
1039 <      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
1040 <      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
1041 <      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
1042 <      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
1043 <      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
1044 <      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
1045 <      else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
1046 <      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
1047 <      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
1048 <      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
1049 <      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
1050 <      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
1051 <      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
1052 <      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
1053 <      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
1054 <      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
784 <      else if(objectToPlot == "primaryvertexs"){
785 <        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
786 <        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
787 <      }
915 >          if(currentHistogram.inputVariables.size() == 1){
916 >            TH1D* histo;
917 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
918 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
919 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
920 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
921 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
922 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
923 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
924 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
925 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
926 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
927 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
928 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
929 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
930 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
931 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
932 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
933 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
934 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
935 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
936 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
937 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
938 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
939 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
940 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
941 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
942 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
943 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
944 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
945 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
946 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
947 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
948 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
949 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
950 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
951 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
952 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
953 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
954 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
955 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
956 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
957 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
958 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
959 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
960 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
961 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
962 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
963 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
964 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
965 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
966 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
967 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
968 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
969 >
970 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
971 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
972 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
973 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
974 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
975 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
976 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
977 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
978 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
979 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
980 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
981 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
982 >          }
983 >          else if(currentHistogram.inputVariables.size() == 2){
984 >            TH2D* histo;
985 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
986 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
987 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
988 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
989 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
990 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
991 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
992 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
993 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
994 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
995 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
996 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
997 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
998 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
999 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1000 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1001 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1002 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1003 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1004 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1005 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1006 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1007 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1008 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1009 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1010 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1011 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1012 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1013 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1014 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1015 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1016 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1017 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1018 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1019 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1020 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1021 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1022 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1023 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1024 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1025 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1026 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1027 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1028 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1029 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1030 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1031 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1032 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1033 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1034 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1035 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1036 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1037 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1038 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1039 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1040 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1041 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1042 >                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1043 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1044 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1045 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1046 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1047 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1048 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1049 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1050 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1051 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1052 >          }
1053 >
1054 >        }
1055  
789    } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1056  
1057 <  } //end loop over channel
1057 >        //fills histograms with the sizes of collections
1058 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1059 >
1060 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1061 >          string objectToPlot = "";
1062 >
1063 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1064 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1065 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1066 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1067 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1068 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1069 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1070 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1071 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1072 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1073 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1074 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1075 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1076 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1077 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1078 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1079 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1080 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1081 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1082 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1083 >          else objectToPlot = currentObject;
1084 >
1085 >          string tempCurrentObject = objectToPlot;
1086 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1087 >          string histoName = "num" + tempCurrentObject;
1088 >
1089 >          //set position of primary vertex in event, in order to calculate quantities relative to it
1090 >          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1091 >            vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1092 >            int numToPlot = 0;
1093 >            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1094 >              if(lastCutFlags.at(currentFlag)) numToPlot++;
1095 >            }
1096 >            if(objectToPlot == "primaryvertexs"){
1097 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1098 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1099 >            }
1100 >            else {
1101 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1102 >            }
1103 >          }
1104 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1105 >
1106 >
1107 >      } // end if(eventPassedPreviousCuts.at(currentDir))
1108 >    } // end loop over cuts
1109 >
1110 >    if (eventPassedAllCuts){
1111 >      // Assign BNTree variables
1112 >      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1113 >        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1114 >        string coll = brSpecs.inputCollection;
1115 >        if (cumulativeFlags.count(coll) == 0) cout << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1116 >
1117 >        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1118 >        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1119 >        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1120 >        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1121 >        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1122 >        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1123 >        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1124 >        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1125 >        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1126 >        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1127 >        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1128 >        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1129 >        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1130 >        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1131 >        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1132 >        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1133 >        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1134 >        else if(coll == "stops"
1135 >                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1136 >      } // end loop over branches
1137 >
1138 >      if (!BNTrees_.at(currentChannelIndex)) { cout << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1139 >      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1140 >    }
1141 >
1142 >  } // end loop over channel
1143 >
1144 >
1145 >  masterCutFlow_->fillCutFlow(masterScaleFactor);
1146  
793  masterCutFlow_->fillCutFlow(scaleFactor);
1147  
1148   } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1149  
# Line 807 | Line 1160 | OSUAnalysis::evaluateComparison (double
1160    else if(comparison == "==") return testValue == cutValue;
1161    else if(comparison == "=") return testValue == cutValue;
1162    else if(comparison == "!=") return testValue != cutValue;
1163 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1163 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1164  
1165   }
1166  
1167   bool
1168 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1168 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1169  
1170 +
1171 +  if(comparison == ">")       return testValue >  cutValue;
1172 +  else if(comparison == ">=") return testValue >= cutValue;
1173 +  else if(comparison == "<")  return testValue <  cutValue;
1174 +  else if(comparison == "<=") return testValue <= cutValue;
1175 +  else if(comparison == "==") return testValue == cutValue;
1176 +  else if(comparison == "=") return testValue == cutValue;
1177 +  else if(comparison == "!=") return testValue != cutValue;
1178 +  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1179 +
1180 + }
1181 +
1182 + bool
1183 + OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1184 +
1185 +  //initialize to false until a chosen trigger is passed
1186    bool triggerDecision = false;
1187  
1188 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1189 <    {
1190 <      if(trigger->pass != 1) continue;
1191 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1192 <        {
1193 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1194 <            triggerDecision = true;
1195 <          }
1196 <        }
1188 >  if (printAllTriggers_) cout << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1189 >  //loop over all triggers defined in the event
1190 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1191 >
1192 >    if (printAllTriggers_) cout << "   " << trigger->name << endl;
1193 >
1194 >    //we're only interested in triggers that actually passed
1195 >    if(trigger->pass != 1) continue;
1196 >
1197 >    //if the event passes one of the veto triggers, exit and return false
1198 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1199 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1200      }
1201 <  return triggerDecision;
1201 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1202 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1203 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1204 >    }
1205 >  }
1206  
1207 +  printAllTriggers_ = false;  // only print triggers once, not every event
1208 +
1209 +  //if none of the veto triggers fired:
1210 +  //return the OR of all the chosen triggers
1211 +  if (triggersToTest.size() != 0) return triggerDecision;
1212 +  //or if no triggers were defined return true
1213 +  else return true;
1214   }
1215  
1216 < std::vector<std::string>
1216 >
1217 > vector<string>
1218   OSUAnalysis::splitString (string inputString){
1219  
1220 <  std::stringstream stringStream(inputString);
1221 <  std::istream_iterator<std::string> begin(stringStream);
1222 <  std::istream_iterator<std::string> end;
1223 <  std::vector<std::string> stringVector(begin, end);
1220 >  stringstream stringStream(inputString);
1221 >  istream_iterator<string> begin(stringStream);
1222 >  istream_iterator<string> end;
1223 >  vector<string> stringVector(begin, end);
1224    return stringVector;
1225  
1226   }
1227  
1228 +
1229 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1230 +  // Set two object strings from the tempInputCollection string,
1231 +  // For example, if tempInputCollection is "electron-muon pairs",
1232 +  // then obj1 = "electrons" and obj2 = "muons".
1233 +  // Note that the objects have an "s" appended.
1234 +
1235 +  int dashIndex = tempInputCollection.find("-");
1236 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1237 +  int secondWordLength = spaceIndex - dashIndex;
1238 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1239 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1240 +
1241 + }
1242 +
1243 +
1244 + string OSUAnalysis::getObjToGet(string obj) {
1245 +  // Return the string corresponding to the object to get for the given obj string.
1246 +  // Right now this only handles the case in which obj contains "secondary",
1247 +  // e.g, "secondary muons".
1248 +  // Note that "s" is NOT appended.
1249 +
1250 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1251 +  int firstSpaceIndex = obj.find_first_of(" ");
1252 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1253 +
1254 + }
1255 +
1256 +
1257 + //!jet valueLookup
1258   double
1259 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1259 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1260  
1261    double value = 0.0;
1262    if(variable == "energy") value = object->energy;
# Line 962 | Line 1376 | OSUAnalysis::valueLookup (const BNjet* o
1376    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1377  
1378  
1379 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1379 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1380  
1381    value = applyFunction(function, value);
1382  
# Line 970 | Line 1384 | OSUAnalysis::valueLookup (const BNjet* o
1384   }
1385  
1386  
1387 <
1387 > //!muon valueLookup
1388   double
1389 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1389 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1390  
1391    double value = 0.0;
1392    if(variable == "energy") value = object->energy;
# Line 1133 | Line 1547 | OSUAnalysis::valueLookup (const BNmuon*
1547    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1548    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1549    else if(variable == "metMT") {
1550 <    const BNmet *met = chosenMET ();
1137 <    if (met)
1550 >    if (const BNmet *met = chosenMET ())
1551        {
1552 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1553 <          p2 (met->px, met->py, 0.0, met->pt);
1141 <
1142 <        value = (p1 + p2).Mt ();
1552 >        double dPhi = deltaPhi (object->phi, met->phi);
1553 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1554        }
1555      else
1556        value = -999;
# Line 1257 | Line 1668 | OSUAnalysis::valueLookup (const BNmuon*
1668      value = object->isGlobalMuon > 0                \
1669        && object->isPFMuon > 0                        \
1670        && object->normalizedChi2 < 10                \
1671 <                                  && object->numberOfValidMuonHits > 0        \
1671 >      && object->numberOfValidMuonHits > 0        \
1672        && object->numberOfMatchedStations > 1        \
1673        && fabs(object->correctedD0Vertex) < 0.2        \
1674        && fabs(object->correctedDZ) < 0.5        \
# Line 1266 | Line 1677 | OSUAnalysis::valueLookup (const BNmuon*
1677    }
1678    else if(variable == "tightIDdisplaced"){
1679      value = object->isGlobalMuon > 0                \
1680 +      && object->isPFMuon > 0                        \
1681        && object->normalizedChi2 < 10                \
1682 <                                  && object->numberOfValidMuonHits > 0        \
1682 >      && object->numberOfValidMuonHits > 0        \
1683        && object->numberOfMatchedStations > 1        \
1684        && object->numberOfValidPixelHits > 0        \
1685        && object->numberOfLayersWithMeasurement > 5;
1686    }
1687  
1688 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1688 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1689  
1690    else if(variable == "genMatchedPdgId"){
1691      int index = getGenMatchedParticleIndex(object);
# Line 1293 | Line 1705 | OSUAnalysis::valueLookup (const BNmuon*
1705    }
1706    else if(variable == "genMatchedMotherIdReverse"){
1707      int index = getGenMatchedParticleIndex(object);
1708 <    if(index == -1) value = 23;
1709 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
1708 >    if(index == -1) value = 24;
1709 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1710    }
1711    else if(variable == "genMatchedGrandmotherId"){
1712      int index = getGenMatchedParticleIndex(object);
# Line 1306 | Line 1718 | OSUAnalysis::valueLookup (const BNmuon*
1718      }
1719      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1720    }
1721 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1722 +    int index = getGenMatchedParticleIndex(object);
1723 +    if(index == -1) value = 24;
1724 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1725 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1726 +      if(motherIndex == -1) value = 24;
1727 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1728 +    }
1729 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1730 +  }
1731 +  else if(variable == "pfMuonsFromVertex"){
1732 +    double d0Error, dzError;
1733  
1734 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1735 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1736 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1737 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1738 +      || fabs (object->correctedDZ / dzError) > 99.0;
1739 +    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1740 +  }
1741  
1742  
1743 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1743 >
1744 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1745  
1746    value = applyFunction(function, value);
1747  
1748    return value;
1749   }
1750  
1751 <
1751 > //!electron valueLookup
1752   double
1753 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1753 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1754  
1755    double value = 0.0;
1756    if(variable == "energy") value = object->energy;
# Line 1484 | Line 1916 | OSUAnalysis::valueLookup (const BNelectr
1916    else if(variable == "detIso") value = (object->trackIso) / object->pt;
1917    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1918    else if(variable == "metMT") {
1919 <    const BNmet *met = chosenMET ();
1488 <    if (met)
1919 >    if (const BNmet *met = chosenMET ())
1920        {
1921 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1922 <          p2 (met->px, met->py, 0.0, met->pt);
1492 <
1493 <        value = (p1 + p2).Mt ();
1921 >        double dPhi = deltaPhi (object->phi, met->phi);
1922 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1923        }
1924      else
1925        value = -999;
# Line 1655 | Line 2084 | OSUAnalysis::valueLookup (const BNelectr
2084    }
2085  
2086  
2087 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2087 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2088  
2089    else if(variable == "genMatchedPdgId"){
2090      int index = getGenMatchedParticleIndex(object);
# Line 1676 | Line 2105 | OSUAnalysis::valueLookup (const BNelectr
2105    }
2106    else if(variable == "genMatchedMotherIdReverse"){
2107      int index = getGenMatchedParticleIndex(object);
2108 <    if(index == -1) value = 23;
2109 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2108 >    if(index == -1) value = 24;
2109 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2110    }
2111    else if(variable == "genMatchedGrandmotherId"){
2112      int index = getGenMatchedParticleIndex(object);
# Line 1689 | Line 2118 | OSUAnalysis::valueLookup (const BNelectr
2118      }
2119      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2120    }
2121 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2122 +    int index = getGenMatchedParticleIndex(object);
2123 +    if(index == -1) value = 24;
2124 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2125 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2126 +      if(motherIndex == -1) value = 24;
2127 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2128 +    }
2129 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2130 +  }
2131 +  else if(variable == "pfElectronsFromVertex"){
2132 +    double d0Error, dzError;
2133  
2134 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2135 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2136 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2137 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2138 +      || fabs (object->correctedDZ / dzError) > 99.0;
2139 +    value = !value;
2140 +  }
2141  
2142  
2143 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2143 >
2144 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2145  
2146    value = applyFunction(function, value);
2147  
2148    return value;
2149   }
2150  
2151 <
2151 > //!event valueLookup
2152   double
2153 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2153 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2154  
2155    double value = 0.0;
2156  
# Line 1770 | Line 2219 | OSUAnalysis::valueLookup (const BNevent*
2219    else if(variable == "id2") value = object->id2;
2220    else if(variable == "evt") value = object->evt;
2221    else if(variable == "puScaleFactor"){
2222 <    if(datasetType_ != "data")
2222 >    if(doPileupReweighting_ && datasetType_ != "data")
2223        value = puWeight_->at (events->at (0).numTruePV);
2224      else
2225        value = 1.0;
2226    }
2227 <  else if(variable == "muonScaleFactor"){
2228 <    if(datasetType_ != "data")
2229 <      //      value = muonSFWeight_->at (chosenMuon ()->eta);
2230 <      value = 1.0;
2231 <    else
1783 <      value = 1.0;
1784 <  }
1785 <  else if(variable == "electronScaleFactor"){
1786 <    if(datasetType_ != "data")
1787 <      //      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1788 <      value = 1.0;
1789 <    else
1790 <      value = 1.0;
1791 <  }
1792 <
1793 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2227 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2228 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2229 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2230 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2231 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2232  
2233    value = applyFunction(function, value);
2234  
2235    return value;
2236   }
2237  
2238 + //!tau valueLookup
2239   double
2240 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2240 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2241  
2242    double value = 0.0;
2243  
# Line 1844 | Line 2283 | OSUAnalysis::valueLookup (const BNtau* o
2283  
2284  
2285  
2286 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2286 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2287  
2288    else if(variable == "genMatchedPdgId"){
2289      int index = getGenMatchedParticleIndex(object);
# Line 1864 | Line 2303 | OSUAnalysis::valueLookup (const BNtau* o
2303    }
2304    else if(variable == "genMatchedMotherIdReverse"){
2305      int index = getGenMatchedParticleIndex(object);
2306 <    if(index == -1) value = 23;
2307 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2306 >    if(index == -1) value = 24;
2307 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2308    }
2309    else if(variable == "genMatchedGrandmotherId"){
2310      int index = getGenMatchedParticleIndex(object);
# Line 1877 | Line 2316 | OSUAnalysis::valueLookup (const BNtau* o
2316      }
2317      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2318    }
2319 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2320 +    int index = getGenMatchedParticleIndex(object);
2321 +    if(index == -1) value = 24;
2322 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2323 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2324 +      if(motherIndex == -1) value = 24;
2325 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2326 +    }
2327 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2328 +  }
2329  
2330  
2331 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2331 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2332  
2333    value = applyFunction(function, value);
2334  
2335    return value;
2336   }
2337  
2338 + //!met valueLookup
2339   double
2340 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2340 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2341  
2342    double value = 0.0;
2343  
# Line 1951 | Line 2401 | OSUAnalysis::valueLookup (const BNmet* o
2401    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2402    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2403  
2404 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2404 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2405  
2406    value = applyFunction(function, value);
2407  
2408    return value;
2409   }
2410  
2411 + //!track valueLookup
2412   double
2413 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2413 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2414  
2415    double value = 0.0;
2416    double pMag = sqrt(object->pt * object->pt +
2417 <                     object->pz * object->pz);
2418 <  
2417 >                     object->pz * object->pz);
2418 >
2419    if(variable == "pt") value = object->pt;
2420    else if(variable == "px") value = object->px;
2421    else if(variable == "py") value = object->py;
# Line 1985 | Line 2436 | OSUAnalysis::valueLookup (const BNtrack*
2436  
2437  
2438    //additional BNs info for disappTrks
1988  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2439    else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2440    else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2441    else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2442    else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2443    else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2444    else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2445 +  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2446    else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2447    else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2448    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2449 <  
2449 >  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2450  
2451    //user defined variables
2452    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;
2453    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2454 +  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2455    else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2456    else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2457 <  else if(variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object);  
2458 <  else if(variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object) / pMag;  
2457 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2458 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2459    else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2460    else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2461    else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2462    else if(variable == "ptError")                    value = object->ptError;
2463    else if(variable == "ptRes")                      value = getTrkPtRes(object);
2464 <  else if (variable == "d0wrtPV"){      
2465 <    double vx = object->vx - chosenVertex ()->x,        
2466 <      vy = object->vy - chosenVertex ()->y,      
2467 <      px = object->px,  
2468 <      py = object->py,  
2469 <      pt = object->pt;  
2470 <    value = (-vx * py + vy * px) / pt;  
2471 <  }      
2472 <  else if (variable == "dZwrtPV"){      
2473 <    double vx = object->vx - chosenVertex ()->x,        
2474 <      vy = object->vy - chosenVertex ()->y,      
2475 <      vz = object->vz - chosenVertex ()->z,      
2476 <      px = object->px,  
2477 <      py = object->py,  
2478 <      pz = object->pz,  
2479 <      pt = object->pt;  
2480 <    value = vz - (vx * px + vy * py)/pt * (pz/pt);      
2481 <  }    
2482 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2464 >  else if (variable == "d0wrtPV"){
2465 >    double vx = object->vx - chosenVertex ()->x,
2466 >      vy = object->vy - chosenVertex ()->y,
2467 >      px = object->px,
2468 >      py = object->py,
2469 >      pt = object->pt;
2470 >    value = (-vx * py + vy * px) / pt;
2471 >  }
2472 >  else if (variable == "dZwrtPV"){
2473 >    double vx = object->vx - chosenVertex ()->x,
2474 >      vy = object->vy - chosenVertex ()->y,
2475 >      vz = object->vz - chosenVertex ()->z,
2476 >      px = object->px,
2477 >      py = object->py,
2478 >      pz = object->pz,
2479 >      pt = object->pt;
2480 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2481 >  }
2482 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2483  
2484    else if(variable == "genMatchedPdgId"){
2485      int index = getGenMatchedParticleIndex(object);
# Line 2048 | Line 2500 | OSUAnalysis::valueLookup (const BNtrack*
2500    }
2501    else if(variable == "genMatchedMotherIdReverse"){
2502      int index = getGenMatchedParticleIndex(object);
2503 <    if(index == -1) value = 23;
2504 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2503 >    if(index == -1) value = 24;
2504 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2505    }
2506    else if(variable == "genMatchedGrandmotherId"){
2507      int index = getGenMatchedParticleIndex(object);
# Line 2061 | Line 2513 | OSUAnalysis::valueLookup (const BNtrack*
2513      }
2514      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2515    }
2516 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2517 +    int index = getGenMatchedParticleIndex(object);
2518 +    if(index == -1) value = 24;
2519 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2520 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2521 +      if(motherIndex == -1) value = 24;
2522 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2523 +    }
2524 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2525 +  }
2526  
2527  
2528  
2529 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2529 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2530  
2531    value = applyFunction(function, value);
2532  
2533    return value;
2534   }
2535  
2536 + //!genjet valueLookup
2537   double
2538 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2538 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2539  
2540    double value = 0.0;
2541  
# Line 2092 | Line 2555 | OSUAnalysis::valueLookup (const BNgenjet
2555    else if(variable == "charge") value = object->charge;
2556  
2557  
2558 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2558 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2559  
2560    value = applyFunction(function, value);
2561  
2562    return value;
2563   }
2564  
2565 + //!mcparticle valueLookup
2566   double
2567 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2567 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2568  
2569    double value = 0.0;
2570  
# Line 2225 | Line 2689 | OSUAnalysis::valueLookup (const BNmcpart
2689    }
2690  
2691  
2692 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2692 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2693  
2694    value = applyFunction(function, value);
2695  
2696    return value;
2697   }
2698  
2699 + //!primaryvertex valueLookup
2700   double
2701 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2701 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2702  
2703    double value = 0.0;
2704  
# Line 2252 | Line 2717 | OSUAnalysis::valueLookup (const BNprimar
2717    else if(variable == "isGood") value = object->isGood;
2718  
2719  
2720 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2720 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2721  
2722    value = applyFunction(function, value);
2723  
2724    return value;
2725   }
2726  
2727 + //!bxlumi valueLookup
2728   double
2729 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2729 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2730  
2731    double value = 0.0;
2732  
# Line 2269 | Line 2735 | OSUAnalysis::valueLookup (const BNbxlumi
2735    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2736  
2737  
2738 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2738 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2739  
2740    value = applyFunction(function, value);
2741  
2742    return value;
2743   }
2744  
2745 + //!photon valueLookup
2746   double
2747 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2747 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2748  
2749    double value = 0.0;
2750  
# Line 2352 | Line 2819 | OSUAnalysis::valueLookup (const BNphoton
2819    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2820  
2821  
2355
2822  
2823 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2823 >
2824 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2825  
2826    else if(variable == "genMatchedPdgId"){
2827      int index = getGenMatchedParticleIndex(object);
# Line 2376 | Line 2843 | OSUAnalysis::valueLookup (const BNphoton
2843    }
2844    else if(variable == "genMatchedMotherIdReverse"){
2845      int index = getGenMatchedParticleIndex(object);
2846 <    if(index == -1) value = 23;
2847 <    else value = 23 -getPdgIdBinValue(mcparticles->at(index).motherId);
2846 >    if(index == -1) value = 24;
2847 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2848    }
2849    else if(variable == "genMatchedGrandmotherId"){
2850      int index = getGenMatchedParticleIndex(object);
# Line 2389 | Line 2856 | OSUAnalysis::valueLookup (const BNphoton
2856      }
2857      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2858    }
2859 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2860 +    int index = getGenMatchedParticleIndex(object);
2861 +    if(index == -1) value = 24;
2862 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2863 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2864 +      if(motherIndex == -1) value = 24;
2865 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2866 +    }
2867 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2868 +  }
2869  
2870  
2871 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2871 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2872  
2873    value = applyFunction(function, value);
2874  
2875    return value;
2876   }
2877  
2878 + //!supercluster valueLookup
2879   double
2880 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
2880 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
2881  
2882    double value = 0.0;
2883  
# Line 2413 | Line 2891 | OSUAnalysis::valueLookup (const BNsuperc
2891    else if(variable == "theta") value = object->theta;
2892  
2893  
2894 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2894 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2895  
2896    value = applyFunction(function, value);
2897  
2898    return value;
2899   }
2900  
2901 + //!trigobj valueLookup
2902 + double
2903 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
2904 +
2905 +  double value = 0.0;
2906  
2907 +  if(variable == "pt") value = object->pt;
2908 +  else if(variable == "eta") value = object->eta;
2909 +  else if(variable == "phi") value = object->phi;
2910 +  else if(variable == "px") value = object->px;
2911 +  else if(variable == "py") value = object->py;
2912 +  else if(variable == "pz") value = object->pz;
2913 +  else if(variable == "et") value = object->et;
2914 +  else if(variable == "energy") value = object->energy;
2915 +  else if(variable == "etTotal") value = object->etTotal;
2916 +  else if(variable == "id") value = object->id;
2917 +  else if(variable == "charge") value = object->charge;
2918 +  else if(variable == "isIsolated") value = object->isIsolated;
2919 +  else if(variable == "isMip") value = object->isMip;
2920 +  else if(variable == "isForward") value = object->isForward;
2921 +  else if(variable == "isRPC") value = object->isRPC;
2922 +  else if(variable == "bx") value = object->bx;
2923 +  else if(variable == "filter") {
2924 +    if ((stringValue = object->filter) == "")
2925 +      stringValue = "none";  // stringValue should only be empty if value is filled
2926 +  }
2927 +
2928 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2929 +
2930 +  value = applyFunction(function, value);
2931 +
2932 +  return value;
2933 + }
2934 +
2935 + //!muon-muon pair valueLookup
2936   double
2937 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
2937 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
2938  
2939    double value = 0.0;
2940  
2941    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2942 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2943    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2944    else if(variable == "invMass"){
2945      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2483 | Line 2996 | OSUAnalysis::valueLookup (const BNmuon*
2996        value = object2->correctedD0;
2997      }
2998  
2999 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2999 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3000  
3001    value = applyFunction(function, value);
3002  
3003    return value;
3004   }
3005  
3006 + //!electron-electron pair valueLookup
3007   double
3008 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
3008 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3009  
3010    double value = 0.0;
3011  
3012    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3013 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3014    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3015    else if(variable == "invMass"){
3016      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2537 | Line 3052 | OSUAnalysis::valueLookup (const BNelectr
3052      value = object2->correctedD0;
3053    }
3054  
3055 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3055 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3056  
3057    value = applyFunction(function, value);
3058  
3059    return value;
3060   }
3061 <
3061 > //!electron-muon pair valueLookup
3062   double
3063 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3063 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3064  
3065    double value = 0.0;
3066  
3067    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3068 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3069    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3070    else if(variable == "invMass"){
3071      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2596 | Line 3112 | OSUAnalysis::valueLookup (const BNelectr
3112    else if(variable == "muonDetIso"){
3113      value = (object2->trackIsoDR03) / object2->pt;
3114    }
3115 +  else if(variable == "electronRelPFrhoIso"){
3116 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3117 +  }
3118 +  else if(variable == "muonRelPFdBetaIso"){
3119 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3120 +  }
3121 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3122 +  value = applyFunction(function, value);
3123  
3124 +  return value;
3125 + }
3126  
3127 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3127 > //!electron-jet pair valueLookup
3128 > double
3129 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3130 >
3131 >  double value = 0.0;
3132  
3133 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3134 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3135 +  else if(variable == "jetEta") value = object2->eta;
3136 +  else if(variable == "jetPhi") value = object2->phi;
3137 +  else if(variable == "electronEta") value = object1->eta;
3138 +  else if(variable == "electronPhi") value = object1->phi;
3139 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3140 +  else if(variable == "invMass"){
3141 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3142 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3143 +    value = (fourVector1 + fourVector2).M();
3144 +  }
3145 +  else if(variable == "pt"){
3146 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3147 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3148 +    value = (fourVector1 + fourVector2).Pt();
3149 +  }
3150 +  else if(variable == "threeDAngle")
3151 +    {
3152 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3153 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3154 +      value = (threeVector1.Angle(threeVector2));
3155 +    }
3156 +  else if(variable == "chargeProduct"){
3157 +    value = object1->charge*object2->charge;
3158 +  }
3159 +
3160 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3161    value = applyFunction(function, value);
3162  
3163    return value;
3164   }
3165  
3166 + //!muon-jet pair valueLookup
3167 + double
3168 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3169 +
3170 +  double value = 0.0;
3171  
3172 < double  
3173 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function){  
3174 <  double electronMass = 0.000511;        
3175 <  double value = 0.0;    
3176 <  TLorentzVector fourVector1(0, 0, 0, 0);        
3177 <  TLorentzVector fourVector2(0, 0, 0, 0);        
3178 <  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));  
3179 <  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);    
3180 <  else if(variable == "invMass"){        
3181 <    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);    
3182 <    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );    
2620 <        
2621 <    value = (fourVector1 + fourVector2).M();    
3172 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3173 >  else if(variable == "jetEta") value = object2->eta;
3174 >  else if(variable == "jetPhi") value = object2->phi;
3175 >  else if(variable == "muonEta") value = object1->eta;
3176 >  else if(variable == "muonPhi") value = object1->phi;
3177 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3178 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3179 >  else if(variable == "invMass"){
3180 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3181 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3182 >    value = (fourVector1 + fourVector2).M();
3183    }
3184 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}  
3185 <  value = applyFunction(function, value);        
3186 <  return value;  
3184 >  else if(variable == "pt"){
3185 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3186 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3187 >    value = (fourVector1 + fourVector2).Pt();
3188 >  }
3189 >  else if(variable == "threeDAngle")
3190 >    {
3191 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3192 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3193 >      value = (threeVector1.Angle(threeVector2));
3194 >    }
3195 >  else if(variable == "chargeProduct"){
3196 >    value = object1->charge*object2->charge;
3197 >  }
3198 >
3199 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3200 >  value = applyFunction(function, value);
3201 >
3202 >  return value;
3203 > }
3204 >
3205 > //!jet-jet pair valueLookup
3206 > double
3207 > OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3208 >
3209 >  double value = 0.0;
3210 >
3211 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3212 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3213 >  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3214 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3215 >  else if(variable == "invMass"){
3216 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3217 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3218 >    value = (fourVector1 + fourVector2).M();
3219 >  }
3220 >  else if(variable == "pt"){
3221 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3222 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3223 >    value = (fourVector1 + fourVector2).Pt();
3224 >  }
3225 >  else if(variable == "threeDAngle")
3226 >    {
3227 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3228 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3229 >      value = (threeVector1.Angle(threeVector2));
3230 >    }
3231 >  else if(variable == "chargeProduct"){
3232 >    value = object1->charge*object2->charge;
3233 >  }
3234 >
3235 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3236 >  value = applyFunction(function, value);
3237 >
3238 >  return value;
3239   }
3240 + //!electron-track pair valueLookup
3241 + double
3242 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3243 +  double electronMass = 0.000511;
3244 +  double value = 0.0;
3245 +  TLorentzVector fourVector1(0, 0, 0, 0);
3246 +  TLorentzVector fourVector2(0, 0, 0, 0);
3247 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3248 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3249 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3250 +  else if(variable == "invMass"){
3251 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3252 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3253 +
3254 +    value = (fourVector1 + fourVector2).M();
3255 +  }
3256 +  else if(variable == "chargeProduct"){
3257 +    value = object1->charge*object2->charge;
3258 +  }
3259 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3260 +  value = applyFunction(function, value);
3261 +  return value;
3262  
3263 + }
3264  
3265  
3266 + //!muon-track pair valueLookup
3267   double
3268 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function){
3268 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3269    double pionMass = 0.140;
3270    double muonMass = 0.106;
3271    double value = 0.0;
3272    TLorentzVector fourVector1(0, 0, 0, 0);
3273    TLorentzVector fourVector2(0, 0, 0, 0);
3274    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3275 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3276    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3277    else if(variable == "invMass"){
3278      fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
# Line 2642 | Line 3280 | OSUAnalysis::valueLookup (const BNmuon*
3280  
3281      value = (fourVector1 + fourVector2).M();
3282    }
3283 +  else if(variable == "chargeProduct"){
3284 +    value = object1->charge*object2->charge;
3285 +  }
3286  
3287    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3288    value = applyFunction(function, value);
3289    return value;
3290   }
3291  
3292 <
3292 > //!tau-tau pair valueLookup
3293   double
3294 < OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function){
3294 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3295    double value = 0.0;
3296    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3297 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3298    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3299    else if(variable == "invMass"){
3300      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2660 | Line 3302 | OSUAnalysis::valueLookup (const BNtau* o
3302      value = (fourVector1 + fourVector2).M();
3303    }
3304  
3305 +  else if(variable == "chargeProduct"){
3306 +    value = object1->charge*object2->charge;
3307 +  }
3308 +
3309    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3310    value = applyFunction(function, value);
3311    return value;
3312   }
3313  
3314 <
3314 > //!muon-tau pair valueLookup
3315   double
3316 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function){
3316 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3317    double value = 0.0;
3318    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3319 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3320    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3321    else if(variable == "invMass"){
3322      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
# Line 2677 | Line 3324 | OSUAnalysis::valueLookup (const BNmuon*
3324      value = (fourVector1 + fourVector2).M();
3325    }
3326  
3327 +  else if(variable == "chargeProduct"){
3328 +    value = object1->charge*object2->charge;
3329 +  }
3330 +
3331 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3332 +  value = applyFunction(function, value);
3333 +  return value;
3334 + }
3335 +
3336 + //!tau-track pair valueLookup
3337 + double
3338 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3339 +  double value = 0.0;
3340 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3341 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3342 +  else if(variable == "chargeProduct"){
3343 +    value = object1->charge*object2->charge;
3344 +  }
3345 +
3346    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3347    value = applyFunction(function, value);
3348    return value;
3349   }
3350  
3351  
3352 + //!track-event pair valueLookup
3353   double
3354 < OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function){
3354 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3355  
3356    double value = 0.0;
3357    double pMag = sqrt(object1->pt * object1->pt +
3358 <                     object1->pz * object1->pz);  
3358 >                     object1->pz * object1->pz);
3359  
3360    if      (variable == "numPV")                      value = object2->numPV;
3361    else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3362    else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3363 <  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);  
3364 <  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;  
3363 >  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3364 >  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3365  
3366 <  else { std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3366 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3367  
3368    value = applyFunction(function, value);
3369  
3370    return value;
3371  
3372 < }  
3372 > }
3373 >
3374 > //!electron-trigobj pair valueLookup
3375 > double
3376 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3377 >
3378 >  double value = 0.0;
3379 >
3380 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3381 >  else if (variable == "match"){
3382 >    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3383 >      stringValue = object2->filter;
3384 >    else
3385 >      stringValue = "none";
3386 >  }
3387 >
3388 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3389 >
3390 >  value = applyFunction(function, value);
3391 >
3392 >  return value;
3393 >
3394 > }
3395 >
3396 > //!muon-trigobj pair valueLookup
3397 > double
3398 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3399 >
3400 >  double value = 0.0;
3401 >
3402 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3403 >
3404 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3405 >
3406 >  value = applyFunction(function, value);
3407 >
3408 >  return value;
3409 >
3410 > }
3411 >
3412 > //!stop valueLookup
3413 > double
3414 > OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3415 >
3416 >
3417 >  double value = 0.0;
3418 >
3419 >  if(variable == "ctau") value = object->ctau;
3420 >
3421 >  else if (variable == "d0"){
3422 >    double vx = object->vx - chosenVertex ()->x,
3423 >      vy = object->vy - chosenVertex ()->y,
3424 >      px = object->px,
3425 >      py = object->py,
3426 >      pt = object->pt;
3427 >    value = (-vx * py + vy * px) / pt;
3428 >  }
3429 >
3430 >  else if (variable == "dz"){
3431 >    double vx = object->vx - chosenVertex ()->x,
3432 >      vy = object->vy - chosenVertex ()->y,
3433 >      vz = object->vz - chosenVertex ()->z,
3434 >      px = object->px,
3435 >      py = object->py,
3436 >      pz = object->pz,
3437 >      pt = object->pt;
3438 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3439 >  }
3440 >
3441 >  else if (variable == "minD0"){
3442 >    double minD0=999;
3443 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3444 >      double vx = object->vx - vertex->x,
3445 >        vy = object->vy - vertex->y,
3446 >        px = object->px,
3447 >        py = object->py,
3448 >        pt = object->pt;
3449 >      value = (-vx * py + vy * px) / pt;
3450 >      if(abs(value) < abs(minD0)) minD0 = value;
3451 >    }
3452 >    value = minD0;
3453 >  }
3454 >  else if (variable == "minDz"){
3455 >    double minDz=999;
3456 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3457 >      double vx = object->vx - vertex->x,
3458 >        vy = object->vy - vertex->y,
3459 >        vz = object->vz - vertex->z,
3460 >        px = object->px,
3461 >        py = object->py,
3462 >        pz = object->pz,
3463 >        pt = object->pt;
3464 >      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3465 >      if(abs(value) < abs(minDz)) minDz = value;
3466 >    }
3467 >    value = minDz;
3468 >  }
3469 >  else if(variable == "distToVertex"){
3470 >    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3471 >                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3472 >                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3473 >  }
3474 >  else if (variable == "minDistToVertex"){
3475 >    double minDistToVertex=999;
3476 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3477 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3478 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3479 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
3480 >
3481 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3482 >    }
3483 >    value = minDistToVertex;
3484 >  }
3485 >  else if (variable == "distToVertexDifference"){
3486 >    double minDistToVertex=999;
3487 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3488 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3489 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3490 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
3491 >
3492 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3493 >    }
3494 >    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3495 >                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3496 >                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3497 >
3498 >    value = distToChosenVertex - minDistToVertex;
3499 >  }
3500 >
3501 >  else if (variable == "closestVertexRank"){
3502 >    double minDistToVertex=999;
3503 >    int vertex_rank = 0;
3504 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3505 >      vertex_rank++;
3506 >      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3507 >                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
3508 >                      (object->vz-vertex->z)*(object->vz-vertex->z));
3509 >
3510 >      if(abs(dist) < abs(minDistToVertex)){
3511 >        value = vertex_rank;
3512 >        minDistToVertex = dist;
3513 >      }
3514 >    }
3515 >  }
3516 >
3517 >
3518 >
3519 >
3520 >  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3521 >
3522 >  value = applyFunction(function, value);
3523 >
3524 >  return value;
3525 >
3526 > }
3527 >
3528 >
3529 >
3530  
3531   // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3532   // Return true iff no other tracks are found in this cone.
# Line 2751 | Line 3575 | OSUAnalysis::getTrkPtTrue (const BNtrack
3575  
3576   double
3577   OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3578 <  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.  
3579 <  if (!useTrackCaloRhoCorr_) return -99;  
3580 <  // if (!rhokt6CaloJetsHandle_) {
3581 <  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;  
3582 <  //   return -99;  
3578 >  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3579 >  if (!useTrackCaloRhoCorr_) return -99;
3580 >  // if (!rhokt6CaloJetsHandle_) {
3581 >  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3582 >  //   return -99;
3583    // }
3584 <  double radDeltaRCone = 0.5;  
3585 <  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.  
3586 <  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;  
3587 <  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);  
3588 <  return caloTotRhoCorrCalo;  
3589 <
3584 >  double radDeltaRCone = 0.5;
3585 >  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3586 >  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3587 >  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3588 >  return caloTotRhoCorrCalo;
3589 >
3590   }
3591  
3592  
# Line 2800 | Line 3624 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3624    double deltaRLowest = 999;
3625    int value = 0;
3626    if (DeadEcalVec.size() == 0) WriteDeadEcal();
3627 <  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3627 >  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3628      double eta = ecal->etaEcal;
3629      double phi = ecal->phiEcal;
3630 <    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
3630 >    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
3631      if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3632    }
3633    if (deltaRLowest<0.05) {value = 1;}
# Line 2811 | Line 3635 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3635    return value;
3636   }
3637  
3638 < // Returns the smallest DeltaR between the object and any generated true particle in the event.  
3638 > // Returns the smallest DeltaR between the object and any generated true particle in the event.
3639   template <class InputObject>
3640   double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3641    double genDeltaRLowest = 999.;
# Line 2831 | Line 3655 | OSUAnalysis::applyFunction(string functi
3655    else if(function == "log") value = log10(value);
3656  
3657    else if(function == "") value = value;
3658 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
3658 >  else{cout << "WARNING: invalid function '" << function << "'\n";}
3659  
3660    return value;
3661  
# Line 2841 | Line 3665 | OSUAnalysis::applyFunction(string functi
3665   template <class InputCollection>
3666   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
3667  
3668 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
3669 +    string obj1, obj2;
3670 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
3671 +    if (inputType==obj1 ||
3672 +        inputType==obj2) {
3673 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
3674 +      // and the inputType is a member of the pair.
3675 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
3676 +      // For example, if currentCut.inputCollection==electron-muon pairs,
3677 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
3678 +      return;
3679 +    }
3680 +  }
3681  
3682    for (uint object = 0; object != inputCollection->size(); object++){
3683  
2847
3684      bool decision = true;//object passes if this cut doesn't cut on that type of object
3685  
2850
3686      if(currentCut.inputCollection == inputType){
3687  
3688        vector<bool> subcutDecisions;
3689        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3690 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3691 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3690 >        string stringValue = "";
3691 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3692 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3693 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3694 >
3695        }
3696        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3697        else{
# Line 2867 | Line 3705 | void OSUAnalysis::setObjectFlags(cut &cu
3705          decision = tempDecision;
3706        }
3707      }
2870    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3708  
3709 +    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3710  
3711      //set flags for objects that pass each cut AND all the previous cuts
3712      bool previousCumulativeFlag = true;
# Line 2878 | Line 3716 | void OSUAnalysis::setObjectFlags(cut &cu
3716      }
3717      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3718  
2881
3719    }
3720  
3721   }
# Line 2892 | Line 3729 | void OSUAnalysis::setObjectFlags(cut &cu
3729    bool sameObjects = false;
3730    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3731  
3732 +  // Get the strings for the two objects that make up the pair.
3733 +  string obj1Type, obj2Type;
3734 +  getTwoObjs(inputType, obj1Type, obj2Type);
3735 +  bool isTwoTypesOfObject = true;
3736 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
3737 +
3738 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
3739 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
3740 +  if (currentCut.inputCollection == inputType) {
3741 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
3742 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3743 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3744 +    }
3745 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
3746 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
3747 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3748 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3749 +      }
3750 +    }
3751 +  }
3752  
3753    int counter = 0;
3754 +
3755    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3756      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3757  
# Line 2906 | Line 3764 | void OSUAnalysis::setObjectFlags(cut &cu
3764  
3765          vector<bool> subcutDecisions;
3766          for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3767 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3768 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3767 >          string stringValue = "";
3768 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3769 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3770 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3771          }
3772  
3773          if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
# Line 2922 | Line 3782 | void OSUAnalysis::setObjectFlags(cut &cu
3782            decision = tempDecision;
3783          }
3784        }
3785 +      // if (decision) isPassObj1.at(object1) = true;
3786 +      // if (decision) isPassObj2.at(object2) = true;
3787        individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3788 +      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3789 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;
3790 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;
3791 +      }
3792  
3793        //set flags for objects that pass each cut AND all the previous cuts
3794        bool previousCumulativeFlag = true;
# Line 2937 | Line 3803 | void OSUAnalysis::setObjectFlags(cut &cu
3803        else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
3804        else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
3805        cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
3806 <
3806 >      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3807 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);
3808 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);
3809 >      }
3810        counter++;
2942    }
3811  
3812 +    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
3813 +  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
3814 +
3815 + }
3816 +
3817 +
3818 + bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
3819 +  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
3820 +  // all cuts up to currentCutIndex
3821 +  bool previousCumulativeFlag = true;
3822 +  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
3823 +    if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
3824 +    else {
3825 +      previousCumulativeFlag = false; break;
3826 +    }
3827    }
3828 +  return previousCumulativeFlag;
3829 + }
3830 +
3831  
3832  
3833 + template <class InputCollection>
3834 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, vector<bool> flags){
3835 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
3836 +
3837 +  if (BNTreeBranchVals_.count(parameters.name)==0) cout << "Error[assignTreeBranch]:  trying to assign value to " << parameters.name << " that does not have a branch set up.  Will likely seg fault." << endl;
3838 +  for (uint object = 0; object != inputCollection->size(); object++) {
3839 +
3840 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3841 +
3842 +    string inputVariable = parameters.inputVariable;
3843 +    string function = "";
3844 +    string stringValue = "";
3845 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3846 +    BNTreeBranchVals_.at(parameters.name).push_back(value);
3847 +
3848 +  }
3849   }
3850  
3851  
# Line 2957 | Line 3859 | void OSUAnalysis::fill1DHistogram(TH1* h
3859      string currentString = parameters.inputVariables.at(0);
3860      string inputVariable = "";
3861      string function = "";
3862 <    if(currentString.find("(")==std::string::npos){
3862 >    if(currentString.find("(")==string::npos){
3863        inputVariable = currentString;// variable to cut on
3864      }
3865      else{
# Line 2966 | Line 3868 | void OSUAnalysis::fill1DHistogram(TH1* h
3868        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3869      }
3870  
3871 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
3871 >    string stringValue = "";
3872 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3873      histo->Fill(value,scaleFactor);
3874  
3875      if (printEventInfo_) {
3876 <      // Write information about event to screen, for testing purposes.  
3877 <      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;  
3876 >      // Write information about event to screen, for testing purposes.
3877 >      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
3878      }
3879 <    
3879 >
3880    }
3881   }
3882  
# Line 2983 | Line 3886 | void OSUAnalysis::fill1DHistogram(TH1* h
3886    bool sameObjects = false;
3887    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3888  
3889 <  int pairCounter = 0;
3889 >  int pairCounter = -1;
3890    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3891      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3892  
3893        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3894  
3895 +      pairCounter++;
3896        //only take objects which have passed all cuts and pairs which have passed all cuts
3897        if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3898        if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
# Line 2997 | Line 3901 | void OSUAnalysis::fill1DHistogram(TH1* h
3901        string currentString = parameters.inputVariables.at(0);
3902        string inputVariable = "";
3903        string function = "";
3904 <      if(currentString.find("(")==std::string::npos){
3904 >      if(currentString.find("(")==string::npos){
3905          inputVariable = currentString;// variable to cut on
3906        }
3907        else{
# Line 3006 | Line 3910 | void OSUAnalysis::fill1DHistogram(TH1* h
3910          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3911        }
3912  
3913 <      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3913 >      string stringValue = "";
3914 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3915        histo->Fill(value,scaleFactor);
3916  
3012      pairCounter++;
3917      }
3918    }
3919  
# Line 3023 | Line 3927 | void OSUAnalysis::fill2DHistogram(TH2* h
3927  
3928      if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3929  
3930 +    string stringValue = "";
3931      string currentString = parameters.inputVariables.at(0);
3932      string inputVariable = "";
3933      string function = "";
3934 <    if(currentString.find("(")==std::string::npos){
3934 >    if(currentString.find("(")==string::npos){
3935        inputVariable = currentString;// variable to cut on
3936      }
3937      else{
# Line 3034 | Line 3939 | void OSUAnalysis::fill2DHistogram(TH2* h
3939        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3940        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3941      }
3942 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
3942 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3943  
3944      currentString = parameters.inputVariables.at(1);
3945      inputVariable = "";
3946      function = "";
3947 <    if(currentString.find("(")==std::string::npos){
3947 >    if(currentString.find("(")==string::npos){
3948        inputVariable = currentString;// variable to cut on
3949      }
3950      else{
# Line 3048 | Line 3953 | void OSUAnalysis::fill2DHistogram(TH2* h
3953        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3954      }
3955  
3956 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
3956 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3957  
3958      histo->Fill(valueX,valueY,scaleFactor);
3959  
# Line 3062 | Line 3967 | void OSUAnalysis::fill2DHistogram(TH2* h
3967    bool sameObjects = false;
3968    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3969  
3970 <  int pairCounter = 0;
3970 >  int pairCounter = -1;
3971    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3972      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3973  
3974        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3975  
3976 +      pairCounter++;
3977 +
3978        //only take objects which have passed all cuts and pairs which have passed all cuts
3979        if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3980        if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3981        if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3982  
3983 +      string stringValue = "";
3984        string currentString = parameters.inputVariables.at(0);
3985        string inputVariable = "";
3986        string function = "";
3987 <      if(currentString.find("(")==std::string::npos){
3987 >      if(currentString.find("(")==string::npos){
3988          inputVariable = currentString;// variable to cut on
3989        }
3990        else{
# Line 3084 | Line 3992 | void OSUAnalysis::fill2DHistogram(TH2* h
3992          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3993          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3994        }
3995 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3995 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3996  
3997        currentString = parameters.inputVariables.at(1);
3998        inputVariable = "";
3999        function = "";
4000 <      if(currentString.find("(")==std::string::npos){
4000 >      if(currentString.find("(")==string::npos){
4001          inputVariable = currentString;// variable to cut on
4002        }
4003        else{
# Line 3097 | Line 4005 | void OSUAnalysis::fill2DHistogram(TH2* h
4005          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4006          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4007        }
4008 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4008 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4009  
4010  
4011        histo->Fill(valueX,valueY,scaleFactor);
4012  
3105      pairCounter++;
3106
4013      }
4014    }
4015  
# Line 3120 | Line 4026 | int OSUAnalysis::getGenMatchedParticleIn
4026  
4027      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4028      if(currentDeltaR > 0.05) continue;
4029 <    //     cout << std::setprecision(3) << std::setw(20)
4029 >    //     cout << setprecision(3) << setw(20)
4030      //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4031 <    //          << std::setw(20)
4031 >    //          << setw(20)
4032      //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4033 <    //          << std::setw(20)
4033 >    //          << setw(20)
4034      //          << "\tdeltaR = " << currentDeltaR
4035 <    //          << std::setprecision(1)
4036 <    //          << std::setw(20)
4035 >    //          << setprecision(1)
4036 >    //          << setw(20)
4037      //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4038 <    //          << std::setw(20)
4038 >    //          << setw(20)
4039      //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4040 <    //          << std::setw(20)
4040 >    //          << setw(20)
4041      //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4042      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4043        bestMatchIndex = mcparticle - mcparticles->begin();
# Line 3194 | Line 4100 | int OSUAnalysis::findTauMotherIndex(cons
4100   // 20        strange baryon
4101   // 21        charm baryon
4102   // 22        bottom baryon
4103 < // 23        other
4103 > // 23        QCD string
4104 > // 24        other
4105  
4106   int OSUAnalysis::getPdgIdBinValue(int pdgId){
4107  
# Line 3218 | Line 4125 | int OSUAnalysis::getPdgIdBinValue(int pd
4125    else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4126    else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4127    else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4128 +  else if(absPdgId == 92  ) binValue = 23;
4129  
4130 <  else binValue = 23;
4130 >  else binValue = 24;
4131  
4132    return binValue;
4133  
# Line 3229 | Line 4137 | const BNprimaryvertex *
4137   OSUAnalysis::chosenVertex ()
4138   {
4139    const BNprimaryvertex *chosenVertex = 0;
4140 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
4141 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
4142 <      cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
4140 >  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4141 >    vector<bool> vertexFlags;
4142 >    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4143 >      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4144 >        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4145 >        break;
4146 >      }
4147 >    }
4148      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4149        if(!vertexFlags.at(vertexIndex)) continue;
4150        chosenVertex = & primaryvertexs->at(vertexIndex);
4151        break;
4152      }
4153    }
4154 <  else {
4155 <    chosenVertex = &primaryvertexs->at(0);
3243 <  }
4154 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4155 >    chosenVertex = & primaryvertexs->at (0);
4156  
4157    return chosenVertex;
4158   }
# Line 3249 | Line 4161 | const BNmet *
4161   OSUAnalysis::chosenMET ()
4162   {
4163    const BNmet *chosenMET = 0;
4164 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
4165 <    vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
4166 <      cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
4164 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4165 >    vector<bool> metFlags;
4166 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4167 >      if (cumulativeFlags.at("mets").at(i).size()){
4168 >        metFlags = cumulativeFlags.at("mets").at(i);
4169 >        break;
4170 >      }
4171 >    }
4172      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4173        if(!metFlags.at(metIndex)) continue;
4174        chosenMET = & mets->at(metIndex);
4175        break;
4176      }
4177    }
4178 <  else {
4179 <    chosenMET = &mets->at(0);
3263 <  }
4178 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4179 >    chosenMET = & mets->at (0);
4180  
4181    return chosenMET;
4182   }
# Line 3269 | Line 4185 | const BNelectron *
4185   OSUAnalysis::chosenElectron ()
4186   {
4187    const BNelectron *chosenElectron = 0;
4188 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
4189 <    vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
4190 <      cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
4188 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4189 >    vector<bool> electronFlags;
4190 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4191 >      if (cumulativeFlags.at("electrons").at(i).size()){
4192 >        electronFlags = cumulativeFlags.at("electrons").at(i);
4193 >        break;
4194 >      }
4195 >    }
4196      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4197        if(!electronFlags.at(electronIndex)) continue;
4198        chosenElectron = & electrons->at(electronIndex);
4199        break;
4200      }
4201    }
4202 <  else {
4203 <    chosenElectron = &electrons->at(0);
3283 <  }
4202 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4203 >    chosenElectron = & electrons->at (0);
4204  
4205    return chosenElectron;
4206   }
# Line 3289 | Line 4209 | const BNmuon *
4209   OSUAnalysis::chosenMuon ()
4210   {
4211    const BNmuon *chosenMuon = 0;
4212 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
4213 <    vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
4214 <      cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
4212 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4213 >    vector<bool> muonFlags;
4214 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4215 >      if (cumulativeFlags.at("muons").at(i).size()){
4216 >        muonFlags = cumulativeFlags.at("muons").at(i);
4217 >        break;
4218 >      }
4219 >    }
4220      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4221        if(!muonFlags.at(muonIndex)) continue;
4222        chosenMuon = & muons->at(muonIndex);
4223        break;
4224      }
4225    }
4226 <  else {
4227 <    chosenMuon = &muons->at(0);
3303 <  }
4226 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4227 >    chosenMuon = & muons->at (0);
4228  
4229    return chosenMuon;
4230   }
4231  
3308
4232   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines