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.34 by wulsin, Wed Mar 20 20:18:43 2013 UTC vs.
Revision 1.86 by lantonel, Wed Jun 19 22:41:18 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 < {
34 >  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
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  
35  cout << "Debug:  about to start doing pile-up reweighting." << endl;  
36
48    //create pile-up reweighting object, if necessary
49    if(datasetType_ != "data") {
50      if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
51 <    cout << "Debug PUReweighting 0." << endl;  
52 <    muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
53 <    cout << "Debug PUReweighting 1." << endl;  
54 <    electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
55 <    cout << "Debug PUReweighting 2." << endl;  
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  
47  cout << "Finished pile-up reweighting." << endl;  
62  
63    // Construct Cutflow Objects. These store the results of cut decisions and
64    // handle filling cut flow histograms.
65    masterCutFlow_ = new CutFlow (fs_);
52  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");
56
57  //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 63 | 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.find("pairs")==std::string::npos){ //just a single object
107 <      objectsToGet.push_back(tempInputCollection);
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 == "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;
80 <      objectsToGet.push_back(tempInputCollection);
81 <      objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
82 <      objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
83 <      objectsToPlot.push_back(tempInputCollection);
84 <      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
85 <      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  
90      }
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 114 | 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 146 | Line 214 | OSUAnalysis::OSUAnalysis (const edm::Par
214      tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
215      tempGmaIdHisto.bins = binVector;
216      tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
217 +    binVector.push_back(maxNum);
218 +    binVector.push_back(0);
219 +    binVector.push_back(maxNum);
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 <
230 >    histograms.push_back(tempIdVsMomIdHisto);
231 >    histograms.push_back(tempIdVsGmaIdHisto);
232    }
233  
234  
157
235    channel tempChannel;
236    //loop over all channels (event selections)
237    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
# Line 167 | 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 );
186 <    directories.push_back(subDir);
187 <
188 <    std::map<std::string, TH1D*> oneDhistoMap;
189 <    oneDHists_.push_back(oneDhistoMap);
190 <    std::map<std::string, TH2D*> twoDhistoMap;
191 <    twoDHists_.push_back(twoDhistoMap);
192 <
193 <
194 <    //book all histograms included in the configuration
195 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
196 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
197 <      int numBinsElements = currentHistogram.bins.size();
198 <      int numInputVariables = currentHistogram.inputVariables.size();
199 <
200 <      if(numBinsElements != 3 && numBinsElements !=6) {
201 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
202 <        exit(0);
203 <      }
204 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
205 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
206 <        exit(0);
207 <      }
208 <      else if(numBinsElements == 3){
209 <        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));
210 <      }
211 <      else if(numBinsElements == 6){
212 <        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));
213 <
214 <      }
215 <
216 <
217 <      if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
218 <
219 < // bin      particle type
220 < // ---      -------------
221 < //  0        unmatched
222 < //  1        u
223 < //  2        d
224 < //  3        s
225 < //  4        c
226 < //  5        b
227 < //  6        t
228 < //  7        e
229 < //  8        mu
230 < //  9        tau
231 < // 10        nu
232 < // 11        g
233 < // 12        gamma
234 < // 13        Z
235 < // 14        W
236 < // 15        light meson
237 < // 16        K meson
238 < // 17        D meson
239 < // 18        B meson
240 < // 19        light baryon
241 < // 20        strange baryon
242 < // 21        charm baryon
243 < // 22        bottom baryon
244 < // 23        other
245 <
246 <      vector<TString> labelArray;
247 <      labelArray.push_back("unmatched");
248 <      labelArray.push_back("u");
249 <      labelArray.push_back("d");
250 <      labelArray.push_back("s");
251 <      labelArray.push_back("c");
252 <      labelArray.push_back("b");
253 <      labelArray.push_back("t");
254 <      labelArray.push_back("e");
255 <      labelArray.push_back("#mu");
256 <      labelArray.push_back("#tau");
257 <      labelArray.push_back("#nu");
258 <      labelArray.push_back("g");
259 <      labelArray.push_back("#gamma");
260 <      labelArray.push_back("Z");
261 <      labelArray.push_back("W");
262 <      labelArray.push_back("light meson");
263 <      labelArray.push_back("K meson");
264 <      labelArray.push_back("D meson");
265 <      labelArray.push_back("B meson");
266 <      labelArray.push_back("light baryon");
267 <      labelArray.push_back("strange baryon");
268 <      labelArray.push_back("charm baryon");
269 <      labelArray.push_back("bottom baryon");
270 <      labelArray.push_back("other");
271 <
272 <      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
273 <        oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
274 <      }
275 <    }
276 <
277 <    //book a histogram for the number of each object type to be plotted
278 <
279 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
280 <      string currentObject = objectsToPlot.at(currentObjectIndex);
281 <      int maxNum = 10;
282 <      if(currentObject == "mcparticles") maxNum = 50;
283 <      else if(currentObject == "primaryvertexs") maxNum = 50;
284 <      else if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
285 <      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
286 <      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
287 <
288 <      currentObject.at(0) = toupper(currentObject.at(0));
289 <      string histoName = "num" + currentObject;
290 <
291 <      if(histoName == "numPrimaryvertexs"){
292 <        string newHistoName = histoName + "BeforePileupCorrection";
293 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
294 <        newHistoName = histoName + "AfterPileupCorrection";
295 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
296 <      }
297 <      else
298 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
299 <    }
300 <
301 <
302 <
303 <
304 <
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);
323 <        objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
324 <        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 332 | 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 352 | 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 367 | 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 " + tempCutName + " Cut Applied";
361        }
362        else{
363          //construct string for cutflow table
# Line 378 | 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        }
382      tempCut.name = tempCutName;
370  
371 +      tempCut.isVeto = false;
372 +      if(cuts_.at(currentCut).exists("isVeto")){
373 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
374 +        if (isVeto == true) tempCut.isVeto = true;
375 +      }
376 +      subSubDirNames.push_back(subSubDirName);
377 +      tempCut.name = tempCutName;
378  
379        tempChannel.cuts.push_back(tempCut);
380  
381  
388
382      }//end loop over cuts
383  
384 +    vector<map<string, TH1D*>> oneDHistsTmp;
385 +    vector<map<string, TH2D*>> twoDHistsTmp;
386 +    //book a directory in the output file with the name of the channel
387 +    TFileDirectory subDir = fs_->mkdir( channelName );
388 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
389 +    if(GetPlotsAfterEachCut_){
390 +      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
391 +        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
392 +        directories.push_back(subSubDir);
393 +        map<string, TH1D*> oneDhistoMap;
394 +        oneDHistsTmp.push_back(oneDhistoMap);
395 +        map<string, TH2D*> twoDhistoMap;
396 +        twoDHistsTmp.push_back(twoDhistoMap);
397 +      }
398 +      treeDirectories.push_back(subDir);
399 +      oneDHists_.push_back(oneDHistsTmp);
400 +      twoDHists_.push_back(twoDHistsTmp);
401 +    }
402 +    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
403 +    else{
404 +      map<string, TH1D*> oneDhistoMap;
405 +      oneDHistsTmp.push_back(oneDhistoMap);
406 +      map<string, TH2D*> twoDhistoMap;
407 +      twoDHistsTmp.push_back(twoDhistoMap);
408 +      oneDHists_.push_back(oneDHistsTmp);
409 +      twoDHists_.push_back(twoDHistsTmp);
410 +      directories.push_back(subDir);
411 +      treeDirectories.push_back(subDir);
412 +
413 +    }
414 +
415 +    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
416 +      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
417 +      BNTrees_.push_back(newTree);
418 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
419 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
420 +        vector<float> newVec;
421 +        BNTreeBranchVals_[currentVar.name] = newVec;
422 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
423 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
424 +    }
425 +
426 +    //book all histograms included in the configuration
427 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
428 +
429 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
430 +
431 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
432 +        int numBinsElements = currentHistogram.bins.size();
433 +        int numInputVariables = currentHistogram.inputVariables.size();
434 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
435 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
436 +
437 +        if(numBinsElements == 1){
438 +          if(numBinEdgesX > 1){
439 +            if(numBinEdgesY > 1)
440 +              numBinsElements = 6;
441 +            else
442 +              numBinsElements = 3;
443 +          }
444 +        }
445 +        if(numBinsElements != 3 && numBinsElements !=6){
446 +          cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
447 +          exit(0);
448 +        }
449 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
450 +          cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
451 +          exit(0);
452 +        }
453 +        else if(numBinsElements == 3){
454 +          if (currentHistogram.bins.size () == 3)
455 +            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));
456 +          else
457 +            {
458 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
459 +            }
460 +        }
461 +        else if(numBinsElements == 6){
462 +          if (currentHistogram.bins.size () == 6)
463 +            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));
464 +          else
465 +            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 ());
466 +        }
467 +
468 +
469 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
470 +
471 +        // bin      particle type
472 +        // ---      -------------
473 +        //  0        unmatched
474 +        //  1        u
475 +        //  2        d
476 +        //  3        s
477 +        //  4        c
478 +        //  5        b
479 +        //  6        t
480 +        //  7        e
481 +        //  8        mu
482 +        //  9        tau
483 +        // 10        nu
484 +        // 11        g
485 +        // 12        gamma
486 +        // 13        Z
487 +        // 14        W
488 +        // 15        light meson
489 +        // 16        K meson
490 +        // 17        D meson
491 +        // 18        B meson
492 +        // 19        light baryon
493 +        // 20        strange baryon
494 +        // 21        charm baryon
495 +        // 22        bottom baryon
496 +        // 23        QCD string
497 +        // 24        other
498 +
499 +        vector<TString> labelArray;
500 +        labelArray.push_back("unmatched");
501 +        labelArray.push_back("u");
502 +        labelArray.push_back("d");
503 +        labelArray.push_back("s");
504 +        labelArray.push_back("c");
505 +        labelArray.push_back("b");
506 +        labelArray.push_back("t");
507 +        labelArray.push_back("e");
508 +        labelArray.push_back("#mu");
509 +        labelArray.push_back("#tau");
510 +        labelArray.push_back("#nu");
511 +        labelArray.push_back("g");
512 +        labelArray.push_back("#gamma");
513 +        labelArray.push_back("Z");
514 +        labelArray.push_back("W");
515 +        labelArray.push_back("light meson");
516 +        labelArray.push_back("K meson");
517 +        labelArray.push_back("D meson");
518 +        labelArray.push_back("B meson");
519 +        labelArray.push_back("light baryon");
520 +        labelArray.push_back("strange baryon");
521 +        labelArray.push_back("charm baryon");
522 +        labelArray.push_back("bottom baryon");
523 +        labelArray.push_back("QCD string");
524 +        labelArray.push_back("other");
525 +
526 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
527 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
528 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
529 +          }
530 +          else {
531 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
532 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
533 +          }
534 +        }
535 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
536 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
537 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
538 +        }
539 +
540 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
541 +
542 +
543 +      // Book a histogram for the number of each object type to be plotted.
544 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
545 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
546 +        string currentObject = objectsToPlot.at(currentObjectIndex);
547 +        int maxNum = 10;
548 +        if(currentObject == "mcparticles") maxNum = 50;
549 +        else if(currentObject == "primaryvertexs") maxNum = 50;
550 +
551 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
552 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
553 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
554 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
555 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
556 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
557 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
558 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
559 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
560 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
561 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
562 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
563 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
564 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
565 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
566 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
567 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
568 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
569 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
570 +
571 +        currentObject.at(0) = toupper(currentObject.at(0));
572 +        string histoName = "num" + currentObject;
573 +
574 +        if(histoName == "numPrimaryvertexs"){
575 +          string newHistoName = histoName + "BeforePileupCorrection";
576 +          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);
577 +          newHistoName = histoName + "AfterPileupCorrection";
578 +          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);
579 +        }
580 +        else
581 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
582 +      }
583 +    }//end of loop over directories
584      channels.push_back(tempChannel);
585      tempChannel.cuts.clear();
393
586    }//end loop over channels
587  
588  
# Line 401 | Line 593 | OSUAnalysis::OSUAnalysis (const edm::Par
593    sort( objectsToCut.begin(), objectsToCut.end() );
594    objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
595  
596 +  produces<map<string, bool> > ("channelDecisions");
597 +
598 + } // end constructor OSUAnalysis::OSUAnalysis()
599  
405 }
600  
601   OSUAnalysis::~OSUAnalysis ()
602   {
603 +
604    // Destroying the CutFlow objects causes the cut flow numbers and time
605    // information to be printed to standard output.
606    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
# Line 414 | Line 609 | OSUAnalysis::~OSUAnalysis ()
609   }
610  
611   void
612 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
612 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
613   {
614 <
614 >  cout << "**********************\n\n\n";
615    // Retrieve necessary collections from the event.
616  
617 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
617 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
618      event.getByLabel (triggers_, triggers);
619  
620 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
620 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
621 >    event.getByLabel (trigobjs_, trigobjs);
622 >
623 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
624      event.getByLabel (jets_, jets);
625  
626 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
626 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
627      event.getByLabel (muons_, muons);
628  
629 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
629 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
630      event.getByLabel (electrons_, electrons);
631  
632 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
632 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
633      event.getByLabel (events_, events);
634  
635 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
635 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
636      event.getByLabel (taus_, taus);
637  
638 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
638 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
639      event.getByLabel (mets_, mets);
640  
641 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
641 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
642      event.getByLabel (tracks_, tracks);
643  
644 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
644 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
645      event.getByLabel (genjets_, genjets);
646  
647 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
647 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
648      event.getByLabel (mcparticles_, mcparticles);
649  
650 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
650 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
651      event.getByLabel (primaryvertexs_, primaryvertexs);
652  
653 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
653 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
654      event.getByLabel (bxlumis_, bxlumis);
655  
656 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
656 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
657      event.getByLabel (photons_, photons);
658  
659 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
659 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
660      event.getByLabel (superclusters_, superclusters);
661  
662 +  if (datasetType_ == "signalMC"){
663 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
664 +      event.getByLabel (stops_, stops);
665 +  }
666 +
667 +  if (useTrackCaloRhoCorr_) {
668 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
669 +    // This rho collection is not available in all BEANs.
670 +    // For description of rho values for different jet reconstruction algorithms, see
671 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
672 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
673 +  }
674 +
675 +  double masterScaleFactor = 1.0;
676 +
677    //get pile-up event weight
678 <  double scaleFactor = 1.00;
679 <  if(doPileupReweighting_ && datasetType_ != "data")
680 <    scaleFactor = puWeight_->at (events->at (0).numTruePV);
678 >  if (doPileupReweighting_ && datasetType_ != "data") {
679 >    //for "data" datasets, the numTruePV is always set to -1
680 >    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
681 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
682 >  }
683  
684 +  stopCTauScaleFactor_ = 1.0;
685 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
686 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
687 +  masterScaleFactor *= stopCTauScaleFactor_;
688  
689    //loop over all channels
690  
691 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
692    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
693      channel currentChannel = channels.at(currentChannelIndex);
694  
# Line 476 | Line 696 | OSUAnalysis::analyze (const edm::Event &
696      counterMap passingCounter;
697      cumulativeFlags.clear ();
698  
699 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
700 +         iter != BNTreeBranchVals_.end(); iter++) {
701 +      iter->second.clear();  // clear array
702 +    }
703 +
704      bool triggerDecision = true;
705 <    if(currentChannel.triggers.size() != 0){  //triggers specified
706 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
705 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
706 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
707        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
708      }
709  
710      //loop over all cuts
486
487
488
711      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
712        cut currentCut = currentChannel.cuts.at(currentCutIndex);
491
713        for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
714          string currentObject = objectsToCut.at(currentObjectIndex);
715  
716          //initialize maps to get ready to set cuts
717 <        individualFlags[currentObject].push_back (vector<bool> ());
718 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
717 >        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
718 >        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
719  
720        }
721        for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
# Line 503 | Line 724 | OSUAnalysis::analyze (const edm::Event &
724          int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
725  
726  
727 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
728 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
727 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
728 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
729 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
730 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
731 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
732          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
733          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
734          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 516 | Line 740 | OSUAnalysis::analyze (const edm::Event &
740          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
741          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
742          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
743 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
744 +
745  
746  
747          else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
748                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
749                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
750                                                                     "muon-muon pairs");
751 +
752 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
753 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
754 +                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
755 +                                                                             "muon-secondary muon pairs");
756 +
757 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
758 +                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
759 +                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
760 +                                                                                     "electron-secondary electron pairs");
761 +
762          else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
763                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
764                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
# Line 530 | Line 767 | OSUAnalysis::analyze (const edm::Event &
767                                                                         cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
768                                                                         cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
769                                                                         "electron-muon pairs");
770 +        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
771 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
772 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
773 +                                                                 "jet-jet pairs");
774 +        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
775 +                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
776 +                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
777 +                                                                      "electron-jet pairs");
778 +        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
779 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
780 +                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
781 +                                                                  "muon-jet pairs");
782 +        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
783 +                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
784 +                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
785 +                                                                     "track-event pairs");
786 +        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
787 +                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
788 +                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
789 +                                                                        "electron-track pairs");
790 +        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
791 +                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
792 +                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
793 +                                                                    "muon-track pairs");
794 +        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
795 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
796 +                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
797 +                                                                  "muon-tau pairs");
798 +        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
799 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
800 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
801 +                                                                 "tau-tau pairs");
802 +        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
803 +                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
804 +                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
805 +                                                                   "tau-track pairs");
806 +        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
807 +                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
808 +                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
809 +                                                                          "electron-trigobj pairs");
810 +        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
811 +                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
812 +                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
813 +                                                                      "muon-trigobj pairs");
814  
815 <
815 >        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
816        }
817  
818  
819  
820      }//end loop over all cuts
540
541
821      //use cumulative flags to apply cuts at event level
822  
823 +    //a vector to store cumulative cut descisions after each cut.
824 +    vector<bool> eventPassedPreviousCuts;
825      bool eventPassedAllCuts = true;
545
826      //apply trigger (true if none were specified)
827      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
828  
549
550
829      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
830  
831        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 555 | Line 833 | OSUAnalysis::analyze (const edm::Event &
833        int numberPassing = 0;
834  
835        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
836 <          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
836 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
837        }
560
838        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
839        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
563
840        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
841 <
841 >      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
842      }
843 +    double scaleFactor = masterScaleFactor;
844  
845 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
846 +    if(applyLeptonSF_ && datasetType_ != "data"){
847 +      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
848 +        flagPair muonFlags;
849 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
850 +          if (cumulativeFlags.at("muons").at(i).size()){
851 +            muonFlags = cumulativeFlags.at("muons").at(i);
852 +            break;
853 +          }
854 +        }
855 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
856 +          if(!muonFlags.at(muonIndex).second) continue;
857 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
858 +        }
859 +      }
860 +      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
861 +        flagPair electronFlags;
862 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
863 +          if (cumulativeFlags.at("electrons").at(i).size()){
864 +            electronFlags = cumulativeFlags.at("electrons").at(i);
865 +            break;
866 +          }
867 +        }
868 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
869 +          if(!electronFlags.at(electronIndex).second) continue;
870 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
871 +        }
872 +      }
873 +    }
874 +    if(applyBtagSF_ && datasetType_ != "data"){
875 +     if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
876 +       flagPair jetFlags;
877 +        vector<double> jetSFs;
878 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
879 +          if (cumulativeFlags.at("jets").at(i).size()){
880 +            jetFlags = cumulativeFlags.at("jets").at(i);
881 +            break;
882 +          }
883 +        }
884 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
885 +          if(!jetFlags.at(jetIndex).second) continue;
886 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt);
887 +          jetSFs.push_back(jetSFTmp);
888 +        }
889 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_, maxBtag_ );
890 +      }
891 +    }
892 +    scaleFactor *= muonScaleFactor_;
893 +    scaleFactor *= electronScaleFactor_;
894 +    scaleFactor *= bTagScaleFactor_;
895      cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
896  
897 +    if (printEventInfo_) {
898 +      // Write information about event to screen, for testing purposes.
899 +      cout << "Event passed all cuts in channel " <<  currentChannel.name
900 +           << ": run="  << events->at(0).run
901 +           << "  lumi=" << events->at(0).lumi
902 +           << "  event=" << events->at(0).evt
903 +           << endl;
904 +    }
905 +
906 +
907 +    //filling histograms
908 +    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
909 +      uint currentDir;
910 +      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
911 +      else{
912 +        currentDir = currentCut;
913 +      }
914  
915  
916 <    if(!eventPassedAllCuts)continue;
916 >      if(eventPassedPreviousCuts.at(currentDir)){
917  
918 +        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
919 +          histogram currentHistogram = histograms.at(histogramIndex);
920  
921 <    //if(datasetType_ != "data") {
576 <    //  scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
577 <    //  scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
578 <    //}
921 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) cout << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
922  
923 <    //filling histograms
924 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
925 <      histogram currentHistogram = histograms.at(histogramIndex);
923 >          if(currentHistogram.inputVariables.size() == 1){
924 >            TH1D* histo;
925 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
926 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
927 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
928 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
929 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
930 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
931 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
932 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
933 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
934 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
935 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
936 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
937 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
938 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
939 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
940 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
941 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
942 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
943 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
944 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
945 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
946 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
947 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
948 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
949 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
950 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
951 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
952 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
953 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
954 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
955 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
956 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
957 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
958 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
959 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
960 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
961 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
962 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
963 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
964 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
965 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
966 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
967 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
968 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
969 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
970 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
971 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
972 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
973 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
974 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
975 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
976 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
977 >
978 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
979 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
980 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
981 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
982 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
983 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
984 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
985 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
986 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
987 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
988 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
989 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
990 >          }
991 >          else if(currentHistogram.inputVariables.size() == 2){
992 >            TH2D* histo;
993 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
994 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
995 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
996 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
997 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
998 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
999 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1000 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1001 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1002 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1003 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1004 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1005 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1006 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1007 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1008 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1009 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1010 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1011 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1012 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1013 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1014 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1015 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1016 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1017 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1018 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1019 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1020 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1021 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1022 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1023 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1024 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1025 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1026 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1027 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1028 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1029 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1030 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1031 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1032 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1033 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1034 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1035 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1036 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1037 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1038 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1039 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1040 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1041 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1042 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1043 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1044 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1045 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1046 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1047 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1048 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1049 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1050 >                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1051 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1052 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1053 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1054 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1055 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1056 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1057 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1058 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1059 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1060 >          }
1061  
584      if(currentHistogram.inputVariables.size() == 1){
585        TH1D* histo;
586        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
587
588
589
590        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
591         else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
592        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
593                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
594                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
595        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
596        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
597                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
598                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
599        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
600                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
601                                                                                              cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
602        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
603        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
604        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
605        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
606        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
607        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
608        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
609        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
610        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
611        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
612      }
613      else if(currentHistogram.inputVariables.size() == 2){
614        TH2D* histo;
615        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
616
617
618
619        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
620        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
621        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
622                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
623                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
624        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
625        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
626                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
627                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
628        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
629                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
630                                                                                               cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
631        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
632        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
633        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
634        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
635        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
636        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
637        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
638        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
639        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
640        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
641      }
642    }
643
644    //fills histograms with the sizes of collections
645    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
646      string currentObject = objectsToPlot.at(currentObjectIndex);
647
648      string objectToPlot = "";
649
650      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
651      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
652      else if(currentObject == "electron-muon pairs") objectToPlot = "electronMuonPairs";
653      else objectToPlot = currentObject;
654      string tempCurrentObject = objectToPlot;
655      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
656      string histoName = "num" + tempCurrentObject;
657
658
659
660
661      //set position of primary vertex in event, in order to calculate quantities relative to it
662      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
663        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
664        int numToPlot = 0;
665        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
666          if(lastCutFlags.at(currentFlag)) numToPlot++;
667        }
668        if(objectToPlot == "primaryvertexs"){
669          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
670          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1062          }
672        else
673          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
674      }
675      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
676      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
677      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
678      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
679      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
680      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
681      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
682      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
683      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
684      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
685      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
686      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
687      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
688      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
689      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
690      else if(objectToPlot == "primaryvertexs"){
691        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
692        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
693      }
1063  
695    }
1064  
1065 +        //fills histograms with the sizes of collections
1066 +        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1067  
1068 +          string currentObject = objectsToPlot.at(currentObjectIndex);
1069 +          string objectToPlot = "";
1070  
1071 +          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1072 +          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1073 +          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1074 +          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1075 +          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1076 +          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1077 +          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1078 +          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1079 +          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1080 +          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1081 +          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1082 +          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1083 +          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1084 +          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1085 +          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1086 +          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1087 +          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1088 +          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1089 +          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1090 +          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1091 +          else objectToPlot = currentObject;
1092 +
1093 +          string tempCurrentObject = objectToPlot;
1094 +          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1095 +          string histoName = "num" + tempCurrentObject;
1096 +
1097 +
1098 +          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1099 +            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1100 +            int numToPlot = 0;
1101 +            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1102 +              if(lastCutFlags.at(currentFlag).second) numToPlot++;
1103 +            }
1104 +
1105 +            if(objectToPlot == "primaryvertexs"){
1106 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1107 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1108 +            }
1109 +            else {
1110 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1111 +            }
1112 +          }
1113 +        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1114  
700  } //end loop over channel
1115  
1116 <  masterCutFlow_->fillCutFlow(scaleFactor);
1116 >      } // end if(eventPassedPreviousCuts.at(currentDir))
1117 >    } // end loop over cuts
1118  
1119 +    if (!useEDMFormat_ && eventPassedAllCuts){
1120 +      // Assign BNTree variables
1121 +      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1122 +        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1123 +        string coll = brSpecs.inputCollection;
1124 +        if (cumulativeFlags.count(coll) == 0) cout << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1125 +
1126 +        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1127 +        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1128 +        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1129 +        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1130 +        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1131 +        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1132 +        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1133 +        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1134 +        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1135 +        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1136 +        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1137 +        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1138 +        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1139 +        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1140 +        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1141 +        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1142 +        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1143 +        else if(coll == "stops"
1144 +                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1145 +      } // end loop over branches
1146  
1147 +      if (!BNTrees_.at(currentChannelIndex)) { cout << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1148 +      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1149 +    }
1150 +
1151 +    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1152 +
1153 +  } // end loop over channel
1154 +
1155 +  masterCutFlow_->fillCutFlow(masterScaleFactor);
1156 +
1157 +  event.put (channelDecisions, "channelDecisions");
1158 +
1159 + } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1160  
706 }
1161  
1162  
1163   bool
# Line 717 | Line 1171 | OSUAnalysis::evaluateComparison (double
1171    else if(comparison == "==") return testValue == cutValue;
1172    else if(comparison == "=") return testValue == cutValue;
1173    else if(comparison == "!=") return testValue != cutValue;
1174 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1174 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1175  
1176   }
1177  
1178   bool
1179 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1179 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1180  
1181 +
1182 +  if(comparison == ">")       return testValue >  cutValue;
1183 +  else if(comparison == ">=") return testValue >= cutValue;
1184 +  else if(comparison == "<")  return testValue <  cutValue;
1185 +  else if(comparison == "<=") return testValue <= cutValue;
1186 +  else if(comparison == "==") return testValue == cutValue;
1187 +  else if(comparison == "=") return testValue == cutValue;
1188 +  else if(comparison == "!=") return testValue != cutValue;
1189 +  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1190 +
1191 + }
1192 +
1193 + bool
1194 + OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1195 +
1196 +  //initialize to false until a chosen trigger is passed
1197    bool triggerDecision = false;
1198  
1199 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1200 <    {
1201 <      if(trigger->pass != 1) continue;
1202 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1203 <        {
1204 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1205 <            triggerDecision = true;
1206 <          }
1207 <        }
1199 >  if (printAllTriggers_) cout << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1200 >  //loop over all triggers defined in the event
1201 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1202 >
1203 >    if (printAllTriggers_) cout << "   " << trigger->name << endl;
1204 >
1205 >    //we're only interested in triggers that actually passed
1206 >    if(trigger->pass != 1) continue;
1207 >
1208 >    //if the event passes one of the veto triggers, exit and return false
1209 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1210 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1211 >    }
1212 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1213 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1214 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1215      }
1216 <  return triggerDecision;
1216 >  }
1217 >
1218 >  printAllTriggers_ = false;  // only print triggers once, not every event
1219  
1220 +  //if none of the veto triggers fired:
1221 +  //return the OR of all the chosen triggers
1222 +  if (triggersToTest.size() != 0) return triggerDecision;
1223 +  //or if no triggers were defined return true
1224 +  else return true;
1225   }
1226  
1227 < std::vector<std::string>
1227 >
1228 > vector<string>
1229   OSUAnalysis::splitString (string inputString){
1230  
1231 <  std::stringstream stringStream(inputString);
1232 <  std::istream_iterator<std::string> begin(stringStream);
1233 <  std::istream_iterator<std::string> end;
1234 <  std::vector<std::string> stringVector(begin, end);
1231 >  stringstream stringStream(inputString);
1232 >  istream_iterator<string> begin(stringStream);
1233 >  istream_iterator<string> end;
1234 >  vector<string> stringVector(begin, end);
1235    return stringVector;
1236  
1237   }
1238  
1239 +
1240 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1241 +  // Set two object strings from the tempInputCollection string,
1242 +  // For example, if tempInputCollection is "electron-muon pairs",
1243 +  // then obj1 = "electrons" and obj2 = "muons".
1244 +  // Note that the objects have an "s" appended.
1245 +
1246 +  int dashIndex = tempInputCollection.find("-");
1247 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1248 +  int secondWordLength = spaceIndex - dashIndex;
1249 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1250 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1251 +
1252 + }
1253 +
1254 +
1255 + string OSUAnalysis::getObjToGet(string obj) {
1256 +  // Return the string corresponding to the object to get for the given obj string.
1257 +  // Right now this only handles the case in which obj contains "secondary",
1258 +  // e.g, "secondary muons".
1259 +  // Note that "s" is NOT appended.
1260 +
1261 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1262 +  int firstSpaceIndex = obj.find_first_of(" ");
1263 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1264 +
1265 + }
1266 +
1267 +
1268 + //!jet valueLookup
1269   double
1270 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1270 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1271  
1272    double value = 0.0;
1273    if(variable == "energy") value = object->energy;
# Line 872 | Line 1387 | OSUAnalysis::valueLookup (const BNjet* o
1387    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1388  
1389  
1390 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1390 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1391  
1392    value = applyFunction(function, value);
1393  
# Line 880 | Line 1395 | OSUAnalysis::valueLookup (const BNjet* o
1395   }
1396  
1397  
1398 <
1398 > //!muon valueLookup
1399   double
1400 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1400 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1401  
1402    double value = 0.0;
1403    if(variable == "energy") value = object->energy;
# Line 1043 | Line 1558 | OSUAnalysis::valueLookup (const BNmuon*
1558    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1559    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1560    else if(variable == "metMT") {
1561 <    const BNmet *met = chosenMET ();
1047 <    if (met)
1561 >    if (const BNmet *met = chosenMET ())
1562        {
1563 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1564 <                       p2 (met->px, met->py, 0.0, met->pt);
1051 <
1052 <        value = (p1 + p2).Mt ();
1563 >        double dPhi = deltaPhi (object->phi, met->phi);
1564 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1565        }
1566      else
1567        value = -999;
# Line 1176 | Line 1688 | OSUAnalysis::valueLookup (const BNmuon*
1688    }
1689    else if(variable == "tightIDdisplaced"){
1690      value = object->isGlobalMuon > 0                \
1691 +      && object->isPFMuon > 0                        \
1692        && object->normalizedChi2 < 10                \
1693        && object->numberOfValidMuonHits > 0        \
1694        && object->numberOfMatchedStations > 1        \
# Line 1183 | Line 1696 | OSUAnalysis::valueLookup (const BNmuon*
1696        && object->numberOfLayersWithMeasurement > 5;
1697    }
1698  
1699 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1700  
1701 +  else if(variable == "genMatchedPdgId"){
1702 +    int index = getGenMatchedParticleIndex(object);
1703 +    if(index == -1) value = 0;
1704 +    else value = mcparticles->at(index).id;
1705 +  }
1706  
1707    else if(variable == "genMatchedId"){
1708      int index = getGenMatchedParticleIndex(object);
# Line 1195 | Line 1714 | OSUAnalysis::valueLookup (const BNmuon*
1714      if(index == -1) value = 0;
1715      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1716    }
1717 +  else if(variable == "genMatchedMotherIdReverse"){
1718 +    int index = getGenMatchedParticleIndex(object);
1719 +    if(index == -1) value = 24;
1720 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1721 +  }
1722    else if(variable == "genMatchedGrandmotherId"){
1723      int index = getGenMatchedParticleIndex(object);
1724      if(index == -1) value = 0;
# Line 1205 | Line 1729 | OSUAnalysis::valueLookup (const BNmuon*
1729      }
1730      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1731    }
1732 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1733 +    int index = getGenMatchedParticleIndex(object);
1734 +    if(index == -1) value = 24;
1735 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1736 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1737 +      if(motherIndex == -1) value = 24;
1738 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1739 +    }
1740 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1741 +  }
1742 +  else if(variable == "pfMuonsFromVertex"){
1743 +    double d0Error, dzError;
1744  
1745 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1746 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1747 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1748 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1749 +      || fabs (object->correctedDZ / dzError) > 99.0;
1750 +    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1751 +  }
1752  
1753  
1754 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1754 >
1755 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1756  
1757    value = applyFunction(function, value);
1758  
1759    return value;
1760   }
1761  
1762 <
1762 > //!electron valueLookup
1763   double
1764 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1764 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1765  
1766    double value = 0.0;
1767    if(variable == "energy") value = object->energy;
# Line 1383 | Line 1927 | OSUAnalysis::valueLookup (const BNelectr
1927    else if(variable == "detIso") value = (object->trackIso) / object->pt;
1928    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1929    else if(variable == "metMT") {
1930 <    const BNmet *met = chosenMET ();
1387 <    if (met)
1930 >    if (const BNmet *met = chosenMET ())
1931        {
1932 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1933 <                       p2 (met->px, met->py, 0.0, met->pt);
1391 <
1392 <        value = (p1 + p2).Mt ();
1932 >        double dPhi = deltaPhi (object->phi, met->phi);
1933 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1934        }
1935      else
1936        value = -999;
# Line 1553 | Line 2094 | OSUAnalysis::valueLookup (const BNelectr
2094        }
2095    }
2096  
2097 +
2098 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2099 +
2100 +  else if(variable == "genMatchedPdgId"){
2101 +    int index = getGenMatchedParticleIndex(object);
2102 +    if(index == -1) value = 0;
2103 +    else value = mcparticles->at(index).id;
2104 +  }
2105 +
2106 +
2107    else if(variable == "genMatchedId"){
2108      int index = getGenMatchedParticleIndex(object);
2109      if(index == -1) value = 0;
# Line 1563 | Line 2114 | OSUAnalysis::valueLookup (const BNelectr
2114      if(index == -1) value = 0;
2115      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2116    }
2117 +  else if(variable == "genMatchedMotherIdReverse"){
2118 +    int index = getGenMatchedParticleIndex(object);
2119 +    if(index == -1) value = 24;
2120 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2121 +  }
2122    else if(variable == "genMatchedGrandmotherId"){
2123      int index = getGenMatchedParticleIndex(object);
2124      if(index == -1) value = 0;
# Line 1573 | Line 2129 | OSUAnalysis::valueLookup (const BNelectr
2129      }
2130      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2131    }
2132 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2133 +    int index = getGenMatchedParticleIndex(object);
2134 +    if(index == -1) value = 24;
2135 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2136 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2137 +      if(motherIndex == -1) value = 24;
2138 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2139 +    }
2140 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2141 +  }
2142 +  else if(variable == "pfElectronsFromVertex"){
2143 +    double d0Error, dzError;
2144  
2145 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2146 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2147 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2148 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2149 +      || fabs (object->correctedDZ / dzError) > 99.0;
2150 +    value = !value;
2151 +  }
2152  
2153  
2154 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2154 >
2155 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2156  
2157    value = applyFunction(function, value);
2158  
2159    return value;
2160   }
2161  
2162 <
2162 > //!event valueLookup
2163   double
2164 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2164 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2165  
2166    double value = 0.0;
2167  
# Line 1654 | Line 2230 | OSUAnalysis::valueLookup (const BNevent*
2230    else if(variable == "id2") value = object->id2;
2231    else if(variable == "evt") value = object->evt;
2232    else if(variable == "puScaleFactor"){
2233 <    if(datasetType_ != "data")
2233 >    if(doPileupReweighting_ && datasetType_ != "data")
2234        value = puWeight_->at (events->at (0).numTruePV);
2235      else
2236        value = 1.0;
2237    }
2238 <  else if(variable == "muonScaleFactor"){
2239 <    if(datasetType_ != "data")
2240 <      value = muonSFWeight_->at (chosenMuon ()->eta);
2241 <    else
2242 <      value = 1.0;
1667 <  }
1668 <  else if(variable == "electronScaleFactor"){
1669 <    if(datasetType_ != "data")
1670 <      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1671 <    else
1672 <      value = 1.0;
1673 <  }
1674 <
1675 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2238 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2239 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2240 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2241 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2242 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2243  
2244    value = applyFunction(function, value);
2245  
2246    return value;
2247   }
2248  
2249 + //!tau valueLookup
2250   double
2251 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2251 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2252  
2253    double value = 0.0;
2254  
# Line 1725 | Line 2293 | OSUAnalysis::valueLookup (const BNtau* o
2293    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2294  
2295  
2296 +
2297 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2298 +
2299 +  else if(variable == "genMatchedPdgId"){
2300 +    int index = getGenMatchedParticleIndex(object);
2301 +    if(index == -1) value = 0;
2302 +    else value = mcparticles->at(index).id;
2303 +  }
2304 +
2305    else if(variable == "genMatchedId"){
2306      int index = getGenMatchedParticleIndex(object);
2307      if(index == -1) value = 0;
# Line 1735 | Line 2312 | OSUAnalysis::valueLookup (const BNtau* o
2312      if(index == -1) value = 0;
2313      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2314    }
2315 +  else if(variable == "genMatchedMotherIdReverse"){
2316 +    int index = getGenMatchedParticleIndex(object);
2317 +    if(index == -1) value = 24;
2318 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2319 +  }
2320    else if(variable == "genMatchedGrandmotherId"){
2321      int index = getGenMatchedParticleIndex(object);
2322      if(index == -1) value = 0;
# Line 1745 | Line 2327 | OSUAnalysis::valueLookup (const BNtau* o
2327      }
2328      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2329    }
2330 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2331 +    int index = getGenMatchedParticleIndex(object);
2332 +    if(index == -1) value = 24;
2333 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2334 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2335 +      if(motherIndex == -1) value = 24;
2336 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2337 +    }
2338 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2339 +  }
2340  
2341  
2342 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2342 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2343  
2344    value = applyFunction(function, value);
2345  
2346    return value;
2347   }
2348  
2349 + //!met valueLookup
2350   double
2351 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2351 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2352  
2353    double value = 0.0;
2354  
# Line 1819 | Line 2412 | OSUAnalysis::valueLookup (const BNmet* o
2412    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2413    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2414  
2415 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2415 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2416  
2417    value = applyFunction(function, value);
2418  
2419    return value;
2420   }
2421  
2422 + //!track valueLookup
2423   double
2424 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2424 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2425  
2426    double value = 0.0;
2427    double pMag = sqrt(object->pt * object->pt +
2428 <                         object->pz * object->pz);
2428 >                     object->pz * object->pz);
2429  
2430    if(variable == "pt") value = object->pt;
2431    else if(variable == "px") value = object->px;
# Line 1853 | Line 2447 | OSUAnalysis::valueLookup (const BNtrack*
2447  
2448  
2449    //additional BNs info for disappTrks
1856  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2450    else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2451    else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2452    else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2453    else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2454    else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2455    else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2456 +  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2457    else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2458    else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2459    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2460 <  
2460 >  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2461  
2462    //user defined variables
2463    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;
2464    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2465 <  else if(variable == "caloTotDeltaRp5") value =(object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2466 <  else if(variable == "caloTotDeltaRp5ByP") value =( (object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2467 <
2468 <
2469 <
2470 <
2471 <
2472 <  else if(variable == "isIso") value = getTrkIsIso(object, tracks.product());
2473 <  else if(variable == "isMatchedDeadEcal") value = getTrkIsMatchedDeadEcal(object);
2474 <  else if(variable == "ptErrorByPt") value = (object->ptError/object->pt);
2475 <  else if(variable == "ptError") value = object->ptError;
2476 <  else if(variable == "ptRes") value = getTrkPtRes(object);
2477 <
2478 <  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2465 >  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2466 >  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2467 >  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2468 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2469 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2470 >  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2471 >  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2472 >  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2473 >  else if(variable == "ptError")                    value = object->ptError;
2474 >  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2475 >  else if (variable == "d0wrtPV"){
2476 >    double vx = object->vx - chosenVertex ()->x,
2477 >      vy = object->vy - chosenVertex ()->y,
2478 >      px = object->px,
2479 >      py = object->py,
2480 >      pt = object->pt;
2481 >    value = (-vx * py + vy * px) / pt;
2482 >  }
2483 >  else if (variable == "dZwrtPV"){
2484 >    double vx = object->vx - chosenVertex ()->x,
2485 >      vy = object->vy - chosenVertex ()->y,
2486 >      vz = object->vz - chosenVertex ()->z,
2487 >      px = object->px,
2488 >      py = object->py,
2489 >      pz = object->pz,
2490 >      pt = object->pt;
2491 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2492 >  }
2493 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2494  
2495 <  else if(variable == "genId"){
2495 >  else if(variable == "genMatchedPdgId"){
2496      int index = getGenMatchedParticleIndex(object);
2497      if(index == -1) value = 0;
2498      else value = mcparticles->at(index).id;
# Line 1900 | Line 2509 | OSUAnalysis::valueLookup (const BNtrack*
2509      if(index == -1) value = 0;
2510      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2511    }
2512 +  else if(variable == "genMatchedMotherIdReverse"){
2513 +    int index = getGenMatchedParticleIndex(object);
2514 +    if(index == -1) value = 24;
2515 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2516 +  }
2517    else if(variable == "genMatchedGrandmotherId"){
2518      int index = getGenMatchedParticleIndex(object);
2519      if(index == -1) value = 0;
# Line 1910 | Line 2524 | OSUAnalysis::valueLookup (const BNtrack*
2524      }
2525      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2526    }
2527 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2528 +    int index = getGenMatchedParticleIndex(object);
2529 +    if(index == -1) value = 24;
2530 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2531 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2532 +      if(motherIndex == -1) value = 24;
2533 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2534 +    }
2535 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2536 +  }
2537  
2538  
2539  
2540 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2540 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2541  
2542    value = applyFunction(function, value);
2543  
2544    return value;
2545   }
2546  
2547 + //!genjet valueLookup
2548   double
2549 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2549 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2550  
2551    double value = 0.0;
2552  
# Line 1941 | Line 2566 | OSUAnalysis::valueLookup (const BNgenjet
2566    else if(variable == "charge") value = object->charge;
2567  
2568  
2569 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2569 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2570  
2571    value = applyFunction(function, value);
2572  
2573    return value;
2574   }
2575  
2576 + //!mcparticle valueLookup
2577   double
2578 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2578 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2579  
2580    double value = 0.0;
2581  
# Line 2074 | Line 2700 | OSUAnalysis::valueLookup (const BNmcpart
2700    }
2701  
2702  
2703 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2703 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2704  
2705    value = applyFunction(function, value);
2706  
2707    return value;
2708   }
2709  
2710 + //!primaryvertex valueLookup
2711   double
2712 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2712 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2713  
2714    double value = 0.0;
2715  
# Line 2101 | Line 2728 | OSUAnalysis::valueLookup (const BNprimar
2728    else if(variable == "isGood") value = object->isGood;
2729  
2730  
2731 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2731 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2732  
2733    value = applyFunction(function, value);
2734  
2735    return value;
2736   }
2737  
2738 + //!bxlumi valueLookup
2739   double
2740 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2740 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2741  
2742    double value = 0.0;
2743  
# Line 2118 | Line 2746 | OSUAnalysis::valueLookup (const BNbxlumi
2746    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2747  
2748  
2749 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2749 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2750  
2751    value = applyFunction(function, value);
2752  
2753    return value;
2754   }
2755  
2756 + //!photon valueLookup
2757   double
2758 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2758 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2759  
2760    double value = 0.0;
2761  
# Line 2201 | Line 2830 | OSUAnalysis::valueLookup (const BNphoton
2830    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2831  
2832  
2204
2833  
2834  
2835 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2836 +
2837 +  else if(variable == "genMatchedPdgId"){
2838 +    int index = getGenMatchedParticleIndex(object);
2839 +    if(index == -1) value = 0;
2840 +    else value = mcparticles->at(index).id;
2841 +  }
2842 +
2843  
2844  
2845    else if(variable == "genMatchedId"){
# Line 2216 | Line 2852 | OSUAnalysis::valueLookup (const BNphoton
2852      if(index == -1) value = 0;
2853      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2854    }
2855 +  else if(variable == "genMatchedMotherIdReverse"){
2856 +    int index = getGenMatchedParticleIndex(object);
2857 +    if(index == -1) value = 24;
2858 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2859 +  }
2860    else if(variable == "genMatchedGrandmotherId"){
2861      int index = getGenMatchedParticleIndex(object);
2862      if(index == -1) value = 0;
# Line 2226 | Line 2867 | OSUAnalysis::valueLookup (const BNphoton
2867      }
2868      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2869    }
2870 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2871 +    int index = getGenMatchedParticleIndex(object);
2872 +    if(index == -1) value = 24;
2873 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2874 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2875 +      if(motherIndex == -1) value = 24;
2876 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2877 +    }
2878 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2879 +  }
2880  
2881  
2882 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2882 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2883  
2884    value = applyFunction(function, value);
2885  
2886    return value;
2887   }
2888  
2889 + //!supercluster valueLookup
2890   double
2891 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
2891 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
2892  
2893    double value = 0.0;
2894  
# Line 2250 | Line 2902 | OSUAnalysis::valueLookup (const BNsuperc
2902    else if(variable == "theta") value = object->theta;
2903  
2904  
2905 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2905 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2906  
2907    value = applyFunction(function, value);
2908  
2909    return value;
2910   }
2911  
2912 + //!trigobj valueLookup
2913 + double
2914 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
2915 +
2916 +  double value = 0.0;
2917  
2918 +  if(variable == "pt") value = object->pt;
2919 +  else if(variable == "eta") value = object->eta;
2920 +  else if(variable == "phi") value = object->phi;
2921 +  else if(variable == "px") value = object->px;
2922 +  else if(variable == "py") value = object->py;
2923 +  else if(variable == "pz") value = object->pz;
2924 +  else if(variable == "et") value = object->et;
2925 +  else if(variable == "energy") value = object->energy;
2926 +  else if(variable == "etTotal") value = object->etTotal;
2927 +  else if(variable == "id") value = object->id;
2928 +  else if(variable == "charge") value = object->charge;
2929 +  else if(variable == "isIsolated") value = object->isIsolated;
2930 +  else if(variable == "isMip") value = object->isMip;
2931 +  else if(variable == "isForward") value = object->isForward;
2932 +  else if(variable == "isRPC") value = object->isRPC;
2933 +  else if(variable == "bx") value = object->bx;
2934 +  else if(variable == "filter") {
2935 +    if ((stringValue = object->filter) == "")
2936 +      stringValue = "none";  // stringValue should only be empty if value is filled
2937 +  }
2938 +
2939 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2940 +
2941 +  value = applyFunction(function, value);
2942 +
2943 +  return value;
2944 + }
2945 +
2946 + //!muon-muon pair valueLookup
2947   double
2948 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
2948 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
2949  
2950    double value = 0.0;
2951  
2952    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2953 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2954    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2955    else if(variable == "invMass"){
2956      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2957      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2958      value = (fourVector1 + fourVector2).M();
2959    }
2960 +  else if(variable == "pt"){
2961 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2962 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2963 +    value = (fourVector1 + fourVector2).Pt();
2964 +  }
2965    else if(variable == "threeDAngle")
2966      {
2967        TVector3 threeVector1(object1->px, object1->py, object1->pz);
# Line 2300 | Line 2992 | OSUAnalysis::valueLookup (const BNmuon*
2992    else if(variable == "muon2CorrectedD0Vertex"){
2993      value = object2->correctedD0Vertex;
2994    }
2995 < else if(variable == "muon1timeAtIpInOut"){
2995 >  else if(variable == "muon1timeAtIpInOut"){
2996      value = object1->timeAtIpInOut;
2997    }
2998 < else if(variable == "muon2timeAtIpInOut"){
2998 >  else if(variable == "muon2timeAtIpInOut"){
2999      value = object2->timeAtIpInOut;
3000    }
3001 < else if(variable == "muon1correctedD0")
3002 <   {
3003 <     value = object1->correctedD0;
3004 <   }
3005 < else if(variable == "muon1correctedD0Vertex")
3006 <   {
3007 <     value = object1->correctedD0Vertex;
3008 <   }
3009 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3001 >  else if(variable == "muon1correctedD0")
3002 >    {
3003 >      value = object1->correctedD0;
3004 >    }
3005 >  else if(variable == "muon2correctedD0")
3006 >    {
3007 >      value = object2->correctedD0;
3008 >    }
3009 >
3010 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3011  
3012    value = applyFunction(function, value);
3013  
3014    return value;
3015   }
3016  
3017 + //!electron-electron pair valueLookup
3018   double
3019 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
3019 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3020  
3021    double value = 0.0;
3022  
3023    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3024 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3025    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3026    else if(variable == "invMass"){
3027      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3028      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3029      value = (fourVector1 + fourVector2).M();
3030    }
3031 +  else if(variable == "pt"){
3032 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3033 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3034 +    value = (fourVector1 + fourVector2).Pt();
3035 +  }
3036    else if(variable == "threeDAngle")
3037      {
3038        TVector3 threeVector1(object1->px, object1->py, object1->pz);
# Line 2356 | Line 3056 | OSUAnalysis::valueLookup (const BNelectr
3056    else if(variable == "electron2CorrectedD0Vertex"){
3057      value = object2->correctedD0Vertex;
3058    }
3059 +  else if(variable == "electron1CorrectedD0"){
3060 +    value = object1->correctedD0;
3061 +  }
3062 +  else if(variable == "electron2CorrectedD0"){
3063 +    value = object2->correctedD0;
3064 +  }
3065  
3066 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3066 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3067  
3068    value = applyFunction(function, value);
3069  
3070    return value;
3071   }
3072 <
3072 > //!electron-muon pair valueLookup
3073   double
3074 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3074 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3075  
3076    double value = 0.0;
3077  
3078    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3079 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3080    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3081    else if(variable == "invMass"){
3082      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3083      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3084      value = (fourVector1 + fourVector2).M();
3085    }
3086 +  else if(variable == "pt"){
3087 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3088 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3089 +    value = (fourVector1 + fourVector2).Pt();
3090 +  }
3091    else if(variable == "threeDAngle")
3092      {
3093        TVector3 threeVector1(object1->px, object1->py, object1->pz);
# Line 2411 | Line 3123 | OSUAnalysis::valueLookup (const BNelectr
3123    else if(variable == "muonDetIso"){
3124      value = (object2->trackIsoDR03) / object2->pt;
3125    }
3126 +  else if(variable == "electronRelPFrhoIso"){
3127 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3128 +  }
3129 +  else if(variable == "muonRelPFdBetaIso"){
3130 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3131 +  }
3132 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3133 +  value = applyFunction(function, value);
3134 +
3135 +  return value;
3136 + }
3137 +
3138 + //!electron-jet pair valueLookup
3139 + double
3140 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3141 +
3142 +  double value = 0.0;
3143 +
3144 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3145 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3146 +  else if(variable == "jetEta") value = object2->eta;
3147 +  else if(variable == "jetPhi") value = object2->phi;
3148 +  else if(variable == "electronEta") value = object1->eta;
3149 +  else if(variable == "electronPhi") value = object1->phi;
3150 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3151 +  else if(variable == "invMass"){
3152 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3153 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3154 +    value = (fourVector1 + fourVector2).M();
3155 +  }
3156 +  else if(variable == "pt"){
3157 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3158 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3159 +    value = (fourVector1 + fourVector2).Pt();
3160 +  }
3161 +  else if(variable == "threeDAngle")
3162 +    {
3163 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3164 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3165 +      value = (threeVector1.Angle(threeVector2));
3166 +    }
3167    else if(variable == "chargeProduct"){
3168 <    value = object1->charge * object2->charge;
3168 >    value = object1->charge*object2->charge;
3169    }
3170  
3171 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3172 +  value = applyFunction(function, value);
3173 +
3174 +  return value;
3175 + }
3176 +
3177 + //!muon-jet pair valueLookup
3178 + double
3179 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3180 +
3181 +  double value = 0.0;
3182 +
3183 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3184 +  else if(variable == "jetEta") value = object2->eta;
3185 +  else if(variable == "jetPhi") value = object2->phi;
3186 +  else if(variable == "muonEta") value = object1->eta;
3187 +  else if(variable == "muonPhi") value = object1->phi;
3188 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3189 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3190 +  else if(variable == "invMass"){
3191 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3192 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3193 +    value = (fourVector1 + fourVector2).M();
3194 +  }
3195 +  else if(variable == "pt"){
3196 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3197 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3198 +    value = (fourVector1 + fourVector2).Pt();
3199 +  }
3200 +  else if(variable == "threeDAngle")
3201 +    {
3202 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3203 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3204 +      value = (threeVector1.Angle(threeVector2));
3205 +    }
3206 +  else if(variable == "chargeProduct"){
3207 +    value = object1->charge*object2->charge;
3208 +  }
3209 +
3210 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3211 +  value = applyFunction(function, value);
3212 +
3213 +  return value;
3214 + }
3215  
3216 + //!jet-jet pair valueLookup
3217 + double
3218 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3219 +
3220 +  double value = 0.0;
3221 +
3222 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3223 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3224 +  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3225 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3226 +  else if(variable == "invMass"){
3227 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3228 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3229 +    value = (fourVector1 + fourVector2).M();
3230 +  }
3231 +  else if(variable == "pt"){
3232 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3233 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3234 +    value = (fourVector1 + fourVector2).Pt();
3235 +  }
3236 +  else if(variable == "threeDAngle")
3237 +    {
3238 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3239 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3240 +      value = (threeVector1.Angle(threeVector2));
3241 +    }
3242 +  else if(variable == "chargeProduct"){
3243 +    value = object1->charge*object2->charge;
3244 +  }
3245 +
3246 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3247 +  value = applyFunction(function, value);
3248 +
3249 +  return value;
3250 + }
3251 + //!electron-track pair valueLookup
3252 + double
3253 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3254 +  double electronMass = 0.000511;
3255 +  double value = 0.0;
3256 +  TLorentzVector fourVector1(0, 0, 0, 0);
3257 +  TLorentzVector fourVector2(0, 0, 0, 0);
3258 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3259 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3260 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3261 +  else if(variable == "invMass"){
3262 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3263 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3264 +
3265 +    value = (fourVector1 + fourVector2).M();
3266 +  }
3267 +  else if(variable == "chargeProduct"){
3268 +    value = object1->charge*object2->charge;
3269 +  }
3270    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3271 +  value = applyFunction(function, value);
3272 +  return value;
3273 +
3274 + }
3275  
3276 +
3277 + //!muon-track pair valueLookup
3278 + double
3279 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3280 +  double pionMass = 0.140;
3281 +  double muonMass = 0.106;
3282 +  double value = 0.0;
3283 +  TLorentzVector fourVector1(0, 0, 0, 0);
3284 +  TLorentzVector fourVector2(0, 0, 0, 0);
3285 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3286 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3287 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3288 +  else if(variable == "invMass"){
3289 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3290 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3291 +
3292 +    value = (fourVector1 + fourVector2).M();
3293 +  }
3294 +  else if(variable == "chargeProduct"){
3295 +    value = object1->charge*object2->charge;
3296 +  }
3297 +
3298 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3299    value = applyFunction(function, value);
3300 +  return value;
3301 + }
3302 +
3303 + //!tau-tau pair valueLookup
3304 + double
3305 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3306 +  double value = 0.0;
3307 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3308 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3309 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3310 +  else if(variable == "invMass"){
3311 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3312 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3313 +    value = (fourVector1 + fourVector2).M();
3314 +  }
3315 +
3316 +  else if(variable == "chargeProduct"){
3317 +    value = object1->charge*object2->charge;
3318 +  }
3319  
3320 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3321 +  value = applyFunction(function, value);
3322    return value;
3323   }
3324  
3325 + //!muon-tau pair valueLookup
3326 + double
3327 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3328 +  double value = 0.0;
3329 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3330 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3331 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3332 +  else if(variable == "invMass"){
3333 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3334 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3335 +    value = (fourVector1 + fourVector2).M();
3336 +  }
3337 +
3338 +  else if(variable == "chargeProduct"){
3339 +    value = object1->charge*object2->charge;
3340 +  }
3341 +
3342 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3343 +  value = applyFunction(function, value);
3344 +  return value;
3345 + }
3346 +
3347 + //!tau-track pair valueLookup
3348 + double
3349 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3350 +  double value = 0.0;
3351 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3352 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3353 +  else if(variable == "chargeProduct"){
3354 +    value = object1->charge*object2->charge;
3355 +  }
3356 +
3357 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3358 +  value = applyFunction(function, value);
3359 +  return value;
3360 + }
3361 +
3362 +
3363 + //!track-event pair valueLookup
3364 + double
3365 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3366 +
3367 +  double value = 0.0;
3368 +  double pMag = sqrt(object1->pt * object1->pt +
3369 +                     object1->pz * object1->pz);
3370 +
3371 +  if      (variable == "numPV")                      value = object2->numPV;
3372 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3373 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3374 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3375 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3376 +
3377 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3378 +
3379 +  value = applyFunction(function, value);
3380 +
3381 +  return value;
3382 +
3383 + }
3384 +
3385 + //!electron-trigobj pair valueLookup
3386 + double
3387 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3388 +
3389 +  double value = 0.0;
3390 +
3391 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3392 +  else if (variable == "match"){
3393 +    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3394 +      stringValue = object2->filter;
3395 +    else
3396 +      stringValue = "none";
3397 +  }
3398 +
3399 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3400 +
3401 +  value = applyFunction(function, value);
3402 +
3403 +  return value;
3404 +
3405 + }
3406 +
3407 + //!muon-trigobj pair valueLookup
3408 + double
3409 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3410 +
3411 +  double value = 0.0;
3412 +
3413 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3414 +
3415 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3416 +
3417 +  value = applyFunction(function, value);
3418 +
3419 +  return value;
3420 +
3421 + }
3422 +
3423 + //!stop valueLookup
3424 + double
3425 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3426 +
3427 +
3428 +  double value = 0.0;
3429 +
3430 +  if(variable == "ctau") value = object->ctau;
3431 +
3432 +  else if (variable == "d0"){
3433 +    double vx = object->vx - chosenVertex ()->x,
3434 +      vy = object->vy - chosenVertex ()->y,
3435 +      px = object->px,
3436 +      py = object->py,
3437 +      pt = object->pt;
3438 +    value = (-vx * py + vy * px) / pt;
3439 +  }
3440 +
3441 +  else if (variable == "dz"){
3442 +    double vx = object->vx - chosenVertex ()->x,
3443 +      vy = object->vy - chosenVertex ()->y,
3444 +      vz = object->vz - chosenVertex ()->z,
3445 +      px = object->px,
3446 +      py = object->py,
3447 +      pz = object->pz,
3448 +      pt = object->pt;
3449 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3450 +  }
3451 +
3452 +  else if (variable == "minD0"){
3453 +    double minD0=999;
3454 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3455 +      double vx = object->vx - vertex->x,
3456 +        vy = object->vy - vertex->y,
3457 +        px = object->px,
3458 +        py = object->py,
3459 +        pt = object->pt;
3460 +      value = (-vx * py + vy * px) / pt;
3461 +      if(abs(value) < abs(minD0)) minD0 = value;
3462 +    }
3463 +    value = minD0;
3464 +  }
3465 +  else if (variable == "minDz"){
3466 +    double minDz=999;
3467 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3468 +      double vx = object->vx - vertex->x,
3469 +        vy = object->vy - vertex->y,
3470 +        vz = object->vz - vertex->z,
3471 +        px = object->px,
3472 +        py = object->py,
3473 +        pz = object->pz,
3474 +        pt = object->pt;
3475 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3476 +      if(abs(value) < abs(minDz)) minDz = value;
3477 +    }
3478 +    value = minDz;
3479 +  }
3480 +  else if(variable == "distToVertex"){
3481 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3482 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3483 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3484 +  }
3485 +  else if (variable == "minDistToVertex"){
3486 +    double minDistToVertex=999;
3487 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3488 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3489 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3490 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3491 +
3492 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3493 +    }
3494 +    value = minDistToVertex;
3495 +  }
3496 +  else if (variable == "distToVertexDifference"){
3497 +    double minDistToVertex=999;
3498 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3499 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3500 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3501 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3502 +
3503 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3504 +    }
3505 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3506 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3507 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3508 +
3509 +    value = distToChosenVertex - minDistToVertex;
3510 +  }
3511 +
3512 +  else if (variable == "closestVertexRank"){
3513 +    double minDistToVertex=999;
3514 +    int vertex_rank = 0;
3515 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3516 +      vertex_rank++;
3517 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3518 +                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
3519 +                      (object->vz-vertex->z)*(object->vz-vertex->z));
3520 +
3521 +      if(abs(dist) < abs(minDistToVertex)){
3522 +        value = vertex_rank;
3523 +        minDistToVertex = dist;
3524 +      }
3525 +    }
3526 +  }
3527 +
3528 +
3529 +
3530 +
3531 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3532 +
3533 +  value = applyFunction(function, value);
3534 +
3535 +  return value;
3536 +
3537 + }
3538 +
3539 +
3540 +
3541  
3542   // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3543   // Return true iff no other tracks are found in this cone.
# Line 2469 | Line 3584 | OSUAnalysis::getTrkPtTrue (const BNtrack
3584  
3585   }
3586  
3587 + double
3588 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3589 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3590 +  if (!useTrackCaloRhoCorr_) return -99;
3591 +  // if (!rhokt6CaloJetsHandle_) {
3592 +  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3593 +  //   return -99;
3594 +  // }
3595 +  double radDeltaRCone = 0.5;
3596 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3597 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3598 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3599 +  return caloTotRhoCorrCalo;
3600 +
3601 + }
3602 +
3603 +
3604 +
3605 +
3606   //creates a map of the dead Ecal channels in the barrel and endcap
3607   //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
3608   //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
# Line 2501 | Line 3635 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3635    double deltaRLowest = 999;
3636    int value = 0;
3637    if (DeadEcalVec.size() == 0) WriteDeadEcal();
3638 <  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3638 >  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3639      double eta = ecal->etaEcal;
3640      double phi = ecal->phiEcal;
3641 <    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
3641 >    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
3642      if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3643    }
3644    if (deltaRLowest<0.05) {value = 1;}
# Line 2512 | Line 3646 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3646    return value;
3647   }
3648  
3649 < // Returns the smallest DeltaR between the object and any generated true particle in the event.  
3649 > // Returns the smallest DeltaR between the object and any generated true particle in the event.
3650   template <class InputObject>
3651   double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3652    double genDeltaRLowest = 999.;
3653    for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3654      double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
3655      if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
3656 < }
3656 >  }
3657    return genDeltaRLowest;
3658   }
3659  
# Line 2532 | Line 3666 | OSUAnalysis::applyFunction(string functi
3666    else if(function == "log") value = log10(value);
3667  
3668    else if(function == "") value = value;
3669 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
3669 >  else{cout << "WARNING: invalid function '" << function << "'\n";}
3670  
3671    return value;
3672  
# Line 2542 | Line 3676 | OSUAnalysis::applyFunction(string functi
3676   template <class InputCollection>
3677   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
3678  
3679 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
3680 +    string obj1, obj2;
3681 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
3682 +    if (inputType==obj1 ||
3683 +        inputType==obj2) {
3684 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
3685 +      // and the inputType is a member of the pair.
3686 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
3687 +      // For example, if currentCut.inputCollection==electron-muon pairs,
3688 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
3689 +      return;
3690 +    }
3691 +  }
3692  
3693    for (uint object = 0; object != inputCollection->size(); object++){
3694  
3695 <
3696 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
2550 <
3695 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
3696 >    bool plotDecision = true;
3697  
3698      if(currentCut.inputCollection == inputType){
3699  
3700        vector<bool> subcutDecisions;
3701        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3702 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3703 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3702 >        string stringValue = "";
3703 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3704 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3705 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3706 >
3707        }
3708 <      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3708 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
3709        else{
3710          bool tempDecision = true;
3711          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
# Line 2565 | Line 3714 | void OSUAnalysis::setObjectFlags(cut &cu
3714            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
3715              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
3716          }
3717 <        decision = tempDecision;
3717 >        cutDecision = tempDecision;
3718        }
3719 +      //invert the cut for plotting if this cut is a veto
3720 +      if(currentCut.isVeto) plotDecision = !cutDecision;
3721 +      else plotDecision = cutDecision;
3722      }
2571    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3723  
3724 +    if(cutDecision != plotDecision && currentCut.variables.at(0) == "pt") cout << "---------------\n" << cutDecision << " " << plotDecision << endl;
3725 +    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
3726  
3727 <    //set flags for objects that pass each cut AND all the previous cuts
3728 <    bool previousCumulativeFlag = true;
3727 >    //set flags for objects that pass this cut AND all the previous cuts
3728 >    bool previousCumulativeCutFlag = true;
3729 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3730 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
3731 >      else{ previousCumulativeCutFlag = false; break;}
3732 >    }
3733 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
3734 >    bool previousCumulativePlotFlag = true;
3735      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3736 <      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
3737 <      else{ previousCumulativeFlag = false; break;}
3736 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
3737 >      else{ previousCumulativePlotFlag = false; break;}
3738      }
3739 <    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3739 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
3740  
3741 +    if(inputType == "muons") cout << previousCumulativeCutFlag << " " << previousCumulativePlotFlag << " " << currentCut.variables.at(0) << "\n---------------\n\n";
3742 +    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
3743  
3744    }
3745  
# Line 2587 | Line 3748 | void OSUAnalysis::setObjectFlags(cut &cu
3748  
3749   template <class InputCollection1, class InputCollection2>
3750   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
3751 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
3751 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, string inputType){
3752  
3753  
3754    bool sameObjects = false;
3755    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3756  
3757 +  // Get the strings for the two objects that make up the pair.
3758 +  string obj1Type, obj2Type;
3759 +  getTwoObjs(inputType, obj1Type, obj2Type);
3760 +  bool isTwoTypesOfObject = true;
3761 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
3762 +
3763 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
3764 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
3765 +  if (currentCut.inputCollection == inputType) {
3766 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
3767 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
3768 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
3769 +    }
3770 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
3771 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
3772 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
3773 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
3774 +      }
3775 +    }
3776 +  }
3777  
3778    int counter = 0;
3779 +
3780    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3781      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3782  
3783        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3784  
3785  
3786 <      bool decision = true;//object passes if this cut doesn't cut on that type of object
3786 >      bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
3787 >      bool plotDecision = true;
3788  
3789        if(currentCut.inputCollection == inputType){
3790  
3791          vector<bool> subcutDecisions;
3792          for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3793 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3794 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3793 >          string stringValue = "";
3794 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3795 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3796 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3797          }
3798  
3799 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3799 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
3800          else{
3801            bool tempDecision = subcutDecisions.at(0);
3802            for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
# Line 2620 | Line 3805 | void OSUAnalysis::setObjectFlags(cut &cu
3805              else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
3806                tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
3807            }
3808 <          decision = tempDecision;
3808 >          cutDecision = tempDecision;
3809          }
3810 +        //invert the cut for plotting if this cut is a veto
3811 +        if(currentCut.isVeto) plotDecision = !cutDecision;
3812 +        else plotDecision = cutDecision;
3813 +      }
3814 +      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
3815 +      if (cutDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3816 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
3817 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
3818 +      }
3819 +      if (plotDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3820 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
3821 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
3822        }
2626      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3823  
3824 <      //set flags for objects that pass each cut AND all the previous cuts
3825 <      bool previousCumulativeFlag = true;
3824 >      //set flags for objects that pass this cut AND all the previous cuts
3825 >      bool previousCumulativeCutFlag = true;
3826        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3827 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
3828 <        else{ previousCumulativeFlag = false; break;}
3827 >        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
3828 >        else{ previousCumulativeCutFlag = false; break;}
3829        }
3830 +      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
3831 +
3832 +      bool previousCumulativePlotFlag = true;
3833 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3834 +        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
3835 +        else{ previousCumulativePlotFlag = false; break;}
3836 +      }
3837 +      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
3838 +      
3839        //apply flags for the components of the composite object as well
3840 <      bool currentCumulativeFlag = true;
3841 <      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
3842 <      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
3843 <      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
3844 <      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
3845 <      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
3840 >      bool currentCumulativeCutFlag = true;
3841 >      bool currentCumulativePlotFlag = true;
3842 >
3843 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
3844 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
3845 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
3846 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
3847 >
3848 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
3849 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
3850 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
3851 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
3852 >
3853 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));
3854 >
3855 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3856 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
3857 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
3858 >      }
3859 >
3860 >      if (currentCumulativePlotFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3861 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
3862 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
3863 >      }
3864  
3865        counter++;
2643    }
3866  
3867 +    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
3868 +  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
3869 +
3870 + }
3871 +
3872 +
3873 + bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
3874 +  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
3875 +  // all cuts up to currentCutIndex
3876 +  bool previousCumulativeFlag = true;
3877 +  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
3878 +    bool tempFlag = false;
3879 +    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
3880 +    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
3881 +
3882 +    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
3883 +    else {
3884 +      previousCumulativeFlag = false; break;
3885 +    }
3886    }
3887 +  return previousCumulativeFlag;
3888 + }
3889  
3890  
3891 +
3892 +
3893 + template <class InputCollection>
3894 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
3895 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
3896 +
3897 +  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;
3898 +  for (uint object = 0; object != inputCollection->size(); object++) {
3899 +
3900 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
3901 +
3902 +    string inputVariable = parameters.inputVariable;
3903 +    string function = "";
3904 +    string stringValue = "";
3905 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3906 +    BNTreeBranchVals_.at(parameters.name).push_back(value);
3907 +
3908 +  }
3909   }
3910  
3911  
3912   template <class InputCollection>
3913 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3913 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
3914 >
3915  
3916    for (uint object = 0; object != inputCollection->size(); object++){
3917  
3918 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3918 >    cout << "flags.at(object).second: " << flags.at(object).second << endl;
3919 >
3920 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
3921  
3922      string currentString = parameters.inputVariables.at(0);
3923      string inputVariable = "";
3924      string function = "";
3925 <    if(currentString.find("(")==std::string::npos){
3925 >    if(currentString.find("(")==string::npos){
3926        inputVariable = currentString;// variable to cut on
3927      }
3928      else{
# Line 2667 | Line 3931 | void OSUAnalysis::fill1DHistogram(TH1* h
3931        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3932      }
3933  
3934 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
3934 >    string stringValue = "";
3935 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3936      histo->Fill(value,scaleFactor);
3937  
3938 <  }
3938 >    if (printEventInfo_) {
3939 >      // Write information about event to screen, for testing purposes.
3940 >      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
3941 >    }
3942  
3943 +  }
3944   }
3945  
3946   template <class InputCollection1, class InputCollection2>
3947 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3947 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
3948  
3949    bool sameObjects = false;
3950    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3951  
3952 <  int pairCounter = 0;
3952 >  int pairCounter = -1;
3953    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3954      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3955  
3956        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3957  
3958 +      pairCounter++;
3959        //only take objects which have passed all cuts and pairs which have passed all cuts
3960 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3961 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3962 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3960 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
3961 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
3962 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
3963  
3964        string currentString = parameters.inputVariables.at(0);
3965        string inputVariable = "";
3966        string function = "";
3967 <      if(currentString.find("(")==std::string::npos){
3967 >      if(currentString.find("(")==string::npos){
3968          inputVariable = currentString;// variable to cut on
3969        }
3970        else{
# Line 2703 | Line 3973 | void OSUAnalysis::fill1DHistogram(TH1* h
3973          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3974        }
3975  
3976 <      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3976 >      string stringValue = "";
3977 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3978        histo->Fill(value,scaleFactor);
3979  
2709      pairCounter++;
3980      }
3981    }
3982  
# Line 2714 | Line 3984 | void OSUAnalysis::fill1DHistogram(TH1* h
3984  
3985  
3986   template <class InputCollection>
3987 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3987 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
3988  
3989    for (uint object = 0; object != inputCollection->size(); object++){
3990  
3991 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3991 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
3992  
3993 +    string stringValue = "";
3994      string currentString = parameters.inputVariables.at(0);
3995      string inputVariable = "";
3996      string function = "";
3997 <    if(currentString.find("(")==std::string::npos){
3997 >    if(currentString.find("(")==string::npos){
3998        inputVariable = currentString;// variable to cut on
3999      }
4000      else{
# Line 2731 | Line 4002 | void OSUAnalysis::fill2DHistogram(TH2* h
4002        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4003        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4004      }
4005 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
4005 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4006  
4007      currentString = parameters.inputVariables.at(1);
4008      inputVariable = "";
4009      function = "";
4010 <    if(currentString.find("(")==std::string::npos){
4010 >    if(currentString.find("(")==string::npos){
4011        inputVariable = currentString;// variable to cut on
4012      }
4013      else{
# Line 2745 | Line 4016 | void OSUAnalysis::fill2DHistogram(TH2* h
4016        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4017      }
4018  
4019 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
4019 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4020  
4021      histo->Fill(valueX,valueY,scaleFactor);
4022  
# Line 2754 | Line 4025 | void OSUAnalysis::fill2DHistogram(TH2* h
4025   }
4026  
4027   template <class InputCollection1, class InputCollection2>
4028 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4028 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4029  
4030    bool sameObjects = false;
4031    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4032  
4033 <  int pairCounter = 0;
4033 >  int pairCounter = -1;
4034    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4035      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4036  
4037        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4038  
4039 +      pairCounter++;
4040 +
4041        //only take objects which have passed all cuts and pairs which have passed all cuts
4042 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4043 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4044 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4042 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4043 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4044 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4045  
4046 +      string stringValue = "";
4047        string currentString = parameters.inputVariables.at(0);
4048        string inputVariable = "";
4049        string function = "";
4050 <      if(currentString.find("(")==std::string::npos){
4050 >      if(currentString.find("(")==string::npos){
4051          inputVariable = currentString;// variable to cut on
4052        }
4053        else{
# Line 2781 | Line 4055 | void OSUAnalysis::fill2DHistogram(TH2* h
4055          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4056          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4057        }
4058 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4058 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4059  
4060        currentString = parameters.inputVariables.at(1);
4061        inputVariable = "";
4062        function = "";
4063 <      if(currentString.find("(")==std::string::npos){
4063 >      if(currentString.find("(")==string::npos){
4064          inputVariable = currentString;// variable to cut on
4065        }
4066        else{
# Line 2794 | Line 4068 | void OSUAnalysis::fill2DHistogram(TH2* h
4068          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4069          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4070        }
4071 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4071 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4072  
4073  
4074        histo->Fill(valueX,valueY,scaleFactor);
4075  
2802      pairCounter++;
2803
4076      }
4077    }
4078  
# Line 2817 | Line 4089 | int OSUAnalysis::getGenMatchedParticleIn
4089  
4090      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4091      if(currentDeltaR > 0.05) continue;
4092 < //     cout << std::setprecision(3) << std::setw(20)
4093 < //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4094 < //          << std::setw(20)
4095 < //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4096 < //          << std::setw(20)
4097 < //          << "\tdeltaR = " << currentDeltaR
4098 < //          << std::setprecision(1)
4099 < //          << std::setw(20)
4100 < //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4101 < //          << std::setw(20)
4102 < //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4103 < //          << std::setw(20)
4104 < //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4092 >    //     cout << setprecision(3) << setw(20)
4093 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4094 >    //          << setw(20)
4095 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4096 >    //          << setw(20)
4097 >    //          << "\tdeltaR = " << currentDeltaR
4098 >    //          << setprecision(1)
4099 >    //          << setw(20)
4100 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4101 >    //          << setw(20)
4102 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4103 >    //          << setw(20)
4104 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4105      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4106        bestMatchIndex = mcparticle - mcparticles->begin();
4107        bestMatchDeltaR = currentDeltaR;
4108      }
4109  
4110    }
4111 < //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4112 < //   else cout << "no match found..." << endl;
4111 >  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4112 >  //   else cout << "no match found..." << endl;
4113    return bestMatchIndex;
4114  
4115   }
# Line 2891 | Line 4163 | int OSUAnalysis::findTauMotherIndex(cons
4163   // 20        strange baryon
4164   // 21        charm baryon
4165   // 22        bottom baryon
4166 < // 23        other
4166 > // 23        QCD string
4167 > // 24        other
4168  
4169   int OSUAnalysis::getPdgIdBinValue(int pdgId){
4170  
# Line 2915 | Line 4188 | int OSUAnalysis::getPdgIdBinValue(int pd
4188    else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4189    else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4190    else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4191 +  else if(absPdgId == 92  ) binValue = 23;
4192  
4193 <  else binValue = 23;
4193 >  else binValue = 24;
4194  
4195    return binValue;
4196  
# Line 2926 | Line 4200 | const BNprimaryvertex *
4200   OSUAnalysis::chosenVertex ()
4201   {
4202    const BNprimaryvertex *chosenVertex = 0;
4203 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
4204 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
4205 <                               cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
4203 >  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4204 >    flagPair vertexFlags;
4205 >    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4206 >      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4207 >        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4208 >        break;
4209 >      }
4210 >    }
4211      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4212 <      if(!vertexFlags.at(vertexIndex)) continue;
4212 >      if(!vertexFlags.at(vertexIndex).first) continue;
4213        chosenVertex = & primaryvertexs->at(vertexIndex);
4214        break;
4215      }
4216    }
4217 <  else {
4218 <    chosenVertex = &primaryvertexs->at(0);
2940 <  }
4217 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4218 >    chosenVertex = & primaryvertexs->at (0);
4219  
4220    return chosenVertex;
4221   }
# Line 2946 | Line 4224 | const BNmet *
4224   OSUAnalysis::chosenMET ()
4225   {
4226    const BNmet *chosenMET = 0;
4227 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
4228 <    vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
4229 <                            cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
4227 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4228 >    flagPair metFlags;
4229 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4230 >      if (cumulativeFlags.at("mets").at(i).size()){
4231 >        metFlags = cumulativeFlags.at("mets").at(i);
4232 >        break;
4233 >      }
4234 >    }
4235      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4236 <      if(!metFlags.at(metIndex)) continue;
4236 >      if(!metFlags.at(metIndex).first) continue;
4237        chosenMET = & mets->at(metIndex);
4238        break;
4239      }
4240    }
4241 <  else {
4242 <    chosenMET = &mets->at(0);
2960 <  }
4241 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4242 >    chosenMET = & mets->at (0);
4243  
4244    return chosenMET;
4245   }
# Line 2966 | Line 4248 | const BNelectron *
4248   OSUAnalysis::chosenElectron ()
4249   {
4250    const BNelectron *chosenElectron = 0;
4251 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
4252 <    vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
4253 <                                 cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
4251 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4252 >    flagPair electronFlags;
4253 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4254 >      if (cumulativeFlags.at("electrons").at(i).size()){
4255 >        electronFlags = cumulativeFlags.at("electrons").at(i);
4256 >        break;
4257 >      }
4258 >    }
4259      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4260 <      if(!electronFlags.at(electronIndex)) continue;
4260 >      if(!electronFlags.at(electronIndex).first) continue;
4261        chosenElectron = & electrons->at(electronIndex);
4262        break;
4263      }
4264    }
4265 <  else {
4266 <    chosenElectron = &electrons->at(0);
2980 <  }
4265 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4266 >    chosenElectron = & electrons->at (0);
4267  
4268    return chosenElectron;
4269   }
# Line 2986 | Line 4272 | const BNmuon *
4272   OSUAnalysis::chosenMuon ()
4273   {
4274    const BNmuon *chosenMuon = 0;
4275 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
4276 <    vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
4277 <                             cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
4275 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4276 >    flagPair muonFlags;
4277 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4278 >      if (cumulativeFlags.at("muons").at(i).size()){
4279 >        muonFlags = cumulativeFlags.at("muons").at(i);
4280 >        break;
4281 >      }
4282 >    }
4283      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4284 <      if(!muonFlags.at(muonIndex)) continue;
4284 >      if(!muonFlags.at(muonIndex).first) continue;
4285        chosenMuon = & muons->at(muonIndex);
4286        break;
4287      }
4288    }
4289 <  else {
4290 <    chosenMuon = &muons->at(0);
3000 <  }
4289 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4290 >    chosenMuon = & muons->at (0);
4291  
4292    return chosenMuon;
4293   }
4294  
3005
4295   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines