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

Comparing UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc (file contents):
Revision 1.18 by lantonel, Fri Feb 22 10:38:08 2013 UTC vs.
Revision 1.100 by ahart, Tue Jul 16 19:48:04 2013 UTC

# Line 1 | Line 1
1   #include "OSUT3Analysis/AnaTools/plugins/OSUAnalysis.h"
2
2   OSUAnalysis::OSUAnalysis (const edm::ParameterSet &cfg) :
3    // Retrieve parameters from the configuration file.
4    jets_ (cfg.getParameter<edm::InputTag> ("jets")),
# Line 11 | Line 10 | OSUAnalysis::OSUAnalysis (const edm::Par
10    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
11    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
12    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
13 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
14    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
15    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
16    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
17    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
18    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
19 <  puFile_ (cfg.getParameter<std::string> ("puFile")),
20 <  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
21 <  dataset_ (cfg.getParameter<std::string> ("dataset")),
22 <  datasetType_ (cfg.getParameter<std::string> ("datasetType")),
19 >  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
20 >  puFile_ (cfg.getParameter<string> ("puFile")),
21 >  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
22 >  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
23 >  dataPU_ (cfg.getParameter<string> ("dataPU")),
24 >  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
25 >  muonSF_ (cfg.getParameter<string> ("muonSF")),
26 >  dataset_ (cfg.getParameter<string> ("dataset")),
27 >  datasetType_ (cfg.getParameter<string> ("datasetType")),
28    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
29    histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
30 <  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents"))
31 <
32 < {
30 >  useEDMFormat_   (cfg.getParameter<bool>("useEDMFormat")),
31 >  treeBranchSets_   (cfg.getParameter<vector<edm::ParameterSet> >("treeBranchSets")),
32 >  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
33 >  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
34 >  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
35 >  applyBtagSF_ (cfg.getParameter<bool> ("applyBtagSF")),
36 >  minBtag_ (cfg.getParameter<int> ("minBtag")),
37 >  printEventInfo_      (cfg.getParameter<bool> ("printEventInfo")),
38 >  printAllTriggers_    (cfg.getParameter<bool> ("printAllTriggers")),
39 >  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
40 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
41 >  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
42 > {
43  
44    TH1::SetDefaultSumw2 ();
45  
46    //create pile-up reweighting object, if necessary
47 <  if(datasetType_ != "data") puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
47 >  if(datasetType_ != "data") {
48 >    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
49 >    if (applyLeptonSF_){
50 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
51 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
52 >    }
53 >    if (applyBtagSF_){
54 >      bTagSFWeight_ = new BtagSFWeight;
55 >    }
56 >  }
57 >  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
58 >    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
59 >
60  
61    // Construct Cutflow Objects. These store the results of cut decisions and
62    // handle filling cut flow histograms.
63    masterCutFlow_ = new CutFlow (fs_);
37  std::vector<TFileDirectory> directories;
64  
65    //always get vertex collection so we can assign the primary vertex in the event
66 <  allNecessaryObjects.push_back("primaryvertexs");
41 <  //always make the plot of number of primary verticex (to check pile-up reweighting)
66 >  objectsToGet.push_back("primaryvertexs");
67    objectsToPlot.push_back("primaryvertexs");
68 +  objectsToFlag.push_back("primaryvertexs");
69 +
70 +
71 +  //always get the MC particles to do GEN-matching
72 +  objectsToGet.push_back("mcparticles");
73  
74    //always get the event collection to do pile-up reweighting
75 <  allNecessaryObjects.push_back("events");
75 >  objectsToGet.push_back("events");
76 >
77 >
78 >  // Parse the tree variable definitions.
79 >  for (uint iBranchSet = 0; !useEDMFormat_ && iBranchSet<treeBranchSets_.size(); iBranchSet++) {
80 >    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
81 >    if(tempInputCollection.find("pairs")!=string::npos) { clog << "Warning:  tree filling is not configured for pairs of objects, so will not work for collection: " << tempInputCollection << endl; }
82 >    objectsToGet.push_back(tempInputCollection);
83 >    objectsToFlag.push_back(tempInputCollection);
84 >
85 >    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
86 >
87 >    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
88 >      BranchSpecs br;
89 >      br.inputCollection = tempInputCollection;
90 >      br.inputVariable = branchList.at(iBranch);
91 >      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);
92 >      br.name = string(newName.Data());
93 >      treeBranches_.push_back(br);
94 >    }
95 >
96 >  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++)
97 >
98  
99    //parse the histogram definitions
100    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
101  
102      string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
103      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
104 <    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
104 >    if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
105 >    if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
106 >    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
107 >    if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
108 >    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
109 >    if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
110 >    if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
111 >    if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
112 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
113 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
114 >    if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
115 >    if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
116 >    if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
117 >    if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
118 >    if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
119 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
120 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
121 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
122 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
123 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
124 >        int spaceIndex = tempInputCollection.find(" ");
125 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
126 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
127 >      }
128 >      else{
129 >        objectsToGet.push_back(tempInputCollection);
130 >      }
131        objectsToPlot.push_back(tempInputCollection);
132 <      allNecessaryObjects.push_back(tempInputCollection);
133 <    }
134 <    else{//pair of objects, need to add them both to the things to allNecessaryObjects
135 <      int dashIndex = tempInputCollection.find("-");
136 <      int spaceIndex = tempInputCollection.find(" ");
137 <      int secondWordLength = spaceIndex - dashIndex;
138 <      allNecessaryObjects.push_back(tempInputCollection);
139 <      allNecessaryObjects.push_back(tempInputCollection.substr(0,dashIndex)+"s");
140 <      allNecessaryObjects.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
132 >      objectsToFlag.push_back(tempInputCollection);
133 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
134 >      string obj1;
135 >      string obj2;
136 >      getTwoObjs(tempInputCollection, obj1, obj2);
137 >      string obj2ToGet = getObjToGet(obj2);
138 >      objectsToFlag.push_back(tempInputCollection);
139 >      objectsToFlag.push_back(obj1);
140 >      objectsToFlag.push_back(obj2);
141        objectsToPlot.push_back(tempInputCollection);
142 <      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
143 <      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
144 <      }
142 >      objectsToPlot.push_back(obj1);
143 >      objectsToPlot.push_back(obj2);
144 >      objectsToGet.push_back(tempInputCollection);
145 >      objectsToGet.push_back(obj1);
146 >      objectsToGet.push_back(obj2ToGet);
147 >    } // end else
148 >      if (find(objectsToPlot.begin(), objectsToPlot.end(), "events") != objectsToPlot.end())
149 >        objectsToGet.push_back("jets");
150 >
151  
152      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
153 <    
153 >
154      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
155  
156 +      vector<double> defaultValue;
157 +      defaultValue.push_back (-1.0);
158 +
159        histogram tempHistogram;
160        tempHistogram.inputCollection = tempInputCollection;
161        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
162        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
163 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
163 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
164 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
165 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
166        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
167 <      
167 >
168        histograms.push_back(tempHistogram);
169  
170      }
171 <  }
172 <  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object
171 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
172 >
173 >  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
174    sort( objectsToPlot.begin(), objectsToPlot.end() );
175    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
176  
177  
178  
179 +  //add histograms with the gen-matched id, mother id, and grandmother id
180 +  for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
181 +
182 +    string currentObject = objectsToPlot.at(currentObjectIndex);
183 +    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "secondary photons"&& currentObject != "superclusters") continue;
184 +
185 +    histogram tempIdHisto;
186 +    histogram tempMomIdHisto;
187 +    histogram tempGmaIdHisto;
188 +    histogram tempIdVsMomIdHisto;
189 +    histogram tempIdVsGmaIdHisto;
190 +
191 +    tempIdHisto.inputCollection = currentObject;
192 +    tempMomIdHisto.inputCollection = currentObject;
193 +    tempGmaIdHisto.inputCollection = currentObject;
194 +    tempIdVsMomIdHisto.inputCollection = currentObject;
195 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
196 +
197 +    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
198 +    if(currentObject == "secondary photons") currentObject = "secondaryPhotons";
199 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
200 +
201 +    currentObject = currentObject.substr(0, currentObject.size()-1);
202 +    tempIdHisto.name = currentObject+"GenMatchId";
203 +    tempMomIdHisto.name = currentObject+"GenMatchMotherId";
204 +    tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
205 +    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
206 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
207 +
208 +    currentObject.at(0) = toupper(currentObject.at(0));
209 +    tempIdHisto.title = currentObject+" Gen-matched Particle";
210 +    tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
211 +    tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
212 +    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
213 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
214 +
215 +
216 +    int maxNum = 25;
217 +    vector<double> binVector;
218 +    binVector.push_back(maxNum);
219 +    binVector.push_back(0);
220 +    binVector.push_back(maxNum);
221 +
222 +    tempIdHisto.bins = binVector;
223 +    tempIdHisto.inputVariables.push_back("genMatchedId");
224 +    tempMomIdHisto.bins = binVector;
225 +    tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
226 +    tempGmaIdHisto.bins = binVector;
227 +    tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
228 +    binVector.push_back(maxNum);
229 +    binVector.push_back(0);
230 +    binVector.push_back(maxNum);
231 +    tempIdVsMomIdHisto.bins = binVector;
232 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
233 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
234 +    tempIdVsGmaIdHisto.bins = binVector;
235 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
236 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
237 +
238 +    histograms.push_back(tempIdHisto);
239 +    histograms.push_back(tempMomIdHisto);
240 +    histograms.push_back(tempGmaIdHisto);
241 +    histograms.push_back(tempIdVsMomIdHisto);
242 +    histograms.push_back(tempIdVsGmaIdHisto);
243 +  }
244 +
245  
246    channel tempChannel;
247    //loop over all channels (event selections)
# Line 99 | Line 255 | OSUAnalysis::OSUAnalysis (const edm::Par
255      //set triggers for this channel
256      vector<string> triggerNames;
257      triggerNames.clear();
258 +    vector<string> triggerToVetoNames;
259 +    triggerToVetoNames.clear();
260 +
261      tempChannel.triggers.clear();
262 +    tempChannel.triggersToVeto.clear();
263      if(channels_.at(currentChannel).exists("triggers")){
264        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
265        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
266          tempChannel.triggers.push_back(triggerNames.at(trigger));
267 <      allNecessaryObjects.push_back("triggers");
267 >      objectsToGet.push_back("triggers");
268 >    }
269 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
270 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
271 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
272 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
273 >      objectsToGet.push_back("triggers");
274      }
109
275  
276  
277  
278      //create cutFlow for this channel
279      cutFlows_.push_back (new CutFlow (fs_, channelName));
280 <
281 <    //book a directory in the output file with the name of the channel
282 <    TFileDirectory subDir = fs_->mkdir( channelName );
118 <    directories.push_back(subDir);
119 <
120 <    std::map<std::string, TH1D*> oneDhistoMap;
121 <    oneDHists_.push_back(oneDhistoMap);
122 <    std::map<std::string, TH2D*> twoDhistoMap;
123 <    twoDHists_.push_back(twoDhistoMap);
124 <
125 <
126 <    //book all histograms included in the configuration
127 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
128 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
129 <      int numBinsElements = currentHistogram.bins.size();
130 <      int numInputVariables = currentHistogram.inputVariables.size();
131 <
132 <      if(numBinsElements != 3 && numBinsElements !=6) {
133 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
134 <        exit(0);
135 <      }
136 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
137 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
138 <        exit(0);
139 <      }
140 <      else if(numBinsElements == 3){
141 <        oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
142 <      }
143 <      else if(numBinsElements == 6){
144 <        twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2),currentHistogram.bins.at(3),currentHistogram.bins.at(4),currentHistogram.bins.at(5));
145 <
146 <      }
147 <
148 <
149 <    }
150 <    //book a histogram for the number of each object type to be plotted
151 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
152 <      string currentObject = objectsToPlot.at(currentObjectIndex);
153 <      int maxNum = 10;
154 <      if(currentObject == "mcparticles") maxNum = 50;
155 <      else if(currentObject == "primaryvertexs") maxNum = 50;
156 <      else if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
157 <      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
158 <      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
159 <
160 <      currentObject.at(0) = toupper(currentObject.at(0));
161 <      string histoName = "num" + currentObject;
162 <
163 <      if(histoName == "numPrimaryvertexs"){
164 <        string newHistoName = histoName + "BeforePileupCorrection";
165 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);    
166 <        newHistoName = histoName + "AfterPileupCorrection";
167 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
168 <      }
169 <      else
170 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
171 <    }
172 <
173 <
280 >    vector<TFileDirectory> directories; //vector of directories in the output file.
281 >    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
282 >    vector<string> subSubDirNames;//subdirectories in each channel.
283      //get list of cuts for this channel
284      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
285  
286 +
287      //loop over and parse all cuts
288      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
289        cut tempCut;
290        //store input collection for cut
291        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
292 +      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
293 +      if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
294 +      if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
295 +      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
296 +      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
297 +      if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
298 +      if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
299 +      if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
300 +      if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
301 +      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
302 +      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
303 +      if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
304 +      if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
305 +      if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
306 +      if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
307 +      if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
308 +      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
309 +      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
310 +      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
311        tempCut.inputCollection = tempInputCollection;
312 <      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
313 <        allNecessaryObjects.push_back(tempInputCollection);
312 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
313 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
314 >          int spaceIndex = tempInputCollection.find(" ");
315 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
316 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
317 >        }
318 >        else{
319 >          objectsToGet.push_back(tempInputCollection);
320 >        }
321 >        objectsToCut.push_back(tempInputCollection);
322 >        objectsToFlag.push_back(tempInputCollection);
323        }
324 <      else{//pair of objects, need to add them both to the things to allNecessaryObjects
325 <        int dashIndex = tempInputCollection.find("-");
326 <        int spaceIndex = tempInputCollection.find(" ");
327 <        int secondWordLength = spaceIndex - dashIndex;
328 <        allNecessaryObjects.push_back(tempInputCollection);
329 <        allNecessaryObjects.push_back(tempInputCollection.substr(0,dashIndex)+"s");
330 <        allNecessaryObjects.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
324 >      else{//pair of objects, need to add them both to objectsToGet
325 >        string obj1;
326 >        string obj2;
327 >        getTwoObjs(tempInputCollection, obj1, obj2);
328 >        string obj2ToGet = getObjToGet(obj2);
329 >        objectsToCut.push_back(tempInputCollection);
330 >        objectsToCut.push_back(obj1);
331 >        objectsToCut.push_back(obj2);
332 >        objectsToFlag.push_back(tempInputCollection);
333 >        objectsToFlag.push_back(obj1);
334 >        objectsToFlag.push_back(obj2);
335 >        objectsToGet.push_back(tempInputCollection);
336 >        objectsToGet.push_back(obj1);
337 >        objectsToGet.push_back(obj2ToGet);
338  
339        }
340  
# Line 197 | Line 342 | OSUAnalysis::OSUAnalysis (const edm::Par
342  
343        //split cut string into parts and store them
344        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
345 <      std::vector<string> cutStringVector = splitString(cutString);
345 >      vector<string> cutStringVector = splitString(cutString);
346        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
347 <        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
348 <        exit(0);
347 >        clog << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
348 >        exit(0);
349        }
350        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
351        for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
352 <        int indexOffset = 4 * subcutIndex;
353 <        string currentVariableString = cutStringVector.at(indexOffset);
354 <        if(currentVariableString.find("(")==std::string::npos){
355 <          tempCut.functions.push_back("");//no function was specified
356 <          tempCut.variables.push_back(currentVariableString);// variable to cut on
357 <        }
358 <        else{
359 <          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
360 <          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
361 <          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
362 <        }
363 <        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
364 <        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
365 <        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
352 >        int indexOffset = 4 * subcutIndex;
353 >        string currentVariableString = cutStringVector.at(indexOffset);
354 >        if(currentVariableString.find("(")==string::npos){
355 >          tempCut.functions.push_back("");//no function was specified
356 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
357 >        }
358 >        else{
359 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
360 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
361 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
362 >        }
363 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
364 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
365 >        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
366 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
367        }
368  
369        //get number of objects required to pass cut for event to pass
370        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
371 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
371 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
372        if(numberRequiredVector.size()!=2){
373 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
373 >        clog << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
374          exit(0);
375        }
376  
# Line 232 | Line 378 | OSUAnalysis::OSUAnalysis (const edm::Par
378        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
379        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
380  
381 <
381 >      //Set up vectors to store the directories and subDirectories for each channel.
382 >      string subSubDirName;
383        string tempCutName;
384        if(cuts_.at(currentCut).exists("alias")){
385          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
386 +        subSubDirName = "After " + tempCutName + " Cut Applied";
387        }
388        else{
389          //construct string for cutflow table
# Line 243 | Line 391 | OSUAnalysis::OSUAnalysis (const edm::Par
391          string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
392          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
393          tempCutName = cutName;
394 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
395        }
247      tempCut.name = tempCutName;
396  
397 +      tempCut.isVeto = false;
398 +      if(cuts_.at(currentCut).exists("isVeto")){
399 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
400 +        if (isVeto == true) tempCut.isVeto = true;
401 +      }
402 +      subSubDirNames.push_back(subSubDirName);
403 +      tempCut.name = tempCutName;
404  
405        tempChannel.cuts.push_back(tempCut);
406  
407  
253
408      }//end loop over cuts
409  
410 +    vector<map<string, TH1D*>> oneDHistsTmp;
411 +    vector<map<string, TH2D*>> twoDHistsTmp;
412 +    //book a directory in the output file with the name of the channel
413 +    TFileDirectory subDir = fs_->mkdir( channelName );
414 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
415 +    if(GetPlotsAfterEachCut_){
416 +      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
417 +        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
418 +        directories.push_back(subSubDir);
419 +        map<string, TH1D*> oneDhistoMap;
420 +        oneDHistsTmp.push_back(oneDhistoMap);
421 +        map<string, TH2D*> twoDhistoMap;
422 +        twoDHistsTmp.push_back(twoDhistoMap);
423 +      }
424 +      treeDirectories.push_back(subDir);
425 +      oneDHists_.push_back(oneDHistsTmp);
426 +      twoDHists_.push_back(twoDHistsTmp);
427 +    }
428 +    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
429 +    else{
430 +      map<string, TH1D*> oneDhistoMap;
431 +      oneDHistsTmp.push_back(oneDhistoMap);
432 +      map<string, TH2D*> twoDhistoMap;
433 +      twoDHistsTmp.push_back(twoDhistoMap);
434 +      oneDHists_.push_back(oneDHistsTmp);
435 +      twoDHists_.push_back(twoDHistsTmp);
436 +      directories.push_back(subDir);
437 +      treeDirectories.push_back(subDir);
438 +
439 +    }
440 +
441 +    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
442 +      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
443 +      BNTrees_.push_back(newTree);
444 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
445 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
446 +        vector<float> newVec;
447 +        BNTreeBranchVals_[currentVar.name] = newVec;
448 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
449 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
450 +    }
451 +
452 +    //book all histograms included in the configuration
453 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
454 +
455 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
456 +
457 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
458 +        int numBinsElements = currentHistogram.bins.size();
459 +        int numInputVariables = currentHistogram.inputVariables.size();
460 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
461 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
462 +
463 +        if(numBinsElements == 1){
464 +          if(numBinEdgesX > 1){
465 +            if(numBinEdgesY > 1)
466 +              numBinsElements = 6;
467 +            else
468 +              numBinsElements = 3;
469 +          }
470 +        }
471 +        if(numBinsElements != 3 && numBinsElements !=6){
472 +          clog << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
473 +          exit(0);
474 +        }
475 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
476 +          clog << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
477 +          exit(0);
478 +        }
479 +        else if(numBinsElements == 3){
480 +          if (currentHistogram.bins.size () == 3)
481 +            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));
482 +          else
483 +            {
484 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
485 +            }
486 +        }
487 +        else if(numBinsElements == 6){
488 +          if (currentHistogram.bins.size () == 6)
489 +            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));
490 +          else
491 +            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 ());
492 +        }
493 +
494 +
495 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
496 +
497 +        // bin      particle type
498 +        // ---      -------------
499 +        //  0        unmatched
500 +        //  1        u
501 +        //  2        d
502 +        //  3        s
503 +        //  4        c
504 +        //  5        b
505 +        //  6        t
506 +        //  7        e
507 +        //  8        mu
508 +        //  9        tau
509 +        // 10        nu
510 +        // 11        g
511 +        // 12        gamma
512 +        // 13        Z
513 +        // 14        W
514 +        // 15        light meson
515 +        // 16        K meson
516 +        // 17        D meson
517 +        // 18        B meson
518 +        // 19        light baryon
519 +        // 20        strange baryon
520 +        // 21        charm baryon
521 +        // 22        bottom baryon
522 +        // 23        QCD string
523 +        // 24        other
524 +
525 +        vector<TString> labelArray;
526 +        labelArray.push_back("unmatched");
527 +        labelArray.push_back("u");
528 +        labelArray.push_back("d");
529 +        labelArray.push_back("s");
530 +        labelArray.push_back("c");
531 +        labelArray.push_back("b");
532 +        labelArray.push_back("t");
533 +        labelArray.push_back("e");
534 +        labelArray.push_back("#mu");
535 +        labelArray.push_back("#tau");
536 +        labelArray.push_back("#nu");
537 +        labelArray.push_back("g");
538 +        labelArray.push_back("#gamma");
539 +        labelArray.push_back("Z");
540 +        labelArray.push_back("W");
541 +        labelArray.push_back("light meson");
542 +        labelArray.push_back("K meson");
543 +        labelArray.push_back("D meson");
544 +        labelArray.push_back("B meson");
545 +        labelArray.push_back("light baryon");
546 +        labelArray.push_back("strange baryon");
547 +        labelArray.push_back("charm baryon");
548 +        labelArray.push_back("bottom baryon");
549 +        labelArray.push_back("QCD string");
550 +        labelArray.push_back("other");
551 +
552 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
553 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
554 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
555 +          }
556 +          else {
557 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
558 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
559 +          }
560 +        }
561 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
562 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
563 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
564 +        }
565 +
566 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
567 +
568 +
569 +      // Book a histogram for the number of each object type to be plotted.
570 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
571 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
572 +        string currentObject = objectsToPlot.at(currentObjectIndex);
573 +        int maxNum = 10;
574 +        if(currentObject == "mcparticles") maxNum = 50;
575 +        else if(currentObject == "primaryvertexs") maxNum = 50;
576 +
577 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
578 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
579 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
580 +        else if(currentObject == "electron-photon pairs")     currentObject = "electronPhotonPairs";
581 +        else if(currentObject == "muon-photon pairs")         currentObject = "muonPhotonPairs";
582 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
583 +        else if(currentObject == "secondary photons")            currentObject = "secondaryPhotons";
584 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
585 +        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
586 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
587 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
588 +        else if(currentObject == "muon-event pairs")            currentObject = "muonEventPairs";
589 +        else if(currentObject == "photon-jet pairs")            currentObject = "photonJetPairs";
590 +        else if(currentObject == "met-jet pairs")             currentObject = "metJetPairs";
591 +        else if(currentObject == "track-jet pairs")           currentObject = "trackJetPairs";
592 +        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
593 +        else if(currentObject == "muon-secondary photon pairs")  currentObject = "muonSecondaryPhotonPairs";
594 +        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
595 +        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
596 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
597 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
598 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
599 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
600 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
601 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
602 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
603 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
604 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
605 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
606 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
607 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
608 +
609 +        currentObject.at(0) = toupper(currentObject.at(0));
610 +        string histoName = "num" + currentObject;
611 +
612 +        if(histoName == "numPrimaryvertexs"){
613 +          string newHistoName = histoName + "BeforePileupCorrection";
614 +          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);
615 +          newHistoName = histoName + "AfterPileupCorrection";
616 +          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);
617 +        }
618 +        else
619 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
620 +      }
621 +    }//end of loop over directories
622      channels.push_back(tempChannel);
623      tempChannel.cuts.clear();
258
624    }//end loop over channels
625  
626  
627 <  //make unique vector of objects we need to cut on (so we make sure to get them from the event)
628 <  sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
629 <  allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
627 >  //make unique vector of objects we need to get from the event
628 >  sort( objectsToGet.begin(), objectsToGet.end() );
629 >  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
630 >  //make unique vector of objects we need to cut on
631 >  sort( objectsToCut.begin(), objectsToCut.end() );
632 >  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
633 >  //make unique vector of objects we need to set flags for
634 >  sort( objectsToFlag.begin(), objectsToFlag.end() );
635 >  objectsToFlag.erase( unique( objectsToFlag.begin(), objectsToFlag.end() ), objectsToFlag.end() );
636  
637 +  produces<map<string, bool> > ("channelDecisions");
638 +
639 + } // end constructor OSUAnalysis::OSUAnalysis()
640  
267 }
641  
642   OSUAnalysis::~OSUAnalysis ()
643   {
644 +
645    // Destroying the CutFlow objects causes the cut flow numbers and time
646    // information to be printed to standard output.
647    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
648      delete cutFlows_.at(currentChannel);
649    }
650 +
651 +  clog << "=============================================" << endl;  
652 +  clog << "Successfully completed OSUAnalysis." << endl;  
653 +  clog << "=============================================" << endl;  
654 +
655   }
656  
657   void
658 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
658 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
659   {
281
282
660    // Retrieve necessary collections from the event.
661 <  edm::Handle<BNtriggerCollection> triggers;
662 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
661 >
662 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
663      event.getByLabel (triggers_, triggers);
664  
665 <  edm::Handle<BNjetCollection> jets;
666 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())
665 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
666 >    event.getByLabel (trigobjs_, trigobjs);
667 >
668 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
669      event.getByLabel (jets_, jets);
670  
671 <  edm::Handle<BNmuonCollection> muons;
293 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())
671 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
672      event.getByLabel (muons_, muons);
673  
674 <  edm::Handle<BNelectronCollection> electrons;
297 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())
674 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
675      event.getByLabel (electrons_, electrons);
676  
677 <  edm::Handle<BNeventCollection> events;
301 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())
677 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
678      event.getByLabel (events_, events);
679  
680 <  edm::Handle<BNtauCollection> taus;
305 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())
680 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
681      event.getByLabel (taus_, taus);
682  
683 <  edm::Handle<BNmetCollection> mets;
309 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())
683 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
684      event.getByLabel (mets_, mets);
685  
686 <  edm::Handle<BNtrackCollection> tracks;
313 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())
686 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
687      event.getByLabel (tracks_, tracks);
688  
689 <  edm::Handle<BNgenjetCollection> genjets;
317 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())
689 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
690      event.getByLabel (genjets_, genjets);
691  
692 <  edm::Handle<BNmcparticleCollection> mcparticles;
321 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())
692 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
693      event.getByLabel (mcparticles_, mcparticles);
694  
695 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
325 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())
695 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
696      event.getByLabel (primaryvertexs_, primaryvertexs);
697  
698 <  edm::Handle<BNbxlumiCollection> bxlumis;
329 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())
698 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
699      event.getByLabel (bxlumis_, bxlumis);
700  
701 <  edm::Handle<BNphotonCollection> photons;
333 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())
701 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
702      event.getByLabel (photons_, photons);
703  
704 <  edm::Handle<BNsuperclusterCollection> superclusters;
337 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())
704 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
705      event.getByLabel (superclusters_, superclusters);
706  
707 +  if (datasetType_ == "signalMC"){
708 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
709 +      event.getByLabel (stops_, stops);
710 +  }
711 +
712 +  if (useTrackCaloRhoCorr_) {
713 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
714 +    // This rho collection is not available in all BEANs.
715 +    // For description of rho values for different jet reconstruction algorithms, see
716 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
717 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
718 +  }
719 +
720 +  double masterScaleFactor = 1.0;
721  
722    //get pile-up event weight
723 <  double puScaleFactor = 0;
724 <  if(datasetType_ != "data")
725 <    puScaleFactor = puWeight_->at (events->at (0).numTruePV);
726 <  else
727 <    puScaleFactor = 1.00;
723 >  if (doPileupReweighting_ && datasetType_ != "data") {
724 >    //for "data" datasets, the numTruePV is always set to -1
725 >    if (events->at(0).numTruePV < 0) clog << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
726 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
727 >  }
728  
729 +  stopCTauScaleFactor_ = 1.0;
730 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
731 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
732 +  masterScaleFactor *= stopCTauScaleFactor_;
733  
734    //loop over all channels
735  
736 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
737    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
738      channel currentChannel = channels.at(currentChannelIndex);
739  
740      flagMap individualFlags;
355    flagMap cumulativeFlags;
741      counterMap passingCounter;
742 +    cumulativeFlags.clear ();
743 +
744 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
745 +         iter != BNTreeBranchVals_.end(); iter++) {
746 +      iter->second.clear();  // clear array
747 +    }
748  
749      bool triggerDecision = true;
750 <    if(currentChannel.triggers.size() != 0){  //triggers specified
751 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
750 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
751 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
752        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
753      }
754  
# Line 365 | Line 756 | OSUAnalysis::analyze (const edm::Event &
756      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
757        cut currentCut = currentChannel.cuts.at(currentCutIndex);
758  
759 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
760 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
759 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
760 >        string currentObject = objectsToFlag.at(currentObjectIndex);
761  
762 <        individualFlags[currentObject].push_back (vector<bool> ());
763 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
762 >        //initialize maps to get ready to set cuts
763 >        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
764 >        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
765 >
766 >      }
767  
768 +      //set flags for all relevant objects
769 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
770 +        string currentObject = objectsToFlag.at(currentObjectIndex);
771 +
772 +        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
773  
774 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
775 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
774 >
775 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
776 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
777 >        else if(currentObject == "secondary photons")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"secondary photons");
778 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
779 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
780 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
781          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
782          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
783          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 385 | Line 789 | OSUAnalysis::analyze (const edm::Event &
789          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
790          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
791          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
792 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
793  
389        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(),"muon-muon pairs");
390        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(),"electron-electron pairs");
391        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(),"electron-muon pairs");
392
393      }
794  
795  
796 +        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
797 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
798 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
799 +                                                                   "muon-muon pairs");
800 +
801 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
802 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
803 +                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
804 +                                                                             "muon-secondary muon pairs");
805 +
806 +        else if(currentObject == "muon-secondary photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
807 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
808 +                                                                             cumulativeFlags.at("secondary photons").at(flagsForPairCutsIndex), \
809 +                                                                             "muon-secondary photon pairs");
810 +        else if(currentObject == "muon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
811 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
812 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
813 +                                                                             "muon-secondary jet pairs");
814 +        else if(currentObject == "photon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
815 +                                                                             cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
816 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
817 +                                                                             "photon-secondary jet pairs");
818 +
819 +        else if(currentObject == "electron-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
820 +                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
821 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
822 +                                                                             "electron-secondary jet pairs");
823 +
824 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
825 +                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
826 +                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
827 +                                                                                     "electron-secondary electron pairs");
828 +
829 +        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
830 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
831 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
832 +                                                                           "electron-electron pairs");
833 +        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
834 +                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
835 +                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
836 +                                                                       "electron-muon pairs");
837 +        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
838 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
839 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
840 +                                                                 "jet-jet pairs");
841 +        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
842 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
843 +                                                                 cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex),\
844 +                                                                 "jet-secondary jet pairs");
845 +        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
846 +                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
847 +                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
848 +                                                                      "electron-jet pairs");
849 +        else if(currentObject == "electron-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), \
850 +                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
851 +                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
852 +                                                                      "electron-photon pairs");
853 +        else if(currentObject == "photon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
854 +                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
855 +                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
856 +                                                                      "photon-jet pairs");
857 +        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
858 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
859 +                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
860 +                                                                  "muon-jet pairs");
861 +        else if(currentObject == "muon-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),events.product(), \
862 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
863 +                                                                  cumulativeFlags.at("events").at(flagsForPairCutsIndex), \
864 +                                                                  "muon-event pairs");
865 +        else if(currentObject == "met-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),jets.product(), \
866 +                                                                  cumulativeFlags.at("mets").at(flagsForPairCutsIndex), \
867 +                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
868 +                                                                  "met-jet pairs");
869 +        else if(currentObject == "track-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),jets.product(), \
870 +                                                                 cumulativeFlags.at("tracks").at(flagsForPairCutsIndex), \
871 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
872 +                                                                 "track-jet pairs");
873 +        else if(currentObject == "muon-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
874 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
875 +                                                                  cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
876 +                                                                  "muon-photon pairs");
877 +        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
878 +                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
879 +                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
880 +                                                                     "track-event pairs");
881 +        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
882 +                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
883 +                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
884 +                                                                        "electron-track pairs");
885 +        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
886 +                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
887 +                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
888 +                                                                    "muon-track pairs");
889 +        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
890 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
891 +                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
892 +                                                                  "muon-tau pairs");
893 +        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
894 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
895 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
896 +                                                                 "tau-tau pairs");
897 +        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
898 +                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
899 +                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
900 +                                                                   "tau-track pairs");
901 +        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
902 +                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
903 +                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
904 +                                                                          "electron-trigobj pairs");
905 +        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
906 +                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
907 +                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
908 +                                                                      "muon-trigobj pairs");
909  
910 <    }//end loop over all cuts
910 >        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
911 >      }
912  
913  
914  
915 +    }//end loop over all cuts
916      //use cumulative flags to apply cuts at event level
917  
918 +    //a vector to store cumulative cut descisions after each cut.
919 +    vector<bool> eventPassedPreviousCuts;
920      bool eventPassedAllCuts = true;
404
921      //apply trigger (true if none were specified)
922      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
923  
408
924      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
925  
926        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 413 | Line 928 | OSUAnalysis::analyze (const edm::Event &
928        int numberPassing = 0;
929  
930        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
931 <          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
931 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
932        }
418
933        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
934        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
421
935        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
936 <
936 >      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
937 >    }
938 >    //applying all appropriate scale factors
939 >    double scaleFactor = masterScaleFactor;
940 >    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
941 >
942 >    if(applyLeptonSF_ && datasetType_ != "data"){
943 >      //only apply SFs if we've cut on this object
944 >      if(find(objectsToCut.begin(),objectsToCut.end(),"muons") != objectsToCut.end ()){
945 >        flagPair muonFlags;
946 >        //get the last valid flags in the flag map
947 >        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
948 >          if (cumulativeFlags.at("muons").at(i).size()){
949 >            muonFlags = cumulativeFlags.at("muons").at(i);
950 >            break;
951 >          }
952 >        }
953 >        //apply the weight for each of those objects
954 >        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
955 >          if(!muonFlags.at(muonIndex).second) continue;
956 >          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
957 >        }
958 >      }
959 >      //only apply SFs if we've cut on this object
960 >      if(find(objectsToCut.begin(),objectsToCut.end(),"electrons") != objectsToCut.end ()){
961 >        flagPair electronFlags;
962 >        //get the last valid flags in the flag map
963 >        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
964 >          if (cumulativeFlags.at("electrons").at(i).size()){
965 >            electronFlags = cumulativeFlags.at("electrons").at(i);
966 >            break;
967 >          }
968 >        }
969 >        //apply the weight for each of those objects
970 >        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
971 >          if(!electronFlags.at(electronIndex).second) continue;
972 >          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
973 >        }
974 >      }
975 >    }
976 >    if(applyBtagSF_ && datasetType_ != "data"){
977 >      //only apply SFs if we've cut on this object
978 >      if(find(objectsToCut.begin(),objectsToCut.end(),"jets") != objectsToCut.end ()){
979 >        flagPair jetFlags;
980 >        vector<double> jetSFs;
981 >        //get the last valid flags in the flag map
982 >        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
983 >          if (cumulativeFlags.at("jets").at(i).size()){
984 >            jetFlags = cumulativeFlags.at("jets").at(i);
985 >            break;
986 >          }
987 >        }
988 >        //apply the weight for each of those objects
989 >        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
990 >          if(!jetFlags.at(jetIndex).second) continue;
991 >          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour, jets->at(jetIndex).eta);
992 >          jetSFs.push_back(jetSFTmp);
993 >        }
994 >        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_);
995 >      }
996 >    }
997 >    scaleFactor *= muonScaleFactor_;
998 >    scaleFactor *= electronScaleFactor_;
999 >    scaleFactor *= bTagScaleFactor_;
1000 >    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
1001 >
1002 >    if (printEventInfo_) {
1003 >      // Write information about event to screen, for testing purposes.
1004 >      clog << "Event passed all cuts in channel " <<  currentChannel.name
1005 >           << ": run="  << events->at(0).run
1006 >           << "  lumi=" << events->at(0).lumi
1007 >           << "  event=" << events->at(0).evt
1008 >           << endl;
1009      }
1010  
426    cutFlows_.at(currentChannelIndex)->fillCutFlow(puScaleFactor);
1011  
1012 +    //filling histograms
1013 +    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
1014 +      uint currentDir;
1015 +      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
1016 +      else{
1017 +        currentDir = currentCut;
1018 +      }
1019  
1020  
1021 <    if(!eventPassedAllCuts)continue;
1021 >      if(eventPassedPreviousCuts.at(currentDir)){
1022  
1023 +        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1024 +          histogram currentHistogram = histograms.at(histogramIndex);
1025  
1026 +          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) clog << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
1027  
1028 +          if(currentHistogram.inputVariables.size() == 1){
1029 +            TH1D* histo;
1030 +            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1031 +            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1032 +            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1033 +            else if(currentHistogram.inputCollection == "secondary photons")  fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1034 +            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1035 +            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1036 +            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1037 +            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1038 +                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1039 +                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1040 +            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1041 +                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1042 +                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1043 +             else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1044 +                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary photons").at(currentDir), \
1045 +                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1046 +             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1047 +                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1048 +                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1049 +             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1050 +                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1051 +                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1052 +             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1053 +                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1054 +                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1055 +
1056 +            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1057 +            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
1058 +                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
1059 +                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1060 +            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
1061 +                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
1062 +                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1063 +             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1064 +                                                                                                     cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1065 +                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1066 +
1067 +            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1068 +                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1069 +                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1070 +            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
1071 +                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
1072 +                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1073 +            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
1074 +                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1075 +                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1076 +            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(), \
1077 +                                                                                              cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1078 +                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1079 +            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
1080 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1081 +                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1082 +            else if(currentHistogram.inputCollection == "muon-event pairs") fill1DHistogram(histo,currentHistogram, muons.product(),events.product(), \
1083 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1084 +                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1085 +            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, mets.product(),jets.product(), \
1086 +                                                                                          cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1087 +                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1088 +            else if(currentHistogram.inputCollection == "track-jet pairs")  fill1DHistogram(histo,currentHistogram,tracks.product(),jets.product(), \
1089 +                                                                                          cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1090 +                                                                                          cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1091 +            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(), \
1092 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1093 +                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1094 +            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(), \
1095 +                                                                                          cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1096 +                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1097 +            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1098 +                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1099 +                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1100 +            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1101 +                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1102 +                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1103 +            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1104 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1105 +                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1106 +            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1107 +                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1108 +                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1109 +            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1110 +                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1111 +                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1112 +            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1113 +                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1114 +                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1115 +            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1116 +                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1117 +                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1118 +
1119 +            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1120 +            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1121 +            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1122 +            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1123 +            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1124 +            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1125 +            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1126 +            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1127 +            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1128 +            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1129 +            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1130 +            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1131 +          }
1132 +          else if(currentHistogram.inputVariables.size() == 2){
1133 +            TH2D* histo;
1134 +            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1135 +            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1136 +            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1137 +            else if(currentHistogram.inputCollection == "secondary photons")  fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1138 +            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1139 +            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1140 +            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1141 +                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1142 +                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1143 +            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1144 +                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1145 +                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1146 +            else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1147 +                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary photons").at(currentDir), \
1148 +                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1149 +            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1150 +                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1151 +                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1152 +            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1153 +                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1154 +                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1155 +            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1156 +                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1157 +                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1158 +            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1159 +            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1160 +            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1161 +                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1162 +                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1163 +            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1164 +                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1165 +                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1166 +            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1167 +                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1168 +                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1169 +            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1170 +                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1171 +                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1172 +            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1173 +                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1174 +                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1175 +            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(), \
1176 +                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1177 +                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1178 +            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1179 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1180 +                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1181 +            else if(currentHistogram.inputCollection == "muon-event pairs") fill2DHistogram(histo,currentHistogram,muons.product(),events.product(), \
1182 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("events").at(currentDir), \
1183 +                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1184 +            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,mets.product(),jets.product(), \
1185 +                                                                                         cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1186 +                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1187 +            else if(currentHistogram.inputCollection == "track-jet pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1188 +                                                                                         cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1189 +                                                                                         cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1190 +            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1191 +                                                                                          cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1192 +                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1193 +            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1194 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1195 +                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1196 +            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1197 +                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1198 +                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1199 +            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1200 +                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1201 +                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1202 +            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1203 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1204 +                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1205 +            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1206 +                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1207 +                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1208 +            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1209 +                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1210 +                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1211 +            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1212 +                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1213 +                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1214 +            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1215 +                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1216 +                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1217 +            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1218 +            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1219 +            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1220 +            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1221 +            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1222 +                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1223 +                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1224 +            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1225 +            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1226 +            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1227 +            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1228 +            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1229 +            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1230 +            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1231 +            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1232 +          }
1233  
1234 <    //set position of primary vertex in event, in order to calculate quantities relative to it
436 <    primaryVertex_ = 0;
437 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back();
438 <    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
439 <      if(!vertexFlags.at(vertexIndex)) continue;
440 <      primaryVertex_ = new BNprimaryvertex (primaryvertexs->at (vertexIndex));
441 <      break;
442 <    }
1234 >        }
1235  
1236  
1237 +        //fills histograms with the sizes of collections
1238 +        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1239  
1240 <    //filling histograms
1241 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1242 <      histogram currentHistogram = histograms.at(histogramIndex);
1240 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1241 >          string objectToPlot = "";
1242 >
1243 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1244 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1245 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1246 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1247 >          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1248 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1249 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1250 >          else if(currentObject == "muon-event pairs")                     objectToPlot = "muonEventPairs";
1251 >          else if(currentObject == "muon-photon pairs")                     objectToPlot = "muonPhotonPairs";
1252 >          else if(currentObject == "photon-jet pairs")                     objectToPlot = "photonJetPairs";
1253 >          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1254 >          else if(currentObject == "track-jet pairs")                    objectToPlot = "trackJetPairs";
1255 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1256 >          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1257 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1258 >          else if(currentObject == "secondary photons")                     objectToPlot = "secondaryPhotons";
1259 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1260 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1261 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1262 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1263 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1264 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1265 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1266 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1267 >          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1268 >          else if(currentObject == "muon-secondary photon pairs")           objectToPlot = "muonSecondaryJetPairs";
1269 >          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1270 >          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1271 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1272 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1273 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1274 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1275 >          else objectToPlot = currentObject;
1276 >
1277 >          string tempCurrentObject = objectToPlot;
1278 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1279 >          string histoName = "num" + tempCurrentObject;
1280 >
1281 >
1282 >          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1283 >            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1284 >            int numToPlot = 0;
1285 >            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1286 >              if(lastCutFlags.at(currentFlag).second) numToPlot++;
1287 >            }
1288 >
1289 >            if(objectToPlot == "primaryvertexs"){
1290 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1291 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1292 >            }
1293 >            else {
1294 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1295 >            }
1296 >          }
1297 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1298  
450      if(currentHistogram.inputVariables.size() == 1){
451        TH1D* histo;
452        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
453        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
454        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
455        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),\
456                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(),\
457                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
458        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
459        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
460                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
461                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
462        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
463                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
464                                                                                              cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
465        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
466        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
467        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
468        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
469        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
470        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
471        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
472        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
473        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
474        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
475      }
476      else if(currentHistogram.inputVariables.size() == 2){
477        TH2D* histo;
478        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
479        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
480        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
481        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
482                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
483                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
484        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
485        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
486                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
487                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
488        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
489                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
490                                                                                               cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
491        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
492        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
493        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
494        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
495        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
496        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
497        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
498        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
499        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
500        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
501      }
502    }
503
504
505    //fills histograms with the sizes of collections
506    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
507      string currentObject = objectsToPlot.at(currentObjectIndex);
508
509      if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
510      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
511      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
512      string tempCurrentObject = currentObject;
513      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
514      string histoName = "num" + tempCurrentObject;
515
516
517      if(currentObject == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),puScaleFactor);
518      else if(currentObject == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),puScaleFactor);
519      else if(currentObject == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,puScaleFactor);
520      else if(currentObject == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),puScaleFactor);
521      else if(currentObject == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,puScaleFactor);
522      else if(currentObject == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),puScaleFactor);
523      else if(currentObject == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),puScaleFactor);
524      else if(currentObject == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),puScaleFactor);
525      else if(currentObject == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),puScaleFactor);
526      else if(currentObject == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),puScaleFactor);
527      else if(currentObject == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),puScaleFactor);
528      else if(currentObject == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),puScaleFactor);
529      else if(currentObject == "primaryvertexs"){
530        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
531        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),puScaleFactor);
532      }
533      else if(currentObject == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),puScaleFactor);
534      else if(currentObject == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),puScaleFactor);
535      else if(currentObject == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),puScaleFactor);
1299  
1300 +      } // end if(eventPassedPreviousCuts.at(currentDir))
1301 +    } // end loop over cuts
1302 +
1303 +    if (!useEDMFormat_ && eventPassedAllCuts){
1304 +      // Assign BNTree variables
1305 +      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1306 +        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1307 +        string coll = brSpecs.inputCollection;
1308 +        if (cumulativeFlags.count(coll) == 0) clog << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1309 +
1310 +        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1311 +        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1312 +        else if(coll == "secondary photons")      assignTreeBranch(brSpecs,photons.product(),          cumulativeFlags.at(coll).back());
1313 +        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1314 +        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1315 +        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1316 +        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1317 +        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1318 +        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1319 +        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1320 +        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1321 +        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1322 +        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1323 +        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1324 +        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1325 +        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1326 +        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1327 +        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1328 +        else if(coll == "stops"
1329 +                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1330 +      } // end loop over branches
1331 +
1332 +      if (!BNTrees_.at(currentChannelIndex)) { clog << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1333 +      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1334      }
538  } //end loop over channel
1335  
1336 <  masterCutFlow_->fillCutFlow(puScaleFactor);
1336 >    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1337  
1338 +  } // end loop over channel
1339  
1340 +  masterCutFlow_->fillCutFlow(masterScaleFactor);
1341 +
1342 +  event.put (channelDecisions, "channelDecisions");
1343 +
1344 + } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1345  
544 }
1346  
1347  
1348   bool
# Line 555 | Line 1356 | OSUAnalysis::evaluateComparison (double
1356    else if(comparison == "==") return testValue == cutValue;
1357    else if(comparison == "=") return testValue == cutValue;
1358    else if(comparison == "!=") return testValue != cutValue;
1359 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1359 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1360  
1361   }
1362  
1363   bool
1364 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1364 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1365 >
1366 >
1367 >  if(comparison == ">")       return testValue >  cutValue;
1368 >  else if(comparison == ">=") return testValue >= cutValue;
1369 >  else if(comparison == "<")  return testValue <  cutValue;
1370 >  else if(comparison == "<=") return testValue <= cutValue;
1371 >  else if(comparison == "==") return testValue == cutValue;
1372 >  else if(comparison == "=") return testValue == cutValue;
1373 >  else if(comparison == "!=") return testValue != cutValue;
1374 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1375 >
1376 > }
1377  
1378 + bool
1379 + OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1380 +
1381 +  //initialize to false until a chosen trigger is passed
1382    bool triggerDecision = false;
1383  
1384 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1385 <    {
1386 <      if(trigger->pass != 1) continue;
1387 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1388 <        {
1389 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1390 <            triggerDecision = true;
1391 <          }
1392 <        }
1384 >  if (printAllTriggers_) clog << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1385 >  //loop over all triggers defined in the event
1386 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1387 >
1388 >    if (printAllTriggers_) clog << "   " << trigger->name << endl;
1389 >
1390 >    //we're only interested in triggers that actually passed
1391 >    if(trigger->pass != 1) continue;
1392 >
1393 >    //if the event passes one of the veto triggers, exit and return false
1394 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1395 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1396 >    }
1397 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1398 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1399 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1400      }
1401 <  return triggerDecision;
1401 >  }
1402 >
1403 >  printAllTriggers_ = false;  // only print triggers once, not every event
1404  
1405 +  //if none of the veto triggers fired:
1406 +  //return the OR of all the chosen triggers
1407 +  if (triggersToTest.size() != 0) return triggerDecision;
1408 +  //or if no triggers were defined return true
1409 +  else return true;
1410   }
1411  
1412 < std::vector<std::string>
1412 >
1413 > vector<string>
1414   OSUAnalysis::splitString (string inputString){
1415  
1416 <  std::stringstream stringStream(inputString);
1417 <  std::istream_iterator<std::string> begin(stringStream);
1418 <  std::istream_iterator<std::string> end;
1419 <  std::vector<std::string> stringVector(begin, end);
1416 >  stringstream stringStream(inputString);
1417 >  istream_iterator<string> begin(stringStream);
1418 >  istream_iterator<string> end;
1419 >  vector<string> stringVector(begin, end);
1420    return stringVector;
1421  
1422   }
1423  
1424 +
1425 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1426 +  // Set two object strings from the tempInputCollection string,
1427 +  // For example, if tempInputCollection is "electron-muon pairs",
1428 +  // then obj1 = "electrons" and obj2 = "muons".
1429 +  // Note that the objects have an "s" appended.
1430 +
1431 +  int dashIndex = tempInputCollection.find("-");
1432 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1433 +  int secondWordLength = spaceIndex - dashIndex;
1434 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1435 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1436 +
1437 + }
1438 +
1439 +
1440 + string OSUAnalysis::getObjToGet(string obj) {
1441 +  // Return the string corresponding to the object to get for the given obj string.
1442 +  // Right now this only handles the case in which obj contains "secondary",
1443 +  // e.g, "secondary muons".
1444 +  // Note that "s" is NOT appended.
1445 +
1446 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1447 +  int firstSpaceIndex = obj.find_first_of(" ");
1448 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1449 +
1450 + }
1451 +
1452 +
1453 + //!jet valueLookup
1454   double
1455 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1455 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1456  
1457    double value = 0.0;
1458    if(variable == "energy") value = object->energy;
# Line 709 | Line 1571 | OSUAnalysis::valueLookup (const BNjet* o
1571    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1572    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1573  
1574 +  //user defined variable
1575 +  else if(variable == "disappTrkLeadingJetID") {
1576 +    value = object->pt > 110
1577 +      && fabs(object->eta) < 2.4
1578 +      && object->chargedHadronEnergyFraction > 0.2
1579 +      && object->neutralHadronEnergyFraction < 0.7
1580 +      && object->chargedEmEnergyFraction < 0.5
1581 +      && object->neutralEmEnergyFraction < 0.7;
1582 +  }
1583 +
1584 +  else if(variable == "disappTrkSubLeadingJetID") {
1585 +    value = object->pt > 30
1586 +      && fabs(object->eta) < 4.5
1587 +      && object->neutralHadronEnergyFraction < 0.7
1588 +      && object->chargedEmEnergyFraction < 0.5;
1589 +  }
1590 +
1591 +  else if(variable == "dPhiMet") {
1592 +    if (const BNmet *met = chosenMET ()) {
1593 +      value = deltaPhi (object->phi, met->phi);
1594 +    } else value = -999;
1595 +  }
1596 +
1597  
1598 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1598 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1599  
1600    value = applyFunction(function, value);
1601  
1602    return value;
1603 < }
719 <
1603 > } // end jet valueLookup
1604  
1605  
1606 + //!muon valueLookup
1607   double
1608 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1608 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1609  
1610    double value = 0.0;
1611    if(variable == "energy") value = object->energy;
# Line 736 | Line 1621 | OSUAnalysis::valueLookup (const BNmuon*
1621    else if(variable == "ecalIso") value = object->ecalIso;
1622    else if(variable == "hcalIso") value = object->hcalIso;
1623    else if(variable == "caloIso") value = object->caloIso;
1624 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
1624 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
1625    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
1626    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
1627    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 812 | Line 1697 | OSUAnalysis::valueLookup (const BNmuon*
1697    else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1698    else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1699    else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1700 +  else if(variable == "chargedHadronIsoDR04") value = object->chargedHadronIsoDR04;
1701 +  else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1702 +  else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1703 +  else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1704    else if(variable == "rhoPrime") value = object->rhoPrime;
1705    else if(variable == "AEffDr03") value = object->AEffDr03;
1706    else if(variable == "AEffDr04") value = object->AEffDr04;
# Line 819 | Line 1708 | OSUAnalysis::valueLookup (const BNmuon*
1708    else if(variable == "pfIsoR03SumNeutralHadronEt") value = object->pfIsoR03SumNeutralHadronEt;
1709    else if(variable == "pfIsoR03SumPhotonEt") value = object->pfIsoR03SumPhotonEt;
1710    else if(variable == "pfIsoR03SumPUPt") value = object->pfIsoR03SumPUPt;
1711 +  else if(variable == "relpfIsoR04SumExceptChargedHad") value = (object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)/ object->pt;
1712 +  else if(variable == "relpfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt/object->pt;
1713 +  else if(variable == "relpfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt/object->pt;
1714 +  else if(variable == "relpfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt/object->pt;
1715 +  else if(variable == "relpfIsoR04SumPUPt") value = object->pfIsoR04SumPUPt/object->pt;
1716    else if(variable == "pfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt;
1717    else if(variable == "pfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt;
1718    else if(variable == "pfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt;
# Line 875 | Line 1769 | OSUAnalysis::valueLookup (const BNmuon*
1769    else if(variable == "time_ndof") value = object->time_ndof;
1770  
1771    //user-defined variables
1772 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1773 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1774 <  else if(variable == "detIso") value = (object->trackIso) / object->pt;
1775 <  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1772 >  else if(variable == "looseID") {
1773 >    value = object->pt > 10 &&
1774 >      (object->isGlobalMuon  > 0 ||
1775 >       object->isTrackerMuon > 0);
1776 >  }
1777 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1778 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1779 >  else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1780 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1781 >  else if(variable == "relPFdBetaIsoPseudo") value = (object->pfIsoR04SumChargedHadronPt + object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt) / object->pt;
1782    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1783 +  else if(variable == "metMT") {
1784 +    if (const BNmet *met = chosenMET ())
1785 +      {
1786 +        double dPhi = deltaPhi (object->phi, met->phi);
1787 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1788 +      }
1789 +    else
1790 +      value = -999;
1791 +  }
1792 +
1793 +
1794 +
1795 +  else if(variable == "correctedD0VertexInEBPlus"){
1796 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1797 +    else value = -999;
1798 +  }
1799 +  else if(variable == "correctedD0VertexOutEBPlus"){
1800 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1801 +    else value = -999;
1802 +  }
1803 +  else if(variable == "correctedD0VertexEEPlus"){
1804 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1805 +    else value = -999;
1806 +  }
1807 +
1808 +  else if(variable == "correctedD0BeamspotInEBPlus"){
1809 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1810 +    else value = -999;
1811 +  }
1812 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
1813 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1814 +    else value = -999;
1815 +  }
1816 +  else if(variable == "correctedD0BeamspotEEPlus"){
1817 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1818 +    else value = -999;
1819 +  }
1820 +
1821 +  else if(variable == "correctedD0VertexInEBMinus"){
1822 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1823 +    else value = -999;
1824 +  }
1825 +  else if(variable == "correctedD0VertexOutEBMinus"){
1826 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1827 +    else value = -999;
1828 +  }
1829 +  else if(variable == "correctedD0VertexEEMinus"){
1830 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1831 +    else value = -999;
1832 +  }
1833 +
1834 +  else if(variable == "correctedD0BeamspotInEBMinus"){
1835 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1836 +    else value = -999;
1837 +  }
1838 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
1839 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1840 +    else value = -999;
1841 +  }
1842 +  else if(variable == "correctedD0BeamspotEEMinus"){
1843 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1844 +    else value = -999;
1845 +  }
1846 +
1847 +
1848 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1849 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1850 +    else value = -999;
1851 +  }
1852 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1853 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1854 +    else value = -999;
1855 +  }
1856 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
1857 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1858 +    else value = -999;
1859 +  }
1860 +
1861 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1862 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1863 +    else value = -999;
1864 +  }
1865 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1866 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1867 +    else value = -999;
1868 +  }
1869 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1870 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1871 +    else value = -999;
1872 +  }
1873 +
1874 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1875 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1876 +    else value = -999;
1877 +  }
1878 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1879 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1880 +    else value = -999;
1881 +  }
1882 +  else if(variable == "correctedD0VertexEENegativeCharge"){
1883 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1884 +    else value = -999;
1885 +  }
1886 +
1887 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1888 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1889 +    else value = -999;
1890 +  }
1891 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1892 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1893 +    else value = -999;
1894 +  }
1895 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1896 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1897 +    else value = -999;
1898 +  }
1899 +
1900 +
1901    else if(variable == "tightID") {
1902 <    value = object->isGlobalMuon > 0            \
1903 <      && object->isPFMuon > 0                   \
1904 <      && object->normalizedChi2 < 10            \
1905 <      && object->numberOfValidMuonHits > 0      \
1906 <      && object->numberOfMatchedStations > 1    \
1907 <      && fabs(object->correctedD0Vertex) < 0.2  \
1908 <      && fabs(object->correctedDZ) < 0.5        \
1909 <      && object->numberOfValidPixelHits > 0     \
1902 >    value = object->isGlobalMuon > 0                \
1903 >      && object->isPFMuon > 0                        \
1904 >      && object->normalizedChi2 < 10                \
1905 >      && object->numberOfValidMuonHits > 0        \
1906 >      && object->numberOfMatchedStations > 1        \
1907 >      && fabs(object->correctedD0Vertex) < 0.2        \
1908 >      && fabs(object->correctedDZ) < 0.5        \
1909 >      && object->numberOfValidPixelHits > 0                \
1910        && object->numberOfLayersWithMeasurement > 5;
893    
894
1911    }
1912    else if(variable == "tightIDdisplaced"){
1913 <    value = object->isGlobalMuon > 0            \
1914 <      && object->isPFMuon > 0                   \
1915 <      && object->normalizedChi2 < 10            \
1916 <      && object->numberOfValidMuonHits > 0      \
1917 <      && object->numberOfMatchedStations > 1    \
1918 <      && object->numberOfValidPixelHits > 0     \
1913 >    value = object->isGlobalMuon > 0                \
1914 >      && object->isPFMuon > 0                        \
1915 >      && object->normalizedChi2 < 10                \
1916 >      && object->numberOfValidMuonHits > 0        \
1917 >      && object->numberOfMatchedStations > 1        \
1918 >      && object->numberOfValidPixelHits > 0        \
1919        && object->numberOfLayersWithMeasurement > 5;
1920    }
1921  
1922 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1922 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1923 >
1924 >  else if(variable == "genMatchedPdgId"){
1925 >    int index = getGenMatchedParticleIndex(object);
1926 >    if(index == -1) value = 0;
1927 >    else value = mcparticles->at(index).id;
1928 >  }
1929 >
1930 >  else if(variable == "genMatchedId"){
1931 >    int index = getGenMatchedParticleIndex(object);
1932 >    if(index == -1) value = 0;
1933 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
1934 >  }
1935 >  else if(variable == "genMatchedMotherId"){
1936 >    int index = getGenMatchedParticleIndex(object);
1937 >    if(index == -1) value = 0;
1938 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1939 >  }
1940 >  else if(variable == "genMatchedMotherIdReverse"){
1941 >    int index = getGenMatchedParticleIndex(object);
1942 >    if(index == -1) value = 24;
1943 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1944 >  }
1945 >  else if(variable == "genMatchedGrandmotherId"){
1946 >    int index = getGenMatchedParticleIndex(object);
1947 >    if(index == -1) value = 0;
1948 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1949 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1950 >      if(motherIndex == -1) value = 0;
1951 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1952 >    }
1953 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1954 >  }
1955 >  else if(variable == "genMatchedGrandmotherIdReverse"){
1956 >    int index = getGenMatchedParticleIndex(object);
1957 >    if(index == -1) value = 24;
1958 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1959 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1960 >      if(motherIndex == -1) value = 24;
1961 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1962 >    }
1963 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1964 >  }
1965 >  else if(variable == "pfMuonsFromVertex"){
1966 >    double d0Error, dzError;
1967 >
1968 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1969 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1970 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1971 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1972 >      || fabs (object->correctedDZ / dzError) > 99.0;
1973 >    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1974 >  }
1975 >
1976 >
1977 >
1978 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1979  
1980    value = applyFunction(function, value);
1981  
1982    return value;
1983 < }
1983 > } // end muon valueLookup
1984  
1985  
1986 + //!electron valueLookup
1987   double
1988 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1988 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1989  
1990    double value = 0.0;
1991    if(variable == "energy") value = object->energy;
# Line 1073 | Line 2146 | OSUAnalysis::valueLookup (const BNelectr
2146    else if(variable == "passConvVeto") value = object->passConvVeto;
2147  
2148    //user-defined variables
2149 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
2150 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
2149 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2150 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2151    else if(variable == "detIso") value = (object->trackIso) / object->pt;
2152    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2153 +  else if(variable == "relPFrhoIsoEB") value = object->isEB ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2154 +  else if(variable == "relPFrhoIsoEE") value = object->isEE ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2155 +  else if(variable == "metMT") {
2156 +    if (const BNmet *met = chosenMET ())
2157 +      {
2158 +        double dPhi = deltaPhi (object->phi, met->phi);
2159 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2160 +      }
2161 +    else
2162 +      value = -999;
2163 +  }
2164 +
2165 +  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
2166 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
2167 +    else value = -999;
2168 +  }
2169 +  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
2170 +    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
2171 +    else value = -999;
2172 +  }
2173 +
2174 +  else if(variable == "correctedD0VertexInEBPlus"){
2175 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
2176 +    else value = -999;
2177 +  }
2178 +  else if(variable == "correctedD0VertexOutEBPlus"){
2179 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
2180 +    else value = -999;
2181 +  }
2182 +  else if(variable == "correctedD0VertexEEPlus"){
2183 +    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
2184 +    else value = -999;
2185 +  }
2186 +
2187 +  else if(variable == "correctedD0BeamspotInEBPlus"){
2188 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
2189 +    else value = -999;
2190 +  }
2191 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
2192 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
2193 +    else value = -999;
2194 +  }
2195 +  else if(variable == "correctedD0BeamspotEEPlus"){
2196 +    if(object->isEE && object->eta > 0) value = object->correctedD0;
2197 +    else value = -999;
2198 +  }
2199 +
2200 +  else if(variable == "correctedD0VertexInEBMinus"){
2201 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
2202 +    else value = -999;
2203 +  }
2204 +  else if(variable == "correctedD0VertexOutEBMinus"){
2205 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
2206 +    else value = -999;
2207 +  }
2208 +  else if(variable == "correctedD0VertexEEMinus"){
2209 +    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
2210 +    else value = -999;
2211 +  }
2212 +
2213 +  else if(variable == "correctedD0BeamspotInEBMinus"){
2214 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
2215 +    else value = -999;
2216 +  }
2217 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
2218 +    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
2219 +    else value = -999;
2220 +  }
2221 +  else if(variable == "correctedD0BeamspotEEMinus"){
2222 +    if(object->isEE && object->eta < 0) value = object->correctedD0;
2223 +    else value = -999;
2224 +  }
2225 +
2226 +  else if(variable == "looseID"){
2227 +    if (object->isEB)
2228 +      {
2229 +        value = fabs(object->delEtaIn) < 0.007 \
2230 +          && fabs (object->delPhiIn) < 0.15 \
2231 +          && object->scSigmaIEtaIEta < 0.01 \
2232 +          && object->hadOverEm < 0.12 \
2233 +          && fabs (object->correctedD0Vertex) < 0.02 \
2234 +          && fabs (object->correctedDZ) < 0.2 \
2235 +          && object->absInvEMinusInvPin < 0.05 \
2236 +          && object->passConvVeto;
2237 +      }
2238 +    else
2239 +      {
2240 +        value = fabs(object->delEtaIn) < 0.009 \
2241 +          && fabs (object->delPhiIn) < 0.10 \
2242 +          && object->scSigmaIEtaIEta < 0.03 \
2243 +          && object->hadOverEm < 0.10 \
2244 +          && fabs (object->correctedD0Vertex) < 0.02 \
2245 +          && fabs (object->correctedDZ) < 0.2 \
2246 +          && object->absInvEMinusInvPin < 0.05 \
2247 +          && object->passConvVeto;
2248 +      }
2249 +  }
2250  
2251 +  else if(variable == "tightID"){
2252 +    if (object->isEB)
2253 +      {
2254 +        value = fabs(object->delEtaIn) < 0.004 \
2255 +          && fabs (object->delPhiIn) < 0.03 \
2256 +          && object->scSigmaIEtaIEta < 0.01 \
2257 +          && object->hadOverEm < 0.12 \
2258 +          && fabs (object->correctedD0Vertex) < 0.02 \
2259 +          && fabs (object->correctedDZ) < 0.1 \
2260 +          && object->absInvEMinusInvPin < 0.05 \
2261 +          && object->passConvVeto;
2262 +      }
2263 +    else
2264 +      {
2265 +        value = fabs(object->delEtaIn) < 0.005 \
2266 +          && fabs (object->delPhiIn) < 0.02 \
2267 +          && object->scSigmaIEtaIEta < 0.03 \
2268 +          && object->hadOverEm < 0.10 \
2269 +          && fabs (object->correctedD0Vertex) < 0.02 \
2270 +          && fabs (object->correctedDZ) < 0.1 \
2271 +          && object->absInvEMinusInvPin < 0.05 \
2272 +          && object->passConvVeto;
2273 +      }
2274 +  }
2275  
2276 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2276 >  else if(variable == "looseID"){
2277 >    value = object->pt > 10
2278 >      && object->mvaNonTrigV0 > 0;
2279 >      }
2280 >  else if(variable == "correctedD0VertexInEBPositiveCharge"){
2281 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2282 >    else value = -999;
2283 >  }
2284 >  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
2285 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2286 >    else value = -999;
2287 >  }
2288 >  else if(variable == "correctedD0VertexEEPositiveCharge"){
2289 >    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
2290 >    else value = -999;
2291 >  }
2292 >
2293 >  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
2294 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
2295 >    else value = -999;
2296 >  }
2297 >  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
2298 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
2299 >    else value = -999;
2300 >  }
2301 >  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
2302 >    if(object->isEE && object->charge > 0) value = object->correctedD0;
2303 >    else value = -999;
2304 >  }
2305 >
2306 >  else if(variable == "correctedD0VertexInEBNegativeCharge"){
2307 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2308 >    else value = -999;
2309 >  }
2310 >  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
2311 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2312 >    else value = -999;
2313 >  }
2314 >  else if(variable == "correctedD0VertexEENegativeCharge"){
2315 >    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
2316 >    else value = -999;
2317 >  }
2318 >
2319 >  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
2320 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
2321 >    else value = -999;
2322 >  }
2323 >  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
2324 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
2325 >    else value = -999;
2326 >  }
2327 >  else if(variable == "correctedD0BeamspotEENegativeCharge"){
2328 >    if(object->isEE && object->charge < 0) value = object->correctedD0;
2329 >    else value = -999;
2330 >  }
2331 >
2332 >
2333 >  else if(variable == "tightIDdisplaced"){
2334 >    if (object->isEB)
2335 >      {
2336 >        value = fabs(object->delEtaIn) < 0.004 \
2337 >          && fabs (object->delPhiIn) < 0.03 \
2338 >          && object->scSigmaIEtaIEta < 0.01 \
2339 >          && object->hadOverEm < 0.12 \
2340 >          && object->absInvEMinusInvPin < 0.05;
2341 >      }
2342 >    else
2343 >      {
2344 >        value = fabs (object->delEtaIn) < 0.005 \
2345 >          && fabs (object->delPhiIn) < 0.02 \
2346 >          && object->scSigmaIEtaIEta < 0.03 \
2347 >          && object->hadOverEm < 0.10 \
2348 >          && object->absInvEMinusInvPin < 0.05;
2349 >      }
2350 >  }
2351 >
2352 >
2353 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2354 >
2355 >  else if(variable == "genMatchedPdgId"){
2356 >    int index = getGenMatchedParticleIndex(object);
2357 >    if(index == -1) value = 0;
2358 >    else value = mcparticles->at(index).id;
2359 >  }
2360 >
2361 >
2362 >  else if(variable == "genMatchedId"){
2363 >    int index = getGenMatchedParticleIndex(object);
2364 >    if(index == -1) value = 0;
2365 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2366 >  }
2367 >  else if(variable == "genMatchedMotherId"){
2368 >    int index = getGenMatchedParticleIndex(object);
2369 >    if(index == -1) value = 0;
2370 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2371 >  }
2372 >  else if(variable == "genMatchedMotherIdReverse"){
2373 >    int index = getGenMatchedParticleIndex(object);
2374 >    if(index == -1) value = 24;
2375 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2376 >  }
2377 >  else if(variable == "genMatchedGrandmotherId"){
2378 >    int index = getGenMatchedParticleIndex(object);
2379 >    if(index == -1) value = 0;
2380 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2381 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2382 >      if(motherIndex == -1) value = 0;
2383 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2384 >    }
2385 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2386 >  }
2387 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2388 >    int index = getGenMatchedParticleIndex(object);
2389 >    if(index == -1) value = 24;
2390 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2391 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2392 >      if(motherIndex == -1) value = 24;
2393 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2394 >    }
2395 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2396 >  }
2397 >  else if(variable == "pfElectronsFromVertex"){
2398 >    double d0Error, dzError;
2399 >
2400 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2401 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2402 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2403 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2404 >      || fabs (object->correctedDZ / dzError) > 99.0;
2405 >    value = !value;
2406 >  }
2407 >
2408 >
2409 >
2410 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2411  
2412    value = applyFunction(function, value);
2413  
2414    return value;
2415 < }
2415 > } // end electron valueLookup
2416  
2417  
2418 + //!event valueLookup
2419   double
2420 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2420 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2421  
2422    double value = 0.0;
2423  
# Line 1096 | Line 2425 | OSUAnalysis::valueLookup (const BNevent*
2425    else if(variable == "pthat") value = object->pthat;
2426    else if(variable == "qScale") value = object->qScale;
2427    else if(variable == "alphaQCD") value = object->alphaQCD;
2428 +  else if(variable == "Ht") value = getHt(jets.product());
2429    else if(variable == "alphaQED") value = object->alphaQED;
2430    else if(variable == "scalePDF") value = object->scalePDF;
2431    else if(variable == "x1") value = object->x1;
# Line 1156 | Line 2486 | OSUAnalysis::valueLookup (const BNevent*
2486    else if(variable == "id1") value = object->id1;
2487    else if(variable == "id2") value = object->id2;
2488    else if(variable == "evt") value = object->evt;
2489 <
2490 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2489 >  else if(variable == "puScaleFactor"){
2490 >    if(doPileupReweighting_ && datasetType_ != "data")
2491 >      value = puWeight_->at (events->at (0).numTruePV);
2492 >    else
2493 >      value = 1.0;
2494 >  }
2495 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2496 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2497 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2498 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2499 >  else if(variable == "ht") value = chosenHT ();
2500 >  else if(variable == "leadMuPairInvMass"){
2501 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2502 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2503 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2504 >    value = (p0 + p1).M ();
2505 >  }
2506 >  else if(variable == "leadMuPairPt"){
2507 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2508 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2509 >             pt1 (muPair.second->px, muPair.second->py);
2510 >    pt0 += pt1;
2511 >    value = pt0.Mod ();
2512 >  }
2513 >  else if(variable == "leadElPairInvMass"){
2514 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2515 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2516 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2517 >    value = (p0 + p1).M ();
2518 >  }
2519 >  else if(variable == "leadElPairPt"){
2520 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2521 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2522 >             pt1 (muPair.second->px, muPair.second->py);
2523 >    pt0 += pt1;
2524 >    value = pt0.Mod ();
2525 >  }
2526 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2527  
2528    value = applyFunction(function, value);
2529  
2530    return value;
2531 < }
2531 > } // end event valueLookup
2532 >
2533  
2534 + //!tau valueLookup
2535   double
2536 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2536 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2537  
2538    double value = 0.0;
2539  
# Line 1209 | Line 2577 | OSUAnalysis::valueLookup (const BNtau* o
2577    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2578    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2579  
2580 +  else if (variable == "looseHadronicID") {
2581 +    value = object->pt > 10
2582 +      && object->eta < 2.3
2583 +      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2584 +      && object->HPSdecayModeFinding > 0
2585 +      && object->HPSagainstElectronLoose > 0
2586 +      && object->HPSagainstMuonTight > 0;
2587 +  }
2588 +
2589 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2590  
2591 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2591 >  else if(variable == "genMatchedPdgId"){
2592 >    int index = getGenMatchedParticleIndex(object);
2593 >    if(index == -1) value = 0;
2594 >    else value = mcparticles->at(index).id;
2595 >  }
2596 >
2597 >  else if(variable == "genMatchedId"){
2598 >    int index = getGenMatchedParticleIndex(object);
2599 >    if(index == -1) value = 0;
2600 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2601 >  }
2602 >  else if(variable == "genMatchedMotherId"){
2603 >    int index = getGenMatchedParticleIndex(object);
2604 >    if(index == -1) value = 0;
2605 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2606 >  }
2607 >  else if(variable == "genMatchedMotherIdReverse"){
2608 >    int index = getGenMatchedParticleIndex(object);
2609 >    if(index == -1) value = 24;
2610 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2611 >  }
2612 >  else if(variable == "genMatchedGrandmotherId"){
2613 >    int index = getGenMatchedParticleIndex(object);
2614 >    if(index == -1) value = 0;
2615 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2616 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2617 >      if(motherIndex == -1) value = 0;
2618 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2619 >    }
2620 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2621 >  }
2622 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2623 >    int index = getGenMatchedParticleIndex(object);
2624 >    if(index == -1) value = 24;
2625 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2626 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2627 >      if(motherIndex == -1) value = 24;
2628 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2629 >    }
2630 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2631 >  }
2632 >
2633 >
2634 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2635  
2636    value = applyFunction(function, value);
2637  
2638    return value;
2639 < }
2639 > } // end tau valueLookup
2640 >
2641  
2642 + //!met valueLookup
2643   double
2644 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2644 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2645  
2646    double value = 0.0;
2647  
# Line 1282 | Line 2705 | OSUAnalysis::valueLookup (const BNmet* o
2705    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2706    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2707  
2708 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2708 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2709  
2710    value = applyFunction(function, value);
2711  
2712    return value;
2713 < }
2713 > } // end met valueLookup
2714 >
2715  
2716 + //!track valueLookup
2717   double
2718 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2718 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2719  
2720    double value = 0.0;
2721 +  double pMag = sqrt(object->pt * object->pt +
2722 +                     object->pz * object->pz);
2723  
2724    if(variable == "pt") value = object->pt;
2725    else if(variable == "px") value = object->px;
# Line 1312 | Line 2739 | OSUAnalysis::valueLookup (const BNtrack*
2739    else if(variable == "numValidHits") value = object->numValidHits;
2740    else if(variable == "isHighPurity") value = object->isHighPurity;
2741  
2742 +  //additional BNs info for disappTrks
2743 +  else if(variable == "caloEMDeltaRp3")     value = object->caloEMDeltaRp3;
2744 +  else if(variable == "caloHadDeltaRp3")    value = object->caloHadDeltaRp3;
2745 +  else if(variable == "caloEMDeltaRp4")     value = object->caloEMDeltaRp4;
2746 +  else if(variable == "caloHadDeltaRp4")    value = object->caloHadDeltaRp4;
2747 +  else if(variable == "caloEMDeltaRp5")     value = object->caloEMDeltaRp5;
2748 +  else if(variable == "caloHadDeltaRp5")    value = object->caloHadDeltaRp5;
2749 +  else if(variable == "nHitsMissingOuter")  value = object->nHitsMissingOuter;
2750 +  else if(variable == "nHitsMissingInner")  value = object->nHitsMissingInner;
2751 +  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2752 +  else if(variable == "depTrkRp3")          value = object->depTrkRp3;
2753 +  else if(variable == "depEcalRp3")         value = object->depEcalRp3;
2754 +  else if(variable == "depHcalRp3")         value = object->depHcalRp3;
2755 +  else if(variable == "depHoRp3")           value = object->depHoRp3;
2756 +  else if(variable == "nTracksRp3")         value = object->nTracksRp3;
2757 +  else if(variable == "trackerVetoPtRp3")   value = object->trackerVetoPtRp3;
2758 +  else if(variable == "emVetoEtRp3")        value = object->emVetoEtRp3;
2759 +  else if(variable == "hadVetoEtRp3")       value = object->hadVetoEtRp3;
2760 +  else if(variable == "hoVetoEtRp3")        value = object->hoVetoEtRp3;
2761 +  else if(variable == "depTrkRp5")          value = object->depTrkRp5;
2762 +  else if(variable == "depEcalRp5")         value = object->depEcalRp5;
2763 +  else if(variable == "depHcalRp5")         value = object->depHcalRp5;
2764 +  else if(variable == "depHoRp5")           value = object->depHoRp5;
2765 +  else if(variable == "nTracksRp5")         value = object->nTracksRp5;
2766 +  else if(variable == "trackerVetoPtRp5")   value = object->trackerVetoPtRp5;
2767 +  else if(variable == "emVetoEtRp5")        value = object->emVetoEtRp5;
2768 +  else if(variable == "hadVetoEtRp5")       value = object->hadVetoEtRp5;
2769 +  else if(variable == "hoVetoEtRp5")        value = object->hoVetoEtRp5;
2770 +
2771 +  //user defined variables
2772 +  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;
2773 +  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2774 +  else if(variable == "depTrkRp5MinusPt"){
2775 +    if ( (object->depTrkRp5 - object->pt) < 0 ) {
2776 +           value = 0;
2777 +         }
2778 +         else value =  (object->depTrkRp5 - object->pt);
2779 +  }
2780 +  else if(variable == "depTrkRp3MinusPt"){
2781 +    if ( (object->depTrkRp3 - object->pt) < 0 ) {
2782 +      value = 0;
2783 +    }
2784 +    else value =  (object->depTrkRp3 - object->pt);
2785 +  }
2786 +
2787 +  else if(variable == "dPhiMet") {
2788 +    if (const BNmet *met = chosenMET ()) {
2789 +      value = deltaPhi (object->phi, met->phi);
2790 +    } else value = -999;
2791 +  }
2792 +  
2793 +  
2794 +  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2795 +  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2796 +  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2797 +  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2798 +  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2799 +  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2800 +  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2801 +  else if(variable == "ptError")                    value = object->ptError;
2802 +  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2803 +  else if (variable == "d0wrtPV"){
2804 +    double vx = object->vx - chosenVertex ()->x,
2805 +      vy = object->vy - chosenVertex ()->y,
2806 +      px = object->px,
2807 +      py = object->py,
2808 +      pt = object->pt;
2809 +    value = (-vx * py + vy * px) / pt;
2810 +  }
2811 +  else if (variable == "dZwrtPV"){
2812 +    double vx = object->vx - chosenVertex ()->x,
2813 +      vy = object->vy - chosenVertex ()->y,
2814 +      vz = object->vz - chosenVertex ()->z,
2815 +      px = object->px,
2816 +      py = object->py,
2817 +      pz = object->pz,
2818 +      pt = object->pt;
2819 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2820 +  }
2821  
2822 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2822 >
2823 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2824 >
2825 >  else if(variable == "genMatchedPdgId"){
2826 >    int index = getGenMatchedParticleIndex(object);
2827 >    if(index == -1) value = 0;
2828 >    else value = mcparticles->at(index).id;
2829 >  }
2830 >
2831 >
2832 >  else if(variable == "genMatchedId"){
2833 >    int index = getGenMatchedParticleIndex(object);
2834 >    if(index == -1) value = 0;
2835 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2836 >  }
2837 >  else if(variable == "genMatchedMotherId"){
2838 >    int index = getGenMatchedParticleIndex(object);
2839 >    if(index == -1) value = 0;
2840 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2841 >  }
2842 >  else if(variable == "genMatchedMotherIdReverse"){
2843 >    int index = getGenMatchedParticleIndex(object);
2844 >    if(index == -1) value = 24;
2845 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2846 >  }
2847 >  else if(variable == "genMatchedGrandmotherId"){
2848 >    int index = getGenMatchedParticleIndex(object);
2849 >    if(index == -1) value = 0;
2850 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2851 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2852 >      if(motherIndex == -1) value = 0;
2853 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2854 >    }
2855 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2856 >  }
2857 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2858 >    int index = getGenMatchedParticleIndex(object);
2859 >    if(index == -1) value = 24;
2860 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2861 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2862 >      if(motherIndex == -1) value = 24;
2863 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2864 >    }
2865 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2866 >  }
2867 >
2868 >
2869 >
2870 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2871  
2872    value = applyFunction(function, value);
2873  
2874    return value;
2875 < }
2875 > } // end track valueLookup
2876  
2877 +
2878 + //!genjet valueLookup
2879   double
2880 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2880 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2881  
2882    double value = 0.0;
2883  
# Line 1341 | Line 2897 | OSUAnalysis::valueLookup (const BNgenjet
2897    else if(variable == "charge") value = object->charge;
2898  
2899  
2900 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2900 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2901  
2902    value = applyFunction(function, value);
2903  
2904    return value;
2905   }
2906  
2907 + //!mcparticle valueLookup
2908   double
2909 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2909 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2910  
2911    double value = 0.0;
2912  
# Line 1440 | Line 2997 | OSUAnalysis::valueLookup (const BNmcpart
2997  
2998    //user-defined variables
2999    else if (variable == "d0"){
3000 <    double vx = object->vx - primaryVertex_->x,
3001 <      vy = object->vy - primaryVertex_->y,
3000 >    double vx = object->vx - chosenVertex ()->x,
3001 >      vy = object->vy - chosenVertex ()->y,
3002        px = object->px,
3003        py = object->py,
3004        pt = object->pt;
3005      value = (-vx * py + vy * px) / pt;
3006    }
3007    else if (variable == "dz"){
3008 <    double vx = object->vx - primaryVertex_->x,
3009 <      vy = object->vy - primaryVertex_->y,
3010 <      vz = object->vz - primaryVertex_->z,
3008 >    double vx = object->vx - chosenVertex ()->x,
3009 >      vy = object->vy - chosenVertex ()->y,
3010 >      vz = object->vz - chosenVertex ()->z,
3011        px = object->px,
3012        py = object->py,
3013        pz = object->pz,
3014        pt = object->pt;
3015      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3016    }
3017 +  else if(variable == "v0"){
3018 +    value = sqrt(object->vx*object->vx + object->vy*object->vy);
3019 +  }
3020 +  else if(variable == "deltaV0"){
3021 +    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
3022 +  }
3023 +  else if (variable == "deltaVx"){
3024 +    value = object->vx - chosenVertex ()->x;
3025 +  }
3026 +  else if (variable == "deltaVy"){
3027 +    value = object->vy - chosenVertex ()->y;
3028 +  }
3029 +  else if (variable == "deltaVz"){
3030 +    value = object->vz - chosenVertex ()->z;
3031 +  }
3032  
3033  
3034 <
1463 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3034 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3035  
3036    value = applyFunction(function, value);
3037  
3038    return value;
3039 < }
3039 > } // end mcparticle valueLookup
3040  
3041 +
3042 + //!primaryvertex valueLookup
3043   double
3044 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
3044 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
3045  
3046    double value = 0.0;
3047  
# Line 1487 | Line 3060 | OSUAnalysis::valueLookup (const BNprimar
3060    else if(variable == "isGood") value = object->isGood;
3061  
3062  
3063 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3063 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3064  
3065    value = applyFunction(function, value);
3066  
3067    return value;
3068   }
3069  
3070 + //!bxlumi valueLookup
3071   double
3072 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
3072 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
3073  
3074    double value = 0.0;
3075  
# Line 1504 | Line 3078 | OSUAnalysis::valueLookup (const BNbxlumi
3078    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
3079  
3080  
3081 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3081 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3082  
3083    value = applyFunction(function, value);
3084  
3085    return value;
3086   }
3087  
3088 + //!photon valueLookup
3089   double
3090 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
3090 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
3091  
3092    double value = 0.0;
3093  
# Line 1587 | Line 3162 | OSUAnalysis::valueLookup (const BNphoton
3162    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
3163  
3164  
3165 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3165 >
3166 >
3167 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3168 >
3169 >  else if(variable == "genMatchedPdgId"){
3170 >    int index = getGenMatchedParticleIndex(object);
3171 >    if(index == -1) value = 0;
3172 >    else value = mcparticles->at(index).id;
3173 >  }
3174 >
3175 >
3176 >
3177 >  else if(variable == "genMatchedId"){
3178 >    int index = getGenMatchedParticleIndex(object);
3179 >    if(index == -1) value = 0;
3180 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
3181 >  }
3182 >  else if(variable == "genMatchedMotherId"){
3183 >    int index = getGenMatchedParticleIndex(object);
3184 >    if(index == -1) value = 0;
3185 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
3186 >  }
3187 >  else if(variable == "genMatchedMotherIdReverse"){
3188 >    int index = getGenMatchedParticleIndex(object);
3189 >    if(index == -1) value = 24;
3190 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
3191 >  }
3192 >  else if(variable == "genMatchedGrandmotherId"){
3193 >    int index = getGenMatchedParticleIndex(object);
3194 >    if(index == -1) value = 0;
3195 >    else if(fabs(mcparticles->at(index).motherId) == 15){
3196 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3197 >      if(motherIndex == -1) value = 0;
3198 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3199 >    }
3200 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3201 >  }
3202 >  else if(variable == "genMatchedGrandmotherIdReverse"){
3203 >    int index = getGenMatchedParticleIndex(object);
3204 >    if(index == -1) value = 24;
3205 >    else if(fabs(mcparticles->at(index).motherId) == 15){
3206 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3207 >      if(motherIndex == -1) value = 24;
3208 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3209 >    }
3210 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3211 >  }
3212 >
3213 >
3214 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3215  
3216    value = applyFunction(function, value);
3217  
3218    return value;
3219 < }
3219 > } // end photon valueLookup
3220 >
3221  
3222 + //!supercluster valueLookup
3223   double
3224 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
3224 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
3225  
3226    double value = 0.0;
3227  
# Line 1609 | Line 3235 | OSUAnalysis::valueLookup (const BNsuperc
3235    else if(variable == "theta") value = object->theta;
3236  
3237  
3238 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3238 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3239  
3240    value = applyFunction(function, value);
3241  
3242    return value;
3243   }
3244  
3245 + //!trigobj valueLookup
3246 + double
3247 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3248 +
3249 +  double value = 0.0;
3250 +
3251 +  if(variable == "pt") value = object->pt;
3252 +  else if(variable == "eta") value = object->eta;
3253 +  else if(variable == "phi") value = object->phi;
3254 +  else if(variable == "px") value = object->px;
3255 +  else if(variable == "py") value = object->py;
3256 +  else if(variable == "pz") value = object->pz;
3257 +  else if(variable == "et") value = object->et;
3258 +  else if(variable == "energy") value = object->energy;
3259 +  else if(variable == "etTotal") value = object->etTotal;
3260 +  else if(variable == "id") value = object->id;
3261 +  else if(variable == "charge") value = object->charge;
3262 +  else if(variable == "isIsolated") value = object->isIsolated;
3263 +  else if(variable == "isMip") value = object->isMip;
3264 +  else if(variable == "isForward") value = object->isForward;
3265 +  else if(variable == "isRPC") value = object->isRPC;
3266 +  else if(variable == "bx") value = object->bx;
3267 +  else if(variable == "filter") {
3268 +    if ((stringValue = object->filter) == "")
3269 +      stringValue = "none";  // stringValue should only be empty if value is filled
3270 +  }
3271 +
3272 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3273 +
3274 +  value = applyFunction(function, value);
3275 +
3276 +  return value;
3277 + }
3278  
3279 + //!muon-muon pair valueLookup
3280   double
3281 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
3281 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3282  
3283    double value = 0.0;
3284  
3285 <  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
3285 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3286 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3287 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3288    else if(variable == "invMass"){
3289      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3290      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3291      value = (fourVector1 + fourVector2).M();
3292    }
3293 +  else if(variable == "pt"){
3294 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3295 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3296 +    value = (fourVector1 + fourVector2).Pt();
3297 +  }
3298 +  else if(variable == "threeDAngle")
3299 +    {
3300 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3301 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3302 +      value = (threeVector1.Angle(threeVector2));
3303 +    }
3304 +  else if(variable == "alpha")
3305 +    {
3306 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3307 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3308 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3309 +      value = (pi-threeVector1.Angle(threeVector2));
3310 +    }
3311    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3312    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3313 <  else if(variable == "d0Sign") value = object1->correctedD0Vertex*object2->correctedD0Vertex/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3313 >  else if(variable == "d0Sign"){
3314 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3315 >    if(d0Sign < 0) value = -0.5;
3316 >    else if (d0Sign > 0) value = 0.5;
3317 >    else value = -999;
3318 >  }
3319 >  else if(variable == "chargeProduct"){
3320 >    value = object1->charge*object2->charge;
3321 >  }
3322 >  else if(variable == "muon1CorrectedD0Vertex"){
3323 >    value = object1->correctedD0Vertex;
3324 >  }
3325 >  else if(variable == "muon2CorrectedD0Vertex"){
3326 >    value = object2->correctedD0Vertex;
3327 >  }
3328 >  else if(variable == "muon1timeAtIpInOut"){
3329 >    value = object1->timeAtIpInOut;
3330 >  }
3331 >  else if(variable == "muon2timeAtIpInOut"){
3332 >    value = object2->timeAtIpInOut;
3333 >  }
3334 >  else if(variable == "muon1correctedD0")
3335 >    {
3336 >      value = object1->correctedD0;
3337 >    }
3338 >  else if(variable == "muon2correctedD0")
3339 >    {
3340 >      value = object2->correctedD0;
3341 >    }
3342  
3343 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3343 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3344 >
3345 >  value = applyFunction(function, value);
3346 >
3347 >  return value;
3348 > } // end muon-muon pair valueLookup
3349 >
3350 >
3351 > //!muon-photon pair valueLookup
3352 > double
3353 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3354 >
3355 >  double value = 0.0;
3356 >
3357 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3358 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3359 >  else if(variable == "photonEta") value = object2->eta;
3360 >  else if(variable == "photonPt") value = object2->pt;
3361 >  else if(variable == "muonEta") value = object1->eta;
3362 >  else if(variable == "photonPhi") value = object2->phi;
3363 >  else if(variable == "muonPhi") value = object1->phi;
3364 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3365 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3366 >  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3367 >  else if(variable == "invMass"){
3368 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3369 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3370 >    value = (fourVector1 + fourVector2).M();
3371 >  }
3372 >  else if(variable == "pt"){
3373 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3374 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3375 >    value = (fourVector1 + fourVector2).Pt();
3376 >  }
3377 >  else if(variable == "threeDAngle")
3378 >    {
3379 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3380 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3381 >      value = (threeVector1.Angle(threeVector2));
3382 >    }
3383 >  else if(variable == "alpha")
3384 >    {
3385 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3386 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3387 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3388 >      value = (pi-threeVector1.Angle(threeVector2));
3389 >    }
3390 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3391 >
3392 >  value = applyFunction(function, value);
3393 >
3394 >  return value;
3395 > }
3396 >
3397 > //!electron-photon pair valueLookup
3398 > double
3399 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3400 >
3401 >  double value = 0.0;
3402 >
3403 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3404 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3405 >  else if(variable == "photonEta") value = object2->eta;
3406 >  else if(variable == "photonPt") value = object2->pt;
3407 >  else if(variable == "electronEta") value = object1->eta;
3408 >  else if(variable == "photonPhi") value = object2->phi;
3409 >  else if(variable == "electronPhi") value = object1->phi;
3410 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3411 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3412 >  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3413 >  else if(variable == "invMass"){
3414 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3415 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3416 >    value = (fourVector1 + fourVector2).M();
3417 >  }
3418 >  else if(variable == "pt"){
3419 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3420 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3421 >    value = (fourVector1 + fourVector2).Pt();
3422 >  }
3423 >  else if(variable == "threeDAngle")
3424 >    {
3425 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3426 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3427 >      value = (threeVector1.Angle(threeVector2));
3428 >    }
3429 >  else if(variable == "alpha")
3430 >    {
3431 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3432 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3433 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3434 >      value = (pi-threeVector1.Angle(threeVector2));
3435 >    }
3436 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3437  
3438    value = applyFunction(function, value);
3439  
3440    return value;
3441   }
3442  
3443 + //!electron-electron pair valueLookup
3444   double
3445 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
3445 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3446  
3447    double value = 0.0;
3448  
3449 <  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
3449 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3450 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3451 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3452    else if(variable == "invMass"){
3453      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3454      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3455      value = (fourVector1 + fourVector2).M();
3456    }
3457 +  else if(variable == "pt"){
3458 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3459 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3460 +    value = (fourVector1 + fourVector2).Pt();
3461 +  }
3462 +  else if(variable == "threeDAngle")
3463 +    {
3464 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3465 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3466 +      value = (threeVector1.Angle(threeVector2));
3467 +    }
3468    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3469    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3470 <  else if(variable == "d0Sign") value = object1->correctedD0Vertex*object2->correctedD0Vertex/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3470 >  else if(variable == "d0Sign"){
3471 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3472 >    if(d0Sign < 0) value = -0.5;
3473 >    else if (d0Sign > 0) value = 0.5;
3474 >    else value = -999;
3475 >  }
3476 >  else if(variable == "chargeProduct"){
3477 >    value = object1->charge*object2->charge;
3478 >  }
3479 >  else if(variable == "electron1CorrectedD0Vertex"){
3480 >    value = object1->correctedD0Vertex;
3481 >  }
3482 >  else if(variable == "electron2CorrectedD0Vertex"){
3483 >    value = object2->correctedD0Vertex;
3484 >  }
3485 >  else if(variable == "electron1CorrectedD0"){
3486 >    value = object1->correctedD0;
3487 >  }
3488 >  else if(variable == "electron2CorrectedD0"){
3489 >    value = object2->correctedD0;
3490 >  }
3491  
3492 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3492 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3493  
3494    value = applyFunction(function, value);
3495  
3496    return value;
3497   }
3498  
3499 + //!electron-muon pair valueLookup
3500   double
3501 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3501 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3502  
3503    double value = 0.0;
3504  
3505 <  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
3505 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3506 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3507 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3508    else if(variable == "invMass"){
3509      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3510      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3511      value = (fourVector1 + fourVector2).M();
3512    }
3513 +  else if(variable == "pt"){
3514 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3515 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3516 +    value = (fourVector1 + fourVector2).Pt();
3517 +  }
3518 +  else if(variable == "threeDAngle")
3519 +    {
3520 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3521 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3522 +      value = (threeVector1.Angle(threeVector2));
3523 +    }
3524    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3525    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3526 <  else if(variable == "d0Sign") value = object1->correctedD0Vertex*object2->correctedD0Vertex/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3526 >  else if(variable == "d0Sign"){
3527 >    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3528 >    if(d0Sign < 0) value = -0.5;
3529 >    else if (d0Sign > 0) value = 0.5;
3530 >    else value = -999;
3531 >  }
3532 >  else if(variable == "chargeProduct"){
3533 >    value = object1->charge*object2->charge;
3534 >  }
3535 >  else if(variable == "electronCorrectedD0Vertex"){
3536 >    value = object1->correctedD0Vertex;
3537 >  }
3538 >  else if(variable == "muonCorrectedD0Vertex"){
3539 >    value = object2->correctedD0Vertex;
3540 >  }
3541 >  else if(variable == "electronCorrectedD0"){
3542 >    value = object1->correctedD0;
3543 >  }
3544 >  else if(variable == "muonCorrectedD0"){
3545 >    value = object2->correctedD0;
3546 >  }
3547 >  else if(variable == "electronDetIso"){
3548 >    value = (object1->trackIso) / object1->pt;
3549 >  }
3550 >  else if(variable == "muonDetIso"){
3551 >    value = (object2->trackIsoDR03) / object2->pt;
3552 >  }
3553 >  else if(variable == "electronRelPFrhoIso"){
3554 >    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3555 >  }
3556 >  else if(variable == "muonRelPFdBetaIso"){
3557 >    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3558 >  }
3559 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3560 >  value = applyFunction(function, value);
3561 >
3562 >  return value;
3563 > } // end electron-muon pair valueLookup
3564 >
3565 >
3566 > //!electron-jet pair valueLookup
3567 > double
3568 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3569 >
3570 >  double value = 0.0;
3571 >
3572 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3573 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3574 >  else if(variable == "jetEta") value = object2->eta;
3575 >  else if(variable == "jetPhi") value = object2->phi;
3576 >  else if(variable == "electronEta") value = object1->eta;
3577 >  else if(variable == "electronPhi") value = object1->phi;
3578 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3579 >  else if(variable == "invMass"){
3580 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3581 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3582 >    value = (fourVector1 + fourVector2).M();
3583 >  }
3584 >  else if(variable == "pt"){
3585 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3586 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3587 >    value = (fourVector1 + fourVector2).Pt();
3588 >  }
3589 >  else if(variable == "threeDAngle")
3590 >    {
3591 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3592 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3593 >      value = (threeVector1.Angle(threeVector2));
3594 >    }
3595 >  else if(variable == "chargeProduct"){
3596 >    value = object1->charge*object2->charge;
3597 >  }
3598 >
3599 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3600 >  value = applyFunction(function, value);
3601 >
3602 >  return value;
3603 > }
3604 >
3605 > //!photon-jet pair valueLookup
3606 > double
3607 > OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3608 >
3609 >  double value = 0.0;
3610 >
3611 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3612 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3613 >  else if(variable == "jetEta") value = object2->eta;
3614 >  else if(variable == "jetPhi") value = object2->phi;
3615 >  else if(variable == "photonEta") value = object1->eta;
3616 >  else if(variable == "photonPhi") value = object1->phi;
3617 >  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3618 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3619 >  else if(variable == "invMass"){
3620 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3621 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3622 >    value = (fourVector1 + fourVector2).M();
3623 >  }
3624 >  else if(variable == "pt"){
3625 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3626 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3627 >    value = (fourVector1 + fourVector2).Pt();
3628 >  }
3629 >  else if(variable == "threeDAngle")
3630 >    {
3631 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3632 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3633 >      value = (threeVector1.Angle(threeVector2));
3634 >    }
3635 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3636 >  value = applyFunction(function, value);
3637 >
3638 >  return value;
3639 > }
3640 >
3641 > // track-jet pair valueLookup
3642 > double
3643 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNjet* object2, string variable, string function, string &stringValue){
3644 >
3645 >  double value = 0.0;
3646 >
3647 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3648 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3649 >
3650 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3651 >  value = applyFunction(function, value);
3652 >
3653 >  return value;
3654 >
3655 > }
3656 >
3657 >
3658 >
3659 > // met-jet pair valueLookup
3660 > double
3661 > OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3662 >
3663 >  double value = 0.0;
3664 >
3665 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3666 >
3667 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3668 >  value = applyFunction(function, value);
3669 >
3670 >  return value;
3671 >
3672 > }  
3673 >
3674 >
3675 >
3676 > //!muon-jet pair valueLookup
3677 > double
3678 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3679 >
3680 >  double value = 0.0;
3681 >
3682 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3683 >  else if(variable == "jetEta") value = object2->eta;
3684 >  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3685 >  else if(variable == "jetPt") value = object2->pt;
3686 >  else if(variable == "jetPhi") value = object2->phi;
3687 >  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3688 >  else if(variable == "muonEta") value = object1->eta;
3689 >  else if(variable == "muonPt") value = object1->pt;
3690 >  else if(variable == "muonPhi") value = object1->phi;
3691 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3692 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3693 >  else if(variable == "invMass"){
3694 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3695 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3696 >    value = (fourVector1 + fourVector2).M();
3697 >  }
3698 >  else if(variable == "pt"){
3699 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3700 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3701 >    value = (fourVector1 + fourVector2).Pt();
3702 >  }
3703 >  else if(variable == "threeDAngle")
3704 >    {
3705 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3706 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3707 >      value = (threeVector1.Angle(threeVector2));
3708 >    }
3709 >  else if(variable == "chargeProduct"){
3710 >    value = object1->charge*object2->charge;
3711 >  }
3712 >
3713 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3714 >  value = applyFunction(function, value);
3715 >
3716 >  return value;
3717 > }
3718 >
3719 > //!muon-event valueLookup
3720 > double
3721 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNevent* object2, string variable, string function, string &stringValue){
3722 >
3723 >  double value = 0.0;
3724  
3725 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3725 >  if(variable == "muonEta") value = object1->eta;
3726 >  else if(variable == "muonPt") value = object1->pt;
3727 >  else if(variable == "muonPhi") value = object1->phi;
3728 >  else if(variable == "Ht") value = getHt(jets.product());
3729 >  else if(variable == "pthat")   value = object2->pthat;
3730 >  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3731 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3732 >  value = applyFunction(function, value);
3733 >
3734 >  return value;
3735 > }
3736 > //!jet-jet pair valueLookup
3737 > double
3738 > OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3739 >
3740 >  double value = 0.0;
3741  
3742 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3743 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3744 +  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3745 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3746 +  else if(variable == "invMass"){
3747 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3748 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3749 +    value = (fourVector1 + fourVector2).M();
3750 +  }
3751 +  else if(variable == "pt"){
3752 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3753 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3754 +    value = (fourVector1 + fourVector2).Pt();
3755 +  }
3756 +  else if(variable == "threeDAngle")
3757 +    {
3758 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3759 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3760 +      value = (threeVector1.Angle(threeVector2));
3761 +    }
3762 +  else if(variable == "chargeProduct"){
3763 +    value = object1->charge*object2->charge;
3764 +  }
3765 +
3766 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3767 +  value = applyFunction(function, value);
3768 +
3769 +  return value;
3770 + }
3771 +
3772 + //!electron-track pair valueLookup
3773 + double
3774 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3775 +  double electronMass = 0.000511;
3776 +  double value = 0.0;
3777 +  TLorentzVector fourVector1(0, 0, 0, 0);
3778 +  TLorentzVector fourVector2(0, 0, 0, 0);
3779 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3780 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3781 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3782 +  else if(variable == "invMass"){
3783 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3784 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3785 +
3786 +    value = (fourVector1 + fourVector2).M();
3787 +  }
3788 +  else if(variable == "chargeProduct"){
3789 +    value = object1->charge*object2->charge;
3790 +  }
3791 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3792    value = applyFunction(function, value);
3793 +  return value;
3794 +
3795 + }
3796 +
3797 +
3798 + //!muon-track pair valueLookup
3799 + double
3800 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3801 +  double pionMass = 0.140;
3802 +  double muonMass = 0.106;
3803 +  double value = 0.0;
3804 +  TLorentzVector fourVector1(0, 0, 0, 0);
3805 +  TLorentzVector fourVector2(0, 0, 0, 0);
3806 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3807 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3808 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3809 +  else if(variable == "invMass"){
3810 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3811 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3812  
3813 +    value = (fourVector1 + fourVector2).M();
3814 +  }
3815 +  else if(variable == "chargeProduct"){
3816 +    value = object1->charge*object2->charge;
3817 +  }
3818 +
3819 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3820 +  value = applyFunction(function, value);
3821    return value;
3822   }
3823  
3824 + //!tau-tau pair valueLookup
3825 + double
3826 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3827 +  double value = 0.0;
3828 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3829 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3830 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3831 +  else if(variable == "invMass"){
3832 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3833 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3834 +    value = (fourVector1 + fourVector2).M();
3835 +  }
3836 +
3837 +  else if(variable == "chargeProduct"){
3838 +    value = object1->charge*object2->charge;
3839 +  }
3840 +
3841 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3842 +  value = applyFunction(function, value);
3843 +  return value;
3844 + }
3845 +
3846 + //!muon-tau pair valueLookup
3847 + double
3848 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3849 +  double value = 0.0;
3850 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3851 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3852 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3853 +  else if(variable == "invMass"){
3854 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3855 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3856 +    value = (fourVector1 + fourVector2).M();
3857 +  }
3858 +
3859 +  else if(variable == "chargeProduct"){
3860 +    value = object1->charge*object2->charge;
3861 +  }
3862 +
3863 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3864 +  value = applyFunction(function, value);
3865 +  return value;
3866 + }
3867 +
3868 + //!tau-track pair valueLookup
3869 + double
3870 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3871 +  double value = 0.0;
3872 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3873 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3874 +  else if(variable == "chargeProduct"){
3875 +    value = object1->charge*object2->charge;
3876 +  }
3877 +
3878 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3879 +  value = applyFunction(function, value);
3880 +  return value;
3881 + }
3882 +
3883 +
3884 + //!track-event pair valueLookup
3885 + double
3886 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3887 +
3888 +  double value = 0.0;
3889 +  double pMag = sqrt(object1->pt * object1->pt +
3890 +                     object1->pz * object1->pz);
3891 +
3892 +  if      (variable == "numPV")                      value = object2->numPV;
3893 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3894 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3895 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3896 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3897 +
3898 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3899 +
3900 +  value = applyFunction(function, value);
3901 +
3902 +  return value;
3903 +
3904 + }
3905 +
3906 + //!electron-trigobj pair valueLookup
3907 + double
3908 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3909 +
3910 +  double value = 0.0;
3911 +
3912 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3913 +  else if (variable == "match"){
3914 +    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3915 +      stringValue = object2->filter;
3916 +    else
3917 +      stringValue = "none";
3918 +  }
3919 +
3920 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3921 +
3922 +  value = applyFunction(function, value);
3923 +
3924 +  return value;
3925 +
3926 + }
3927 +
3928 + //!muon-trigobj pair valueLookup
3929 + double
3930 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3931 +
3932 +  double value = 0.0;
3933 +
3934 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3935 +
3936 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3937 +
3938 +  value = applyFunction(function, value);
3939 +
3940 +  return value;
3941 +
3942 + }
3943 +
3944 + //!stop valueLookup
3945 + double
3946 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3947 +
3948 +
3949 +  double value = 0.0;
3950 +
3951 +  if(variable == "ctau") value = object->ctau;
3952 +
3953 +  else if (variable == "d0"){
3954 +    double vx = object->vx - chosenVertex ()->x,
3955 +      vy = object->vy - chosenVertex ()->y,
3956 +      px = object->px,
3957 +      py = object->py,
3958 +      pt = object->pt;
3959 +    value = (-vx * py + vy * px) / pt;
3960 +  }
3961 +
3962 +  else if (variable == "dz"){
3963 +    double vx = object->vx - chosenVertex ()->x,
3964 +      vy = object->vy - chosenVertex ()->y,
3965 +      vz = object->vz - chosenVertex ()->z,
3966 +      px = object->px,
3967 +      py = object->py,
3968 +      pz = object->pz,
3969 +      pt = object->pt;
3970 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3971 +  }
3972 +
3973 +  else if (variable == "minD0"){
3974 +    double minD0=999;
3975 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3976 +      double vx = object->vx - vertex->x,
3977 +        vy = object->vy - vertex->y,
3978 +        px = object->px,
3979 +        py = object->py,
3980 +        pt = object->pt;
3981 +      value = (-vx * py + vy * px) / pt;
3982 +      if(abs(value) < abs(minD0)) minD0 = value;
3983 +    }
3984 +    value = minD0;
3985 +  }
3986 +  else if (variable == "minDz"){
3987 +    double minDz=999;
3988 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3989 +      double vx = object->vx - vertex->x,
3990 +        vy = object->vy - vertex->y,
3991 +        vz = object->vz - vertex->z,
3992 +        px = object->px,
3993 +        py = object->py,
3994 +        pz = object->pz,
3995 +        pt = object->pt;
3996 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3997 +      if(abs(value) < abs(minDz)) minDz = value;
3998 +    }
3999 +    value = minDz;
4000 +  }
4001 +  else if(variable == "distToVertex"){
4002 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4003 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4004 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4005 +  }
4006 +  else if (variable == "minDistToVertex"){
4007 +    double minDistToVertex=999;
4008 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4009 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4010 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4011 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
4012 +
4013 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4014 +    }
4015 +    value = minDistToVertex;
4016 +  }
4017 +  else if (variable == "distToVertexDifference"){
4018 +    double minDistToVertex=999;
4019 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4020 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4021 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4022 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
4023 +
4024 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4025 +    }
4026 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4027 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4028 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4029 +
4030 +    value = distToChosenVertex - minDistToVertex;
4031 +  }
4032 +
4033 +  else if (variable == "closestVertexRank"){
4034 +    double minDistToVertex=999;
4035 +    int vertex_rank = 0;
4036 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4037 +      vertex_rank++;
4038 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4039 +                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
4040 +                      (object->vz-vertex->z)*(object->vz-vertex->z));
4041 +
4042 +      if(abs(dist) < abs(minDistToVertex)){
4043 +        value = vertex_rank;
4044 +        minDistToVertex = dist;
4045 +      }
4046 +    }
4047 +  }
4048 +
4049 +  else if (variable == "decaysToTau"){
4050 +    value = abs (object->daughter0Id) == 15 || abs (object->daughter1Id) == 15;
4051 +  }
4052 +
4053 +
4054 +
4055 +
4056 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4057 +
4058 +  value = applyFunction(function, value);
4059 +
4060 +  return value;
4061 +
4062 + } // end stop valueLookup
4063 +
4064 +
4065 +
4066 +
4067 +
4068 + // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
4069 + // Return true iff no other tracks are found in this cone.
4070 + int
4071 + OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
4072 +  for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
4073 +    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
4074 +    double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
4075 +    if(deltaRtrk < 0.5) return 0;
4076 +  }
4077 +  return 1;
4078 +
4079 + }
4080 +
4081 + //calculate the scalar sum of Jet Pt in the event.
4082 + double
4083 + OSUAnalysis::getHt (const BNjetCollection* jetColl){
4084 +  double Ht = 0;
4085 +  for(BNjetCollection::const_iterator jet = jetColl->begin(); jet !=jetColl->end(); jet++){
4086 +    Ht += abs(jet->pt);
4087 +  }
4088 +  return Ht;
4089 + }
4090 +
4091 + double
4092 + OSUAnalysis::getTrkPtRes (const BNtrack* track1){
4093 +
4094 +  double ptTrue = getTrkPtTrue(track1, mcparticles.product());
4095 +  double PtRes = (track1->pt - ptTrue) / ptTrue;
4096 +
4097 +  return PtRes;
4098 +
4099 + }
4100 +
4101 +
4102 + double
4103 + OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
4104 +  double value = -99;
4105 +  double genDeltaRLowest = 999;
4106 +
4107 +  for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
4108 +    double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
4109 +    if (genDeltaRtemp < genDeltaRLowest) {
4110 +      genDeltaRLowest = genDeltaRtemp;
4111 +      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
4112 +        double ptTrue = genPart->pt;
4113 +        value = ptTrue;
4114 +      }
4115 +    }
4116 +  }
4117 +
4118 +  return value;
4119 +
4120 + }
4121 +
4122 + double
4123 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
4124 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
4125 +  if (!useTrackCaloRhoCorr_) return -99;
4126 +  // if (!rhokt6CaloJetsHandle_) {
4127 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
4128 +  //   return -99;
4129 +  // }
4130 +  double radDeltaRCone = 0.5;
4131 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
4132 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
4133 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
4134 +  return caloTotRhoCorrCalo;
4135 +
4136 + }
4137 +
4138 +
4139 +
4140 +
4141 + //creates a map of the dead Ecal channels in the barrel and endcap
4142 + //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
4143 + //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
4144 + void
4145 + OSUAnalysis::WriteDeadEcal (){
4146 +  double etaEcal, phiEcal;
4147 +  ifstream DeadEcalFile(deadEcalFile_);
4148 +  if(!DeadEcalFile) {
4149 +    clog << "Error: DeadEcalFile has not been found." << endl;
4150 +    return;
4151 +  }
4152 +  if(DeadEcalVec.size()!= 0){
4153 +    clog << "Error: DeadEcalVec has a nonzero size" << endl;
4154 +    return;
4155 +  }
4156 +  while(!DeadEcalFile.eof())
4157 +    {
4158 +      DeadEcalFile >> etaEcal >> phiEcal;
4159 +      DeadEcal newChan;
4160 +      newChan.etaEcal = etaEcal;
4161 +      newChan.phiEcal = phiEcal;
4162 +      DeadEcalVec.push_back(newChan);
4163 +    }
4164 +  if(DeadEcalVec.size() == 0) clog << "Warning: No dead Ecal channels have been found." << endl;
4165 + }
4166 +
4167 + //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
4168 + int
4169 + OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
4170 +  double deltaRLowest = 999;
4171 +  int value = 0;
4172 +  if (DeadEcalVec.size() == 0) WriteDeadEcal();
4173 +  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4174 +    double eta = ecal->etaEcal;
4175 +    double phi = ecal->phiEcal;
4176 +    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
4177 +    if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
4178 +  }
4179 +  if (deltaRLowest<0.05) {value = 1;}
4180 +  else {value = 0;}
4181 +  return value;
4182 + }
4183 +
4184 + // Returns the smallest DeltaR between the object and any generated true particle in the event.
4185 + template <class InputObject>
4186 + double OSUAnalysis::getGenDeltaRLowest(InputObject object){
4187 +  double genDeltaRLowest = 999.;
4188 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4189 +    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
4190 +    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
4191 +  }
4192 +  return genDeltaRLowest;
4193 + }
4194  
4195   double
4196   OSUAnalysis::applyFunction(string function, double value){
4197  
4198    if(function == "abs") value = fabs(value);
4199 +  else if(function == "fabs") value = fabs(value);
4200 +  else if(function == "log10") value = log10(value);
4201 +  else if(function == "log") value = log10(value);
4202  
4203 +  else if(function == "") value = value;
4204 +  else{clog << "WARNING: invalid function '" << function << "'\n";}
4205  
4206    return value;
4207  
# Line 1698 | Line 4211 | OSUAnalysis::applyFunction(string functi
4211   template <class InputCollection>
4212   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
4213  
4214 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
4215 +    string obj1, obj2;
4216 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
4217 +    if (inputType==obj1 ||
4218 +        inputType==obj2) {
4219 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
4220 +      // and the inputType is a member of the pair.
4221 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
4222 +      // For example, if currentCut.inputCollection==electron-muon pairs,
4223 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
4224 +      return;
4225 +    }
4226 +  }
4227 +
4228    for (uint object = 0; object != inputCollection->size(); object++){
4229  
4230 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
4230 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4231 >    bool plotDecision = true;
4232  
4233      if(currentCut.inputCollection == inputType){
4234  
4235        vector<bool> subcutDecisions;
4236        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4237 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4238 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4237 >        string stringValue = "";
4238 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4239 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4240 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4241 >
4242        }
4243 <      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4243 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4244        else{
4245 <        bool tempDecision = true;
4246 <        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4247 <          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4248 <            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4249 <          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4245 >        bool tempDecision = true;
4246 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4247 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4248 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4249 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4250              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4251 <        }
4252 <        decision = tempDecision;
4251 >        }
4252 >        cutDecision = tempDecision;
4253        }
4254 +      //invert the cut for plotting if this cut is a veto
4255 +      if(currentCut.isVeto) plotDecision = !cutDecision;
4256 +      else plotDecision = cutDecision;
4257      }
1724    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4258  
4259 <    //set flags for objects that pass each cut AND all the previous cuts
4260 <    bool previousCumulativeFlag = true;
4259 >    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4260 >
4261 >    //set flags for objects that pass this cut AND all the previous cuts
4262 >    bool previousCumulativeCutFlag = true;
4263 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4264 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4265 >      else{ previousCumulativeCutFlag = false; break;}
4266 >    }
4267 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4268 >    bool previousCumulativePlotFlag = true;
4269      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4270 <      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4271 <      else{ previousCumulativeFlag = false; break;}
4270 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4271 >      else{ previousCumulativePlotFlag = false; break;}
4272      }
4273 <    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4273 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4274 >
4275 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4276  
4277    }
4278  
# Line 1738 | Line 4281 | void OSUAnalysis::setObjectFlags(cut &cu
4281  
4282   template <class InputCollection1, class InputCollection2>
4283   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
4284 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, string inputType){
4284 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, string inputType){
4285  
4286  
4287    bool sameObjects = false;
4288    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4289  
4290 <  int counter = 0;  
4290 >  // Get the strings for the two objects that make up the pair.
4291 >  string obj1Type, obj2Type;
4292 >  getTwoObjs(inputType, obj1Type, obj2Type);
4293 >  bool isTwoTypesOfObject = true;
4294 >  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
4295 >
4296 >  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
4297 >  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4298 >  if (currentCut.inputCollection == inputType) {
4299 >    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4300 >      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4301 >      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4302 >    }
4303 >    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4304 >      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4305 >        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4306 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4307 >      }
4308 >    }
4309 >  }
4310 >
4311 >  int counter = 0;
4312 >
4313    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4314      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4315 <      
4315 >
4316        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4317  
4318  
4319 <      bool decision = true;//object passes if this cut doesn't cut on that type of object
4319 >      bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4320 >      bool plotDecision = true;
4321  
4322        if(currentCut.inputCollection == inputType){
4323  
4324 <        vector<bool> subcutDecisions;
4325 <        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4326 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4327 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4328 <        }
4329 <
4330 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4331 <        else{
4332 <          bool tempDecision = true;
4333 <          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4334 <            if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4335 <              tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4336 <            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4337 <              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4338 <          }
4339 <          decision = tempDecision;
4340 <        }
4324 >        vector<bool> subcutDecisions;
4325 >        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4326 >          string stringValue = "";
4327 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4328 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4329 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4330 >        }
4331 >
4332 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4333 >        else{
4334 >          bool tempDecision = subcutDecisions.at(0);
4335 >          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
4336 >            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
4337 >              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
4338 >            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4339 >              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4340 >          }
4341 >          cutDecision = tempDecision;
4342 >        }
4343 >        //invert the cut for plotting if this cut is a veto
4344 >        if(currentCut.isVeto) plotDecision = !cutDecision;
4345 >        else plotDecision = cutDecision;
4346        }
4347 <      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4348 <      
4349 <      //set flags for objects that pass each cut AND all the previous cuts
4350 <      bool previousCumulativeFlag = true;
4347 >      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4348 >      if (cutDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4349 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4350 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4351 >      }
4352 >      if (plotDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4353 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4354 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4355 >      }
4356 >
4357 >      //set flags for objects that pass this cut AND all the previous cuts
4358 >      bool previousCumulativeCutFlag = true;
4359        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4360 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
4361 <        else{ previousCumulativeFlag = false; break;}
4360 >        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4361 >        else{ previousCumulativeCutFlag = false; break;}
4362        }
4363 <      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4363 >      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4364  
4365 <      counter++;      
4365 >      bool previousCumulativePlotFlag = true;
4366 >      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4367 >        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4368 >        else{ previousCumulativePlotFlag = false; break;}
4369 >      }
4370 >      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4371 >      
4372 >      //apply flags for the components of the composite object as well
4373 >      bool currentCumulativeCutFlag = true;
4374 >      bool currentCumulativePlotFlag = true;
4375 >
4376 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4377 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4378 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4379 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4380 >
4381 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4382 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4383 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4384 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4385 >
4386 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));
4387 >
4388 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4389 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4390 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4391 >      }
4392 >
4393 >      if (currentCumulativePlotFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4394 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4395 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4396 >      }
4397 >
4398 >      counter++;
4399 >
4400 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4401 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4402 >
4403 > }
4404 >
4405 >
4406 > bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4407 >  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4408 >  // all cuts up to currentCutIndex
4409 >  bool previousCumulativeFlag = true;
4410 >  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4411 >    bool tempFlag = false;
4412 >    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4413 >    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4414 >
4415 >    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4416 >    else {
4417 >      previousCumulativeFlag = false; break;
4418      }
1788    
4419    }
4420 +  return previousCumulativeFlag;
4421 + }
4422 +
4423  
4424  
4425 +
4426 + template <class InputCollection>
4427 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4428 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4429 +
4430 +  if (BNTreeBranchVals_.count(parameters.name)==0) clog << "Error[assignTreeBranch]:  trying to assign value to " << parameters.name << " that does not have a branch set up.  Will likely seg fault." << endl;
4431 +  for (uint object = 0; object != inputCollection->size(); object++) {
4432 +
4433 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4434 +
4435 +    string inputVariable = parameters.inputVariable;
4436 +    string function = "";
4437 +    string stringValue = "";
4438 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4439 +    BNTreeBranchVals_.at(parameters.name).push_back(value);
4440 +
4441 +  }
4442   }
4443  
4444  
4445   template <class InputCollection>
4446 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
4446 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4447 >
4448  
4449    for (uint object = 0; object != inputCollection->size(); object++){
4450  
4451 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4451 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4452  
4453      string currentString = parameters.inputVariables.at(0);
4454      string inputVariable = "";
4455      string function = "";
4456 <    if(currentString.find("(")==std::string::npos){
4457 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
4456 >    if(currentString.find("(")==string::npos){
4457 >      inputVariable = currentString;// variable to cut on
4458      }
4459      else{
4460 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4461 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4462 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4460 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4461 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4462 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4463      }
4464  
4465 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
4466 <    histo->Fill(value,puScaleFactor);
4465 >    string stringValue = "";
4466 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4467 >    histo->Fill(value,scaleFactor);
4468 >
4469 >    if (printEventInfo_) {
4470 >      // Write information about event to screen, for testing purposes.
4471 >      clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
4472 >    }
4473  
4474    }
1818
4475   }
4476  
4477   template <class InputCollection1, class InputCollection2>
4478 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
4478 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4479  
4480    bool sameObjects = false;
4481    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4482  
4483 <  int counter = 0;  
4483 >  int pairCounter = -1;
4484    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4485      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4486 <      
4486 >
4487        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4488  
4489 +      pairCounter++;
4490        //only take objects which have passed all cuts and pairs which have passed all cuts
4491 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4492 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4493 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(counter)) continue;
4491 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4492 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4493 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4494  
4495        string currentString = parameters.inputVariables.at(0);
4496        string inputVariable = "";
4497        string function = "";
4498 <      if(currentString.find("(")==std::string::npos){
4499 <        inputVariable = currentString;// variable to cut on                                                                                                          
4498 >      if(currentString.find("(")==string::npos){
4499 >        inputVariable = currentString;// variable to cut on
4500        }
4501        else{
4502 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4503 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4504 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4502 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4503 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4504 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4505        }
1849      
1850      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
1851      histo->Fill(value,puScaleFactor);
4506  
4507 <      counter++;      
4507 >      string stringValue = "";
4508 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4509 >      histo->Fill(value,scaleFactor);
4510 >
4511      }
4512    }
4513  
# Line 1858 | Line 4515 | void OSUAnalysis::fill1DHistogram(TH1* h
4515  
4516  
4517   template <class InputCollection>
4518 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
4518 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4519  
4520    for (uint object = 0; object != inputCollection->size(); object++){
4521  
4522 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4522 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4523  
4524 +    string stringValue = "";
4525      string currentString = parameters.inputVariables.at(0);
4526      string inputVariable = "";
4527      string function = "";
4528 <    if(currentString.find("(")==std::string::npos){
4529 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
4528 >    if(currentString.find("(")==string::npos){
4529 >      inputVariable = currentString;// variable to cut on
4530      }
4531      else{
4532 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4533 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4534 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4532 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4533 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4534 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4535      }
4536 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
4536 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4537  
4538      currentString = parameters.inputVariables.at(1);
4539      inputVariable = "";
4540      function = "";
4541 <    if(currentString.find("(")==std::string::npos){
4542 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
4541 >    if(currentString.find("(")==string::npos){
4542 >      inputVariable = currentString;// variable to cut on
4543      }
4544      else{
4545 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4546 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4547 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4545 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4546 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4547 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4548      }
4549  
4550 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
4550 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4551  
4552 <    histo->Fill(valueX,valueY,puScaleFactor);
4552 >    histo->Fill(valueX,valueY,scaleFactor);
4553  
4554    }
4555  
4556   }
4557  
4558   template <class InputCollection1, class InputCollection2>
4559 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
4559 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4560  
4561    bool sameObjects = false;
4562    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4563  
4564 <  int counter = 0;  
4564 >  int pairCounter = -1;
4565    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4566      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4567 <      
4567 >
4568        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4569  
4570 +      pairCounter++;
4571 +
4572        //only take objects which have passed all cuts and pairs which have passed all cuts
4573 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4574 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4575 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(counter)) continue;
4573 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4574 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4575 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4576  
4577 +      string stringValue = "";
4578        string currentString = parameters.inputVariables.at(0);
4579        string inputVariable = "";
4580        string function = "";
4581 <      if(currentString.find("(")==std::string::npos){
4582 <        inputVariable = currentString;// variable to cut on                                                                                                          
4581 >      if(currentString.find("(")==string::npos){
4582 >        inputVariable = currentString;// variable to cut on
4583        }
4584        else{
4585 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4586 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4587 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4585 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4586 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4587 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4588        }
4589 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4589 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4590  
4591        currentString = parameters.inputVariables.at(1);
4592        inputVariable = "";
4593        function = "";
4594 <      if(currentString.find("(")==std::string::npos){
4595 <        inputVariable = currentString;// variable to cut on                                                                                                          
4594 >      if(currentString.find("(")==string::npos){
4595 >        inputVariable = currentString;// variable to cut on
4596        }
4597        else{
4598 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4599 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4600 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4598 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4599 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4600 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4601        }
4602 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4602 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4603  
4604  
4605 <      histo->Fill(valueX,valueY,puScaleFactor);
4605 >      histo->Fill(valueX,valueY,scaleFactor);
4606  
1946      counter++;      
4607      }
4608    }
4609  
4610   }
4611  
4612  
4613 + template <class InputObject>
4614 + int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
4615  
4616 < DEFINE_FWK_MODULE(OSUAnalysis);
4616 >  int bestMatchIndex = -1;
4617 >  double bestMatchDeltaR = 999;
4618 >
4619 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4620 >
4621 >    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4622 >    if(currentDeltaR > 0.05) continue;
4623 >    //     clog << setprecision(3) << setw(20)
4624 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4625 >    //          << setw(20)
4626 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4627 >    //          << setw(20)
4628 >    //          << "\tdeltaR = " << currentDeltaR
4629 >    //          << setprecision(1)
4630 >    //          << setw(20)
4631 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4632 >    //          << setw(20)
4633 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4634 >    //          << setw(20)
4635 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4636 >    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4637 >      bestMatchIndex = mcparticle - mcparticles->begin();
4638 >      bestMatchDeltaR = currentDeltaR;
4639 >    }
4640 >
4641 >  }
4642 >  //   if(bestMatchDeltaR != 999)  clog << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4643 >  //   else clog << "no match found..." << endl;
4644 >  return bestMatchIndex;
4645 >
4646 > }
4647 >
4648 >
4649 > int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
4650 >
4651 >  int bestMatchIndex = -1;
4652 >  double bestMatchDeltaR = 999;
4653 >
4654 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4655 >
4656 >    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
4657 >
4658 >    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
4659 >    if(currentDeltaR > 0.05) continue;
4660 >
4661 >    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4662 >      bestMatchIndex = mcparticle - mcparticles->begin();
4663 >      bestMatchDeltaR = currentDeltaR;
4664 >    }
4665 >
4666 >  }
4667 >
4668 >  return bestMatchIndex;
4669 > }
4670 >
4671 >
4672 > // bin      particle type
4673 > // ---      -------------
4674 > //  0        unmatched
4675 > //  1        u
4676 > //  2        d
4677 > //  3        s
4678 > //  4        c
4679 > //  5        b
4680 > //  6        t
4681 > //  7        e
4682 > //  8        mu
4683 > //  9        tau
4684 > // 10        nu
4685 > // 11        g
4686 > // 12        gamma
4687 > // 13        Z
4688 > // 14        W
4689 > // 15        light meson
4690 > // 16        K meson
4691 > // 17        D meson
4692 > // 18        B meson
4693 > // 19        light baryon
4694 > // 20        strange baryon
4695 > // 21        charm baryon
4696 > // 22        bottom baryon
4697 > // 23        QCD string
4698 > // 24        other
4699 >
4700 > int OSUAnalysis::getPdgIdBinValue(int pdgId){
4701 >
4702 >  int binValue = -999;
4703 >  int absPdgId = fabs(pdgId);
4704 >  if(pdgId == -1) binValue = 0;
4705 >  else if(absPdgId <= 6 ) binValue = absPdgId;
4706 >  else if(absPdgId == 11 ) binValue = 7;
4707 >  else if(absPdgId == 13 ) binValue = 8;
4708 >  else if(absPdgId == 15 ) binValue = 9;
4709 >  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
4710 >  else if(absPdgId == 21 ) binValue = 11;
4711 >  else if(absPdgId == 22 ) binValue = 12;
4712 >  else if(absPdgId == 23 ) binValue = 13;
4713 >  else if(absPdgId == 24 ) binValue = 14;
4714 >  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
4715 >  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
4716 >  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
4717 >  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
4718 >  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
4719 >  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4720 >  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4721 >  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4722 >  else if(absPdgId == 92  ) binValue = 23;
4723 >
4724 >  else binValue = 24;
4725 >
4726 >  return binValue;
4727 >
4728 > }
4729 >
4730 > const BNprimaryvertex *
4731 > OSUAnalysis::chosenVertex ()
4732 > {
4733 >  const BNprimaryvertex *chosenVertex = 0;
4734 >  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4735 >    flagPair vertexFlags;
4736 >    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4737 >      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4738 >        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4739 >        break;
4740 >      }
4741 >    }
4742 >    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4743 >      if(!vertexFlags.at(vertexIndex).first) continue;
4744 >      chosenVertex = & primaryvertexs->at(vertexIndex);
4745 >      break;
4746 >    }
4747 >  }
4748 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4749 >    chosenVertex = & primaryvertexs->at (0);
4750 >
4751 >  return chosenVertex;
4752 > }
4753 >
4754 > const BNmet *
4755 > OSUAnalysis::chosenMET ()
4756 > {
4757 >  const BNmet *chosenMET = 0;
4758 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4759 >    flagPair metFlags;
4760 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4761 >      if (cumulativeFlags.at("mets").at(i).size()){
4762 >        metFlags = cumulativeFlags.at("mets").at(i);
4763 >        break;
4764 >      }
4765 >    }
4766 >    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4767 >      if(!metFlags.at(metIndex).first) continue;
4768 >      chosenMET = & mets->at(metIndex);
4769 >      break;
4770 >    }
4771 >  }
4772 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4773 >    chosenMET = & mets->at (0);
4774  
4775 +  return chosenMET;
4776 + }
4777 +
4778 + const BNelectron *
4779 + OSUAnalysis::chosenElectron ()
4780 + {
4781 +  const BNelectron *chosenElectron = 0;
4782 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4783 +    flagPair electronFlags;
4784 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4785 +      if (cumulativeFlags.at("electrons").at(i).size()){
4786 +        electronFlags = cumulativeFlags.at("electrons").at(i);
4787 +        break;
4788 +      }
4789 +    }
4790 +    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4791 +      if(!electronFlags.at(electronIndex).first) continue;
4792 +      chosenElectron = & electrons->at(electronIndex);
4793 +      break;
4794 +    }
4795 +  }
4796 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4797 +    chosenElectron = & electrons->at (0);
4798  
4799 +  return chosenElectron;
4800 + }
4801 +
4802 +
4803 + const BNmuon *
4804 + OSUAnalysis::chosenMuon ()
4805 + {
4806 +  const BNmuon *chosenMuon = 0;
4807 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4808 +    flagPair muonFlags;
4809 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4810 +      if (cumulativeFlags.at("muons").at(i).size()){
4811 +        muonFlags = cumulativeFlags.at("muons").at(i);
4812 +        break;
4813 +      }
4814 +    }
4815 +    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4816 +      if(!muonFlags.at(muonIndex).first) continue;
4817 +      chosenMuon = & muons->at(muonIndex);
4818 +      break;
4819 +    }
4820 +  }
4821 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4822 +    chosenMuon = & muons->at (0);
4823 +
4824 +  return chosenMuon;
4825 + }
4826 +
4827 + double
4828 + OSUAnalysis::chosenHT ()
4829 + {
4830 +  double chosenHT = 0.0;
4831 +  if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
4832 +    flagPair jetFlags;
4833 +    for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
4834 +      if (cumulativeFlags.at("jets").at(i).size()){
4835 +        jetFlags = cumulativeFlags.at("jets").at(i);
4836 +        break;
4837 +      }
4838 +    }
4839 +    for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
4840 +      if(!jetFlags.at(jetIndex).first) continue;
4841 +      chosenHT += jets->at(jetIndex).pt;
4842 +    }
4843 +  }
4844 +
4845 +  return chosenHT;
4846 + }
4847 +
4848 + pair<const BNmuon *, const BNmuon *>
4849 + OSUAnalysis::leadMuonPair ()
4850 + {
4851 +  pair<const BNmuon *, const BNmuon *> leadMuonPair;
4852 +  leadMuonPair.first = leadMuonPair.second = 0;
4853 +
4854 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4855 +    flagPair muonFlags;
4856 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4857 +      if (cumulativeFlags.at("muons").at(i).size()){
4858 +        muonFlags = cumulativeFlags.at("muons").at(i);
4859 +        break;
4860 +      }
4861 +    }
4862 +    for (uint muonIndex0 = 0; muonIndex0 != muonFlags.size(); muonIndex0++){
4863 +      if(!muonFlags.at(muonIndex0).first) continue;
4864 +      for (uint muonIndex1 = muonIndex0 + 1; muonIndex1 < muonFlags.size(); muonIndex1++){
4865 +        if(!muonFlags.at(muonIndex1).first) continue;
4866 +        const BNmuon *mu0 = & muons->at(muonIndex0);
4867 +        const BNmuon *mu1 = & muons->at(muonIndex1);
4868 +        if(leadMuonPair.first == 0 || leadMuonPair.second == 0){
4869 +          leadMuonPair.first = mu0;
4870 +          leadMuonPair.second = mu1;
4871 +        }
4872 +        else{
4873 +          TVector2 newPt0 (mu0->px, mu0->py),
4874 +                   newPt1 (mu1->px, mu1->py),
4875 +                   oldPt0 (leadMuonPair.first->px, leadMuonPair.first->py),
4876 +                   oldPt1 (leadMuonPair.second->px, leadMuonPair.second->py);
4877 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
4878 +            {
4879 +              leadMuonPair.first = mu0;
4880 +              leadMuonPair.second = mu1;
4881 +            }
4882 +        }
4883 +      }
4884 +    }
4885 +  }
4886 +
4887 +  return leadMuonPair;
4888 + }
4889 +
4890 + pair<const BNelectron *, const BNelectron *>
4891 + OSUAnalysis::leadElectronPair ()
4892 + {
4893 +  pair<const BNelectron *, const BNelectron *> leadElectronPair;
4894 +  leadElectronPair.first = leadElectronPair.second = 0;
4895 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4896 +    flagPair electronFlags;
4897 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4898 +      if (cumulativeFlags.at("electrons").at(i).size()){
4899 +        electronFlags = cumulativeFlags.at("electrons").at(i);
4900 +        break;
4901 +      }
4902 +    }
4903 +    for (uint electronIndex0 = 0; electronIndex0 != electronFlags.size(); electronIndex0++){
4904 +      if(!electronFlags.at(electronIndex0).first) continue;
4905 +      for (uint electronIndex1 = electronIndex0 + 1; electronIndex1 < electronFlags.size(); electronIndex1++){
4906 +        if(!electronFlags.at(electronIndex1).first) continue;
4907 +        const BNelectron *el0 = & electrons->at(electronIndex0);
4908 +        const BNelectron *el1 = & electrons->at(electronIndex1);
4909 +        if(leadElectronPair.first == 0 || leadElectronPair.second == 0){
4910 +          leadElectronPair.first = el0;
4911 +          leadElectronPair.second = el1;
4912 +        }
4913 +        else{
4914 +          TVector2 newPt0 (el0->px, el0->py),
4915 +                   newPt1 (el1->px, el1->py),
4916 +                   oldPt0 (leadElectronPair.first->px, leadElectronPair.first->py),
4917 +                   oldPt1 (leadElectronPair.second->px, leadElectronPair.second->py);
4918 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
4919 +            {
4920 +              leadElectronPair.first = el0;
4921 +              leadElectronPair.second = el1;
4922 +            }
4923 +        }
4924 +      }
4925 +    }
4926 +  }
4927 +
4928 +  return leadElectronPair;
4929 + }
4930 +
4931 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines