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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines