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.18 by lantonel, Fri Feb 22 10:38:08 2013 UTC vs.
Revision 1.95 by jbrinson, Tue Jul 9 08:16: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 <  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
22 <  dataset_ (cfg.getParameter<std::string> ("dataset")),
23 <  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 <  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents"))
32 <
33 < {
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 >  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
36 >  applyBtagSF_ (cfg.getParameter<bool> ("applyBtagSF")),
37 >  minBtag_ (cfg.getParameter<int> ("minBtag")),
38 >  maxBtag_ (cfg.getParameter<int> ("maxBtag")),
39 >  printEventInfo_      (cfg.getParameter<bool> ("printEventInfo")),
40 >  printAllTriggers_    (cfg.getParameter<bool> ("printAllTriggers")),
41 >  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
42 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
43 >  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
44 > {
45  
46    TH1::SetDefaultSumw2 ();
47  
48    //create pile-up reweighting object, if necessary
49 <  if(datasetType_ != "data") puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
49 >  if(datasetType_ != "data") {
50 >    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
51 >    if (applyLeptonSF_){
52 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
53 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
54 >    }
55 >    if (applyBtagSF_){
56 >      bTagSFWeight_ = new BtagSFWeight;
57 >    }
58 >  }
59 >  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
60 >    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
61 >
62  
63    // Construct Cutflow Objects. These store the results of cut decisions and
64    // handle filling cut flow histograms.
65    masterCutFlow_ = new CutFlow (fs_);
37  std::vector<TFileDirectory> directories;
66  
67    //always get vertex collection so we can assign the primary vertex in the event
68 <  allNecessaryObjects.push_back("primaryvertexs");
41 <  //always make the plot of number of primary verticex (to check pile-up reweighting)
68 >  objectsToGet.push_back("primaryvertexs");
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");
75  
76    //always get the event collection to do pile-up reweighting
77 <  allNecessaryObjects.push_back("events");
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
106 >    if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
107 >    if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
108 >    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
109 >    if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
110 >    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
111 >    if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
112 >    if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
113 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
114 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
115 >    if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
116 >    if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
117 >    if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
118 >    if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
119 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
120 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
121 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
122 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
123 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
124 >        int spaceIndex = tempInputCollection.find(" ");
125 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
126 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
127 >      }
128 >      else{
129 >        objectsToGet.push_back(tempInputCollection);
130 >      }
131        objectsToPlot.push_back(tempInputCollection);
132 <      allNecessaryObjects.push_back(tempInputCollection);
133 <    }
134 <    else{//pair of objects, need to add them both to the things to allNecessaryObjects
135 <      int dashIndex = tempInputCollection.find("-");
136 <      int spaceIndex = tempInputCollection.find(" ");
137 <      int secondWordLength = spaceIndex - dashIndex;
138 <      allNecessaryObjects.push_back(tempInputCollection);
139 <      allNecessaryObjects.push_back(tempInputCollection.substr(0,dashIndex)+"s");
140 <      allNecessaryObjects.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
132 >      objectsToCut.push_back(tempInputCollection);
133 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
134 >      string obj1;
135 >      string obj2;
136 >      getTwoObjs(tempInputCollection, obj1, obj2);
137 >      string obj2ToGet = getObjToGet(obj2);
138 >      objectsToCut.push_back(tempInputCollection);
139 >      objectsToCut.push_back(obj1);
140 >      objectsToCut.push_back(obj2);
141        objectsToPlot.push_back(tempInputCollection);
142 <      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
143 <      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
144 <      }
142 >      objectsToPlot.push_back(obj1);
143 >      objectsToPlot.push_back(obj2);
144 >      objectsToGet.push_back(tempInputCollection);
145 >      objectsToGet.push_back(obj1);
146 >      objectsToGet.push_back(obj2ToGet);
147 >    } // end else
148 >
149 >
150  
151      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
152 <    
152 >
153      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
154  
155 +      vector<double> defaultValue;
156 +      defaultValue.push_back (-1.0);
157 +
158        histogram tempHistogram;
159        tempHistogram.inputCollection = tempInputCollection;
160        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
161        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
162 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
162 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
163 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
164 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
165        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
166 <      
166 >
167        histograms.push_back(tempHistogram);
168  
169      }
170 <  }
171 <  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object
170 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
171 >
172 >  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
173    sort( objectsToPlot.begin(), objectsToPlot.end() );
174    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
175  
176  
177  
178 +  //add histograms with the gen-matched id, mother id, and grandmother id
179 +  for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
180 +
181 +    string currentObject = objectsToPlot.at(currentObjectIndex);
182 +    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
183 +
184 +    histogram tempIdHisto;
185 +    histogram tempMomIdHisto;
186 +    histogram tempGmaIdHisto;
187 +    histogram tempIdVsMomIdHisto;
188 +    histogram tempIdVsGmaIdHisto;
189 +
190 +    tempIdHisto.inputCollection = currentObject;
191 +    tempMomIdHisto.inputCollection = currentObject;
192 +    tempGmaIdHisto.inputCollection = currentObject;
193 +    tempIdVsMomIdHisto.inputCollection = currentObject;
194 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
195 +
196 +    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
197 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
198 +
199 +    currentObject = currentObject.substr(0, currentObject.size()-1);
200 +    tempIdHisto.name = currentObject+"GenMatchId";
201 +    tempMomIdHisto.name = currentObject+"GenMatchMotherId";
202 +    tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
203 +    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
204 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
205 +
206 +    currentObject.at(0) = toupper(currentObject.at(0));
207 +    tempIdHisto.title = currentObject+" Gen-matched Particle";
208 +    tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
209 +    tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
210 +    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
211 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
212 +
213 +
214 +    int maxNum = 25;
215 +    vector<double> binVector;
216 +    binVector.push_back(maxNum);
217 +    binVector.push_back(0);
218 +    binVector.push_back(maxNum);
219 +
220 +    tempIdHisto.bins = binVector;
221 +    tempIdHisto.inputVariables.push_back("genMatchedId");
222 +    tempMomIdHisto.bins = binVector;
223 +    tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
224 +    tempGmaIdHisto.bins = binVector;
225 +    tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
226 +    binVector.push_back(maxNum);
227 +    binVector.push_back(0);
228 +    binVector.push_back(maxNum);
229 +    tempIdVsMomIdHisto.bins = binVector;
230 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
231 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
232 +    tempIdVsGmaIdHisto.bins = binVector;
233 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
234 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
235 +
236 +    histograms.push_back(tempIdHisto);
237 +    histograms.push_back(tempMomIdHisto);
238 +    histograms.push_back(tempGmaIdHisto);
239 +    histograms.push_back(tempIdVsMomIdHisto);
240 +    histograms.push_back(tempIdVsGmaIdHisto);
241 +  }
242 +
243  
244    channel tempChannel;
245    //loop over all channels (event selections)
# Line 99 | Line 253 | OSUAnalysis::OSUAnalysis (const edm::Par
253      //set triggers for this channel
254      vector<string> triggerNames;
255      triggerNames.clear();
256 +    vector<string> triggerToVetoNames;
257 +    triggerToVetoNames.clear();
258 +
259      tempChannel.triggers.clear();
260 +    tempChannel.triggersToVeto.clear();
261      if(channels_.at(currentChannel).exists("triggers")){
262        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
263        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
264          tempChannel.triggers.push_back(triggerNames.at(trigger));
265 <      allNecessaryObjects.push_back("triggers");
265 >      objectsToGet.push_back("triggers");
266 >    }
267 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
268 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
269 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
270 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
271 >      objectsToGet.push_back("triggers");
272      }
109
273  
274  
275  
276      //create cutFlow for this channel
277      cutFlows_.push_back (new CutFlow (fs_, channelName));
278 <
279 <    //book a directory in the output file with the name of the channel
280 <    TFileDirectory subDir = fs_->mkdir( channelName );
118 <    directories.push_back(subDir);
119 <
120 <    std::map<std::string, TH1D*> oneDhistoMap;
121 <    oneDHists_.push_back(oneDhistoMap);
122 <    std::map<std::string, TH2D*> twoDhistoMap;
123 <    twoDHists_.push_back(twoDhistoMap);
124 <
125 <
126 <    //book all histograms included in the configuration
127 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
128 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
129 <      int numBinsElements = currentHistogram.bins.size();
130 <      int numInputVariables = currentHistogram.inputVariables.size();
131 <
132 <      if(numBinsElements != 3 && numBinsElements !=6) {
133 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
134 <        exit(0);
135 <      }
136 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
137 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
138 <        exit(0);
139 <      }
140 <      else if(numBinsElements == 3){
141 <        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));
142 <      }
143 <      else if(numBinsElements == 6){
144 <        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));
145 <
146 <      }
147 <
148 <
149 <    }
150 <    //book a histogram for the number of each object type to be plotted
151 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
152 <      string currentObject = objectsToPlot.at(currentObjectIndex);
153 <      int maxNum = 10;
154 <      if(currentObject == "mcparticles") maxNum = 50;
155 <      else if(currentObject == "primaryvertexs") maxNum = 50;
156 <      else if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
157 <      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
158 <      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
159 <
160 <      currentObject.at(0) = toupper(currentObject.at(0));
161 <      string histoName = "num" + currentObject;
162 <
163 <      if(histoName == "numPrimaryvertexs"){
164 <        string newHistoName = histoName + "BeforePileupCorrection";
165 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);    
166 <        newHistoName = histoName + "AfterPileupCorrection";
167 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
168 <      }
169 <      else
170 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
171 <    }
172 <
173 <
278 >    vector<TFileDirectory> directories; //vector of directories in the output file.
279 >    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
280 >    vector<string> subSubDirNames;//subdirectories in each channel.
281      //get list of cuts for this channel
282      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
283  
284 +
285      //loop over and parse all cuts
286      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
287        cut tempCut;
288        //store input collection for cut
289        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
290 +      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
291 +      if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
292 +      if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
293 +      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
294 +      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
295 +      if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
296 +      if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
297 +      if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
298 +      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
299 +      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
300 +      if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
301 +      if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
302 +      if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
303 +      if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
304 +      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
305 +      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
306 +      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
307        tempCut.inputCollection = tempInputCollection;
308 <      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
309 <        allNecessaryObjects.push_back(tempInputCollection);
308 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
309 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
310 >          int spaceIndex = tempInputCollection.find(" ");
311 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
312 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
313 >        }
314 >        else{
315 >          objectsToGet.push_back(tempInputCollection);
316 >        }
317 >        objectsToCut.push_back(tempInputCollection);
318        }
319 <      else{//pair of objects, need to add them both to the things to allNecessaryObjects
320 <        int dashIndex = tempInputCollection.find("-");
321 <        int spaceIndex = tempInputCollection.find(" ");
322 <        int secondWordLength = spaceIndex - dashIndex;
323 <        allNecessaryObjects.push_back(tempInputCollection);
324 <        allNecessaryObjects.push_back(tempInputCollection.substr(0,dashIndex)+"s");
325 <        allNecessaryObjects.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
319 >      else{//pair of objects, need to add them both to objectsToGet
320 >        string obj1;
321 >        string obj2;
322 >        getTwoObjs(tempInputCollection, obj1, obj2);
323 >        string obj2ToGet = getObjToGet(obj2);
324 >        objectsToCut.push_back(tempInputCollection);
325 >        objectsToCut.push_back(obj1);
326 >        objectsToCut.push_back(obj2);
327 >        objectsToGet.push_back(tempInputCollection);
328 >        objectsToGet.push_back(obj1);
329 >        objectsToGet.push_back(obj2ToGet);
330  
331        }
332  
# Line 197 | Line 334 | OSUAnalysis::OSUAnalysis (const edm::Par
334  
335        //split cut string into parts and store them
336        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
337 <      std::vector<string> cutStringVector = splitString(cutString);
337 >      vector<string> cutStringVector = splitString(cutString);
338        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
339 <        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
340 <        exit(0);
339 >        cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
340 >        exit(0);
341        }
342        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
343        for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
344 <        int indexOffset = 4 * subcutIndex;
345 <        string currentVariableString = cutStringVector.at(indexOffset);
346 <        if(currentVariableString.find("(")==std::string::npos){
347 <          tempCut.functions.push_back("");//no function was specified
348 <          tempCut.variables.push_back(currentVariableString);// variable to cut on
349 <        }
350 <        else{
351 <          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
352 <          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
353 <          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
354 <        }
355 <        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
356 <        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
357 <        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
344 >        int indexOffset = 4 * subcutIndex;
345 >        string currentVariableString = cutStringVector.at(indexOffset);
346 >        if(currentVariableString.find("(")==string::npos){
347 >          tempCut.functions.push_back("");//no function was specified
348 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
349 >        }
350 >        else{
351 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
352 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
353 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
354 >        }
355 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
356 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
357 >        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
358 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
359        }
360  
361        //get number of objects required to pass cut for event to pass
362        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
363 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
363 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
364        if(numberRequiredVector.size()!=2){
365 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
365 >        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
366          exit(0);
367        }
368  
# Line 232 | Line 370 | OSUAnalysis::OSUAnalysis (const edm::Par
370        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
371        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
372  
373 <
373 >      //Set up vectors to store the directories and subDirectories for each channel.
374 >      string subSubDirName;
375        string tempCutName;
376        if(cuts_.at(currentCut).exists("alias")){
377          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
378 +        subSubDirName = "After " + tempCutName + " Cut Applied";
379        }
380        else{
381          //construct string for cutflow table
# Line 243 | Line 383 | OSUAnalysis::OSUAnalysis (const edm::Par
383          string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
384          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
385          tempCutName = cutName;
386 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
387        }
247      tempCut.name = tempCutName;
388  
389 +      tempCut.isVeto = false;
390 +      if(cuts_.at(currentCut).exists("isVeto")){
391 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
392 +        if (isVeto == true) tempCut.isVeto = true;
393 +      }
394 +      subSubDirNames.push_back(subSubDirName);
395 +      tempCut.name = tempCutName;
396  
397        tempChannel.cuts.push_back(tempCut);
398  
399  
253
400      }//end loop over cuts
401  
402 +    vector<map<string, TH1D*>> oneDHistsTmp;
403 +    vector<map<string, TH2D*>> twoDHistsTmp;
404 +    //book a directory in the output file with the name of the channel
405 +    TFileDirectory subDir = fs_->mkdir( channelName );
406 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
407 +    if(GetPlotsAfterEachCut_){
408 +      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
409 +        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
410 +        directories.push_back(subSubDir);
411 +        map<string, TH1D*> oneDhistoMap;
412 +        oneDHistsTmp.push_back(oneDhistoMap);
413 +        map<string, TH2D*> twoDhistoMap;
414 +        twoDHistsTmp.push_back(twoDhistoMap);
415 +      }
416 +      treeDirectories.push_back(subDir);
417 +      oneDHists_.push_back(oneDHistsTmp);
418 +      twoDHists_.push_back(twoDHistsTmp);
419 +    }
420 +    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
421 +    else{
422 +      map<string, TH1D*> oneDhistoMap;
423 +      oneDHistsTmp.push_back(oneDhistoMap);
424 +      map<string, TH2D*> twoDhistoMap;
425 +      twoDHistsTmp.push_back(twoDhistoMap);
426 +      oneDHists_.push_back(oneDHistsTmp);
427 +      twoDHists_.push_back(twoDHistsTmp);
428 +      directories.push_back(subDir);
429 +      treeDirectories.push_back(subDir);
430 +
431 +    }
432 +
433 +    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
434 +      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
435 +      BNTrees_.push_back(newTree);
436 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
437 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
438 +        vector<float> newVec;
439 +        BNTreeBranchVals_[currentVar.name] = newVec;
440 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
441 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
442 +    }
443 +
444 +    //book all histograms included in the configuration
445 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
446 +
447 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
448 +
449 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
450 +        int numBinsElements = currentHistogram.bins.size();
451 +        int numInputVariables = currentHistogram.inputVariables.size();
452 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
453 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
454 +
455 +        if(numBinsElements == 1){
456 +          if(numBinEdgesX > 1){
457 +            if(numBinEdgesY > 1)
458 +              numBinsElements = 6;
459 +            else
460 +              numBinsElements = 3;
461 +          }
462 +        }
463 +        if(numBinsElements != 3 && numBinsElements !=6){
464 +          cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
465 +          exit(0);
466 +        }
467 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
468 +          cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
469 +          exit(0);
470 +        }
471 +        else if(numBinsElements == 3){
472 +          if (currentHistogram.bins.size () == 3)
473 +            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));
474 +          else
475 +            {
476 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
477 +            }
478 +        }
479 +        else if(numBinsElements == 6){
480 +          if (currentHistogram.bins.size () == 6)
481 +            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));
482 +          else
483 +            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 ());
484 +        }
485 +
486 +
487 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
488 +
489 +        // bin      particle type
490 +        // ---      -------------
491 +        //  0        unmatched
492 +        //  1        u
493 +        //  2        d
494 +        //  3        s
495 +        //  4        c
496 +        //  5        b
497 +        //  6        t
498 +        //  7        e
499 +        //  8        mu
500 +        //  9        tau
501 +        // 10        nu
502 +        // 11        g
503 +        // 12        gamma
504 +        // 13        Z
505 +        // 14        W
506 +        // 15        light meson
507 +        // 16        K meson
508 +        // 17        D meson
509 +        // 18        B meson
510 +        // 19        light baryon
511 +        // 20        strange baryon
512 +        // 21        charm baryon
513 +        // 22        bottom baryon
514 +        // 23        QCD string
515 +        // 24        other
516 +
517 +        vector<TString> labelArray;
518 +        labelArray.push_back("unmatched");
519 +        labelArray.push_back("u");
520 +        labelArray.push_back("d");
521 +        labelArray.push_back("s");
522 +        labelArray.push_back("c");
523 +        labelArray.push_back("b");
524 +        labelArray.push_back("t");
525 +        labelArray.push_back("e");
526 +        labelArray.push_back("#mu");
527 +        labelArray.push_back("#tau");
528 +        labelArray.push_back("#nu");
529 +        labelArray.push_back("g");
530 +        labelArray.push_back("#gamma");
531 +        labelArray.push_back("Z");
532 +        labelArray.push_back("W");
533 +        labelArray.push_back("light meson");
534 +        labelArray.push_back("K meson");
535 +        labelArray.push_back("D meson");
536 +        labelArray.push_back("B meson");
537 +        labelArray.push_back("light baryon");
538 +        labelArray.push_back("strange baryon");
539 +        labelArray.push_back("charm baryon");
540 +        labelArray.push_back("bottom baryon");
541 +        labelArray.push_back("QCD string");
542 +        labelArray.push_back("other");
543 +
544 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
545 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
546 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
547 +          }
548 +          else {
549 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
550 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
551 +          }
552 +        }
553 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
554 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
555 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
556 +        }
557 +
558 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
559 +
560 +
561 +      // Book a histogram for the number of each object type to be plotted.
562 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
563 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
564 +        string currentObject = objectsToPlot.at(currentObjectIndex);
565 +        int maxNum = 10;
566 +        if(currentObject == "mcparticles") maxNum = 50;
567 +        else if(currentObject == "primaryvertexs") maxNum = 50;
568 +
569 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
570 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
571 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
572 +        else if(currentObject == "electron-photon pairs")     currentObject = "electronPhotonPairs";
573 +        else if(currentObject == "muon-photon pairs")         currentObject = "muonPhotonPairs";
574 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
575 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
576 +        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
577 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
578 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
579 +        else if(currentObject == "photon-jet pairs")          currentObject = "photonJetPairs";
580 +        else if(currentObject == "met-jet pairs")             currentObject = "metJetPairs";
581 +        else if(currentObject == "track-jet pairs")           currentObject = "trackJetPairs";
582 +        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
583 +        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
584 +        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
585 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
586 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
587 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
588 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
589 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
590 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
591 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
592 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
593 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
594 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
595 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
596 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
597 +
598 +        currentObject.at(0) = toupper(currentObject.at(0));
599 +        string histoName = "num" + currentObject;
600 +
601 +        if(histoName == "numPrimaryvertexs"){
602 +          string newHistoName = histoName + "BeforePileupCorrection";
603 +          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);
604 +          newHistoName = histoName + "AfterPileupCorrection";
605 +          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);
606 +        }
607 +        else
608 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
609 +      }
610 +    }//end of loop over directories
611      channels.push_back(tempChannel);
612      tempChannel.cuts.clear();
258
613    }//end loop over channels
614  
615  
616 <  //make unique vector of objects we need to cut on (so we make sure to get them from the event)
617 <  sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
618 <  allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
616 >  //make unique vector of objects we need to get from the event
617 >  sort( objectsToGet.begin(), objectsToGet.end() );
618 >  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
619 >  //make unique vector of objects we need to cut on
620 >  sort( objectsToCut.begin(), objectsToCut.end() );
621 >  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
622  
623 +  produces<map<string, bool> > ("channelDecisions");
624 +
625 + } // end constructor OSUAnalysis::OSUAnalysis()
626  
267 }
627  
628   OSUAnalysis::~OSUAnalysis ()
629   {
630 +
631    // Destroying the CutFlow objects causes the cut flow numbers and time
632    // information to be printed to standard output.
633    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
634      delete cutFlows_.at(currentChannel);
635    }
636 +
637 +  cout << "=============================================" << endl;  
638 +  cout << "Successfully completed OSUAnalysis." << endl;  
639 +  cout << "=============================================" << endl;  
640 +
641   }
642  
643   void
644 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
644 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
645   {
281
282
646    // Retrieve necessary collections from the event.
647 <  edm::Handle<BNtriggerCollection> triggers;
648 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
647 >
648 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
649      event.getByLabel (triggers_, triggers);
650  
651 <  edm::Handle<BNjetCollection> jets;
652 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())
651 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
652 >    event.getByLabel (trigobjs_, trigobjs);
653 >
654 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
655      event.getByLabel (jets_, jets);
656  
657 <  edm::Handle<BNmuonCollection> muons;
293 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())
657 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
658      event.getByLabel (muons_, muons);
659  
660 <  edm::Handle<BNelectronCollection> electrons;
297 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())
660 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
661      event.getByLabel (electrons_, electrons);
662  
663 <  edm::Handle<BNeventCollection> events;
301 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())
663 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
664      event.getByLabel (events_, events);
665  
666 <  edm::Handle<BNtauCollection> taus;
305 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())
666 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
667      event.getByLabel (taus_, taus);
668  
669 <  edm::Handle<BNmetCollection> mets;
309 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())
669 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
670      event.getByLabel (mets_, mets);
671  
672 <  edm::Handle<BNtrackCollection> tracks;
313 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())
672 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
673      event.getByLabel (tracks_, tracks);
674  
675 <  edm::Handle<BNgenjetCollection> genjets;
317 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())
675 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
676      event.getByLabel (genjets_, genjets);
677  
678 <  edm::Handle<BNmcparticleCollection> mcparticles;
321 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())
678 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
679      event.getByLabel (mcparticles_, mcparticles);
680  
681 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
325 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())
681 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
682      event.getByLabel (primaryvertexs_, primaryvertexs);
683  
684 <  edm::Handle<BNbxlumiCollection> bxlumis;
329 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())
684 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
685      event.getByLabel (bxlumis_, bxlumis);
686  
687 <  edm::Handle<BNphotonCollection> photons;
333 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())
687 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
688      event.getByLabel (photons_, photons);
689  
690 <  edm::Handle<BNsuperclusterCollection> superclusters;
337 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())
690 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
691      event.getByLabel (superclusters_, superclusters);
692  
693 +  if (datasetType_ == "signalMC"){
694 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
695 +      event.getByLabel (stops_, stops);
696 +  }
697 +
698 +  if (useTrackCaloRhoCorr_) {
699 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
700 +    // This rho collection is not available in all BEANs.
701 +    // For description of rho values for different jet reconstruction algorithms, see
702 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
703 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
704 +  }
705 +
706 +  double masterScaleFactor = 1.0;
707  
708    //get pile-up event weight
709 <  double puScaleFactor = 0;
710 <  if(datasetType_ != "data")
711 <    puScaleFactor = puWeight_->at (events->at (0).numTruePV);
712 <  else
713 <    puScaleFactor = 1.00;
709 >  if (doPileupReweighting_ && datasetType_ != "data") {
710 >    //for "data" datasets, the numTruePV is always set to -1
711 >    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
712 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
713 >  }
714  
715 +  stopCTauScaleFactor_ = 1.0;
716 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
717 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
718 +  masterScaleFactor *= stopCTauScaleFactor_;
719  
720    //loop over all channels
721  
722 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
723    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
724      channel currentChannel = channels.at(currentChannelIndex);
725  
726      flagMap individualFlags;
355    flagMap cumulativeFlags;
727      counterMap passingCounter;
728 +    cumulativeFlags.clear ();
729 +
730 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
731 +         iter != BNTreeBranchVals_.end(); iter++) {
732 +      iter->second.clear();  // clear array
733 +    }
734  
735      bool triggerDecision = true;
736 <    if(currentChannel.triggers.size() != 0){  //triggers specified
737 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
736 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
737 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
738        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
739      }
740  
741      //loop over all cuts
742      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
743        cut currentCut = currentChannel.cuts.at(currentCutIndex);
744 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
745 +        string currentObject = objectsToCut.at(currentObjectIndex);
746  
747 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
748 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
747 >        //initialize maps to get ready to set cuts
748 >        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
749 >        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
750  
751 <        individualFlags[currentObject].push_back (vector<bool> ());
752 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
751 >      }
752 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
753 >        string currentObject = objectsToCut.at(currentObjectIndex);
754  
755 +        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
756  
757 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
758 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
757 >
758 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
759 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
760 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
761 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
762 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
763          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
764          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
765          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 385 | Line 771 | OSUAnalysis::analyze (const edm::Event &
771          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
772          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
773          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
774 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
775  
389        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(),"muon-muon pairs");
390        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(),"electron-electron pairs");
391        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(),"electron-muon pairs");
392
393      }
776  
777  
778 +        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
779 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
780 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
781 +                                                                   "muon-muon pairs");
782 +
783 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
784 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
785 +                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
786 +                                                                             "muon-secondary muon pairs");
787 +
788 +        else if(currentObject == "muon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
789 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
790 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
791 +                                                                             "muon-secondary jet pairs");
792 +        else if(currentObject == "photon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
793 +                                                                             cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
794 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
795 +                                                                             "photon-secondary jet pairs");
796 +
797 +        else if(currentObject == "electron-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
798 +                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
799 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
800 +                                                                             "electron-secondary jet pairs");
801 +
802 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
803 +                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
804 +                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
805 +                                                                                     "electron-secondary electron pairs");
806 +
807 +        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
808 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
809 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
810 +                                                                           "electron-electron pairs");
811 +        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
812 +                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
813 +                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
814 +                                                                       "electron-muon pairs");
815 +        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
816 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
817 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
818 +                                                                 "jet-jet pairs");
819 +        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
820 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
821 +                                                                 cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex),\
822 +                                                                 "jet-secondary jet pairs");
823 +        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
824 +                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
825 +                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
826 +                                                                      "electron-jet pairs");
827 +        else if(currentObject == "electron-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), \
828 +                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
829 +                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
830 +                                                                      "electron-photon pairs");
831 +        else if(currentObject == "photon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
832 +                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
833 +                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
834 +                                                                      "photon-jet pairs");
835 +        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
836 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
837 +                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
838 +                                                                  "muon-jet pairs");
839 +        else if(currentObject == "met-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),jets.product(), \
840 +                                                                  cumulativeFlags.at("mets").at(flagsForPairCutsIndex), \
841 +                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
842 +                                                                  "met-jet pairs");
843 +        else if(currentObject == "track-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),jets.product(), \
844 +                                                                 cumulativeFlags.at("tracks").at(flagsForPairCutsIndex), \
845 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
846 +                                                                 "track-jet pairs");
847 +        else if(currentObject == "muon-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
848 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
849 +                                                                  cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
850 +                                                                  "muon-photon pairs");
851 +        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
852 +                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
853 +                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
854 +                                                                     "track-event pairs");
855 +        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
856 +                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
857 +                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
858 +                                                                        "electron-track pairs");
859 +        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
860 +                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
861 +                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
862 +                                                                    "muon-track pairs");
863 +        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
864 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
865 +                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
866 +                                                                  "muon-tau pairs");
867 +        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
868 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
869 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
870 +                                                                 "tau-tau pairs");
871 +        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
872 +                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
873 +                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
874 +                                                                   "tau-track pairs");
875 +        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
876 +                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
877 +                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
878 +                                                                          "electron-trigobj pairs");
879 +        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
880 +                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
881 +                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
882 +                                                                      "muon-trigobj pairs");
883  
884 <    }//end loop over all cuts
884 >        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
885 >      }
886  
887  
888  
889 +    }//end loop over all cuts
890      //use cumulative flags to apply cuts at event level
891  
892 +    //a vector to store cumulative cut descisions after each cut.
893 +    vector<bool> eventPassedPreviousCuts;
894      bool eventPassedAllCuts = true;
404
895      //apply trigger (true if none were specified)
896      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
897  
408
898      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
899  
900        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 413 | Line 902 | OSUAnalysis::analyze (const edm::Event &
902        int numberPassing = 0;
903  
904        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
905 <          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
905 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
906        }
418
907        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
908        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
421
909        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
910 +      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
911 +    }
912 +    double scaleFactor = masterScaleFactor;
913  
914 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
915 +    if(applyLeptonSF_ && datasetType_ != "data"){
916 +      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
917 +        flagPair muonFlags;
918 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
919 +          if (cumulativeFlags.at("muons").at(i).size()){
920 +            muonFlags = cumulativeFlags.at("muons").at(i);
921 +            break;
922 +          }
923 +        }
924 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
925 +          if(!muonFlags.at(muonIndex).second) continue;
926 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
927 +        }
928 +      }
929 +      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
930 +        flagPair electronFlags;
931 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
932 +          if (cumulativeFlags.at("electrons").at(i).size()){
933 +            electronFlags = cumulativeFlags.at("electrons").at(i);
934 +            break;
935 +          }
936 +        }
937 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
938 +          if(!electronFlags.at(electronIndex).second) continue;
939 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
940 +        }
941 +      }
942 +    }
943 +    if(applyBtagSF_ && datasetType_ != "data"){
944 +     if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
945 +       flagPair jetFlags;
946 +        vector<double> jetSFs;
947 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
948 +          if (cumulativeFlags.at("jets").at(i).size()){
949 +            jetFlags = cumulativeFlags.at("jets").at(i);
950 +            break;
951 +          }
952 +        }
953 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
954 +          if(!jetFlags.at(jetIndex).second) continue;
955 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour);
956 +          jetSFs.push_back(jetSFTmp);
957 +        }
958 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_, maxBtag_ );
959 +      }
960 +    }
961 +    scaleFactor *= muonScaleFactor_;
962 +    scaleFactor *= electronScaleFactor_;
963 +    scaleFactor *= bTagScaleFactor_;
964 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
965 +
966 +    if (printEventInfo_) {
967 +      // Write information about event to screen, for testing purposes.
968 +      cout << "Event passed all cuts in channel " <<  currentChannel.name
969 +           << ": run="  << events->at(0).run
970 +           << "  lumi=" << events->at(0).lumi
971 +           << "  event=" << events->at(0).evt
972 +           << endl;
973      }
974  
426    cutFlows_.at(currentChannelIndex)->fillCutFlow(puScaleFactor);
975  
976 +    //filling histograms
977 +    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
978 +      uint currentDir;
979 +      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
980 +      else{
981 +        currentDir = currentCut;
982 +      }
983  
984  
985 <    if(!eventPassedAllCuts)continue;
985 >      if(eventPassedPreviousCuts.at(currentDir)){
986  
987 +        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
988 +          histogram currentHistogram = histograms.at(histogramIndex);
989  
990 +          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) cout << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
991  
992 +          if(currentHistogram.inputVariables.size() == 1){
993 +            TH1D* histo;
994 +            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
995 +            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
996 +            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
997 +            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
998 +            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
999 +            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1000 +            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1001 +                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1002 +                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1003 +            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1004 +                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1005 +                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1006 +             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1007 +                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1008 +                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1009 +             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1010 +                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1011 +                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1012 +             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1013 +                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1014 +                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1015 +
1016 +            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1017 +            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
1018 +                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
1019 +                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1020 +            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
1021 +                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
1022 +                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1023 +             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1024 +                                                                                                     cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1025 +                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1026 +
1027 +            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1028 +                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1029 +                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1030 +            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
1031 +                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
1032 +                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1033 +            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
1034 +                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1035 +                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1036 +            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(), \
1037 +                                                                                              cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1038 +                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1039 +            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
1040 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1041 +                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1042 +            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, mets.product(),jets.product(), \
1043 +                                                                                          cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1044 +                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1045 +            else if(currentHistogram.inputCollection == "track-jet pairs")  fill1DHistogram(histo,currentHistogram,tracks.product(),jets.product(), \
1046 +                                                                                          cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1047 +                                                                                          cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1048 +            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(), \
1049 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1050 +                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1051 +            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(), \
1052 +                                                                                          cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1053 +                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1054 +            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1055 +                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1056 +                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1057 +            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1058 +                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1059 +                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1060 +            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1061 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1062 +                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1063 +            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1064 +                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1065 +                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1066 +            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1067 +                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1068 +                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1069 +            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1070 +                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1071 +                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1072 +            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1073 +                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1074 +                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1075 +
1076 +            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1077 +            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1078 +            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1079 +            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1080 +            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1081 +            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1082 +            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1083 +            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1084 +            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1085 +            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1086 +            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1087 +            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1088 +          }
1089 +          else if(currentHistogram.inputVariables.size() == 2){
1090 +            TH2D* histo;
1091 +            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1092 +            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1093 +            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1094 +            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1095 +            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1096 +            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1097 +                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1098 +                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1099 +            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1100 +                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1101 +                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1102 +            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1103 +                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1104 +                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1105 +            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1106 +                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1107 +                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1108 +            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1109 +                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1110 +                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1111 +            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1112 +            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1113 +            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1114 +                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1115 +                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1116 +            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1117 +                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1118 +                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1119 +            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1120 +                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1121 +                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1122 +            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1123 +                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1124 +                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1125 +            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1126 +                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1127 +                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1128 +            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(), \
1129 +                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1130 +                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1131 +            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1132 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1133 +                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1134 +            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,mets.product(),jets.product(), \
1135 +                                                                                         cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1136 +                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1137 +            else if(currentHistogram.inputCollection == "track-jet pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1138 +                                                                                         cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1139 +                                                                                         cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1140 +            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1141 +                                                                                          cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1142 +                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1143 +            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1144 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1145 +                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1146 +            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1147 +                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1148 +                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1149 +            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1150 +                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1151 +                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1152 +            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1153 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1154 +                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1155 +            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1156 +                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1157 +                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1158 +            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1159 +                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1160 +                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1161 +            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1162 +                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1163 +                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1164 +            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1165 +                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1166 +                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1167 +            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1168 +            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1169 +            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1170 +            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1171 +            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1172 +                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1173 +                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1174 +            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1175 +            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1176 +            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1177 +            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1178 +            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1179 +            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1180 +            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1181 +            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1182 +          }
1183  
1184 <    //set position of primary vertex in event, in order to calculate quantities relative to it
436 <    primaryVertex_ = 0;
437 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back();
438 <    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
439 <      if(!vertexFlags.at(vertexIndex)) continue;
440 <      primaryVertex_ = new BNprimaryvertex (primaryvertexs->at (vertexIndex));
441 <      break;
442 <    }
1184 >        }
1185  
1186  
1187 +        //fills histograms with the sizes of collections
1188 +        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1189  
1190 <    //filling histograms
1191 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1192 <      histogram currentHistogram = histograms.at(histogramIndex);
1190 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1191 >          string objectToPlot = "";
1192 >
1193 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1194 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1195 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1196 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1197 >          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1198 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1199 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1200 >          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1201 >          else if(currentObject == "track-jet pairs")                    objectToPlot = "trackJetPairs";
1202 >          else if(currentObject == "muon-photon pairs")                  objectToPlot = "muonPhotonPairs";
1203 >          else if(currentObject == "photon-jet pairs")                   objectToPlot = "photonJetPairs";
1204 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1205 >          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1206 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1207 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1208 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1209 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1210 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1211 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1212 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1213 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1214 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1215 >          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1216 >          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1217 >          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1218 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1219 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1220 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1221 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1222 >          else objectToPlot = currentObject;
1223 >
1224 >          string tempCurrentObject = objectToPlot;
1225 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1226 >          string histoName = "num" + tempCurrentObject;
1227 >
1228 >
1229 >          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1230 >            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1231 >            int numToPlot = 0;
1232 >            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1233 >              if(lastCutFlags.at(currentFlag).second) numToPlot++;
1234 >            }
1235 >
1236 >            if(objectToPlot == "primaryvertexs"){
1237 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1238 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1239 >            }
1240 >            else {
1241 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1242 >            }
1243 >          }
1244 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1245  
450      if(currentHistogram.inputVariables.size() == 1){
451        TH1D* histo;
452        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
453        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
454        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
455        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),\
456                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(),\
457                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
458        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
459        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
460                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
461                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
462        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
463                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
464                                                                                              cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
465        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
466        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
467        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
468        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
469        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
470        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
471        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
472        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
473        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
474        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
475      }
476      else if(currentHistogram.inputVariables.size() == 2){
477        TH2D* histo;
478        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
479        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
480        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
481        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
482                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
483                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
484        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
485        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
486                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
487                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
488        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
489                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
490                                                                                               cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
491        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
492        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
493        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
494        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
495        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
496        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
497        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
498        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
499        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
500        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
501      }
502    }
503
504
505    //fills histograms with the sizes of collections
506    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
507      string currentObject = objectsToPlot.at(currentObjectIndex);
508
509      if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
510      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
511      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
512      string tempCurrentObject = currentObject;
513      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
514      string histoName = "num" + tempCurrentObject;
515
516
517      if(currentObject == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),puScaleFactor);
518      else if(currentObject == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),puScaleFactor);
519      else if(currentObject == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,puScaleFactor);
520      else if(currentObject == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),puScaleFactor);
521      else if(currentObject == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,puScaleFactor);
522      else if(currentObject == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),puScaleFactor);
523      else if(currentObject == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),puScaleFactor);
524      else if(currentObject == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),puScaleFactor);
525      else if(currentObject == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),puScaleFactor);
526      else if(currentObject == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),puScaleFactor);
527      else if(currentObject == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),puScaleFactor);
528      else if(currentObject == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),puScaleFactor);
529      else if(currentObject == "primaryvertexs"){
530        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
531        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),puScaleFactor);
532      }
533      else if(currentObject == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),puScaleFactor);
534      else if(currentObject == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),puScaleFactor);
535      else if(currentObject == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),puScaleFactor);
1246  
1247 +      } // end if(eventPassedPreviousCuts.at(currentDir))
1248 +    } // end loop over cuts
1249 +
1250 +    if (!useEDMFormat_ && eventPassedAllCuts){
1251 +      // Assign BNTree variables
1252 +      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1253 +        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1254 +        string coll = brSpecs.inputCollection;
1255 +        if (cumulativeFlags.count(coll) == 0) cout << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1256 +
1257 +        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1258 +        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1259 +        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1260 +        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1261 +        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1262 +        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1263 +        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1264 +        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1265 +        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1266 +        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1267 +        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1268 +        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1269 +        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1270 +        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1271 +        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1272 +        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1273 +        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1274 +        else if(coll == "stops"
1275 +                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1276 +      } // end loop over branches
1277 +
1278 +      if (!BNTrees_.at(currentChannelIndex)) { cout << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1279 +      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1280      }
538  } //end loop over channel
1281  
1282 <  masterCutFlow_->fillCutFlow(puScaleFactor);
1282 >    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1283  
1284 +  } // end loop over channel
1285  
1286 +  masterCutFlow_->fillCutFlow(masterScaleFactor);
1287 +
1288 +  event.put (channelDecisions, "channelDecisions");
1289 +
1290 + } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1291  
544 }
1292  
1293  
1294   bool
# Line 555 | Line 1302 | OSUAnalysis::evaluateComparison (double
1302    else if(comparison == "==") return testValue == cutValue;
1303    else if(comparison == "=") return testValue == cutValue;
1304    else if(comparison == "!=") return testValue != cutValue;
1305 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1305 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1306  
1307   }
1308  
1309   bool
1310 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1310 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1311 >
1312  
1313 +  if(comparison == ">")       return testValue >  cutValue;
1314 +  else if(comparison == ">=") return testValue >= cutValue;
1315 +  else if(comparison == "<")  return testValue <  cutValue;
1316 +  else if(comparison == "<=") return testValue <= cutValue;
1317 +  else if(comparison == "==") return testValue == cutValue;
1318 +  else if(comparison == "=") return testValue == cutValue;
1319 +  else if(comparison == "!=") return testValue != cutValue;
1320 +  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1321 +
1322 + }
1323 +
1324 + bool
1325 + OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1326 +
1327 +  //initialize to false until a chosen trigger is passed
1328    bool triggerDecision = false;
1329  
1330 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1331 <    {
1332 <      if(trigger->pass != 1) continue;
1333 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1334 <        {
1335 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1336 <            triggerDecision = true;
1337 <          }
1338 <        }
1330 >  if (printAllTriggers_) cout << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1331 >  //loop over all triggers defined in the event
1332 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1333 >
1334 >    if (printAllTriggers_) cout << "   " << trigger->name << endl;
1335 >
1336 >    //we're only interested in triggers that actually passed
1337 >    if(trigger->pass != 1) continue;
1338 >
1339 >    //if the event passes one of the veto triggers, exit and return false
1340 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1341 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1342 >    }
1343 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1344 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1345 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1346      }
1347 <  return triggerDecision;
1347 >  }
1348 >
1349 >  printAllTriggers_ = false;  // only print triggers once, not every event
1350  
1351 +  //if none of the veto triggers fired:
1352 +  //return the OR of all the chosen triggers
1353 +  if (triggersToTest.size() != 0) return triggerDecision;
1354 +  //or if no triggers were defined return true
1355 +  else return true;
1356   }
1357  
1358 < std::vector<std::string>
1358 >
1359 > vector<string>
1360   OSUAnalysis::splitString (string inputString){
1361  
1362 <  std::stringstream stringStream(inputString);
1363 <  std::istream_iterator<std::string> begin(stringStream);
1364 <  std::istream_iterator<std::string> end;
1365 <  std::vector<std::string> stringVector(begin, end);
1362 >  stringstream stringStream(inputString);
1363 >  istream_iterator<string> begin(stringStream);
1364 >  istream_iterator<string> end;
1365 >  vector<string> stringVector(begin, end);
1366    return stringVector;
1367  
1368   }
1369  
1370 +
1371 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1372 +  // Set two object strings from the tempInputCollection string,
1373 +  // For example, if tempInputCollection is "electron-muon pairs",
1374 +  // then obj1 = "electrons" and obj2 = "muons".
1375 +  // Note that the objects have an "s" appended.
1376 +
1377 +  int dashIndex = tempInputCollection.find("-");
1378 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1379 +  int secondWordLength = spaceIndex - dashIndex;
1380 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1381 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1382 +
1383 + }
1384 +
1385 +
1386 + string OSUAnalysis::getObjToGet(string obj) {
1387 +  // Return the string corresponding to the object to get for the given obj string.
1388 +  // Right now this only handles the case in which obj contains "secondary",
1389 +  // e.g, "secondary muons".
1390 +  // Note that "s" is NOT appended.
1391 +
1392 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1393 +  int firstSpaceIndex = obj.find_first_of(" ");
1394 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1395 +
1396 + }
1397 +
1398 +
1399 + //!jet valueLookup
1400   double
1401 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1401 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1402  
1403    double value = 0.0;
1404    if(variable == "energy") value = object->energy;
# Line 709 | Line 1517 | OSUAnalysis::valueLookup (const BNjet* o
1517    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1518    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1519  
1520 +  //user defined variable
1521 +  else if(variable == "disappTrkLeadingJetID") {
1522 +    value = object->pt > 110
1523 +      && fabs(object->eta) < 2.4
1524 +      && object->chargedHadronEnergyFraction > 0.2
1525 +      && object->neutralHadronEnergyFraction < 0.7
1526 +      && object->chargedEmEnergyFraction < 0.5
1527 +      && object->neutralEmEnergyFraction < 0.7;
1528 +  }
1529 +
1530 +  else if(variable == "disappTrkSubLeadingJetID") {
1531 +    value = object->pt > 30
1532 +      && fabs(object->eta) < 4.5
1533 +      && object->neutralHadronEnergyFraction < 0.7
1534 +      && object->chargedEmEnergyFraction < 0.5;
1535 +  }
1536 +
1537 +  else if(variable == "dPhiMet") {
1538 +    if (const BNmet *met = chosenMET ()) {
1539 +      value = deltaPhi (object->phi, met->phi);
1540 +    } else value = -999;
1541 +  }
1542  
1543 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1543 >
1544 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1545  
1546    value = applyFunction(function, value);
1547  
1548    return value;
1549 < }
719 <
1549 > } // end jet valueLookup
1550  
1551  
1552 + //!muon valueLookup
1553   double
1554 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1554 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1555  
1556    double value = 0.0;
1557    if(variable == "energy") value = object->energy;
# Line 736 | Line 1567 | OSUAnalysis::valueLookup (const BNmuon*
1567    else if(variable == "ecalIso") value = object->ecalIso;
1568    else if(variable == "hcalIso") value = object->hcalIso;
1569    else if(variable == "caloIso") value = object->caloIso;
1570 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
1570 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
1571    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
1572    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
1573    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 875 | Line 1706 | OSUAnalysis::valueLookup (const BNmuon*
1706    else if(variable == "time_ndof") value = object->time_ndof;
1707  
1708    //user-defined variables
1709 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1710 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1711 <  else if(variable == "detIso") value = (object->trackIso) / object->pt;
1712 <  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1709 >  else if(variable == "looseID") {
1710 >    value = object->pt > 10 &&
1711 >      (object->isGlobalMuon  > 0 ||
1712 >       object->isTrackerMuon > 0);
1713 >  }
1714 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1715 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1716 >  else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1717 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1718    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1719 +  else if(variable == "metMT") {
1720 +    if (const BNmet *met = chosenMET ())
1721 +      {
1722 +        double dPhi = deltaPhi (object->phi, met->phi);
1723 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1724 +      }
1725 +    else
1726 +      value = -999;
1727 +  }
1728 +
1729 +
1730 +
1731 +  else if(variable == "correctedD0VertexInEBPlus"){
1732 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1733 +    else value = -999;
1734 +  }
1735 +  else if(variable == "correctedD0VertexOutEBPlus"){
1736 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1737 +    else value = -999;
1738 +  }
1739 +  else if(variable == "correctedD0VertexEEPlus"){
1740 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1741 +    else value = -999;
1742 +  }
1743 +
1744 +  else if(variable == "correctedD0BeamspotInEBPlus"){
1745 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1746 +    else value = -999;
1747 +  }
1748 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
1749 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1750 +    else value = -999;
1751 +  }
1752 +  else if(variable == "correctedD0BeamspotEEPlus"){
1753 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1754 +    else value = -999;
1755 +  }
1756 +
1757 +  else if(variable == "correctedD0VertexInEBMinus"){
1758 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1759 +    else value = -999;
1760 +  }
1761 +  else if(variable == "correctedD0VertexOutEBMinus"){
1762 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1763 +    else value = -999;
1764 +  }
1765 +  else if(variable == "correctedD0VertexEEMinus"){
1766 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1767 +    else value = -999;
1768 +  }
1769 +
1770 +  else if(variable == "correctedD0BeamspotInEBMinus"){
1771 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1772 +    else value = -999;
1773 +  }
1774 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
1775 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1776 +    else value = -999;
1777 +  }
1778 +  else if(variable == "correctedD0BeamspotEEMinus"){
1779 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1780 +    else value = -999;
1781 +  }
1782 +
1783 +
1784 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1785 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1786 +    else value = -999;
1787 +  }
1788 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1789 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1790 +    else value = -999;
1791 +  }
1792 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
1793 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1794 +    else value = -999;
1795 +  }
1796 +
1797 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1798 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1799 +    else value = -999;
1800 +  }
1801 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1802 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1803 +    else value = -999;
1804 +  }
1805 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1806 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1807 +    else value = -999;
1808 +  }
1809 +
1810 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1811 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1812 +    else value = -999;
1813 +  }
1814 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1815 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1816 +    else value = -999;
1817 +  }
1818 +  else if(variable == "correctedD0VertexEENegativeCharge"){
1819 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1820 +    else value = -999;
1821 +  }
1822 +
1823 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1824 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1825 +    else value = -999;
1826 +  }
1827 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1828 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1829 +    else value = -999;
1830 +  }
1831 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1832 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1833 +    else value = -999;
1834 +  }
1835 +
1836 +
1837    else if(variable == "tightID") {
1838 <    value = object->isGlobalMuon > 0            \
1839 <      && object->isPFMuon > 0                   \
1840 <      && object->normalizedChi2 < 10            \
1841 <      && object->numberOfValidMuonHits > 0      \
1842 <      && object->numberOfMatchedStations > 1    \
1843 <      && fabs(object->correctedD0Vertex) < 0.2  \
1844 <      && fabs(object->correctedDZ) < 0.5        \
1845 <      && object->numberOfValidPixelHits > 0     \
1838 >    value = object->isGlobalMuon > 0                \
1839 >      && object->isPFMuon > 0                        \
1840 >      && object->normalizedChi2 < 10                \
1841 >      && object->numberOfValidMuonHits > 0        \
1842 >      && object->numberOfMatchedStations > 1        \
1843 >      && fabs(object->correctedD0Vertex) < 0.2        \
1844 >      && fabs(object->correctedDZ) < 0.5        \
1845 >      && object->numberOfValidPixelHits > 0                \
1846        && object->numberOfLayersWithMeasurement > 5;
893    
894
1847    }
1848    else if(variable == "tightIDdisplaced"){
1849 <    value = object->isGlobalMuon > 0            \
1850 <      && object->isPFMuon > 0                   \
1851 <      && object->normalizedChi2 < 10            \
1852 <      && object->numberOfValidMuonHits > 0      \
1853 <      && object->numberOfMatchedStations > 1    \
1854 <      && object->numberOfValidPixelHits > 0     \
1849 >    value = object->isGlobalMuon > 0                \
1850 >      && object->isPFMuon > 0                        \
1851 >      && object->normalizedChi2 < 10                \
1852 >      && object->numberOfValidMuonHits > 0        \
1853 >      && object->numberOfMatchedStations > 1        \
1854 >      && object->numberOfValidPixelHits > 0        \
1855        && object->numberOfLayersWithMeasurement > 5;
1856    }
1857  
1858 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1858 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1859 >
1860 >  else if(variable == "genMatchedPdgId"){
1861 >    int index = getGenMatchedParticleIndex(object);
1862 >    if(index == -1) value = 0;
1863 >    else value = mcparticles->at(index).id;
1864 >  }
1865 >
1866 >  else if(variable == "genMatchedId"){
1867 >    int index = getGenMatchedParticleIndex(object);
1868 >    if(index == -1) value = 0;
1869 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
1870 >  }
1871 >  else if(variable == "genMatchedMotherId"){
1872 >    int index = getGenMatchedParticleIndex(object);
1873 >    if(index == -1) value = 0;
1874 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1875 >  }
1876 >  else if(variable == "genMatchedMotherIdReverse"){
1877 >    int index = getGenMatchedParticleIndex(object);
1878 >    if(index == -1) value = 24;
1879 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1880 >  }
1881 >  else if(variable == "genMatchedGrandmotherId"){
1882 >    int index = getGenMatchedParticleIndex(object);
1883 >    if(index == -1) value = 0;
1884 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1885 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1886 >      if(motherIndex == -1) value = 0;
1887 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1888 >    }
1889 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1890 >  }
1891 >  else if(variable == "genMatchedGrandmotherIdReverse"){
1892 >    int index = getGenMatchedParticleIndex(object);
1893 >    if(index == -1) value = 24;
1894 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1895 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1896 >      if(motherIndex == -1) value = 24;
1897 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1898 >    }
1899 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1900 >  }
1901 >  else if(variable == "pfMuonsFromVertex"){
1902 >    double d0Error, dzError;
1903 >
1904 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1905 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1906 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1907 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1908 >      || fabs (object->correctedDZ / dzError) > 99.0;
1909 >    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1910 >  }
1911 >
1912 >
1913 >
1914 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1915  
1916    value = applyFunction(function, value);
1917  
1918    return value;
1919 < }
1919 > } // end muon valueLookup
1920  
1921  
1922 + //!electron valueLookup
1923   double
1924 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1924 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1925  
1926    double value = 0.0;
1927    if(variable == "energy") value = object->energy;
# Line 1073 | Line 2082 | OSUAnalysis::valueLookup (const BNelectr
2082    else if(variable == "passConvVeto") value = object->passConvVeto;
2083  
2084    //user-defined variables
2085 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
2086 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
2085 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2086 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2087    else if(variable == "detIso") value = (object->trackIso) / object->pt;
2088    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2089 +  else if(variable == "metMT") {
2090 +    if (const BNmet *met = chosenMET ())
2091 +      {
2092 +        double dPhi = deltaPhi (object->phi, met->phi);
2093 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2094 +      }
2095 +    else
2096 +      value = -999;
2097 +  }
2098  
2099 +  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
2100 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
2101 +    else value = -999;
2102 +  }
2103 +  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
2104 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
2105 +    else value = -999;
2106 +  }
2107 +
2108 +  else if(variable == "correctedD0VertexInEBPlus"){
2109 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
2110 +    else value = -999;
2111 +  }
2112 +  else if(variable == "correctedD0VertexOutEBPlus"){
2113 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
2114 +    else value = -999;
2115 +  }
2116 +  else if(variable == "correctedD0VertexEEPlus"){
2117 +    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
2118 +    else value = -999;
2119 +  }
2120 +
2121 +  else if(variable == "correctedD0BeamspotInEBPlus"){
2122 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
2123 +    else value = -999;
2124 +  }
2125 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
2126 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
2127 +    else value = -999;
2128 +  }
2129 +  else if(variable == "correctedD0BeamspotEEPlus"){
2130 +    if(object->isEE && object->eta > 0) value = object->correctedD0;
2131 +    else value = -999;
2132 +  }
2133 +
2134 +  else if(variable == "correctedD0VertexInEBMinus"){
2135 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
2136 +    else value = -999;
2137 +  }
2138 +  else if(variable == "correctedD0VertexOutEBMinus"){
2139 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
2140 +    else value = -999;
2141 +  }
2142 +  else if(variable == "correctedD0VertexEEMinus"){
2143 +    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
2144 +    else value = -999;
2145 +  }
2146 +
2147 +  else if(variable == "correctedD0BeamspotInEBMinus"){
2148 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
2149 +    else value = -999;
2150 +  }
2151 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
2152 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
2153 +    else value = -999;
2154 +  }
2155 +  else if(variable == "correctedD0BeamspotEEMinus"){
2156 +    if(object->isEE && object->eta < 0) value = object->correctedD0;
2157 +    else value = -999;
2158 +  }
2159 +
2160 +  else if(variable == "tightID"){
2161 +    if (object->isEB)
2162 +      {
2163 +        value = fabs(object->delEtaIn) < 0.004 \
2164 +          && fabs (object->delPhiIn) < 0.03 \
2165 +          && object->scSigmaIEtaIEta < 0.01 \
2166 +          && object->hadOverEm < 0.12 \
2167 +          && fabs (object->correctedD0Vertex) < 0.02 \
2168 +          && fabs (object->correctedDZ) < 0.1 \
2169 +          && object->absInvEMinusInvPin < 0.05 \
2170 +          && object->passConvVeto;
2171 +      }
2172 +    else
2173 +      {
2174 +        value = fabs(object->delEtaIn) < 0.005 \
2175 +          && fabs (object->delPhiIn) < 0.02 \
2176 +          && object->scSigmaIEtaIEta < 0.03 \
2177 +          && object->hadOverEm < 0.10 \
2178 +          && fabs (object->correctedD0Vertex) < 0.02 \
2179 +          && fabs (object->correctedDZ) < 0.1 \
2180 +          && object->absInvEMinusInvPin < 0.05 \
2181 +          && object->passConvVeto;
2182 +      }
2183 +  }
2184 +
2185 +  else if(variable == "looseID"){
2186 +    value = object->pt > 10
2187 +      && object->mvaNonTrigV0 > 0;
2188 +      }
2189 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
2190 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2191 +    else value = -999;
2192 +  }
2193 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
2194 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2195 +    else value = -999;
2196 +  }
2197 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
2198 +    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
2199 +    else value = -999;
2200 +  }
2201 +
2202 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
2203 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
2204 +    else value = -999;
2205 +  }
2206 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
2207 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
2208 +    else value = -999;
2209 +  }
2210 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
2211 +    if(object->isEE && object->charge > 0) value = object->correctedD0;
2212 +    else value = -999;
2213 +  }
2214 +
2215 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
2216 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2217 +    else value = -999;
2218 +  }
2219 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
2220 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2221 +    else value = -999;
2222 +  }
2223 +  else if(variable == "correctedD0VertexEENegativeCharge"){
2224 +    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
2225 +    else value = -999;
2226 +  }
2227 +
2228 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
2229 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
2230 +    else value = -999;
2231 +  }
2232 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
2233 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
2234 +    else value = -999;
2235 +  }
2236 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
2237 +    if(object->isEE && object->charge < 0) value = object->correctedD0;
2238 +    else value = -999;
2239 +  }
2240 +
2241 +
2242 +  else if(variable == "tightIDdisplaced"){
2243 +    if (object->isEB)
2244 +      {
2245 +        value = fabs(object->delEtaIn) < 0.004 \
2246 +          && fabs (object->delPhiIn) < 0.03 \
2247 +          && object->scSigmaIEtaIEta < 0.01 \
2248 +          && object->hadOverEm < 0.12 \
2249 +          && object->absInvEMinusInvPin < 0.05;
2250 +      }
2251 +    else
2252 +      {
2253 +        value = fabs (object->delEtaIn) < 0.005 \
2254 +          && fabs (object->delPhiIn) < 0.02 \
2255 +          && object->scSigmaIEtaIEta < 0.03 \
2256 +          && object->hadOverEm < 0.10 \
2257 +          && object->absInvEMinusInvPin < 0.05;
2258 +      }
2259 +  }
2260 +
2261 +
2262 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2263 +
2264 +  else if(variable == "genMatchedPdgId"){
2265 +    int index = getGenMatchedParticleIndex(object);
2266 +    if(index == -1) value = 0;
2267 +    else value = mcparticles->at(index).id;
2268 +  }
2269 +
2270 +
2271 +  else if(variable == "genMatchedId"){
2272 +    int index = getGenMatchedParticleIndex(object);
2273 +    if(index == -1) value = 0;
2274 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
2275 +  }
2276 +  else if(variable == "genMatchedMotherId"){
2277 +    int index = getGenMatchedParticleIndex(object);
2278 +    if(index == -1) value = 0;
2279 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2280 +  }
2281 +  else if(variable == "genMatchedMotherIdReverse"){
2282 +    int index = getGenMatchedParticleIndex(object);
2283 +    if(index == -1) value = 24;
2284 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2285 +  }
2286 +  else if(variable == "genMatchedGrandmotherId"){
2287 +    int index = getGenMatchedParticleIndex(object);
2288 +    if(index == -1) value = 0;
2289 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2290 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2291 +      if(motherIndex == -1) value = 0;
2292 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2293 +    }
2294 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2295 +  }
2296 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2297 +    int index = getGenMatchedParticleIndex(object);
2298 +    if(index == -1) value = 24;
2299 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2300 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2301 +      if(motherIndex == -1) value = 24;
2302 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2303 +    }
2304 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2305 +  }
2306 +  else if(variable == "pfElectronsFromVertex"){
2307 +    double d0Error, dzError;
2308 +
2309 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2310 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2311 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2312 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2313 +      || fabs (object->correctedDZ / dzError) > 99.0;
2314 +    value = !value;
2315 +  }
2316  
2317 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2317 >
2318 >
2319 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2320  
2321    value = applyFunction(function, value);
2322  
2323    return value;
2324 < }
2324 > } // end electron valueLookup
2325  
2326  
2327 + //!event valueLookup
2328   double
2329 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2329 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2330  
2331    double value = 0.0;
2332  
# Line 1156 | Line 2394 | OSUAnalysis::valueLookup (const BNevent*
2394    else if(variable == "id1") value = object->id1;
2395    else if(variable == "id2") value = object->id2;
2396    else if(variable == "evt") value = object->evt;
2397 <
2398 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2397 >  else if(variable == "puScaleFactor"){
2398 >    if(doPileupReweighting_ && datasetType_ != "data")
2399 >      value = puWeight_->at (events->at (0).numTruePV);
2400 >    else
2401 >      value = 1.0;
2402 >  }
2403 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2404 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2405 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2406 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2407 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2408  
2409    value = applyFunction(function, value);
2410  
2411    return value;
2412 < }
2412 > } // end event valueLookup
2413  
2414 +
2415 + //!tau valueLookup
2416   double
2417 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2417 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2418  
2419    double value = 0.0;
2420  
# Line 1209 | Line 2458 | OSUAnalysis::valueLookup (const BNtau* o
2458    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2459    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2460  
2461 +  else if (variable == "looseHadronicID") {
2462 +    value = object->pt > 10
2463 +      && object->eta < 2.3
2464 +      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2465 +      && object->HPSdecayModeFinding > 0
2466 +      && object->HPSagainstElectronLoose > 0
2467 +      && object->HPSagainstMuonTight > 0;
2468 +  }
2469 +
2470 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2471  
2472 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2472 >  else if(variable == "genMatchedPdgId"){
2473 >    int index = getGenMatchedParticleIndex(object);
2474 >    if(index == -1) value = 0;
2475 >    else value = mcparticles->at(index).id;
2476 >  }
2477 >
2478 >  else if(variable == "genMatchedId"){
2479 >    int index = getGenMatchedParticleIndex(object);
2480 >    if(index == -1) value = 0;
2481 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2482 >  }
2483 >  else if(variable == "genMatchedMotherId"){
2484 >    int index = getGenMatchedParticleIndex(object);
2485 >    if(index == -1) value = 0;
2486 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2487 >  }
2488 >  else if(variable == "genMatchedMotherIdReverse"){
2489 >    int index = getGenMatchedParticleIndex(object);
2490 >    if(index == -1) value = 24;
2491 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2492 >  }
2493 >  else if(variable == "genMatchedGrandmotherId"){
2494 >    int index = getGenMatchedParticleIndex(object);
2495 >    if(index == -1) value = 0;
2496 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2497 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2498 >      if(motherIndex == -1) value = 0;
2499 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2500 >    }
2501 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2502 >  }
2503 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2504 >    int index = getGenMatchedParticleIndex(object);
2505 >    if(index == -1) value = 24;
2506 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2507 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2508 >      if(motherIndex == -1) value = 24;
2509 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2510 >    }
2511 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2512 >  }
2513 >
2514 >
2515 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2516  
2517    value = applyFunction(function, value);
2518  
2519    return value;
2520 < }
2520 > } // end tau valueLookup
2521 >
2522  
2523 + //!met valueLookup
2524   double
2525 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2525 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2526  
2527    double value = 0.0;
2528  
# Line 1282 | Line 2586 | OSUAnalysis::valueLookup (const BNmet* o
2586    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2587    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2588  
2589 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2589 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2590  
2591    value = applyFunction(function, value);
2592  
2593    return value;
2594 < }
2594 > } // end met valueLookup
2595  
2596 +
2597 + //!track valueLookup
2598   double
2599 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2599 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2600  
2601    double value = 0.0;
2602 +  double pMag = sqrt(object->pt * object->pt +
2603 +                     object->pz * object->pz);
2604  
2605    if(variable == "pt") value = object->pt;
2606    else if(variable == "px") value = object->px;
# Line 1312 | Line 2620 | OSUAnalysis::valueLookup (const BNtrack*
2620    else if(variable == "numValidHits") value = object->numValidHits;
2621    else if(variable == "isHighPurity") value = object->isHighPurity;
2622  
2623 +  //additional BNs info for disappTrks
2624 +  else if(variable == "caloEMDeltaRp3")     value = object->caloEMDeltaRp3;
2625 +  else if(variable == "caloHadDeltaRp3")    value = object->caloHadDeltaRp3;
2626 +  else if(variable == "caloEMDeltaRp4")     value = object->caloEMDeltaRp4;
2627 +  else if(variable == "caloHadDeltaRp4")    value = object->caloHadDeltaRp4;
2628 +  else if(variable == "caloEMDeltaRp5")     value = object->caloEMDeltaRp5;
2629 +  else if(variable == "caloHadDeltaRp5")    value = object->caloHadDeltaRp5;
2630 +  else if(variable == "nHitsMissingOuter")  value = object->nHitsMissingOuter;
2631 +  else if(variable == "nHitsMissingInner")  value = object->nHitsMissingInner;
2632 +  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2633 +  else if(variable == "depTrkRp3")          value = object->depTrkRp3;
2634 +  else if(variable == "depEcalRp3")         value = object->depEcalRp3;
2635 +  else if(variable == "depHcalRp3")         value = object->depHcalRp3;
2636 +  else if(variable == "depHoRp3")           value = object->depHoRp3;
2637 +  else if(variable == "nTracksRp3")         value = object->nTracksRp3;
2638 +  else if(variable == "trackerVetoPtRp3")   value = object->trackerVetoPtRp3;
2639 +  else if(variable == "emVetoEtRp3")        value = object->emVetoEtRp3;
2640 +  else if(variable == "hadVetoEtRp3")       value = object->hadVetoEtRp3;
2641 +  else if(variable == "hoVetoEtRp3")        value = object->hoVetoEtRp3;
2642 +  else if(variable == "depTrkRp5")          value = object->depTrkRp5;
2643 +  else if(variable == "depEcalRp5")         value = object->depEcalRp5;
2644 +  else if(variable == "depHcalRp5")         value = object->depHcalRp5;
2645 +  else if(variable == "depHoRp5")           value = object->depHoRp5;
2646 +  else if(variable == "nTracksRp5")         value = object->nTracksRp5;
2647 +  else if(variable == "trackerVetoPtRp5")   value = object->trackerVetoPtRp5;
2648 +  else if(variable == "emVetoEtRp5")        value = object->emVetoEtRp5;
2649 +  else if(variable == "hadVetoEtRp5")       value = object->hadVetoEtRp5;
2650 +  else if(variable == "hoVetoEtRp5")        value = object->hoVetoEtRp5;
2651 +
2652 +  //user defined variables
2653 +  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;
2654 +  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2655 +  else if(variable == "depTrkRp5MinusPt"){
2656 +    if ( (object->depTrkRp5 - object->pt) < 0 ) {
2657 +           value = 0;
2658 +         }
2659 +         else value =  (object->depTrkRp5 - object->pt);
2660 +  }
2661 +  else if(variable == "depTrkRp3MinusPt"){
2662 +    if ( (object->depTrkRp3 - object->pt) < 0 ) {
2663 +      value = 0;
2664 +    }
2665 +    else value =  (object->depTrkRp3 - object->pt);
2666 +  }
2667  
2668 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2668 >  else if(variable == "dPhiMet") {
2669 >    if (const BNmet *met = chosenMET ()) {
2670 >      value = deltaPhi (object->phi, met->phi);
2671 >    } else value = -999;
2672 >  }
2673 >  
2674 >  
2675 >  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2676 >  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2677 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2678 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2679 >  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2680 >  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2681 >  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2682 >  else if(variable == "ptError")                    value = object->ptError;
2683 >  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2684 >  else if (variable == "d0wrtPV"){
2685 >    double vx = object->vx - chosenVertex ()->x,
2686 >      vy = object->vy - chosenVertex ()->y,
2687 >      px = object->px,
2688 >      py = object->py,
2689 >      pt = object->pt;
2690 >    value = (-vx * py + vy * px) / pt;
2691 >  }
2692 >  else if (variable == "dZwrtPV"){
2693 >    double vx = object->vx - chosenVertex ()->x,
2694 >      vy = object->vy - chosenVertex ()->y,
2695 >      vz = object->vz - chosenVertex ()->z,
2696 >      px = object->px,
2697 >      py = object->py,
2698 >      pz = object->pz,
2699 >      pt = object->pt;
2700 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2701 >  }
2702 >
2703 >
2704 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2705 >
2706 >  else if(variable == "genMatchedPdgId"){
2707 >    int index = getGenMatchedParticleIndex(object);
2708 >    if(index == -1) value = 0;
2709 >    else value = mcparticles->at(index).id;
2710 >  }
2711 >
2712 >
2713 >  else if(variable == "genMatchedId"){
2714 >    int index = getGenMatchedParticleIndex(object);
2715 >    if(index == -1) value = 0;
2716 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2717 >  }
2718 >  else if(variable == "genMatchedMotherId"){
2719 >    int index = getGenMatchedParticleIndex(object);
2720 >    if(index == -1) value = 0;
2721 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2722 >  }
2723 >  else if(variable == "genMatchedMotherIdReverse"){
2724 >    int index = getGenMatchedParticleIndex(object);
2725 >    if(index == -1) value = 24;
2726 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2727 >  }
2728 >  else if(variable == "genMatchedGrandmotherId"){
2729 >    int index = getGenMatchedParticleIndex(object);
2730 >    if(index == -1) value = 0;
2731 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2732 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2733 >      if(motherIndex == -1) value = 0;
2734 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2735 >    }
2736 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2737 >  }
2738 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2739 >    int index = getGenMatchedParticleIndex(object);
2740 >    if(index == -1) value = 24;
2741 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2742 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2743 >      if(motherIndex == -1) value = 24;
2744 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2745 >    }
2746 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2747 >  }
2748 >
2749 >
2750 >
2751 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2752  
2753    value = applyFunction(function, value);
2754  
2755    return value;
2756 < }
2756 > } // end track valueLookup
2757 >
2758  
2759 + //!genjet valueLookup
2760   double
2761 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2761 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2762  
2763    double value = 0.0;
2764  
# Line 1341 | Line 2778 | OSUAnalysis::valueLookup (const BNgenjet
2778    else if(variable == "charge") value = object->charge;
2779  
2780  
2781 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2781 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2782  
2783    value = applyFunction(function, value);
2784  
2785    return value;
2786   }
2787  
2788 + //!mcparticle valueLookup
2789   double
2790 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2790 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2791  
2792    double value = 0.0;
2793  
# Line 1440 | Line 2878 | OSUAnalysis::valueLookup (const BNmcpart
2878  
2879    //user-defined variables
2880    else if (variable == "d0"){
2881 <    double vx = object->vx - primaryVertex_->x,
2882 <      vy = object->vy - primaryVertex_->y,
2881 >    double vx = object->vx - chosenVertex ()->x,
2882 >      vy = object->vy - chosenVertex ()->y,
2883        px = object->px,
2884        py = object->py,
2885        pt = object->pt;
2886      value = (-vx * py + vy * px) / pt;
2887    }
2888    else if (variable == "dz"){
2889 <    double vx = object->vx - primaryVertex_->x,
2890 <      vy = object->vy - primaryVertex_->y,
2891 <      vz = object->vz - primaryVertex_->z,
2889 >    double vx = object->vx - chosenVertex ()->x,
2890 >      vy = object->vy - chosenVertex ()->y,
2891 >      vz = object->vz - chosenVertex ()->z,
2892        px = object->px,
2893        py = object->py,
2894        pz = object->pz,
2895        pt = object->pt;
2896      value = vz - (vx * px + vy * py)/pt * (pz/pt);
2897    }
2898 +  else if(variable == "v0"){
2899 +    value = sqrt(object->vx*object->vx + object->vy*object->vy);
2900 +  }
2901 +  else if(variable == "deltaV0"){
2902 +    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
2903 +  }
2904 +  else if (variable == "deltaVx"){
2905 +    value = object->vx - chosenVertex ()->x;
2906 +  }
2907 +  else if (variable == "deltaVy"){
2908 +    value = object->vy - chosenVertex ()->y;
2909 +  }
2910 +  else if (variable == "deltaVz"){
2911 +    value = object->vz - chosenVertex ()->z;
2912 +  }
2913  
2914  
2915 <
1463 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2915 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2916  
2917    value = applyFunction(function, value);
2918  
2919    return value;
2920 < }
2920 > } // end mcparticle valueLookup
2921  
2922 +
2923 + //!primaryvertex valueLookup
2924   double
2925 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2925 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2926  
2927    double value = 0.0;
2928  
# Line 1487 | Line 2941 | OSUAnalysis::valueLookup (const BNprimar
2941    else if(variable == "isGood") value = object->isGood;
2942  
2943  
2944 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2944 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2945  
2946    value = applyFunction(function, value);
2947  
2948    return value;
2949   }
2950  
2951 + //!bxlumi valueLookup
2952   double
2953 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2953 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2954  
2955    double value = 0.0;
2956  
# Line 1504 | Line 2959 | OSUAnalysis::valueLookup (const BNbxlumi
2959    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2960  
2961  
2962 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2962 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2963  
2964    value = applyFunction(function, value);
2965  
2966    return value;
2967   }
2968  
2969 + //!photon valueLookup
2970   double
2971 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2971 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2972  
2973    double value = 0.0;
2974  
# Line 1587 | Line 3043 | OSUAnalysis::valueLookup (const BNphoton
3043    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
3044  
3045  
3046 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3046 >
3047 >
3048 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3049 >
3050 >  else if(variable == "genMatchedPdgId"){
3051 >    int index = getGenMatchedParticleIndex(object);
3052 >    if(index == -1) value = 0;
3053 >    else value = mcparticles->at(index).id;
3054 >  }
3055 >
3056 >
3057 >
3058 >  else if(variable == "genMatchedId"){
3059 >    int index = getGenMatchedParticleIndex(object);
3060 >    if(index == -1) value = 0;
3061 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
3062 >  }
3063 >  else if(variable == "genMatchedMotherId"){
3064 >    int index = getGenMatchedParticleIndex(object);
3065 >    if(index == -1) value = 0;
3066 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
3067 >  }
3068 >  else if(variable == "genMatchedMotherIdReverse"){
3069 >    int index = getGenMatchedParticleIndex(object);
3070 >    if(index == -1) value = 24;
3071 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
3072 >  }
3073 >  else if(variable == "genMatchedGrandmotherId"){
3074 >    int index = getGenMatchedParticleIndex(object);
3075 >    if(index == -1) value = 0;
3076 >    else if(fabs(mcparticles->at(index).motherId) == 15){
3077 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3078 >      if(motherIndex == -1) value = 0;
3079 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3080 >    }
3081 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3082 >  }
3083 >  else if(variable == "genMatchedGrandmotherIdReverse"){
3084 >    int index = getGenMatchedParticleIndex(object);
3085 >    if(index == -1) value = 24;
3086 >    else if(fabs(mcparticles->at(index).motherId) == 15){
3087 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3088 >      if(motherIndex == -1) value = 24;
3089 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3090 >    }
3091 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3092 >  }
3093 >
3094 >
3095 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3096  
3097    value = applyFunction(function, value);
3098  
3099    return value;
3100 < }
3100 > } // end photon valueLookup
3101 >
3102  
3103 + //!supercluster valueLookup
3104   double
3105 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
3105 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
3106  
3107    double value = 0.0;
3108  
# Line 1609 | Line 3116 | OSUAnalysis::valueLookup (const BNsuperc
3116    else if(variable == "theta") value = object->theta;
3117  
3118  
3119 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3119 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3120  
3121    value = applyFunction(function, value);
3122  
3123    return value;
3124   }
3125  
3126 + //!trigobj valueLookup
3127 + double
3128 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3129  
3130 +  double value = 0.0;
3131 +
3132 +  if(variable == "pt") value = object->pt;
3133 +  else if(variable == "eta") value = object->eta;
3134 +  else if(variable == "phi") value = object->phi;
3135 +  else if(variable == "px") value = object->px;
3136 +  else if(variable == "py") value = object->py;
3137 +  else if(variable == "pz") value = object->pz;
3138 +  else if(variable == "et") value = object->et;
3139 +  else if(variable == "energy") value = object->energy;
3140 +  else if(variable == "etTotal") value = object->etTotal;
3141 +  else if(variable == "id") value = object->id;
3142 +  else if(variable == "charge") value = object->charge;
3143 +  else if(variable == "isIsolated") value = object->isIsolated;
3144 +  else if(variable == "isMip") value = object->isMip;
3145 +  else if(variable == "isForward") value = object->isForward;
3146 +  else if(variable == "isRPC") value = object->isRPC;
3147 +  else if(variable == "bx") value = object->bx;
3148 +  else if(variable == "filter") {
3149 +    if ((stringValue = object->filter) == "")
3150 +      stringValue = "none";  // stringValue should only be empty if value is filled
3151 +  }
3152 +
3153 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3154 +
3155 +  value = applyFunction(function, value);
3156 +
3157 +  return value;
3158 + }
3159 +
3160 + //!muon-muon pair valueLookup
3161   double
3162 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
3162 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3163  
3164    double value = 0.0;
3165  
3166 <  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
3166 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3167 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3168 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3169    else if(variable == "invMass"){
3170      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3171      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3172      value = (fourVector1 + fourVector2).M();
3173    }
3174 +  else if(variable == "pt"){
3175 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3176 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3177 +    value = (fourVector1 + fourVector2).Pt();
3178 +  }
3179 +  else if(variable == "threeDAngle")
3180 +    {
3181 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3182 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3183 +      value = (threeVector1.Angle(threeVector2));
3184 +    }
3185 +  else if(variable == "alpha")
3186 +    {
3187 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3188 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3189 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3190 +      value = (pi-threeVector1.Angle(threeVector2));
3191 +    }
3192    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3193    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3194 <  else if(variable == "d0Sign") value = object1->correctedD0Vertex*object2->correctedD0Vertex/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3194 >  else if(variable == "d0Sign"){
3195 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3196 >    if(d0Sign < 0) value = -0.5;
3197 >    else if (d0Sign > 0) value = 0.5;
3198 >    else value = -999;
3199 >  }
3200 >  else if(variable == "chargeProduct"){
3201 >    value = object1->charge*object2->charge;
3202 >  }
3203 >  else if(variable == "muon1CorrectedD0Vertex"){
3204 >    value = object1->correctedD0Vertex;
3205 >  }
3206 >  else if(variable == "muon2CorrectedD0Vertex"){
3207 >    value = object2->correctedD0Vertex;
3208 >  }
3209 >  else if(variable == "muon1timeAtIpInOut"){
3210 >    value = object1->timeAtIpInOut;
3211 >  }
3212 >  else if(variable == "muon2timeAtIpInOut"){
3213 >    value = object2->timeAtIpInOut;
3214 >  }
3215 >  else if(variable == "muon1correctedD0")
3216 >    {
3217 >      value = object1->correctedD0;
3218 >    }
3219 >  else if(variable == "muon2correctedD0")
3220 >    {
3221 >      value = object2->correctedD0;
3222 >    }
3223  
3224 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3224 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3225 >
3226 >  value = applyFunction(function, value);
3227 >
3228 >  return value;
3229 > } // end muon-muon pair valueLookup
3230 >
3231 >
3232 > //!muon-photon pair valueLookup
3233 > double
3234 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3235 >
3236 >  double value = 0.0;
3237 >
3238 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3239 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3240 >  else if(variable == "photonEta") value = object2->eta;
3241 >  else if(variable == "muonEta") value = object1->eta;
3242 >  else if(variable == "photonPhi") value = object2->phi;
3243 >  else if(variable == "muonPhi") value = object1->phi;
3244 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3245 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3246 >  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3247 >  else if(variable == "invMass"){
3248 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3249 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3250 >    value = (fourVector1 + fourVector2).M();
3251 >  }
3252 >  else if(variable == "pt"){
3253 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3254 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3255 >    value = (fourVector1 + fourVector2).Pt();
3256 >  }
3257 >  else if(variable == "threeDAngle")
3258 >    {
3259 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3260 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3261 >      value = (threeVector1.Angle(threeVector2));
3262 >    }
3263 >  else if(variable == "alpha")
3264 >    {
3265 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3266 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3267 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3268 >      value = (pi-threeVector1.Angle(threeVector2));
3269 >    }
3270 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3271 >
3272 >  value = applyFunction(function, value);
3273 >
3274 >  return value;
3275 > }
3276 >
3277 > //!electron-photon pair valueLookup
3278 > double
3279 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3280 >
3281 >  double value = 0.0;
3282 >
3283 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3284 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3285 >  else if(variable == "photonEta") value = object2->eta;
3286 >  else if(variable == "electronEta") value = object1->eta;
3287 >  else if(variable == "photonPhi") value = object2->phi;
3288 >  else if(variable == "electronPhi") value = object1->phi;
3289 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3290 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3291 >  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3292 >  else if(variable == "invMass"){
3293 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3294 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3295 >    value = (fourVector1 + fourVector2).M();
3296 >  }
3297 >  else if(variable == "pt"){
3298 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3299 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3300 >    value = (fourVector1 + fourVector2).Pt();
3301 >  }
3302 >  else if(variable == "threeDAngle")
3303 >    {
3304 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3305 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3306 >      value = (threeVector1.Angle(threeVector2));
3307 >    }
3308 >  else if(variable == "alpha")
3309 >    {
3310 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3311 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3312 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3313 >      value = (pi-threeVector1.Angle(threeVector2));
3314 >    }
3315 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3316  
3317    value = applyFunction(function, value);
3318  
3319    return value;
3320   }
3321  
3322 + //!electron-electron pair valueLookup
3323   double
3324 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
3324 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3325  
3326    double value = 0.0;
3327  
3328 <  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
3328 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3329 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3330 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3331    else if(variable == "invMass"){
3332      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3333      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3334      value = (fourVector1 + fourVector2).M();
3335    }
3336 +  else if(variable == "pt"){
3337 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3338 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3339 +    value = (fourVector1 + fourVector2).Pt();
3340 +  }
3341 +  else if(variable == "threeDAngle")
3342 +    {
3343 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3344 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3345 +      value = (threeVector1.Angle(threeVector2));
3346 +    }
3347    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3348    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3349 <  else if(variable == "d0Sign") value = object1->correctedD0Vertex*object2->correctedD0Vertex/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3349 >  else if(variable == "d0Sign"){
3350 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3351 >    if(d0Sign < 0) value = -0.5;
3352 >    else if (d0Sign > 0) value = 0.5;
3353 >    else value = -999;
3354 >  }
3355 >  else if(variable == "chargeProduct"){
3356 >    value = object1->charge*object2->charge;
3357 >  }
3358 >  else if(variable == "electron1CorrectedD0Vertex"){
3359 >    value = object1->correctedD0Vertex;
3360 >  }
3361 >  else if(variable == "electron2CorrectedD0Vertex"){
3362 >    value = object2->correctedD0Vertex;
3363 >  }
3364 >  else if(variable == "electron1CorrectedD0"){
3365 >    value = object1->correctedD0;
3366 >  }
3367 >  else if(variable == "electron2CorrectedD0"){
3368 >    value = object2->correctedD0;
3369 >  }
3370  
3371 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3371 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3372  
3373    value = applyFunction(function, value);
3374  
3375    return value;
3376   }
3377  
3378 + //!electron-muon pair valueLookup
3379   double
3380 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3380 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3381  
3382    double value = 0.0;
3383  
3384 <  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
3384 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3385 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3386 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3387    else if(variable == "invMass"){
3388      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3389      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3390      value = (fourVector1 + fourVector2).M();
3391    }
3392 +  else if(variable == "pt"){
3393 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3394 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3395 +    value = (fourVector1 + fourVector2).Pt();
3396 +  }
3397 +  else if(variable == "threeDAngle")
3398 +    {
3399 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3400 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3401 +      value = (threeVector1.Angle(threeVector2));
3402 +    }
3403    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3404    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3405 <  else if(variable == "d0Sign") value = object1->correctedD0Vertex*object2->correctedD0Vertex/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3405 >  else if(variable == "d0Sign"){
3406 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3407 >    if(d0Sign < 0) value = -0.5;
3408 >    else if (d0Sign > 0) value = 0.5;
3409 >    else value = -999;
3410 >  }
3411 >  else if(variable == "chargeProduct"){
3412 >    value = object1->charge*object2->charge;
3413 >  }
3414 >  else if(variable == "electronCorrectedD0Vertex"){
3415 >    value = object1->correctedD0Vertex;
3416 >  }
3417 >  else if(variable == "muonCorrectedD0Vertex"){
3418 >    value = object2->correctedD0Vertex;
3419 >  }
3420 >  else if(variable == "electronCorrectedD0"){
3421 >    value = object1->correctedD0;
3422 >  }
3423 >  else if(variable == "muonCorrectedD0"){
3424 >    value = object2->correctedD0;
3425 >  }
3426 >  else if(variable == "electronDetIso"){
3427 >    value = (object1->trackIso) / object1->pt;
3428 >  }
3429 >  else if(variable == "muonDetIso"){
3430 >    value = (object2->trackIsoDR03) / object2->pt;
3431 >  }
3432 >  else if(variable == "electronRelPFrhoIso"){
3433 >    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3434 >  }
3435 >  else if(variable == "muonRelPFdBetaIso"){
3436 >    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3437 >  }
3438 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3439 >  value = applyFunction(function, value);
3440 >
3441 >  return value;
3442 > } // end electron-muon pair valueLookup
3443 >
3444 >
3445 > //!electron-jet pair valueLookup
3446 > double
3447 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3448 >
3449 >  double value = 0.0;
3450 >
3451 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3452 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3453 >  else if(variable == "jetEta") value = object2->eta;
3454 >  else if(variable == "jetPhi") value = object2->phi;
3455 >  else if(variable == "electronEta") value = object1->eta;
3456 >  else if(variable == "electronPhi") value = object1->phi;
3457 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3458 >  else if(variable == "invMass"){
3459 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3460 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3461 >    value = (fourVector1 + fourVector2).M();
3462 >  }
3463 >  else if(variable == "pt"){
3464 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3465 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3466 >    value = (fourVector1 + fourVector2).Pt();
3467 >  }
3468 >  else if(variable == "threeDAngle")
3469 >    {
3470 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3471 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3472 >      value = (threeVector1.Angle(threeVector2));
3473 >    }
3474 >  else if(variable == "chargeProduct"){
3475 >    value = object1->charge*object2->charge;
3476 >  }
3477 >
3478 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3479 >  value = applyFunction(function, value);
3480 >
3481 >  return value;
3482 > }
3483 >
3484 > //!photon-jet pair valueLookup
3485 > double
3486 > OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3487 >
3488 >  double value = 0.0;
3489 >
3490 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3491 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3492 >  else if(variable == "jetEta") value = object2->eta;
3493 >  else if(variable == "jetPhi") value = object2->phi;
3494 >  else if(variable == "photonEta") value = object1->eta;
3495 >  else if(variable == "photonPhi") value = object1->phi;
3496 >  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3497 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3498 >  else if(variable == "invMass"){
3499 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3500 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3501 >    value = (fourVector1 + fourVector2).M();
3502 >  }
3503 >  else if(variable == "pt"){
3504 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3505 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3506 >    value = (fourVector1 + fourVector2).Pt();
3507 >  }
3508 >  else if(variable == "threeDAngle")
3509 >    {
3510 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3511 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3512 >      value = (threeVector1.Angle(threeVector2));
3513 >    }
3514 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3515 >  value = applyFunction(function, value);
3516 >
3517 >  return value;
3518 > }
3519 >
3520 > // track-jet pair valueLookup
3521 > double
3522 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNjet* object2, string variable, string function, string &stringValue){
3523 >
3524 >  double value = 0.0;
3525 >
3526 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3527 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3528 >
3529 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3530 >  value = applyFunction(function, value);
3531 >
3532 >  return value;
3533 >
3534 > }
3535 >
3536 >
3537 >
3538 > // met-jet pair valueLookup
3539 > double
3540 > OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3541 >
3542 >  double value = 0.0;
3543 >
3544 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3545 >
3546 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3547 >  value = applyFunction(function, value);
3548 >
3549 >  return value;
3550 >
3551 > }  
3552 >
3553  
3554 +
3555 + //!muon-jet pair valueLookup
3556 + double
3557 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3558 +
3559 +  double value = 0.0;
3560 +
3561 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3562 +  else if(variable == "jetEta") value = object2->eta;
3563 +  else if(variable == "jetPhi") value = object2->phi;
3564 +  else if(variable == "muonEta") value = object1->eta;
3565 +  else if(variable == "muonPhi") value = object1->phi;
3566 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3567 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3568 +  else if(variable == "invMass"){
3569 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3570 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3571 +    value = (fourVector1 + fourVector2).M();
3572 +  }
3573 +  else if(variable == "pt"){
3574 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3575 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3576 +    value = (fourVector1 + fourVector2).Pt();
3577 +  }
3578 +  else if(variable == "threeDAngle")
3579 +    {
3580 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3581 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3582 +      value = (threeVector1.Angle(threeVector2));
3583 +    }
3584 +  else if(variable == "chargeProduct"){
3585 +    value = object1->charge*object2->charge;
3586 +  }
3587 +
3588 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3589 +  value = applyFunction(function, value);
3590 +
3591 +  return value;
3592 + }
3593 + //!jet-jet pair valueLookup
3594 + double
3595 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3596 +
3597 +  double value = 0.0;
3598 +
3599 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3600 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3601 +  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3602 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3603 +  else if(variable == "invMass"){
3604 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3605 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3606 +    value = (fourVector1 + fourVector2).M();
3607 +  }
3608 +  else if(variable == "pt"){
3609 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3610 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3611 +    value = (fourVector1 + fourVector2).Pt();
3612 +  }
3613 +  else if(variable == "threeDAngle")
3614 +    {
3615 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3616 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3617 +      value = (threeVector1.Angle(threeVector2));
3618 +    }
3619 +  else if(variable == "chargeProduct"){
3620 +    value = object1->charge*object2->charge;
3621 +  }
3622 +
3623 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3624 +  value = applyFunction(function, value);
3625 +
3626 +  return value;
3627 + }
3628 +
3629 + //!electron-track pair valueLookup
3630 + double
3631 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3632 +  double electronMass = 0.000511;
3633 +  double value = 0.0;
3634 +  TLorentzVector fourVector1(0, 0, 0, 0);
3635 +  TLorentzVector fourVector2(0, 0, 0, 0);
3636 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3637 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3638 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3639 +  else if(variable == "invMass"){
3640 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3641 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3642 +
3643 +    value = (fourVector1 + fourVector2).M();
3644 +  }
3645 +  else if(variable == "chargeProduct"){
3646 +    value = object1->charge*object2->charge;
3647 +  }
3648    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3649 +  value = applyFunction(function, value);
3650 +  return value;
3651 +
3652 + }
3653 +
3654 +
3655 + //!muon-track pair valueLookup
3656 + double
3657 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3658 +  double pionMass = 0.140;
3659 +  double muonMass = 0.106;
3660 +  double value = 0.0;
3661 +  TLorentzVector fourVector1(0, 0, 0, 0);
3662 +  TLorentzVector fourVector2(0, 0, 0, 0);
3663 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3664 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3665 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3666 +  else if(variable == "invMass"){
3667 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3668 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3669 +
3670 +    value = (fourVector1 + fourVector2).M();
3671 +  }
3672 +  else if(variable == "chargeProduct"){
3673 +    value = object1->charge*object2->charge;
3674 +  }
3675 +
3676 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3677 +  value = applyFunction(function, value);
3678 +  return value;
3679 + }
3680 +
3681 + //!tau-tau pair valueLookup
3682 + double
3683 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3684 +  double value = 0.0;
3685 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3686 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3687 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3688 +  else if(variable == "invMass"){
3689 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3690 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3691 +    value = (fourVector1 + fourVector2).M();
3692 +  }
3693 +
3694 +  else if(variable == "chargeProduct"){
3695 +    value = object1->charge*object2->charge;
3696 +  }
3697 +
3698 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3699 +  value = applyFunction(function, value);
3700 +  return value;
3701 + }
3702 +
3703 + //!muon-tau pair valueLookup
3704 + double
3705 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3706 +  double value = 0.0;
3707 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3708 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3709 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3710 +  else if(variable == "invMass"){
3711 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3712 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3713 +    value = (fourVector1 + fourVector2).M();
3714 +  }
3715 +
3716 +  else if(variable == "chargeProduct"){
3717 +    value = object1->charge*object2->charge;
3718 +  }
3719 +
3720 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3721 +  value = applyFunction(function, value);
3722 +  return value;
3723 + }
3724 +
3725 + //!tau-track pair valueLookup
3726 + double
3727 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3728 +  double value = 0.0;
3729 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3730 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3731 +  else if(variable == "chargeProduct"){
3732 +    value = object1->charge*object2->charge;
3733 +  }
3734 +
3735 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3736 +  value = applyFunction(function, value);
3737 +  return value;
3738 + }
3739 +
3740 +
3741 + //!track-event pair valueLookup
3742 + double
3743 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3744 +
3745 +  double value = 0.0;
3746 +  double pMag = sqrt(object1->pt * object1->pt +
3747 +                     object1->pz * object1->pz);
3748 +
3749 +  if      (variable == "numPV")                      value = object2->numPV;
3750 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3751 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3752 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3753 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3754 +
3755 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3756 +
3757 +  value = applyFunction(function, value);
3758 +
3759 +  return value;
3760 +
3761 + }
3762 +
3763 + //!electron-trigobj pair valueLookup
3764 + double
3765 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3766 +
3767 +  double value = 0.0;
3768 +
3769 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3770 +  else if (variable == "match"){
3771 +    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3772 +      stringValue = object2->filter;
3773 +    else
3774 +      stringValue = "none";
3775 +  }
3776 +
3777 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3778 +
3779 +  value = applyFunction(function, value);
3780 +
3781 +  return value;
3782 +
3783 + }
3784 +
3785 + //!muon-trigobj pair valueLookup
3786 + double
3787 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3788 +
3789 +  double value = 0.0;
3790 +
3791 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3792 +
3793 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3794 +
3795 +  value = applyFunction(function, value);
3796 +
3797 +  return value;
3798 +
3799 + }
3800 +
3801 + //!stop valueLookup
3802 + double
3803 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3804 +
3805 +
3806 +  double value = 0.0;
3807 +
3808 +  if(variable == "ctau") value = object->ctau;
3809 +
3810 +  else if (variable == "d0"){
3811 +    double vx = object->vx - chosenVertex ()->x,
3812 +      vy = object->vy - chosenVertex ()->y,
3813 +      px = object->px,
3814 +      py = object->py,
3815 +      pt = object->pt;
3816 +    value = (-vx * py + vy * px) / pt;
3817 +  }
3818 +
3819 +  else if (variable == "dz"){
3820 +    double vx = object->vx - chosenVertex ()->x,
3821 +      vy = object->vy - chosenVertex ()->y,
3822 +      vz = object->vz - chosenVertex ()->z,
3823 +      px = object->px,
3824 +      py = object->py,
3825 +      pz = object->pz,
3826 +      pt = object->pt;
3827 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3828 +  }
3829 +
3830 +  else if (variable == "minD0"){
3831 +    double minD0=999;
3832 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3833 +      double vx = object->vx - vertex->x,
3834 +        vy = object->vy - vertex->y,
3835 +        px = object->px,
3836 +        py = object->py,
3837 +        pt = object->pt;
3838 +      value = (-vx * py + vy * px) / pt;
3839 +      if(abs(value) < abs(minD0)) minD0 = value;
3840 +    }
3841 +    value = minD0;
3842 +  }
3843 +  else if (variable == "minDz"){
3844 +    double minDz=999;
3845 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3846 +      double vx = object->vx - vertex->x,
3847 +        vy = object->vy - vertex->y,
3848 +        vz = object->vz - vertex->z,
3849 +        px = object->px,
3850 +        py = object->py,
3851 +        pz = object->pz,
3852 +        pt = object->pt;
3853 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3854 +      if(abs(value) < abs(minDz)) minDz = value;
3855 +    }
3856 +    value = minDz;
3857 +  }
3858 +  else if(variable == "distToVertex"){
3859 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3860 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3861 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3862 +  }
3863 +  else if (variable == "minDistToVertex"){
3864 +    double minDistToVertex=999;
3865 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3866 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3867 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3868 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3869 +
3870 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3871 +    }
3872 +    value = minDistToVertex;
3873 +  }
3874 +  else if (variable == "distToVertexDifference"){
3875 +    double minDistToVertex=999;
3876 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3877 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3878 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3879 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3880 +
3881 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3882 +    }
3883 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3884 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3885 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3886 +
3887 +    value = distToChosenVertex - minDistToVertex;
3888 +  }
3889 +
3890 +  else if (variable == "closestVertexRank"){
3891 +    double minDistToVertex=999;
3892 +    int vertex_rank = 0;
3893 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3894 +      vertex_rank++;
3895 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3896 +                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
3897 +                      (object->vz-vertex->z)*(object->vz-vertex->z));
3898 +
3899 +      if(abs(dist) < abs(minDistToVertex)){
3900 +        value = vertex_rank;
3901 +        minDistToVertex = dist;
3902 +      }
3903 +    }
3904 +  }
3905 +
3906 +
3907 +
3908 +
3909 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3910  
3911    value = applyFunction(function, value);
3912  
3913    return value;
3914 +
3915 + } // end stop valueLookup
3916 +
3917 +
3918 +
3919 +
3920 +
3921 + // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3922 + // Return true iff no other tracks are found in this cone.
3923 + int
3924 + OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
3925 +  for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
3926 +    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
3927 +    double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
3928 +    if(deltaRtrk < 0.5) return 0;
3929 +  }
3930 +  return 1;
3931 +
3932   }
3933  
3934  
3935   double
3936 + OSUAnalysis::getTrkPtRes (const BNtrack* track1){
3937 +
3938 +  double ptTrue = getTrkPtTrue(track1, mcparticles.product());
3939 +  double PtRes = (track1->pt - ptTrue) / ptTrue;
3940 +
3941 +  return PtRes;
3942 +
3943 + }
3944 +
3945 +
3946 + double
3947 + OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
3948 +  double value = -99;
3949 +  double genDeltaRLowest = 999;
3950 +
3951 +  for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
3952 +    double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
3953 +    if (genDeltaRtemp < genDeltaRLowest) {
3954 +      genDeltaRLowest = genDeltaRtemp;
3955 +      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
3956 +        double ptTrue = genPart->pt;
3957 +        value = ptTrue;
3958 +      }
3959 +    }
3960 +  }
3961 +
3962 +  return value;
3963 +
3964 + }
3965 +
3966 + double
3967 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3968 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3969 +  if (!useTrackCaloRhoCorr_) return -99;
3970 +  // if (!rhokt6CaloJetsHandle_) {
3971 +  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3972 +  //   return -99;
3973 +  // }
3974 +  double radDeltaRCone = 0.5;
3975 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3976 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3977 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3978 +  return caloTotRhoCorrCalo;
3979 +
3980 + }
3981 +
3982 +
3983 +
3984 +
3985 + //creates a map of the dead Ecal channels in the barrel and endcap
3986 + //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
3987 + //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
3988 + void
3989 + OSUAnalysis::WriteDeadEcal (){
3990 +  double etaEcal, phiEcal;
3991 +  ifstream DeadEcalFile(deadEcalFile_);
3992 +  if(!DeadEcalFile) {
3993 +    cout << "Error: DeadEcalFile has not been found." << endl;
3994 +    return;
3995 +  }
3996 +  if(DeadEcalVec.size()!= 0){
3997 +    cout << "Error: DeadEcalVec has a nonzero size" << endl;
3998 +    return;
3999 +  }
4000 +  while(!DeadEcalFile.eof())
4001 +    {
4002 +      DeadEcalFile >> etaEcal >> phiEcal;
4003 +      DeadEcal newChan;
4004 +      newChan.etaEcal = etaEcal;
4005 +      newChan.phiEcal = phiEcal;
4006 +      DeadEcalVec.push_back(newChan);
4007 +    }
4008 +  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
4009 + }
4010 +
4011 + //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
4012 + int
4013 + OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
4014 +  double deltaRLowest = 999;
4015 +  int value = 0;
4016 +  if (DeadEcalVec.size() == 0) WriteDeadEcal();
4017 +  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4018 +    double eta = ecal->etaEcal;
4019 +    double phi = ecal->phiEcal;
4020 +    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
4021 +    if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
4022 +  }
4023 +  if (deltaRLowest<0.05) {value = 1;}
4024 +  else {value = 0;}
4025 +  return value;
4026 + }
4027 +
4028 + // Returns the smallest DeltaR between the object and any generated true particle in the event.
4029 + template <class InputObject>
4030 + double OSUAnalysis::getGenDeltaRLowest(InputObject object){
4031 +  double genDeltaRLowest = 999.;
4032 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4033 +    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
4034 +    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
4035 +  }
4036 +  return genDeltaRLowest;
4037 + }
4038 +
4039 + double
4040   OSUAnalysis::applyFunction(string function, double value){
4041  
4042    if(function == "abs") value = fabs(value);
4043 +  else if(function == "fabs") value = fabs(value);
4044 +  else if(function == "log10") value = log10(value);
4045 +  else if(function == "log") value = log10(value);
4046  
4047 +  else if(function == "") value = value;
4048 +  else{cout << "WARNING: invalid function '" << function << "'\n";}
4049  
4050    return value;
4051  
# Line 1698 | Line 4055 | OSUAnalysis::applyFunction(string functi
4055   template <class InputCollection>
4056   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
4057  
4058 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
4059 +    string obj1, obj2;
4060 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
4061 +    if (inputType==obj1 ||
4062 +        inputType==obj2) {
4063 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
4064 +      // and the inputType is a member of the pair.
4065 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
4066 +      // For example, if currentCut.inputCollection==electron-muon pairs,
4067 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
4068 +      return;
4069 +    }
4070 +  }
4071 +
4072    for (uint object = 0; object != inputCollection->size(); object++){
4073  
4074 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
4074 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4075 >    bool plotDecision = true;
4076  
4077      if(currentCut.inputCollection == inputType){
4078  
4079        vector<bool> subcutDecisions;
4080        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4081 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4082 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4081 >        string stringValue = "";
4082 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4083 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4084 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4085 >
4086        }
4087 <      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4087 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4088        else{
4089 <        bool tempDecision = true;
4090 <        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4091 <          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4092 <            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4093 <          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4089 >        bool tempDecision = true;
4090 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4091 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4092 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4093 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4094              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4095 <        }
4096 <        decision = tempDecision;
4095 >        }
4096 >        cutDecision = tempDecision;
4097        }
4098 +      //invert the cut for plotting if this cut is a veto
4099 +      if(currentCut.isVeto) plotDecision = !cutDecision;
4100 +      else plotDecision = cutDecision;
4101      }
1724    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4102  
4103 <    //set flags for objects that pass each cut AND all the previous cuts
4104 <    bool previousCumulativeFlag = true;
4103 >    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4104 >
4105 >    //set flags for objects that pass this cut AND all the previous cuts
4106 >    bool previousCumulativeCutFlag = true;
4107 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4108 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4109 >      else{ previousCumulativeCutFlag = false; break;}
4110 >    }
4111 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4112 >    bool previousCumulativePlotFlag = true;
4113      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4114 <      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4115 <      else{ previousCumulativeFlag = false; break;}
4114 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4115 >      else{ previousCumulativePlotFlag = false; break;}
4116      }
4117 <    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4117 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4118 >
4119 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4120  
4121    }
4122  
# Line 1738 | Line 4125 | void OSUAnalysis::setObjectFlags(cut &cu
4125  
4126   template <class InputCollection1, class InputCollection2>
4127   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
4128 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, string inputType){
4128 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, string inputType){
4129  
4130  
4131    bool sameObjects = false;
4132    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4133  
4134 <  int counter = 0;  
4134 >  // Get the strings for the two objects that make up the pair.
4135 >  string obj1Type, obj2Type;
4136 >  getTwoObjs(inputType, obj1Type, obj2Type);
4137 >  bool isTwoTypesOfObject = true;
4138 >  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
4139 >
4140 >  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
4141 >  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4142 >  if (currentCut.inputCollection == inputType) {
4143 >    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4144 >      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4145 >      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4146 >    }
4147 >    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4148 >      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4149 >        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4150 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4151 >      }
4152 >    }
4153 >  }
4154 >
4155 >  int counter = 0;
4156 >
4157    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4158      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4159 <      
4159 >
4160        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4161  
4162  
4163 <      bool decision = true;//object passes if this cut doesn't cut on that type of object
4163 >      bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4164 >      bool plotDecision = true;
4165  
4166        if(currentCut.inputCollection == inputType){
4167  
4168 <        vector<bool> subcutDecisions;
4169 <        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4170 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4171 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4172 <        }
4173 <
4174 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4175 <        else{
4176 <          bool tempDecision = true;
4177 <          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4178 <            if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4179 <              tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4180 <            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4181 <              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4182 <          }
4183 <          decision = tempDecision;
4184 <        }
4168 >        vector<bool> subcutDecisions;
4169 >        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4170 >          string stringValue = "";
4171 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4172 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4173 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4174 >        }
4175 >
4176 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4177 >        else{
4178 >          bool tempDecision = subcutDecisions.at(0);
4179 >          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
4180 >            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
4181 >              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
4182 >            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4183 >              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4184 >          }
4185 >          cutDecision = tempDecision;
4186 >        }
4187 >        //invert the cut for plotting if this cut is a veto
4188 >        if(currentCut.isVeto) plotDecision = !cutDecision;
4189 >        else plotDecision = cutDecision;
4190        }
4191 <      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4192 <      
4193 <      //set flags for objects that pass each cut AND all the previous cuts
4194 <      bool previousCumulativeFlag = true;
4191 >      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4192 >      if (cutDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4193 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4194 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4195 >      }
4196 >      if (plotDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4197 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4198 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4199 >      }
4200 >
4201 >      //set flags for objects that pass this cut AND all the previous cuts
4202 >      bool previousCumulativeCutFlag = true;
4203        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4204 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
4205 <        else{ previousCumulativeFlag = false; break;}
4204 >        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4205 >        else{ previousCumulativeCutFlag = false; break;}
4206        }
4207 <      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4207 >      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4208 >
4209 >      bool previousCumulativePlotFlag = true;
4210 >      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4211 >        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4212 >        else{ previousCumulativePlotFlag = false; break;}
4213 >      }
4214 >      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4215 >      
4216 >      //apply flags for the components of the composite object as well
4217 >      bool currentCumulativeCutFlag = true;
4218 >      bool currentCumulativePlotFlag = true;
4219 >
4220 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4221 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4222 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4223 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4224 >
4225 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4226 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4227 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4228 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4229 >
4230 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));
4231 >
4232 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4233 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4234 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4235 >      }
4236 >
4237 >      if (currentCumulativePlotFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4238 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4239 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4240 >      }
4241 >
4242 >      counter++;
4243 >
4244 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4245 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4246  
4247 <      counter++;      
4247 > }
4248 >
4249 >
4250 > bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4251 >  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4252 >  // all cuts up to currentCutIndex
4253 >  bool previousCumulativeFlag = true;
4254 >  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4255 >    bool tempFlag = false;
4256 >    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4257 >    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4258 >
4259 >    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4260 >    else {
4261 >      previousCumulativeFlag = false; break;
4262      }
1788    
4263    }
4264 +  return previousCumulativeFlag;
4265 + }
4266  
4267  
4268 +
4269 +
4270 + template <class InputCollection>
4271 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4272 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4273 +
4274 +  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;
4275 +  for (uint object = 0; object != inputCollection->size(); object++) {
4276 +
4277 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4278 +
4279 +    string inputVariable = parameters.inputVariable;
4280 +    string function = "";
4281 +    string stringValue = "";
4282 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4283 +    BNTreeBranchVals_.at(parameters.name).push_back(value);
4284 +
4285 +  }
4286   }
4287  
4288  
4289   template <class InputCollection>
4290 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
4290 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4291 >
4292  
4293    for (uint object = 0; object != inputCollection->size(); object++){
4294  
4295 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4295 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4296  
4297      string currentString = parameters.inputVariables.at(0);
4298      string inputVariable = "";
4299      string function = "";
4300 <    if(currentString.find("(")==std::string::npos){
4301 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
4300 >    if(currentString.find("(")==string::npos){
4301 >      inputVariable = currentString;// variable to cut on
4302      }
4303      else{
4304 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4305 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4306 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4304 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4305 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4306 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4307      }
4308  
4309 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
4310 <    histo->Fill(value,puScaleFactor);
4309 >    string stringValue = "";
4310 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4311 >    histo->Fill(value,scaleFactor);
4312 >
4313 >    if (printEventInfo_) {
4314 >      // Write information about event to screen, for testing purposes.
4315 >      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
4316 >    }
4317  
4318    }
1818
4319   }
4320  
4321   template <class InputCollection1, class InputCollection2>
4322 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
4322 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4323  
4324    bool sameObjects = false;
4325    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4326  
4327 <  int counter = 0;  
4327 >  int pairCounter = -1;
4328    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4329      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4330 <      
4330 >
4331        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4332  
4333 +      pairCounter++;
4334        //only take objects which have passed all cuts and pairs which have passed all cuts
4335 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4336 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4337 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(counter)) continue;
4335 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4336 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4337 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4338  
4339        string currentString = parameters.inputVariables.at(0);
4340        string inputVariable = "";
4341        string function = "";
4342 <      if(currentString.find("(")==std::string::npos){
4343 <        inputVariable = currentString;// variable to cut on                                                                                                          
4342 >      if(currentString.find("(")==string::npos){
4343 >        inputVariable = currentString;// variable to cut on
4344        }
4345        else{
4346 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4347 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4348 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4346 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4347 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4348 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4349        }
1849      
1850      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
1851      histo->Fill(value,puScaleFactor);
4350  
4351 <      counter++;      
4351 >      string stringValue = "";
4352 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4353 >      histo->Fill(value,scaleFactor);
4354 >
4355      }
4356    }
4357  
# Line 1858 | Line 4359 | void OSUAnalysis::fill1DHistogram(TH1* h
4359  
4360  
4361   template <class InputCollection>
4362 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
4362 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4363  
4364    for (uint object = 0; object != inputCollection->size(); object++){
4365  
4366 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4366 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4367  
4368 +    string stringValue = "";
4369      string currentString = parameters.inputVariables.at(0);
4370      string inputVariable = "";
4371      string function = "";
4372 <    if(currentString.find("(")==std::string::npos){
4373 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
4372 >    if(currentString.find("(")==string::npos){
4373 >      inputVariable = currentString;// variable to cut on
4374      }
4375      else{
4376 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4377 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4378 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4376 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4377 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4378 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4379      }
4380 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
4380 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4381  
4382      currentString = parameters.inputVariables.at(1);
4383      inputVariable = "";
4384      function = "";
4385 <    if(currentString.find("(")==std::string::npos){
4386 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
4385 >    if(currentString.find("(")==string::npos){
4386 >      inputVariable = currentString;// variable to cut on
4387      }
4388      else{
4389 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4390 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4391 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4389 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4390 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4391 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4392      }
4393  
4394 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
4394 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4395  
4396 <    histo->Fill(valueX,valueY,puScaleFactor);
4396 >    histo->Fill(valueX,valueY,scaleFactor);
4397  
4398    }
4399  
4400   }
4401  
4402   template <class InputCollection1, class InputCollection2>
4403 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
4403 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4404  
4405    bool sameObjects = false;
4406    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4407  
4408 <  int counter = 0;  
4408 >  int pairCounter = -1;
4409    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4410      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4411 <      
4411 >
4412        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4413  
4414 +      pairCounter++;
4415 +
4416        //only take objects which have passed all cuts and pairs which have passed all cuts
4417 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4418 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4419 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(counter)) continue;
4417 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4418 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4419 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4420  
4421 +      string stringValue = "";
4422        string currentString = parameters.inputVariables.at(0);
4423        string inputVariable = "";
4424        string function = "";
4425 <      if(currentString.find("(")==std::string::npos){
4426 <        inputVariable = currentString;// variable to cut on                                                                                                          
4425 >      if(currentString.find("(")==string::npos){
4426 >        inputVariable = currentString;// variable to cut on
4427        }
4428        else{
4429 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4430 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4431 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4429 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4430 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4431 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4432        }
4433 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4433 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4434  
4435        currentString = parameters.inputVariables.at(1);
4436        inputVariable = "";
4437        function = "";
4438 <      if(currentString.find("(")==std::string::npos){
4439 <        inputVariable = currentString;// variable to cut on                                                                                                          
4438 >      if(currentString.find("(")==string::npos){
4439 >        inputVariable = currentString;// variable to cut on
4440        }
4441        else{
4442 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4443 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4444 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4442 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4443 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4444 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4445        }
4446 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4446 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4447  
4448  
4449 <      histo->Fill(valueX,valueY,puScaleFactor);
4449 >      histo->Fill(valueX,valueY,scaleFactor);
4450  
1946      counter++;      
4451      }
4452    }
4453  
4454   }
4455  
4456  
4457 + template <class InputObject>
4458 + int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
4459  
4460 < DEFINE_FWK_MODULE(OSUAnalysis);
4460 >  int bestMatchIndex = -1;
4461 >  double bestMatchDeltaR = 999;
4462  
4463 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4464 +
4465 +    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4466 +    if(currentDeltaR > 0.05) continue;
4467 +    //     cout << setprecision(3) << setw(20)
4468 +    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4469 +    //          << setw(20)
4470 +    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4471 +    //          << setw(20)
4472 +    //          << "\tdeltaR = " << currentDeltaR
4473 +    //          << setprecision(1)
4474 +    //          << setw(20)
4475 +    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4476 +    //          << setw(20)
4477 +    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4478 +    //          << setw(20)
4479 +    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4480 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4481 +      bestMatchIndex = mcparticle - mcparticles->begin();
4482 +      bestMatchDeltaR = currentDeltaR;
4483 +    }
4484  
4485 +  }
4486 +  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4487 +  //   else cout << "no match found..." << endl;
4488 +  return bestMatchIndex;
4489 +
4490 + }
4491 +
4492 +
4493 + int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
4494 +
4495 +  int bestMatchIndex = -1;
4496 +  double bestMatchDeltaR = 999;
4497 +
4498 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4499 +
4500 +    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
4501 +
4502 +    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
4503 +    if(currentDeltaR > 0.05) continue;
4504 +
4505 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4506 +      bestMatchIndex = mcparticle - mcparticles->begin();
4507 +      bestMatchDeltaR = currentDeltaR;
4508 +    }
4509 +
4510 +  }
4511 +
4512 +  return bestMatchIndex;
4513 + }
4514 +
4515 +
4516 + // bin      particle type
4517 + // ---      -------------
4518 + //  0        unmatched
4519 + //  1        u
4520 + //  2        d
4521 + //  3        s
4522 + //  4        c
4523 + //  5        b
4524 + //  6        t
4525 + //  7        e
4526 + //  8        mu
4527 + //  9        tau
4528 + // 10        nu
4529 + // 11        g
4530 + // 12        gamma
4531 + // 13        Z
4532 + // 14        W
4533 + // 15        light meson
4534 + // 16        K meson
4535 + // 17        D meson
4536 + // 18        B meson
4537 + // 19        light baryon
4538 + // 20        strange baryon
4539 + // 21        charm baryon
4540 + // 22        bottom baryon
4541 + // 23        QCD string
4542 + // 24        other
4543 +
4544 + int OSUAnalysis::getPdgIdBinValue(int pdgId){
4545 +
4546 +  int binValue = -999;
4547 +  int absPdgId = fabs(pdgId);
4548 +  if(pdgId == -1) binValue = 0;
4549 +  else if(absPdgId <= 6 ) binValue = absPdgId;
4550 +  else if(absPdgId == 11 ) binValue = 7;
4551 +  else if(absPdgId == 13 ) binValue = 8;
4552 +  else if(absPdgId == 15 ) binValue = 9;
4553 +  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
4554 +  else if(absPdgId == 21 ) binValue = 11;
4555 +  else if(absPdgId == 22 ) binValue = 12;
4556 +  else if(absPdgId == 23 ) binValue = 13;
4557 +  else if(absPdgId == 24 ) binValue = 14;
4558 +  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
4559 +  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
4560 +  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
4561 +  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
4562 +  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
4563 +  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4564 +  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4565 +  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4566 +  else if(absPdgId == 92  ) binValue = 23;
4567 +
4568 +  else binValue = 24;
4569 +
4570 +  return binValue;
4571 +
4572 + }
4573 +
4574 + const BNprimaryvertex *
4575 + OSUAnalysis::chosenVertex ()
4576 + {
4577 +  const BNprimaryvertex *chosenVertex = 0;
4578 +  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4579 +    flagPair vertexFlags;
4580 +    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4581 +      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4582 +        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4583 +        break;
4584 +      }
4585 +    }
4586 +    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4587 +      if(!vertexFlags.at(vertexIndex).first) continue;
4588 +      chosenVertex = & primaryvertexs->at(vertexIndex);
4589 +      break;
4590 +    }
4591 +  }
4592 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4593 +    chosenVertex = & primaryvertexs->at (0);
4594 +
4595 +  return chosenVertex;
4596 + }
4597 +
4598 + const BNmet *
4599 + OSUAnalysis::chosenMET ()
4600 + {
4601 +  const BNmet *chosenMET = 0;
4602 +  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4603 +    flagPair metFlags;
4604 +    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4605 +      if (cumulativeFlags.at("mets").at(i).size()){
4606 +        metFlags = cumulativeFlags.at("mets").at(i);
4607 +        break;
4608 +      }
4609 +    }
4610 +    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4611 +      if(!metFlags.at(metIndex).first) continue;
4612 +      chosenMET = & mets->at(metIndex);
4613 +      break;
4614 +    }
4615 +  }
4616 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4617 +    chosenMET = & mets->at (0);
4618 +
4619 +  return chosenMET;
4620 + }
4621 +
4622 + const BNelectron *
4623 + OSUAnalysis::chosenElectron ()
4624 + {
4625 +  const BNelectron *chosenElectron = 0;
4626 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4627 +    flagPair electronFlags;
4628 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4629 +      if (cumulativeFlags.at("electrons").at(i).size()){
4630 +        electronFlags = cumulativeFlags.at("electrons").at(i);
4631 +        break;
4632 +      }
4633 +    }
4634 +    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4635 +      if(!electronFlags.at(electronIndex).first) continue;
4636 +      chosenElectron = & electrons->at(electronIndex);
4637 +      break;
4638 +    }
4639 +  }
4640 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4641 +    chosenElectron = & electrons->at (0);
4642 +
4643 +  return chosenElectron;
4644 + }
4645 +
4646 +
4647 + const BNmuon *
4648 + OSUAnalysis::chosenMuon ()
4649 + {
4650 +  const BNmuon *chosenMuon = 0;
4651 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4652 +    flagPair muonFlags;
4653 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4654 +      if (cumulativeFlags.at("muons").at(i).size()){
4655 +        muonFlags = cumulativeFlags.at("muons").at(i);
4656 +        break;
4657 +      }
4658 +    }
4659 +    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4660 +      if(!muonFlags.at(muonIndex).first) continue;
4661 +      chosenMuon = & muons->at(muonIndex);
4662 +      break;
4663 +    }
4664 +  }
4665 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4666 +    chosenMuon = & muons->at (0);
4667 +
4668 +  return chosenMuon;
4669 + }
4670 +
4671 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines