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

Comparing UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc (file contents):
Revision 1.21 by qpython, Wed Feb 27 14:16:26 2013 UTC vs.
Revision 1.83 by biliu, Wed Jun 5 03:18:56 2013 UTC

# Line 11 | Line 11 | OSUAnalysis::OSUAnalysis (const edm::Par
11    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
12    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
13    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
14 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
15    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
16    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
17    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
18    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
19    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
20 <  puFile_ (cfg.getParameter<std::string> ("puFile")),
21 <  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
22 <  dataset_ (cfg.getParameter<std::string> ("dataset")),
23 <  datasetType_ (cfg.getParameter<std::string> ("datasetType")),
20 >  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
21 >  puFile_ (cfg.getParameter<string> ("puFile")),
22 >  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
23 >  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
24 >  dataPU_ (cfg.getParameter<string> ("dataPU")),
25 >  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
26 >  muonSF_ (cfg.getParameter<string> ("muonSF")),
27 >  dataset_ (cfg.getParameter<string> ("dataset")),
28 >  datasetType_ (cfg.getParameter<string> ("datasetType")),
29    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
30    histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
31 <  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents"))
32 <
33 < {
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 >  maxBtag_ (cfg.getParameter<int> ("maxBtag")),
38 >  printEventInfo_      (cfg.getParameter<bool> ("printEventInfo")),
39 >  printAllTriggers_    (cfg.getParameter<bool> ("printAllTriggers")),
40 >  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
41 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
42 >  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
43 > {
44  
45    TH1::SetDefaultSumw2 ();
46  
47    //create pile-up reweighting object, if necessary
48 <  if(datasetType_ != "data") puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
48 >  if(datasetType_ != "data") {
49 >    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
50 >    if (applyLeptonSF_){
51 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
52 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
53 >    }
54 >    if (applyBtagSF_){
55 >      bTagSFWeight_ = new BtagSFWeight;
56 >    }
57 >  }
58 >  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
59 >    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
60 >
61  
62    // Construct Cutflow Objects. These store the results of cut decisions and
63    // handle filling cut flow histograms.
64    masterCutFlow_ = new CutFlow (fs_);
37  std::vector<TFileDirectory> directories;
65  
66    //always get vertex collection so we can assign the primary vertex in the event
67 <  allNecessaryObjects.push_back("primaryvertexs");
41 <  //always make the plot of number of primary verticex (to check pile-up reweighting)
67 >  objectsToGet.push_back("primaryvertexs");
68    objectsToPlot.push_back("primaryvertexs");
69 +  objectsToCut.push_back("primaryvertexs");
70 +
71  
72    //always get the MC particles to do GEN-matching
73 <  allNecessaryObjects.push_back("mcparticles");
73 >  objectsToGet.push_back("mcparticles");
74  
75    //always get the event collection to do pile-up reweighting
76 <  allNecessaryObjects.push_back("events");
76 >  objectsToGet.push_back("events");
77 >
78 >
79 >  // Parse the tree variable definitions.    
80 >  for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++) {
81 >    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
82 >    if(tempInputCollection.find("pairs")!=string::npos) { cout << "Warning:  tree filling is not configured for pairs of objects, so will not work for collection: " << tempInputCollection << endl; }  
83 >    objectsToGet.push_back(tempInputCollection);
84 >    objectsToCut.push_back(tempInputCollection);
85 >
86 >    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
87 >
88 >    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
89 >      BranchSpecs br;
90 >      br.inputCollection = tempInputCollection;
91 >      br.inputVariable = branchList.at(iBranch);  
92 >      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);  
93 >      br.name = string(newName.Data());  
94 >      treeBranches_.push_back(br);
95 >    }  
96 >
97 >  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++) {
98 >
99  
100    //parse the histogram definitions
101    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
102  
103      string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
104      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
105 <    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
105 >    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
106 >    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
107 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
108 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
109 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
110 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
111 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
112 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
113 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
114 >        int spaceIndex = tempInputCollection.find(" ");
115 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
116 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
117 >      }
118 >      else{
119 >        objectsToGet.push_back(tempInputCollection);
120 >      }
121        objectsToPlot.push_back(tempInputCollection);
122 <      allNecessaryObjects.push_back(tempInputCollection);
123 <    }
124 <    else{//pair of objects, need to add them both to the things to allNecessaryObjects
125 <      int dashIndex = tempInputCollection.find("-");
126 <      int spaceIndex = tempInputCollection.find(" ");
127 <      int secondWordLength = spaceIndex - dashIndex;
128 <      allNecessaryObjects.push_back(tempInputCollection);
129 <      allNecessaryObjects.push_back(tempInputCollection.substr(0,dashIndex)+"s");
130 <      allNecessaryObjects.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
122 >      objectsToCut.push_back(tempInputCollection);
123 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
124 >      string obj1;
125 >      string obj2;
126 >      getTwoObjs(tempInputCollection, obj1, obj2);
127 >      string obj2ToGet = getObjToGet(obj2);
128 >      objectsToCut.push_back(tempInputCollection);
129 >      objectsToCut.push_back(obj1);
130 >      objectsToCut.push_back(obj2);
131        objectsToPlot.push_back(tempInputCollection);
132 <      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
133 <      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
134 <      }
132 >      objectsToPlot.push_back(obj1);
133 >      objectsToPlot.push_back(obj2);
134 >      objectsToGet.push_back(tempInputCollection);
135 >      objectsToGet.push_back(obj1);
136 >      objectsToGet.push_back(obj2ToGet);
137 >    } // end else
138 >
139 >
140  
141      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
142 <    
142 >
143      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
144  
145 +      vector<double> defaultValue;
146 +      defaultValue.push_back (-1.0);
147 +
148        histogram tempHistogram;
149        tempHistogram.inputCollection = tempInputCollection;
150        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
151        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
152 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
152 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
153 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
154 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
155        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
156 <      
156 >
157        histograms.push_back(tempHistogram);
158  
159      }
160 <  }
160 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
161 >
162    //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
163    sort( objectsToPlot.begin(), objectsToPlot.end() );
164    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
165  
166  
167  
168 +  //add histograms with the gen-matched id, mother id, and grandmother id
169 +  for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
170 +
171 +    string currentObject = objectsToPlot.at(currentObjectIndex);
172 +    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
173 +
174 +    histogram tempIdHisto;
175 +    histogram tempMomIdHisto;
176 +    histogram tempGmaIdHisto;
177 +    histogram tempIdVsMomIdHisto;
178 +    histogram tempIdVsGmaIdHisto;
179 +
180 +    tempIdHisto.inputCollection = currentObject;
181 +    tempMomIdHisto.inputCollection = currentObject;
182 +    tempGmaIdHisto.inputCollection = currentObject;
183 +    tempIdVsMomIdHisto.inputCollection = currentObject;
184 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
185 +
186 +    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
187 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
188 +
189 +    currentObject = currentObject.substr(0, currentObject.size()-1);
190 +    tempIdHisto.name = currentObject+"GenMatchId";
191 +    tempMomIdHisto.name = currentObject+"GenMatchMotherId";
192 +    tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
193 +    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
194 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
195 +
196 +    currentObject.at(0) = toupper(currentObject.at(0));
197 +    tempIdHisto.title = currentObject+" Gen-matched Particle";
198 +    tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
199 +    tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
200 +    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
201 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
202 +
203 +
204 +    int maxNum = 25;
205 +    vector<double> binVector;
206 +    binVector.push_back(maxNum);
207 +    binVector.push_back(0);
208 +    binVector.push_back(maxNum);
209 +
210 +    tempIdHisto.bins = binVector;
211 +    tempIdHisto.inputVariables.push_back("genMatchedId");
212 +    tempMomIdHisto.bins = binVector;
213 +    tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
214 +    tempGmaIdHisto.bins = binVector;
215 +    tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
216 +    binVector.push_back(maxNum);
217 +    binVector.push_back(0);
218 +    binVector.push_back(maxNum);
219 +    tempIdVsMomIdHisto.bins = binVector;
220 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
221 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
222 +    tempIdVsGmaIdHisto.bins = binVector;
223 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
224 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
225 +
226 +    histograms.push_back(tempIdHisto);
227 +    histograms.push_back(tempMomIdHisto);
228 +    histograms.push_back(tempGmaIdHisto);
229 +    histograms.push_back(tempIdVsMomIdHisto);
230 +    histograms.push_back(tempIdVsGmaIdHisto);
231 +  }
232 +
233  
234    channel tempChannel;
235    //loop over all channels (event selections)
# Line 102 | Line 243 | OSUAnalysis::OSUAnalysis (const edm::Par
243      //set triggers for this channel
244      vector<string> triggerNames;
245      triggerNames.clear();
246 +    vector<string> triggerToVetoNames;
247 +    triggerToVetoNames.clear();
248 +
249      tempChannel.triggers.clear();
250 +    tempChannel.triggersToVeto.clear();
251      if(channels_.at(currentChannel).exists("triggers")){
252        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
253        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
254          tempChannel.triggers.push_back(triggerNames.at(trigger));
255 <      allNecessaryObjects.push_back("triggers");
255 >      objectsToGet.push_back("triggers");
256 >    }
257 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
258 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
259 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
260 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
261 >      objectsToGet.push_back("triggers");
262      }
112
263  
264  
265  
266      //create cutFlow for this channel
267      cutFlows_.push_back (new CutFlow (fs_, channelName));
268 <
269 <    //book a directory in the output file with the name of the channel
120 <    TFileDirectory subDir = fs_->mkdir( channelName );
121 <    directories.push_back(subDir);
122 <
123 <    std::map<std::string, TH1D*> oneDhistoMap;
124 <    oneDHists_.push_back(oneDhistoMap);
125 <    std::map<std::string, TH2D*> twoDhistoMap;
126 <    twoDHists_.push_back(twoDhistoMap);
127 <
128 <
129 <    //book all histograms included in the configuration
130 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
131 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
132 <      int numBinsElements = currentHistogram.bins.size();
133 <      int numInputVariables = currentHistogram.inputVariables.size();
134 <
135 <      if(numBinsElements != 3 && numBinsElements !=6) {
136 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
137 <        exit(0);
138 <      }
139 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
140 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
141 <        exit(0);
142 <      }
143 <      else if(numBinsElements == 3){
144 <        oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
145 <      }
146 <      else if(numBinsElements == 6){
147 <        twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2),currentHistogram.bins.at(3),currentHistogram.bins.at(4),currentHistogram.bins.at(5));
148 <
149 <      }
150 <
151 <
152 <    }
153 <    //book a histogram for the number of each object type to be plotted
154 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
155 <      string currentObject = objectsToPlot.at(currentObjectIndex);
156 <      int maxNum = 10;
157 <      if(currentObject == "mcparticles") maxNum = 50;
158 <      else if(currentObject == "primaryvertexs") maxNum = 50;
159 <      else if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
160 <      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
161 <      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
162 <
163 <      currentObject.at(0) = toupper(currentObject.at(0));
164 <      string histoName = "num" + currentObject;
165 <
166 <      if(histoName == "numPrimaryvertexs"){
167 <        string newHistoName = histoName + "BeforePileupCorrection";
168 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);    
169 <        newHistoName = histoName + "AfterPileupCorrection";
170 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
171 <      }
172 <      else
173 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
174 <    }
175 <
176 <
268 >    vector<TFileDirectory> directories; //vector of directories in the output file.
269 >    vector<string> subSubDirNames;//subdirectories in each channel.
270      //get list of cuts for this channel
271      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
272  
273 +
274      //loop over and parse all cuts
275      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
276        cut tempCut;
277        //store input collection for cut
278        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
279 +      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
280 +      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
281 +      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
282 +      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
283 +      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
284 +      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
285 +      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
286 +      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
287        tempCut.inputCollection = tempInputCollection;
288 <      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
289 <        allNecessaryObjects.push_back(tempInputCollection);
288 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
289 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
290 >          int spaceIndex = tempInputCollection.find(" ");
291 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
292 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
293 >        }
294 >        else{
295 >          objectsToGet.push_back(tempInputCollection);
296 >        }
297 >        objectsToCut.push_back(tempInputCollection);
298        }
299 <      else{//pair of objects, need to add them both to the things to allNecessaryObjects
300 <        int dashIndex = tempInputCollection.find("-");
301 <        int spaceIndex = tempInputCollection.find(" ");
302 <        int secondWordLength = spaceIndex - dashIndex;
303 <        allNecessaryObjects.push_back(tempInputCollection);
304 <        allNecessaryObjects.push_back(tempInputCollection.substr(0,dashIndex)+"s");
305 <        allNecessaryObjects.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
299 >      else{//pair of objects, need to add them both to objectsToGet
300 >        string obj1;
301 >        string obj2;
302 >        getTwoObjs(tempInputCollection, obj1, obj2);
303 >        string obj2ToGet = getObjToGet(obj2);
304 >        objectsToCut.push_back(tempInputCollection);
305 >        objectsToCut.push_back(obj1);
306 >        objectsToCut.push_back(obj2);
307 >        objectsToGet.push_back(tempInputCollection);
308 >        objectsToGet.push_back(obj1);
309 >        objectsToGet.push_back(obj2ToGet);
310  
311        }
312  
# Line 200 | Line 314 | OSUAnalysis::OSUAnalysis (const edm::Par
314  
315        //split cut string into parts and store them
316        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
317 <      std::vector<string> cutStringVector = splitString(cutString);
317 >      vector<string> cutStringVector = splitString(cutString);
318        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
319 <        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
320 <        exit(0);
319 >        cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
320 >        exit(0);
321        }
322        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
323        for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
324 <        int indexOffset = 4 * subcutIndex;
325 <        string currentVariableString = cutStringVector.at(indexOffset);
326 <        if(currentVariableString.find("(")==std::string::npos){
327 <          tempCut.functions.push_back("");//no function was specified
328 <          tempCut.variables.push_back(currentVariableString);// variable to cut on
329 <        }
330 <        else{
331 <          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
332 <          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
333 <          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
334 <        }
335 <        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
336 <        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
337 <        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
324 >        int indexOffset = 4 * subcutIndex;
325 >        string currentVariableString = cutStringVector.at(indexOffset);
326 >        if(currentVariableString.find("(")==string::npos){
327 >          tempCut.functions.push_back("");//no function was specified
328 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
329 >        }
330 >        else{
331 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
332 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
333 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
334 >        }
335 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
336 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
337 >        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
338 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
339        }
340  
341        //get number of objects required to pass cut for event to pass
342        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
343 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
343 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
344        if(numberRequiredVector.size()!=2){
345 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
345 >        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
346          exit(0);
347        }
348  
# Line 235 | Line 350 | OSUAnalysis::OSUAnalysis (const edm::Par
350        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
351        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
352  
353 <
353 >      //Set up vectors to store the directories and subDIrectories for each channel.
354 >      string subSubDirName;
355        string tempCutName;
356        if(cuts_.at(currentCut).exists("alias")){
357          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
358 +        subSubDirName = "After " + cuts_.at(currentCut).getParameter<string> ("alias") + " Cut Applied";
359        }
360        else{
361          //construct string for cutflow table
# Line 246 | Line 363 | OSUAnalysis::OSUAnalysis (const edm::Par
363          string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
364          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
365          tempCutName = cutName;
366 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
367        }
250      tempCut.name = tempCutName;
368  
369 +      subSubDirNames.push_back(subSubDirName);
370 +      tempCut.name = tempCutName;
371  
372        tempChannel.cuts.push_back(tempCut);
373  
374  
256
375      }//end loop over cuts
376  
377 +    vector<map<string, TH1D*>> oneDHistsTmp;
378 +    vector<map<string, TH2D*>> twoDHistsTmp;
379 +    //book a directory in the output file with the name of the channel
380 +    TFileDirectory subDir = fs_->mkdir( channelName );
381 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
382 +    if(GetPlotsAfterEachCut_){
383 +      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
384 +        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
385 +        directories.push_back(subSubDir);
386 +        map<string, TH1D*> oneDhistoMap;
387 +        oneDHistsTmp.push_back(oneDhistoMap);
388 +        map<string, TH2D*> twoDhistoMap;
389 +        twoDHistsTmp.push_back(twoDhistoMap);
390 +      }
391 +      oneDHists_.push_back(oneDHistsTmp);
392 +      twoDHists_.push_back(twoDHistsTmp);
393 +    }
394 +    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
395 +    else{
396 +      map<string, TH1D*> oneDhistoMap;
397 +      oneDHistsTmp.push_back(oneDhistoMap);
398 +      map<string, TH2D*> twoDhistoMap;
399 +      twoDHistsTmp.push_back(twoDhistoMap);
400 +      oneDHists_.push_back(oneDHistsTmp);
401 +      twoDHists_.push_back(twoDHistsTmp);
402 +      directories.push_back(subDir);
403 +
404 +    }
405 +
406 +
407 +    //book all histograms included in the configuration
408 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
409 +      
410 +      TTree* newTree = directories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));  
411 +      BNTrees_.push_back(newTree);      
412 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
413 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
414 +        vector<float> newVec;  
415 +        BNTreeBranchVals_[currentVar.name] = newVec;  
416 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
417 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
418 +
419 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
420 +
421 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
422 +        int numBinsElements = currentHistogram.bins.size();
423 +        int numInputVariables = currentHistogram.inputVariables.size();
424 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
425 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
426 +        
427 +        if(numBinsElements == 1){
428 +          if(numBinEdgesX > 1){
429 +            if(numBinEdgesY > 1)
430 +              numBinsElements = 6;
431 +            else
432 +              numBinsElements = 3;
433 +          }
434 +        }
435 +        if(numBinsElements != 3 && numBinsElements !=6){
436 +          cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
437 +          exit(0);
438 +        }
439 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
440 +          cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
441 +          exit(0);
442 +        }
443 +        else if(numBinsElements == 3){
444 +          if (currentHistogram.bins.size () == 3)
445 +            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));
446 +          else
447 +            {
448 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
449 +            }
450 +        }
451 +        else if(numBinsElements == 6){
452 +          if (currentHistogram.bins.size () == 6)
453 +            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));
454 +          else
455 +            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 ());
456 +        }
457 +
458 +
459 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
460 +
461 +        // bin      particle type
462 +        // ---      -------------
463 +        //  0        unmatched
464 +        //  1        u
465 +        //  2        d
466 +        //  3        s
467 +        //  4        c
468 +        //  5        b
469 +        //  6        t
470 +        //  7        e
471 +        //  8        mu
472 +        //  9        tau
473 +        // 10        nu
474 +        // 11        g
475 +        // 12        gamma
476 +        // 13        Z
477 +        // 14        W
478 +        // 15        light meson
479 +        // 16        K meson
480 +        // 17        D meson
481 +        // 18        B meson
482 +        // 19        light baryon
483 +        // 20        strange baryon
484 +        // 21        charm baryon
485 +        // 22        bottom baryon
486 +        // 23        QCD string
487 +        // 24        other
488 +
489 +        vector<TString> labelArray;
490 +        labelArray.push_back("unmatched");
491 +        labelArray.push_back("u");
492 +        labelArray.push_back("d");
493 +        labelArray.push_back("s");
494 +        labelArray.push_back("c");
495 +        labelArray.push_back("b");
496 +        labelArray.push_back("t");
497 +        labelArray.push_back("e");
498 +        labelArray.push_back("#mu");
499 +        labelArray.push_back("#tau");
500 +        labelArray.push_back("#nu");
501 +        labelArray.push_back("g");
502 +        labelArray.push_back("#gamma");
503 +        labelArray.push_back("Z");
504 +        labelArray.push_back("W");
505 +        labelArray.push_back("light meson");
506 +        labelArray.push_back("K meson");
507 +        labelArray.push_back("D meson");
508 +        labelArray.push_back("B meson");
509 +        labelArray.push_back("light baryon");
510 +        labelArray.push_back("strange baryon");
511 +        labelArray.push_back("charm baryon");
512 +        labelArray.push_back("bottom baryon");
513 +        labelArray.push_back("QCD string");
514 +        labelArray.push_back("other");
515 +
516 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
517 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
518 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
519 +          }
520 +          else {
521 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
522 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
523 +          }
524 +        }
525 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
526 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
527 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
528 +        }
529 +
530 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
531 +
532 +
533 +      // Book a histogram for the number of each object type to be plotted.
534 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
535 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
536 +        string currentObject = objectsToPlot.at(currentObjectIndex);
537 +        int maxNum = 10;
538 +        if(currentObject == "mcparticles") maxNum = 50;
539 +        else if(currentObject == "primaryvertexs") maxNum = 50;
540 +
541 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
542 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
543 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
544 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
545 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
546 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
547 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
548 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
549 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
550 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
551 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
552 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
553 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
554 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
555 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
556 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
557 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
558 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
559 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
560 +
561 +        currentObject.at(0) = toupper(currentObject.at(0));
562 +        string histoName = "num" + currentObject;
563 +
564 +        if(histoName == "numPrimaryvertexs"){
565 +          string newHistoName = histoName + "BeforePileupCorrection";
566 +          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);
567 +          newHistoName = histoName + "AfterPileupCorrection";
568 +          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);
569 +        }
570 +        else
571 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
572 +      }
573 +    }//end of loop over directories
574      channels.push_back(tempChannel);
575      tempChannel.cuts.clear();
261
576    }//end loop over channels
577  
578  
579 <  //make unique vector of objects we need to cut on (so we make sure to get them from the event)
580 <  sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
581 <  allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
579 >  //make unique vector of objects we need to get from the event
580 >  sort( objectsToGet.begin(), objectsToGet.end() );
581 >  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
582 >  //make unique vector of objects we need to cut on
583 >  sort( objectsToCut.begin(), objectsToCut.end() );
584 >  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
585  
586  
587 < }
587 > } // end constructor OSUAnalysis::OSUAnalysis()
588 >
589  
590   OSUAnalysis::~OSUAnalysis ()
591   {
592 +
593    // Destroying the CutFlow objects causes the cut flow numbers and time
594    // information to be printed to standard output.
595    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
# Line 282 | Line 601 | void
601   OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
602   {
603  
285
604    // Retrieve necessary collections from the event.
605 <  edm::Handle<BNtriggerCollection> triggers;
606 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
605 >
606 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
607      event.getByLabel (triggers_, triggers);
608  
609 <  edm::Handle<BNjetCollection> jets;
610 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())
609 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
610 >    event.getByLabel (trigobjs_, trigobjs);
611 >
612 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
613      event.getByLabel (jets_, jets);
614  
615 <  edm::Handle<BNmuonCollection> muons;
296 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())
615 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
616      event.getByLabel (muons_, muons);
617  
618 <  edm::Handle<BNelectronCollection> electrons;
300 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())
618 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
619      event.getByLabel (electrons_, electrons);
620  
621 <  edm::Handle<BNeventCollection> events;
304 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())
621 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
622      event.getByLabel (events_, events);
623  
624 <  edm::Handle<BNtauCollection> taus;
308 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())
624 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
625      event.getByLabel (taus_, taus);
626  
627 <  edm::Handle<BNmetCollection> mets;
312 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())
627 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
628      event.getByLabel (mets_, mets);
629  
630 <  edm::Handle<BNtrackCollection> tracks;
316 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())
630 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
631      event.getByLabel (tracks_, tracks);
632  
633 <  edm::Handle<BNgenjetCollection> genjets;
320 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())
633 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
634      event.getByLabel (genjets_, genjets);
635  
636 <  edm::Handle<BNmcparticleCollection> mcparticles;
324 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())
636 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
637      event.getByLabel (mcparticles_, mcparticles);
638  
639 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
328 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())
639 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
640      event.getByLabel (primaryvertexs_, primaryvertexs);
641  
642 <  edm::Handle<BNbxlumiCollection> bxlumis;
332 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())
642 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
643      event.getByLabel (bxlumis_, bxlumis);
644  
645 <  edm::Handle<BNphotonCollection> photons;
336 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())
645 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
646      event.getByLabel (photons_, photons);
647  
648 <  edm::Handle<BNsuperclusterCollection> superclusters;
340 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())
648 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
649      event.getByLabel (superclusters_, superclusters);
650  
651 +  if (datasetType_ == "signalMC"){
652 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
653 +      event.getByLabel (stops_, stops);
654 +  }
655 +
656 +  if (useTrackCaloRhoCorr_) {
657 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
658 +    // This rho collection is not available in all BEANs.
659 +    // For description of rho values for different jet reconstruction algorithms, see
660 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
661 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
662 +  }
663 +
664 +  double masterScaleFactor = 1.0;
665  
666    //get pile-up event weight
667 <  double puScaleFactor = 0;
668 <  if(datasetType_ != "data")
669 <    puScaleFactor = puWeight_->at (events->at (0).numTruePV);
670 <  else
671 <    puScaleFactor = 1.00;
667 >  if (doPileupReweighting_ && datasetType_ != "data") {
668 >    //for "data" datasets, the numTruePV is always set to -1
669 >    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;  
670 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);  
671 >  }
672  
673 +  stopCTauScaleFactor_ = 1.0;
674 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
675 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
676 +  masterScaleFactor *= stopCTauScaleFactor_;
677  
678    //loop over all channels
679  
# Line 355 | Line 681 | OSUAnalysis::analyze (const edm::Event &
681      channel currentChannel = channels.at(currentChannelIndex);
682  
683      flagMap individualFlags;
358    flagMap cumulativeFlags;
684      counterMap passingCounter;
685 +    cumulativeFlags.clear ();
686 +
687 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
688 +         iter != BNTreeBranchVals_.end(); iter++) {
689 +      iter->second.clear();  // clear array
690 +    }
691  
692      bool triggerDecision = true;
693 <    if(currentChannel.triggers.size() != 0){  //triggers specified
694 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
693 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
694 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
695        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
696      }
697  
698      //loop over all cuts
699      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
700        cut currentCut = currentChannel.cuts.at(currentCutIndex);
701 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
702 +        string currentObject = objectsToCut.at(currentObjectIndex);
703  
704 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
372 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
373 <
704 >        //initialize maps to get ready to set cuts
705          individualFlags[currentObject].push_back (vector<bool> ());
706          cumulativeFlags[currentObject].push_back (vector<bool> ());
707  
708 +      }
709 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
710 +        string currentObject = objectsToCut.at(currentObjectIndex);
711  
712 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
713 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
712 >        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
713 >
714 >
715 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
716 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
717 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
718 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
719 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
720          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
721          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
722          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 388 | Line 728 | OSUAnalysis::analyze (const edm::Event &
728          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
729          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
730          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
731 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
732  
392        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(),"muon-muon pairs");
393        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(),"electron-electron pairs");
394        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(),"electron-muon pairs");
395
396      }
733  
734  
735 +        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
736 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
737 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
738 +                                                                   "muon-muon pairs");
739 +
740 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
741 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
742 +                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
743 +                                                                             "muon-secondary muon pairs");
744 +
745 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
746 +                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
747 +                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
748 +                                                                                     "electron-secondary electron pairs");
749 +
750 +        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
751 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
752 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
753 +                                                                           "electron-electron pairs");
754 +        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
755 +                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
756 +                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
757 +                                                                       "electron-muon pairs");
758 +        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
759 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
760 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
761 +                                                                 "jet-jet pairs");
762 +        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
763 +                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
764 +                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
765 +                                                                      "electron-jet pairs");
766 +        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
767 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
768 +                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
769 +                                                                  "muon-jet pairs");
770 +        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
771 +                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
772 +                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
773 +                                                                     "track-event pairs");
774 +        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
775 +                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
776 +                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
777 +                                                                        "electron-track pairs");
778 +        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
779 +                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
780 +                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
781 +                                                                    "muon-track pairs");
782 +        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
783 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
784 +                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
785 +                                                                  "muon-tau pairs");
786 +        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
787 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
788 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
789 +                                                                 "tau-tau pairs");
790 +        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
791 +                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
792 +                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
793 +                                                                   "tau-track pairs");
794 +        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
795 +                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
796 +                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
797 +                                                                          "electron-trigobj pairs");
798 +        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
799 +                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
800 +                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
801 +                                                                      "muon-trigobj pairs");
802  
803 <    }//end loop over all cuts
803 >        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
804 >      }
805  
806  
807  
808 +    }//end loop over all cuts
809      //use cumulative flags to apply cuts at event level
810  
811      bool eventPassedAllCuts = true;
812 <
812 >    //a vector to store cumulative cut descisions after each cut.
813 >    vector<bool> eventPassedPreviousCuts;
814      //apply trigger (true if none were specified)
815      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
816  
411
817      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
818  
819        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 416 | Line 821 | OSUAnalysis::analyze (const edm::Event &
821        int numberPassing = 0;
822  
823        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
824 <          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
824 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
825        }
421
826        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
827        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
424
828        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
829 +      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
830 +    }
831 +    double scaleFactor = masterScaleFactor;
832  
833 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
834 +    if(applyLeptonSF_ && datasetType_ != "data"){
835 +      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
836 +        vector<bool> muonFlags;
837 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
838 +          if (cumulativeFlags.at("muons").at(i).size()){
839 +            muonFlags = cumulativeFlags.at("muons").at(i);
840 +            break;
841 +          }
842 +        }
843 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
844 +          if(!muonFlags.at(muonIndex)) continue;
845 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
846 +        }
847 +      }
848 +      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
849 +        vector<bool> electronFlags;
850 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
851 +          if (cumulativeFlags.at("electrons").at(i).size()){
852 +            electronFlags = cumulativeFlags.at("electrons").at(i);
853 +            break;
854 +          }
855 +        }
856 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
857 +          if(!electronFlags.at(electronIndex)) continue;
858 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
859 +        }
860 +      }
861 +    }
862 +    if(applyBtagSF_ && datasetType_ != "data"){
863 +     if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
864 +        vector<bool> jetFlags;        
865 +        vector<double> jetSFs;
866 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
867 +          if (cumulativeFlags.at("jets").at(i).size()){            
868 +            jetFlags = cumulativeFlags.at("jets").at(i);
869 +            break;          
870 +          }
871 +        }        
872 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
873 +          if(!jetFlags.at(jetIndex)) continue;          
874 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt);
875 +          jetSFs.push_back(jetSFTmp);
876 +        }
877 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_, maxBtag_ );    
878 +      }
879 +    }
880 +    scaleFactor *= muonScaleFactor_;
881 +    scaleFactor *= electronScaleFactor_;
882 +    scaleFactor *= bTagScaleFactor_;
883 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
884 +
885 +    if (printEventInfo_) {
886 +      // Write information about event to screen, for testing purposes.
887 +      cout << "Event passed all cuts in channel " <<  currentChannel.name
888 +           << ": run="  << events->at(0).run
889 +           << "  lumi=" << events->at(0).lumi
890 +           << "  event=" << events->at(0).evt
891 +           << endl;
892      }
893  
429    cutFlows_.at(currentChannelIndex)->fillCutFlow(puScaleFactor);
894  
895 +    //filling histograms
896 +    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
897 +      uint currentDir;
898 +      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
899 +      else{
900 +        currentDir = currentCut;
901 +      }
902 +      if(eventPassedPreviousCuts.at(currentDir)){
903  
904 +        // Assign BNTree variables
905 +        for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
906 +          BranchSpecs brSpecs = treeBranches_.at(iBranch);  
907 +          string coll = brSpecs.inputCollection;  
908 +          if (cumulativeFlags.count(coll) == 0) cout << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
909 +
910 +          if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).at(currentDir));            
911 +          else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).at(currentDir));
912 +          else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).at(currentDir));        
913 +          else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).at(currentDir));
914 +          else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).at(currentDir));
915 +          else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).at(currentDir));
916 +          else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).at(currentDir));
917 +          else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).at(currentDir));
918 +          else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).at(currentDir));
919 +          else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).at(currentDir));
920 +          else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).at(currentDir));
921 +          else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).at(currentDir));
922 +          else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).at(currentDir));
923 +          else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).at(currentDir));
924 +          else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).at(currentDir));
925 +          else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).at(currentDir));
926 +          else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).at(currentDir));
927 +          else if(coll == "stops"
928 +                  && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).at(currentDir));
929 +        } // end loop over branches  
930 +                                                                                          
931 +        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
932 +          histogram currentHistogram = histograms.at(histogramIndex);
933 +
934 +          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) cout << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
935 +
936 +          if(currentHistogram.inputVariables.size() == 1){
937 +            TH1D* histo;  
938 +            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
939 +            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
940 +            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
941 +            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
942 +            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
943 +            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
944 +            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
945 +                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
946 +                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
947 +            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
948 +                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
949 +                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
950 +            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
951 +            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
952 +                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
953 +                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
954 +            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
955 +                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
956 +                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
957 +            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
958 +                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
959 +                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
960 +            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
961 +                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
962 +                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
963 +            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
964 +                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
965 +                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
966 +            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
967 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
968 +                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
969 +            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
970 +                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
971 +                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
972 +            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
973 +                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
974 +                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
975 +            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
976 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
977 +                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
978 +            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
979 +                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
980 +                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
981 +            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
982 +                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
983 +                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
984 +            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
985 +                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
986 +                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
987 +            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
988 +                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
989 +                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
990 +
991 +            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
992 +            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
993 +            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
994 +            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
995 +            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
996 +            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
997 +            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
998 +            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
999 +            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1000 +            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1001 +            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1002 +            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1003 +          }
1004 +          else if(currentHistogram.inputVariables.size() == 2){
1005 +            TH2D* histo;
1006 +            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1007 +            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1008 +            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1009 +            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1010 +            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1011 +            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1012 +                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1013 +                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1014 +            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1015 +                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1016 +                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1017 +            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1018 +            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1019 +            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1020 +                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1021 +                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1022 +            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1023 +                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1024 +                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1025 +            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1026 +                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1027 +                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1028 +            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1029 +                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1030 +                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1031 +            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1032 +                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1033 +                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1034 +            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1035 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1036 +                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1037 +            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1038 +                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1039 +                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1040 +            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1041 +                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1042 +                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1043 +            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1044 +                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1045 +                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1046 +            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1047 +                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1048 +                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1049 +            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1050 +                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1051 +                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1052 +            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1053 +                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1054 +                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1055 +            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1056 +                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1057 +                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1058 +            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1059 +            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1060 +            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1061 +            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1062 +            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1063 +                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1064 +                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1065 +            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1066 +            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1067 +            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1068 +            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1069 +            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1070 +            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1071 +            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1072 +            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1073 +          }
1074 +          
1075 +        }
1076  
433    if(!eventPassedAllCuts)continue;
1077  
1078 +        //fills histograms with the sizes of collections
1079 +        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1080  
1081 +          string currentObject = objectsToPlot.at(currentObjectIndex);
1082 +          string objectToPlot = "";
1083  
1084 +          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1085 +          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1086 +          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1087 +          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1088 +          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1089 +          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1090 +          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1091 +          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1092 +          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1093 +          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1094 +          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1095 +          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1096 +          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1097 +          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1098 +          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1099 +          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1100 +          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1101 +          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1102 +          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1103 +          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1104 +          else objectToPlot = currentObject;
1105 +
1106 +          string tempCurrentObject = objectToPlot;
1107 +          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1108 +          string histoName = "num" + tempCurrentObject;
1109 +
1110 +          //set position of primary vertex in event, in order to calculate quantities relative to it
1111 +          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1112 +            vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1113 +            int numToPlot = 0;
1114 +            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1115 +              if(lastCutFlags.at(currentFlag)) numToPlot++;
1116 +            }
1117 +            if(objectToPlot == "primaryvertexs"){
1118 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1119 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1120 +            }
1121 +            else {
1122 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1123 +            }
1124 +          }
1125 +        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1126 +        
1127 +        if (!BNTrees_.at(currentChannelIndex)) { cout << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }  
1128 +        BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts  
1129  
1130 <    //set position of primary vertex in event, in order to calculate quantities relative to it
1131 <    primaryVertex_ = 0;
1132 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back();
1133 <    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
442 <      if(!vertexFlags.at(vertexIndex)) continue;
443 <      primaryVertex_ = new BNprimaryvertex (primaryvertexs->at (vertexIndex));
444 <      break;
445 <    }
1130 >      } // end if(eventPassedPreviousCuts.at(currentDir)){
1131 >    } // end loop over cuts
1132 >    
1133 >  } // end loop over channel
1134  
1135  
1136 <    //filling histograms
449 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
450 <      histogram currentHistogram = histograms.at(histogramIndex);
1136 >  masterCutFlow_->fillCutFlow(masterScaleFactor);
1137  
452      if(currentHistogram.inputVariables.size() == 1){
453        TH1D* histo;
454        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
455        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
456        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
457        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),\
458                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(),\
459                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
460        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
461        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
462                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
463                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
464        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
465                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
466                                                                                              cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
467        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
468        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
469        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
470        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
471        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
472        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
473        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
474        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
475        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
476        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
477      }
478      else if(currentHistogram.inputVariables.size() == 2){
479        TH2D* histo;
480        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
481        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
482        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
483        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
484                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
485                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
486        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
487        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
488                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
489                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
490        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
491                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
492                                                                                               cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
493        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
494        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
495        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
496        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
497        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
498        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
499        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
500        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
501        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
502        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
503      }
504    }
505
506
507    //fills histograms with the sizes of collections
508    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
509      string currentObject = objectsToPlot.at(currentObjectIndex);
510
511      if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
512      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
513      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
514      string tempCurrentObject = currentObject;
515      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
516      string histoName = "num" + tempCurrentObject;
517
518
519      if(currentObject == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),puScaleFactor);
520      else if(currentObject == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),puScaleFactor);
521      else if(currentObject == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,puScaleFactor);
522      else if(currentObject == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),puScaleFactor);
523      else if(currentObject == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,puScaleFactor);
524      else if(currentObject == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),puScaleFactor);
525      else if(currentObject == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),puScaleFactor);
526      else if(currentObject == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),puScaleFactor);
527      else if(currentObject == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),puScaleFactor);
528      else if(currentObject == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),puScaleFactor);
529      else if(currentObject == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),puScaleFactor);
530      else if(currentObject == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),puScaleFactor);
531      else if(currentObject == "primaryvertexs"){
532        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
533        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),puScaleFactor);
534      }
535      else if(currentObject == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),puScaleFactor);
536      else if(currentObject == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),puScaleFactor);
537      else if(currentObject == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),puScaleFactor);
1138  
1139 <    }
540 <  } //end loop over channel
1139 > } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1140  
542  masterCutFlow_->fillCutFlow(puScaleFactor);
1141  
1142  
1143 + bool
1144 + OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
1145  
546 }
1146  
1147 +  if(comparison == ">")       return testValue >  cutValue;
1148 +  else if(comparison == ">=") return testValue >= cutValue;
1149 +  else if(comparison == "<")  return testValue <  cutValue;
1150 +  else if(comparison == "<=") return testValue <= cutValue;
1151 +  else if(comparison == "==") return testValue == cutValue;
1152 +  else if(comparison == "=") return testValue == cutValue;
1153 +  else if(comparison == "!=") return testValue != cutValue;
1154 +  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1155 +
1156 + }
1157  
1158   bool
1159 < OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
1159 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1160  
1161  
1162    if(comparison == ">")       return testValue >  cutValue;
# Line 557 | Line 1166 | OSUAnalysis::evaluateComparison (double
1166    else if(comparison == "==") return testValue == cutValue;
1167    else if(comparison == "=") return testValue == cutValue;
1168    else if(comparison == "!=") return testValue != cutValue;
1169 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1169 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1170  
1171   }
1172  
1173   bool
1174 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1174 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1175  
1176 +  //initialize to false until a chosen trigger is passed
1177    bool triggerDecision = false;
1178  
1179 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1180 <    {
1181 <      if(trigger->pass != 1) continue;
1182 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1183 <        {
1184 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1185 <            triggerDecision = true;
1186 <          }
1187 <        }
1179 >  if (printAllTriggers_) cout << "Printing list of all available triggers (which this event may or may not pass):" << endl;  
1180 >  //loop over all triggers defined in the event
1181 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1182 >
1183 >    if (printAllTriggers_) cout << "   " << trigger->name << endl;  
1184 >
1185 >    //we're only interested in triggers that actually passed
1186 >    if(trigger->pass != 1) continue;
1187 >
1188 >    //if the event passes one of the veto triggers, exit and return false
1189 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1190 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1191      }
1192 <  return triggerDecision;
1192 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1193 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1194 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1195 >    }  
1196 >  }
1197 >
1198 >  printAllTriggers_ = false;  // only print triggers once, not every event  
1199  
1200 +  //if none of the veto triggers fired:
1201 +  //return the OR of all the chosen triggers
1202 +  if (triggersToTest.size() != 0) return triggerDecision;
1203 +  //or if no triggers were defined return true
1204 +  else return true;
1205   }
1206  
1207 < std::vector<std::string>
1207 >
1208 > vector<string>
1209   OSUAnalysis::splitString (string inputString){
1210  
1211 <  std::stringstream stringStream(inputString);
1212 <  std::istream_iterator<std::string> begin(stringStream);
1213 <  std::istream_iterator<std::string> end;
1214 <  std::vector<std::string> stringVector(begin, end);
1211 >  stringstream stringStream(inputString);
1212 >  istream_iterator<string> begin(stringStream);
1213 >  istream_iterator<string> end;
1214 >  vector<string> stringVector(begin, end);
1215    return stringVector;
1216  
1217   }
1218  
1219 +
1220 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1221 +  // Set two object strings from the tempInputCollection string,
1222 +  // For example, if tempInputCollection is "electron-muon pairs",
1223 +  // then obj1 = "electrons" and obj2 = "muons".
1224 +  // Note that the objects have an "s" appended.
1225 +
1226 +  int dashIndex = tempInputCollection.find("-");
1227 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1228 +  int secondWordLength = spaceIndex - dashIndex;
1229 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1230 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1231 +
1232 + }
1233 +
1234 +
1235 + string OSUAnalysis::getObjToGet(string obj) {
1236 +  // Return the string corresponding to the object to get for the given obj string.
1237 +  // Right now this only handles the case in which obj contains "secondary",
1238 +  // e.g, "secondary muons".
1239 +  // Note that "s" is NOT appended.
1240 +
1241 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1242 +  int firstSpaceIndex = obj.find_first_of(" ");
1243 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1244 +
1245 + }
1246 +
1247 +
1248 + //!jet valueLookup
1249   double
1250 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1250 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1251  
1252    double value = 0.0;
1253    if(variable == "energy") value = object->energy;
# Line 712 | Line 1367 | OSUAnalysis::valueLookup (const BNjet* o
1367    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1368  
1369  
1370 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1370 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1371  
1372    value = applyFunction(function, value);
1373  
# Line 720 | Line 1375 | OSUAnalysis::valueLookup (const BNjet* o
1375   }
1376  
1377  
1378 <
1378 > //!muon valueLookup
1379   double
1380 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1380 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1381  
1382    double value = 0.0;
1383    if(variable == "energy") value = object->energy;
# Line 738 | Line 1393 | OSUAnalysis::valueLookup (const BNmuon*
1393    else if(variable == "ecalIso") value = object->ecalIso;
1394    else if(variable == "hcalIso") value = object->hcalIso;
1395    else if(variable == "caloIso") value = object->caloIso;
1396 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
1396 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
1397    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
1398    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
1399    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 877 | Line 1532 | OSUAnalysis::valueLookup (const BNmuon*
1532    else if(variable == "time_ndof") value = object->time_ndof;
1533  
1534    //user-defined variables
1535 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1536 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1535 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1536 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1537    else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1538 <  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1538 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1539    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1540 +  else if(variable == "metMT") {
1541 +    if (const BNmet *met = chosenMET ())
1542 +      {
1543 +        double dPhi = deltaPhi (object->phi, met->phi);
1544 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1545 +      }
1546 +    else
1547 +      value = -999;
1548 +  }
1549 +
1550 +
1551 +
1552 +  else if(variable == "correctedD0VertexInEBPlus"){
1553 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1554 +    else value = -999;
1555 +  }
1556 +  else if(variable == "correctedD0VertexOutEBPlus"){
1557 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1558 +    else value = -999;
1559 +  }
1560 +  else if(variable == "correctedD0VertexEEPlus"){
1561 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1562 +    else value = -999;
1563 +  }
1564 +
1565 +  else if(variable == "correctedD0BeamspotInEBPlus"){
1566 +    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1567 +    else value = -999;
1568 +  }
1569 +  else if(variable == "correctedD0BeamspotOutEBPlus"){
1570 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1571 +    else value = -999;
1572 +  }
1573 +  else if(variable == "correctedD0BeamspotEEPlus"){
1574 +    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1575 +    else value = -999;
1576 +  }
1577 +
1578 +  else if(variable == "correctedD0VertexInEBMinus"){
1579 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1580 +    else value = -999;
1581 +  }
1582 +  else if(variable == "correctedD0VertexOutEBMinus"){
1583 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1584 +    else value = -999;
1585 +  }
1586 +  else if(variable == "correctedD0VertexEEMinus"){
1587 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1588 +    else value = -999;
1589 +  }
1590 +
1591 +  else if(variable == "correctedD0BeamspotInEBMinus"){
1592 +    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1593 +    else value = -999;
1594 +  }
1595 +  else if(variable == "correctedD0BeamspotOutEBMinus"){
1596 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1597 +    else value = -999;
1598 +  }
1599 +  else if(variable == "correctedD0BeamspotEEMinus"){
1600 +    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1601 +    else value = -999;
1602 +  }
1603 +
1604 +
1605 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1606 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1607 +    else value = -999;
1608 +  }
1609 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1610 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1611 +    else value = -999;
1612 +  }
1613 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
1614 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1615 +    else value = -999;
1616 +  }
1617 +
1618 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1619 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1620 +    else value = -999;
1621 +  }
1622 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1623 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1624 +    else value = -999;
1625 +  }
1626 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1627 +    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1628 +    else value = -999;
1629 +  }
1630 +
1631 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1632 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1633 +    else value = -999;
1634 +  }
1635 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1636 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1637 +    else value = -999;
1638 +  }
1639 +  else if(variable == "correctedD0VertexEENegativeCharge"){
1640 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1641 +    else value = -999;
1642 +  }
1643 +
1644 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1645 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1646 +    else value = -999;
1647 +  }
1648 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1649 +    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1650 +    else value = -999;
1651 +  }
1652 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1653 +    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1654 +    else value = -999;
1655 +  }
1656 +
1657 +
1658    else if(variable == "tightID") {
1659 <    value = object->isGlobalMuon > 0            \
1660 <      && object->isPFMuon > 0                   \
1661 <      && object->normalizedChi2 < 10            \
1662 <      && object->numberOfValidMuonHits > 0      \
1663 <      && object->numberOfMatchedStations > 1    \
1664 <      && fabs(object->correctedD0Vertex) < 0.2  \
1665 <      && fabs(object->correctedDZ) < 0.5        \
1666 <      && object->numberOfValidPixelHits > 0             \
1659 >    value = object->isGlobalMuon > 0                \
1660 >      && object->isPFMuon > 0                        \
1661 >      && object->normalizedChi2 < 10                \
1662 >      && object->numberOfValidMuonHits > 0        \
1663 >      && object->numberOfMatchedStations > 1        \
1664 >      && fabs(object->correctedD0Vertex) < 0.2        \
1665 >      && fabs(object->correctedDZ) < 0.5        \
1666 >      && object->numberOfValidPixelHits > 0                \
1667        && object->numberOfLayersWithMeasurement > 5;
1668    }
1669    else if(variable == "tightIDdisplaced"){
1670 <    value = object->isGlobalMuon > 0            \
1671 <      && object->normalizedChi2 < 10            \
1672 <      && object->numberOfValidMuonHits > 0      \
1673 <      && object->numberOfMatchedStations > 1    \
1674 <      && object->numberOfValidPixelHits > 0     \
1670 >    value = object->isGlobalMuon > 0                \
1671 >      && object->isPFMuon > 0                        \
1672 >      && object->normalizedChi2 < 10                \
1673 >      && object->numberOfValidMuonHits > 0        \
1674 >      && object->numberOfMatchedStations > 1        \
1675 >      && object->numberOfValidPixelHits > 0        \
1676        && object->numberOfLayersWithMeasurement > 5;
1677    }
1678  
1679 < //   else if(variable == "genMatchedID"){
906 < //     value = getGenMatchedParticle(object)->id;
907 < //   }
908 < //   else if(variable == "genMatchedMotherID"){
909 < //     value = getGenMatchedParticle(object)->motherId;
910 < //   }
911 < //   else if(variable == "genMatchedGrandmotherID"){
912 < //     value = getGenMatchedParticle(object)->grandMotherId;
913 < //   }
1679 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1680  
1681 +  else if(variable == "genMatchedPdgId"){
1682 +    int index = getGenMatchedParticleIndex(object);
1683 +    if(index == -1) value = 0;
1684 +    else value = mcparticles->at(index).id;
1685 +  }
1686  
1687 +  else if(variable == "genMatchedId"){
1688 +    int index = getGenMatchedParticleIndex(object);
1689 +    if(index == -1) value = 0;
1690 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
1691 +  }
1692 +  else if(variable == "genMatchedMotherId"){
1693 +    int index = getGenMatchedParticleIndex(object);
1694 +    if(index == -1) value = 0;
1695 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1696 +  }
1697 +  else if(variable == "genMatchedMotherIdReverse"){
1698 +    int index = getGenMatchedParticleIndex(object);
1699 +    if(index == -1) value = 24;
1700 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1701 +  }
1702 +  else if(variable == "genMatchedGrandmotherId"){
1703 +    int index = getGenMatchedParticleIndex(object);
1704 +    if(index == -1) value = 0;
1705 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1706 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1707 +      if(motherIndex == -1) value = 0;
1708 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1709 +    }
1710 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1711 +  }
1712 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1713 +    int index = getGenMatchedParticleIndex(object);
1714 +    if(index == -1) value = 24;
1715 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1716 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1717 +      if(motherIndex == -1) value = 24;
1718 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1719 +    }
1720 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1721 +  }
1722 +  else if(variable == "pfMuonsFromVertex"){
1723 +    double d0Error, dzError;
1724  
1725 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1725 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1726 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1727 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1728 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1729 >      || fabs (object->correctedDZ / dzError) > 99.0;
1730 >    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1731 >  }
1732 >
1733 >
1734 >
1735 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1736  
1737    value = applyFunction(function, value);
1738  
1739    return value;
1740   }
1741  
1742 <
1742 > //!electron valueLookup
1743   double
1744 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1744 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1745  
1746    double value = 0.0;
1747    if(variable == "energy") value = object->energy;
# Line 1084 | Line 1902 | OSUAnalysis::valueLookup (const BNelectr
1902    else if(variable == "passConvVeto") value = object->passConvVeto;
1903  
1904    //user-defined variables
1905 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1906 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (primaryVertex_->xError, primaryVertex_->yError));
1905 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1906 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1907    else if(variable == "detIso") value = (object->trackIso) / object->pt;
1908    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1909 <  else if(variable == "correctedD0VertexInEB"){
1910 <    if(fabs(object->eta) < 0.8) value = object->correctedD0Vertex;
1909 >  else if(variable == "metMT") {
1910 >    if (const BNmet *met = chosenMET ())
1911 >      {
1912 >        double dPhi = deltaPhi (object->phi, met->phi);
1913 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1914 >      }
1915 >    else
1916 >      value = -999;
1917 >  }
1918 >
1919 >  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
1920 >    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
1921      else value = -999;
1922    }
1923 <  else if(variable == "correctedD0VertexOutEB"){
1924 <    if(object->isEB && fabs(object->eta) > 0.8) value = object->correctedD0Vertex;
1923 >  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
1924 >    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
1925 >    else value = -999;
1926 >  }
1927 >
1928 >  else if(variable == "correctedD0VertexInEBPlus"){
1929 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1930      else value = -999;
1931    }
1932 <  else if(variable == "correctedD0VertexEE"){
1933 <    if(object->isEE) value = object->correctedD0Vertex;
1932 >  else if(variable == "correctedD0VertexOutEBPlus"){
1933 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1934 >    else value = -999;
1935 >  }
1936 >  else if(variable == "correctedD0VertexEEPlus"){
1937 >    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
1938 >    else value = -999;
1939 >  }
1940 >
1941 >  else if(variable == "correctedD0BeamspotInEBPlus"){
1942 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1943 >    else value = -999;
1944 >  }
1945 >  else if(variable == "correctedD0BeamspotOutEBPlus"){
1946 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1947 >    else value = -999;
1948 >  }
1949 >  else if(variable == "correctedD0BeamspotEEPlus"){
1950 >    if(object->isEE && object->eta > 0) value = object->correctedD0;
1951      else value = -999;
1952    }
1953  
1954 <  else if(variable == "correctedD0BeamspotInEB"){
1955 <    if(fabs(object->eta) < 0.8) value = object->correctedD0;
1954 >  else if(variable == "correctedD0VertexInEBMinus"){
1955 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1956      else value = -999;
1957    }
1958 <  else if(variable == "correctedD0BeamspotOutEB"){
1959 <    if(object->isEB && fabs(object->eta) > 0.8) value = object->correctedD0;
1958 >  else if(variable == "correctedD0VertexOutEBMinus"){
1959 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1960      else value = -999;
1961    }
1962 <  else if(variable == "correctedD0BeamspotEE"){
1963 <    if(object->isEE) value = object->correctedD0;
1962 >  else if(variable == "correctedD0VertexEEMinus"){
1963 >    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
1964      else value = -999;
1965    }
1966  
1967 <  else if(variable == "correctedD0OriginInEB"){
1968 <    if(fabs(object->eta) < 0.8) value = object->tkD0;
1967 >  else if(variable == "correctedD0BeamspotInEBMinus"){
1968 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1969      else value = -999;
1970    }
1971 <  else if(variable == "correctedD0OriginOutEB"){
1972 <    if(object->isEB && fabs(object->eta) > 0.8) value = object->tkD0;
1971 >  else if(variable == "correctedD0BeamspotOutEBMinus"){
1972 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1973      else value = -999;
1974    }
1975 <  else if(variable == "correctedD0OriginEE"){
1976 <    if(object->isEE) value = object->tkD0;
1975 >  else if(variable == "correctedD0BeamspotEEMinus"){
1976 >    if(object->isEE && object->eta < 0) value = object->correctedD0;
1977      else value = -999;
1978    }
1979  
1980 +  else if(variable == "tightID"){
1981 +    if (object->isEB)
1982 +      {
1983 +        value = fabs(object->delEtaIn) < 0.004 \
1984 +          && fabs (object->delPhiIn) < 0.03 \
1985 +          && object->scSigmaIEtaIEta < 0.01 \
1986 +          && object->hadOverEm < 0.12 \
1987 +          && fabs (object->correctedD0Vertex) < 0.02 \
1988 +          && fabs (object->correctedDZ) < 0.1 \
1989 +          && object->absInvEMinusInvPin < 0.05 \
1990 +          && object->passConvVeto;
1991 +      }
1992 +    else
1993 +      {
1994 +        value = fabs(object->delEtaIn) < 0.005 \
1995 +          && fabs (object->delPhiIn) < 0.02 \
1996 +          && object->scSigmaIEtaIEta < 0.03 \
1997 +          && object->hadOverEm < 0.10 \
1998 +          && fabs (object->correctedD0Vertex) < 0.02 \
1999 +          && fabs (object->correctedDZ) < 0.1 \
2000 +          && object->absInvEMinusInvPin < 0.05 \
2001 +          && object->passConvVeto;
2002 +      }
2003 +  }
2004 +
2005 +  else if(variable == "correctedD0VertexInEBPositiveCharge"){
2006 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2007 +    else value = -999;
2008 +  }
2009 +  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
2010 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2011 +    else value = -999;
2012 +  }
2013 +  else if(variable == "correctedD0VertexEEPositiveCharge"){
2014 +    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
2015 +    else value = -999;
2016 +  }
2017 +
2018 +  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
2019 +    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
2020 +    else value = -999;
2021 +  }
2022 +  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
2023 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
2024 +    else value = -999;
2025 +  }
2026 +  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
2027 +    if(object->isEE && object->charge > 0) value = object->correctedD0;
2028 +    else value = -999;
2029 +  }
2030 +
2031 +  else if(variable == "correctedD0VertexInEBNegativeCharge"){
2032 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2033 +    else value = -999;
2034 +  }
2035 +  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
2036 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2037 +    else value = -999;
2038 +  }
2039 +  else if(variable == "correctedD0VertexEENegativeCharge"){
2040 +    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
2041 +    else value = -999;
2042 +  }
2043 +
2044 +  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
2045 +    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
2046 +    else value = -999;
2047 +  }
2048 +  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
2049 +    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
2050 +    else value = -999;
2051 +  }
2052 +  else if(variable == "correctedD0BeamspotEENegativeCharge"){
2053 +    if(object->isEE && object->charge < 0) value = object->correctedD0;
2054 +    else value = -999;
2055 +  }
2056 +
2057 +
2058    else if(variable == "tightIDdisplaced"){
2059      if (object->isEB)
2060        {
2061 <        value = fabs(object->delEtaIn) < 0.004 \
2062 <          && fabs (object->delPhiIn) < 0.03 \
2061 >        value = fabs(object->delEtaIn) < 0.004 \
2062 >          && fabs (object->delPhiIn) < 0.03 \
2063            && object->scSigmaIEtaIEta < 0.01 \
2064            && object->hadOverEm < 0.12 \
2065 <          && object->absInvEMinusInvPin < 0.05;
2065 >          && object->absInvEMinusInvPin < 0.05;
2066        }
2067      else
2068        {
2069 <        value = fabs (object->delEtaIn) < 0.005 \
2070 <          && fabs (object->delPhiIn) < 0.02 \
2069 >        value = fabs (object->delEtaIn) < 0.005 \
2070 >          && fabs (object->delPhiIn) < 0.02 \
2071            && object->scSigmaIEtaIEta < 0.03 \
2072            && object->hadOverEm < 0.10 \
2073 <          && object->absInvEMinusInvPin < 0.05;
2073 >          && object->absInvEMinusInvPin < 0.05;
2074        }
2075    }
2076  
2077 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2077 >
2078 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2079 >
2080 >  else if(variable == "genMatchedPdgId"){
2081 >    int index = getGenMatchedParticleIndex(object);
2082 >    if(index == -1) value = 0;
2083 >    else value = mcparticles->at(index).id;
2084 >  }
2085 >
2086 >
2087 >  else if(variable == "genMatchedId"){
2088 >    int index = getGenMatchedParticleIndex(object);
2089 >    if(index == -1) value = 0;
2090 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2091 >  }
2092 >  else if(variable == "genMatchedMotherId"){
2093 >    int index = getGenMatchedParticleIndex(object);
2094 >    if(index == -1) value = 0;
2095 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2096 >  }
2097 >  else if(variable == "genMatchedMotherIdReverse"){
2098 >    int index = getGenMatchedParticleIndex(object);
2099 >    if(index == -1) value = 24;
2100 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2101 >  }
2102 >  else if(variable == "genMatchedGrandmotherId"){
2103 >    int index = getGenMatchedParticleIndex(object);
2104 >    if(index == -1) value = 0;
2105 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2106 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2107 >      if(motherIndex == -1) value = 0;
2108 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2109 >    }
2110 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2111 >  }
2112 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2113 >    int index = getGenMatchedParticleIndex(object);
2114 >    if(index == -1) value = 24;
2115 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2116 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2117 >      if(motherIndex == -1) value = 24;
2118 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2119 >    }
2120 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2121 >  }
2122 >  else if(variable == "pfElectronsFromVertex"){
2123 >    double d0Error, dzError;
2124 >
2125 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2126 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2127 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2128 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2129 >      || fabs (object->correctedDZ / dzError) > 99.0;
2130 >    value = !value;
2131 >  }
2132 >
2133 >
2134 >
2135 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2136  
2137    value = applyFunction(function, value);
2138  
2139    return value;
2140   }
2141  
2142 <
2142 > //!event valueLookup
2143   double
2144 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2144 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2145  
2146    double value = 0.0;
2147  
# Line 1223 | Line 2209 | OSUAnalysis::valueLookup (const BNevent*
2209    else if(variable == "id1") value = object->id1;
2210    else if(variable == "id2") value = object->id2;
2211    else if(variable == "evt") value = object->evt;
2212 <
2213 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2212 >  else if(variable == "puScaleFactor"){
2213 >    if(doPileupReweighting_ && datasetType_ != "data")
2214 >      value = puWeight_->at (events->at (0).numTruePV);
2215 >    else
2216 >      value = 1.0;
2217 >  }
2218 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2219 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2220 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2221 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2222 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2223  
2224    value = applyFunction(function, value);
2225  
2226    return value;
2227   }
2228  
2229 + //!tau valueLookup
2230   double
2231 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2231 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2232  
2233    double value = 0.0;
2234  
# Line 1277 | Line 2273 | OSUAnalysis::valueLookup (const BNtau* o
2273    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2274  
2275  
2276 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2276 >
2277 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2278 >
2279 >  else if(variable == "genMatchedPdgId"){
2280 >    int index = getGenMatchedParticleIndex(object);
2281 >    if(index == -1) value = 0;
2282 >    else value = mcparticles->at(index).id;
2283 >  }
2284 >
2285 >  else if(variable == "genMatchedId"){
2286 >    int index = getGenMatchedParticleIndex(object);
2287 >    if(index == -1) value = 0;
2288 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2289 >  }
2290 >  else if(variable == "genMatchedMotherId"){
2291 >    int index = getGenMatchedParticleIndex(object);
2292 >    if(index == -1) value = 0;
2293 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2294 >  }
2295 >  else if(variable == "genMatchedMotherIdReverse"){
2296 >    int index = getGenMatchedParticleIndex(object);
2297 >    if(index == -1) value = 24;
2298 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2299 >  }
2300 >  else if(variable == "genMatchedGrandmotherId"){
2301 >    int index = getGenMatchedParticleIndex(object);
2302 >    if(index == -1) value = 0;
2303 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2304 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2305 >      if(motherIndex == -1) value = 0;
2306 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2307 >    }
2308 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2309 >  }
2310 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2311 >    int index = getGenMatchedParticleIndex(object);
2312 >    if(index == -1) value = 24;
2313 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2314 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2315 >      if(motherIndex == -1) value = 24;
2316 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2317 >    }
2318 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2319 >  }
2320 >
2321 >
2322 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2323  
2324    value = applyFunction(function, value);
2325  
2326    return value;
2327   }
2328  
2329 + //!met valueLookup
2330   double
2331 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2331 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2332  
2333    double value = 0.0;
2334  
# Line 1349 | Line 2392 | OSUAnalysis::valueLookup (const BNmet* o
2392    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2393    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2394  
2395 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2395 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2396  
2397    value = applyFunction(function, value);
2398  
2399    return value;
2400   }
2401  
2402 + //!track valueLookup
2403   double
2404 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2404 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2405  
2406    double value = 0.0;
2407 +  double pMag = sqrt(object->pt * object->pt +
2408 +                     object->pz * object->pz);
2409  
2410    if(variable == "pt") value = object->pt;
2411    else if(variable == "px") value = object->px;
# Line 1380 | Line 2426 | OSUAnalysis::valueLookup (const BNtrack*
2426    else if(variable == "isHighPurity") value = object->isHighPurity;
2427  
2428  
2429 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2429 >  //additional BNs info for disappTrks
2430 >  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2431 >  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2432 >  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2433 >  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2434 >  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2435 >  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2436 >  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2437 >  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2438 >  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2439 >  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2440 >  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2441 >
2442 >  //user defined variables
2443 >  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;
2444 >  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2445 >  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2446 >  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2447 >  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2448 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2449 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2450 >  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2451 >  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2452 >  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2453 >  else if(variable == "ptError")                    value = object->ptError;
2454 >  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2455 >  else if (variable == "d0wrtPV"){
2456 >    double vx = object->vx - chosenVertex ()->x,
2457 >      vy = object->vy - chosenVertex ()->y,
2458 >      px = object->px,
2459 >      py = object->py,
2460 >      pt = object->pt;
2461 >    value = (-vx * py + vy * px) / pt;
2462 >  }
2463 >  else if (variable == "dZwrtPV"){
2464 >    double vx = object->vx - chosenVertex ()->x,
2465 >      vy = object->vy - chosenVertex ()->y,
2466 >      vz = object->vz - chosenVertex ()->z,
2467 >      px = object->px,
2468 >      py = object->py,
2469 >      pz = object->pz,
2470 >      pt = object->pt;
2471 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2472 >  }
2473 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2474 >
2475 >  else if(variable == "genMatchedPdgId"){
2476 >    int index = getGenMatchedParticleIndex(object);
2477 >    if(index == -1) value = 0;
2478 >    else value = mcparticles->at(index).id;
2479 >  }
2480 >
2481 >
2482 >  else if(variable == "genMatchedId"){
2483 >    int index = getGenMatchedParticleIndex(object);
2484 >    if(index == -1) value = 0;
2485 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2486 >  }
2487 >  else if(variable == "genMatchedMotherId"){
2488 >    int index = getGenMatchedParticleIndex(object);
2489 >    if(index == -1) value = 0;
2490 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2491 >  }
2492 >  else if(variable == "genMatchedMotherIdReverse"){
2493 >    int index = getGenMatchedParticleIndex(object);
2494 >    if(index == -1) value = 24;
2495 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2496 >  }
2497 >  else if(variable == "genMatchedGrandmotherId"){
2498 >    int index = getGenMatchedParticleIndex(object);
2499 >    if(index == -1) value = 0;
2500 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2501 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2502 >      if(motherIndex == -1) value = 0;
2503 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2504 >    }
2505 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2506 >  }
2507 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2508 >    int index = getGenMatchedParticleIndex(object);
2509 >    if(index == -1) value = 24;
2510 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2511 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2512 >      if(motherIndex == -1) value = 24;
2513 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2514 >    }
2515 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2516 >  }
2517 >
2518 >
2519 >
2520 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2521  
2522    value = applyFunction(function, value);
2523  
2524    return value;
2525   }
2526  
2527 + //!genjet valueLookup
2528   double
2529 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2529 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2530  
2531    double value = 0.0;
2532  
# Line 1408 | Line 2546 | OSUAnalysis::valueLookup (const BNgenjet
2546    else if(variable == "charge") value = object->charge;
2547  
2548  
2549 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2549 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2550  
2551    value = applyFunction(function, value);
2552  
2553    return value;
2554   }
2555  
2556 + //!mcparticle valueLookup
2557   double
2558 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2558 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2559  
2560    double value = 0.0;
2561  
# Line 1507 | Line 2646 | OSUAnalysis::valueLookup (const BNmcpart
2646  
2647    //user-defined variables
2648    else if (variable == "d0"){
2649 <    double vx = object->vx - primaryVertex_->x,
2650 <      vy = object->vy - primaryVertex_->y,
2649 >    double vx = object->vx - chosenVertex ()->x,
2650 >      vy = object->vy - chosenVertex ()->y,
2651        px = object->px,
2652        py = object->py,
2653        pt = object->pt;
2654      value = (-vx * py + vy * px) / pt;
2655    }
2656    else if (variable == "dz"){
2657 <    double vx = object->vx - primaryVertex_->x,
2658 <      vy = object->vy - primaryVertex_->y,
2659 <      vz = object->vz - primaryVertex_->z,
2657 >    double vx = object->vx - chosenVertex ()->x,
2658 >      vy = object->vy - chosenVertex ()->y,
2659 >      vz = object->vz - chosenVertex ()->z,
2660        px = object->px,
2661        py = object->py,
2662        pz = object->pz,
# Line 1528 | Line 2667 | OSUAnalysis::valueLookup (const BNmcpart
2667      value = sqrt(object->vx*object->vx + object->vy*object->vy);
2668    }
2669    else if(variable == "deltaV0"){
2670 <    value = sqrt((object->vx-primaryVertex_->x)*(object->vx-primaryVertex_->x) + (object->vy-primaryVertex_->y)*(object->vy-primaryVertex_->y));
2670 >    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
2671    }
2672    else if (variable == "deltaVx"){
2673 <    value = object->vx - primaryVertex_->x;
2673 >    value = object->vx - chosenVertex ()->x;
2674    }
2675    else if (variable == "deltaVy"){
2676 <    value = object->vy - primaryVertex_->y;
2676 >    value = object->vy - chosenVertex ()->y;
2677    }
2678    else if (variable == "deltaVz"){
2679 <    value = object->vz - primaryVertex_->z;
2679 >    value = object->vz - chosenVertex ()->z;
2680    }
2681  
2682  
2683 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2683 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2684  
2685    value = applyFunction(function, value);
2686  
2687    return value;
2688   }
2689  
2690 + //!primaryvertex valueLookup
2691   double
2692 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2692 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2693  
2694    double value = 0.0;
2695  
# Line 1568 | Line 2708 | OSUAnalysis::valueLookup (const BNprimar
2708    else if(variable == "isGood") value = object->isGood;
2709  
2710  
2711 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2711 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2712  
2713    value = applyFunction(function, value);
2714  
2715    return value;
2716   }
2717  
2718 + //!bxlumi valueLookup
2719   double
2720 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2720 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2721  
2722    double value = 0.0;
2723  
# Line 1585 | Line 2726 | OSUAnalysis::valueLookup (const BNbxlumi
2726    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2727  
2728  
2729 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2729 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2730  
2731    value = applyFunction(function, value);
2732  
2733    return value;
2734   }
2735  
2736 + //!photon valueLookup
2737   double
2738 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2738 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2739  
2740    double value = 0.0;
2741  
# Line 1668 | Line 2810 | OSUAnalysis::valueLookup (const BNphoton
2810    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2811  
2812  
2813 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2813 >
2814 >
2815 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2816 >
2817 >  else if(variable == "genMatchedPdgId"){
2818 >    int index = getGenMatchedParticleIndex(object);
2819 >    if(index == -1) value = 0;
2820 >    else value = mcparticles->at(index).id;
2821 >  }
2822 >
2823 >
2824 >
2825 >  else if(variable == "genMatchedId"){
2826 >    int index = getGenMatchedParticleIndex(object);
2827 >    if(index == -1) value = 0;
2828 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2829 >  }
2830 >  else if(variable == "genMatchedMotherId"){
2831 >    int index = getGenMatchedParticleIndex(object);
2832 >    if(index == -1) value = 0;
2833 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2834 >  }
2835 >  else if(variable == "genMatchedMotherIdReverse"){
2836 >    int index = getGenMatchedParticleIndex(object);
2837 >    if(index == -1) value = 24;
2838 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2839 >  }
2840 >  else if(variable == "genMatchedGrandmotherId"){
2841 >    int index = getGenMatchedParticleIndex(object);
2842 >    if(index == -1) value = 0;
2843 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2844 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2845 >      if(motherIndex == -1) value = 0;
2846 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2847 >    }
2848 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2849 >  }
2850 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2851 >    int index = getGenMatchedParticleIndex(object);
2852 >    if(index == -1) value = 24;
2853 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2854 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2855 >      if(motherIndex == -1) value = 24;
2856 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2857 >    }
2858 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2859 >  }
2860 >
2861 >
2862 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2863  
2864    value = applyFunction(function, value);
2865  
2866    return value;
2867   }
2868  
2869 + //!supercluster valueLookup
2870   double
2871 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
2871 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
2872  
2873    double value = 0.0;
2874  
# Line 1690 | Line 2882 | OSUAnalysis::valueLookup (const BNsuperc
2882    else if(variable == "theta") value = object->theta;
2883  
2884  
2885 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2885 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2886  
2887    value = applyFunction(function, value);
2888  
2889    return value;
2890   }
2891  
2892 + //!trigobj valueLookup
2893 + double
2894 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
2895 +
2896 +  double value = 0.0;
2897 +
2898 +  if(variable == "pt") value = object->pt;
2899 +  else if(variable == "eta") value = object->eta;
2900 +  else if(variable == "phi") value = object->phi;
2901 +  else if(variable == "px") value = object->px;
2902 +  else if(variable == "py") value = object->py;
2903 +  else if(variable == "pz") value = object->pz;
2904 +  else if(variable == "et") value = object->et;
2905 +  else if(variable == "energy") value = object->energy;
2906 +  else if(variable == "etTotal") value = object->etTotal;
2907 +  else if(variable == "id") value = object->id;
2908 +  else if(variable == "charge") value = object->charge;
2909 +  else if(variable == "isIsolated") value = object->isIsolated;
2910 +  else if(variable == "isMip") value = object->isMip;
2911 +  else if(variable == "isForward") value = object->isForward;
2912 +  else if(variable == "isRPC") value = object->isRPC;
2913 +  else if(variable == "bx") value = object->bx;
2914 +  else if(variable == "filter") {
2915 +    if ((stringValue = object->filter) == "")
2916 +      stringValue = "none";  // stringValue should only be empty if value is filled
2917 +  }
2918 +
2919 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2920  
2921 +  value = applyFunction(function, value);
2922 +
2923 +  return value;
2924 + }
2925 +
2926 + //!muon-muon pair valueLookup
2927   double
2928 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
2928 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
2929  
2930    double value = 0.0;
2931  
2932 <  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
2932 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2933 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2934 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2935    else if(variable == "invMass"){
2936      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2937      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2938 <
2939 <    value = (fourVector1 + fourVector2).M();}
2938 >    value = (fourVector1 + fourVector2).M();
2939 >  }
2940 >  else if(variable == "pt"){
2941 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2942 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2943 >    value = (fourVector1 + fourVector2).Pt();
2944 >  }
2945    else if(variable == "threeDAngle")
2946      {
2947        TVector3 threeVector1(object1->px, object1->py, object1->pz);
2948        TVector3 threeVector2(object2->px, object2->py, object2->pz);
2949        value = (threeVector1.Angle(threeVector2));
2950      }
2951 <
2952 <
2953 <
2951 >  else if(variable == "alpha")
2952 >    {
2953 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
2954 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2955 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2956 >      value = (pi-threeVector1.Angle(threeVector2));
2957 >    }
2958    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2959    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2960    else if(variable == "d0Sign"){
# Line 1726 | Line 2963 | OSUAnalysis::valueLookup (const BNmuon*
2963      else if (d0Sign > 0) value = 0.5;
2964      else value = -999;
2965    }
2966 +  else if(variable == "chargeProduct"){
2967 +    value = object1->charge*object2->charge;
2968 +  }
2969    else if(variable == "muon1CorrectedD0Vertex"){
2970      value = object1->correctedD0Vertex;
2971    }
2972    else if(variable == "muon2CorrectedD0Vertex"){
2973      value = object2->correctedD0Vertex;
2974    }
2975 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2976 <
2977 <
2978 <
2979 <
2980 <
2981 <
2975 >  else if(variable == "muon1timeAtIpInOut"){
2976 >    value = object1->timeAtIpInOut;
2977 >  }
2978 >  else if(variable == "muon2timeAtIpInOut"){
2979 >    value = object2->timeAtIpInOut;
2980 >  }
2981 >  else if(variable == "muon1correctedD0")
2982 >    {
2983 >      value = object1->correctedD0;
2984 >    }
2985 >  else if(variable == "muon2correctedD0")
2986 >    {
2987 >      value = object2->correctedD0;
2988 >    }
2989  
2990 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2991  
2992    value = applyFunction(function, value);
2993  
2994    return value;
2995   }
2996  
2997 + //!electron-electron pair valueLookup
2998   double
2999 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
2999 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3000  
3001    double value = 0.0;
3002  
3003 <  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
3003 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3004 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3005 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3006    else if(variable == "invMass"){
3007      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3008      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3009 <
3010 <    value = (fourVector1 + fourVector2).M();}
3011 < else if(variable == "threeDAngle")
3009 >    value = (fourVector1 + fourVector2).M();
3010 >  }
3011 >  else if(variable == "pt"){
3012 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3013 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3014 >    value = (fourVector1 + fourVector2).Pt();
3015 >  }
3016 >  else if(variable == "threeDAngle")
3017      {
3018        TVector3 threeVector1(object1->px, object1->py, object1->pz);
3019        TVector3 threeVector2(object2->px, object2->py, object2->pz);
3020        value = (threeVector1.Angle(threeVector2));
3021      }
1766  
1767
1768
1769
3022    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3023    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
1772
1773
1774
1775
1776
3024    else if(variable == "d0Sign"){
3025      double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3026      if(d0Sign < 0) value = -0.5;
3027      else if (d0Sign > 0) value = 0.5;
3028      else value = -999;
3029    }
3030 +  else if(variable == "chargeProduct"){
3031 +    value = object1->charge*object2->charge;
3032 +  }
3033    else if(variable == "electron1CorrectedD0Vertex"){
3034      value = object1->correctedD0Vertex;
3035    }
3036    else if(variable == "electron2CorrectedD0Vertex"){
3037      value = object2->correctedD0Vertex;
3038    }
3039 +  else if(variable == "electron1CorrectedD0"){
3040 +    value = object1->correctedD0;
3041 +  }
3042 +  else if(variable == "electron2CorrectedD0"){
3043 +    value = object2->correctedD0;
3044 +  }
3045  
3046 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3046 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3047  
3048    value = applyFunction(function, value);
3049  
3050    return value;
3051   }
3052 <
3052 > //!electron-muon pair valueLookup
3053   double
3054 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3054 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3055  
3056    double value = 0.0;
3057  
3058 <  if(variable == "deltaPhi") value = deltaPhi(object1->phi,object2->phi);
3058 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3059 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3060 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3061    else if(variable == "invMass"){
3062      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3063      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3064 <
3065 <    value = (fourVector1 + fourVector2).M();}
3066 < else if(variable == "threeDAngle")
3064 >    value = (fourVector1 + fourVector2).M();
3065 >  }
3066 >  else if(variable == "pt"){
3067 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3068 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3069 >    value = (fourVector1 + fourVector2).Pt();
3070 >  }
3071 >  else if(variable == "threeDAngle")
3072      {
3073        TVector3 threeVector1(object1->px, object1->py, object1->pz);
3074        TVector3 threeVector2(object2->px, object2->py, object2->pz);
3075        value = (threeVector1.Angle(threeVector2));
3076      }
1814  
1815
1816
1817
3077    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3078    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3079    else if(variable == "d0Sign"){
# Line 1823 | Line 3082 | OSUAnalysis::valueLookup (const BNelectr
3082      else if (d0Sign > 0) value = 0.5;
3083      else value = -999;
3084    }
3085 +  else if(variable == "chargeProduct"){
3086 +    value = object1->charge*object2->charge;
3087 +  }
3088    else if(variable == "electronCorrectedD0Vertex"){
3089      value = object1->correctedD0Vertex;
3090    }
3091    else if(variable == "muonCorrectedD0Vertex"){
3092      value = object2->correctedD0Vertex;
3093    }
3094 +  else if(variable == "electronCorrectedD0"){
3095 +    value = object1->correctedD0;
3096 +  }
3097 +  else if(variable == "muonCorrectedD0"){
3098 +    value = object2->correctedD0;
3099 +  }
3100 +  else if(variable == "electronDetIso"){
3101 +    value = (object1->trackIso) / object1->pt;
3102 +  }
3103 +  else if(variable == "muonDetIso"){
3104 +    value = (object2->trackIsoDR03) / object2->pt;
3105 +  }
3106 +  else if(variable == "electronRelPFrhoIso"){
3107 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3108 +  }
3109 +  else if(variable == "muonRelPFdBetaIso"){
3110 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3111 +  }
3112 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3113 +  value = applyFunction(function, value);
3114 +
3115 +  return value;
3116 + }
3117 +
3118 + //!electron-jet pair valueLookup
3119 + double
3120 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3121 +
3122 +  double value = 0.0;
3123 +
3124 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3125 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3126 +  else if(variable == "jetEta") value = object2->eta;
3127 +  else if(variable == "jetPhi") value = object2->phi;
3128 +  else if(variable == "electronEta") value = object1->eta;
3129 +  else if(variable == "electronPhi") value = object1->phi;
3130 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3131 +  else if(variable == "invMass"){
3132 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3133 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3134 +    value = (fourVector1 + fourVector2).M();
3135 +  }
3136 +  else if(variable == "pt"){
3137 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3138 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3139 +    value = (fourVector1 + fourVector2).Pt();
3140 +  }
3141 +  else if(variable == "threeDAngle")
3142 +    {
3143 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3144 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3145 +      value = (threeVector1.Angle(threeVector2));
3146 +    }
3147 +  else if(variable == "chargeProduct"){
3148 +    value = object1->charge*object2->charge;
3149 +  }
3150 +
3151 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3152 +  value = applyFunction(function, value);
3153 +
3154 +  return value;
3155 + }
3156 +
3157 + //!muon-jet pair valueLookup
3158 + double
3159 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3160 +
3161 +  double value = 0.0;
3162 +
3163 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3164 +  else if(variable == "jetEta") value = object2->eta;
3165 +  else if(variable == "jetPhi") value = object2->phi;
3166 +  else if(variable == "muonEta") value = object1->eta;
3167 +  else if(variable == "muonPhi") value = object1->phi;
3168 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3169 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3170 +  else if(variable == "invMass"){
3171 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3172 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3173 +    value = (fourVector1 + fourVector2).M();
3174 +  }
3175 +  else if(variable == "pt"){
3176 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3177 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3178 +    value = (fourVector1 + fourVector2).Pt();
3179 +  }
3180 +  else if(variable == "threeDAngle")
3181 +    {
3182 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3183 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3184 +      value = (threeVector1.Angle(threeVector2));
3185 +    }
3186 +  else if(variable == "chargeProduct"){
3187 +    value = object1->charge*object2->charge;
3188 +  }
3189 +
3190 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3191 +  value = applyFunction(function, value);
3192 +
3193 +  return value;
3194 + }
3195 +
3196 + //!jet-jet pair valueLookup
3197 + double
3198 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3199 +
3200 +  double value = 0.0;
3201 +
3202 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3203 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3204 +  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3205 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3206 +  else if(variable == "invMass"){
3207 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3208 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3209 +    value = (fourVector1 + fourVector2).M();
3210 +  }
3211 +  else if(variable == "pt"){
3212 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3213 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3214 +    value = (fourVector1 + fourVector2).Pt();
3215 +  }
3216 +  else if(variable == "threeDAngle")
3217 +    {
3218 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3219 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3220 +      value = (threeVector1.Angle(threeVector2));
3221 +    }
3222 +  else if(variable == "chargeProduct"){
3223 +    value = object1->charge*object2->charge;
3224 +  }
3225  
3226 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3227 +  value = applyFunction(function, value);
3228 +
3229 +  return value;
3230 + }
3231 + //!electron-track pair valueLookup
3232 + double
3233 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3234 +  double electronMass = 0.000511;
3235 +  double value = 0.0;
3236 +  TLorentzVector fourVector1(0, 0, 0, 0);
3237 +  TLorentzVector fourVector2(0, 0, 0, 0);
3238 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3239 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3240 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3241 +  else if(variable == "invMass"){
3242 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3243 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3244  
3245 +    value = (fourVector1 + fourVector2).M();
3246 +  }
3247 +  else if(variable == "chargeProduct"){
3248 +    value = object1->charge*object2->charge;
3249 +  }
3250    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3251 +  value = applyFunction(function, value);
3252 +  return value;
3253 +
3254 + }
3255  
3256 +
3257 + //!muon-track pair valueLookup
3258 + double
3259 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3260 +  double pionMass = 0.140;
3261 +  double muonMass = 0.106;
3262 +  double value = 0.0;
3263 +  TLorentzVector fourVector1(0, 0, 0, 0);
3264 +  TLorentzVector fourVector2(0, 0, 0, 0);
3265 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3266 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3267 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3268 +  else if(variable == "invMass"){
3269 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3270 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3271 +
3272 +    value = (fourVector1 + fourVector2).M();
3273 +  }
3274 +  else if(variable == "chargeProduct"){
3275 +    value = object1->charge*object2->charge;
3276 +  }
3277 +
3278 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3279    value = applyFunction(function, value);
3280 +  return value;
3281 + }
3282 +
3283 + //!tau-tau pair valueLookup
3284 + double
3285 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3286 +  double value = 0.0;
3287 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3288 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3289 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3290 +  else if(variable == "invMass"){
3291 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3292 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3293 +    value = (fourVector1 + fourVector2).M();
3294 +  }
3295 +
3296 +  else if(variable == "chargeProduct"){
3297 +    value = object1->charge*object2->charge;
3298 +  }
3299  
3300 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3301 +  value = applyFunction(function, value);
3302    return value;
3303   }
3304  
3305 + //!muon-tau pair valueLookup
3306 + double
3307 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3308 +  double value = 0.0;
3309 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3310 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3311 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3312 +  else if(variable == "invMass"){
3313 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3314 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3315 +    value = (fourVector1 + fourVector2).M();
3316 +  }
3317 +
3318 +  else if(variable == "chargeProduct"){
3319 +    value = object1->charge*object2->charge;
3320 +  }
3321 +
3322 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3323 +  value = applyFunction(function, value);
3324 +  return value;
3325 + }
3326 +
3327 + //!tau-track pair valueLookup
3328 + double
3329 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3330 +  double value = 0.0;
3331 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3332 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3333 +  else if(variable == "chargeProduct"){
3334 +    value = object1->charge*object2->charge;
3335 +  }
3336 +
3337 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3338 +  value = applyFunction(function, value);
3339 +  return value;
3340 + }
3341 +
3342 +
3343 + //!track-event pair valueLookup
3344 + double
3345 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3346 +
3347 +  double value = 0.0;
3348 +  double pMag = sqrt(object1->pt * object1->pt +
3349 +                     object1->pz * object1->pz);
3350 +
3351 +  if      (variable == "numPV")                      value = object2->numPV;
3352 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3353 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3354 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3355 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3356 +
3357 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3358 +
3359 +  value = applyFunction(function, value);
3360 +
3361 +  return value;
3362 +
3363 + }
3364 +
3365 + //!electron-trigobj pair valueLookup
3366 + double
3367 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3368 +
3369 +  double value = 0.0;
3370 +
3371 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3372 +  else if (variable == "match"){
3373 +    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3374 +      stringValue = object2->filter;
3375 +    else
3376 +      stringValue = "none";
3377 +  }
3378 +
3379 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3380 +
3381 +  value = applyFunction(function, value);
3382 +
3383 +  return value;
3384 +
3385 + }
3386 +
3387 + //!muon-trigobj pair valueLookup
3388 + double
3389 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3390 +
3391 +  double value = 0.0;
3392 +
3393 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3394 +
3395 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3396 +
3397 +  value = applyFunction(function, value);
3398 +
3399 +  return value;
3400 +
3401 + }
3402 +
3403 + //!stop valueLookup
3404 + double
3405 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3406 +
3407 +
3408 +  double value = 0.0;
3409 +
3410 +  if(variable == "ctau") value = object->ctau;
3411 +
3412 +  else if (variable == "d0"){
3413 +    double vx = object->vx - chosenVertex ()->x,
3414 +      vy = object->vy - chosenVertex ()->y,
3415 +      px = object->px,
3416 +      py = object->py,
3417 +      pt = object->pt;
3418 +    value = (-vx * py + vy * px) / pt;
3419 +  }
3420 +
3421 +  else if (variable == "dz"){
3422 +    double vx = object->vx - chosenVertex ()->x,
3423 +      vy = object->vy - chosenVertex ()->y,
3424 +      vz = object->vz - chosenVertex ()->z,
3425 +      px = object->px,
3426 +      py = object->py,
3427 +      pz = object->pz,
3428 +      pt = object->pt;
3429 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3430 +  }
3431 +
3432 +  else if (variable == "minD0"){
3433 +    double minD0=999;
3434 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3435 +      double vx = object->vx - vertex->x,
3436 +        vy = object->vy - vertex->y,
3437 +        px = object->px,
3438 +        py = object->py,
3439 +        pt = object->pt;
3440 +      value = (-vx * py + vy * px) / pt;
3441 +      if(abs(value) < abs(minD0)) minD0 = value;
3442 +    }
3443 +    value = minD0;
3444 +  }
3445 +  else if (variable == "minDz"){
3446 +    double minDz=999;
3447 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3448 +      double vx = object->vx - vertex->x,
3449 +        vy = object->vy - vertex->y,
3450 +        vz = object->vz - vertex->z,
3451 +        px = object->px,
3452 +        py = object->py,
3453 +        pz = object->pz,
3454 +        pt = object->pt;
3455 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3456 +      if(abs(value) < abs(minDz)) minDz = value;
3457 +    }
3458 +    value = minDz;
3459 +  }
3460 +  else if(variable == "distToVertex"){
3461 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3462 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3463 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3464 +  }
3465 +  else if (variable == "minDistToVertex"){
3466 +    double minDistToVertex=999;
3467 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3468 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3469 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3470 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3471 +
3472 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3473 +    }
3474 +    value = minDistToVertex;
3475 +  }
3476 +  else if (variable == "distToVertexDifference"){
3477 +    double minDistToVertex=999;
3478 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3479 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3480 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3481 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3482 +
3483 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3484 +    }
3485 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3486 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3487 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3488 +
3489 +    value = distToChosenVertex - minDistToVertex;
3490 +  }
3491 +
3492 +  else if (variable == "closestVertexRank"){
3493 +    double minDistToVertex=999;
3494 +    int vertex_rank = 0;
3495 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3496 +      vertex_rank++;
3497 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3498 +                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
3499 +                      (object->vz-vertex->z)*(object->vz-vertex->z));
3500 +
3501 +      if(abs(dist) < abs(minDistToVertex)){
3502 +        value = vertex_rank;
3503 +        minDistToVertex = dist;
3504 +      }
3505 +    }
3506 +  }
3507 +
3508 +
3509 +
3510 +
3511 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3512 +
3513 +  value = applyFunction(function, value);
3514 +
3515 +  return value;
3516 +
3517 + }
3518 +
3519 +
3520 +
3521 +
3522 + // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3523 + // Return true iff no other tracks are found in this cone.
3524 + int
3525 + OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
3526 +  for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
3527 +    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
3528 +    double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
3529 +    if(deltaRtrk < 0.5) return 0;
3530 +  }
3531 +  return 1;
3532 +
3533 + }
3534 +
3535 +
3536 + double
3537 + OSUAnalysis::getTrkPtRes (const BNtrack* track1){
3538 +
3539 +  double ptTrue = getTrkPtTrue(track1, mcparticles.product());
3540 +  double PtRes = (track1->pt - ptTrue) / ptTrue;
3541 +
3542 +  return PtRes;
3543 +
3544 + }
3545 +
3546 +
3547 + double
3548 + OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
3549 +  double value = -99;
3550 +  double genDeltaRLowest = 999;
3551 +
3552 +  for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
3553 +    double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
3554 +    if (genDeltaRtemp < genDeltaRLowest) {
3555 +      genDeltaRLowest = genDeltaRtemp;
3556 +      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
3557 +        double ptTrue = genPart->pt;
3558 +        value = ptTrue;
3559 +      }
3560 +    }
3561 +  }
3562 +
3563 +  return value;
3564 +
3565 + }
3566 +
3567 + double
3568 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3569 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3570 +  if (!useTrackCaloRhoCorr_) return -99;
3571 +  // if (!rhokt6CaloJetsHandle_) {
3572 +  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3573 +  //   return -99;
3574 +  // }
3575 +  double radDeltaRCone = 0.5;
3576 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3577 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3578 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3579 +  return caloTotRhoCorrCalo;
3580 +
3581 + }
3582 +
3583 +
3584 +
3585 +
3586 + //creates a map of the dead Ecal channels in the barrel and endcap
3587 + //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
3588 + //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
3589 + void
3590 + OSUAnalysis::WriteDeadEcal (){
3591 +  double etaEcal, phiEcal;
3592 +  ifstream DeadEcalFile(deadEcalFile_);
3593 +  if(!DeadEcalFile) {
3594 +    cout << "Error: DeadEcalFile has not been found." << endl;
3595 +    return;
3596 +  }
3597 +  if(DeadEcalVec.size()!= 0){
3598 +    cout << "Error: DeadEcalVec has a nonzero size" << endl;
3599 +    return;
3600 +  }
3601 +  while(!DeadEcalFile.eof())
3602 +    {
3603 +      DeadEcalFile >> etaEcal >> phiEcal;
3604 +      DeadEcal newChan;
3605 +      newChan.etaEcal = etaEcal;
3606 +      newChan.phiEcal = phiEcal;
3607 +      DeadEcalVec.push_back(newChan);
3608 +    }
3609 +  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
3610 + }
3611 +
3612 + //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
3613 + int
3614 + OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
3615 +  double deltaRLowest = 999;
3616 +  int value = 0;
3617 +  if (DeadEcalVec.size() == 0) WriteDeadEcal();
3618 +  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3619 +    double eta = ecal->etaEcal;
3620 +    double phi = ecal->phiEcal;
3621 +    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
3622 +    if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3623 +  }
3624 +  if (deltaRLowest<0.05) {value = 1;}
3625 +  else {value = 0;}
3626 +  return value;
3627 + }
3628 +
3629 + // Returns the smallest DeltaR between the object and any generated true particle in the event.
3630 + template <class InputObject>
3631 + double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3632 +  double genDeltaRLowest = 999.;
3633 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3634 +    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
3635 +    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
3636 +  }
3637 +  return genDeltaRLowest;
3638 + }
3639  
3640   double
3641   OSUAnalysis::applyFunction(string function, double value){
3642  
3643    if(function == "abs") value = fabs(value);
3644    else if(function == "fabs") value = fabs(value);
3645 <
3645 >  else if(function == "log10") value = log10(value);
3646 >  else if(function == "log") value = log10(value);
3647  
3648    else if(function == "") value = value;
3649 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
3649 >  else{cout << "WARNING: invalid function '" << function << "'\n";}
3650  
3651    return value;
3652  
# Line 1857 | Line 3656 | OSUAnalysis::applyFunction(string functi
3656   template <class InputCollection>
3657   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
3658  
3659 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
3660 +    string obj1, obj2;
3661 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
3662 +    if (inputType==obj1 ||
3663 +        inputType==obj2) {
3664 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
3665 +      // and the inputType is a member of the pair.
3666 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
3667 +      // For example, if currentCut.inputCollection==electron-muon pairs,
3668 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
3669 +      return;
3670 +    }
3671 +  }
3672 +
3673    for (uint object = 0; object != inputCollection->size(); object++){
3674  
3675      bool decision = true;//object passes if this cut doesn't cut on that type of object
# Line 1865 | Line 3678 | void OSUAnalysis::setObjectFlags(cut &cu
3678  
3679        vector<bool> subcutDecisions;
3680        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3681 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3682 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3681 >        string stringValue = "";
3682 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3683 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3684 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3685 >
3686        }
3687        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3688        else{
3689 <        bool tempDecision = true;
3690 <        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
3691 <          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
3692 <            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
3693 <          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
3689 >        bool tempDecision = true;
3690 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
3691 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
3692 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
3693 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
3694              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
3695 <        }
3696 <        decision = tempDecision;
3695 >        }
3696 >        decision = tempDecision;
3697        }
3698      }
3699 +
3700      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3701  
3702      //set flags for objects that pass each cut AND all the previous cuts
# Line 1897 | Line 3714 | void OSUAnalysis::setObjectFlags(cut &cu
3714  
3715   template <class InputCollection1, class InputCollection2>
3716   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
3717 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, string inputType){
3717 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
3718  
3719  
3720    bool sameObjects = false;
3721    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3722  
3723 <  int counter = 0;  
3723 >  // Get the strings for the two objects that make up the pair.
3724 >  string obj1Type, obj2Type;
3725 >  getTwoObjs(inputType, obj1Type, obj2Type);
3726 >  bool isTwoTypesOfObject = true;
3727 >  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
3728 >
3729 >  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
3730 >  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
3731 >  if (currentCut.inputCollection == inputType) {
3732 >    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
3733 >      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3734 >      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3735 >    }
3736 >    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
3737 >      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
3738 >        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3739 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3740 >      }
3741 >    }
3742 >  }
3743 >
3744 >  int counter = 0;
3745 >
3746    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3747      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3748 <      
3748 >
3749        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3750  
3751  
# Line 1914 | Line 3753 | void OSUAnalysis::setObjectFlags(cut &cu
3753  
3754        if(currentCut.inputCollection == inputType){
3755  
3756 <        vector<bool> subcutDecisions;
3757 <        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3758 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3759 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3760 <        }
3756 >        vector<bool> subcutDecisions;
3757 >        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3758 >          string stringValue = "";
3759 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3760 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3761 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3762 >        }
3763  
3764 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3765 <        else{
3766 <          bool tempDecision = true;
3767 <          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
3768 <            if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
3769 <              tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
3770 <            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
3771 <              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
3772 <          }
3773 <          decision = tempDecision;
3774 <        }
3764 >        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3765 >        else{
3766 >          bool tempDecision = subcutDecisions.at(0);
3767 >          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
3768 >            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
3769 >              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
3770 >            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
3771 >              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
3772 >          }
3773 >          decision = tempDecision;
3774 >        }
3775        }
3776 +      // if (decision) isPassObj1.at(object1) = true;
3777 +      // if (decision) isPassObj2.at(object2) = true;
3778        individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3779 <      
3779 >      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3780 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;
3781 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;
3782 >      }
3783 >
3784        //set flags for objects that pass each cut AND all the previous cuts
3785        bool previousCumulativeFlag = true;
3786        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3787 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
3788 <        else{ previousCumulativeFlag = false; break;}
3787 >        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
3788 >        else{ previousCumulativeFlag = false; break;}
3789        }
3790 <      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3790 >      //apply flags for the components of the composite object as well
3791 >      bool currentCumulativeFlag = true;
3792 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
3793 >      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
3794 >      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
3795 >      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
3796 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
3797 >      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3798 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);
3799 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);
3800 >      }
3801 >      counter++;
3802 >
3803 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
3804 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
3805 >
3806 > }
3807 >
3808  
3809 <      counter++;      
3809 > bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
3810 >  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
3811 >  // all cuts up to currentCutIndex
3812 >  bool previousCumulativeFlag = true;
3813 >  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
3814 >    if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
3815 >    else {
3816 >      previousCumulativeFlag = false; break;
3817      }
1947    
3818    }
3819 +  return previousCumulativeFlag;
3820 + }
3821 +
3822  
3823  
3824 + template <class InputCollection>
3825 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, vector<bool> flags){
3826 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree  
3827 +
3828 +  if (BNTreeBranchVals_.count(parameters.name)==0) cout << "Error[assignTreeBranch]:  trying to assign value to " << parameters.name << " that does not have a branch set up.  Will likely seg fault." << endl;  
3829 +  for (uint object = 0; object != inputCollection->size(); object++) {  
3830 +
3831 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;  
3832 +
3833 +    string inputVariable = parameters.inputVariable;
3834 +    string function = "";
3835 +    string stringValue = "";  
3836 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);  
3837 +    BNTreeBranchVals_.at(parameters.name).push_back(value);  
3838 +
3839 +  }
3840   }
3841  
3842  
3843   template <class InputCollection>
3844 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
3844 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3845  
3846    for (uint object = 0; object != inputCollection->size(); object++){
3847  
# Line 1961 | Line 3850 | void OSUAnalysis::fill1DHistogram(TH1* h
3850      string currentString = parameters.inputVariables.at(0);
3851      string inputVariable = "";
3852      string function = "";
3853 <    if(currentString.find("(")==std::string::npos){
3854 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
3853 >    if(currentString.find("(")==string::npos){
3854 >      inputVariable = currentString;// variable to cut on
3855      }
3856      else{
3857 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
3858 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
3859 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
3857 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3858 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3859 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3860 >    }  
3861 >
3862 >    string stringValue = "";  
3863 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);  
3864 >    histo->Fill(value,scaleFactor);  
3865 >
3866 >    if (printEventInfo_) {
3867 >      // Write information about event to screen, for testing purposes.
3868 >      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
3869      }
3870  
1973    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
1974    histo->Fill(value,puScaleFactor);
1975
3871    }
1977
3872   }
3873  
3874   template <class InputCollection1, class InputCollection2>
3875 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
3875 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3876  
3877    bool sameObjects = false;
3878    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3879  
3880 <  int counter = 0;  
3880 >  int pairCounter = -1;
3881    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3882      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3883 <      
3883 >
3884        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3885  
3886 +      pairCounter++;
3887        //only take objects which have passed all cuts and pairs which have passed all cuts
3888        if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3889        if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3890 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(counter)) continue;
3890 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3891  
3892        string currentString = parameters.inputVariables.at(0);
3893        string inputVariable = "";
3894        string function = "";
3895 <      if(currentString.find("(")==std::string::npos){
3896 <        inputVariable = currentString;// variable to cut on                                                                                                          
3895 >      if(currentString.find("(")==string::npos){
3896 >        inputVariable = currentString;// variable to cut on
3897        }
3898        else{
3899 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
3900 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
3901 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
3899 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3900 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3901 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3902        }
2008      
2009      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
2010      histo->Fill(value,puScaleFactor);
3903  
3904 <      counter++;      
3904 >      string stringValue = "";
3905 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3906 >      histo->Fill(value,scaleFactor);
3907 >
3908      }
3909    }
3910  
# Line 2017 | Line 3912 | void OSUAnalysis::fill1DHistogram(TH1* h
3912  
3913  
3914   template <class InputCollection>
3915 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
3915 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3916  
3917    for (uint object = 0; object != inputCollection->size(); object++){
3918  
3919      if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3920  
3921 +    string stringValue = "";
3922      string currentString = parameters.inputVariables.at(0);
3923      string inputVariable = "";
3924      string function = "";
3925 <    if(currentString.find("(")==std::string::npos){
3926 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
3925 >    if(currentString.find("(")==string::npos){
3926 >      inputVariable = currentString;// variable to cut on
3927      }
3928      else{
3929 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
3930 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
3931 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
3929 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3930 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3931 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3932      }
3933 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
3933 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3934  
3935      currentString = parameters.inputVariables.at(1);
3936      inputVariable = "";
3937      function = "";
3938 <    if(currentString.find("(")==std::string::npos){
3939 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
3938 >    if(currentString.find("(")==string::npos){
3939 >      inputVariable = currentString;// variable to cut on
3940      }
3941      else{
3942 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
3943 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
3944 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
3942 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3943 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3944 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3945      }
3946  
3947 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
3947 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3948  
3949 <    histo->Fill(valueX,valueY,puScaleFactor);
3949 >    histo->Fill(valueX,valueY,scaleFactor);
3950  
3951    }
3952  
3953   }
3954  
3955   template <class InputCollection1, class InputCollection2>
3956 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
3956 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3957  
3958    bool sameObjects = false;
3959    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3960  
3961 <  int counter = 0;  
3961 >  int pairCounter = -1;
3962    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3963      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3964 <      
3964 >
3965        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3966  
3967 +      pairCounter++;
3968 +
3969        //only take objects which have passed all cuts and pairs which have passed all cuts
3970        if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3971        if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3972 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(counter)) continue;
3972 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3973  
3974 +      string stringValue = "";
3975        string currentString = parameters.inputVariables.at(0);
3976        string inputVariable = "";
3977        string function = "";
3978 <      if(currentString.find("(")==std::string::npos){
3979 <        inputVariable = currentString;// variable to cut on                                                                                                          
3978 >      if(currentString.find("(")==string::npos){
3979 >        inputVariable = currentString;// variable to cut on
3980        }
3981        else{
3982 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
3983 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
3984 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
3982 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3983 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3984 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3985        }
3986 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3986 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3987  
3988        currentString = parameters.inputVariables.at(1);
3989        inputVariable = "";
3990        function = "";
3991 <      if(currentString.find("(")==std::string::npos){
3992 <        inputVariable = currentString;// variable to cut on                                                                                                          
3991 >      if(currentString.find("(")==string::npos){
3992 >        inputVariable = currentString;// variable to cut on
3993        }
3994        else{
3995 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
3996 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
3997 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
3995 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3996 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3997 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3998        }
3999 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
3999 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4000  
4001  
4002 <      histo->Fill(valueX,valueY,puScaleFactor);
4002 >      histo->Fill(valueX,valueY,scaleFactor);
4003  
2105      counter++;      
4004      }
4005    }
4006  
4007   }
4008  
4009  
4010 < // template <class InputObject>
4011 < // BNmcparticle* getGenMatchedParticle(InputObject object){
4010 > template <class InputObject>
4011 > int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
4012  
4013 < //   BNmcparticle bestMatch;
4014 < //   std::cout << bestMatch.energy() << std:endl;
2117 < //   for(BNmcparticleCollection::const_iterator mcparticle = mcParticles_->begin (); mcparticle != mcParticles_->end (); mcparticle++){
4013 >  int bestMatchIndex = -1;
4014 >  double bestMatchDeltaR = 999;
4015  
4016 < //   }
2120 < //   return bestMatch;
2121 < // }
4016 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4017  
4018 +    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4019 +    if(currentDeltaR > 0.05) continue;
4020 +    //     cout << setprecision(3) << setw(20)
4021 +    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4022 +    //          << setw(20)
4023 +    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4024 +    //          << setw(20)
4025 +    //          << "\tdeltaR = " << currentDeltaR
4026 +    //          << setprecision(1)
4027 +    //          << setw(20)
4028 +    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4029 +    //          << setw(20)
4030 +    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4031 +    //          << setw(20)
4032 +    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4033 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4034 +      bestMatchIndex = mcparticle - mcparticles->begin();
4035 +      bestMatchDeltaR = currentDeltaR;
4036 +    }
4037  
4038 < DEFINE_FWK_MODULE(OSUAnalysis);
4038 >  }
4039 >  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4040 >  //   else cout << "no match found..." << endl;
4041 >  return bestMatchIndex;
4042 >
4043 > }
4044 >
4045 >
4046 > int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
4047 >
4048 >  int bestMatchIndex = -1;
4049 >  double bestMatchDeltaR = 999;
4050  
4051 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4052  
4053 +    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
4054 +
4055 +    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
4056 +    if(currentDeltaR > 0.05) continue;
4057 +
4058 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4059 +      bestMatchIndex = mcparticle - mcparticles->begin();
4060 +      bestMatchDeltaR = currentDeltaR;
4061 +    }
4062 +
4063 +  }
4064 +
4065 +  return bestMatchIndex;
4066 + }
4067 +
4068 +
4069 + // bin      particle type
4070 + // ---      -------------
4071 + //  0        unmatched
4072 + //  1        u
4073 + //  2        d
4074 + //  3        s
4075 + //  4        c
4076 + //  5        b
4077 + //  6        t
4078 + //  7        e
4079 + //  8        mu
4080 + //  9        tau
4081 + // 10        nu
4082 + // 11        g
4083 + // 12        gamma
4084 + // 13        Z
4085 + // 14        W
4086 + // 15        light meson
4087 + // 16        K meson
4088 + // 17        D meson
4089 + // 18        B meson
4090 + // 19        light baryon
4091 + // 20        strange baryon
4092 + // 21        charm baryon
4093 + // 22        bottom baryon
4094 + // 23        QCD string
4095 + // 24        other
4096 +
4097 + int OSUAnalysis::getPdgIdBinValue(int pdgId){
4098 +
4099 +  int binValue = -999;
4100 +  int absPdgId = fabs(pdgId);
4101 +  if(pdgId == -1) binValue = 0;
4102 +  else if(absPdgId <= 6 ) binValue = absPdgId;
4103 +  else if(absPdgId == 11 ) binValue = 7;
4104 +  else if(absPdgId == 13 ) binValue = 8;
4105 +  else if(absPdgId == 15 ) binValue = 9;
4106 +  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
4107 +  else if(absPdgId == 21 ) binValue = 11;
4108 +  else if(absPdgId == 22 ) binValue = 12;
4109 +  else if(absPdgId == 23 ) binValue = 13;
4110 +  else if(absPdgId == 24 ) binValue = 14;
4111 +  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
4112 +  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
4113 +  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
4114 +  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
4115 +  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
4116 +  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4117 +  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4118 +  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4119 +  else if(absPdgId == 92  ) binValue = 23;
4120 +
4121 +  else binValue = 24;
4122 +
4123 +  return binValue;
4124 +
4125 + }
4126 +
4127 + const BNprimaryvertex *
4128 + OSUAnalysis::chosenVertex ()
4129 + {
4130 +  const BNprimaryvertex *chosenVertex = 0;
4131 +  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4132 +    vector<bool> vertexFlags;
4133 +    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4134 +      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4135 +        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4136 +        break;
4137 +      }
4138 +    }
4139 +    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4140 +      if(!vertexFlags.at(vertexIndex)) continue;
4141 +      chosenVertex = & primaryvertexs->at(vertexIndex);
4142 +      break;
4143 +    }
4144 +  }
4145 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4146 +    chosenVertex = & primaryvertexs->at (0);
4147 +
4148 +  return chosenVertex;
4149 + }
4150 +
4151 + const BNmet *
4152 + OSUAnalysis::chosenMET ()
4153 + {
4154 +  const BNmet *chosenMET = 0;
4155 +  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4156 +    vector<bool> metFlags;
4157 +    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4158 +      if (cumulativeFlags.at("mets").at(i).size()){
4159 +        metFlags = cumulativeFlags.at("mets").at(i);
4160 +        break;
4161 +      }
4162 +    }
4163 +    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4164 +      if(!metFlags.at(metIndex)) continue;
4165 +      chosenMET = & mets->at(metIndex);
4166 +      break;
4167 +    }
4168 +  }
4169 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4170 +    chosenMET = & mets->at (0);
4171 +
4172 +  return chosenMET;
4173 + }
4174 +
4175 + const BNelectron *
4176 + OSUAnalysis::chosenElectron ()
4177 + {
4178 +  const BNelectron *chosenElectron = 0;
4179 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4180 +    vector<bool> electronFlags;
4181 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4182 +      if (cumulativeFlags.at("electrons").at(i).size()){
4183 +        electronFlags = cumulativeFlags.at("electrons").at(i);
4184 +        break;
4185 +      }
4186 +    }
4187 +    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4188 +      if(!electronFlags.at(electronIndex)) continue;
4189 +      chosenElectron = & electrons->at(electronIndex);
4190 +      break;
4191 +    }
4192 +  }
4193 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4194 +    chosenElectron = & electrons->at (0);
4195 +
4196 +  return chosenElectron;
4197 + }
4198 +
4199 + const BNmuon *
4200 + OSUAnalysis::chosenMuon ()
4201 + {
4202 +  const BNmuon *chosenMuon = 0;
4203 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4204 +    vector<bool> muonFlags;
4205 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4206 +      if (cumulativeFlags.at("muons").at(i).size()){
4207 +        muonFlags = cumulativeFlags.at("muons").at(i);
4208 +        break;
4209 +      }
4210 +    }
4211 +    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4212 +      if(!muonFlags.at(muonIndex)) continue;
4213 +      chosenMuon = & muons->at(muonIndex);
4214 +      break;
4215 +    }
4216 +  }
4217 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4218 +    chosenMuon = & muons->at (0);
4219 +
4220 +  return chosenMuon;
4221 + }
4222 +
4223 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines