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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines