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.94 by jbrinson, Wed Jul 3 09:30:38 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines