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.71 by biliu, Wed May 29 18:18:28 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 >  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
32 >  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
33 >  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
34 >  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
35 >  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
36 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
37 >  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
38   {
39  
40    TH1::SetDefaultSumw2 ();
41  
42    //create pile-up reweighting object, if necessary
43 <  if(datasetType_ != "data") puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
43 >  if(datasetType_ != "data") {
44 >    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
45 >    if (applyLeptonSF_){
46 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
47 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
48 >    }
49 >  }
50 >  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
51 >    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
52 >
53  
54    // Construct Cutflow Objects. These store the results of cut decisions and
55    // handle filling cut flow histograms.
56    masterCutFlow_ = new CutFlow (fs_);
37  std::vector<TFileDirectory> directories;
57  
58    //always get vertex collection so we can assign the primary vertex in the event
59 <  allNecessaryObjects.push_back("primaryvertexs");
60 <  //always make the plot of number of primary verticex (to check pile-up reweighting)
59 >  objectsToGet.push_back("primaryvertexs");
60 >
61 >  //always make the plot of number of primary vertices (to check pile-up reweighting)
62    objectsToPlot.push_back("primaryvertexs");
63  
64 +  //always get the MC particles to do GEN-matching
65 +  objectsToGet.push_back("mcparticles");
66 +
67    //always get the event collection to do pile-up reweighting
68 <  allNecessaryObjects.push_back("events");
68 >  objectsToGet.push_back("events");
69  
70    //parse the histogram definitions
71    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
72  
73      string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
74      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
75 <    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
75 >    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
76 >    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
77 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
78 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
79 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
80 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
81 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
82 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
83 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
84 >        int spaceIndex = tempInputCollection.find(" ");
85 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
86 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
87 >      }
88 >      else{
89 >        objectsToGet.push_back(tempInputCollection);
90 >      }
91        objectsToPlot.push_back(tempInputCollection);
92 <      allNecessaryObjects.push_back(tempInputCollection);
92 >      objectsToCut.push_back(tempInputCollection);
93      }
94 <    else{//pair of objects, need to add them both to the things to allNecessaryObjects
95 <      int dashIndex = tempInputCollection.find("-");
96 <      int spaceIndex = tempInputCollection.find(" ");
97 <      int secondWordLength = spaceIndex - dashIndex;
98 <      allNecessaryObjects.push_back(tempInputCollection);
99 <      allNecessaryObjects.push_back(tempInputCollection.substr(0,dashIndex)+"s");
100 <      allNecessaryObjects.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
94 >    else{//pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
95 >      string obj1;
96 >      string obj2;
97 >      getTwoObjs(tempInputCollection, obj1, obj2);
98 >      string obj2ToGet = getObjToGet(obj2);
99 >      objectsToCut.push_back(tempInputCollection);
100 >      objectsToCut.push_back(obj1);
101 >      objectsToCut.push_back(obj2);
102        objectsToPlot.push_back(tempInputCollection);
103 <      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
104 <      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
105 <      }
103 >      objectsToPlot.push_back(obj1);
104 >      objectsToPlot.push_back(obj2);
105 >      objectsToGet.push_back(tempInputCollection);
106 >      objectsToGet.push_back(obj1);
107 >      objectsToGet.push_back(obj2ToGet);
108 >
109 >    }
110  
111      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
112 <    
112 >
113      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
114  
115 +      vector<double> defaultValue;
116 +      defaultValue.push_back (-1.0);
117 +
118        histogram tempHistogram;
119        tempHistogram.inputCollection = tempInputCollection;
120        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
121        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
122 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
122 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
123 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
124 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
125        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
126 <      
126 >
127        histograms.push_back(tempHistogram);
128  
129      }
130    }
131 <  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object
131 >  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
132    sort( objectsToPlot.begin(), objectsToPlot.end() );
133    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
134  
135  
136  
137 +  //add histograms with the gen-matched id, mother id, and grandmother id
138 +  for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
139 +
140 +    string currentObject = objectsToPlot.at(currentObjectIndex);
141 +    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
142 +
143 +    histogram tempIdHisto;
144 +    histogram tempMomIdHisto;
145 +    histogram tempGmaIdHisto;
146 +    histogram tempIdVsMomIdHisto;
147 +    histogram tempIdVsGmaIdHisto;
148 +
149 +    tempIdHisto.inputCollection = currentObject;
150 +    tempMomIdHisto.inputCollection = currentObject;
151 +    tempGmaIdHisto.inputCollection = currentObject;
152 +    tempIdVsMomIdHisto.inputCollection = currentObject;
153 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
154 +
155 +    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
156 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
157 +
158 +    currentObject = currentObject.substr(0, currentObject.size()-1);
159 +    tempIdHisto.name = currentObject+"GenMatchId";
160 +    tempMomIdHisto.name = currentObject+"GenMatchMotherId";
161 +    tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
162 +    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
163 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
164 +
165 +    currentObject.at(0) = toupper(currentObject.at(0));
166 +    tempIdHisto.title = currentObject+" Gen-matched Particle";
167 +    tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
168 +    tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
169 +    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
170 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
171 +
172 +
173 +    int maxNum = 25;
174 +    vector<double> binVector;
175 +    binVector.push_back(maxNum);
176 +    binVector.push_back(0);
177 +    binVector.push_back(maxNum);
178 +
179 +    tempIdHisto.bins = binVector;
180 +    tempIdHisto.inputVariables.push_back("genMatchedId");
181 +    tempMomIdHisto.bins = binVector;
182 +    tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
183 +    tempGmaIdHisto.bins = binVector;
184 +    tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
185 +    binVector.push_back(maxNum);
186 +    binVector.push_back(0);
187 +    binVector.push_back(maxNum);
188 +    tempIdVsMomIdHisto.bins = binVector;
189 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
190 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
191 +    tempIdVsGmaIdHisto.bins = binVector;
192 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
193 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
194 +
195 +    histograms.push_back(tempIdHisto);
196 +    histograms.push_back(tempMomIdHisto);
197 +    histograms.push_back(tempGmaIdHisto);
198 +    histograms.push_back(tempIdVsMomIdHisto);
199 +    histograms.push_back(tempIdVsGmaIdHisto);
200 +  }
201 +
202  
203    channel tempChannel;
204    //loop over all channels (event selections)
# Line 99 | Line 212 | OSUAnalysis::OSUAnalysis (const edm::Par
212      //set triggers for this channel
213      vector<string> triggerNames;
214      triggerNames.clear();
215 +    vector<string> triggerToVetoNames;
216 +    triggerToVetoNames.clear();
217      tempChannel.triggers.clear();
218 +    tempChannel.triggersToVeto.clear();
219      if(channels_.at(currentChannel).exists("triggers")){
220        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
221        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
222          tempChannel.triggers.push_back(triggerNames.at(trigger));
223 <      allNecessaryObjects.push_back("triggers");
223 >      objectsToGet.push_back("triggers");
224 >    }
225 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
226 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
227 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
228 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
229 >      objectsToGet.push_back("triggersToVeto");
230      }
109
231  
232  
233  
234      //create cutFlow for this channel
235      cutFlows_.push_back (new CutFlow (fs_, channelName));
236 <
237 <    //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 <
236 >    vector<TFileDirectory> directories; //vector of directories in the output file.
237 >    vector<string> subSubDirNames;//subdirectories in each channel.
238      //get list of cuts for this channel
239      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
240  
241 +
242      //loop over and parse all cuts
243      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
244        cut tempCut;
245        //store input collection for cut
246        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
247 +      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
248 +      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
249 +      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
250 +      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
251 +      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
252 +      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
253 +      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
254 +      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
255        tempCut.inputCollection = tempInputCollection;
256 <      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
257 <        allNecessaryObjects.push_back(tempInputCollection);
256 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
257 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
258 >          int spaceIndex = tempInputCollection.find(" ");
259 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
260 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
261 >        }
262 >        else{
263 >          objectsToGet.push_back(tempInputCollection);
264 >        }
265 >        objectsToCut.push_back(tempInputCollection);
266        }
267 <      else{//pair of objects, need to add them both to the things to allNecessaryObjects
268 <        int dashIndex = tempInputCollection.find("-");
269 <        int spaceIndex = tempInputCollection.find(" ");
270 <        int secondWordLength = spaceIndex - dashIndex;
271 <        allNecessaryObjects.push_back(tempInputCollection);
272 <        allNecessaryObjects.push_back(tempInputCollection.substr(0,dashIndex)+"s");
273 <        allNecessaryObjects.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
267 >      else{//pair of objects, need to add them both to objectsToGet
268 >        string obj1;
269 >        string obj2;
270 >        getTwoObjs(tempInputCollection, obj1, obj2);
271 >        string obj2ToGet = getObjToGet(obj2);
272 >        objectsToCut.push_back(tempInputCollection);
273 >        objectsToCut.push_back(obj1);
274 >        objectsToCut.push_back(obj2);
275 >        objectsToGet.push_back(tempInputCollection);
276 >        objectsToGet.push_back(obj1);
277 >        objectsToGet.push_back(obj2ToGet);
278  
279        }
280  
# Line 197 | Line 282 | OSUAnalysis::OSUAnalysis (const edm::Par
282  
283        //split cut string into parts and store them
284        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
285 <      std::vector<string> cutStringVector = splitString(cutString);
285 >      vector<string> cutStringVector = splitString(cutString);
286        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
287 <        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
288 <        exit(0);
287 >        cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
288 >        exit(0);
289        }
290        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
291        for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
292 <        int indexOffset = 4 * subcutIndex;
293 <        string currentVariableString = cutStringVector.at(indexOffset);
294 <        if(currentVariableString.find("(")==std::string::npos){
295 <          tempCut.functions.push_back("");//no function was specified
296 <          tempCut.variables.push_back(currentVariableString);// variable to cut on
297 <        }
298 <        else{
299 <          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
300 <          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
301 <          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
302 <        }
303 <        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
304 <        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
305 <        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
292 >        int indexOffset = 4 * subcutIndex;
293 >        string currentVariableString = cutStringVector.at(indexOffset);
294 >        if(currentVariableString.find("(")==string::npos){
295 >          tempCut.functions.push_back("");//no function was specified
296 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
297 >        }
298 >        else{
299 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
300 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
301 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
302 >        }
303 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
304 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
305 >        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
306 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
307        }
308  
309        //get number of objects required to pass cut for event to pass
310        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
311 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
311 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
312        if(numberRequiredVector.size()!=2){
313 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
313 >        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
314          exit(0);
315        }
316  
# Line 232 | Line 318 | OSUAnalysis::OSUAnalysis (const edm::Par
318        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
319        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
320  
321 <
321 >      //Set up vectors to store the directories and subDIrectories for each channel.
322 >      string subSubDirName;
323        string tempCutName;
324        if(cuts_.at(currentCut).exists("alias")){
325          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
326 +        subSubDirName = "After " + cuts_.at(currentCut).getParameter<string> ("alias") + " Cut Applied";
327        }
328        else{
329          //construct string for cutflow table
# Line 243 | Line 331 | OSUAnalysis::OSUAnalysis (const edm::Par
331          string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
332          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
333          tempCutName = cutName;
334 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
335        }
247      tempCut.name = tempCutName;
336  
337 +      subSubDirNames.push_back(subSubDirName);
338 +      tempCut.name = tempCutName;
339  
340        tempChannel.cuts.push_back(tempCut);
341  
342  
253
343      }//end loop over cuts
344  
345 +    vector<map<string, TH1D*>> oneDHistsTmp;
346 +    vector<map<string, TH2D*>> twoDHistsTmp;
347 +    //book a directory in the output file with the name of the channel
348 +    TFileDirectory subDir = fs_->mkdir( channelName );
349 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
350 +    if(GetPlotsAfterEachCut_){
351 +       for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
352 +            TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
353 +            directories.push_back(subSubDir);
354 +            map<string, TH1D*> oneDhistoMap;
355 +            oneDHistsTmp.push_back(oneDhistoMap);
356 +            map<string, TH2D*> twoDhistoMap;
357 +            twoDHistsTmp.push_back(twoDhistoMap);
358 +      }
359 +      oneDHists_.push_back(oneDHistsTmp);
360 +      twoDHists_.push_back(twoDHistsTmp);
361 +    }
362 +   //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
363 +   else{
364 +      map<string, TH1D*> oneDhistoMap;
365 +      oneDHistsTmp.push_back(oneDhistoMap);
366 +      map<string, TH2D*> twoDhistoMap;
367 +      twoDHistsTmp.push_back(twoDhistoMap);
368 +      oneDHists_.push_back(oneDHistsTmp);
369 +      twoDHists_.push_back(twoDHistsTmp);
370 +      directories.push_back(subDir);
371 +   }
372 +    //book all histograms included in the configuration
373 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
374 +    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
375 +      histogram currentHistogram = histograms.at(currentHistogramIndex);
376 +      int numBinsElements = currentHistogram.bins.size();
377 +      int numInputVariables = currentHistogram.inputVariables.size();
378 +      int numBinEdgesX = currentHistogram.variableBinsX.size();
379 +      int numBinEdgesY = currentHistogram.variableBinsY.size();
380 +
381 +      if(numBinsElements == 1){
382 +        if(numBinEdgesX > 1){
383 +          if(numBinEdgesY > 1)
384 +            numBinsElements = 6;
385 +          else
386 +            numBinsElements = 3;
387 +        }
388 +      }
389 +      if(numBinsElements != 3 && numBinsElements !=6){
390 +        cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
391 +        exit(0);
392 +      }
393 +      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
394 +        cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
395 +        exit(0);
396 +      }
397 +      else if(numBinsElements == 3){
398 +        if (currentHistogram.bins.size () == 3)
399 +          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));
400 +        else
401 +          {
402 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
403 +          }
404 +      }
405 +      else if(numBinsElements == 6){
406 +        if (currentHistogram.bins.size () == 6)
407 +          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));
408 +        else
409 +          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 ());
410 +      }
411 +
412 +
413 +      if(currentHistogram.name.find("GenMatch")==string::npos) continue;
414 +
415 +      // bin      particle type
416 +      // ---      -------------
417 +      //  0        unmatched
418 +      //  1        u
419 +      //  2        d
420 +      //  3        s
421 +      //  4        c
422 +      //  5        b
423 +      //  6        t
424 +      //  7        e
425 +      //  8        mu
426 +      //  9        tau
427 +      // 10        nu
428 +      // 11        g
429 +      // 12        gamma
430 +      // 13        Z
431 +      // 14        W
432 +      // 15        light meson
433 +      // 16        K meson
434 +      // 17        D meson
435 +      // 18        B meson
436 +      // 19        light baryon
437 +      // 20        strange baryon
438 +      // 21        charm baryon
439 +      // 22        bottom baryon
440 +      // 23        QCD string
441 +      // 24        other
442 +
443 +      vector<TString> labelArray;
444 +      labelArray.push_back("unmatched");
445 +      labelArray.push_back("u");
446 +      labelArray.push_back("d");
447 +      labelArray.push_back("s");
448 +      labelArray.push_back("c");
449 +      labelArray.push_back("b");
450 +      labelArray.push_back("t");
451 +      labelArray.push_back("e");
452 +      labelArray.push_back("#mu");
453 +      labelArray.push_back("#tau");
454 +      labelArray.push_back("#nu");
455 +      labelArray.push_back("g");
456 +      labelArray.push_back("#gamma");
457 +      labelArray.push_back("Z");
458 +      labelArray.push_back("W");
459 +      labelArray.push_back("light meson");
460 +      labelArray.push_back("K meson");
461 +      labelArray.push_back("D meson");
462 +      labelArray.push_back("B meson");
463 +      labelArray.push_back("light baryon");
464 +      labelArray.push_back("strange baryon");
465 +      labelArray.push_back("charm baryon");
466 +      labelArray.push_back("bottom baryon");
467 +      labelArray.push_back("QCD string");
468 +      labelArray.push_back("other");
469 +
470 +      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
471 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
472 +          oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
473 +        }
474 +        else {
475 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
476 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
477 +        }
478 +      }
479 +      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
480 +        twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
481 +        twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
482 +      }
483 +
484 +    }
485 +
486 +    // Book a histogram for the number of each object type to be plotted.
487 +    // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
488 +    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
489 +      string currentObject = objectsToPlot.at(currentObjectIndex);
490 +      int maxNum = 10;
491 +      if(currentObject == "mcparticles") maxNum = 50;
492 +      else if(currentObject == "primaryvertexs") maxNum = 50;
493 +
494 +      if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
495 +      else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
496 +      else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
497 +      else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
498 +      else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
499 +      else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
500 +      else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
501 +      else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
502 +      else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
503 +      else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
504 +      else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
505 +      else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
506 +      else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
507 +      else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
508 +      else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
509 +      else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
510 +      else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
511 +      else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
512 +      else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
513 +
514 +      currentObject.at(0) = toupper(currentObject.at(0));
515 +      string histoName = "num" + currentObject;
516 +
517 +      if(histoName == "numPrimaryvertexs"){
518 +        string newHistoName = histoName + "BeforePileupCorrection";
519 +        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);
520 +        newHistoName = histoName + "AfterPileupCorrection";
521 +        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);
522 +      }
523 +      else
524 +        oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
525 +    }
526 +   }//end of loop over directories
527      channels.push_back(tempChannel);
528      tempChannel.cuts.clear();
258
529    }//end loop over channels
530  
531  
532 <  //make unique vector of objects we need to cut on (so we make sure to get them from the event)
533 <  sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
534 <  allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
532 >  //make unique vector of objects we need to get from the event
533 >  sort( objectsToGet.begin(), objectsToGet.end() );
534 >  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
535 >  //make unique vector of objects we need to cut on
536 >  sort( objectsToCut.begin(), objectsToCut.end() );
537 >  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
538  
539  
540   }
# Line 279 | Line 552 | void
552   OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
553   {
554  
282
555    // Retrieve necessary collections from the event.
556 <  edm::Handle<BNtriggerCollection> triggers;
557 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
556 >
557 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
558      event.getByLabel (triggers_, triggers);
559  
560 <  edm::Handle<BNjetCollection> jets;
561 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())
560 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
561 >    event.getByLabel (trigobjs_, trigobjs);
562 >
563 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
564      event.getByLabel (jets_, jets);
565  
566 <  edm::Handle<BNmuonCollection> muons;
293 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())
566 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
567      event.getByLabel (muons_, muons);
568  
569 <  edm::Handle<BNelectronCollection> electrons;
297 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())
569 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
570      event.getByLabel (electrons_, electrons);
571  
572 <  edm::Handle<BNeventCollection> events;
301 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())
572 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
573      event.getByLabel (events_, events);
574  
575 <  edm::Handle<BNtauCollection> taus;
305 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())
575 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
576      event.getByLabel (taus_, taus);
577  
578 <  edm::Handle<BNmetCollection> mets;
309 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())
578 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
579      event.getByLabel (mets_, mets);
580  
581 <  edm::Handle<BNtrackCollection> tracks;
313 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())
581 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
582      event.getByLabel (tracks_, tracks);
583  
584 <  edm::Handle<BNgenjetCollection> genjets;
317 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())
584 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
585      event.getByLabel (genjets_, genjets);
586  
587 <  edm::Handle<BNmcparticleCollection> mcparticles;
321 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())
587 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
588      event.getByLabel (mcparticles_, mcparticles);
589  
590 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
325 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())
590 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
591      event.getByLabel (primaryvertexs_, primaryvertexs);
592  
593 <  edm::Handle<BNbxlumiCollection> bxlumis;
329 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())
593 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
594      event.getByLabel (bxlumis_, bxlumis);
595  
596 <  edm::Handle<BNphotonCollection> photons;
333 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())
596 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
597      event.getByLabel (photons_, photons);
598  
599 <  edm::Handle<BNsuperclusterCollection> superclusters;
337 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())
599 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
600      event.getByLabel (superclusters_, superclusters);
601  
602 +  if (datasetType_ == "signalMC"){
603 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
604 +      event.getByLabel (stops_, stops);
605 +  }
606 +
607 +  if (useTrackCaloRhoCorr_) {
608 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
609 +    // This rho collection is not available in all BEANs.
610 +    // For description of rho values for different jet reconstruction algorithms, see
611 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
612 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
613 +  }
614 +
615 +  double masterScaleFactor = 1.0;
616  
617    //get pile-up event weight
618 <  double puScaleFactor = 0;
619 <  if(datasetType_ != "data")
620 <    puScaleFactor = puWeight_->at (events->at (0).numTruePV);
621 <  else
346 <    puScaleFactor = 1.00;
618 >  if (doPileupReweighting_ && datasetType_ != "data") {
619 >    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  This will give an incorrect pile-up weight." << endl;  
620 >    masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);  
621 >  }
622  
623 +  stopCTauScaleFactor_ = 1.0;
624 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
625 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
626 +  masterScaleFactor *= stopCTauScaleFactor_;
627  
628    //loop over all channels
629  
# Line 352 | Line 631 | OSUAnalysis::analyze (const edm::Event &
631      channel currentChannel = channels.at(currentChannelIndex);
632  
633      flagMap individualFlags;
355    flagMap cumulativeFlags;
634      counterMap passingCounter;
635 +    cumulativeFlags.clear ();
636  
637      bool triggerDecision = true;
638      if(currentChannel.triggers.size() != 0){  //triggers specified
639 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
639 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
640        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
641      }
642  
643      //loop over all cuts
644      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
645        cut currentCut = currentChannel.cuts.at(currentCutIndex);
646 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
647 +        string currentObject = objectsToCut.at(currentObjectIndex);
648  
649 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
369 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
370 <
649 >        //initialize maps to get ready to set cuts
650          individualFlags[currentObject].push_back (vector<bool> ());
651          cumulativeFlags[currentObject].push_back (vector<bool> ());
652  
653 +      }
654 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
655 +        string currentObject = objectsToCut.at(currentObjectIndex);
656 +
657 +        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
658 +
659  
660 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
661 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
660 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
661 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
662 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
663 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
664 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
665          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
666          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
667          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 385 | Line 673 | OSUAnalysis::analyze (const edm::Event &
673          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
674          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
675          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
676 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
677  
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");
678  
393      }
679  
680 +        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
681 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
682 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
683 +                                                                   "muon-muon pairs");
684 +
685 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
686 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
687 +                                                                   cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
688 +                                                                   "muon-secondary muon pairs");
689 +
690 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
691 +                                                                   cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
692 +                                                                   cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
693 +                                                                   "electron-secondary electron pairs");
694 +
695 +        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
696 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
697 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
698 +                                                                           "electron-electron pairs");
699 +        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
700 +                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
701 +                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
702 +                                                                       "electron-muon pairs");
703 +        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
704 +                                                                           cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
705 +                                                                           cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
706 +                                                                           "jet-jet pairs");
707 +        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
708 +                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
709 +                                                                       cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
710 +                                                                       "electron-jet pairs");
711 +        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
712 +                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
713 +                                                                       cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
714 +                                                                       "muon-jet pairs");
715 +        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
716 +                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
717 +                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
718 +                                                                     "track-event pairs");
719 +        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
720 +                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
721 +                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
722 +                                                                        "electron-track pairs");
723 +        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
724 +                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
725 +                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
726 +                                                                    "muon-track pairs");
727 +        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
728 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
729 +                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
730 +                                                                  "muon-tau pairs");
731 +        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
732 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
733 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
734 +                                                                 "tau-tau pairs");
735 +        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
736 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
737 +                                                                 cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
738 +                                                                 "tau-track pairs");
739 +        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
740 +                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
741 +                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
742 +                                                                          "electron-trigobj pairs");
743 +        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
744 +                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
745 +                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
746 +                                                                      "muon-trigobj pairs");
747  
748 <
749 <    }//end loop over all cuts
748 >        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
749 >      }
750  
751  
752  
753 +    }//end loop over all cuts
754      //use cumulative flags to apply cuts at event level
755  
756      bool eventPassedAllCuts = true;
757 <
757 >    //a vector to store cumulative cut descisions after each cut.
758 >    vector<bool> eventPassedPreviousCuts;
759      //apply trigger (true if none were specified)
760      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
761  
# Line 413 | Line 767 | OSUAnalysis::analyze (const edm::Event &
767        int numberPassing = 0;
768  
769        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
770 <          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
770 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
771        }
418
772        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
773        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
421
774        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
775 <
775 >      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
776      }
777 +    double scaleFactor = masterScaleFactor;
778  
779 <    cutFlows_.at(currentChannelIndex)->fillCutFlow(puScaleFactor);
780 <
781 <
782 <
783 <    if(!eventPassedAllCuts)continue;
784 <
785 <
786 <
787 <
788 <    //set position of primary vertex in event, in order to calculate quantities relative to it
789 <    primaryVertex_ = 0;
790 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back();
791 <    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
792 <      if(!vertexFlags.at(vertexIndex)) continue;
793 <      primaryVertex_ = new BNprimaryvertex (primaryvertexs->at (vertexIndex));
794 <      break;
779 >    muonScaleFactor_ = electronScaleFactor_ = 1.0;
780 >    if(applyLeptonSF_ && datasetType_ != "data"){
781 >      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
782 >        vector<bool> muonFlags;
783 >        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
784 >          if (cumulativeFlags.at("muons").at(i).size()){
785 >            muonFlags = cumulativeFlags.at("muons").at(i);
786 >            break;
787 >          }
788 >        }
789 >        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
790 >          if(!muonFlags.at(muonIndex)) continue;
791 >          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
792 >        }
793 >      }
794 >      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
795 >        vector<bool> electronFlags;
796 >        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
797 >          if (cumulativeFlags.at("electrons").at(i).size()){
798 >            electronFlags = cumulativeFlags.at("electrons").at(i);
799 >            break;
800 >          }
801 >        }
802 >        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
803 >          if(!electronFlags.at(electronIndex)) continue;
804 >          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
805 >        }
806 >      }
807      }
808 +    scaleFactor *= muonScaleFactor_;
809 +    scaleFactor *= electronScaleFactor_;
810  
811 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
812 +    if(!(GetPlotsAfterEachCut_ || eventPassedAllCuts)) continue;
813  
814 <
814 >    if (printEventInfo_) {
815 >      // Write information about event to screen, for testing purposes.
816 >      cout << "Event passed all cuts in channel " <<  currentChannel.name
817 >           << ": run="  << events->at(0).run
818 >           << "  lumi=" << events->at(0).lumi
819 >           << "  event=" << events->at(0).evt
820 >           << endl;
821 >    }
822      //filling histograms
823 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
824 <      histogram currentHistogram = histograms.at(histogramIndex);
823 >    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
824 >        uint currentDir;
825 >        if(!GetPlotsAfterEachCut_){ currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size();}//if GetPlotsAfterEachCut_ is true, set currentDir point to the lat cut.
826 >        else{
827 >          currentDir = currentCut;
828 >        }
829 >        if(eventPassedPreviousCuts.at(currentDir)){
830 >        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
831 >          histogram currentHistogram = histograms.at(histogramIndex);
832  
833        if(currentHistogram.inputVariables.size() == 1){
834 <        TH1D* histo;
835 <        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
836 <        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
837 <        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
838 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),\
839 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(),\
840 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
841 <        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
842 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
843 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
844 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
845 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
846 <                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
847 <                                                                                              cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
848 <        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
849 <        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
850 <        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
851 <        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
852 <        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
853 <        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
854 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
855 <        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
856 <        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
857 <        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
834 >        TH1D* histo;
835 >        histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
836 >        if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
837 >        else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
838 >        else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
839 >        else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
840 >        else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
841 >        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
842 >                                                                                       cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
843 >                                                                                       cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
844 >        else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
845 >                                                                                       cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
846 >                                                                                       cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
847 >        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
848 >        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
849 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
850 >                                                                                               cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
851 >        else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
852 >                                                                                               cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
853 >                                                                                               cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
854 >        else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
855 >                                                                                       cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
856 >                                                                                       cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
857 >        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
858 >                                                                                           cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
859 >                                                                                           cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
860 >        else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
861 >                                                                                           cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
862 >                                                                                           cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
863 >        else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
864 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
865 >                                                                                           cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
866 >        else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
867 >                                                                                            cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
868 >                                                                                            cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
869 >        else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
870 >                                                                                        cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
871 >                                                                                        cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
872 >        else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
873 >                                                                                      cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
874 >                                                                                      cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
875 >        else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
876 >                                                                                     cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
877 >                                                                                     cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
878 >        else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
879 >                                                                                     cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
880 >                                                                                     cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
881 >        else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
882 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
883 >                                                                                              cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
884 >        else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
885 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
886 >                                                                                          cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
887 >
888 >        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
889 >        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
890 >        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
891 >        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
892 >        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
893 >        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
894 >        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
895 >        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
896 >        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
897 >        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
898 >        else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
899 >        else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
900        }
901        else if(currentHistogram.inputVariables.size() == 2){
902 <        TH2D* histo;
903 <        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
904 <        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
905 <        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
906 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
907 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
908 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
909 <        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
910 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
911 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
912 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
913 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
914 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
915 <                                                                                               cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
916 <        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
917 <        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
918 <        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
919 <        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
920 <        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
921 <        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
922 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
923 <        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
924 <        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
925 <        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
926 <      }
902 >        TH2D* histo;
903 >        histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
904 >        if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
905 >        else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
906 >        else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
907 >        else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
908 >        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
909 >                                                                                       cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
910 >                                                                                       cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
911 >        else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
912 >                                                                                       cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
913 >                                                                                       cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
914 >        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
915 >        else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
916 >        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
917 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
918 >                                                                                               cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
919 >        else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
920 >                                                                                               cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
921 >                                                                                               cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
922 >        else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
923 >                                                                                       cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
924 >                                                                                       cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
925 >        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
926 >                                                                                           cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
927 >                                                                                           cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
928 >        else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
929 >                                                                                           cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
930 >                                                                                           cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
931 >        else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
932 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
933 >                                                                                           cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
934 >        else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
935 >                                                                                            cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
936 >                                                                                            cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
937 >        else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
938 >                                                                                        cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
939 >                                                                                        cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
940 >        else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
941 >                                                                                      cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
942 >                                                                                      cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
943 >        else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
944 >                                                                                     cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
945 >                                                                                     cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
946 >        else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
947 >                                                                                     cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
948 >                                                                                     cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
949 >        else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
950 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
951 >                                                                                              cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
952 >        else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
953 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
954 >                                                                                          cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
955 >        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
956 >        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
957 >        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
958 >        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
959 >        else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
960 >                                                                                         cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
961 >                                                                                         cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
962 >        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
963 >        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
964 >        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
965 >        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
966 >        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
967 >        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
968 >        else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
969 >        else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
970 >      }
971      }
972  
973  
974 +
975      //fills histograms with the sizes of collections
976      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
977 +
978        string currentObject = objectsToPlot.at(currentObjectIndex);
979 +      string objectToPlot = "";
980  
981 <      if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
982 <      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
983 <      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
984 <      string tempCurrentObject = currentObject;
981 >      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
982 >      if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
983 >      else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
984 >      else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
985 >      else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
986 >      else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
987 >      else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
988 >      else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
989 >      else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
990 >      else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
991 >      else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
992 >      else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
993 >      else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
994 >      else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
995 >      else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
996 >      else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
997 >      else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
998 >      else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
999 >      else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1000 >      else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1001 >      else objectToPlot = currentObject;
1002 >
1003 >      string tempCurrentObject = objectToPlot;
1004        tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1005        string histoName = "num" + tempCurrentObject;
1006  
1007 +      //set position of primary vertex in event, in order to calculate quantities relative to it
1008 +      if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1009 +        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1010 +        int numToPlot = 0;
1011 +        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1012 +          if(lastCutFlags.at(currentFlag)) numToPlot++;
1013 +        }
1014 +        if(objectToPlot == "primaryvertexs"){
1015 +          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1016 +          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1017 +        }
1018 +        else {
1019 +          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1020 +        }
1021 +      }
1022 +      else if(objectToPlot == "jets")           oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(jets->size(),scaleFactor);
1023 +      else if(objectToPlot == "secondaryJets")  oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(jets->size(),scaleFactor);
1024 +      else if(objectToPlot == "muons")          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size(),scaleFactor);
1025 +      else if(objectToPlot == "secondaryMuons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size(),scaleFactor);
1026 +      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
1027 +      else if(objectToPlot == "muonSecondaryMuonPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
1028 +      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size(),scaleFactor);
1029 +      else if(objectToPlot == "secondaryElectrons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size(),scaleFactor);
1030 +      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
1031 +      else if(objectToPlot == "electronSecondaryElectronPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
1032 +      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
1033 +      else if(objectToPlot == "electronJetPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*jets->size(),scaleFactor);
1034 +      else if(objectToPlot == "muonJetPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*jets->size(),scaleFactor);
1035 +      else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
1036 +      else if(objectToPlot == "electronTrigobjPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*trigobjs->size(),scaleFactor);
1037 +      else if(objectToPlot == "muonTrigobjPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*trigobjs->size(),scaleFactor);
1038 +      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(events->size(),scaleFactor);
1039 +      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(taus->size(),scaleFactor);
1040 +      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(mets->size(),scaleFactor);
1041 +      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(tracks->size(),scaleFactor);
1042 +      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(genjets->size(),scaleFactor);
1043 +      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(mcparticles->size(),scaleFactor);
1044 +      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(bxlumis->size(),scaleFactor);
1045 +      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(photons->size(),scaleFactor);
1046 +      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(superclusters->size(),scaleFactor);
1047 +      else if(objectToPlot == "trigobjs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(trigobjs->size(),scaleFactor);
1048 +      else if(objectToPlot == "primaryvertexs"){
1049 +        oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1050 +        oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1051 +      }
1052 +      if(objectToPlot == "stops" && datasetType_ == "signalMC") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(stops->size(),scaleFactor);
1053  
1054 <      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);
536 <
1054 >     } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1055      }
1056 +  }
1057    } //end loop over channel
1058  
1059 <  masterCutFlow_->fillCutFlow(puScaleFactor);
1059 >  masterCutFlow_->fillCutFlow(masterScaleFactor);
1060  
1061 + } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1062  
1063  
544 }
545
1064  
1065   bool
1066   OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
# Line 555 | Line 1073 | OSUAnalysis::evaluateComparison (double
1073    else if(comparison == "==") return testValue == cutValue;
1074    else if(comparison == "=") return testValue == cutValue;
1075    else if(comparison == "!=") return testValue != cutValue;
1076 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1076 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1077  
1078   }
1079  
1080   bool
1081 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1081 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1082  
565  bool triggerDecision = false;
1083  
1084 +  if(comparison == ">")       return testValue >  cutValue;
1085 +  else if(comparison == ">=") return testValue >= cutValue;
1086 +  else if(comparison == "<")  return testValue <  cutValue;
1087 +  else if(comparison == "<=") return testValue <= cutValue;
1088 +  else if(comparison == "==") return testValue == cutValue;
1089 +  else if(comparison == "=") return testValue == cutValue;
1090 +  else if(comparison == "!=") return testValue != cutValue;
1091 +  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1092 +
1093 + }
1094 +
1095 + bool
1096 + OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1097 +
1098 +  bool triggerDecision = false;
1099    for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1100      {
1101        if(trigger->pass != 1) continue;
1102        for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1103          {
1104 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1104 >          if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos){
1105              triggerDecision = true;
1106 <          }
1106 >               }
1107 >        }
1108 >    }  
1109 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1110 >    {
1111 >      if(trigger->pass != 1) continue;
1112 >      for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++)
1113 >        {
1114 >          if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos){
1115 >            triggerDecision = false;
1116 >               }
1117          }
1118      }
1119    return triggerDecision;
578
1120   }
1121 <
581 < std::vector<std::string>
1121 > vector<string>
1122   OSUAnalysis::splitString (string inputString){
1123  
1124 <  std::stringstream stringStream(inputString);
1125 <  std::istream_iterator<std::string> begin(stringStream);
1126 <  std::istream_iterator<std::string> end;
1127 <  std::vector<std::string> stringVector(begin, end);
1124 >  stringstream stringStream(inputString);
1125 >  istream_iterator<string> begin(stringStream);
1126 >  istream_iterator<string> end;
1127 >  vector<string> stringVector(begin, end);
1128    return stringVector;
1129  
1130   }
1131  
1132 +
1133 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1134 +  // Set two object strings from the tempInputCollection string,
1135 +  // For example, if tempInputCollection is "electron-muon pairs",
1136 +  // then obj1 = "electrons" and obj2 = "muons".
1137 +  // Note that the objects have an "s" appended.
1138 +
1139 +  int dashIndex = tempInputCollection.find("-");
1140 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1141 +  int secondWordLength = spaceIndex - dashIndex;
1142 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1143 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1144 +
1145 + }
1146 +
1147 +
1148 + string OSUAnalysis::getObjToGet(string obj) {
1149 +  // Return the string corresponding to the object to get for the given obj string.
1150 +  // Right now this only handles the case in which obj contains "secondary",
1151 +  // e.g, "secondary muons".
1152 +  // Note that "s" is NOT appended.
1153 +
1154 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1155 +  int firstSpaceIndex = obj.find_first_of(" ");
1156 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1157 +
1158 + }
1159 +
1160 +
1161 + //!jet valueLookup
1162   double
1163 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1163 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1164  
1165    double value = 0.0;
1166    if(variable == "energy") value = object->energy;
# Line 710 | Line 1280 | OSUAnalysis::valueLookup (const BNjet* o
1280    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1281  
1282  
1283 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1283 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1284  
1285    value = applyFunction(function, value);
1286  
# Line 718 | Line 1288 | OSUAnalysis::valueLookup (const BNjet* o
1288   }
1289  
1290  
1291 <
1291 > //!muon valueLookup
1292   double
1293 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1293 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1294  
1295    double value = 0.0;
1296    if(variable == "energy") value = object->energy;
# Line 736 | Line 1306 | OSUAnalysis::valueLookup (const BNmuon*
1306    else if(variable == "ecalIso") value = object->ecalIso;
1307    else if(variable == "hcalIso") value = object->hcalIso;
1308    else if(variable == "caloIso") value = object->caloIso;
1309 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
1309 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
1310    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
1311    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
1312    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 875 | Line 1445 | OSUAnalysis::valueLookup (const BNmuon*
1445    else if(variable == "time_ndof") value = object->time_ndof;
1446  
1447    //user-defined variables
1448 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1449 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1450 <  else if(variable == "detIso") value = (object->trackIso) / object->pt;
1451 <  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1448 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1449 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1450 >  else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1451 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1452    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1453 +  else if(variable == "metMT") {
1454 +    if (const BNmet *met = chosenMET ())
1455 +      {
1456 +        double dPhi = deltaPhi (object->phi, met->phi);
1457 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1458 +      }
1459 +    else
1460 +      value = -999;
1461 +  }
1462 +
1463 +
1464 +
1465 +  else if(variable == "correctedD0VertexInEBPlus"){
1466 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1467 +    else value = -999;
1468 +  }
1469 +  else if(variable == "correctedD0VertexOutEBPlus"){
1470 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1471 +    else value = -999;
1472 +  }
1473 +  else if(variable == "correctedD0VertexEEPlus"){
1474 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1475 +    else value = -999;
1476 +  }
1477 +
1478 +  else if(variable == "correctedD0BeamspotInEBPlus"){
1479 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1480 +    else value = -999;
1481 +  }
1482 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
1483 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1484 +    else value = -999;
1485 +  }
1486 +  else if(variable == "correctedD0BeamspotEEPlus"){
1487 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1488 +    else value = -999;
1489 +  }
1490 +
1491 +  else if(variable == "correctedD0VertexInEBMinus"){
1492 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1493 +    else value = -999;
1494 +  }
1495 +  else if(variable == "correctedD0VertexOutEBMinus"){
1496 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1497 +    else value = -999;
1498 +  }
1499 +  else if(variable == "correctedD0VertexEEMinus"){
1500 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1501 +    else value = -999;
1502 +  }
1503 +
1504 +  else if(variable == "correctedD0BeamspotInEBMinus"){
1505 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1506 +    else value = -999;
1507 +  }
1508 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
1509 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1510 +    else value = -999;
1511 +  }
1512 +  else if(variable == "correctedD0BeamspotEEMinus"){
1513 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1514 +    else value = -999;
1515 +  }
1516 +
1517 +
1518 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1519 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1520 +    else value = -999;
1521 +  }
1522 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1523 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1524 +    else value = -999;
1525 +  }
1526 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
1527 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1528 +    else value = -999;
1529 +  }
1530 +
1531 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1532 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1533 +    else value = -999;
1534 +  }
1535 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1536 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1537 +    else value = -999;
1538 +  }
1539 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1540 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1541 +    else value = -999;
1542 +  }
1543 +
1544 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1545 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1546 +    else value = -999;
1547 +  }
1548 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1549 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1550 +    else value = -999;
1551 +  }
1552 +  else if(variable == "correctedD0VertexEENegativeCharge"){
1553 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1554 +    else value = -999;
1555 +  }
1556 +
1557 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1558 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1559 +    else value = -999;
1560 +  }
1561 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1562 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1563 +    else value = -999;
1564 +  }
1565 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1566 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1567 +    else value = -999;
1568 +  }
1569 +
1570 +
1571    else if(variable == "tightID") {
1572 <    value = object->isGlobalMuon > 0            \
1573 <      && object->isPFMuon > 0                   \
1574 <      && object->normalizedChi2 < 10            \
1575 <      && object->numberOfValidMuonHits > 0      \
1576 <      && object->numberOfMatchedStations > 1    \
1577 <      && fabs(object->correctedD0Vertex) < 0.2  \
1578 <      && fabs(object->correctedDZ) < 0.5        \
1579 <      && object->numberOfValidPixelHits > 0     \
1572 >    value = object->isGlobalMuon > 0                \
1573 >      && object->isPFMuon > 0                        \
1574 >      && object->normalizedChi2 < 10                \
1575 >                                  && object->numberOfValidMuonHits > 0        \
1576 >      && object->numberOfMatchedStations > 1        \
1577 >      && fabs(object->correctedD0Vertex) < 0.2        \
1578 >      && fabs(object->correctedDZ) < 0.5        \
1579 >      && object->numberOfValidPixelHits > 0                \
1580        && object->numberOfLayersWithMeasurement > 5;
893    
894
1581    }
1582    else if(variable == "tightIDdisplaced"){
1583 <    value = object->isGlobalMuon > 0            \
1584 <      && object->isPFMuon > 0                   \
1585 <      && object->normalizedChi2 < 10            \
1586 <      && object->numberOfValidMuonHits > 0      \
1587 <      && object->numberOfMatchedStations > 1    \
1588 <      && object->numberOfValidPixelHits > 0     \
1583 >    value = object->isGlobalMuon > 0                \
1584 >      && object->isPFMuon > 0                        \
1585 >      && object->normalizedChi2 < 10                \
1586 >                                  && object->numberOfValidMuonHits > 0        \
1587 >      && object->numberOfMatchedStations > 1        \
1588 >      && object->numberOfValidPixelHits > 0        \
1589        && object->numberOfLayersWithMeasurement > 5;
1590    }
1591  
1592 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1592 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1593 >
1594 >  else if(variable == "genMatchedPdgId"){
1595 >    int index = getGenMatchedParticleIndex(object);
1596 >    if(index == -1) value = 0;
1597 >    else value = mcparticles->at(index).id;
1598 >  }
1599 >
1600 >  else if(variable == "genMatchedId"){
1601 >    int index = getGenMatchedParticleIndex(object);
1602 >    if(index == -1) value = 0;
1603 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
1604 >  }
1605 >  else if(variable == "genMatchedMotherId"){
1606 >    int index = getGenMatchedParticleIndex(object);
1607 >    if(index == -1) value = 0;
1608 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1609 >  }
1610 >  else if(variable == "genMatchedMotherIdReverse"){
1611 >    int index = getGenMatchedParticleIndex(object);
1612 >    if(index == -1) value = 24;
1613 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1614 >  }
1615 >  else if(variable == "genMatchedGrandmotherId"){
1616 >    int index = getGenMatchedParticleIndex(object);
1617 >    if(index == -1) value = 0;
1618 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1619 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1620 >      if(motherIndex == -1) value = 0;
1621 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1622 >    }
1623 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1624 >  }
1625 >  else if(variable == "genMatchedGrandmotherIdReverse"){
1626 >    int index = getGenMatchedParticleIndex(object);
1627 >    if(index == -1) value = 24;
1628 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1629 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1630 >      if(motherIndex == -1) value = 24;
1631 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1632 >    }
1633 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1634 >  }
1635 >  else if(variable == "pfMuonsFromVertex"){
1636 >    double d0Error, dzError;
1637 >
1638 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1639 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1640 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1641 >         || fabs (object->correctedD0Vertex / d0Error) > 99.0
1642 >         || fabs (object->correctedDZ / dzError) > 99.0;
1643 >    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1644 >  }
1645 >
1646 >
1647 >
1648 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1649  
1650    value = applyFunction(function, value);
1651  
1652    return value;
1653   }
1654  
1655 <
1655 > //!electron valueLookup
1656   double
1657 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1657 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1658  
1659    double value = 0.0;
1660    if(variable == "energy") value = object->energy;
# Line 1073 | Line 1815 | OSUAnalysis::valueLookup (const BNelectr
1815    else if(variable == "passConvVeto") value = object->passConvVeto;
1816  
1817    //user-defined variables
1818 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1819 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1818 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1819 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1820    else if(variable == "detIso") value = (object->trackIso) / object->pt;
1821    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1822 +  else if(variable == "metMT") {
1823 +    if (const BNmet *met = chosenMET ())
1824 +      {
1825 +        double dPhi = deltaPhi (object->phi, met->phi);
1826 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1827 +      }
1828 +    else
1829 +      value = -999;
1830 +  }
1831  
1832 +  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
1833 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
1834 +    else value = -999;
1835 +  }
1836 +  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
1837 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
1838 +    else value = -999;
1839 +  }
1840  
1841 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1841 >  else if(variable == "correctedD0VertexInEBPlus"){
1842 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1843 >    else value = -999;
1844 >  }
1845 >  else if(variable == "correctedD0VertexOutEBPlus"){
1846 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1847 >    else value = -999;
1848 >  }
1849 >  else if(variable == "correctedD0VertexEEPlus"){
1850 >    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
1851 >    else value = -999;
1852 >  }
1853 >
1854 >  else if(variable == "correctedD0BeamspotInEBPlus"){
1855 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1856 >    else value = -999;
1857 >  }
1858 >  else if(variable == "correctedD0BeamspotOutEBPlus"){
1859 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1860 >    else value = -999;
1861 >  }
1862 >  else if(variable == "correctedD0BeamspotEEPlus"){
1863 >    if(object->isEE && object->eta > 0) value = object->correctedD0;
1864 >    else value = -999;
1865 >  }
1866 >
1867 >  else if(variable == "correctedD0VertexInEBMinus"){
1868 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1869 >    else value = -999;
1870 >  }
1871 >  else if(variable == "correctedD0VertexOutEBMinus"){
1872 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1873 >    else value = -999;
1874 >  }
1875 >  else if(variable == "correctedD0VertexEEMinus"){
1876 >    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
1877 >    else value = -999;
1878 >  }
1879 >
1880 >  else if(variable == "correctedD0BeamspotInEBMinus"){
1881 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1882 >    else value = -999;
1883 >  }
1884 >  else if(variable == "correctedD0BeamspotOutEBMinus"){
1885 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1886 >    else value = -999;
1887 >  }
1888 >  else if(variable == "correctedD0BeamspotEEMinus"){
1889 >    if(object->isEE && object->eta < 0) value = object->correctedD0;
1890 >    else value = -999;
1891 >  }
1892 >
1893 >  else if(variable == "tightID"){
1894 >    if (object->isEB)
1895 >      {
1896 >        value = fabs(object->delEtaIn) < 0.004 \
1897 >          && fabs (object->delPhiIn) < 0.03 \
1898 >          && object->scSigmaIEtaIEta < 0.01 \
1899 >          && object->hadOverEm < 0.12 \
1900 >          && fabs (object->correctedD0Vertex) < 0.02 \
1901 >          && fabs (object->correctedDZ) < 0.1 \
1902 >          && object->absInvEMinusInvPin < 0.05 \
1903 >          && object->passConvVeto;
1904 >      }
1905 >    else
1906 >      {
1907 >        value = fabs(object->delEtaIn) < 0.005 \
1908 >          && fabs (object->delPhiIn) < 0.02 \
1909 >          && object->scSigmaIEtaIEta < 0.03 \
1910 >          && object->hadOverEm < 0.10 \
1911 >          && fabs (object->correctedD0Vertex) < 0.02 \
1912 >          && fabs (object->correctedDZ) < 0.1 \
1913 >          && object->absInvEMinusInvPin < 0.05 \
1914 >          && object->passConvVeto;
1915 >      }
1916 >  }
1917 >
1918 >  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1919 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1920 >    else value = -999;
1921 >  }
1922 >  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1923 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1924 >    else value = -999;
1925 >  }
1926 >  else if(variable == "correctedD0VertexEEPositiveCharge"){
1927 >    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
1928 >    else value = -999;
1929 >  }
1930 >
1931 >  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1932 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1933 >    else value = -999;
1934 >  }
1935 >  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1936 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1937 >    else value = -999;
1938 >  }
1939 >  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1940 >    if(object->isEE && object->charge > 0) value = object->correctedD0;
1941 >    else value = -999;
1942 >  }
1943 >
1944 >  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1945 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1946 >    else value = -999;
1947 >  }
1948 >  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1949 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1950 >    else value = -999;
1951 >  }
1952 >  else if(variable == "correctedD0VertexEENegativeCharge"){
1953 >    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
1954 >    else value = -999;
1955 >  }
1956 >
1957 >  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1958 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1959 >    else value = -999;
1960 >  }
1961 >  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1962 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1963 >    else value = -999;
1964 >  }
1965 >  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1966 >    if(object->isEE && object->charge < 0) value = object->correctedD0;
1967 >    else value = -999;
1968 >  }
1969 >
1970 >
1971 >  else if(variable == "tightIDdisplaced"){
1972 >    if (object->isEB)
1973 >      {
1974 >        value = fabs(object->delEtaIn) < 0.004 \
1975 >          && fabs (object->delPhiIn) < 0.03 \
1976 >          && object->scSigmaIEtaIEta < 0.01 \
1977 >          && object->hadOverEm < 0.12 \
1978 >          && object->absInvEMinusInvPin < 0.05;
1979 >      }
1980 >    else
1981 >      {
1982 >        value = fabs (object->delEtaIn) < 0.005 \
1983 >          && fabs (object->delPhiIn) < 0.02 \
1984 >          && object->scSigmaIEtaIEta < 0.03 \
1985 >          && object->hadOverEm < 0.10 \
1986 >          && object->absInvEMinusInvPin < 0.05;
1987 >      }
1988 >  }
1989 >
1990 >
1991 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1992 >
1993 >  else if(variable == "genMatchedPdgId"){
1994 >    int index = getGenMatchedParticleIndex(object);
1995 >    if(index == -1) value = 0;
1996 >    else value = mcparticles->at(index).id;
1997 >  }
1998 >
1999 >
2000 >  else if(variable == "genMatchedId"){
2001 >    int index = getGenMatchedParticleIndex(object);
2002 >    if(index == -1) value = 0;
2003 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2004 >  }
2005 >  else if(variable == "genMatchedMotherId"){
2006 >    int index = getGenMatchedParticleIndex(object);
2007 >    if(index == -1) value = 0;
2008 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2009 >  }
2010 >  else if(variable == "genMatchedMotherIdReverse"){
2011 >    int index = getGenMatchedParticleIndex(object);
2012 >    if(index == -1) value = 24;
2013 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2014 >  }
2015 >  else if(variable == "genMatchedGrandmotherId"){
2016 >    int index = getGenMatchedParticleIndex(object);
2017 >    if(index == -1) value = 0;
2018 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2019 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2020 >      if(motherIndex == -1) value = 0;
2021 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2022 >    }
2023 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2024 >  }
2025 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2026 >    int index = getGenMatchedParticleIndex(object);
2027 >    if(index == -1) value = 24;
2028 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2029 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2030 >      if(motherIndex == -1) value = 24;
2031 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2032 >    }
2033 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2034 >  }
2035 >  else if(variable == "pfElectronsFromVertex"){
2036 >    double d0Error, dzError;
2037 >
2038 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2039 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2040 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2041 >         || fabs (object->correctedD0Vertex / d0Error) > 99.0
2042 >         || fabs (object->correctedDZ / dzError) > 99.0;
2043 >    value = !value;
2044 >  }
2045 >
2046 >
2047 >
2048 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2049  
2050    value = applyFunction(function, value);
2051  
2052    return value;
2053   }
2054  
2055 <
2055 > //!event valueLookup
2056   double
2057 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2057 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2058  
2059    double value = 0.0;
2060  
# Line 1156 | Line 2122 | OSUAnalysis::valueLookup (const BNevent*
2122    else if(variable == "id1") value = object->id1;
2123    else if(variable == "id2") value = object->id2;
2124    else if(variable == "evt") value = object->evt;
2125 +  else if(variable == "puScaleFactor"){
2126 +    if(doPileupReweighting_ && datasetType_ != "data")
2127 +      value = puWeight_->at (events->at (0).numTruePV);
2128 +    else
2129 +      value = 1.0;
2130 +  }
2131 +  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2132 +  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2133 +  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2134  
2135 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2135 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2136  
2137    value = applyFunction(function, value);
2138  
2139    return value;
2140   }
2141  
2142 + //!tau valueLookup
2143   double
2144 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2144 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2145  
2146    double value = 0.0;
2147  
# Line 1210 | Line 2186 | OSUAnalysis::valueLookup (const BNtau* o
2186    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2187  
2188  
2189 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2189 >
2190 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2191 >
2192 >  else if(variable == "genMatchedPdgId"){
2193 >    int index = getGenMatchedParticleIndex(object);
2194 >    if(index == -1) value = 0;
2195 >    else value = mcparticles->at(index).id;
2196 >  }
2197 >
2198 >  else if(variable == "genMatchedId"){
2199 >    int index = getGenMatchedParticleIndex(object);
2200 >    if(index == -1) value = 0;
2201 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2202 >  }
2203 >  else if(variable == "genMatchedMotherId"){
2204 >    int index = getGenMatchedParticleIndex(object);
2205 >    if(index == -1) value = 0;
2206 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2207 >  }
2208 >  else if(variable == "genMatchedMotherIdReverse"){
2209 >    int index = getGenMatchedParticleIndex(object);
2210 >    if(index == -1) value = 24;
2211 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2212 >  }
2213 >  else if(variable == "genMatchedGrandmotherId"){
2214 >    int index = getGenMatchedParticleIndex(object);
2215 >    if(index == -1) value = 0;
2216 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2217 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2218 >      if(motherIndex == -1) value = 0;
2219 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2220 >    }
2221 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2222 >  }
2223 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2224 >    int index = getGenMatchedParticleIndex(object);
2225 >    if(index == -1) value = 24;
2226 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2227 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2228 >      if(motherIndex == -1) value = 24;
2229 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2230 >    }
2231 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2232 >  }
2233 >
2234 >
2235 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2236  
2237    value = applyFunction(function, value);
2238  
2239    return value;
2240   }
2241  
2242 + //!met valueLookup
2243   double
2244 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2244 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2245  
2246    double value = 0.0;
2247  
# Line 1282 | Line 2305 | OSUAnalysis::valueLookup (const BNmet* o
2305    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2306    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2307  
2308 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2308 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2309  
2310    value = applyFunction(function, value);
2311  
2312    return value;
2313   }
2314  
2315 + //!track valueLookup
2316   double
2317 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2317 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2318  
2319    double value = 0.0;
2320 +  double pMag = sqrt(object->pt * object->pt +
2321 +                     object->pz * object->pz);
2322  
2323    if(variable == "pt") value = object->pt;
2324    else if(variable == "px") value = object->px;
# Line 1313 | Line 2339 | OSUAnalysis::valueLookup (const BNtrack*
2339    else if(variable == "isHighPurity") value = object->isHighPurity;
2340  
2341  
2342 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2342 >  //additional BNs info for disappTrks
2343 >  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2344 >  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2345 >  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2346 >  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2347 >  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2348 >  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2349 >  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2350 >  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2351 >  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2352 >  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2353 >  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2354 >
2355 >  //user defined variables
2356 >  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;
2357 >  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2358 >  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2359 >  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2360 >  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2361 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2362 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2363 >  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2364 >  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2365 >  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2366 >  else if(variable == "ptError")                    value = object->ptError;
2367 >  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2368 >  else if (variable == "d0wrtPV"){
2369 >    double vx = object->vx - chosenVertex ()->x,
2370 >      vy = object->vy - chosenVertex ()->y,
2371 >      px = object->px,
2372 >      py = object->py,
2373 >      pt = object->pt;
2374 >    value = (-vx * py + vy * px) / pt;
2375 >  }
2376 >  else if (variable == "dZwrtPV"){
2377 >    double vx = object->vx - chosenVertex ()->x,
2378 >      vy = object->vy - chosenVertex ()->y,
2379 >      vz = object->vz - chosenVertex ()->z,
2380 >      px = object->px,
2381 >      py = object->py,
2382 >      pz = object->pz,
2383 >      pt = object->pt;
2384 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2385 >  }
2386 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2387 >
2388 >  else if(variable == "genMatchedPdgId"){
2389 >    int index = getGenMatchedParticleIndex(object);
2390 >    if(index == -1) value = 0;
2391 >    else value = mcparticles->at(index).id;
2392 >  }
2393 >
2394 >
2395 >  else if(variable == "genMatchedId"){
2396 >    int index = getGenMatchedParticleIndex(object);
2397 >    if(index == -1) value = 0;
2398 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2399 >  }
2400 >  else if(variable == "genMatchedMotherId"){
2401 >    int index = getGenMatchedParticleIndex(object);
2402 >    if(index == -1) value = 0;
2403 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2404 >  }
2405 >  else if(variable == "genMatchedMotherIdReverse"){
2406 >    int index = getGenMatchedParticleIndex(object);
2407 >    if(index == -1) value = 24;
2408 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2409 >  }
2410 >  else if(variable == "genMatchedGrandmotherId"){
2411 >    int index = getGenMatchedParticleIndex(object);
2412 >    if(index == -1) value = 0;
2413 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2414 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2415 >      if(motherIndex == -1) value = 0;
2416 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2417 >    }
2418 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2419 >  }
2420 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2421 >    int index = getGenMatchedParticleIndex(object);
2422 >    if(index == -1) value = 24;
2423 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2424 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2425 >      if(motherIndex == -1) value = 24;
2426 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2427 >    }
2428 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2429 >  }
2430 >
2431 >
2432 >
2433 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2434  
2435    value = applyFunction(function, value);
2436  
2437    return value;
2438   }
2439  
2440 + //!genjet valueLookup
2441   double
2442 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2442 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2443  
2444    double value = 0.0;
2445  
# Line 1341 | Line 2459 | OSUAnalysis::valueLookup (const BNgenjet
2459    else if(variable == "charge") value = object->charge;
2460  
2461  
2462 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2462 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2463  
2464    value = applyFunction(function, value);
2465  
2466    return value;
2467   }
2468  
2469 + //!mcparticle valueLookup
2470   double
2471 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2471 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2472  
2473    double value = 0.0;
2474  
# Line 1440 | Line 2559 | OSUAnalysis::valueLookup (const BNmcpart
2559  
2560    //user-defined variables
2561    else if (variable == "d0"){
2562 <    double vx = object->vx - primaryVertex_->x,
2563 <      vy = object->vy - primaryVertex_->y,
2562 >    double vx = object->vx - chosenVertex ()->x,
2563 >      vy = object->vy - chosenVertex ()->y,
2564        px = object->px,
2565        py = object->py,
2566        pt = object->pt;
2567      value = (-vx * py + vy * px) / pt;
2568    }
2569    else if (variable == "dz"){
2570 <    double vx = object->vx - primaryVertex_->x,
2571 <      vy = object->vy - primaryVertex_->y,
2572 <      vz = object->vz - primaryVertex_->z,
2570 >    double vx = object->vx - chosenVertex ()->x,
2571 >      vy = object->vy - chosenVertex ()->y,
2572 >      vz = object->vz - chosenVertex ()->z,
2573        px = object->px,
2574        py = object->py,
2575        pz = object->pz,
2576        pt = object->pt;
2577      value = vz - (vx * px + vy * py)/pt * (pz/pt);
2578    }
2579 +  else if(variable == "v0"){
2580 +    value = sqrt(object->vx*object->vx + object->vy*object->vy);
2581 +  }
2582 +  else if(variable == "deltaV0"){
2583 +    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
2584 +  }
2585 +  else if (variable == "deltaVx"){
2586 +    value = object->vx - chosenVertex ()->x;
2587 +  }
2588 +  else if (variable == "deltaVy"){
2589 +    value = object->vy - chosenVertex ()->y;
2590 +  }
2591 +  else if (variable == "deltaVz"){
2592 +    value = object->vz - chosenVertex ()->z;
2593 +  }
2594  
2595  
2596 <
1463 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2596 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2597  
2598    value = applyFunction(function, value);
2599  
2600    return value;
2601   }
2602  
2603 + //!primaryvertex valueLookup
2604   double
2605 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2605 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2606  
2607    double value = 0.0;
2608  
# Line 1487 | Line 2621 | OSUAnalysis::valueLookup (const BNprimar
2621    else if(variable == "isGood") value = object->isGood;
2622  
2623  
2624 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2624 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2625  
2626    value = applyFunction(function, value);
2627  
2628    return value;
2629   }
2630  
2631 + //!bxlumi valueLookup
2632   double
2633 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2633 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2634  
2635    double value = 0.0;
2636  
# Line 1504 | Line 2639 | OSUAnalysis::valueLookup (const BNbxlumi
2639    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2640  
2641  
2642 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2642 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2643  
2644    value = applyFunction(function, value);
2645  
2646    return value;
2647   }
2648  
2649 + //!photon valueLookup
2650   double
2651 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2651 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2652  
2653    double value = 0.0;
2654  
# Line 1587 | Line 2723 | OSUAnalysis::valueLookup (const BNphoton
2723    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2724  
2725  
2726 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2726 >
2727 >
2728 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2729 >
2730 >  else if(variable == "genMatchedPdgId"){
2731 >    int index = getGenMatchedParticleIndex(object);
2732 >    if(index == -1) value = 0;
2733 >    else value = mcparticles->at(index).id;
2734 >  }
2735 >
2736 >
2737 >
2738 >  else if(variable == "genMatchedId"){
2739 >    int index = getGenMatchedParticleIndex(object);
2740 >    if(index == -1) value = 0;
2741 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2742 >  }
2743 >  else if(variable == "genMatchedMotherId"){
2744 >    int index = getGenMatchedParticleIndex(object);
2745 >    if(index == -1) value = 0;
2746 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2747 >  }
2748 >  else if(variable == "genMatchedMotherIdReverse"){
2749 >    int index = getGenMatchedParticleIndex(object);
2750 >    if(index == -1) value = 24;
2751 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2752 >  }
2753 >  else if(variable == "genMatchedGrandmotherId"){
2754 >    int index = getGenMatchedParticleIndex(object);
2755 >    if(index == -1) value = 0;
2756 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2757 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2758 >      if(motherIndex == -1) value = 0;
2759 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2760 >    }
2761 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2762 >  }
2763 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2764 >    int index = getGenMatchedParticleIndex(object);
2765 >    if(index == -1) value = 24;
2766 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2767 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2768 >      if(motherIndex == -1) value = 24;
2769 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2770 >    }
2771 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2772 >  }
2773 >
2774 >
2775 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2776  
2777    value = applyFunction(function, value);
2778  
2779    return value;
2780   }
2781  
2782 + //!supercluster valueLookup
2783   double
2784 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
2784 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
2785  
2786    double value = 0.0;
2787  
# Line 1609 | Line 2795 | OSUAnalysis::valueLookup (const BNsuperc
2795    else if(variable == "theta") value = object->theta;
2796  
2797  
2798 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2798 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2799  
2800    value = applyFunction(function, value);
2801  
2802    return value;
2803   }
2804  
2805 + //!trigobj valueLookup
2806 + double
2807 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
2808 +
2809 +  double value = 0.0;
2810 +
2811 +  if(variable == "pt") value = object->pt;
2812 +  else if(variable == "eta") value = object->eta;
2813 +  else if(variable == "phi") value = object->phi;
2814 +  else if(variable == "px") value = object->px;
2815 +  else if(variable == "py") value = object->py;
2816 +  else if(variable == "pz") value = object->pz;
2817 +  else if(variable == "et") value = object->et;
2818 +  else if(variable == "energy") value = object->energy;
2819 +  else if(variable == "etTotal") value = object->etTotal;
2820 +  else if(variable == "id") value = object->id;
2821 +  else if(variable == "charge") value = object->charge;
2822 +  else if(variable == "isIsolated") value = object->isIsolated;
2823 +  else if(variable == "isMip") value = object->isMip;
2824 +  else if(variable == "isForward") value = object->isForward;
2825 +  else if(variable == "isRPC") value = object->isRPC;
2826 +  else if(variable == "bx") value = object->bx;
2827 +  else if(variable == "filter") {
2828 +    if ((stringValue = object->filter) == "")
2829 +      stringValue = "none";  // stringValue should only be empty if value is filled
2830 +  }
2831 +
2832 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2833  
2834 +  value = applyFunction(function, value);
2835 +
2836 +  return value;
2837 + }
2838 +
2839 + //!muon-muon pair valueLookup
2840   double
2841 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
2841 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
2842  
2843    double value = 0.0;
2844  
2845 <  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
2845 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2846 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2847 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2848    else if(variable == "invMass"){
2849      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2850      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2851      value = (fourVector1 + fourVector2).M();
2852    }
2853 +  else if(variable == "pt"){
2854 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2855 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2856 +    value = (fourVector1 + fourVector2).Pt();
2857 +  }
2858 +  else if(variable == "threeDAngle")
2859 +    {
2860 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2861 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2862 +      value = (threeVector1.Angle(threeVector2));
2863 +    }
2864 +  else if(variable == "alpha")
2865 +    {
2866 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
2867 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2868 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2869 +      value = (pi-threeVector1.Angle(threeVector2));
2870 +    }
2871    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2872    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2873 <  else if(variable == "d0Sign") value = object1->correctedD0Vertex*object2->correctedD0Vertex/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2873 >  else if(variable == "d0Sign"){
2874 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2875 >    if(d0Sign < 0) value = -0.5;
2876 >    else if (d0Sign > 0) value = 0.5;
2877 >    else value = -999;
2878 >  }
2879 >  else if(variable == "chargeProduct"){
2880 >    value = object1->charge*object2->charge;
2881 >  }
2882 >  else if(variable == "muon1CorrectedD0Vertex"){
2883 >    value = object1->correctedD0Vertex;
2884 >  }
2885 >  else if(variable == "muon2CorrectedD0Vertex"){
2886 >    value = object2->correctedD0Vertex;
2887 >  }
2888 >  else if(variable == "muon1timeAtIpInOut"){
2889 >    value = object1->timeAtIpInOut;
2890 >  }
2891 >  else if(variable == "muon2timeAtIpInOut"){
2892 >    value = object2->timeAtIpInOut;
2893 >  }
2894 >  else if(variable == "muon1correctedD0")
2895 >    {
2896 >      value = object1->correctedD0;
2897 >    }
2898 >  else if(variable == "muon2correctedD0")
2899 >    {
2900 >      value = object2->correctedD0;
2901 >    }
2902  
2903 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2903 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2904  
2905    value = applyFunction(function, value);
2906  
2907    return value;
2908   }
2909  
2910 + //!electron-electron pair valueLookup
2911   double
2912 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
2912 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
2913  
2914    double value = 0.0;
2915  
2916 <  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
2916 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2917 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2918 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2919    else if(variable == "invMass"){
2920      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2921      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2922      value = (fourVector1 + fourVector2).M();
2923    }
2924 +  else if(variable == "pt"){
2925 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2926 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2927 +    value = (fourVector1 + fourVector2).Pt();
2928 +  }
2929 +  else if(variable == "threeDAngle")
2930 +    {
2931 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2932 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2933 +      value = (threeVector1.Angle(threeVector2));
2934 +    }
2935    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2936    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2937 <  else if(variable == "d0Sign") value = object1->correctedD0Vertex*object2->correctedD0Vertex/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2937 >  else if(variable == "d0Sign"){
2938 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2939 >    if(d0Sign < 0) value = -0.5;
2940 >    else if (d0Sign > 0) value = 0.5;
2941 >    else value = -999;
2942 >  }
2943 >  else if(variable == "chargeProduct"){
2944 >    value = object1->charge*object2->charge;
2945 >  }
2946 >  else if(variable == "electron1CorrectedD0Vertex"){
2947 >    value = object1->correctedD0Vertex;
2948 >  }
2949 >  else if(variable == "electron2CorrectedD0Vertex"){
2950 >    value = object2->correctedD0Vertex;
2951 >  }
2952 >  else if(variable == "electron1CorrectedD0"){
2953 >    value = object1->correctedD0;
2954 >  }
2955 >  else if(variable == "electron2CorrectedD0"){
2956 >    value = object2->correctedD0;
2957 >  }
2958  
2959 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2959 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2960  
2961    value = applyFunction(function, value);
2962  
2963    return value;
2964   }
2965 <
2965 > //!electron-muon pair valueLookup
2966   double
2967 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
2967 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
2968  
2969    double value = 0.0;
2970  
2971 <  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
2971 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2972 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2973 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2974    else if(variable == "invMass"){
2975      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2976      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2977      value = (fourVector1 + fourVector2).M();
2978    }
2979 +  else if(variable == "pt"){
2980 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2981 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2982 +    value = (fourVector1 + fourVector2).Pt();
2983 +  }
2984 +  else if(variable == "threeDAngle")
2985 +    {
2986 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2987 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2988 +      value = (threeVector1.Angle(threeVector2));
2989 +    }
2990    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2991    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2992 <  else if(variable == "d0Sign") value = object1->correctedD0Vertex*object2->correctedD0Vertex/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2992 >  else if(variable == "d0Sign"){
2993 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2994 >    if(d0Sign < 0) value = -0.5;
2995 >    else if (d0Sign > 0) value = 0.5;
2996 >    else value = -999;
2997 >  }
2998 >  else if(variable == "chargeProduct"){
2999 >    value = object1->charge*object2->charge;
3000 >  }
3001 >  else if(variable == "electronCorrectedD0Vertex"){
3002 >    value = object1->correctedD0Vertex;
3003 >  }
3004 >  else if(variable == "muonCorrectedD0Vertex"){
3005 >    value = object2->correctedD0Vertex;
3006 >  }
3007 >  else if(variable == "electronCorrectedD0"){
3008 >    value = object1->correctedD0;
3009 >  }
3010 >  else if(variable == "muonCorrectedD0"){
3011 >    value = object2->correctedD0;
3012 >  }
3013 >  else if(variable == "electronDetIso"){
3014 >    value = (object1->trackIso) / object1->pt;
3015 >  }
3016 >  else if(variable == "muonDetIso"){
3017 >    value = (object2->trackIsoDR03) / object2->pt;
3018 >  }
3019 >  else if(variable == "electronRelPFrhoIso"){
3020 >    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3021 >  }
3022 >  else if(variable == "muonRelPFdBetaIso"){
3023 >    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3024 >  }
3025 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3026 >  value = applyFunction(function, value);
3027 >
3028 >  return value;
3029 > }
3030 >
3031 > //!electron-jet pair valueLookup
3032 > double
3033 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3034 >
3035 >  double value = 0.0;
3036 >
3037 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3038 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3039 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3040 >  else if(variable == "invMass"){
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).M();
3044 >  }
3045 >  else if(variable == "pt"){
3046 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3047 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3048 >    value = (fourVector1 + fourVector2).Pt();
3049 >  }
3050 >  else if(variable == "threeDAngle")
3051 >    {
3052 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3053 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3054 >      value = (threeVector1.Angle(threeVector2));
3055 >    }
3056 >  else if(variable == "chargeProduct"){
3057 >    value = object1->charge*object2->charge;
3058 >  }
3059 >
3060 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3061 >  value = applyFunction(function, value);
3062 >
3063 >  return value;
3064 > }
3065 >
3066 > //!muon-jet pair valueLookup
3067 > double
3068 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3069 >
3070 >  double value = 0.0;
3071 >
3072 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3073 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3074 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3075 >  else if(variable == "invMass"){
3076 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3077 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3078 >    value = (fourVector1 + fourVector2).M();
3079 >  }
3080 >  else if(variable == "pt"){
3081 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3082 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3083 >    value = (fourVector1 + fourVector2).Pt();
3084 >  }
3085 >  else if(variable == "threeDAngle")
3086 >    {
3087 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3088 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3089 >      value = (threeVector1.Angle(threeVector2));
3090 >    }
3091 >  else if(variable == "chargeProduct"){
3092 >    value = object1->charge*object2->charge;
3093 >  }
3094 >
3095 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3096 >  value = applyFunction(function, value);
3097 >
3098 >  return value;
3099 > }
3100 >
3101 > //!jet-jet pair valueLookup
3102 > double
3103 > OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3104 >
3105 >  double value = 0.0;
3106 >
3107 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3108 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3109 >  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3110 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3111 >  else if(variable == "invMass"){
3112 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3113 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3114 >    value = (fourVector1 + fourVector2).M();
3115 >  }
3116 >  else if(variable == "pt"){
3117 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3118 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3119 >    value = (fourVector1 + fourVector2).Pt();
3120 >  }
3121 >  else if(variable == "threeDAngle")
3122 >    {
3123 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3124 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3125 >      value = (threeVector1.Angle(threeVector2));
3126 >    }
3127 >  else if(variable == "chargeProduct"){
3128 >    value = object1->charge*object2->charge;
3129 >  }
3130 >
3131 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3132 >  value = applyFunction(function, value);
3133 >
3134 >  return value;
3135 > }
3136 > //!electron-track pair valueLookup
3137 > double
3138 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3139 >  double electronMass = 0.000511;
3140 >  double value = 0.0;
3141 >  TLorentzVector fourVector1(0, 0, 0, 0);
3142 >  TLorentzVector fourVector2(0, 0, 0, 0);
3143 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3144 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3145 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3146 >  else if(variable == "invMass"){
3147 >    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3148 >    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3149 >
3150 >    value = (fourVector1 + fourVector2).M();
3151 >  }
3152 >  else if(variable == "chargeProduct"){
3153 >    value = object1->charge*object2->charge;
3154 >  }
3155 >  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3156 >  value = applyFunction(function, value);
3157 >  return value;
3158 >
3159 > }
3160 >
3161 >
3162 > //!muon-track pair valueLookup
3163 > double
3164 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3165 >  double pionMass = 0.140;
3166 >  double muonMass = 0.106;
3167 >  double value = 0.0;
3168 >  TLorentzVector fourVector1(0, 0, 0, 0);
3169 >  TLorentzVector fourVector2(0, 0, 0, 0);
3170 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3171 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3172 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3173 >  else if(variable == "invMass"){
3174 >    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3175 >    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3176 >
3177 >    value = (fourVector1 + fourVector2).M();
3178 >  }
3179 >  else if(variable == "chargeProduct"){
3180 >    value = object1->charge*object2->charge;
3181 >  }
3182 >
3183 >  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3184 >  value = applyFunction(function, value);
3185 >  return value;
3186 > }
3187 >
3188 > //!tau-tau pair valueLookup
3189 > double
3190 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3191 >  double value = 0.0;
3192 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3193 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3194 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3195 >  else if(variable == "invMass"){
3196 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3197 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3198 >    value = (fourVector1 + fourVector2).M();
3199 >  }
3200 >
3201 >  else if(variable == "chargeProduct"){
3202 >    value = object1->charge*object2->charge;
3203 >  }
3204  
3205    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3206 +  value = applyFunction(function, value);
3207 +  return value;
3208 + }
3209 +
3210 + //!muon-tau pair valueLookup
3211 + double
3212 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3213 +  double value = 0.0;
3214 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3215 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3216 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3217 +  else if(variable == "invMass"){
3218 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3219 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3220 +    value = (fourVector1 + fourVector2).M();
3221 +  }
3222  
3223 +  else if(variable == "chargeProduct"){
3224 +    value = object1->charge*object2->charge;
3225 +  }
3226 +
3227 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3228    value = applyFunction(function, value);
3229 +  return value;
3230 + }
3231 +
3232 + //!tau-track pair valueLookup
3233 + double
3234 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3235 +  double value = 0.0;
3236 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3237 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3238 +  else if(variable == "chargeProduct"){
3239 +    value = object1->charge*object2->charge;
3240 +  }
3241  
3242 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3243 +  value = applyFunction(function, value);
3244    return value;
3245   }
3246  
3247  
3248 + //!track-event pair valueLookup
3249 + double
3250 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3251 +
3252 +  double value = 0.0;
3253 +  double pMag = sqrt(object1->pt * object1->pt +
3254 +                     object1->pz * object1->pz);
3255 +
3256 +  if      (variable == "numPV")                      value = object2->numPV;
3257 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3258 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3259 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3260 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3261 +
3262 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3263 +
3264 +  value = applyFunction(function, value);
3265 +
3266 +  return value;
3267 +
3268 + }
3269 +
3270 + //!electron-trigobj pair valueLookup
3271 + double
3272 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3273 +
3274 +  double value = 0.0;
3275 +
3276 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3277 +  else if (variable == "match"){
3278 +    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3279 +      stringValue = object2->filter;
3280 +    else
3281 +      stringValue = "none";
3282 +  }
3283 +
3284 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3285 +
3286 +  value = applyFunction(function, value);
3287 +
3288 +  return value;
3289 +
3290 + }
3291 +
3292 + //!muon-trigobj pair valueLookup
3293 + double
3294 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3295 +
3296 +  double value = 0.0;
3297 +
3298 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3299 +
3300 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3301 +
3302 +  value = applyFunction(function, value);
3303 +
3304 +  return value;
3305 +
3306 + }
3307 +
3308 + //!stop valueLookup
3309 + double
3310 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3311 +
3312 +
3313 +  double value = 0.0;
3314 +
3315 +  if(variable == "ctau") value = object->ctau;
3316 +
3317 +  else if (variable == "d0"){
3318 +    double vx = object->vx - chosenVertex ()->x,
3319 +      vy = object->vy - chosenVertex ()->y,
3320 +      px = object->px,
3321 +      py = object->py,
3322 +      pt = object->pt;
3323 +    value = (-vx * py + vy * px) / pt;
3324 +  }
3325 +
3326 +  else if (variable == "dz"){
3327 +    double vx = object->vx - chosenVertex ()->x,
3328 +      vy = object->vy - chosenVertex ()->y,
3329 +      vz = object->vz - chosenVertex ()->z,
3330 +      px = object->px,
3331 +      py = object->py,
3332 +      pz = object->pz,
3333 +      pt = object->pt;
3334 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3335 +  }
3336 +
3337 +  else if (variable == "minD0"){
3338 +    double minD0=999;
3339 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3340 +      double vx = object->vx - vertex->x,
3341 +        vy = object->vy - vertex->y,
3342 +        px = object->px,
3343 +        py = object->py,
3344 +        pt = object->pt;
3345 +      value = (-vx * py + vy * px) / pt;
3346 +      if(abs(value) < abs(minD0)) minD0 = value;
3347 +    }
3348 +    value = minD0;
3349 +  }
3350 +  else if (variable == "minDz"){
3351 +    double minDz=999;
3352 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3353 +      double vx = object->vx - vertex->x,
3354 +        vy = object->vy - vertex->y,
3355 +        vz = object->vz - vertex->z,
3356 +        px = object->px,
3357 +        py = object->py,
3358 +        pz = object->pz,
3359 +        pt = object->pt;
3360 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3361 +      if(abs(value) < abs(minDz)) minDz = value;
3362 +    }
3363 +    value = minDz;
3364 +  }
3365 +  else if(variable == "distToVertex"){
3366 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3367 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3368 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3369 +  }
3370 +  else if (variable == "minDistToVertex"){
3371 +    double minDistToVertex=999;
3372 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3373 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3374 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3375 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3376 +
3377 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3378 +    }
3379 +    value = minDistToVertex;
3380 +  }
3381 +  else if (variable == "distToVertexDifference"){
3382 +    double minDistToVertex=999;
3383 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3384 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3385 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3386 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3387 +
3388 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3389 +    }
3390 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3391 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3392 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3393 +
3394 +    value = distToChosenVertex - minDistToVertex;
3395 +  }
3396 +
3397 +  else if (variable == "closestVertexRank"){
3398 +    double minDistToVertex=999;
3399 +    int vertex_rank = 0;
3400 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3401 +      vertex_rank++;
3402 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3403 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3404 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3405 +
3406 +      if(abs(dist) < abs(minDistToVertex)){
3407 +        value = vertex_rank;
3408 +        minDistToVertex = dist;
3409 +      }
3410 +    }
3411 +  }
3412 +
3413 +
3414 +
3415 +
3416 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3417 +
3418 +  value = applyFunction(function, value);
3419 +
3420 +  return value;
3421 +
3422 + }
3423 +
3424 +
3425 +
3426 +
3427 + // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3428 + // Return true iff no other tracks are found in this cone.
3429 + int
3430 + OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
3431 +  for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
3432 +    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
3433 +    double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
3434 +    if(deltaRtrk < 0.5) return 0;
3435 +  }
3436 +  return 1;
3437 +
3438 + }
3439 +
3440 +
3441 + double
3442 + OSUAnalysis::getTrkPtRes (const BNtrack* track1){
3443 +
3444 +  double ptTrue = getTrkPtTrue(track1, mcparticles.product());
3445 +  double PtRes = (track1->pt - ptTrue) / ptTrue;
3446 +
3447 +  return PtRes;
3448 +
3449 + }
3450 +
3451 +
3452 + double
3453 + OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
3454 +  double value = -99;
3455 +  double genDeltaRLowest = 999;
3456 +
3457 +  for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
3458 +    double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
3459 +    if (genDeltaRtemp < genDeltaRLowest) {
3460 +      genDeltaRLowest = genDeltaRtemp;
3461 +      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
3462 +        double ptTrue = genPart->pt;
3463 +        value = ptTrue;
3464 +      }
3465 +    }
3466 +  }
3467 +
3468 +  return value;
3469 +
3470 + }
3471 +
3472 + double
3473 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3474 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3475 +  if (!useTrackCaloRhoCorr_) return -99;
3476 +  // if (!rhokt6CaloJetsHandle_) {
3477 +  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3478 +  //   return -99;
3479 +  // }
3480 +  double radDeltaRCone = 0.5;
3481 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3482 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3483 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3484 +  return caloTotRhoCorrCalo;
3485 +
3486 + }
3487 +
3488 +
3489 +
3490 +
3491 + //creates a map of the dead Ecal channels in the barrel and endcap
3492 + //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
3493 + //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
3494 + void
3495 + OSUAnalysis::WriteDeadEcal (){
3496 +  double etaEcal, phiEcal;
3497 +  ifstream DeadEcalFile(deadEcalFile_);
3498 +  if(!DeadEcalFile) {
3499 +    cout << "Error: DeadEcalFile has not been found." << endl;
3500 +    return;
3501 +  }
3502 +  if(DeadEcalVec.size()!= 0){
3503 +    cout << "Error: DeadEcalVec has a nonzero size" << endl;
3504 +    return;
3505 +  }
3506 +  while(!DeadEcalFile.eof())
3507 +    {
3508 +      DeadEcalFile >> etaEcal >> phiEcal;
3509 +      DeadEcal newChan;
3510 +      newChan.etaEcal = etaEcal;
3511 +      newChan.phiEcal = phiEcal;
3512 +      DeadEcalVec.push_back(newChan);
3513 +    }
3514 +  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
3515 + }
3516 +
3517 + //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
3518 + int
3519 + OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
3520 +  double deltaRLowest = 999;
3521 +  int value = 0;
3522 +  if (DeadEcalVec.size() == 0) WriteDeadEcal();
3523 +  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3524 +    double eta = ecal->etaEcal;
3525 +    double phi = ecal->phiEcal;
3526 +    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
3527 +    if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3528 +  }
3529 +  if (deltaRLowest<0.05) {value = 1;}
3530 +  else {value = 0;}
3531 +  return value;
3532 + }
3533 +
3534 + // Returns the smallest DeltaR between the object and any generated true particle in the event.
3535 + template <class InputObject>
3536 + double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3537 +  double genDeltaRLowest = 999.;
3538 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3539 +    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
3540 +    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
3541 +  }
3542 +  return genDeltaRLowest;
3543 + }
3544 +
3545   double
3546   OSUAnalysis::applyFunction(string function, double value){
3547  
3548    if(function == "abs") value = fabs(value);
3549 +  else if(function == "fabs") value = fabs(value);
3550 +  else if(function == "log10") value = log10(value);
3551 +  else if(function == "log") value = log10(value);
3552  
3553 +  else if(function == "") value = value;
3554 +  else{cout << "WARNING: invalid function '" << function << "'\n";}
3555  
3556    return value;
3557  
# Line 1698 | Line 3561 | OSUAnalysis::applyFunction(string functi
3561   template <class InputCollection>
3562   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
3563  
3564 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
3565 +    string obj1, obj2;
3566 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
3567 +    if (inputType==obj1 ||
3568 +          inputType==obj2) {
3569 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
3570 +      // and the inputType is a member of the pair.
3571 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
3572 +      // For example, if currentCut.inputCollection==electron-muon pairs,
3573 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
3574 +      return;
3575 +    }
3576 +  }
3577 +
3578    for (uint object = 0; object != inputCollection->size(); object++){
3579  
3580      bool decision = true;//object passes if this cut doesn't cut on that type of object
# Line 1706 | Line 3583 | void OSUAnalysis::setObjectFlags(cut &cu
3583  
3584        vector<bool> subcutDecisions;
3585        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3586 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3587 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3586 >        string stringValue = "";
3587 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3588 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3589 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3590 >
3591        }
3592        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3593        else{
3594 <        bool tempDecision = true;
3595 <        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
3596 <          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
3597 <            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
3598 <          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
3594 >        bool tempDecision = true;
3595 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
3596 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
3597 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
3598 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
3599              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
3600 <        }
3601 <        decision = tempDecision;
3600 >        }
3601 >        decision = tempDecision;
3602        }
3603      }
3604 +
3605      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3606  
3607      //set flags for objects that pass each cut AND all the previous cuts
# Line 1738 | Line 3619 | void OSUAnalysis::setObjectFlags(cut &cu
3619  
3620   template <class InputCollection1, class InputCollection2>
3621   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
3622 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, string inputType){
3622 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
3623  
3624  
3625    bool sameObjects = false;
3626    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3627  
3628 <  int counter = 0;  
3628 >  // Get the strings for the two objects that make up the pair.
3629 >  string obj1Type, obj2Type;
3630 >  getTwoObjs(inputType, obj1Type, obj2Type);
3631 >  bool isTwoTypesOfObject = true;
3632 >  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
3633 >
3634 >  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
3635 >  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
3636 >  if (currentCut.inputCollection == inputType) {
3637 >    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
3638 >      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3639 >      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3640 >    }
3641 >    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
3642 >      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
3643 >        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3644 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3645 >      }
3646 >    }
3647 >  }
3648 >
3649 >  int counter = 0;
3650 >
3651    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3652      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3653 <      
3653 >
3654        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3655  
3656  
# Line 1755 | Line 3658 | void OSUAnalysis::setObjectFlags(cut &cu
3658  
3659        if(currentCut.inputCollection == inputType){
3660  
3661 <        vector<bool> subcutDecisions;
3662 <        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3663 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3664 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3665 <        }
3666 <
3667 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3668 <        else{
3669 <          bool tempDecision = true;
3670 <          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
3671 <            if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
3672 <              tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
3673 <            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
3674 <              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
3675 <          }
3676 <          decision = tempDecision;
3677 <        }
3661 >        vector<bool> subcutDecisions;
3662 >        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3663 >          string stringValue = "";
3664 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3665 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3666 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3667 >        }
3668 >
3669 >        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3670 >        else{
3671 >          bool tempDecision = subcutDecisions.at(0);
3672 >          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
3673 >            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
3674 >              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
3675 >            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
3676 >              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
3677 >          }
3678 >          decision = tempDecision;
3679 >        }
3680        }
3681 +      // if (decision) isPassObj1.at(object1) = true;
3682 +      // if (decision) isPassObj2.at(object2) = true;
3683        individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3684 <      
3684 >      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3685 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;
3686 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;
3687 >      }
3688 >
3689        //set flags for objects that pass each cut AND all the previous cuts
3690        bool previousCumulativeFlag = true;
3691        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3692 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
3693 <        else{ previousCumulativeFlag = false; break;}
3692 >        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
3693 >        else{ previousCumulativeFlag = false; break;}
3694 >      }
3695 >      //apply flags for the components of the composite object as well
3696 >      bool currentCumulativeFlag = true;
3697 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
3698 >      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
3699 >      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
3700 >      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
3701 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
3702 >      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3703 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);
3704 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);
3705        }
3706 <      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3706 >      counter++;
3707  
3708 <      counter++;      
3709 <    }
3710 <    
3711 <  }
3708 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
3709 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
3710 >
3711 > }
3712  
3713  
3714 + bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
3715 +  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
3716 +  // all cuts up to currentCutIndex
3717 +  bool previousCumulativeFlag = true;
3718 +  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
3719 +    if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
3720 +    else {
3721 +      previousCumulativeFlag = false; break;
3722 +    }
3723 +  }
3724 +  return previousCumulativeFlag;
3725   }
3726  
3727  
3728   template <class InputCollection>
3729 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
3729 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3730  
3731    for (uint object = 0; object != inputCollection->size(); object++){
3732  
# Line 1802 | Line 3735 | void OSUAnalysis::fill1DHistogram(TH1* h
3735      string currentString = parameters.inputVariables.at(0);
3736      string inputVariable = "";
3737      string function = "";
3738 <    if(currentString.find("(")==std::string::npos){
3739 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
3738 >    if(currentString.find("(")==string::npos){
3739 >      inputVariable = currentString;// variable to cut on
3740      }
3741      else{
3742 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
3743 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
3744 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
3742 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3743 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3744 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3745      }
3746  
3747 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
3748 <    histo->Fill(value,puScaleFactor);
3747 >    string stringValue = "";
3748 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3749 >    histo->Fill(value,scaleFactor);
3750 >    if (printEventInfo_) {
3751 >      // Write information about event to screen, for testing purposes.
3752 >      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
3753 >    }
3754  
3755    }
1818
3756   }
3757  
3758   template <class InputCollection1, class InputCollection2>
3759 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
3759 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3760  
3761    bool sameObjects = false;
3762    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3763  
3764 <  int counter = 0;  
3764 >  int pairCounter = -1;
3765    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3766      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3767 <      
3767 >
3768        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3769  
3770 +      pairCounter++;
3771        //only take objects which have passed all cuts and pairs which have passed all cuts
3772        if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3773        if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3774 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(counter)) continue;
3774 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3775  
3776        string currentString = parameters.inputVariables.at(0);
3777        string inputVariable = "";
3778        string function = "";
3779 <      if(currentString.find("(")==std::string::npos){
3780 <        inputVariable = currentString;// variable to cut on                                                                                                          
3779 >      if(currentString.find("(")==string::npos){
3780 >        inputVariable = currentString;// variable to cut on
3781        }
3782        else{
3783 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
3784 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
3785 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
3786 <      }
3787 <      
3788 <      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3789 <      histo->Fill(value,puScaleFactor);
3783 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3784 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3785 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3786 >      }
3787 >
3788 >      string stringValue = "";
3789 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3790 >      histo->Fill(value,scaleFactor);
3791  
1853      counter++;      
3792      }
3793    }
3794  
# Line 1858 | Line 3796 | void OSUAnalysis::fill1DHistogram(TH1* h
3796  
3797  
3798   template <class InputCollection>
3799 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
3799 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3800  
3801    for (uint object = 0; object != inputCollection->size(); object++){
3802  
3803      if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3804  
3805 +    string stringValue = "";
3806      string currentString = parameters.inputVariables.at(0);
3807      string inputVariable = "";
3808      string function = "";
3809 <    if(currentString.find("(")==std::string::npos){
3810 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
3809 >    if(currentString.find("(")==string::npos){
3810 >      inputVariable = currentString;// variable to cut on
3811      }
3812      else{
3813 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
3814 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
3815 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
3813 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3814 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3815 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3816      }
3817 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
3817 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3818  
3819      currentString = parameters.inputVariables.at(1);
3820      inputVariable = "";
3821      function = "";
3822 <    if(currentString.find("(")==std::string::npos){
3823 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
3822 >    if(currentString.find("(")==string::npos){
3823 >      inputVariable = currentString;// variable to cut on
3824      }
3825      else{
3826 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
3827 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
3828 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
3826 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3827 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3828 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3829      }
3830  
3831 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
3831 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3832  
3833 <    histo->Fill(valueX,valueY,puScaleFactor);
3833 >    histo->Fill(valueX,valueY,scaleFactor);
3834  
3835    }
3836  
3837   }
3838  
3839   template <class InputCollection1, class InputCollection2>
3840 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
3840 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3841  
3842    bool sameObjects = false;
3843    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3844  
3845 <  int counter = 0;  
3845 >  int pairCounter = -1;
3846    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3847      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3848 <      
3848 >
3849        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3850  
3851 +      pairCounter++;
3852 +
3853        //only take objects which have passed all cuts and pairs which have passed all cuts
3854        if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3855        if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3856 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(counter)) continue;
3856 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3857  
3858 +      string stringValue = "";
3859        string currentString = parameters.inputVariables.at(0);
3860        string inputVariable = "";
3861        string function = "";
3862 <      if(currentString.find("(")==std::string::npos){
3863 <        inputVariable = currentString;// variable to cut on                                                                                                          
3862 >      if(currentString.find("(")==string::npos){
3863 >        inputVariable = currentString;// variable to cut on
3864        }
3865        else{
3866 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
3867 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
3868 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
3866 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3867 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3868 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3869        }
3870 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3870 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3871  
3872        currentString = parameters.inputVariables.at(1);
3873        inputVariable = "";
3874        function = "";
3875 <      if(currentString.find("(")==std::string::npos){
3876 <        inputVariable = currentString;// variable to cut on                                                                                                          
3875 >      if(currentString.find("(")==string::npos){
3876 >        inputVariable = currentString;// variable to cut on
3877        }
3878        else{
3879 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
3880 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
3881 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
3879 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3880 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3881 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3882        }
3883 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3883 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3884  
3885  
3886 <      histo->Fill(valueX,valueY,puScaleFactor);
3886 >      histo->Fill(valueX,valueY,scaleFactor);
3887  
1946      counter++;      
3888      }
3889    }
3890  
3891   }
3892  
3893  
3894 + template <class InputObject>
3895 + int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
3896  
3897 < DEFINE_FWK_MODULE(OSUAnalysis);
3897 >  int bestMatchIndex = -1;
3898 >  double bestMatchDeltaR = 999;
3899 >
3900 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3901 >
3902 >    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
3903 >    if(currentDeltaR > 0.05) continue;
3904 >    //     cout << setprecision(3) << setw(20)
3905 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
3906 >    //          << setw(20)
3907 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
3908 >    //          << setw(20)
3909 >    //          << "\tdeltaR = " << currentDeltaR
3910 >    //          << setprecision(1)
3911 >    //          << setw(20)
3912 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
3913 >    //          << setw(20)
3914 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
3915 >    //          << setw(20)
3916 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
3917 >    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
3918 >      bestMatchIndex = mcparticle - mcparticles->begin();
3919 >      bestMatchDeltaR = currentDeltaR;
3920 >    }
3921 >
3922 >  }
3923 >  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
3924 >  //   else cout << "no match found..." << endl;
3925 >  return bestMatchIndex;
3926 >
3927 > }
3928 >
3929 >
3930 > int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
3931 >
3932 >  int bestMatchIndex = -1;
3933 >  double bestMatchDeltaR = 999;
3934 >
3935 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3936 >
3937 >    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
3938  
3939 +    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
3940 +    if(currentDeltaR > 0.05) continue;
3941  
3942 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
3943 +      bestMatchIndex = mcparticle - mcparticles->begin();
3944 +      bestMatchDeltaR = currentDeltaR;
3945 +    }
3946 +
3947 +  }
3948 +
3949 +  return bestMatchIndex;
3950 + }
3951 +
3952 +
3953 + // bin      particle type
3954 + // ---      -------------
3955 + //  0        unmatched
3956 + //  1        u
3957 + //  2        d
3958 + //  3        s
3959 + //  4        c
3960 + //  5        b
3961 + //  6        t
3962 + //  7        e
3963 + //  8        mu
3964 + //  9        tau
3965 + // 10        nu
3966 + // 11        g
3967 + // 12        gamma
3968 + // 13        Z
3969 + // 14        W
3970 + // 15        light meson
3971 + // 16        K meson
3972 + // 17        D meson
3973 + // 18        B meson
3974 + // 19        light baryon
3975 + // 20        strange baryon
3976 + // 21        charm baryon
3977 + // 22        bottom baryon
3978 + // 23        QCD string
3979 + // 24        other
3980 +
3981 + int OSUAnalysis::getPdgIdBinValue(int pdgId){
3982 +
3983 +  int binValue = -999;
3984 +  int absPdgId = fabs(pdgId);
3985 +  if(pdgId == -1) binValue = 0;
3986 +  else if(absPdgId <= 6 ) binValue = absPdgId;
3987 +  else if(absPdgId == 11 ) binValue = 7;
3988 +  else if(absPdgId == 13 ) binValue = 8;
3989 +  else if(absPdgId == 15 ) binValue = 9;
3990 +  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
3991 +  else if(absPdgId == 21 ) binValue = 11;
3992 +  else if(absPdgId == 22 ) binValue = 12;
3993 +  else if(absPdgId == 23 ) binValue = 13;
3994 +  else if(absPdgId == 24 ) binValue = 14;
3995 +  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
3996 +  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
3997 +  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
3998 +  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
3999 +  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
4000 +  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4001 +  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4002 +  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4003 +  else if(absPdgId == 92  ) binValue = 23;
4004 +
4005 +  else binValue = 24;
4006 +
4007 +  return binValue;
4008 +
4009 + }
4010 +
4011 + const BNprimaryvertex *
4012 + OSUAnalysis::chosenVertex ()
4013 + {
4014 +  const BNprimaryvertex *chosenVertex = 0;
4015 +  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4016 +    vector<bool> vertexFlags;
4017 +    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4018 +      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4019 +        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4020 +        break;
4021 +      }
4022 +    }
4023 +    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4024 +      if(!vertexFlags.at(vertexIndex)) continue;
4025 +      chosenVertex = & primaryvertexs->at(vertexIndex);
4026 +      break;
4027 +    }
4028 +  }
4029 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4030 +    chosenVertex = & primaryvertexs->at (0);
4031 +
4032 +  return chosenVertex;
4033 + }
4034 +
4035 + const BNmet *
4036 + OSUAnalysis::chosenMET ()
4037 + {
4038 +  const BNmet *chosenMET = 0;
4039 +  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4040 +    vector<bool> metFlags;
4041 +    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4042 +      if (cumulativeFlags.at("mets").at(i).size()){
4043 +        metFlags = cumulativeFlags.at("mets").at(i);
4044 +        break;
4045 +      }
4046 +    }
4047 +    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4048 +      if(!metFlags.at(metIndex)) continue;
4049 +      chosenMET = & mets->at(metIndex);
4050 +      break;
4051 +    }
4052 +  }
4053 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4054 +    chosenMET = & mets->at (0);
4055 +
4056 +  return chosenMET;
4057 + }
4058 +
4059 + const BNelectron *
4060 + OSUAnalysis::chosenElectron ()
4061 + {
4062 +  const BNelectron *chosenElectron = 0;
4063 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4064 +    vector<bool> electronFlags;
4065 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4066 +      if (cumulativeFlags.at("electrons").at(i).size()){
4067 +        electronFlags = cumulativeFlags.at("electrons").at(i);
4068 +        break;
4069 +      }
4070 +    }
4071 +    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4072 +      if(!electronFlags.at(electronIndex)) continue;
4073 +      chosenElectron = & electrons->at(electronIndex);
4074 +      break;
4075 +    }
4076 +  }
4077 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4078 +    chosenElectron = & electrons->at (0);
4079 +
4080 +  return chosenElectron;
4081 + }
4082 +
4083 + const BNmuon *
4084 + OSUAnalysis::chosenMuon ()
4085 + {
4086 +  const BNmuon *chosenMuon = 0;
4087 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4088 +    vector<bool> muonFlags;
4089 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4090 +      if (cumulativeFlags.at("muons").at(i).size()){
4091 +        muonFlags = cumulativeFlags.at("muons").at(i);
4092 +        break;
4093 +      }
4094 +    }
4095 +    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4096 +      if(!muonFlags.at(muonIndex)) continue;
4097 +      chosenMuon = & muons->at(muonIndex);
4098 +      break;
4099 +    }
4100 +  }
4101 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4102 +    chosenMuon = & muons->at (0);
4103 +
4104 +  return chosenMuon;
4105 + }
4106 +
4107 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines