ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
(Generate patch)

Comparing UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc (file contents):
Revision 1.18 by lantonel, Fri Feb 22 10:38:08 2013 UTC vs.
Revision 1.72 by lantonel, Wed May 29 20:15:01 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines