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.82 by wulsin, Tue Jun 4 15:53:18 2013 UTC

# Line 11 | Line 11 | OSUAnalysis::OSUAnalysis (const edm::Par
11    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
12    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
13    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
14 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
15    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
16    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
17    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
18    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
19    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
20 <  puFile_ (cfg.getParameter<std::string> ("puFile")),
21 <  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
22 <  dataset_ (cfg.getParameter<std::string> ("dataset")),
23 <  datasetType_ (cfg.getParameter<std::string> ("datasetType")),
20 >  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
21 >  puFile_ (cfg.getParameter<string> ("puFile")),
22 >  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
23 >  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
24 >  dataPU_ (cfg.getParameter<string> ("dataPU")),
25 >  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
26 >  muonSF_ (cfg.getParameter<string> ("muonSF")),
27 >  dataset_ (cfg.getParameter<string> ("dataset")),
28 >  datasetType_ (cfg.getParameter<string> ("datasetType")),
29    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
30    histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
31 <  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents"))
32 <
31 >  treeBranchSets_   (cfg.getParameter<vector<edm::ParameterSet> >("treeBranchSets")),
32 >  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
33 >  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
34 >  applyLeptonSF_       (cfg.getParameter<bool> ("applyLeptonSF")),
35 >  printEventInfo_      (cfg.getParameter<bool> ("printEventInfo")),
36 >  printAllTriggers_    (cfg.getParameter<bool> ("printAllTriggers")),
37 >  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
38 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
39 >  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
40   {
41  
42    TH1::SetDefaultSumw2 ();
43  
44    //create pile-up reweighting object, if necessary
45 <  if(datasetType_ != "data") puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
45 >  if(datasetType_ != "data") {
46 >    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
47 >    if (applyLeptonSF_){
48 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
49 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
50 >    }
51 >  }
52 >  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
53 >    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
54 >
55  
56    // Construct Cutflow Objects. These store the results of cut decisions and
57    // handle filling cut flow histograms.
58    masterCutFlow_ = new CutFlow (fs_);
37  std::vector<TFileDirectory> directories;
59  
60    //always get vertex collection so we can assign the primary vertex in the event
61 <  allNecessaryObjects.push_back("primaryvertexs");
41 <  //always make the plot of number of primary verticex (to check pile-up reweighting)
61 >  objectsToGet.push_back("primaryvertexs");
62    objectsToPlot.push_back("primaryvertexs");
63 +  objectsToCut.push_back("primaryvertexs");
64 +
65 +
66 +  //always get the MC particles to do GEN-matching
67 +  objectsToGet.push_back("mcparticles");
68  
69    //always get the event collection to do pile-up reweighting
70 <  allNecessaryObjects.push_back("events");
70 >  objectsToGet.push_back("events");
71 >
72 >
73 >  // Parse the tree variable definitions.    
74 >  for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++) {
75 >    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
76 >    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; }  
77 >    objectsToGet.push_back(tempInputCollection);
78 >    objectsToCut.push_back(tempInputCollection);
79 >
80 >    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
81 >
82 >    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
83 >      BranchSpecs br;
84 >      br.inputCollection = tempInputCollection;
85 >      br.inputVariable = branchList.at(iBranch);  
86 >      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);  
87 >      br.name = string(newName.Data());  
88 >      treeBranches_.push_back(br);
89 >    }  
90 >
91 >  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++) {
92 >
93  
94    //parse the histogram definitions
95    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
96  
97      string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
98      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
99 <    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
99 >    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
100 >    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
101 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
102 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
103 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
104 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
105 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
106 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
107 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
108 >        int spaceIndex = tempInputCollection.find(" ");
109 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
110 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
111 >      }
112 >      else{
113 >        objectsToGet.push_back(tempInputCollection);
114 >      }
115        objectsToPlot.push_back(tempInputCollection);
116 <      allNecessaryObjects.push_back(tempInputCollection);
117 <    }
118 <    else{//pair of objects, need to add them both to the things to allNecessaryObjects
119 <      int dashIndex = tempInputCollection.find("-");
120 <      int spaceIndex = tempInputCollection.find(" ");
121 <      int secondWordLength = spaceIndex - dashIndex;
122 <      allNecessaryObjects.push_back(tempInputCollection);
123 <      allNecessaryObjects.push_back(tempInputCollection.substr(0,dashIndex)+"s");
124 <      allNecessaryObjects.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
116 >      objectsToCut.push_back(tempInputCollection);
117 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
118 >      string obj1;
119 >      string obj2;
120 >      getTwoObjs(tempInputCollection, obj1, obj2);
121 >      string obj2ToGet = getObjToGet(obj2);
122 >      objectsToCut.push_back(tempInputCollection);
123 >      objectsToCut.push_back(obj1);
124 >      objectsToCut.push_back(obj2);
125        objectsToPlot.push_back(tempInputCollection);
126 <      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
127 <      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
128 <      }
126 >      objectsToPlot.push_back(obj1);
127 >      objectsToPlot.push_back(obj2);
128 >      objectsToGet.push_back(tempInputCollection);
129 >      objectsToGet.push_back(obj1);
130 >      objectsToGet.push_back(obj2ToGet);
131 >    } // end else
132 >
133 >
134  
135      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
136 <    
136 >
137      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
138  
139 +      vector<double> defaultValue;
140 +      defaultValue.push_back (-1.0);
141 +
142        histogram tempHistogram;
143        tempHistogram.inputCollection = tempInputCollection;
144        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
145        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
146 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
146 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
147 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
148 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
149        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
150 <      
150 >
151        histograms.push_back(tempHistogram);
152  
153      }
154 <  }
155 <  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object
154 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
155 >
156 >  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
157    sort( objectsToPlot.begin(), objectsToPlot.end() );
158    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
159  
160  
161  
162 +  //add histograms with the gen-matched id, mother id, and grandmother id
163 +  for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
164 +
165 +    string currentObject = objectsToPlot.at(currentObjectIndex);
166 +    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
167 +
168 +    histogram tempIdHisto;
169 +    histogram tempMomIdHisto;
170 +    histogram tempGmaIdHisto;
171 +    histogram tempIdVsMomIdHisto;
172 +    histogram tempIdVsGmaIdHisto;
173 +
174 +    tempIdHisto.inputCollection = currentObject;
175 +    tempMomIdHisto.inputCollection = currentObject;
176 +    tempGmaIdHisto.inputCollection = currentObject;
177 +    tempIdVsMomIdHisto.inputCollection = currentObject;
178 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
179 +
180 +    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
181 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
182 +
183 +    currentObject = currentObject.substr(0, currentObject.size()-1);
184 +    tempIdHisto.name = currentObject+"GenMatchId";
185 +    tempMomIdHisto.name = currentObject+"GenMatchMotherId";
186 +    tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
187 +    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
188 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
189 +
190 +    currentObject.at(0) = toupper(currentObject.at(0));
191 +    tempIdHisto.title = currentObject+" Gen-matched Particle";
192 +    tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
193 +    tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
194 +    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
195 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
196 +
197 +
198 +    int maxNum = 25;
199 +    vector<double> binVector;
200 +    binVector.push_back(maxNum);
201 +    binVector.push_back(0);
202 +    binVector.push_back(maxNum);
203 +
204 +    tempIdHisto.bins = binVector;
205 +    tempIdHisto.inputVariables.push_back("genMatchedId");
206 +    tempMomIdHisto.bins = binVector;
207 +    tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
208 +    tempGmaIdHisto.bins = binVector;
209 +    tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
210 +    binVector.push_back(maxNum);
211 +    binVector.push_back(0);
212 +    binVector.push_back(maxNum);
213 +    tempIdVsMomIdHisto.bins = binVector;
214 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
215 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
216 +    tempIdVsGmaIdHisto.bins = binVector;
217 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
218 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
219 +
220 +    histograms.push_back(tempIdHisto);
221 +    histograms.push_back(tempMomIdHisto);
222 +    histograms.push_back(tempGmaIdHisto);
223 +    histograms.push_back(tempIdVsMomIdHisto);
224 +    histograms.push_back(tempIdVsGmaIdHisto);
225 +  }
226 +
227  
228    channel tempChannel;
229    //loop over all channels (event selections)
# Line 99 | Line 237 | OSUAnalysis::OSUAnalysis (const edm::Par
237      //set triggers for this channel
238      vector<string> triggerNames;
239      triggerNames.clear();
240 +    vector<string> triggerToVetoNames;
241 +    triggerToVetoNames.clear();
242 +
243      tempChannel.triggers.clear();
244 +    tempChannel.triggersToVeto.clear();
245      if(channels_.at(currentChannel).exists("triggers")){
246        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
247        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
248          tempChannel.triggers.push_back(triggerNames.at(trigger));
249 <      allNecessaryObjects.push_back("triggers");
249 >      objectsToGet.push_back("triggers");
250 >    }
251 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
252 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
253 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
254 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
255 >      objectsToGet.push_back("triggers");
256      }
109
257  
258  
259  
260      //create cutFlow for this channel
261      cutFlows_.push_back (new CutFlow (fs_, channelName));
262 <
263 <    //book a directory in the output file with the name of the channel
117 <    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 <
262 >    vector<TFileDirectory> directories; //vector of directories in the output file.
263 >    vector<string> subSubDirNames;//subdirectories in each channel.
264      //get list of cuts for this channel
265      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
266  
267 +
268      //loop over and parse all cuts
269      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
270        cut tempCut;
271        //store input collection for cut
272        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
273 +      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
274 +      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
275 +      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
276 +      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
277 +      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
278 +      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
279 +      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
280 +      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
281        tempCut.inputCollection = tempInputCollection;
282 <      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
283 <        allNecessaryObjects.push_back(tempInputCollection);
282 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
283 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
284 >          int spaceIndex = tempInputCollection.find(" ");
285 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
286 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
287 >        }
288 >        else{
289 >          objectsToGet.push_back(tempInputCollection);
290 >        }
291 >        objectsToCut.push_back(tempInputCollection);
292        }
293 <      else{//pair of objects, need to add them both to the things to allNecessaryObjects
294 <        int dashIndex = tempInputCollection.find("-");
295 <        int spaceIndex = tempInputCollection.find(" ");
296 <        int secondWordLength = spaceIndex - dashIndex;
297 <        allNecessaryObjects.push_back(tempInputCollection);
298 <        allNecessaryObjects.push_back(tempInputCollection.substr(0,dashIndex)+"s");
299 <        allNecessaryObjects.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
293 >      else{//pair of objects, need to add them both to objectsToGet
294 >        string obj1;
295 >        string obj2;
296 >        getTwoObjs(tempInputCollection, obj1, obj2);
297 >        string obj2ToGet = getObjToGet(obj2);
298 >        objectsToCut.push_back(tempInputCollection);
299 >        objectsToCut.push_back(obj1);
300 >        objectsToCut.push_back(obj2);
301 >        objectsToGet.push_back(tempInputCollection);
302 >        objectsToGet.push_back(obj1);
303 >        objectsToGet.push_back(obj2ToGet);
304  
305        }
306  
# Line 197 | Line 308 | OSUAnalysis::OSUAnalysis (const edm::Par
308  
309        //split cut string into parts and store them
310        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
311 <      std::vector<string> cutStringVector = splitString(cutString);
311 >      vector<string> cutStringVector = splitString(cutString);
312        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
313 <        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
314 <        exit(0);
313 >        cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
314 >        exit(0);
315        }
316        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
317        for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
318 <        int indexOffset = 4 * subcutIndex;
319 <        string currentVariableString = cutStringVector.at(indexOffset);
320 <        if(currentVariableString.find("(")==std::string::npos){
321 <          tempCut.functions.push_back("");//no function was specified
322 <          tempCut.variables.push_back(currentVariableString);// variable to cut on
323 <        }
324 <        else{
325 <          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
326 <          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
327 <          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
328 <        }
329 <        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
330 <        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
331 <        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
318 >        int indexOffset = 4 * subcutIndex;
319 >        string currentVariableString = cutStringVector.at(indexOffset);
320 >        if(currentVariableString.find("(")==string::npos){
321 >          tempCut.functions.push_back("");//no function was specified
322 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
323 >        }
324 >        else{
325 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
326 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
327 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
328 >        }
329 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
330 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
331 >        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
332 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
333        }
334  
335        //get number of objects required to pass cut for event to pass
336        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
337 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
337 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
338        if(numberRequiredVector.size()!=2){
339 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
339 >        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
340          exit(0);
341        }
342  
# Line 232 | Line 344 | OSUAnalysis::OSUAnalysis (const edm::Par
344        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
345        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
346  
347 <
347 >      //Set up vectors to store the directories and subDIrectories for each channel.
348 >      string subSubDirName;
349        string tempCutName;
350        if(cuts_.at(currentCut).exists("alias")){
351          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
352 +        subSubDirName = "After " + cuts_.at(currentCut).getParameter<string> ("alias") + " Cut Applied";
353        }
354        else{
355          //construct string for cutflow table
# Line 243 | Line 357 | OSUAnalysis::OSUAnalysis (const edm::Par
357          string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
358          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
359          tempCutName = cutName;
360 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
361        }
247      tempCut.name = tempCutName;
362  
363 +      subSubDirNames.push_back(subSubDirName);
364 +      tempCut.name = tempCutName;
365  
366        tempChannel.cuts.push_back(tempCut);
367  
368  
253
369      }//end loop over cuts
370  
371 +    vector<map<string, TH1D*>> oneDHistsTmp;
372 +    vector<map<string, TH2D*>> twoDHistsTmp;
373 +    //book a directory in the output file with the name of the channel
374 +    TFileDirectory subDir = fs_->mkdir( channelName );
375 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
376 +    if(GetPlotsAfterEachCut_){
377 +      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
378 +        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
379 +        directories.push_back(subSubDir);
380 +        map<string, TH1D*> oneDhistoMap;
381 +        oneDHistsTmp.push_back(oneDhistoMap);
382 +        map<string, TH2D*> twoDhistoMap;
383 +        twoDHistsTmp.push_back(twoDhistoMap);
384 +      }
385 +      oneDHists_.push_back(oneDHistsTmp);
386 +      twoDHists_.push_back(twoDHistsTmp);
387 +    }
388 +    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
389 +    else{
390 +      map<string, TH1D*> oneDhistoMap;
391 +      oneDHistsTmp.push_back(oneDhistoMap);
392 +      map<string, TH2D*> twoDhistoMap;
393 +      twoDHistsTmp.push_back(twoDhistoMap);
394 +      oneDHists_.push_back(oneDHistsTmp);
395 +      twoDHists_.push_back(twoDHistsTmp);
396 +      directories.push_back(subDir);
397 +
398 +    }
399 +
400 +
401 +    //book all histograms included in the configuration
402 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
403 +      
404 +      TTree* newTree = directories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));  
405 +      BNTrees_.push_back(newTree);      
406 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
407 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
408 +        vector<float> newVec;  
409 +        BNTreeBranchVals_[currentVar.name] = newVec;  
410 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
411 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
412 +
413 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
414 +
415 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
416 +        int numBinsElements = currentHistogram.bins.size();
417 +        int numInputVariables = currentHistogram.inputVariables.size();
418 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
419 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
420 +        
421 +        if(numBinsElements == 1){
422 +          if(numBinEdgesX > 1){
423 +            if(numBinEdgesY > 1)
424 +              numBinsElements = 6;
425 +            else
426 +              numBinsElements = 3;
427 +          }
428 +        }
429 +        if(numBinsElements != 3 && numBinsElements !=6){
430 +          cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
431 +          exit(0);
432 +        }
433 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
434 +          cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
435 +          exit(0);
436 +        }
437 +        else if(numBinsElements == 3){
438 +          if (currentHistogram.bins.size () == 3)
439 +            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));
440 +          else
441 +            {
442 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
443 +            }
444 +        }
445 +        else if(numBinsElements == 6){
446 +          if (currentHistogram.bins.size () == 6)
447 +            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));
448 +          else
449 +            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 ());
450 +        }
451 +
452 +
453 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
454 +
455 +        // bin      particle type
456 +        // ---      -------------
457 +        //  0        unmatched
458 +        //  1        u
459 +        //  2        d
460 +        //  3        s
461 +        //  4        c
462 +        //  5        b
463 +        //  6        t
464 +        //  7        e
465 +        //  8        mu
466 +        //  9        tau
467 +        // 10        nu
468 +        // 11        g
469 +        // 12        gamma
470 +        // 13        Z
471 +        // 14        W
472 +        // 15        light meson
473 +        // 16        K meson
474 +        // 17        D meson
475 +        // 18        B meson
476 +        // 19        light baryon
477 +        // 20        strange baryon
478 +        // 21        charm baryon
479 +        // 22        bottom baryon
480 +        // 23        QCD string
481 +        // 24        other
482 +
483 +        vector<TString> labelArray;
484 +        labelArray.push_back("unmatched");
485 +        labelArray.push_back("u");
486 +        labelArray.push_back("d");
487 +        labelArray.push_back("s");
488 +        labelArray.push_back("c");
489 +        labelArray.push_back("b");
490 +        labelArray.push_back("t");
491 +        labelArray.push_back("e");
492 +        labelArray.push_back("#mu");
493 +        labelArray.push_back("#tau");
494 +        labelArray.push_back("#nu");
495 +        labelArray.push_back("g");
496 +        labelArray.push_back("#gamma");
497 +        labelArray.push_back("Z");
498 +        labelArray.push_back("W");
499 +        labelArray.push_back("light meson");
500 +        labelArray.push_back("K meson");
501 +        labelArray.push_back("D meson");
502 +        labelArray.push_back("B meson");
503 +        labelArray.push_back("light baryon");
504 +        labelArray.push_back("strange baryon");
505 +        labelArray.push_back("charm baryon");
506 +        labelArray.push_back("bottom baryon");
507 +        labelArray.push_back("QCD string");
508 +        labelArray.push_back("other");
509 +
510 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
511 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
512 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
513 +          }
514 +          else {
515 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
516 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
517 +          }
518 +        }
519 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
520 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
521 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
522 +        }
523 +
524 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
525 +
526 +
527 +      // Book a histogram for the number of each object type to be plotted.
528 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
529 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
530 +        string currentObject = objectsToPlot.at(currentObjectIndex);
531 +        int maxNum = 10;
532 +        if(currentObject == "mcparticles") maxNum = 50;
533 +        else if(currentObject == "primaryvertexs") maxNum = 50;
534 +
535 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
536 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
537 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
538 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
539 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
540 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
541 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
542 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
543 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
544 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
545 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
546 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
547 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
548 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
549 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
550 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
551 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
552 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
553 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
554 +
555 +        currentObject.at(0) = toupper(currentObject.at(0));
556 +        string histoName = "num" + currentObject;
557 +
558 +        if(histoName == "numPrimaryvertexs"){
559 +          string newHistoName = histoName + "BeforePileupCorrection";
560 +          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);
561 +          newHistoName = histoName + "AfterPileupCorrection";
562 +          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);
563 +        }
564 +        else
565 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
566 +      }
567 +    }//end of loop over directories
568      channels.push_back(tempChannel);
569      tempChannel.cuts.clear();
258
570    }//end loop over channels
571  
572  
573 <  //make unique vector of objects we need to cut on (so we make sure to get them from the event)
574 <  sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
575 <  allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
573 >  //make unique vector of objects we need to get from the event
574 >  sort( objectsToGet.begin(), objectsToGet.end() );
575 >  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
576 >  //make unique vector of objects we need to cut on
577 >  sort( objectsToCut.begin(), objectsToCut.end() );
578 >  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
579  
580  
581 < }
581 > } // end constructor OSUAnalysis::OSUAnalysis()
582 >
583  
584   OSUAnalysis::~OSUAnalysis ()
585   {
586 +
587    // Destroying the CutFlow objects causes the cut flow numbers and time
588    // information to be printed to standard output.
589    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
# Line 279 | Line 595 | void
595   OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
596   {
597  
282
598    // Retrieve necessary collections from the event.
599 <  edm::Handle<BNtriggerCollection> triggers;
600 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
599 >
600 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
601      event.getByLabel (triggers_, triggers);
602  
603 <  edm::Handle<BNjetCollection> jets;
604 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())
603 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
604 >    event.getByLabel (trigobjs_, trigobjs);
605 >
606 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
607      event.getByLabel (jets_, jets);
608  
609 <  edm::Handle<BNmuonCollection> muons;
293 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())
609 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
610      event.getByLabel (muons_, muons);
611  
612 <  edm::Handle<BNelectronCollection> electrons;
297 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())
612 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
613      event.getByLabel (electrons_, electrons);
614  
615 <  edm::Handle<BNeventCollection> events;
301 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())
615 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
616      event.getByLabel (events_, events);
617  
618 <  edm::Handle<BNtauCollection> taus;
305 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())
618 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
619      event.getByLabel (taus_, taus);
620  
621 <  edm::Handle<BNmetCollection> mets;
309 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())
621 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
622      event.getByLabel (mets_, mets);
623  
624 <  edm::Handle<BNtrackCollection> tracks;
313 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())
624 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
625      event.getByLabel (tracks_, tracks);
626  
627 <  edm::Handle<BNgenjetCollection> genjets;
317 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())
627 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
628      event.getByLabel (genjets_, genjets);
629  
630 <  edm::Handle<BNmcparticleCollection> mcparticles;
321 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())
630 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
631      event.getByLabel (mcparticles_, mcparticles);
632  
633 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
325 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())
633 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
634      event.getByLabel (primaryvertexs_, primaryvertexs);
635  
636 <  edm::Handle<BNbxlumiCollection> bxlumis;
329 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())
636 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
637      event.getByLabel (bxlumis_, bxlumis);
638  
639 <  edm::Handle<BNphotonCollection> photons;
333 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())
639 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
640      event.getByLabel (photons_, photons);
641  
642 <  edm::Handle<BNsuperclusterCollection> superclusters;
337 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())
642 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
643      event.getByLabel (superclusters_, superclusters);
644  
645 +  if (datasetType_ == "signalMC"){
646 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
647 +      event.getByLabel (stops_, stops);
648 +  }
649 +
650 +  if (useTrackCaloRhoCorr_) {
651 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
652 +    // This rho collection is not available in all BEANs.
653 +    // For description of rho values for different jet reconstruction algorithms, see
654 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
655 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
656 +  }
657 +
658 +  double masterScaleFactor = 1.0;
659  
660    //get pile-up event weight
661 <  double puScaleFactor = 0;
662 <  if(datasetType_ != "data")
663 <    puScaleFactor = puWeight_->at (events->at (0).numTruePV);
664 <  else
665 <    puScaleFactor = 1.00;
661 >  if (doPileupReweighting_ && datasetType_ != "data") {
662 >    //for "data" datasets, the numTruePV is always set to -1
663 >    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;  
664 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);  
665 >  }
666  
667 +  stopCTauScaleFactor_ = 1.0;
668 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
669 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
670 +  masterScaleFactor *= stopCTauScaleFactor_;
671  
672    //loop over all channels
673  
# Line 352 | Line 675 | OSUAnalysis::analyze (const edm::Event &
675      channel currentChannel = channels.at(currentChannelIndex);
676  
677      flagMap individualFlags;
355    flagMap cumulativeFlags;
678      counterMap passingCounter;
679 +    cumulativeFlags.clear ();
680 +
681 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
682 +         iter != BNTreeBranchVals_.end(); iter++) {
683 +      iter->second.clear();  // clear array
684 +    }
685  
686      bool triggerDecision = true;
687 <    if(currentChannel.triggers.size() != 0){  //triggers specified
688 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
687 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
688 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
689        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
690      }
691  
692      //loop over all cuts
693      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
694        cut currentCut = currentChannel.cuts.at(currentCutIndex);
695 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
696 +        string currentObject = objectsToCut.at(currentObjectIndex);
697  
698 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
369 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
370 <
698 >        //initialize maps to get ready to set cuts
699          individualFlags[currentObject].push_back (vector<bool> ());
700          cumulativeFlags[currentObject].push_back (vector<bool> ());
701  
702 +      }
703 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
704 +        string currentObject = objectsToCut.at(currentObjectIndex);
705 +
706 +        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
707  
708 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
709 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
708 >
709 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
710 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
711 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
712 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
713 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
714          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
715          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
716          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 385 | Line 722 | OSUAnalysis::analyze (const edm::Event &
722          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
723          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
724          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
725 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
726  
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      }
727  
728  
729 +        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
730 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
731 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
732 +                                                                   "muon-muon pairs");
733 +
734 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
735 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
736 +                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
737 +                                                                             "muon-secondary muon pairs");
738 +
739 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
740 +                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
741 +                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
742 +                                                                                     "electron-secondary electron pairs");
743 +
744 +        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
745 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
746 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
747 +                                                                           "electron-electron pairs");
748 +        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
749 +                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
750 +                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
751 +                                                                       "electron-muon pairs");
752 +        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
753 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
754 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
755 +                                                                 "jet-jet pairs");
756 +        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
757 +                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
758 +                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
759 +                                                                      "electron-jet pairs");
760 +        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
761 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
762 +                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
763 +                                                                  "muon-jet pairs");
764 +        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
765 +                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
766 +                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
767 +                                                                     "track-event pairs");
768 +        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
769 +                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
770 +                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
771 +                                                                        "electron-track pairs");
772 +        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
773 +                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
774 +                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
775 +                                                                    "muon-track pairs");
776 +        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
777 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
778 +                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
779 +                                                                  "muon-tau pairs");
780 +        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
781 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
782 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
783 +                                                                 "tau-tau pairs");
784 +        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
785 +                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
786 +                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
787 +                                                                   "tau-track pairs");
788 +        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
789 +                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
790 +                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
791 +                                                                          "electron-trigobj pairs");
792 +        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
793 +                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
794 +                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
795 +                                                                      "muon-trigobj pairs");
796  
797 <    }//end loop over all cuts
797 >        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
798 >      }
799  
800  
801  
802 +    }//end loop over all cuts
803      //use cumulative flags to apply cuts at event level
804  
805      bool eventPassedAllCuts = true;
806 <
806 >    //a vector to store cumulative cut descisions after each cut.
807 >    vector<bool> eventPassedPreviousCuts;
808      //apply trigger (true if none were specified)
809      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
810  
408
811      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
812  
813        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 413 | Line 815 | OSUAnalysis::analyze (const edm::Event &
815        int numberPassing = 0;
816  
817        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
818 <          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
818 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
819        }
418
820        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
821        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
421
822        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
823 +      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
824 +    }
825 +    double scaleFactor = masterScaleFactor;
826  
827 +    muonScaleFactor_ = electronScaleFactor_ = 1.0;
828 +    if(applyLeptonSF_ && datasetType_ != "data"){
829 +      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
830 +        vector<bool> muonFlags;
831 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
832 +          if (cumulativeFlags.at("muons").at(i).size()){
833 +            muonFlags = cumulativeFlags.at("muons").at(i);
834 +            break;
835 +          }
836 +        }
837 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
838 +          if(!muonFlags.at(muonIndex)) continue;
839 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
840 +        }
841 +      }
842 +      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
843 +        vector<bool> electronFlags;
844 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
845 +          if (cumulativeFlags.at("electrons").at(i).size()){
846 +            electronFlags = cumulativeFlags.at("electrons").at(i);
847 +            break;
848 +          }
849 +        }
850 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
851 +          if(!electronFlags.at(electronIndex)) continue;
852 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
853 +        }
854 +      }
855      }
856 +    scaleFactor *= muonScaleFactor_;
857 +    scaleFactor *= electronScaleFactor_;
858  
859 <    cutFlows_.at(currentChannelIndex)->fillCutFlow(puScaleFactor);
859 >    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
860  
861 +    if (printEventInfo_) {
862 +      // Write information about event to screen, for testing purposes.
863 +      cout << "Event passed all cuts in channel " <<  currentChannel.name
864 +           << ": run="  << events->at(0).run
865 +           << "  lumi=" << events->at(0).lumi
866 +           << "  event=" << events->at(0).evt
867 +           << endl;
868 +    }
869  
870  
871 <    if(!eventPassedAllCuts)continue;
871 >    //filling histograms
872 >    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
873 >      uint currentDir;
874 >      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
875 >      else{
876 >        currentDir = currentCut;
877 >      }
878 >      if(eventPassedPreviousCuts.at(currentDir)){
879  
880 +        // Assign BNTree variables
881 +        for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
882 +          BranchSpecs brSpecs = treeBranches_.at(iBranch);  
883 +          string coll = brSpecs.inputCollection;  
884 +          if (cumulativeFlags.count(coll) == 0) cout << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
885 +
886 +          if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).at(currentDir));            
887 +          else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).at(currentDir));
888 +          else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).at(currentDir));        
889 +          else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).at(currentDir));
890 +          else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).at(currentDir));
891 +          else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).at(currentDir));
892 +          else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).at(currentDir));
893 +          else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).at(currentDir));
894 +          else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).at(currentDir));
895 +          else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).at(currentDir));
896 +          else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).at(currentDir));
897 +          else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).at(currentDir));
898 +          else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).at(currentDir));
899 +          else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).at(currentDir));
900 +          else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).at(currentDir));
901 +          else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).at(currentDir));
902 +          else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).at(currentDir));
903 +          else if(coll == "stops"
904 +                  && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).at(currentDir));
905 +        } // end loop over branches  
906 +                                                                                          
907 +        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
908 +          histogram currentHistogram = histograms.at(histogramIndex);
909 +
910 +          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) cout << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
911 +
912 +          if(currentHistogram.inputVariables.size() == 1){
913 +            TH1D* histo;  
914 +            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
915 +            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
916 +            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
917 +            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
918 +            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
919 +            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
920 +            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
921 +                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
922 +                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
923 +            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
924 +                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
925 +                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
926 +            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
927 +            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
928 +                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
929 +                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
930 +            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
931 +                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
932 +                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
933 +            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
934 +                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
935 +                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
936 +            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
937 +                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
938 +                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
939 +            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
940 +                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
941 +                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
942 +            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
943 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
944 +                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
945 +            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
946 +                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
947 +                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
948 +            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
949 +                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
950 +                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
951 +            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
952 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
953 +                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
954 +            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
955 +                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
956 +                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
957 +            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
958 +                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
959 +                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
960 +            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
961 +                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
962 +                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
963 +            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
964 +                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
965 +                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
966 +
967 +            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
968 +            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
969 +            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
970 +            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
971 +            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
972 +            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
973 +            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
974 +            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
975 +            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
976 +            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
977 +            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
978 +            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
979 +          }
980 +          else if(currentHistogram.inputVariables.size() == 2){
981 +            TH2D* histo;
982 +            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
983 +            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
984 +            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
985 +            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
986 +            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
987 +            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
988 +                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
989 +                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
990 +            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
991 +                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
992 +                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
993 +            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
994 +            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
995 +            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
996 +                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
997 +                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
998 +            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
999 +                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1000 +                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1001 +            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1002 +                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1003 +                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1004 +            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1005 +                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1006 +                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1007 +            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1008 +                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1009 +                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1010 +            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1011 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1012 +                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1013 +            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1014 +                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1015 +                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1016 +            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1017 +                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1018 +                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1019 +            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1020 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1021 +                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1022 +            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1023 +                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1024 +                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1025 +            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1026 +                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1027 +                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1028 +            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1029 +                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1030 +                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1031 +            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1032 +                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1033 +                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1034 +            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1035 +            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1036 +            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1037 +            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1038 +            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1039 +                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1040 +                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1041 +            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1042 +            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1043 +            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1044 +            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1045 +            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1046 +            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1047 +            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1048 +            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1049 +          }
1050 +          
1051 +        }
1052  
1053  
1054 +        //fills histograms with the sizes of collections
1055 +        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1056  
1057 <    //set position of primary vertex in event, in order to calculate quantities relative to it
1058 <    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 <    }
1057 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1058 >          string objectToPlot = "";
1059  
1060 +          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1061 +          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1062 +          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1063 +          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1064 +          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1065 +          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1066 +          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1067 +          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1068 +          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1069 +          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1070 +          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1071 +          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1072 +          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1073 +          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1074 +          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1075 +          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1076 +          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1077 +          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1078 +          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1079 +          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1080 +          else objectToPlot = currentObject;
1081 +
1082 +          string tempCurrentObject = objectToPlot;
1083 +          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1084 +          string histoName = "num" + tempCurrentObject;
1085 +
1086 +          //set position of primary vertex in event, in order to calculate quantities relative to it
1087 +          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1088 +            vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1089 +            int numToPlot = 0;
1090 +            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1091 +              if(lastCutFlags.at(currentFlag)) numToPlot++;
1092 +            }
1093 +            if(objectToPlot == "primaryvertexs"){
1094 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1095 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1096 +            }
1097 +            else {
1098 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1099 +            }
1100 +          }
1101 +        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1102 +        
1103 +        if (!BNTrees_.at(currentChannelIndex)) { cout << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }  
1104 +        BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts  
1105  
1106 +      } // end if(eventPassedPreviousCuts.at(currentDir)){
1107 +    } // end loop over cuts
1108 +    
1109 +  } // end loop over channel
1110  
446    //filling histograms
447    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
448      histogram currentHistogram = histograms.at(histogramIndex);
1111  
1112 <      if(currentHistogram.inputVariables.size() == 1){
451 <        TH1D* histo;
452 <        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
453 <        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
454 <        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
455 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),\
456 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(),\
457 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
458 <        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
459 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
460 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
461 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
462 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
463 <                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
464 <                                                                                              cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
465 <        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
466 <        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
467 <        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
468 <        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
469 <        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
470 <        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
471 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
472 <        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
473 <        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
474 <        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
475 <      }
476 <      else if(currentHistogram.inputVariables.size() == 2){
477 <        TH2D* histo;
478 <        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
479 <        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
480 <        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
481 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
482 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
483 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
484 <        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
485 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
486 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
487 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
488 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
489 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
490 <                                                                                               cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
491 <        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
492 <        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
493 <        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
494 <        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
495 <        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
496 <        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
497 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
498 <        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
499 <        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
500 <        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
501 <      }
502 <    }
503 <
504 <
505 <    //fills histograms with the sizes of collections
506 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
507 <      string currentObject = objectsToPlot.at(currentObjectIndex);
508 <
509 <      if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
510 <      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
511 <      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
512 <      string tempCurrentObject = currentObject;
513 <      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
514 <      string histoName = "num" + tempCurrentObject;
515 <
516 <
517 <      if(currentObject == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),puScaleFactor);
518 <      else if(currentObject == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),puScaleFactor);
519 <      else if(currentObject == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,puScaleFactor);
520 <      else if(currentObject == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),puScaleFactor);
521 <      else if(currentObject == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,puScaleFactor);
522 <      else if(currentObject == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),puScaleFactor);
523 <      else if(currentObject == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),puScaleFactor);
524 <      else if(currentObject == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),puScaleFactor);
525 <      else if(currentObject == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),puScaleFactor);
526 <      else if(currentObject == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),puScaleFactor);
527 <      else if(currentObject == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),puScaleFactor);
528 <      else if(currentObject == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),puScaleFactor);
529 <      else if(currentObject == "primaryvertexs"){
530 <        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
531 <        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),puScaleFactor);
532 <      }
533 <      else if(currentObject == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),puScaleFactor);
534 <      else if(currentObject == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),puScaleFactor);
535 <      else if(currentObject == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),puScaleFactor);
1112 >  masterCutFlow_->fillCutFlow(masterScaleFactor);
1113  
537    }
538  } //end loop over channel
1114  
1115 <  masterCutFlow_->fillCutFlow(puScaleFactor);
1115 > } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1116  
1117  
1118  
1119 < }
1119 > bool
1120 > OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
1121  
1122  
1123 +  if(comparison == ">")       return testValue >  cutValue;
1124 +  else if(comparison == ">=") return testValue >= cutValue;
1125 +  else if(comparison == "<")  return testValue <  cutValue;
1126 +  else if(comparison == "<=") return testValue <= cutValue;
1127 +  else if(comparison == "==") return testValue == cutValue;
1128 +  else if(comparison == "=") return testValue == cutValue;
1129 +  else if(comparison == "!=") return testValue != cutValue;
1130 +  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1131 +
1132 + }
1133 +
1134   bool
1135 < OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
1135 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1136  
1137  
1138    if(comparison == ">")       return testValue >  cutValue;
# Line 555 | Line 1142 | OSUAnalysis::evaluateComparison (double
1142    else if(comparison == "==") return testValue == cutValue;
1143    else if(comparison == "=") return testValue == cutValue;
1144    else if(comparison == "!=") return testValue != cutValue;
1145 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1145 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1146  
1147   }
1148  
1149   bool
1150 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1150 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1151  
1152 +  //initialize to false until a chosen trigger is passed
1153    bool triggerDecision = false;
1154  
1155 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1156 <    {
1157 <      if(trigger->pass != 1) continue;
1158 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1159 <        {
1160 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1161 <            triggerDecision = true;
1162 <          }
1163 <        }
1155 >  if (printAllTriggers_) cout << "Printing list of all available triggers (which this event may or may not pass):" << endl;  
1156 >  //loop over all triggers defined in the event
1157 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1158 >
1159 >    if (printAllTriggers_) cout << "   " << trigger->name << endl;  
1160 >
1161 >    //we're only interested in triggers that actually passed
1162 >    if(trigger->pass != 1) continue;
1163 >
1164 >    //if the event passes one of the veto triggers, exit and return false
1165 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1166 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1167      }
1168 <  return triggerDecision;
1168 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1169 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1170 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1171 >    }  
1172 >  }
1173 >
1174 >  printAllTriggers_ = false;  // only print triggers once, not every event  
1175  
1176 +  //if none of the veto triggers fired:
1177 +  //return the OR of all the chosen triggers
1178 +  if (triggersToTest.size() != 0) return triggerDecision;
1179 +  //or if no triggers were defined return true
1180 +  else return true;
1181   }
1182  
1183 < std::vector<std::string>
1183 >
1184 > vector<string>
1185   OSUAnalysis::splitString (string inputString){
1186  
1187 <  std::stringstream stringStream(inputString);
1188 <  std::istream_iterator<std::string> begin(stringStream);
1189 <  std::istream_iterator<std::string> end;
1190 <  std::vector<std::string> stringVector(begin, end);
1187 >  stringstream stringStream(inputString);
1188 >  istream_iterator<string> begin(stringStream);
1189 >  istream_iterator<string> end;
1190 >  vector<string> stringVector(begin, end);
1191    return stringVector;
1192  
1193   }
1194  
1195 +
1196 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1197 +  // Set two object strings from the tempInputCollection string,
1198 +  // For example, if tempInputCollection is "electron-muon pairs",
1199 +  // then obj1 = "electrons" and obj2 = "muons".
1200 +  // Note that the objects have an "s" appended.
1201 +
1202 +  int dashIndex = tempInputCollection.find("-");
1203 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1204 +  int secondWordLength = spaceIndex - dashIndex;
1205 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1206 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1207 +
1208 + }
1209 +
1210 +
1211 + string OSUAnalysis::getObjToGet(string obj) {
1212 +  // Return the string corresponding to the object to get for the given obj string.
1213 +  // Right now this only handles the case in which obj contains "secondary",
1214 +  // e.g, "secondary muons".
1215 +  // Note that "s" is NOT appended.
1216 +
1217 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1218 +  int firstSpaceIndex = obj.find_first_of(" ");
1219 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1220 +
1221 + }
1222 +
1223 +
1224 + //!jet valueLookup
1225   double
1226 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1226 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1227  
1228    double value = 0.0;
1229    if(variable == "energy") value = object->energy;
# Line 710 | Line 1343 | OSUAnalysis::valueLookup (const BNjet* o
1343    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1344  
1345  
1346 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1346 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1347  
1348    value = applyFunction(function, value);
1349  
# Line 718 | Line 1351 | OSUAnalysis::valueLookup (const BNjet* o
1351   }
1352  
1353  
1354 <
1354 > //!muon valueLookup
1355   double
1356 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1356 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1357  
1358    double value = 0.0;
1359    if(variable == "energy") value = object->energy;
# Line 736 | Line 1369 | OSUAnalysis::valueLookup (const BNmuon*
1369    else if(variable == "ecalIso") value = object->ecalIso;
1370    else if(variable == "hcalIso") value = object->hcalIso;
1371    else if(variable == "caloIso") value = object->caloIso;
1372 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
1372 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
1373    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
1374    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
1375    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 875 | Line 1508 | OSUAnalysis::valueLookup (const BNmuon*
1508    else if(variable == "time_ndof") value = object->time_ndof;
1509  
1510    //user-defined variables
1511 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1512 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1513 <  else if(variable == "detIso") value = (object->trackIso) / object->pt;
1514 <  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1511 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1512 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1513 >  else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1514 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1515    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1516 +  else if(variable == "metMT") {
1517 +    if (const BNmet *met = chosenMET ())
1518 +      {
1519 +        double dPhi = deltaPhi (object->phi, met->phi);
1520 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1521 +      }
1522 +    else
1523 +      value = -999;
1524 +  }
1525 +
1526 +
1527 +
1528 +  else if(variable == "correctedD0VertexInEBPlus"){
1529 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1530 +    else value = -999;
1531 +  }
1532 +  else if(variable == "correctedD0VertexOutEBPlus"){
1533 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1534 +    else value = -999;
1535 +  }
1536 +  else if(variable == "correctedD0VertexEEPlus"){
1537 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1538 +    else value = -999;
1539 +  }
1540 +
1541 +  else if(variable == "correctedD0BeamspotInEBPlus"){
1542 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1543 +    else value = -999;
1544 +  }
1545 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
1546 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1547 +    else value = -999;
1548 +  }
1549 +  else if(variable == "correctedD0BeamspotEEPlus"){
1550 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1551 +    else value = -999;
1552 +  }
1553 +
1554 +  else if(variable == "correctedD0VertexInEBMinus"){
1555 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1556 +    else value = -999;
1557 +  }
1558 +  else if(variable == "correctedD0VertexOutEBMinus"){
1559 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1560 +    else value = -999;
1561 +  }
1562 +  else if(variable == "correctedD0VertexEEMinus"){
1563 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1564 +    else value = -999;
1565 +  }
1566 +
1567 +  else if(variable == "correctedD0BeamspotInEBMinus"){
1568 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1569 +    else value = -999;
1570 +  }
1571 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
1572 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1573 +    else value = -999;
1574 +  }
1575 +  else if(variable == "correctedD0BeamspotEEMinus"){
1576 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1577 +    else value = -999;
1578 +  }
1579 +
1580 +
1581 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1582 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1583 +    else value = -999;
1584 +  }
1585 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1586 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1587 +    else value = -999;
1588 +  }
1589 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
1590 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1591 +    else value = -999;
1592 +  }
1593 +
1594 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1595 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1596 +    else value = -999;
1597 +  }
1598 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1599 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1600 +    else value = -999;
1601 +  }
1602 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1603 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1604 +    else value = -999;
1605 +  }
1606 +
1607 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1608 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1609 +    else value = -999;
1610 +  }
1611 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1612 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1613 +    else value = -999;
1614 +  }
1615 +  else if(variable == "correctedD0VertexEENegativeCharge"){
1616 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1617 +    else value = -999;
1618 +  }
1619 +
1620 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1621 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1622 +    else value = -999;
1623 +  }
1624 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1625 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1626 +    else value = -999;
1627 +  }
1628 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1629 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1630 +    else value = -999;
1631 +  }
1632 +
1633 +
1634    else if(variable == "tightID") {
1635 <    value = object->isGlobalMuon > 0            \
1636 <      && object->isPFMuon > 0                   \
1637 <      && object->normalizedChi2 < 10            \
1638 <      && object->numberOfValidMuonHits > 0      \
1639 <      && object->numberOfMatchedStations > 1    \
1640 <      && fabs(object->correctedD0Vertex) < 0.2  \
1641 <      && fabs(object->correctedDZ) < 0.5        \
1642 <      && object->numberOfValidPixelHits > 0     \
1635 >    value = object->isGlobalMuon > 0                \
1636 >      && object->isPFMuon > 0                        \
1637 >      && object->normalizedChi2 < 10                \
1638 >      && object->numberOfValidMuonHits > 0        \
1639 >      && object->numberOfMatchedStations > 1        \
1640 >      && fabs(object->correctedD0Vertex) < 0.2        \
1641 >      && fabs(object->correctedDZ) < 0.5        \
1642 >      && object->numberOfValidPixelHits > 0                \
1643        && object->numberOfLayersWithMeasurement > 5;
893    
894
1644    }
1645    else if(variable == "tightIDdisplaced"){
1646 <    value = object->isGlobalMuon > 0            \
1647 <      && object->isPFMuon > 0                   \
1648 <      && object->normalizedChi2 < 10            \
1649 <      && object->numberOfValidMuonHits > 0      \
1650 <      && object->numberOfMatchedStations > 1    \
1651 <      && object->numberOfValidPixelHits > 0     \
1646 >    value = object->isGlobalMuon > 0                \
1647 >      && object->isPFMuon > 0                        \
1648 >      && object->normalizedChi2 < 10                \
1649 >      && object->numberOfValidMuonHits > 0        \
1650 >      && object->numberOfMatchedStations > 1        \
1651 >      && object->numberOfValidPixelHits > 0        \
1652        && object->numberOfLayersWithMeasurement > 5;
1653    }
1654  
1655 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1655 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1656 >
1657 >  else if(variable == "genMatchedPdgId"){
1658 >    int index = getGenMatchedParticleIndex(object);
1659 >    if(index == -1) value = 0;
1660 >    else value = mcparticles->at(index).id;
1661 >  }
1662 >
1663 >  else if(variable == "genMatchedId"){
1664 >    int index = getGenMatchedParticleIndex(object);
1665 >    if(index == -1) value = 0;
1666 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
1667 >  }
1668 >  else if(variable == "genMatchedMotherId"){
1669 >    int index = getGenMatchedParticleIndex(object);
1670 >    if(index == -1) value = 0;
1671 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1672 >  }
1673 >  else if(variable == "genMatchedMotherIdReverse"){
1674 >    int index = getGenMatchedParticleIndex(object);
1675 >    if(index == -1) value = 24;
1676 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1677 >  }
1678 >  else if(variable == "genMatchedGrandmotherId"){
1679 >    int index = getGenMatchedParticleIndex(object);
1680 >    if(index == -1) value = 0;
1681 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1682 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1683 >      if(motherIndex == -1) value = 0;
1684 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1685 >    }
1686 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1687 >  }
1688 >  else if(variable == "genMatchedGrandmotherIdReverse"){
1689 >    int index = getGenMatchedParticleIndex(object);
1690 >    if(index == -1) value = 24;
1691 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1692 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1693 >      if(motherIndex == -1) value = 24;
1694 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1695 >    }
1696 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1697 >  }
1698 >  else if(variable == "pfMuonsFromVertex"){
1699 >    double d0Error, dzError;
1700 >
1701 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1702 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1703 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1704 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1705 >      || fabs (object->correctedDZ / dzError) > 99.0;
1706 >    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1707 >  }
1708 >
1709 >
1710 >
1711 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1712  
1713    value = applyFunction(function, value);
1714  
1715    return value;
1716   }
1717  
1718 <
1718 > //!electron valueLookup
1719   double
1720 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1720 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1721  
1722    double value = 0.0;
1723    if(variable == "energy") value = object->energy;
# Line 1073 | Line 1878 | OSUAnalysis::valueLookup (const BNelectr
1878    else if(variable == "passConvVeto") value = object->passConvVeto;
1879  
1880    //user-defined variables
1881 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1882 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1881 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1882 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1883    else if(variable == "detIso") value = (object->trackIso) / object->pt;
1884    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1885 +  else if(variable == "metMT") {
1886 +    if (const BNmet *met = chosenMET ())
1887 +      {
1888 +        double dPhi = deltaPhi (object->phi, met->phi);
1889 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1890 +      }
1891 +    else
1892 +      value = -999;
1893 +  }
1894  
1895 +  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
1896 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
1897 +    else value = -999;
1898 +  }
1899 +  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
1900 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
1901 +    else value = -999;
1902 +  }
1903  
1904 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1904 >  else if(variable == "correctedD0VertexInEBPlus"){
1905 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1906 >    else value = -999;
1907 >  }
1908 >  else if(variable == "correctedD0VertexOutEBPlus"){
1909 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1910 >    else value = -999;
1911 >  }
1912 >  else if(variable == "correctedD0VertexEEPlus"){
1913 >    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
1914 >    else value = -999;
1915 >  }
1916 >
1917 >  else if(variable == "correctedD0BeamspotInEBPlus"){
1918 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1919 >    else value = -999;
1920 >  }
1921 >  else if(variable == "correctedD0BeamspotOutEBPlus"){
1922 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1923 >    else value = -999;
1924 >  }
1925 >  else if(variable == "correctedD0BeamspotEEPlus"){
1926 >    if(object->isEE && object->eta > 0) value = object->correctedD0;
1927 >    else value = -999;
1928 >  }
1929 >
1930 >  else if(variable == "correctedD0VertexInEBMinus"){
1931 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1932 >    else value = -999;
1933 >  }
1934 >  else if(variable == "correctedD0VertexOutEBMinus"){
1935 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1936 >    else value = -999;
1937 >  }
1938 >  else if(variable == "correctedD0VertexEEMinus"){
1939 >    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
1940 >    else value = -999;
1941 >  }
1942 >
1943 >  else if(variable == "correctedD0BeamspotInEBMinus"){
1944 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1945 >    else value = -999;
1946 >  }
1947 >  else if(variable == "correctedD0BeamspotOutEBMinus"){
1948 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1949 >    else value = -999;
1950 >  }
1951 >  else if(variable == "correctedD0BeamspotEEMinus"){
1952 >    if(object->isEE && object->eta < 0) value = object->correctedD0;
1953 >    else value = -999;
1954 >  }
1955 >
1956 >  else if(variable == "tightID"){
1957 >    if (object->isEB)
1958 >      {
1959 >        value = fabs(object->delEtaIn) < 0.004 \
1960 >          && fabs (object->delPhiIn) < 0.03 \
1961 >          && object->scSigmaIEtaIEta < 0.01 \
1962 >          && object->hadOverEm < 0.12 \
1963 >          && fabs (object->correctedD0Vertex) < 0.02 \
1964 >          && fabs (object->correctedDZ) < 0.1 \
1965 >          && object->absInvEMinusInvPin < 0.05 \
1966 >          && object->passConvVeto;
1967 >      }
1968 >    else
1969 >      {
1970 >        value = fabs(object->delEtaIn) < 0.005 \
1971 >          && fabs (object->delPhiIn) < 0.02 \
1972 >          && object->scSigmaIEtaIEta < 0.03 \
1973 >          && object->hadOverEm < 0.10 \
1974 >          && fabs (object->correctedD0Vertex) < 0.02 \
1975 >          && fabs (object->correctedDZ) < 0.1 \
1976 >          && object->absInvEMinusInvPin < 0.05 \
1977 >          && object->passConvVeto;
1978 >      }
1979 >  }
1980 >
1981 >  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1982 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1983 >    else value = -999;
1984 >  }
1985 >  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1986 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1987 >    else value = -999;
1988 >  }
1989 >  else if(variable == "correctedD0VertexEEPositiveCharge"){
1990 >    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
1991 >    else value = -999;
1992 >  }
1993 >
1994 >  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1995 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1996 >    else value = -999;
1997 >  }
1998 >  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1999 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
2000 >    else value = -999;
2001 >  }
2002 >  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
2003 >    if(object->isEE && object->charge > 0) value = object->correctedD0;
2004 >    else value = -999;
2005 >  }
2006 >
2007 >  else if(variable == "correctedD0VertexInEBNegativeCharge"){
2008 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2009 >    else value = -999;
2010 >  }
2011 >  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
2012 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2013 >    else value = -999;
2014 >  }
2015 >  else if(variable == "correctedD0VertexEENegativeCharge"){
2016 >    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
2017 >    else value = -999;
2018 >  }
2019 >
2020 >  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
2021 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
2022 >    else value = -999;
2023 >  }
2024 >  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
2025 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
2026 >    else value = -999;
2027 >  }
2028 >  else if(variable == "correctedD0BeamspotEENegativeCharge"){
2029 >    if(object->isEE && object->charge < 0) value = object->correctedD0;
2030 >    else value = -999;
2031 >  }
2032 >
2033 >
2034 >  else if(variable == "tightIDdisplaced"){
2035 >    if (object->isEB)
2036 >      {
2037 >        value = fabs(object->delEtaIn) < 0.004 \
2038 >          && fabs (object->delPhiIn) < 0.03 \
2039 >          && object->scSigmaIEtaIEta < 0.01 \
2040 >          && object->hadOverEm < 0.12 \
2041 >          && object->absInvEMinusInvPin < 0.05;
2042 >      }
2043 >    else
2044 >      {
2045 >        value = fabs (object->delEtaIn) < 0.005 \
2046 >          && fabs (object->delPhiIn) < 0.02 \
2047 >          && object->scSigmaIEtaIEta < 0.03 \
2048 >          && object->hadOverEm < 0.10 \
2049 >          && object->absInvEMinusInvPin < 0.05;
2050 >      }
2051 >  }
2052 >
2053 >
2054 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2055 >
2056 >  else if(variable == "genMatchedPdgId"){
2057 >    int index = getGenMatchedParticleIndex(object);
2058 >    if(index == -1) value = 0;
2059 >    else value = mcparticles->at(index).id;
2060 >  }
2061 >
2062 >
2063 >  else if(variable == "genMatchedId"){
2064 >    int index = getGenMatchedParticleIndex(object);
2065 >    if(index == -1) value = 0;
2066 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2067 >  }
2068 >  else if(variable == "genMatchedMotherId"){
2069 >    int index = getGenMatchedParticleIndex(object);
2070 >    if(index == -1) value = 0;
2071 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2072 >  }
2073 >  else if(variable == "genMatchedMotherIdReverse"){
2074 >    int index = getGenMatchedParticleIndex(object);
2075 >    if(index == -1) value = 24;
2076 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2077 >  }
2078 >  else if(variable == "genMatchedGrandmotherId"){
2079 >    int index = getGenMatchedParticleIndex(object);
2080 >    if(index == -1) value = 0;
2081 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2082 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2083 >      if(motherIndex == -1) value = 0;
2084 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2085 >    }
2086 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2087 >  }
2088 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2089 >    int index = getGenMatchedParticleIndex(object);
2090 >    if(index == -1) value = 24;
2091 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2092 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2093 >      if(motherIndex == -1) value = 24;
2094 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2095 >    }
2096 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2097 >  }
2098 >  else if(variable == "pfElectronsFromVertex"){
2099 >    double d0Error, dzError;
2100 >
2101 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2102 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2103 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2104 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2105 >      || fabs (object->correctedDZ / dzError) > 99.0;
2106 >    value = !value;
2107 >  }
2108 >
2109 >
2110 >
2111 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2112  
2113    value = applyFunction(function, value);
2114  
2115    return value;
2116   }
2117  
2118 <
2118 > //!event valueLookup
2119   double
2120 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2120 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2121  
2122    double value = 0.0;
2123  
# Line 1156 | Line 2185 | OSUAnalysis::valueLookup (const BNevent*
2185    else if(variable == "id1") value = object->id1;
2186    else if(variable == "id2") value = object->id2;
2187    else if(variable == "evt") value = object->evt;
2188 +  else if(variable == "puScaleFactor"){
2189 +    if(doPileupReweighting_ && datasetType_ != "data")
2190 +      value = puWeight_->at (events->at (0).numTruePV);
2191 +    else
2192 +      value = 1.0;
2193 +  }
2194 +  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2195 +  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2196 +  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2197  
2198 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2198 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2199  
2200    value = applyFunction(function, value);
2201  
2202    return value;
2203   }
2204  
2205 + //!tau valueLookup
2206   double
2207 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2207 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2208  
2209    double value = 0.0;
2210  
# Line 1210 | Line 2249 | OSUAnalysis::valueLookup (const BNtau* o
2249    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2250  
2251  
2252 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2252 >
2253 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2254 >
2255 >  else if(variable == "genMatchedPdgId"){
2256 >    int index = getGenMatchedParticleIndex(object);
2257 >    if(index == -1) value = 0;
2258 >    else value = mcparticles->at(index).id;
2259 >  }
2260 >
2261 >  else if(variable == "genMatchedId"){
2262 >    int index = getGenMatchedParticleIndex(object);
2263 >    if(index == -1) value = 0;
2264 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2265 >  }
2266 >  else if(variable == "genMatchedMotherId"){
2267 >    int index = getGenMatchedParticleIndex(object);
2268 >    if(index == -1) value = 0;
2269 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2270 >  }
2271 >  else if(variable == "genMatchedMotherIdReverse"){
2272 >    int index = getGenMatchedParticleIndex(object);
2273 >    if(index == -1) value = 24;
2274 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2275 >  }
2276 >  else if(variable == "genMatchedGrandmotherId"){
2277 >    int index = getGenMatchedParticleIndex(object);
2278 >    if(index == -1) value = 0;
2279 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2280 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2281 >      if(motherIndex == -1) value = 0;
2282 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2283 >    }
2284 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2285 >  }
2286 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2287 >    int index = getGenMatchedParticleIndex(object);
2288 >    if(index == -1) value = 24;
2289 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2290 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2291 >      if(motherIndex == -1) value = 24;
2292 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2293 >    }
2294 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2295 >  }
2296 >
2297 >
2298 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2299  
2300    value = applyFunction(function, value);
2301  
2302    return value;
2303   }
2304  
2305 + //!met valueLookup
2306   double
2307 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2307 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2308  
2309    double value = 0.0;
2310  
# Line 1282 | Line 2368 | OSUAnalysis::valueLookup (const BNmet* o
2368    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2369    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2370  
2371 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2371 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2372  
2373    value = applyFunction(function, value);
2374  
2375    return value;
2376   }
2377  
2378 + //!track valueLookup
2379   double
2380 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2380 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2381  
2382    double value = 0.0;
2383 +  double pMag = sqrt(object->pt * object->pt +
2384 +                     object->pz * object->pz);
2385  
2386    if(variable == "pt") value = object->pt;
2387    else if(variable == "px") value = object->px;
# Line 1313 | Line 2402 | OSUAnalysis::valueLookup (const BNtrack*
2402    else if(variable == "isHighPurity") value = object->isHighPurity;
2403  
2404  
2405 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2405 >  //additional BNs info for disappTrks
2406 >  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2407 >  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2408 >  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2409 >  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2410 >  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2411 >  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2412 >  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2413 >  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2414 >  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2415 >  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2416 >  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2417 >
2418 >  //user defined variables
2419 >  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;
2420 >  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2421 >  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2422 >  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2423 >  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2424 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2425 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2426 >  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2427 >  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2428 >  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2429 >  else if(variable == "ptError")                    value = object->ptError;
2430 >  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2431 >  else if (variable == "d0wrtPV"){
2432 >    double vx = object->vx - chosenVertex ()->x,
2433 >      vy = object->vy - chosenVertex ()->y,
2434 >      px = object->px,
2435 >      py = object->py,
2436 >      pt = object->pt;
2437 >    value = (-vx * py + vy * px) / pt;
2438 >  }
2439 >  else if (variable == "dZwrtPV"){
2440 >    double vx = object->vx - chosenVertex ()->x,
2441 >      vy = object->vy - chosenVertex ()->y,
2442 >      vz = object->vz - chosenVertex ()->z,
2443 >      px = object->px,
2444 >      py = object->py,
2445 >      pz = object->pz,
2446 >      pt = object->pt;
2447 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2448 >  }
2449 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2450 >
2451 >  else if(variable == "genMatchedPdgId"){
2452 >    int index = getGenMatchedParticleIndex(object);
2453 >    if(index == -1) value = 0;
2454 >    else value = mcparticles->at(index).id;
2455 >  }
2456 >
2457 >
2458 >  else if(variable == "genMatchedId"){
2459 >    int index = getGenMatchedParticleIndex(object);
2460 >    if(index == -1) value = 0;
2461 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2462 >  }
2463 >  else if(variable == "genMatchedMotherId"){
2464 >    int index = getGenMatchedParticleIndex(object);
2465 >    if(index == -1) value = 0;
2466 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2467 >  }
2468 >  else if(variable == "genMatchedMotherIdReverse"){
2469 >    int index = getGenMatchedParticleIndex(object);
2470 >    if(index == -1) value = 24;
2471 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2472 >  }
2473 >  else if(variable == "genMatchedGrandmotherId"){
2474 >    int index = getGenMatchedParticleIndex(object);
2475 >    if(index == -1) value = 0;
2476 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2477 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2478 >      if(motherIndex == -1) value = 0;
2479 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2480 >    }
2481 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2482 >  }
2483 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2484 >    int index = getGenMatchedParticleIndex(object);
2485 >    if(index == -1) value = 24;
2486 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2487 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2488 >      if(motherIndex == -1) value = 24;
2489 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2490 >    }
2491 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2492 >  }
2493 >
2494 >
2495 >
2496 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2497  
2498    value = applyFunction(function, value);
2499  
2500    return value;
2501   }
2502  
2503 + //!genjet valueLookup
2504   double
2505 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2505 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2506  
2507    double value = 0.0;
2508  
# Line 1341 | Line 2522 | OSUAnalysis::valueLookup (const BNgenjet
2522    else if(variable == "charge") value = object->charge;
2523  
2524  
2525 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2525 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2526  
2527    value = applyFunction(function, value);
2528  
2529    return value;
2530   }
2531  
2532 + //!mcparticle valueLookup
2533   double
2534 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2534 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2535  
2536    double value = 0.0;
2537  
# Line 1440 | Line 2622 | OSUAnalysis::valueLookup (const BNmcpart
2622  
2623    //user-defined variables
2624    else if (variable == "d0"){
2625 <    double vx = object->vx - primaryVertex_->x,
2626 <      vy = object->vy - primaryVertex_->y,
2625 >    double vx = object->vx - chosenVertex ()->x,
2626 >      vy = object->vy - chosenVertex ()->y,
2627        px = object->px,
2628        py = object->py,
2629        pt = object->pt;
2630      value = (-vx * py + vy * px) / pt;
2631    }
2632    else if (variable == "dz"){
2633 <    double vx = object->vx - primaryVertex_->x,
2634 <      vy = object->vy - primaryVertex_->y,
2635 <      vz = object->vz - primaryVertex_->z,
2633 >    double vx = object->vx - chosenVertex ()->x,
2634 >      vy = object->vy - chosenVertex ()->y,
2635 >      vz = object->vz - chosenVertex ()->z,
2636        px = object->px,
2637        py = object->py,
2638        pz = object->pz,
2639        pt = object->pt;
2640      value = vz - (vx * px + vy * py)/pt * (pz/pt);
2641    }
2642 +  else if(variable == "v0"){
2643 +    value = sqrt(object->vx*object->vx + object->vy*object->vy);
2644 +  }
2645 +  else if(variable == "deltaV0"){
2646 +    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
2647 +  }
2648 +  else if (variable == "deltaVx"){
2649 +    value = object->vx - chosenVertex ()->x;
2650 +  }
2651 +  else if (variable == "deltaVy"){
2652 +    value = object->vy - chosenVertex ()->y;
2653 +  }
2654 +  else if (variable == "deltaVz"){
2655 +    value = object->vz - chosenVertex ()->z;
2656 +  }
2657  
2658  
2659 <
1463 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2659 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2660  
2661    value = applyFunction(function, value);
2662  
2663    return value;
2664   }
2665  
2666 + //!primaryvertex valueLookup
2667   double
2668 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2668 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2669  
2670    double value = 0.0;
2671  
# Line 1487 | Line 2684 | OSUAnalysis::valueLookup (const BNprimar
2684    else if(variable == "isGood") value = object->isGood;
2685  
2686  
2687 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2687 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2688  
2689    value = applyFunction(function, value);
2690  
2691    return value;
2692   }
2693  
2694 + //!bxlumi valueLookup
2695   double
2696 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2696 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2697  
2698    double value = 0.0;
2699  
# Line 1504 | Line 2702 | OSUAnalysis::valueLookup (const BNbxlumi
2702    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2703  
2704  
2705 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2705 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2706  
2707    value = applyFunction(function, value);
2708  
2709    return value;
2710   }
2711  
2712 + //!photon valueLookup
2713   double
2714 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2714 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2715  
2716    double value = 0.0;
2717  
# Line 1587 | Line 2786 | OSUAnalysis::valueLookup (const BNphoton
2786    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2787  
2788  
2789 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2789 >
2790 >
2791 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2792 >
2793 >  else if(variable == "genMatchedPdgId"){
2794 >    int index = getGenMatchedParticleIndex(object);
2795 >    if(index == -1) value = 0;
2796 >    else value = mcparticles->at(index).id;
2797 >  }
2798 >
2799 >
2800 >
2801 >  else if(variable == "genMatchedId"){
2802 >    int index = getGenMatchedParticleIndex(object);
2803 >    if(index == -1) value = 0;
2804 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2805 >  }
2806 >  else if(variable == "genMatchedMotherId"){
2807 >    int index = getGenMatchedParticleIndex(object);
2808 >    if(index == -1) value = 0;
2809 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2810 >  }
2811 >  else if(variable == "genMatchedMotherIdReverse"){
2812 >    int index = getGenMatchedParticleIndex(object);
2813 >    if(index == -1) value = 24;
2814 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2815 >  }
2816 >  else if(variable == "genMatchedGrandmotherId"){
2817 >    int index = getGenMatchedParticleIndex(object);
2818 >    if(index == -1) value = 0;
2819 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2820 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2821 >      if(motherIndex == -1) value = 0;
2822 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2823 >    }
2824 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2825 >  }
2826 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2827 >    int index = getGenMatchedParticleIndex(object);
2828 >    if(index == -1) value = 24;
2829 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2830 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2831 >      if(motherIndex == -1) value = 24;
2832 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2833 >    }
2834 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2835 >  }
2836 >
2837 >
2838 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2839  
2840    value = applyFunction(function, value);
2841  
2842    return value;
2843   }
2844  
2845 + //!supercluster valueLookup
2846   double
2847 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
2847 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
2848  
2849    double value = 0.0;
2850  
# Line 1609 | Line 2858 | OSUAnalysis::valueLookup (const BNsuperc
2858    else if(variable == "theta") value = object->theta;
2859  
2860  
2861 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2861 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2862  
2863    value = applyFunction(function, value);
2864  
2865    return value;
2866   }
2867  
2868 + //!trigobj valueLookup
2869 + double
2870 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
2871 +
2872 +  double value = 0.0;
2873 +
2874 +  if(variable == "pt") value = object->pt;
2875 +  else if(variable == "eta") value = object->eta;
2876 +  else if(variable == "phi") value = object->phi;
2877 +  else if(variable == "px") value = object->px;
2878 +  else if(variable == "py") value = object->py;
2879 +  else if(variable == "pz") value = object->pz;
2880 +  else if(variable == "et") value = object->et;
2881 +  else if(variable == "energy") value = object->energy;
2882 +  else if(variable == "etTotal") value = object->etTotal;
2883 +  else if(variable == "id") value = object->id;
2884 +  else if(variable == "charge") value = object->charge;
2885 +  else if(variable == "isIsolated") value = object->isIsolated;
2886 +  else if(variable == "isMip") value = object->isMip;
2887 +  else if(variable == "isForward") value = object->isForward;
2888 +  else if(variable == "isRPC") value = object->isRPC;
2889 +  else if(variable == "bx") value = object->bx;
2890 +  else if(variable == "filter") {
2891 +    if ((stringValue = object->filter) == "")
2892 +      stringValue = "none";  // stringValue should only be empty if value is filled
2893 +  }
2894 +
2895 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2896  
2897 +  value = applyFunction(function, value);
2898 +
2899 +  return value;
2900 + }
2901 +
2902 + //!muon-muon pair valueLookup
2903   double
2904 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
2904 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
2905  
2906    double value = 0.0;
2907  
2908 <  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
2908 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2909 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2910 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2911    else if(variable == "invMass"){
2912      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2913      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2914      value = (fourVector1 + fourVector2).M();
2915    }
2916 +  else if(variable == "pt"){
2917 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2918 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2919 +    value = (fourVector1 + fourVector2).Pt();
2920 +  }
2921 +  else if(variable == "threeDAngle")
2922 +    {
2923 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2924 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2925 +      value = (threeVector1.Angle(threeVector2));
2926 +    }
2927 +  else if(variable == "alpha")
2928 +    {
2929 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
2930 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2931 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2932 +      value = (pi-threeVector1.Angle(threeVector2));
2933 +    }
2934    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2935    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2936 <  else if(variable == "d0Sign") value = object1->correctedD0Vertex*object2->correctedD0Vertex/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2936 >  else if(variable == "d0Sign"){
2937 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2938 >    if(d0Sign < 0) value = -0.5;
2939 >    else if (d0Sign > 0) value = 0.5;
2940 >    else value = -999;
2941 >  }
2942 >  else if(variable == "chargeProduct"){
2943 >    value = object1->charge*object2->charge;
2944 >  }
2945 >  else if(variable == "muon1CorrectedD0Vertex"){
2946 >    value = object1->correctedD0Vertex;
2947 >  }
2948 >  else if(variable == "muon2CorrectedD0Vertex"){
2949 >    value = object2->correctedD0Vertex;
2950 >  }
2951 >  else if(variable == "muon1timeAtIpInOut"){
2952 >    value = object1->timeAtIpInOut;
2953 >  }
2954 >  else if(variable == "muon2timeAtIpInOut"){
2955 >    value = object2->timeAtIpInOut;
2956 >  }
2957 >  else if(variable == "muon1correctedD0")
2958 >    {
2959 >      value = object1->correctedD0;
2960 >    }
2961 >  else if(variable == "muon2correctedD0")
2962 >    {
2963 >      value = object2->correctedD0;
2964 >    }
2965  
2966 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2966 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2967  
2968    value = applyFunction(function, value);
2969  
2970    return value;
2971   }
2972  
2973 + //!electron-electron pair valueLookup
2974   double
2975 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
2975 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
2976  
2977    double value = 0.0;
2978  
2979 <  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
2979 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2980 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2981 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2982    else if(variable == "invMass"){
2983      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2984      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2985      value = (fourVector1 + fourVector2).M();
2986    }
2987 +  else if(variable == "pt"){
2988 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2989 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2990 +    value = (fourVector1 + fourVector2).Pt();
2991 +  }
2992 +  else if(variable == "threeDAngle")
2993 +    {
2994 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2995 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2996 +      value = (threeVector1.Angle(threeVector2));
2997 +    }
2998    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2999    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3000 <  else if(variable == "d0Sign") value = object1->correctedD0Vertex*object2->correctedD0Vertex/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3000 >  else if(variable == "d0Sign"){
3001 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3002 >    if(d0Sign < 0) value = -0.5;
3003 >    else if (d0Sign > 0) value = 0.5;
3004 >    else value = -999;
3005 >  }
3006 >  else if(variable == "chargeProduct"){
3007 >    value = object1->charge*object2->charge;
3008 >  }
3009 >  else if(variable == "electron1CorrectedD0Vertex"){
3010 >    value = object1->correctedD0Vertex;
3011 >  }
3012 >  else if(variable == "electron2CorrectedD0Vertex"){
3013 >    value = object2->correctedD0Vertex;
3014 >  }
3015 >  else if(variable == "electron1CorrectedD0"){
3016 >    value = object1->correctedD0;
3017 >  }
3018 >  else if(variable == "electron2CorrectedD0"){
3019 >    value = object2->correctedD0;
3020 >  }
3021  
3022 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3022 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3023  
3024    value = applyFunction(function, value);
3025  
3026    return value;
3027   }
3028 <
3028 > //!electron-muon pair valueLookup
3029   double
3030 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3030 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3031  
3032    double value = 0.0;
3033  
3034 <  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
3034 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3035 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3036 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3037    else if(variable == "invMass"){
3038      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3039      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3040      value = (fourVector1 + fourVector2).M();
3041    }
3042 +  else if(variable == "pt"){
3043 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3044 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3045 +    value = (fourVector1 + fourVector2).Pt();
3046 +  }
3047 +  else if(variable == "threeDAngle")
3048 +    {
3049 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3050 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3051 +      value = (threeVector1.Angle(threeVector2));
3052 +    }
3053    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3054    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3055 <  else if(variable == "d0Sign") value = object1->correctedD0Vertex*object2->correctedD0Vertex/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3055 >  else if(variable == "d0Sign"){
3056 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3057 >    if(d0Sign < 0) value = -0.5;
3058 >    else if (d0Sign > 0) value = 0.5;
3059 >    else value = -999;
3060 >  }
3061 >  else if(variable == "chargeProduct"){
3062 >    value = object1->charge*object2->charge;
3063 >  }
3064 >  else if(variable == "electronCorrectedD0Vertex"){
3065 >    value = object1->correctedD0Vertex;
3066 >  }
3067 >  else if(variable == "muonCorrectedD0Vertex"){
3068 >    value = object2->correctedD0Vertex;
3069 >  }
3070 >  else if(variable == "electronCorrectedD0"){
3071 >    value = object1->correctedD0;
3072 >  }
3073 >  else if(variable == "muonCorrectedD0"){
3074 >    value = object2->correctedD0;
3075 >  }
3076 >  else if(variable == "electronDetIso"){
3077 >    value = (object1->trackIso) / object1->pt;
3078 >  }
3079 >  else if(variable == "muonDetIso"){
3080 >    value = (object2->trackIsoDR03) / object2->pt;
3081 >  }
3082 >  else if(variable == "electronRelPFrhoIso"){
3083 >    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3084 >  }
3085 >  else if(variable == "muonRelPFdBetaIso"){
3086 >    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3087 >  }
3088 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3089 >  value = applyFunction(function, value);
3090 >
3091 >  return value;
3092 > }
3093 >
3094 > //!electron-jet pair valueLookup
3095 > double
3096 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3097 >
3098 >  double value = 0.0;
3099 >
3100 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3101 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3102 >  else if(variable == "jetEta") value = object2->eta;
3103 >  else if(variable == "jetPhi") value = object2->phi;
3104 >  else if(variable == "electronEta") value = object1->eta;
3105 >  else if(variable == "electronPhi") value = object1->phi;
3106 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3107 >  else if(variable == "invMass"){
3108 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3109 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3110 >    value = (fourVector1 + fourVector2).M();
3111 >  }
3112 >  else if(variable == "pt"){
3113 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3114 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3115 >    value = (fourVector1 + fourVector2).Pt();
3116 >  }
3117 >  else if(variable == "threeDAngle")
3118 >    {
3119 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3120 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3121 >      value = (threeVector1.Angle(threeVector2));
3122 >    }
3123 >  else if(variable == "chargeProduct"){
3124 >    value = object1->charge*object2->charge;
3125 >  }
3126 >
3127 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3128 >  value = applyFunction(function, value);
3129 >
3130 >  return value;
3131 > }
3132 >
3133 > //!muon-jet pair valueLookup
3134 > double
3135 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3136 >
3137 >  double value = 0.0;
3138 >
3139 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3140 >  else if(variable == "jetEta") value = object2->eta;
3141 >  else if(variable == "jetPhi") value = object2->phi;
3142 >  else if(variable == "muonEta") value = object1->eta;
3143 >  else if(variable == "muonPhi") value = object1->phi;
3144 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3145 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3146 >  else if(variable == "invMass"){
3147 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3148 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3149 >    value = (fourVector1 + fourVector2).M();
3150 >  }
3151 >  else if(variable == "pt"){
3152 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3153 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3154 >    value = (fourVector1 + fourVector2).Pt();
3155 >  }
3156 >  else if(variable == "threeDAngle")
3157 >    {
3158 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3159 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3160 >      value = (threeVector1.Angle(threeVector2));
3161 >    }
3162 >  else if(variable == "chargeProduct"){
3163 >    value = object1->charge*object2->charge;
3164 >  }
3165 >
3166 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3167 >  value = applyFunction(function, value);
3168 >
3169 >  return value;
3170 > }
3171 >
3172 > //!jet-jet pair valueLookup
3173 > double
3174 > OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3175 >
3176 >  double value = 0.0;
3177 >
3178 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3179 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3180 >  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3181 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3182 >  else if(variable == "invMass"){
3183 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3184 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3185 >    value = (fourVector1 + fourVector2).M();
3186 >  }
3187 >  else if(variable == "pt"){
3188 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3189 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3190 >    value = (fourVector1 + fourVector2).Pt();
3191 >  }
3192 >  else if(variable == "threeDAngle")
3193 >    {
3194 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3195 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3196 >      value = (threeVector1.Angle(threeVector2));
3197 >    }
3198 >  else if(variable == "chargeProduct"){
3199 >    value = object1->charge*object2->charge;
3200 >  }
3201 >
3202 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3203 >  value = applyFunction(function, value);
3204 >
3205 >  return value;
3206 > }
3207 > //!electron-track pair valueLookup
3208 > double
3209 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3210 >  double electronMass = 0.000511;
3211 >  double value = 0.0;
3212 >  TLorentzVector fourVector1(0, 0, 0, 0);
3213 >  TLorentzVector fourVector2(0, 0, 0, 0);
3214 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3215 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3216 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3217 >  else if(variable == "invMass"){
3218 >    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3219 >    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3220  
3221 +    value = (fourVector1 + fourVector2).M();
3222 +  }
3223 +  else if(variable == "chargeProduct"){
3224 +    value = object1->charge*object2->charge;
3225 +  }
3226    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3227 +  value = applyFunction(function, value);
3228 +  return value;
3229 +
3230 + }
3231 +
3232  
3233 + //!muon-track pair valueLookup
3234 + double
3235 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3236 +  double pionMass = 0.140;
3237 +  double muonMass = 0.106;
3238 +  double value = 0.0;
3239 +  TLorentzVector fourVector1(0, 0, 0, 0);
3240 +  TLorentzVector fourVector2(0, 0, 0, 0);
3241 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3242 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3243 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3244 +  else if(variable == "invMass"){
3245 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3246 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3247 +
3248 +    value = (fourVector1 + fourVector2).M();
3249 +  }
3250 +  else if(variable == "chargeProduct"){
3251 +    value = object1->charge*object2->charge;
3252 +  }
3253 +
3254 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3255    value = applyFunction(function, value);
3256 +  return value;
3257 + }
3258  
3259 + //!tau-tau pair valueLookup
3260 + double
3261 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3262 +  double value = 0.0;
3263 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3264 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3265 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3266 +  else if(variable == "invMass"){
3267 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3268 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3269 +    value = (fourVector1 + fourVector2).M();
3270 +  }
3271 +
3272 +  else if(variable == "chargeProduct"){
3273 +    value = object1->charge*object2->charge;
3274 +  }
3275 +
3276 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3277 +  value = applyFunction(function, value);
3278    return value;
3279   }
3280  
3281 + //!muon-tau pair valueLookup
3282 + double
3283 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3284 +  double value = 0.0;
3285 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3286 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3287 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3288 +  else if(variable == "invMass"){
3289 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3290 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3291 +    value = (fourVector1 + fourVector2).M();
3292 +  }
3293 +
3294 +  else if(variable == "chargeProduct"){
3295 +    value = object1->charge*object2->charge;
3296 +  }
3297 +
3298 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3299 +  value = applyFunction(function, value);
3300 +  return value;
3301 + }
3302 +
3303 + //!tau-track pair valueLookup
3304 + double
3305 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3306 +  double value = 0.0;
3307 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3308 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3309 +  else if(variable == "chargeProduct"){
3310 +    value = object1->charge*object2->charge;
3311 +  }
3312 +
3313 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3314 +  value = applyFunction(function, value);
3315 +  return value;
3316 + }
3317 +
3318 +
3319 + //!track-event pair valueLookup
3320 + double
3321 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3322 +
3323 +  double value = 0.0;
3324 +  double pMag = sqrt(object1->pt * object1->pt +
3325 +                     object1->pz * object1->pz);
3326 +
3327 +  if      (variable == "numPV")                      value = object2->numPV;
3328 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3329 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3330 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3331 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3332 +
3333 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3334 +
3335 +  value = applyFunction(function, value);
3336 +
3337 +  return value;
3338 +
3339 + }
3340 +
3341 + //!electron-trigobj pair valueLookup
3342 + double
3343 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3344 +
3345 +  double value = 0.0;
3346 +
3347 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3348 +  else if (variable == "match"){
3349 +    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3350 +      stringValue = object2->filter;
3351 +    else
3352 +      stringValue = "none";
3353 +  }
3354 +
3355 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3356 +
3357 +  value = applyFunction(function, value);
3358 +
3359 +  return value;
3360 +
3361 + }
3362 +
3363 + //!muon-trigobj pair valueLookup
3364 + double
3365 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3366 +
3367 +  double value = 0.0;
3368 +
3369 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3370 +
3371 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3372 +
3373 +  value = applyFunction(function, value);
3374 +
3375 +  return value;
3376 +
3377 + }
3378 +
3379 + //!stop valueLookup
3380 + double
3381 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3382 +
3383 +
3384 +  double value = 0.0;
3385 +
3386 +  if(variable == "ctau") value = object->ctau;
3387 +
3388 +  else if (variable == "d0"){
3389 +    double vx = object->vx - chosenVertex ()->x,
3390 +      vy = object->vy - chosenVertex ()->y,
3391 +      px = object->px,
3392 +      py = object->py,
3393 +      pt = object->pt;
3394 +    value = (-vx * py + vy * px) / pt;
3395 +  }
3396 +
3397 +  else if (variable == "dz"){
3398 +    double vx = object->vx - chosenVertex ()->x,
3399 +      vy = object->vy - chosenVertex ()->y,
3400 +      vz = object->vz - chosenVertex ()->z,
3401 +      px = object->px,
3402 +      py = object->py,
3403 +      pz = object->pz,
3404 +      pt = object->pt;
3405 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3406 +  }
3407 +
3408 +  else if (variable == "minD0"){
3409 +    double minD0=999;
3410 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3411 +      double vx = object->vx - vertex->x,
3412 +        vy = object->vy - vertex->y,
3413 +        px = object->px,
3414 +        py = object->py,
3415 +        pt = object->pt;
3416 +      value = (-vx * py + vy * px) / pt;
3417 +      if(abs(value) < abs(minD0)) minD0 = value;
3418 +    }
3419 +    value = minD0;
3420 +  }
3421 +  else if (variable == "minDz"){
3422 +    double minDz=999;
3423 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3424 +      double vx = object->vx - vertex->x,
3425 +        vy = object->vy - vertex->y,
3426 +        vz = object->vz - vertex->z,
3427 +        px = object->px,
3428 +        py = object->py,
3429 +        pz = object->pz,
3430 +        pt = object->pt;
3431 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3432 +      if(abs(value) < abs(minDz)) minDz = value;
3433 +    }
3434 +    value = minDz;
3435 +  }
3436 +  else if(variable == "distToVertex"){
3437 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3438 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3439 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3440 +  }
3441 +  else if (variable == "minDistToVertex"){
3442 +    double minDistToVertex=999;
3443 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3444 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3445 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3446 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3447 +
3448 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3449 +    }
3450 +    value = minDistToVertex;
3451 +  }
3452 +  else if (variable == "distToVertexDifference"){
3453 +    double minDistToVertex=999;
3454 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3455 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3456 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3457 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3458 +
3459 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3460 +    }
3461 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3462 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3463 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3464 +
3465 +    value = distToChosenVertex - minDistToVertex;
3466 +  }
3467 +
3468 +  else if (variable == "closestVertexRank"){
3469 +    double minDistToVertex=999;
3470 +    int vertex_rank = 0;
3471 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3472 +      vertex_rank++;
3473 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3474 +                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
3475 +                      (object->vz-vertex->z)*(object->vz-vertex->z));
3476 +
3477 +      if(abs(dist) < abs(minDistToVertex)){
3478 +        value = vertex_rank;
3479 +        minDistToVertex = dist;
3480 +      }
3481 +    }
3482 +  }
3483 +
3484 +
3485 +
3486 +
3487 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3488 +
3489 +  value = applyFunction(function, value);
3490 +
3491 +  return value;
3492 +
3493 + }
3494 +
3495 +
3496 +
3497 +
3498 + // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3499 + // Return true iff no other tracks are found in this cone.
3500 + int
3501 + OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
3502 +  for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
3503 +    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
3504 +    double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
3505 +    if(deltaRtrk < 0.5) return 0;
3506 +  }
3507 +  return 1;
3508 +
3509 + }
3510 +
3511 +
3512 + double
3513 + OSUAnalysis::getTrkPtRes (const BNtrack* track1){
3514 +
3515 +  double ptTrue = getTrkPtTrue(track1, mcparticles.product());
3516 +  double PtRes = (track1->pt - ptTrue) / ptTrue;
3517 +
3518 +  return PtRes;
3519 +
3520 + }
3521 +
3522 +
3523 + double
3524 + OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
3525 +  double value = -99;
3526 +  double genDeltaRLowest = 999;
3527 +
3528 +  for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
3529 +    double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
3530 +    if (genDeltaRtemp < genDeltaRLowest) {
3531 +      genDeltaRLowest = genDeltaRtemp;
3532 +      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
3533 +        double ptTrue = genPart->pt;
3534 +        value = ptTrue;
3535 +      }
3536 +    }
3537 +  }
3538 +
3539 +  return value;
3540 +
3541 + }
3542 +
3543 + double
3544 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3545 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3546 +  if (!useTrackCaloRhoCorr_) return -99;
3547 +  // if (!rhokt6CaloJetsHandle_) {
3548 +  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3549 +  //   return -99;
3550 +  // }
3551 +  double radDeltaRCone = 0.5;
3552 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3553 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3554 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3555 +  return caloTotRhoCorrCalo;
3556 +
3557 + }
3558 +
3559 +
3560 +
3561 +
3562 + //creates a map of the dead Ecal channels in the barrel and endcap
3563 + //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
3564 + //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
3565 + void
3566 + OSUAnalysis::WriteDeadEcal (){
3567 +  double etaEcal, phiEcal;
3568 +  ifstream DeadEcalFile(deadEcalFile_);
3569 +  if(!DeadEcalFile) {
3570 +    cout << "Error: DeadEcalFile has not been found." << endl;
3571 +    return;
3572 +  }
3573 +  if(DeadEcalVec.size()!= 0){
3574 +    cout << "Error: DeadEcalVec has a nonzero size" << endl;
3575 +    return;
3576 +  }
3577 +  while(!DeadEcalFile.eof())
3578 +    {
3579 +      DeadEcalFile >> etaEcal >> phiEcal;
3580 +      DeadEcal newChan;
3581 +      newChan.etaEcal = etaEcal;
3582 +      newChan.phiEcal = phiEcal;
3583 +      DeadEcalVec.push_back(newChan);
3584 +    }
3585 +  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
3586 + }
3587 +
3588 + //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
3589 + int
3590 + OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
3591 +  double deltaRLowest = 999;
3592 +  int value = 0;
3593 +  if (DeadEcalVec.size() == 0) WriteDeadEcal();
3594 +  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3595 +    double eta = ecal->etaEcal;
3596 +    double phi = ecal->phiEcal;
3597 +    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
3598 +    if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3599 +  }
3600 +  if (deltaRLowest<0.05) {value = 1;}
3601 +  else {value = 0;}
3602 +  return value;
3603 + }
3604 +
3605 + // Returns the smallest DeltaR between the object and any generated true particle in the event.
3606 + template <class InputObject>
3607 + double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3608 +  double genDeltaRLowest = 999.;
3609 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3610 +    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
3611 +    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
3612 +  }
3613 +  return genDeltaRLowest;
3614 + }
3615  
3616   double
3617   OSUAnalysis::applyFunction(string function, double value){
3618  
3619    if(function == "abs") value = fabs(value);
3620 +  else if(function == "fabs") value = fabs(value);
3621 +  else if(function == "log10") value = log10(value);
3622 +  else if(function == "log") value = log10(value);
3623  
3624 +  else if(function == "") value = value;
3625 +  else{cout << "WARNING: invalid function '" << function << "'\n";}
3626  
3627    return value;
3628  
# Line 1698 | Line 3632 | OSUAnalysis::applyFunction(string functi
3632   template <class InputCollection>
3633   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
3634  
3635 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
3636 +    string obj1, obj2;
3637 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
3638 +    if (inputType==obj1 ||
3639 +        inputType==obj2) {
3640 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
3641 +      // and the inputType is a member of the pair.
3642 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
3643 +      // For example, if currentCut.inputCollection==electron-muon pairs,
3644 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
3645 +      return;
3646 +    }
3647 +  }
3648 +
3649    for (uint object = 0; object != inputCollection->size(); object++){
3650  
3651      bool decision = true;//object passes if this cut doesn't cut on that type of object
# Line 1706 | Line 3654 | void OSUAnalysis::setObjectFlags(cut &cu
3654  
3655        vector<bool> subcutDecisions;
3656        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3657 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3658 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3657 >        string stringValue = "";
3658 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3659 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3660 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3661 >
3662        }
3663        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3664        else{
3665 <        bool tempDecision = true;
3666 <        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
3667 <          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
3668 <            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
3669 <          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
3665 >        bool tempDecision = true;
3666 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
3667 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
3668 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
3669 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
3670              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
3671 <        }
3672 <        decision = tempDecision;
3671 >        }
3672 >        decision = tempDecision;
3673        }
3674      }
3675 +
3676      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3677  
3678      //set flags for objects that pass each cut AND all the previous cuts
# Line 1738 | Line 3690 | void OSUAnalysis::setObjectFlags(cut &cu
3690  
3691   template <class InputCollection1, class InputCollection2>
3692   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
3693 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, string inputType){
3693 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
3694  
3695  
3696    bool sameObjects = false;
3697    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3698  
3699 <  int counter = 0;  
3699 >  // Get the strings for the two objects that make up the pair.
3700 >  string obj1Type, obj2Type;
3701 >  getTwoObjs(inputType, obj1Type, obj2Type);
3702 >  bool isTwoTypesOfObject = true;
3703 >  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
3704 >
3705 >  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
3706 >  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
3707 >  if (currentCut.inputCollection == inputType) {
3708 >    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
3709 >      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3710 >      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3711 >    }
3712 >    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
3713 >      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
3714 >        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3715 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3716 >      }
3717 >    }
3718 >  }
3719 >
3720 >  int counter = 0;
3721 >
3722    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3723      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3724 <      
3724 >
3725        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3726  
3727  
# Line 1755 | Line 3729 | void OSUAnalysis::setObjectFlags(cut &cu
3729  
3730        if(currentCut.inputCollection == inputType){
3731  
3732 <        vector<bool> subcutDecisions;
3733 <        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3734 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3735 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3736 <        }
3732 >        vector<bool> subcutDecisions;
3733 >        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3734 >          string stringValue = "";
3735 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3736 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3737 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3738 >        }
3739  
3740 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3741 <        else{
3742 <          bool tempDecision = true;
3743 <          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
3744 <            if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
3745 <              tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
3746 <            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
3747 <              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
3748 <          }
3749 <          decision = tempDecision;
3750 <        }
3740 >        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3741 >        else{
3742 >          bool tempDecision = subcutDecisions.at(0);
3743 >          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
3744 >            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
3745 >              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
3746 >            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
3747 >              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
3748 >          }
3749 >          decision = tempDecision;
3750 >        }
3751        }
3752 +      // if (decision) isPassObj1.at(object1) = true;
3753 +      // if (decision) isPassObj2.at(object2) = true;
3754        individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3755 <      
3755 >      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3756 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;
3757 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;
3758 >      }
3759 >
3760        //set flags for objects that pass each cut AND all the previous cuts
3761        bool previousCumulativeFlag = true;
3762        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3763 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
3764 <        else{ previousCumulativeFlag = false; break;}
3763 >        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
3764 >        else{ previousCumulativeFlag = false; break;}
3765 >      }
3766 >      //apply flags for the components of the composite object as well
3767 >      bool currentCumulativeFlag = true;
3768 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
3769 >      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
3770 >      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
3771 >      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
3772 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
3773 >      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3774 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);
3775 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);
3776        }
3777 <      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3777 >      counter++;
3778  
3779 <      counter++;      
3779 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
3780 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
3781 >
3782 > }
3783 >
3784 >
3785 > bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
3786 >  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
3787 >  // all cuts up to currentCutIndex
3788 >  bool previousCumulativeFlag = true;
3789 >  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
3790 >    if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
3791 >    else {
3792 >      previousCumulativeFlag = false; break;
3793      }
1788    
3794    }
3795 +  return previousCumulativeFlag;
3796 + }
3797 +
3798 +
3799 +
3800 + template <class InputCollection>
3801 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, vector<bool> flags){
3802 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree  
3803 +
3804 +  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;  
3805 +  for (uint object = 0; object != inputCollection->size(); object++) {  
3806 +
3807 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;  
3808  
3809 +    string inputVariable = parameters.inputVariable;
3810 +    string function = "";
3811 +    string stringValue = "";  
3812 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);  
3813 +    BNTreeBranchVals_.at(parameters.name).push_back(value);  
3814  
3815 +  }
3816   }
3817  
3818  
3819   template <class InputCollection>
3820 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
3820 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3821  
3822    for (uint object = 0; object != inputCollection->size(); object++){
3823  
# Line 1802 | Line 3826 | void OSUAnalysis::fill1DHistogram(TH1* h
3826      string currentString = parameters.inputVariables.at(0);
3827      string inputVariable = "";
3828      string function = "";
3829 <    if(currentString.find("(")==std::string::npos){
3830 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
3829 >    if(currentString.find("(")==string::npos){
3830 >      inputVariable = currentString;// variable to cut on
3831      }
3832      else{
3833 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
3834 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
3835 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
3833 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3834 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3835 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3836 >    }  
3837 >
3838 >    string stringValue = "";  
3839 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);  
3840 >    histo->Fill(value,scaleFactor);  
3841 >
3842 >    if (printEventInfo_) {
3843 >      // Write information about event to screen, for testing purposes.
3844 >      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
3845      }
3846  
1814    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
1815    histo->Fill(value,puScaleFactor);
1816
3847    }
1818
3848   }
3849  
3850   template <class InputCollection1, class InputCollection2>
3851 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
3851 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3852  
3853    bool sameObjects = false;
3854    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3855  
3856 <  int counter = 0;  
3856 >  int pairCounter = -1;
3857    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3858      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3859 <      
3859 >
3860        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3861  
3862 +      pairCounter++;
3863        //only take objects which have passed all cuts and pairs which have passed all cuts
3864        if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3865        if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3866 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(counter)) continue;
3866 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3867  
3868        string currentString = parameters.inputVariables.at(0);
3869        string inputVariable = "";
3870        string function = "";
3871 <      if(currentString.find("(")==std::string::npos){
3872 <        inputVariable = currentString;// variable to cut on                                                                                                          
3871 >      if(currentString.find("(")==string::npos){
3872 >        inputVariable = currentString;// variable to cut on
3873        }
3874        else{
3875 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
3876 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
3877 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
3875 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3876 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3877 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3878        }
1849      
1850      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
1851      histo->Fill(value,puScaleFactor);
3879  
3880 <      counter++;      
3880 >      string stringValue = "";
3881 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3882 >      histo->Fill(value,scaleFactor);
3883 >
3884      }
3885    }
3886  
# Line 1858 | Line 3888 | void OSUAnalysis::fill1DHistogram(TH1* h
3888  
3889  
3890   template <class InputCollection>
3891 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
3891 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3892  
3893    for (uint object = 0; object != inputCollection->size(); object++){
3894  
3895      if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3896  
3897 +    string stringValue = "";
3898      string currentString = parameters.inputVariables.at(0);
3899      string inputVariable = "";
3900      string function = "";
3901 <    if(currentString.find("(")==std::string::npos){
3902 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
3901 >    if(currentString.find("(")==string::npos){
3902 >      inputVariable = currentString;// variable to cut on
3903      }
3904      else{
3905 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
3906 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
3907 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
3905 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3906 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3907 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3908      }
3909 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
3909 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3910  
3911      currentString = parameters.inputVariables.at(1);
3912      inputVariable = "";
3913      function = "";
3914 <    if(currentString.find("(")==std::string::npos){
3915 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
3914 >    if(currentString.find("(")==string::npos){
3915 >      inputVariable = currentString;// variable to cut on
3916      }
3917      else{
3918 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
3919 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
3920 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
3918 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3919 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3920 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3921      }
3922  
3923 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
3923 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3924  
3925 <    histo->Fill(valueX,valueY,puScaleFactor);
3925 >    histo->Fill(valueX,valueY,scaleFactor);
3926  
3927    }
3928  
3929   }
3930  
3931   template <class InputCollection1, class InputCollection2>
3932 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
3932 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3933  
3934    bool sameObjects = false;
3935    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3936  
3937 <  int counter = 0;  
3937 >  int pairCounter = -1;
3938    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3939      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3940 <      
3940 >
3941        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3942  
3943 +      pairCounter++;
3944 +
3945        //only take objects which have passed all cuts and pairs which have passed all cuts
3946        if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3947        if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3948 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(counter)) continue;
3948 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3949  
3950 +      string stringValue = "";
3951        string currentString = parameters.inputVariables.at(0);
3952        string inputVariable = "";
3953        string function = "";
3954 <      if(currentString.find("(")==std::string::npos){
3955 <        inputVariable = currentString;// variable to cut on                                                                                                          
3954 >      if(currentString.find("(")==string::npos){
3955 >        inputVariable = currentString;// variable to cut on
3956        }
3957        else{
3958 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
3959 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
3960 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
3958 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3959 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3960 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3961        }
3962 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3962 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3963  
3964        currentString = parameters.inputVariables.at(1);
3965        inputVariable = "";
3966        function = "";
3967 <      if(currentString.find("(")==std::string::npos){
3968 <        inputVariable = currentString;// variable to cut on                                                                                                          
3967 >      if(currentString.find("(")==string::npos){
3968 >        inputVariable = currentString;// variable to cut on
3969        }
3970        else{
3971 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
3972 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
3973 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
3971 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3972 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3973 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3974        }
3975 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3975 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3976  
3977  
3978 <      histo->Fill(valueX,valueY,puScaleFactor);
3978 >      histo->Fill(valueX,valueY,scaleFactor);
3979  
1946      counter++;      
3980      }
3981    }
3982  
3983   }
3984  
3985  
3986 + template <class InputObject>
3987 + int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
3988  
3989 < DEFINE_FWK_MODULE(OSUAnalysis);
3989 >  int bestMatchIndex = -1;
3990 >  double bestMatchDeltaR = 999;
3991 >
3992 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3993 >
3994 >    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
3995 >    if(currentDeltaR > 0.05) continue;
3996 >    //     cout << setprecision(3) << setw(20)
3997 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
3998 >    //          << setw(20)
3999 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4000 >    //          << setw(20)
4001 >    //          << "\tdeltaR = " << currentDeltaR
4002 >    //          << setprecision(1)
4003 >    //          << setw(20)
4004 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4005 >    //          << setw(20)
4006 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4007 >    //          << setw(20)
4008 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4009 >    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4010 >      bestMatchIndex = mcparticle - mcparticles->begin();
4011 >      bestMatchDeltaR = currentDeltaR;
4012 >    }
4013 >
4014 >  }
4015 >  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4016 >  //   else cout << "no match found..." << endl;
4017 >  return bestMatchIndex;
4018 >
4019 > }
4020 >
4021 >
4022 > int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
4023 >
4024 >  int bestMatchIndex = -1;
4025 >  double bestMatchDeltaR = 999;
4026 >
4027 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4028 >
4029 >    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
4030 >
4031 >    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
4032 >    if(currentDeltaR > 0.05) continue;
4033  
4034 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4035 +      bestMatchIndex = mcparticle - mcparticles->begin();
4036 +      bestMatchDeltaR = currentDeltaR;
4037 +    }
4038 +
4039 +  }
4040 +
4041 +  return bestMatchIndex;
4042 + }
4043 +
4044 +
4045 + // bin      particle type
4046 + // ---      -------------
4047 + //  0        unmatched
4048 + //  1        u
4049 + //  2        d
4050 + //  3        s
4051 + //  4        c
4052 + //  5        b
4053 + //  6        t
4054 + //  7        e
4055 + //  8        mu
4056 + //  9        tau
4057 + // 10        nu
4058 + // 11        g
4059 + // 12        gamma
4060 + // 13        Z
4061 + // 14        W
4062 + // 15        light meson
4063 + // 16        K meson
4064 + // 17        D meson
4065 + // 18        B meson
4066 + // 19        light baryon
4067 + // 20        strange baryon
4068 + // 21        charm baryon
4069 + // 22        bottom baryon
4070 + // 23        QCD string
4071 + // 24        other
4072 +
4073 + int OSUAnalysis::getPdgIdBinValue(int pdgId){
4074 +
4075 +  int binValue = -999;
4076 +  int absPdgId = fabs(pdgId);
4077 +  if(pdgId == -1) binValue = 0;
4078 +  else if(absPdgId <= 6 ) binValue = absPdgId;
4079 +  else if(absPdgId == 11 ) binValue = 7;
4080 +  else if(absPdgId == 13 ) binValue = 8;
4081 +  else if(absPdgId == 15 ) binValue = 9;
4082 +  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
4083 +  else if(absPdgId == 21 ) binValue = 11;
4084 +  else if(absPdgId == 22 ) binValue = 12;
4085 +  else if(absPdgId == 23 ) binValue = 13;
4086 +  else if(absPdgId == 24 ) binValue = 14;
4087 +  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
4088 +  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
4089 +  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
4090 +  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
4091 +  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
4092 +  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4093 +  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4094 +  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4095 +  else if(absPdgId == 92  ) binValue = 23;
4096 +
4097 +  else binValue = 24;
4098 +
4099 +  return binValue;
4100 +
4101 + }
4102 +
4103 + const BNprimaryvertex *
4104 + OSUAnalysis::chosenVertex ()
4105 + {
4106 +  const BNprimaryvertex *chosenVertex = 0;
4107 +  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4108 +    vector<bool> vertexFlags;
4109 +    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4110 +      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4111 +        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4112 +        break;
4113 +      }
4114 +    }
4115 +    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4116 +      if(!vertexFlags.at(vertexIndex)) continue;
4117 +      chosenVertex = & primaryvertexs->at(vertexIndex);
4118 +      break;
4119 +    }
4120 +  }
4121 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4122 +    chosenVertex = & primaryvertexs->at (0);
4123 +
4124 +  return chosenVertex;
4125 + }
4126 +
4127 + const BNmet *
4128 + OSUAnalysis::chosenMET ()
4129 + {
4130 +  const BNmet *chosenMET = 0;
4131 +  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4132 +    vector<bool> metFlags;
4133 +    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4134 +      if (cumulativeFlags.at("mets").at(i).size()){
4135 +        metFlags = cumulativeFlags.at("mets").at(i);
4136 +        break;
4137 +      }
4138 +    }
4139 +    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4140 +      if(!metFlags.at(metIndex)) continue;
4141 +      chosenMET = & mets->at(metIndex);
4142 +      break;
4143 +    }
4144 +  }
4145 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4146 +    chosenMET = & mets->at (0);
4147 +
4148 +  return chosenMET;
4149 + }
4150 +
4151 + const BNelectron *
4152 + OSUAnalysis::chosenElectron ()
4153 + {
4154 +  const BNelectron *chosenElectron = 0;
4155 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4156 +    vector<bool> electronFlags;
4157 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4158 +      if (cumulativeFlags.at("electrons").at(i).size()){
4159 +        electronFlags = cumulativeFlags.at("electrons").at(i);
4160 +        break;
4161 +      }
4162 +    }
4163 +    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4164 +      if(!electronFlags.at(electronIndex)) continue;
4165 +      chosenElectron = & electrons->at(electronIndex);
4166 +      break;
4167 +    }
4168 +  }
4169 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4170 +    chosenElectron = & electrons->at (0);
4171  
4172 +  return chosenElectron;
4173 + }
4174 +
4175 + const BNmuon *
4176 + OSUAnalysis::chosenMuon ()
4177 + {
4178 +  const BNmuon *chosenMuon = 0;
4179 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4180 +    vector<bool> muonFlags;
4181 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4182 +      if (cumulativeFlags.at("muons").at(i).size()){
4183 +        muonFlags = cumulativeFlags.at("muons").at(i);
4184 +        break;
4185 +      }
4186 +    }
4187 +    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4188 +      if(!muonFlags.at(muonIndex)) continue;
4189 +      chosenMuon = & muons->at(muonIndex);
4190 +      break;
4191 +    }
4192 +  }
4193 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4194 +    chosenMuon = & muons->at (0);
4195 +
4196 +  return chosenMuon;
4197 + }
4198 +
4199 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines