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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines