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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines