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.28 by jbrinson, Thu Mar 14 10:06:38 2013 UTC vs.
Revision 1.68 by ahart, Wed May 29 01:06:36 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines