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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines