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.8 by ahart, Wed Jan 30 22:29:59 2013 UTC vs.
Revision 1.75 by wulsin, Fri May 31 09:15:04 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 +  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 +  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 +  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
36 +  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
37 +  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
38 +  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
39 + {
40  
41 +  TH1::SetDefaultSumw2 ();
42  
43 <  channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels"))
43 >  //create pile-up reweighting object, if necessary
44 >  if(datasetType_ != "data") {
45 >    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
46 >    if (applyLeptonSF_){
47 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
48 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
49 >    }
50 >  }
51 >  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
52 >    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
53  
23 {
24  TH1::SetDefaultSumw2 ();
54  
55    // Construct Cutflow Objects. These store the results of cut decisions and
56    // handle filling cut flow histograms.
57    masterCutFlow_ = new CutFlow (fs_);
58 <  std::vector<TFileDirectory> directories;
58 >
59 >  //always get vertex collection so we can assign the primary vertex in the event
60 >  objectsToGet.push_back("primaryvertexs");
61 >  objectsToPlot.push_back("primaryvertexs");
62 >  objectsToCut.push_back("primaryvertexs");
63 >
64 >
65 >  //always get the MC particles to do GEN-matching
66 >  objectsToGet.push_back("mcparticles");
67 >
68 >  //always get the event collection to do pile-up reweighting
69 >  objectsToGet.push_back("events");
70 >
71 >
72 >  // Parse the tree variable definitions.    
73 >  for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++) {
74 >    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
75 >    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; }  
76 >    objectsToGet.push_back(tempInputCollection);
77 >    objectsToCut.push_back(tempInputCollection);
78 >
79 >    //    vector<edm::ParameterSet> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<edm::ParameterSet> >("histograms"));
80 >    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
81 >
82 >    for(uint iBranch = 0; iBranch<branchList.size(); iBranch++){
83 >
84 >      vector<double> defaultValue;
85 >      defaultValue.push_back (-1.0);
86 >
87 >      BranchSpecs br;
88 >      br.inputCollection = tempInputCollection;
89 >      br.inputVariable = branchList.at(iBranch);  
90 >      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);  
91 >      br.name = string(newName.Data());  
92 >
93 >      treeBranches_.push_back(br);
94 >
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 == "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 >      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(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 >
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).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 >
157 >      histograms.push_back(tempHistogram);
158 >
159 >    }
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;
# Line 41 | 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      }
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
57 <    TFileDirectory subDir = fs_->mkdir( channelName );
58 <    directories.push_back(subDir);
59 <    std::map<std::string, TH1D*> histoMap;
60 <    oneDHists_.push_back(histoMap);
61 <
62 <    //gen histograms
63 <    oneDHists_.at(currentChannel)["genD0"] = directories.at(currentChannel).make<TH1D> ("genD0",channelLabel+" channel: Gen d_{0}; d_{0} [cm] ", 1000, -1, 1);
64 <    oneDHists_.at(currentChannel)["genAbsD0"] = directories.at(currentChannel).make<TH1D> ("genAbsD0",channelLabel+" channel: Gen d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
65 <    oneDHists_.at(currentChannel)["genDZ"] = directories.at(currentChannel).make<TH1D> ("genDZ",channelLabel+" channel: Gen d_{z}; d_{z} [cm] ", 1000, -10, 10);
66 <    oneDHists_.at(currentChannel)["genAbsDZ"] = directories.at(currentChannel).make<TH1D> ("genAbsDZ",channelLabel+" channel: Gen d_{z}; |d_{z}| [cm] ", 1000, 0, 10);
67 <
68 <    //muon histograms
69 <    allNecessaryObjects.push_back("muons");
70 <    oneDHists_.at(currentChannel)["muonPt"]  = directories.at(currentChannel).make<TH1D> ("muonPt",channelLabel+" channel: Muon Transverse Momentum; p_{T} [GeV]", 100, 0, 500);
71 <    oneDHists_.at(currentChannel)["muonEta"] = directories.at(currentChannel).make<TH1D> ("muonEta",channelLabel+" channel: Muon Eta; #eta", 100, -5, 5);
72 <    oneDHists_.at(currentChannel)["muonD0"] = directories.at(currentChannel).make<TH1D> ("muonD0",channelLabel+" channel: Muon d_{0}; d_{0} [cm] ", 1000, -1, 1);
73 <    oneDHists_.at(currentChannel)["muonDz"] = directories.at(currentChannel).make<TH1D> ("muonDz",channelLabel+" channel: Muon d_{z}; d_{z} [cm] ", 1000, -20, 20);
74 <    oneDHists_.at(currentChannel)["muonAbsD0"] = directories.at(currentChannel).make<TH1D> ("muonAbsD0",channelLabel+" channel: Muon d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
75 <    oneDHists_.at(currentChannel)["muonDZ"] = directories.at(currentChannel).make<TH1D> ("muonDZ",channelLabel+" channel: Muon d_{z}; d_{z} [cm] ", 1000, -10, 10);
76 <    oneDHists_.at(currentChannel)["muonAbsDZ"] = directories.at(currentChannel).make<TH1D> ("muonAbsDZ",channelLabel+" channel: Muon d_{z}; |d_{z}| [cm] ", 1000, 0, 10);
77 <    oneDHists_.at(currentChannel)["muonD0Sig"] = directories.at(currentChannel).make<TH1D> ("muonD0Sig",channelLabel+" channel: Muon d_{0} Significance; d_{0} / #sigma_{d_{0}} ", 1000, -10.0, 10.0);
78 <    oneDHists_.at(currentChannel)["muonAbsD0Sig"] = directories.at(currentChannel).make<TH1D> ("muonAbsD0Sig",channelLabel+" channel: Muon d_{0} Significance; |d_{0}| / #sigma_{d_{0}} ", 1000, 0, 10.0);
79 <    oneDHists_.at(currentChannel)["muonIso"] = directories.at(currentChannel).make<TH1D> ("muonIso",channelLabel+" channel: Muon Combined Relative Isolation; rel. iso. ", 1000, 0, 1);
80 <    oneDHists_.at(currentChannel)["numMuons"] = directories.at(currentChannel).make<TH1D> ("numMuons",channelLabel+" channel: Number of Selected Muons; # muons", 10, 0, 10);
81 <
82 <
83 <    //electron histograms
84 <    allNecessaryObjects.push_back("electrons");
85 <    oneDHists_.at(currentChannel)["electronPt"]  = directories.at(currentChannel).make<TH1D> ("electronPt",channelLabel+" channel: Electron Transverse Momentum; p_{T} [GeV]", 100, 0, 500);
86 <    oneDHists_.at(currentChannel)["electronEta"] = directories.at(currentChannel).make<TH1D> ("electronEta",channelLabel+" channel: Electron Eta; #eta", 50, -5, 5);
87 <    oneDHists_.at(currentChannel)["electronD0"] = directories.at(currentChannel).make<TH1D> ("electronD0",channelLabel+" channel: Electron d_{0}; d_{0} [cm] ", 1000, -1, 1);
88 <    oneDHists_.at(currentChannel)["electronDz"] = directories.at(currentChannel).make<TH1D> ("electronDz",channelLabel+" channel: Electron d_{z}; d_{z} [cm] ", 1000, -20, 20);
89 <    oneDHists_.at(currentChannel)["electronAbsD0"] = directories.at(currentChannel).make<TH1D> ("electronAbsD0",channelLabel+" channel: Electron d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
90 <    oneDHists_.at(currentChannel)["electronDZ"] = directories.at(currentChannel).make<TH1D> ("electronDZ",channelLabel+" channel: Electron d_{z}; d_{z} [cm] ", 1000, -10, 10);
91 <    oneDHists_.at(currentChannel)["electronAbsDZ"] = directories.at(currentChannel).make<TH1D> ("electronAbsDZ",channelLabel+" channel: Electron d_{z}; |d_{z}| [cm] ", 1000, 0, 10);
92 <    oneDHists_.at(currentChannel)["electronD0Sig"] = directories.at(currentChannel).make<TH1D> ("electronD0Sig",channelLabel+" channel: Electron d_{0} Significance; d_{0} / #sigma_{d_{0}} ", 1000, -10.0, 10.0);
93 <    oneDHists_.at(currentChannel)["electronAbsD0Sig"] = directories.at(currentChannel).make<TH1D> ("electronAbsD0Sig",channelLabel+" channel: Electron d_{0} Significance; |d_{0}| / #sigma_{d_{0}} ", 1000, 0, 10.0);
94 <    oneDHists_.at(currentChannel)["electronIso"] = directories.at(currentChannel).make<TH1D> ("electronIso",channelLabel+" channel: Electron Combined Relative Isolation; rel. iso. ", 1000, 0, 1);
95 <    oneDHists_.at(currentChannel)["electronFbrem"] = directories.at(currentChannel).make<TH1D> ("electronFbrem",channelLabel+" channel: Electron Brem. Energy Fraction; fbrem", 1000, 0, 2);
96 <    oneDHists_.at(currentChannel)["electronMVATrig"] = directories.at(currentChannel).make<TH1D> ("electronMVATrig",channelLabel+" channel: Electron ID MVA Output", 100, -1, 1);
97 <    oneDHists_.at(currentChannel)["electronMVANonTrig"] = directories.at(currentChannel).make<TH1D> ("electronMVANonTrig",channelLabel+" channel: Electron ID MVA Output", 100, -1, 1);
98 <    oneDHists_.at(currentChannel)["numElectrons"] = directories.at(currentChannel).make<TH1D> ("numElectrons",channelLabel+" channel: Number of Selected Electrons; # electrons", 10, 0, 10);
99 <
100 <
101 <
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  
105    vector<string> tempInputCollections;
106
273  
274      //loop over and parse all cuts
275      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
110
276        cut tempCut;
277 <     //store input collection for cut
278 <      string inputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
279 <      tempCut.inputCollection = inputCollection;
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")==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 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 >
313  
116      tempInputCollections.push_back(inputCollection);
117      allNecessaryObjects.push_back(inputCollection);
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);
318 <      tempCut.variable = cutStringVector.at(0);// variable to cut on
319 <      tempCut.comparativeOperator = cutStringVector.at(1);// comparison to make
320 <      tempCut.cutValue = atof(cutStringVector.at(2).c_str());// threshold value to pass cut
317 >      vector<string> cutStringVector = splitString(cutString);
318 >      if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
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("(")==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 >        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
346 >        exit(0);
347 >      }
348  
130      // determine number required if comparison contains "="
349        int numberRequiredInt = atoi(numberRequiredVector.at(1).c_str());
132      if(numberRequiredVector.at(0) == ">") numberRequiredInt++;
133      else if(numberRequiredVector.at(0) == "<") numberRequiredInt--;
134
350        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
351        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
352  
353 <      if(cuts_.at(currentCut).exists("function")){
354 <        tempCut.function = cuts_.at(currentCut).getParameter<string> ("function");
140 <      }
141 <      else tempCut.function = "";
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
362          bool plural = numberRequiredInt != 1;
363 <        string collectionString = plural ? inputCollection : inputCollection.substr(0, inputCollection.size()-1);
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        }
153      tempCut.name = tempCutName;
368  
369 +      subSubDirNames.push_back(subSubDirName);
370 +      tempCut.name = tempCutName;
371  
372        tempChannel.cuts.push_back(tempCut);
373  
374  
375      }//end loop over cuts
376  
377 <    //make unique vector of all objects that this channel cuts on (so we know to set flags for those)
378 <    sort( tempInputCollections.begin(), tempInputCollections.end() );
379 <    tempInputCollections.erase( unique( tempInputCollections.begin(), tempInputCollections.end() ), tempInputCollections.end() );
380 <    tempChannel.inputCollections = tempInputCollections;
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 +      
413 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
414 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
415 +        vector<float> newVec;  
416 +        BNTreeBranchVals_[currentVar.name] = newVec;  
417 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
418 +
419 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
420 +
421 +
422 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
423 +
424 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
425 +        int numBinsElements = currentHistogram.bins.size();
426 +        int numInputVariables = currentHistogram.inputVariables.size();
427 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
428 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
429 +        
430 +        if(numBinsElements == 1){
431 +          if(numBinEdgesX > 1){
432 +            if(numBinEdgesY > 1)
433 +              numBinsElements = 6;
434 +            else
435 +              numBinsElements = 3;
436 +          }
437 +        }
438 +        if(numBinsElements != 3 && numBinsElements !=6){
439 +          cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
440 +          exit(0);
441 +        }
442 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
443 +          cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
444 +          exit(0);
445 +        }
446 +        else if(numBinsElements == 3){
447 +          if (currentHistogram.bins.size () == 3)
448 +            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));
449 +          else
450 +            {
451 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
452 +            }
453 +        }
454 +        else if(numBinsElements == 6){
455 +          if (currentHistogram.bins.size () == 6)
456 +            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));
457 +          else
458 +            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 ());
459 +        }
460 +
461 +
462 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
463 +
464 +        // bin      particle type
465 +        // ---      -------------
466 +        //  0        unmatched
467 +        //  1        u
468 +        //  2        d
469 +        //  3        s
470 +        //  4        c
471 +        //  5        b
472 +        //  6        t
473 +        //  7        e
474 +        //  8        mu
475 +        //  9        tau
476 +        // 10        nu
477 +        // 11        g
478 +        // 12        gamma
479 +        // 13        Z
480 +        // 14        W
481 +        // 15        light meson
482 +        // 16        K meson
483 +        // 17        D meson
484 +        // 18        B meson
485 +        // 19        light baryon
486 +        // 20        strange baryon
487 +        // 21        charm baryon
488 +        // 22        bottom baryon
489 +        // 23        QCD string
490 +        // 24        other
491 +
492 +        vector<TString> labelArray;
493 +        labelArray.push_back("unmatched");
494 +        labelArray.push_back("u");
495 +        labelArray.push_back("d");
496 +        labelArray.push_back("s");
497 +        labelArray.push_back("c");
498 +        labelArray.push_back("b");
499 +        labelArray.push_back("t");
500 +        labelArray.push_back("e");
501 +        labelArray.push_back("#mu");
502 +        labelArray.push_back("#tau");
503 +        labelArray.push_back("#nu");
504 +        labelArray.push_back("g");
505 +        labelArray.push_back("#gamma");
506 +        labelArray.push_back("Z");
507 +        labelArray.push_back("W");
508 +        labelArray.push_back("light meson");
509 +        labelArray.push_back("K meson");
510 +        labelArray.push_back("D meson");
511 +        labelArray.push_back("B meson");
512 +        labelArray.push_back("light baryon");
513 +        labelArray.push_back("strange baryon");
514 +        labelArray.push_back("charm baryon");
515 +        labelArray.push_back("bottom baryon");
516 +        labelArray.push_back("QCD string");
517 +        labelArray.push_back("other");
518 +
519 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
520 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
521 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
522 +          }
523 +          else {
524 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
525 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
526 +          }
527 +        }
528 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
529 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
530 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
531 +        }
532 +
533 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
534 +
535 +
536 +      // Book a histogram for the number of each object type to be plotted.
537 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
538 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
539 +        string currentObject = objectsToPlot.at(currentObjectIndex);
540 +        int maxNum = 10;
541 +        if(currentObject == "mcparticles") maxNum = 50;
542 +        else if(currentObject == "primaryvertexs") maxNum = 50;
543 +
544 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
545 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
546 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
547 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
548 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
549 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
550 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
551 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
552 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
553 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
554 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
555 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
556 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
557 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
558 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
559 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
560 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
561 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
562 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
563 +
564 +        currentObject.at(0) = toupper(currentObject.at(0));
565 +        string histoName = "num" + currentObject;
566 +
567 +        if(histoName == "numPrimaryvertexs"){
568 +          string newHistoName = histoName + "BeforePileupCorrection";
569 +          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);
570 +          newHistoName = histoName + "AfterPileupCorrection";
571 +          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);
572 +        }
573 +        else
574 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
575 +      }
576 +    }//end of loop over directories
577      channels.push_back(tempChannel);
578      tempChannel.cuts.clear();
168
579    }//end loop over channels
580  
581 <  //make unique vector of objects we need to cut on (so we make sure to get them from the event)
582 <  sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
583 <  allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
581 >
582 >  //make unique vector of objects we need to get from the event
583 >  sort( objectsToGet.begin(), objectsToGet.end() );
584 >  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
585 >  //make unique vector of objects we need to cut on
586 >  sort( objectsToCut.begin(), objectsToCut.end() );
587 >  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
588  
589  
590   }
# Line 188 | Line 602 | void
602   OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
603   {
604  
191
605    // Retrieve necessary collections from the event.
606 <  edm::Handle<BNtriggerCollection> triggers;
607 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
606 >
607 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
608      event.getByLabel (triggers_, triggers);
609  
610 <  edm::Handle<BNjetCollection> jets;
611 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())
610 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
611 >    event.getByLabel (trigobjs_, trigobjs);
612 >
613 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
614      event.getByLabel (jets_, jets);
615  
616 <  edm::Handle<BNmuonCollection> muons;
202 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())
616 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
617      event.getByLabel (muons_, muons);
618  
619 <  edm::Handle<BNelectronCollection> electrons;
206 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())
619 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
620      event.getByLabel (electrons_, electrons);
621  
622 <  edm::Handle<BNeventCollection> events;
210 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())
622 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
623      event.getByLabel (events_, events);
624  
625 <  edm::Handle<BNtauCollection> taus;
214 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())
625 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
626      event.getByLabel (taus_, taus);
627  
628 <  edm::Handle<BNmetCollection> mets;
218 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())
628 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
629      event.getByLabel (mets_, mets);
630  
631 <  edm::Handle<BNtrackCollection> tracks;
222 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())
631 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
632      event.getByLabel (tracks_, tracks);
633  
634 <  edm::Handle<BNgenjetCollection> genjets;
226 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())
634 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
635      event.getByLabel (genjets_, genjets);
636  
637 <  edm::Handle<BNmcparticleCollection> mcparticles;
230 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())
637 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
638      event.getByLabel (mcparticles_, mcparticles);
639  
640 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
234 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())
640 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
641      event.getByLabel (primaryvertexs_, primaryvertexs);
642  
643 <  edm::Handle<BNbxlumiCollection> bxlumis;
238 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())
643 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
644      event.getByLabel (bxlumis_, bxlumis);
645  
646 <  edm::Handle<BNphotonCollection> photons;
242 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())
646 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
647      event.getByLabel (photons_, photons);
648  
649 <  edm::Handle<BNsuperclusterCollection> superclusters;
246 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())
649 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
650      event.getByLabel (superclusters_, superclusters);
651  
652 +  if (datasetType_ == "signalMC"){
653 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
654 +      event.getByLabel (stops_, stops);
655 +  }
656 +
657 +  if (useTrackCaloRhoCorr_) {
658 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
659 +    // This rho collection is not available in all BEANs.
660 +    // For description of rho values for different jet reconstruction algorithms, see
661 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
662 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
663 +  }
664 +
665 +  double masterScaleFactor = 1.0;
666 +
667 +  //get pile-up event weight
668 +  if (doPileupReweighting_ && datasetType_ != "data") {
669 +    //for "data" datasets, the numTruePV is always set to -1
670 +    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;  
671 +    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);  
672 +  }
673 +
674 +  stopCTauScaleFactor_ = 1.0;
675 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
676 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
677 +  masterScaleFactor *= stopCTauScaleFactor_;
678  
679    //loop over all channels
680  
# Line 253 | Line 682 | OSUAnalysis::analyze (const edm::Event &
682      channel currentChannel = channels.at(currentChannelIndex);
683  
684      flagMap individualFlags;
256    flagMap cumulativeFlags;
685      counterMap passingCounter;
686 +    cumulativeFlags.clear ();
687 +
688 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
689 +         iter != BNTreeBranchVals_.end(); iter++) {
690 +      iter->second.clear();  // clear array
691 +    }
692 +
693  
694      bool triggerDecision = true;
695 <    if(currentChannel.triggers.size() != 0){  //triggers specified
696 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
695 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
696 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
697        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
698      }
699  
700      //loop over all cuts
701      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
702        cut currentCut = currentChannel.cuts.at(currentCutIndex);
703 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
704 +        string currentObject = objectsToCut.at(currentObjectIndex);
705  
706 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
270 <
271 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
706 >        //initialize maps to get ready to set cuts
707          individualFlags[currentObject].push_back (vector<bool> ());
708          cumulativeFlags[currentObject].push_back (vector<bool> ());
709  
710 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
711 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
710 >      }
711 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
712 >        string currentObject = objectsToCut.at(currentObjectIndex);
713 >
714 >        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
715 >
716 >
717 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
718 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
719 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
720 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
721 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
722          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
723          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
724          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 285 | Line 730 | OSUAnalysis::analyze (const edm::Event &
730          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
731          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
732          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
733 <
289 <
290 <      }
733 >        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
734  
735  
736  
737 <    }//end loop over all cuts
737 >        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
738 >                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
739 >                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
740 >                                                                   "muon-muon pairs");
741 >
742 >        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
743 >                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
744 >                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
745 >                                                                             "muon-secondary muon pairs");
746 >
747 >        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
748 >                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
749 >                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
750 >                                                                                     "electron-secondary electron pairs");
751 >
752 >        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
753 >                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
754 >                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
755 >                                                                           "electron-electron pairs");
756 >        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
757 >                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
758 >                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
759 >                                                                       "electron-muon pairs");
760 >        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
761 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
762 >                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
763 >                                                                 "jet-jet pairs");
764 >        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
765 >                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
766 >                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
767 >                                                                      "electron-jet pairs");
768 >        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
769 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
770 >                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
771 >                                                                  "muon-jet pairs");
772 >        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
773 >                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
774 >                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
775 >                                                                     "track-event pairs");
776 >        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
777 >                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
778 >                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
779 >                                                                        "electron-track pairs");
780 >        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
781 >                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
782 >                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
783 >                                                                    "muon-track pairs");
784 >        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
785 >                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
786 >                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
787 >                                                                  "muon-tau pairs");
788 >        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
789 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
790 >                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
791 >                                                                 "tau-tau pairs");
792 >        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
793 >                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
794 >                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
795 >                                                                   "tau-track pairs");
796 >        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
797 >                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
798 >                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
799 >                                                                          "electron-trigobj pairs");
800 >        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
801 >                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
802 >                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
803 >                                                                      "muon-trigobj pairs");
804  
805 +        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
806 +      }
807  
808  
809  
810 +    }//end loop over all cuts
811      //use cumulative flags to apply cuts at event level
812  
813      bool eventPassedAllCuts = true;
814 <
814 >    //a vector to store cumulative cut descisions after each cut.
815 >    vector<bool> eventPassedPreviousCuts;
816      //apply trigger (true if none were specified)
817      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
818  
306
819      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
820  
821        //loop over all objects and count how many passed the cumulative selection up to this point
822        cut currentCut = currentChannel.cuts.at(currentCutIndex);
823        int numberPassing = 0;
824  
825 <      for (uint object = 0; object != cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).size() ; object++)
826 <          if(cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).at(object)) numberPassing++;
827 <
316 <
825 >      for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
826 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
827 >      }
828        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
829        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
319
830        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
831 <
831 >      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
832      }
833 +    double scaleFactor = masterScaleFactor;
834  
835 <    cutFlows_.at(currentChannelIndex)->fillCutFlow();
836 <
837 <
838 <
839 <    if(!eventPassedAllCuts)continue;
840 <
841 <
842 <    TVector3 vertexPosition;
843 <    vector<bool> vertexFlags = cumulativeFlags["primaryvertexs"].back();
844 <
845 <    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
846 <      if(!vertexFlags.at(vertexIndex)) continue;
847 <
848 <      vertexPosition.SetXYZ (primaryvertexs->at(vertexIndex).x,primaryvertexs->at(vertexIndex).y,primaryvertexs->at(vertexIndex).z);
849 <      break;
835 >    muonScaleFactor_ = electronScaleFactor_ = 1.0;
836 >    if(applyLeptonSF_ && datasetType_ != "data"){
837 >      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
838 >        vector<bool> muonFlags;
839 >        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
840 >          if (cumulativeFlags.at("muons").at(i).size()){
841 >            muonFlags = cumulativeFlags.at("muons").at(i);
842 >            break;
843 >          }
844 >        }
845 >        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
846 >          if(!muonFlags.at(muonIndex)) continue;
847 >          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
848 >        }
849 >      }
850 >      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
851 >        vector<bool> electronFlags;
852 >        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
853 >          if (cumulativeFlags.at("electrons").at(i).size()){
854 >            electronFlags = cumulativeFlags.at("electrons").at(i);
855 >            break;
856 >          }
857 >        }
858 >        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
859 >          if(!electronFlags.at(electronIndex)) continue;
860 >          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
861 >        }
862 >      }
863      }
864 +    scaleFactor *= muonScaleFactor_;
865 +    scaleFactor *= electronScaleFactor_;
866  
867 <    vector<bool> mcparticleFlags = cumulativeFlags["mcparticles"].back();
867 >    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
868  
869 <    for (uint mcparticleIndex = 0; mcparticleIndex != mcparticleFlags.size(); mcparticleIndex++){
870 <      if(!mcparticleFlags.at(mcparticleIndex)) continue;
871 <
872 <      double vx = mcparticles->at(mcparticleIndex).vx - vertexPosition.X (),
873 <             vy = mcparticles->at(mcparticleIndex).vy - vertexPosition.Y (),
874 <             vz = mcparticles->at(mcparticleIndex).vz - vertexPosition.Z (),
875 <             px = mcparticles->at(mcparticleIndex).px,
350 <             py = mcparticles->at(mcparticleIndex).py,
351 <             pt = mcparticles->at(mcparticleIndex).pt,
352 <             d0;
353 <
354 <      d0 = (-vx * py + vy * px) / pt;
355 <      oneDHists_.at(currentChannelIndex)["genD0"]->Fill (d0);
356 <      oneDHists_.at(currentChannelIndex)["genAbsD0"]->Fill (fabs (d0));
357 <      oneDHists_.at(currentChannelIndex)["genDZ"]->Fill (vz);
358 <      oneDHists_.at(currentChannelIndex)["genAbsDZ"]->Fill (fabs (vz));
869 >    if (printEventInfo_) {
870 >      // Write information about event to screen, for testing purposes.
871 >      cout << "Event passed all cuts in channel " <<  currentChannel.name
872 >           << ": run="  << events->at(0).run
873 >           << "  lumi=" << events->at(0).lumi
874 >           << "  event=" << events->at(0).evt
875 >           << endl;
876      }
877  
361    vector<bool> electronFlags = cumulativeFlags["electrons"].back();
362    int electronCounter = 0;
363
364    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
365      if(!electronFlags.at(electronIndex)) continue;
878  
879 +    //filling histograms
880 +    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
881 +      uint currentDir;
882 +      if(!GetPlotsAfterEachCut_){ currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size();}//if GetPlotsAfterEachCut_ is true, set currentDir point to the lat cut.
883 +      else{
884 +        currentDir = currentCut;
885 +      }
886 +      if(eventPassedPreviousCuts.at(currentDir)){
887  
888 <      electronCounter++;
889 <      oneDHists_.at(currentChannelIndex)["electronPt"]->Fill (electrons->at(electronIndex).pt);
890 <      oneDHists_.at(currentChannelIndex)["electronEta"]->Fill (electrons->at(electronIndex).eta);
891 <      oneDHists_.at(currentChannelIndex)["electronD0"]->Fill (electrons->at(electronIndex).correctedD0Vertex);
892 <      oneDHists_.at(currentChannelIndex)["electronDz"]->Fill (electrons->at(electronIndex).correctedDZ);
893 <      oneDHists_.at(currentChannelIndex)["electronAbsD0"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex));
894 <      oneDHists_.at(currentChannelIndex)["electronDZ"]->Fill (electrons->at(electronIndex).correctedDZ);
895 <      oneDHists_.at(currentChannelIndex)["electronAbsDZ"]->Fill (fabs(electrons->at(electronIndex).correctedDZ));
896 <      oneDHists_.at(currentChannelIndex)["electronD0Sig"]->Fill (electrons->at(electronIndex).correctedD0Vertex / electrons->at(electronIndex).tkD0err);
897 <      oneDHists_.at(currentChannelIndex)["electronAbsD0Sig"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex) / electrons->at(electronIndex).tkD0err);
898 <      oneDHists_.at(currentChannelIndex)["electronIso"]->Fill (electrons->at(electronIndex).puChargedHadronIso / electrons->at(electronIndex).pt);
899 <      oneDHists_.at(currentChannelIndex)["electronFbrem"]->Fill (electrons->at(electronIndex).fbrem);
900 <      oneDHists_.at(currentChannelIndex)["electronMVATrig"]->Fill (electrons->at(electronIndex).mvaTrigV0);
901 <      oneDHists_.at(currentChannelIndex)["electronMVANonTrig"]->Fill (electrons->at(electronIndex).mvaNonTrigV0);
888 >        // Assign BNTree variables
889 >        for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
890 >          BranchSpecs brSpecs = treeBranches_.at(iBranch);  
891 >          string coll = brSpecs.inputCollection;  
892 >          if (cumulativeFlags.count(coll) == 0) cout << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
893 >
894 >          if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).at(currentDir));            
895 >          else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).at(currentDir));
896 >          else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).at(currentDir));        
897 >          else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).at(currentDir));
898 >          else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).at(currentDir));
899 >          else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).at(currentDir));
900 >          else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).at(currentDir));
901 >          else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).at(currentDir));
902 >          else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).at(currentDir));
903 >          else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).at(currentDir));
904 >          else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).at(currentDir));
905 >          else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).at(currentDir));
906 >          else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).at(currentDir));
907 >          else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).at(currentDir));
908 >          else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).at(currentDir));
909 >          else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).at(currentDir));
910 >          else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).at(currentDir));
911 >          else if(coll == "stops"
912 >                  && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).at(currentDir));
913 >        } // end loop over histograms  
914 >                                                                                          
915 >
916 >        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
917 >          histogram currentHistogram = histograms.at(histogramIndex);
918 >
919 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) cout << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
920 >
921 >          if(currentHistogram.inputVariables.size() == 1){
922 >            TH1D* histo;  
923 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
924 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
925 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
926 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
927 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
928 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
929 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
930 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
931 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
932 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
933 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
934 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
935 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
936 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
937 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
938 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
939 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
940 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
941 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
942 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
943 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
944 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
945 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
946 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
947 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
948 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
949 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
950 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
951 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
952 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
953 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
954 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
955 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
956 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
957 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
958 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
959 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
960 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
961 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
962 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
963 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
964 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
965 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
966 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
967 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
968 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
969 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
970 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
971 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
972 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
973 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
974 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
975 >
976 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
977 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
978 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
979 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
980 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
981 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
982 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
983 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
984 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
985 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
986 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
987 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
988 >          }
989 >          else if(currentHistogram.inputVariables.size() == 2){
990 >            TH2D* histo;
991 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
992 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
993 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
994 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
995 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
996 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
997 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
998 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
999 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1000 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1001 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1002 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1003 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1004 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1005 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1006 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1007 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1008 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1009 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1010 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1011 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1012 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1013 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1014 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1015 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1016 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1017 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1018 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1019 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1020 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1021 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1022 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1023 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1024 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1025 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1026 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1027 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1028 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1029 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1030 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1031 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1032 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1033 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1034 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1035 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1036 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1037 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1038 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1039 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1040 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1041 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1042 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1043 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1044 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1045 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1046 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1047 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1048 >                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1049 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1050 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1051 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1052 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1053 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1054 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1055 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1056 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1057 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1058 >          }
1059 >          
1060 >        }
1061 >
1062 >
1063 >        //fills histograms with the sizes of collections
1064 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1065 >
1066 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1067 >          string objectToPlot = "";
1068 >
1069 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1070 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1071 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1072 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1073 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1074 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1075 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1076 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1077 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1078 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1079 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1080 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1081 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1082 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1083 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1084 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1085 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1086 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1087 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1088 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1089 >          else objectToPlot = currentObject;
1090 >
1091 >          string tempCurrentObject = objectToPlot;
1092 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1093 >          string histoName = "num" + tempCurrentObject;
1094 >
1095 >          //set position of primary vertex in event, in order to calculate quantities relative to it
1096 >          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1097 >            vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1098 >            int numToPlot = 0;
1099 >            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1100 >              if(lastCutFlags.at(currentFlag)) numToPlot++;
1101 >            }
1102 >            if(objectToPlot == "primaryvertexs"){
1103 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1104 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1105 >            }
1106 >            else {
1107 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1108 >            }
1109 >          }
1110 >          else if(objectToPlot == "jets")           oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(jets->size(),scaleFactor);
1111 >          else if(objectToPlot == "secondaryJets")  oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(jets->size(),scaleFactor);
1112 >          else if(objectToPlot == "muons")          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size(),scaleFactor);
1113 >          else if(objectToPlot == "secondaryMuons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size(),scaleFactor);
1114 >          else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
1115 >          else if(objectToPlot == "muonSecondaryMuonPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
1116 >          else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size(),scaleFactor);
1117 >          else if(objectToPlot == "secondaryElectrons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size(),scaleFactor);
1118 >          else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
1119 >          else if(objectToPlot == "electronSecondaryElectronPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
1120 >          else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
1121 >          else if(objectToPlot == "electronJetPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*jets->size(),scaleFactor);
1122 >          else if(objectToPlot == "muonJetPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*jets->size(),scaleFactor);
1123 >          else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
1124 >          else if(objectToPlot == "electronTrigobjPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*trigobjs->size(),scaleFactor);
1125 >          else if(objectToPlot == "muonTrigobjPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*trigobjs->size(),scaleFactor);
1126 >          else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(events->size(),scaleFactor);
1127 >          else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(taus->size(),scaleFactor);
1128 >          else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(mets->size(),scaleFactor);
1129 >          else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(tracks->size(),scaleFactor);
1130 >          else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(genjets->size(),scaleFactor);
1131 >          else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(mcparticles->size(),scaleFactor);
1132 >          else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(bxlumis->size(),scaleFactor);
1133 >          else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(photons->size(),scaleFactor);
1134 >          else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(superclusters->size(),scaleFactor);
1135 >          else if(objectToPlot == "trigobjs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(trigobjs->size(),scaleFactor);
1136 >          else if(objectToPlot == "primaryvertexs"){
1137 >            oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1138 >            oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1139 >          }
1140 >          if(objectToPlot == "stops" && datasetType_ == "signalMC") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(stops->size(),scaleFactor);
1141  
1142 +        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1143 +      }
1144      }
384    oneDHists_.at(currentChannelIndex)["numElectrons"]->Fill (electronCounter);
385
1145  
1146 <    vector<bool> muonFlags = cumulativeFlags["muons"].back();
388 <    int muonCounter = 0;
1146 >    BNTrees_.at(currentChannelIndex)->Fill();  
1147  
1148 +  } //end loop over channel
1149  
1150 <    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
392 <      if(!muonFlags.at(muonIndex)) continue;
393 <      muonCounter++;
394 <
395 <      oneDHists_.at(currentChannelIndex)["muonPt"]->Fill (muons->at(muonIndex).pt);
396 <      oneDHists_.at(currentChannelIndex)["muonEta"]->Fill (muons->at(muonIndex).eta);
397 <      oneDHists_.at(currentChannelIndex)["muonD0"]->Fill (muons->at(muonIndex).correctedD0Vertex);
398 <      oneDHists_.at(currentChannelIndex)["muonDz"]->Fill (muons->at(muonIndex).correctedDZ);
399 <      oneDHists_.at(currentChannelIndex)["muonAbsD0"]->Fill (fabs(muons->at(muonIndex).correctedD0Vertex));
400 <      oneDHists_.at(currentChannelIndex)["muonDZ"]->Fill (muons->at(muonIndex).correctedDZ);
401 <      oneDHists_.at(currentChannelIndex)["muonAbsDZ"]->Fill (fabs(muons->at(muonIndex).correctedDZ));
402 <      oneDHists_.at(currentChannelIndex)["muonD0Sig"]->Fill (muons->at(muonIndex).correctedD0Vertex / muons->at(muonIndex).tkD0err);
403 <      oneDHists_.at(currentChannelIndex)["muonAbsD0Sig"]->Fill (fabs(muons->at(muonIndex).correctedD0Vertex) / muons->at(muonIndex).tkD0err);
404 <      oneDHists_.at(currentChannelIndex)["muonIso"]->Fill (muons->at(muonIndex).puChargedHadronIso / muons->at(muonIndex).pt);
405 <    }
406 <    oneDHists_.at(currentChannelIndex)["numMuons"]->Fill (muonCounter);
1150 >  masterCutFlow_->fillCutFlow(masterScaleFactor);
1151  
1152  
1153 + } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1154  
1155  
1156  
1157 <  } //end loop over channel
1157 > bool
1158 > OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
1159  
414  masterCutFlow_->fillCutFlow();
1160  
1161 +  if(comparison == ">")       return testValue >  cutValue;
1162 +  else if(comparison == ">=") return testValue >= cutValue;
1163 +  else if(comparison == "<")  return testValue <  cutValue;
1164 +  else if(comparison == "<=") return testValue <= cutValue;
1165 +  else if(comparison == "==") return testValue == cutValue;
1166 +  else if(comparison == "=") return testValue == cutValue;
1167 +  else if(comparison == "!=") return testValue != cutValue;
1168 +  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1169  
1170   }
1171  
419
1172   bool
1173 < OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
1173 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1174  
1175  
1176    if(comparison == ">")       return testValue >  cutValue;
# Line 426 | Line 1178 | OSUAnalysis::evaluateComparison (double
1178    else if(comparison == "<")  return testValue <  cutValue;
1179    else if(comparison == "<=") return testValue <= cutValue;
1180    else if(comparison == "==") return testValue == cutValue;
1181 +  else if(comparison == "=") return testValue == cutValue;
1182    else if(comparison == "!=") return testValue != cutValue;
1183 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1183 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1184  
1185   }
1186  
1187   bool
1188 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1188 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1189  
1190 +  //initialize to false until a chosen trigger is passed
1191    bool triggerDecision = false;
1192  
1193 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1194 <    {
441 <      if(trigger->pass != 1) continue;
442 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
443 <        {
444 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
445 <            triggerDecision = true;
446 <          }
447 <        }
448 <    }
449 <  return triggerDecision;
1193 >  //loop over all triggers defined in the event
1194 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1195  
1196 +    //we're only interested in triggers that actually passed
1197 +    if(trigger->pass != 1) continue;
1198 +
1199 +    //if the event passes one of the veto triggers, exit and return false
1200 +    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1201 +      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1202 +    }
1203 +    //if the event passes one of the chosen triggers, set triggerDecision to true
1204 +    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1205 +      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1206 +    }  
1207 +  }
1208 +  //if none of the veto triggers fired:
1209 +  //return the OR of all the chosen triggers
1210 +  if (triggersToTest.size() != 0) return triggerDecision;
1211 +  //or if no triggers were defined return true
1212 +  else return true;
1213   }
1214  
1215 < std::vector<std::string>
1215 >
1216 > vector<string>
1217   OSUAnalysis::splitString (string inputString){
1218  
1219 <  std::stringstream stringStream(inputString);
1220 <  std::istream_iterator<std::string> begin(stringStream);
1221 <  std::istream_iterator<std::string> end;
1222 <  std::vector<std::string> stringVector(begin, end);
1219 >  stringstream stringStream(inputString);
1220 >  istream_iterator<string> begin(stringStream);
1221 >  istream_iterator<string> end;
1222 >  vector<string> stringVector(begin, end);
1223    return stringVector;
1224  
1225   }
1226  
1227 +
1228 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1229 +  // Set two object strings from the tempInputCollection string,
1230 +  // For example, if tempInputCollection is "electron-muon pairs",
1231 +  // then obj1 = "electrons" and obj2 = "muons".
1232 +  // Note that the objects have an "s" appended.
1233 +
1234 +  int dashIndex = tempInputCollection.find("-");
1235 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1236 +  int secondWordLength = spaceIndex - dashIndex;
1237 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1238 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1239 +
1240 + }
1241 +
1242 +
1243 + string OSUAnalysis::getObjToGet(string obj) {
1244 +  // Return the string corresponding to the object to get for the given obj string.
1245 +  // Right now this only handles the case in which obj contains "secondary",
1246 +  // e.g, "secondary muons".
1247 +  // Note that "s" is NOT appended.
1248 +
1249 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1250 +  int firstSpaceIndex = obj.find_first_of(" ");
1251 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1252 +
1253 + }
1254 +
1255 +
1256 + //!jet valueLookup
1257   double
1258 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1258 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1259  
1260    double value = 0.0;
1261    if(variable == "energy") value = object->energy;
# Line 582 | Line 1375 | OSUAnalysis::valueLookup (const BNjet* o
1375    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1376  
1377  
1378 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1378 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1379  
1380    value = applyFunction(function, value);
1381  
# Line 590 | Line 1383 | OSUAnalysis::valueLookup (const BNjet* o
1383   }
1384  
1385  
1386 <
1386 > //!muon valueLookup
1387   double
1388 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1388 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1389  
1390    double value = 0.0;
1391    if(variable == "energy") value = object->energy;
# Line 608 | Line 1401 | OSUAnalysis::valueLookup (const BNmuon*
1401    else if(variable == "ecalIso") value = object->ecalIso;
1402    else if(variable == "hcalIso") value = object->hcalIso;
1403    else if(variable == "caloIso") value = object->caloIso;
1404 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
1404 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
1405    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
1406    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
1407    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 746 | Line 1539 | OSUAnalysis::valueLookup (const BNmuon*
1539    else if(variable == "numberOfMatchedStations") value = object->numberOfMatchedStations;
1540    else if(variable == "time_ndof") value = object->time_ndof;
1541  
1542 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1542 >  //user-defined variables
1543 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1544 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1545 >  else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1546 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1547 >  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1548 >  else if(variable == "metMT") {
1549 >    if (const BNmet *met = chosenMET ())
1550 >      {
1551 >        double dPhi = deltaPhi (object->phi, met->phi);
1552 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1553 >      }
1554 >    else
1555 >      value = -999;
1556 >  }
1557 >
1558 >
1559 >
1560 >  else if(variable == "correctedD0VertexInEBPlus"){
1561 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1562 >    else value = -999;
1563 >  }
1564 >  else if(variable == "correctedD0VertexOutEBPlus"){
1565 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1566 >    else value = -999;
1567 >  }
1568 >  else if(variable == "correctedD0VertexEEPlus"){
1569 >    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1570 >    else value = -999;
1571 >  }
1572 >
1573 >  else if(variable == "correctedD0BeamspotInEBPlus"){
1574 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1575 >    else value = -999;
1576 >  }
1577 >  else if(variable == "correctedD0BeamspotOutEBPlus"){
1578 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1579 >    else value = -999;
1580 >  }
1581 >  else if(variable == "correctedD0BeamspotEEPlus"){
1582 >    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1583 >    else value = -999;
1584 >  }
1585 >
1586 >  else if(variable == "correctedD0VertexInEBMinus"){
1587 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1588 >    else value = -999;
1589 >  }
1590 >  else if(variable == "correctedD0VertexOutEBMinus"){
1591 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1592 >    else value = -999;
1593 >  }
1594 >  else if(variable == "correctedD0VertexEEMinus"){
1595 >    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1596 >    else value = -999;
1597 >  }
1598 >
1599 >  else if(variable == "correctedD0BeamspotInEBMinus"){
1600 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1601 >    else value = -999;
1602 >  }
1603 >  else if(variable == "correctedD0BeamspotOutEBMinus"){
1604 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1605 >    else value = -999;
1606 >  }
1607 >  else if(variable == "correctedD0BeamspotEEMinus"){
1608 >    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1609 >    else value = -999;
1610 >  }
1611 >
1612 >
1613 >  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1614 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1615 >    else value = -999;
1616 >  }
1617 >  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1618 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1619 >    else value = -999;
1620 >  }
1621 >  else if(variable == "correctedD0VertexEEPositiveCharge"){
1622 >    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1623 >    else value = -999;
1624 >  }
1625 >
1626 >  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1627 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1628 >    else value = -999;
1629 >  }
1630 >  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1631 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1632 >    else value = -999;
1633 >  }
1634 >  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1635 >    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1636 >    else value = -999;
1637 >  }
1638 >
1639 >  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1640 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1641 >    else value = -999;
1642 >  }
1643 >  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1644 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1645 >    else value = -999;
1646 >  }
1647 >  else if(variable == "correctedD0VertexEENegativeCharge"){
1648 >    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1649 >    else value = -999;
1650 >  }
1651 >
1652 >  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1653 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1654 >    else value = -999;
1655 >  }
1656 >  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1657 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1658 >    else value = -999;
1659 >  }
1660 >  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1661 >    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1662 >    else value = -999;
1663 >  }
1664 >
1665 >
1666 >  else if(variable == "tightID") {
1667 >    value = object->isGlobalMuon > 0                \
1668 >      && object->isPFMuon > 0                        \
1669 >      && object->normalizedChi2 < 10                \
1670 >      && object->numberOfValidMuonHits > 0        \
1671 >      && object->numberOfMatchedStations > 1        \
1672 >      && fabs(object->correctedD0Vertex) < 0.2        \
1673 >      && fabs(object->correctedDZ) < 0.5        \
1674 >      && object->numberOfValidPixelHits > 0                \
1675 >      && object->numberOfLayersWithMeasurement > 5;
1676 >  }
1677 >  else if(variable == "tightIDdisplaced"){
1678 >    value = object->isGlobalMuon > 0                \
1679 >      && object->isPFMuon > 0                        \
1680 >      && object->normalizedChi2 < 10                \
1681 >      && object->numberOfValidMuonHits > 0        \
1682 >      && object->numberOfMatchedStations > 1        \
1683 >      && object->numberOfValidPixelHits > 0        \
1684 >      && object->numberOfLayersWithMeasurement > 5;
1685 >  }
1686 >
1687 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1688 >
1689 >  else if(variable == "genMatchedPdgId"){
1690 >    int index = getGenMatchedParticleIndex(object);
1691 >    if(index == -1) value = 0;
1692 >    else value = mcparticles->at(index).id;
1693 >  }
1694 >
1695 >  else if(variable == "genMatchedId"){
1696 >    int index = getGenMatchedParticleIndex(object);
1697 >    if(index == -1) value = 0;
1698 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
1699 >  }
1700 >  else if(variable == "genMatchedMotherId"){
1701 >    int index = getGenMatchedParticleIndex(object);
1702 >    if(index == -1) value = 0;
1703 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1704 >  }
1705 >  else if(variable == "genMatchedMotherIdReverse"){
1706 >    int index = getGenMatchedParticleIndex(object);
1707 >    if(index == -1) value = 24;
1708 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1709 >  }
1710 >  else if(variable == "genMatchedGrandmotherId"){
1711 >    int index = getGenMatchedParticleIndex(object);
1712 >    if(index == -1) value = 0;
1713 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1714 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1715 >      if(motherIndex == -1) value = 0;
1716 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1717 >    }
1718 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1719 >  }
1720 >  else if(variable == "genMatchedGrandmotherIdReverse"){
1721 >    int index = getGenMatchedParticleIndex(object);
1722 >    if(index == -1) value = 24;
1723 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1724 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1725 >      if(motherIndex == -1) value = 24;
1726 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1727 >    }
1728 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1729 >  }
1730 >  else if(variable == "pfMuonsFromVertex"){
1731 >    double d0Error, dzError;
1732 >
1733 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1734 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1735 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1736 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1737 >      || fabs (object->correctedDZ / dzError) > 99.0;
1738 >    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1739 >  }
1740 >
1741 >
1742 >
1743 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1744  
1745    value = applyFunction(function, value);
1746  
1747    return value;
1748   }
1749  
1750 <
1750 > //!electron valueLookup
1751   double
1752 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1752 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1753  
1754    double value = 0.0;
1755    if(variable == "energy") value = object->energy;
# Line 915 | Line 1909 | OSUAnalysis::valueLookup (const BNelectr
1909    else if(variable == "eidHyperTight4MC") value = object->eidHyperTight4MC;
1910    else if(variable == "passConvVeto") value = object->passConvVeto;
1911  
1912 +  //user-defined variables
1913 +  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1914 +  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1915 +  else if(variable == "detIso") value = (object->trackIso) / object->pt;
1916 +  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1917 +  else if(variable == "metMT") {
1918 +    if (const BNmet *met = chosenMET ())
1919 +      {
1920 +        double dPhi = deltaPhi (object->phi, met->phi);
1921 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1922 +      }
1923 +    else
1924 +      value = -999;
1925 +  }
1926  
1927 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1927 >  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
1928 >    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
1929 >    else value = -999;
1930 >  }
1931 >  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
1932 >    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
1933 >    else value = -999;
1934 >  }
1935 >
1936 >  else if(variable == "correctedD0VertexInEBPlus"){
1937 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1938 >    else value = -999;
1939 >  }
1940 >  else if(variable == "correctedD0VertexOutEBPlus"){
1941 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1942 >    else value = -999;
1943 >  }
1944 >  else if(variable == "correctedD0VertexEEPlus"){
1945 >    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
1946 >    else value = -999;
1947 >  }
1948 >
1949 >  else if(variable == "correctedD0BeamspotInEBPlus"){
1950 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1951 >    else value = -999;
1952 >  }
1953 >  else if(variable == "correctedD0BeamspotOutEBPlus"){
1954 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1955 >    else value = -999;
1956 >  }
1957 >  else if(variable == "correctedD0BeamspotEEPlus"){
1958 >    if(object->isEE && object->eta > 0) value = object->correctedD0;
1959 >    else value = -999;
1960 >  }
1961 >
1962 >  else if(variable == "correctedD0VertexInEBMinus"){
1963 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1964 >    else value = -999;
1965 >  }
1966 >  else if(variable == "correctedD0VertexOutEBMinus"){
1967 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1968 >    else value = -999;
1969 >  }
1970 >  else if(variable == "correctedD0VertexEEMinus"){
1971 >    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
1972 >    else value = -999;
1973 >  }
1974 >
1975 >  else if(variable == "correctedD0BeamspotInEBMinus"){
1976 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1977 >    else value = -999;
1978 >  }
1979 >  else if(variable == "correctedD0BeamspotOutEBMinus"){
1980 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1981 >    else value = -999;
1982 >  }
1983 >  else if(variable == "correctedD0BeamspotEEMinus"){
1984 >    if(object->isEE && object->eta < 0) value = object->correctedD0;
1985 >    else value = -999;
1986 >  }
1987 >
1988 >  else if(variable == "tightID"){
1989 >    if (object->isEB)
1990 >      {
1991 >        value = fabs(object->delEtaIn) < 0.004 \
1992 >          && fabs (object->delPhiIn) < 0.03 \
1993 >          && object->scSigmaIEtaIEta < 0.01 \
1994 >          && object->hadOverEm < 0.12 \
1995 >          && fabs (object->correctedD0Vertex) < 0.02 \
1996 >          && fabs (object->correctedDZ) < 0.1 \
1997 >          && object->absInvEMinusInvPin < 0.05 \
1998 >          && object->passConvVeto;
1999 >      }
2000 >    else
2001 >      {
2002 >        value = fabs(object->delEtaIn) < 0.005 \
2003 >          && fabs (object->delPhiIn) < 0.02 \
2004 >          && object->scSigmaIEtaIEta < 0.03 \
2005 >          && object->hadOverEm < 0.10 \
2006 >          && fabs (object->correctedD0Vertex) < 0.02 \
2007 >          && fabs (object->correctedDZ) < 0.1 \
2008 >          && object->absInvEMinusInvPin < 0.05 \
2009 >          && object->passConvVeto;
2010 >      }
2011 >  }
2012 >
2013 >  else if(variable == "correctedD0VertexInEBPositiveCharge"){
2014 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2015 >    else value = -999;
2016 >  }
2017 >  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
2018 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2019 >    else value = -999;
2020 >  }
2021 >  else if(variable == "correctedD0VertexEEPositiveCharge"){
2022 >    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
2023 >    else value = -999;
2024 >  }
2025 >
2026 >  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
2027 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
2028 >    else value = -999;
2029 >  }
2030 >  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
2031 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
2032 >    else value = -999;
2033 >  }
2034 >  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
2035 >    if(object->isEE && object->charge > 0) value = object->correctedD0;
2036 >    else value = -999;
2037 >  }
2038 >
2039 >  else if(variable == "correctedD0VertexInEBNegativeCharge"){
2040 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2041 >    else value = -999;
2042 >  }
2043 >  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
2044 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2045 >    else value = -999;
2046 >  }
2047 >  else if(variable == "correctedD0VertexEENegativeCharge"){
2048 >    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
2049 >    else value = -999;
2050 >  }
2051 >
2052 >  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
2053 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
2054 >    else value = -999;
2055 >  }
2056 >  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
2057 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
2058 >    else value = -999;
2059 >  }
2060 >  else if(variable == "correctedD0BeamspotEENegativeCharge"){
2061 >    if(object->isEE && object->charge < 0) value = object->correctedD0;
2062 >    else value = -999;
2063 >  }
2064 >
2065 >
2066 >  else if(variable == "tightIDdisplaced"){
2067 >    if (object->isEB)
2068 >      {
2069 >        value = fabs(object->delEtaIn) < 0.004 \
2070 >          && fabs (object->delPhiIn) < 0.03 \
2071 >          && object->scSigmaIEtaIEta < 0.01 \
2072 >          && object->hadOverEm < 0.12 \
2073 >          && object->absInvEMinusInvPin < 0.05;
2074 >      }
2075 >    else
2076 >      {
2077 >        value = fabs (object->delEtaIn) < 0.005 \
2078 >          && fabs (object->delPhiIn) < 0.02 \
2079 >          && object->scSigmaIEtaIEta < 0.03 \
2080 >          && object->hadOverEm < 0.10 \
2081 >          && object->absInvEMinusInvPin < 0.05;
2082 >      }
2083 >  }
2084 >
2085 >
2086 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2087 >
2088 >  else if(variable == "genMatchedPdgId"){
2089 >    int index = getGenMatchedParticleIndex(object);
2090 >    if(index == -1) value = 0;
2091 >    else value = mcparticles->at(index).id;
2092 >  }
2093 >
2094 >
2095 >  else if(variable == "genMatchedId"){
2096 >    int index = getGenMatchedParticleIndex(object);
2097 >    if(index == -1) value = 0;
2098 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2099 >  }
2100 >  else if(variable == "genMatchedMotherId"){
2101 >    int index = getGenMatchedParticleIndex(object);
2102 >    if(index == -1) value = 0;
2103 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2104 >  }
2105 >  else if(variable == "genMatchedMotherIdReverse"){
2106 >    int index = getGenMatchedParticleIndex(object);
2107 >    if(index == -1) value = 24;
2108 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2109 >  }
2110 >  else if(variable == "genMatchedGrandmotherId"){
2111 >    int index = getGenMatchedParticleIndex(object);
2112 >    if(index == -1) value = 0;
2113 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2114 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2115 >      if(motherIndex == -1) value = 0;
2116 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2117 >    }
2118 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2119 >  }
2120 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2121 >    int index = getGenMatchedParticleIndex(object);
2122 >    if(index == -1) value = 24;
2123 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2124 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2125 >      if(motherIndex == -1) value = 24;
2126 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2127 >    }
2128 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2129 >  }
2130 >  else if(variable == "pfElectronsFromVertex"){
2131 >    double d0Error, dzError;
2132 >
2133 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2134 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2135 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2136 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2137 >      || fabs (object->correctedDZ / dzError) > 99.0;
2138 >    value = !value;
2139 >  }
2140 >
2141 >
2142 >
2143 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2144  
2145    value = applyFunction(function, value);
2146  
2147    return value;
2148   }
2149  
2150 <
2150 > //!event valueLookup
2151   double
2152 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2152 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2153  
2154    double value = 0.0;
2155  
# Line 993 | Line 2217 | OSUAnalysis::valueLookup (const BNevent*
2217    else if(variable == "id1") value = object->id1;
2218    else if(variable == "id2") value = object->id2;
2219    else if(variable == "evt") value = object->evt;
2220 +  else if(variable == "puScaleFactor"){
2221 +    if(doPileupReweighting_ && datasetType_ != "data")
2222 +      value = puWeight_->at (events->at (0).numTruePV);
2223 +    else
2224 +      value = 1.0;
2225 +  }
2226 +  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2227 +  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2228 +  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2229  
2230 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2230 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2231  
2232    value = applyFunction(function, value);
2233  
2234    return value;
2235   }
2236  
2237 + //!tau valueLookup
2238   double
2239 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2239 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2240  
2241    double value = 0.0;
2242  
# Line 1047 | Line 2281 | OSUAnalysis::valueLookup (const BNtau* o
2281    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2282  
2283  
2284 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2284 >
2285 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2286 >
2287 >  else if(variable == "genMatchedPdgId"){
2288 >    int index = getGenMatchedParticleIndex(object);
2289 >    if(index == -1) value = 0;
2290 >    else value = mcparticles->at(index).id;
2291 >  }
2292 >
2293 >  else if(variable == "genMatchedId"){
2294 >    int index = getGenMatchedParticleIndex(object);
2295 >    if(index == -1) value = 0;
2296 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2297 >  }
2298 >  else if(variable == "genMatchedMotherId"){
2299 >    int index = getGenMatchedParticleIndex(object);
2300 >    if(index == -1) value = 0;
2301 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2302 >  }
2303 >  else if(variable == "genMatchedMotherIdReverse"){
2304 >    int index = getGenMatchedParticleIndex(object);
2305 >    if(index == -1) value = 24;
2306 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2307 >  }
2308 >  else if(variable == "genMatchedGrandmotherId"){
2309 >    int index = getGenMatchedParticleIndex(object);
2310 >    if(index == -1) value = 0;
2311 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2312 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2313 >      if(motherIndex == -1) value = 0;
2314 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2315 >    }
2316 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2317 >  }
2318 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2319 >    int index = getGenMatchedParticleIndex(object);
2320 >    if(index == -1) value = 24;
2321 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2322 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2323 >      if(motherIndex == -1) value = 24;
2324 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2325 >    }
2326 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2327 >  }
2328 >
2329 >
2330 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2331  
2332    value = applyFunction(function, value);
2333  
2334    return value;
2335   }
2336  
2337 + //!met valueLookup
2338   double
2339 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2339 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2340  
2341    double value = 0.0;
2342  
# Line 1119 | Line 2400 | OSUAnalysis::valueLookup (const BNmet* o
2400    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2401    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2402  
2403 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2403 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2404  
2405    value = applyFunction(function, value);
2406  
2407    return value;
2408   }
2409  
2410 + //!track valueLookup
2411   double
2412 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2412 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2413  
2414    double value = 0.0;
2415 +  double pMag = sqrt(object->pt * object->pt +
2416 +                     object->pz * object->pz);
2417  
2418    if(variable == "pt") value = object->pt;
2419    else if(variable == "px") value = object->px;
# Line 1150 | Line 2434 | OSUAnalysis::valueLookup (const BNtrack*
2434    else if(variable == "isHighPurity") value = object->isHighPurity;
2435  
2436  
2437 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2437 >  //additional BNs info for disappTrks
2438 >  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2439 >  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2440 >  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2441 >  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2442 >  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2443 >  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2444 >  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2445 >  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2446 >  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2447 >  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2448 >  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2449 >
2450 >  //user defined variables
2451 >  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;
2452 >  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2453 >  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2454 >  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2455 >  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2456 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2457 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2458 >  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2459 >  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2460 >  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2461 >  else if(variable == "ptError")                    value = object->ptError;
2462 >  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2463 >  else if (variable == "d0wrtPV"){
2464 >    double vx = object->vx - chosenVertex ()->x,
2465 >      vy = object->vy - chosenVertex ()->y,
2466 >      px = object->px,
2467 >      py = object->py,
2468 >      pt = object->pt;
2469 >    value = (-vx * py + vy * px) / pt;
2470 >  }
2471 >  else if (variable == "dZwrtPV"){
2472 >    double vx = object->vx - chosenVertex ()->x,
2473 >      vy = object->vy - chosenVertex ()->y,
2474 >      vz = object->vz - chosenVertex ()->z,
2475 >      px = object->px,
2476 >      py = object->py,
2477 >      pz = object->pz,
2478 >      pt = object->pt;
2479 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2480 >  }
2481 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2482 >
2483 >  else if(variable == "genMatchedPdgId"){
2484 >    int index = getGenMatchedParticleIndex(object);
2485 >    if(index == -1) value = 0;
2486 >    else value = mcparticles->at(index).id;
2487 >  }
2488 >
2489 >
2490 >  else if(variable == "genMatchedId"){
2491 >    int index = getGenMatchedParticleIndex(object);
2492 >    if(index == -1) value = 0;
2493 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2494 >  }
2495 >  else if(variable == "genMatchedMotherId"){
2496 >    int index = getGenMatchedParticleIndex(object);
2497 >    if(index == -1) value = 0;
2498 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2499 >  }
2500 >  else if(variable == "genMatchedMotherIdReverse"){
2501 >    int index = getGenMatchedParticleIndex(object);
2502 >    if(index == -1) value = 24;
2503 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2504 >  }
2505 >  else if(variable == "genMatchedGrandmotherId"){
2506 >    int index = getGenMatchedParticleIndex(object);
2507 >    if(index == -1) value = 0;
2508 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2509 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2510 >      if(motherIndex == -1) value = 0;
2511 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2512 >    }
2513 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2514 >  }
2515 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2516 >    int index = getGenMatchedParticleIndex(object);
2517 >    if(index == -1) value = 24;
2518 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2519 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2520 >      if(motherIndex == -1) value = 24;
2521 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2522 >    }
2523 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2524 >  }
2525 >
2526 >
2527 >
2528 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2529  
2530    value = applyFunction(function, value);
2531  
2532    return value;
2533   }
2534  
2535 + //!genjet valueLookup
2536   double
2537 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2537 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2538  
2539    double value = 0.0;
2540  
# Line 1178 | Line 2554 | OSUAnalysis::valueLookup (const BNgenjet
2554    else if(variable == "charge") value = object->charge;
2555  
2556  
2557 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2557 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2558  
2559    value = applyFunction(function, value);
2560  
2561    return value;
2562   }
2563  
2564 + //!mcparticle valueLookup
2565   double
2566 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2566 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2567  
2568    double value = 0.0;
2569  
# Line 1275 | Line 2652 | OSUAnalysis::valueLookup (const BNmcpart
2652    else if(variable == "grandMother11Status") value = object->grandMother11Status;
2653    else if(variable == "grandMother11Charge") value = object->grandMother11Charge;
2654  
2655 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2655 >  //user-defined variables
2656 >  else if (variable == "d0"){
2657 >    double vx = object->vx - chosenVertex ()->x,
2658 >      vy = object->vy - chosenVertex ()->y,
2659 >      px = object->px,
2660 >      py = object->py,
2661 >      pt = object->pt;
2662 >    value = (-vx * py + vy * px) / pt;
2663 >  }
2664 >  else if (variable == "dz"){
2665 >    double vx = object->vx - chosenVertex ()->x,
2666 >      vy = object->vy - chosenVertex ()->y,
2667 >      vz = object->vz - chosenVertex ()->z,
2668 >      px = object->px,
2669 >      py = object->py,
2670 >      pz = object->pz,
2671 >      pt = object->pt;
2672 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2673 >  }
2674 >  else if(variable == "v0"){
2675 >    value = sqrt(object->vx*object->vx + object->vy*object->vy);
2676 >  }
2677 >  else if(variable == "deltaV0"){
2678 >    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
2679 >  }
2680 >  else if (variable == "deltaVx"){
2681 >    value = object->vx - chosenVertex ()->x;
2682 >  }
2683 >  else if (variable == "deltaVy"){
2684 >    value = object->vy - chosenVertex ()->y;
2685 >  }
2686 >  else if (variable == "deltaVz"){
2687 >    value = object->vz - chosenVertex ()->z;
2688 >  }
2689 >
2690 >
2691 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2692  
2693    value = applyFunction(function, value);
2694  
2695    return value;
2696   }
2697  
2698 + //!primaryvertex valueLookup
2699   double
2700 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2700 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2701  
2702    double value = 0.0;
2703  
# Line 1302 | Line 2716 | OSUAnalysis::valueLookup (const BNprimar
2716    else if(variable == "isGood") value = object->isGood;
2717  
2718  
2719 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2719 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2720  
2721    value = applyFunction(function, value);
2722  
2723    return value;
2724   }
2725  
2726 + //!bxlumi valueLookup
2727   double
2728 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2728 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2729  
2730    double value = 0.0;
2731  
# Line 1319 | Line 2734 | OSUAnalysis::valueLookup (const BNbxlumi
2734    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2735  
2736  
2737 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2737 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2738  
2739    value = applyFunction(function, value);
2740  
2741    return value;
2742   }
2743  
2744 + //!photon valueLookup
2745   double
2746 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2746 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2747  
2748    double value = 0.0;
2749  
# Line 1402 | Line 2818 | OSUAnalysis::valueLookup (const BNphoton
2818    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2819  
2820  
2821 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2821 >
2822 >
2823 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2824 >
2825 >  else if(variable == "genMatchedPdgId"){
2826 >    int index = getGenMatchedParticleIndex(object);
2827 >    if(index == -1) value = 0;
2828 >    else value = mcparticles->at(index).id;
2829 >  }
2830 >
2831 >
2832 >
2833 >  else if(variable == "genMatchedId"){
2834 >    int index = getGenMatchedParticleIndex(object);
2835 >    if(index == -1) value = 0;
2836 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2837 >  }
2838 >  else if(variable == "genMatchedMotherId"){
2839 >    int index = getGenMatchedParticleIndex(object);
2840 >    if(index == -1) value = 0;
2841 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2842 >  }
2843 >  else if(variable == "genMatchedMotherIdReverse"){
2844 >    int index = getGenMatchedParticleIndex(object);
2845 >    if(index == -1) value = 24;
2846 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2847 >  }
2848 >  else if(variable == "genMatchedGrandmotherId"){
2849 >    int index = getGenMatchedParticleIndex(object);
2850 >    if(index == -1) value = 0;
2851 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2852 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2853 >      if(motherIndex == -1) value = 0;
2854 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2855 >    }
2856 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2857 >  }
2858 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2859 >    int index = getGenMatchedParticleIndex(object);
2860 >    if(index == -1) value = 24;
2861 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2862 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2863 >      if(motherIndex == -1) value = 24;
2864 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2865 >    }
2866 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2867 >  }
2868 >
2869 >
2870 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2871  
2872    value = applyFunction(function, value);
2873  
2874    return value;
2875   }
2876  
2877 + //!supercluster valueLookup
2878   double
2879 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
2879 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
2880  
2881    double value = 0.0;
2882  
# Line 1424 | Line 2890 | OSUAnalysis::valueLookup (const BNsuperc
2890    else if(variable == "theta") value = object->theta;
2891  
2892  
2893 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2894 +
2895 +  value = applyFunction(function, value);
2896 +
2897 +  return value;
2898 + }
2899 +
2900 + //!trigobj valueLookup
2901 + double
2902 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
2903 +
2904 +  double value = 0.0;
2905 +
2906 +  if(variable == "pt") value = object->pt;
2907 +  else if(variable == "eta") value = object->eta;
2908 +  else if(variable == "phi") value = object->phi;
2909 +  else if(variable == "px") value = object->px;
2910 +  else if(variable == "py") value = object->py;
2911 +  else if(variable == "pz") value = object->pz;
2912 +  else if(variable == "et") value = object->et;
2913 +  else if(variable == "energy") value = object->energy;
2914 +  else if(variable == "etTotal") value = object->etTotal;
2915 +  else if(variable == "id") value = object->id;
2916 +  else if(variable == "charge") value = object->charge;
2917 +  else if(variable == "isIsolated") value = object->isIsolated;
2918 +  else if(variable == "isMip") value = object->isMip;
2919 +  else if(variable == "isForward") value = object->isForward;
2920 +  else if(variable == "isRPC") value = object->isRPC;
2921 +  else if(variable == "bx") value = object->bx;
2922 +  else if(variable == "filter") {
2923 +    if ((stringValue = object->filter) == "")
2924 +      stringValue = "none";  // stringValue should only be empty if value is filled
2925 +  }
2926 +
2927 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2928 +
2929 +  value = applyFunction(function, value);
2930 +
2931 +  return value;
2932 + }
2933 +
2934 + //!muon-muon pair valueLookup
2935 + double
2936 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
2937 +
2938 +  double value = 0.0;
2939 +
2940 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2941 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2942 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2943 +  else if(variable == "invMass"){
2944 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2945 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2946 +    value = (fourVector1 + fourVector2).M();
2947 +  }
2948 +  else if(variable == "pt"){
2949 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2950 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2951 +    value = (fourVector1 + fourVector2).Pt();
2952 +  }
2953 +  else if(variable == "threeDAngle")
2954 +    {
2955 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2956 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2957 +      value = (threeVector1.Angle(threeVector2));
2958 +    }
2959 +  else if(variable == "alpha")
2960 +    {
2961 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
2962 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2963 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2964 +      value = (pi-threeVector1.Angle(threeVector2));
2965 +    }
2966 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2967 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2968 +  else if(variable == "d0Sign"){
2969 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2970 +    if(d0Sign < 0) value = -0.5;
2971 +    else if (d0Sign > 0) value = 0.5;
2972 +    else value = -999;
2973 +  }
2974 +  else if(variable == "chargeProduct"){
2975 +    value = object1->charge*object2->charge;
2976 +  }
2977 +  else if(variable == "muon1CorrectedD0Vertex"){
2978 +    value = object1->correctedD0Vertex;
2979 +  }
2980 +  else if(variable == "muon2CorrectedD0Vertex"){
2981 +    value = object2->correctedD0Vertex;
2982 +  }
2983 +  else if(variable == "muon1timeAtIpInOut"){
2984 +    value = object1->timeAtIpInOut;
2985 +  }
2986 +  else if(variable == "muon2timeAtIpInOut"){
2987 +    value = object2->timeAtIpInOut;
2988 +  }
2989 +  else if(variable == "muon1correctedD0")
2990 +    {
2991 +      value = object1->correctedD0;
2992 +    }
2993 +  else if(variable == "muon2correctedD0")
2994 +    {
2995 +      value = object2->correctedD0;
2996 +    }
2997 +
2998 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2999 +
3000 +  value = applyFunction(function, value);
3001 +
3002 +  return value;
3003 + }
3004 +
3005 + //!electron-electron pair valueLookup
3006 + double
3007 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3008 +
3009 +  double value = 0.0;
3010 +
3011 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3012 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3013 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3014 +  else if(variable == "invMass"){
3015 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3016 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3017 +    value = (fourVector1 + fourVector2).M();
3018 +  }
3019 +  else if(variable == "pt"){
3020 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3021 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3022 +    value = (fourVector1 + fourVector2).Pt();
3023 +  }
3024 +  else if(variable == "threeDAngle")
3025 +    {
3026 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3027 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3028 +      value = (threeVector1.Angle(threeVector2));
3029 +    }
3030 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3031 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3032 +  else if(variable == "d0Sign"){
3033 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3034 +    if(d0Sign < 0) value = -0.5;
3035 +    else if (d0Sign > 0) value = 0.5;
3036 +    else value = -999;
3037 +  }
3038 +  else if(variable == "chargeProduct"){
3039 +    value = object1->charge*object2->charge;
3040 +  }
3041 +  else if(variable == "electron1CorrectedD0Vertex"){
3042 +    value = object1->correctedD0Vertex;
3043 +  }
3044 +  else if(variable == "electron2CorrectedD0Vertex"){
3045 +    value = object2->correctedD0Vertex;
3046 +  }
3047 +  else if(variable == "electron1CorrectedD0"){
3048 +    value = object1->correctedD0;
3049 +  }
3050 +  else if(variable == "electron2CorrectedD0"){
3051 +    value = object2->correctedD0;
3052 +  }
3053 +
3054 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3055 +
3056 +  value = applyFunction(function, value);
3057 +
3058 +  return value;
3059 + }
3060 + //!electron-muon pair valueLookup
3061 + double
3062 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3063 +
3064 +  double value = 0.0;
3065 +
3066 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3067 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3068 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3069 +  else if(variable == "invMass"){
3070 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3071 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3072 +    value = (fourVector1 + fourVector2).M();
3073 +  }
3074 +  else if(variable == "pt"){
3075 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3076 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3077 +    value = (fourVector1 + fourVector2).Pt();
3078 +  }
3079 +  else if(variable == "threeDAngle")
3080 +    {
3081 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3082 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3083 +      value = (threeVector1.Angle(threeVector2));
3084 +    }
3085 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3086 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3087 +  else if(variable == "d0Sign"){
3088 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3089 +    if(d0Sign < 0) value = -0.5;
3090 +    else if (d0Sign > 0) value = 0.5;
3091 +    else value = -999;
3092 +  }
3093 +  else if(variable == "chargeProduct"){
3094 +    value = object1->charge*object2->charge;
3095 +  }
3096 +  else if(variable == "electronCorrectedD0Vertex"){
3097 +    value = object1->correctedD0Vertex;
3098 +  }
3099 +  else if(variable == "muonCorrectedD0Vertex"){
3100 +    value = object2->correctedD0Vertex;
3101 +  }
3102 +  else if(variable == "electronCorrectedD0"){
3103 +    value = object1->correctedD0;
3104 +  }
3105 +  else if(variable == "muonCorrectedD0"){
3106 +    value = object2->correctedD0;
3107 +  }
3108 +  else if(variable == "electronDetIso"){
3109 +    value = (object1->trackIso) / object1->pt;
3110 +  }
3111 +  else if(variable == "muonDetIso"){
3112 +    value = (object2->trackIsoDR03) / object2->pt;
3113 +  }
3114 +  else if(variable == "electronRelPFrhoIso"){
3115 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3116 +  }
3117 +  else if(variable == "muonRelPFdBetaIso"){
3118 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3119 +  }
3120 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3121 +  value = applyFunction(function, value);
3122 +
3123 +  return value;
3124 + }
3125 +
3126 + //!electron-jet pair valueLookup
3127 + double
3128 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3129 +
3130 +  double value = 0.0;
3131 +
3132 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3133 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3134 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3135 +  else if(variable == "invMass"){
3136 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3137 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3138 +    value = (fourVector1 + fourVector2).M();
3139 +  }
3140 +  else if(variable == "pt"){
3141 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3142 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3143 +    value = (fourVector1 + fourVector2).Pt();
3144 +  }
3145 +  else if(variable == "threeDAngle")
3146 +    {
3147 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3148 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3149 +      value = (threeVector1.Angle(threeVector2));
3150 +    }
3151 +  else if(variable == "chargeProduct"){
3152 +    value = object1->charge*object2->charge;
3153 +  }
3154 +
3155 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3156 +  value = applyFunction(function, value);
3157 +
3158 +  return value;
3159 + }
3160 +
3161 + //!muon-jet pair valueLookup
3162 + double
3163 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3164 +
3165 +  double value = 0.0;
3166 +
3167 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->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 = abs(value);
3643 >  if(function == "abs") value = fabs(value);
3644 >  else if(function == "fabs") value = fabs(value);
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{cout << "WARNING: invalid function '" << function << "'\n";}
3650  
3651    return value;
3652  
# Line 1446 | 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  
# Line 1453 | Line 3676 | void OSUAnalysis::setObjectFlags(cut &cu
3676  
3677      if(currentCut.inputCollection == inputType){
3678  
3679 <      double value = valueLookup(&inputCollection->at(object), currentCut.variable, currentCut.function);
3679 >      vector<bool> subcutDecisions;
3680 >      for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; 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 <      decision = evaluateComparison(value,currentCut.comparativeOperator,currentCut.cutValue);
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) == "||")
3694 >            tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
3695 >        }
3696 >        decision = tempDecision;
3697 >      }
3698      }
1460    individualFlags[inputType].at(currentCutIndex).push_back(decision);
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
3703      bool previousCumulativeFlag = true;
3704      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3705 <      if(previousCumulativeFlag && individualFlags[inputType].at(previousCutIndex).at(object)) previousCumulativeFlag = true;
3705 >      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
3706        else{ previousCumulativeFlag = false; break;}
3707      }
3708 <    cumulativeFlags[inputType].at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3708 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3709  
3710    }
3711  
3712   }
3713  
3714  
3715 + template <class InputCollection1, class InputCollection2>
3716 + void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
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 +  // 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  
3749 < DEFINE_FWK_MODULE(OSUAnalysis);
3749 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3750 >
3751 >
3752 >      bool decision = true;//object passes if this cut doesn't cut on that type of object
3753 >
3754 >      if(currentCut.inputCollection == inputType){
3755 >
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 = 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 >      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;}
3789 >      }
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 > 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 >    }
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 >  for (uint object = 0; object != inputCollection->size(); object++){
3829 >
3830 >    if (!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3831 >
3832 >    string inputVariable = parameters.inputVariable;
3833 >    string function = "";
3834 >    string stringValue = "";  
3835 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);  
3836 >    BNTreeBranchVals_.at(parameters.name).push_back(value);  
3837 >
3838 >  }
3839 > }
3840  
3841  
3842 + template <class InputCollection>
3843 + void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3844 +
3845 +  for (uint object = 0; object != inputCollection->size(); object++){
3846 +
3847 +    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3848 +
3849 +    string currentString = parameters.inputVariables.at(0);
3850 +    string inputVariable = "";
3851 +    string function = "";
3852 +    if(currentString.find("(")==string::npos){
3853 +      inputVariable = currentString;// variable to cut on
3854 +    }
3855 +    else{
3856 +      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3857 +      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3858 +      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3859 +    }  
3860 +
3861 +    string stringValue = "";  
3862 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);  
3863 +    histo->Fill(value,scaleFactor);  
3864 +
3865 +    if (printEventInfo_) {
3866 +      // Write information about event to screen, for testing purposes.
3867 +      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
3868 +    }
3869 +
3870 +  }
3871 + }
3872 +
3873 + template <class InputCollection1, class InputCollection2>
3874 + void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3875 +
3876 +  bool sameObjects = false;
3877 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3878 +
3879 +  int pairCounter = -1;
3880 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3881 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3882 +
3883 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3884 +
3885 +      pairCounter++;
3886 +      //only take objects which have passed all cuts and pairs which have passed all cuts
3887 +      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3888 +      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3889 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3890 +
3891 +      string currentString = parameters.inputVariables.at(0);
3892 +      string inputVariable = "";
3893 +      string function = "";
3894 +      if(currentString.find("(")==string::npos){
3895 +        inputVariable = currentString;// variable to cut on
3896 +      }
3897 +      else{
3898 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3899 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3900 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3901 +      }
3902 +
3903 +      string stringValue = "";
3904 +      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3905 +      histo->Fill(value,scaleFactor);
3906 +
3907 +    }
3908 +  }
3909 +
3910 + }
3911 +
3912 +
3913 + template <class InputCollection>
3914 + void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3915 +
3916 +  for (uint object = 0; object != inputCollection->size(); object++){
3917 +
3918 +    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3919 +
3920 +    string stringValue = "";
3921 +    string currentString = parameters.inputVariables.at(0);
3922 +    string inputVariable = "";
3923 +    string function = "";
3924 +    if(currentString.find("(")==string::npos){
3925 +      inputVariable = currentString;// variable to cut on
3926 +    }
3927 +    else{
3928 +      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3929 +      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3930 +      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3931 +    }
3932 +    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3933 +
3934 +    currentString = parameters.inputVariables.at(1);
3935 +    inputVariable = "";
3936 +    function = "";
3937 +    if(currentString.find("(")==string::npos){
3938 +      inputVariable = currentString;// variable to cut on
3939 +    }
3940 +    else{
3941 +      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3942 +      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3943 +      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3944 +    }
3945 +
3946 +    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3947 +
3948 +    histo->Fill(valueX,valueY,scaleFactor);
3949 +
3950 +  }
3951 +
3952 + }
3953 +
3954 + template <class InputCollection1, class InputCollection2>
3955 + void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3956 +
3957 +  bool sameObjects = false;
3958 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3959 +
3960 +  int pairCounter = -1;
3961 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3962 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3963 +
3964 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3965 +
3966 +      pairCounter++;
3967 +
3968 +      //only take objects which have passed all cuts and pairs which have passed all cuts
3969 +      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3970 +      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3971 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3972 +
3973 +      string stringValue = "";
3974 +      string currentString = parameters.inputVariables.at(0);
3975 +      string inputVariable = "";
3976 +      string function = "";
3977 +      if(currentString.find("(")==string::npos){
3978 +        inputVariable = currentString;// variable to cut on
3979 +      }
3980 +      else{
3981 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3982 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3983 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3984 +      }
3985 +      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3986 +
3987 +      currentString = parameters.inputVariables.at(1);
3988 +      inputVariable = "";
3989 +      function = "";
3990 +      if(currentString.find("(")==string::npos){
3991 +        inputVariable = currentString;// variable to cut on
3992 +      }
3993 +      else{
3994 +        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3995 +        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3996 +        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3997 +      }
3998 +      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3999 +
4000 +
4001 +      histo->Fill(valueX,valueY,scaleFactor);
4002 +
4003 +    }
4004 +  }
4005 +
4006 + }
4007 +
4008 +
4009 + template <class InputObject>
4010 + int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
4011 +
4012 +  int bestMatchIndex = -1;
4013 +  double bestMatchDeltaR = 999;
4014 +
4015 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4016 +
4017 +    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4018 +    if(currentDeltaR > 0.05) continue;
4019 +    //     cout << setprecision(3) << setw(20)
4020 +    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4021 +    //          << setw(20)
4022 +    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4023 +    //          << setw(20)
4024 +    //          << "\tdeltaR = " << currentDeltaR
4025 +    //          << setprecision(1)
4026 +    //          << setw(20)
4027 +    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4028 +    //          << setw(20)
4029 +    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4030 +    //          << setw(20)
4031 +    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4032 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4033 +      bestMatchIndex = mcparticle - mcparticles->begin();
4034 +      bestMatchDeltaR = currentDeltaR;
4035 +    }
4036 +
4037 +  }
4038 +  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4039 +  //   else cout << "no match found..." << endl;
4040 +  return bestMatchIndex;
4041 +
4042 + }
4043 +
4044 +
4045 + int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
4046 +
4047 +  int bestMatchIndex = -1;
4048 +  double bestMatchDeltaR = 999;
4049 +
4050 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4051 +
4052 +    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
4053 +
4054 +    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
4055 +    if(currentDeltaR > 0.05) continue;
4056 +
4057 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4058 +      bestMatchIndex = mcparticle - mcparticles->begin();
4059 +      bestMatchDeltaR = currentDeltaR;
4060 +    }
4061 +
4062 +  }
4063 +
4064 +  return bestMatchIndex;
4065 + }
4066 +
4067 +
4068 + // bin      particle type
4069 + // ---      -------------
4070 + //  0        unmatched
4071 + //  1        u
4072 + //  2        d
4073 + //  3        s
4074 + //  4        c
4075 + //  5        b
4076 + //  6        t
4077 + //  7        e
4078 + //  8        mu
4079 + //  9        tau
4080 + // 10        nu
4081 + // 11        g
4082 + // 12        gamma
4083 + // 13        Z
4084 + // 14        W
4085 + // 15        light meson
4086 + // 16        K meson
4087 + // 17        D meson
4088 + // 18        B meson
4089 + // 19        light baryon
4090 + // 20        strange baryon
4091 + // 21        charm baryon
4092 + // 22        bottom baryon
4093 + // 23        QCD string
4094 + // 24        other
4095 +
4096 + int OSUAnalysis::getPdgIdBinValue(int pdgId){
4097 +
4098 +  int binValue = -999;
4099 +  int absPdgId = fabs(pdgId);
4100 +  if(pdgId == -1) binValue = 0;
4101 +  else if(absPdgId <= 6 ) binValue = absPdgId;
4102 +  else if(absPdgId == 11 ) binValue = 7;
4103 +  else if(absPdgId == 13 ) binValue = 8;
4104 +  else if(absPdgId == 15 ) binValue = 9;
4105 +  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
4106 +  else if(absPdgId == 21 ) binValue = 11;
4107 +  else if(absPdgId == 22 ) binValue = 12;
4108 +  else if(absPdgId == 23 ) binValue = 13;
4109 +  else if(absPdgId == 24 ) binValue = 14;
4110 +  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
4111 +  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
4112 +  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
4113 +  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
4114 +  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
4115 +  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4116 +  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4117 +  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4118 +  else if(absPdgId == 92  ) binValue = 23;
4119 +
4120 +  else binValue = 24;
4121 +
4122 +  return binValue;
4123 +
4124 + }
4125 +
4126 + const BNprimaryvertex *
4127 + OSUAnalysis::chosenVertex ()
4128 + {
4129 +  const BNprimaryvertex *chosenVertex = 0;
4130 +  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4131 +    vector<bool> vertexFlags;
4132 +    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4133 +      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4134 +        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4135 +        break;
4136 +      }
4137 +    }
4138 +    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4139 +      if(!vertexFlags.at(vertexIndex)) continue;
4140 +      chosenVertex = & primaryvertexs->at(vertexIndex);
4141 +      break;
4142 +    }
4143 +  }
4144 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4145 +    chosenVertex = & primaryvertexs->at (0);
4146 +
4147 +  return chosenVertex;
4148 + }
4149 +
4150 + const BNmet *
4151 + OSUAnalysis::chosenMET ()
4152 + {
4153 +  const BNmet *chosenMET = 0;
4154 +  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4155 +    vector<bool> metFlags;
4156 +    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4157 +      if (cumulativeFlags.at("mets").at(i).size()){
4158 +        metFlags = cumulativeFlags.at("mets").at(i);
4159 +        break;
4160 +      }
4161 +    }
4162 +    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4163 +      if(!metFlags.at(metIndex)) continue;
4164 +      chosenMET = & mets->at(metIndex);
4165 +      break;
4166 +    }
4167 +  }
4168 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4169 +    chosenMET = & mets->at (0);
4170 +
4171 +  return chosenMET;
4172 + }
4173 +
4174 + const BNelectron *
4175 + OSUAnalysis::chosenElectron ()
4176 + {
4177 +  const BNelectron *chosenElectron = 0;
4178 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4179 +    vector<bool> electronFlags;
4180 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4181 +      if (cumulativeFlags.at("electrons").at(i).size()){
4182 +        electronFlags = cumulativeFlags.at("electrons").at(i);
4183 +        break;
4184 +      }
4185 +    }
4186 +    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4187 +      if(!electronFlags.at(electronIndex)) continue;
4188 +      chosenElectron = & electrons->at(electronIndex);
4189 +      break;
4190 +    }
4191 +  }
4192 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4193 +    chosenElectron = & electrons->at (0);
4194 +
4195 +  return chosenElectron;
4196 + }
4197 +
4198 + const BNmuon *
4199 + OSUAnalysis::chosenMuon ()
4200 + {
4201 +  const BNmuon *chosenMuon = 0;
4202 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4203 +    vector<bool> muonFlags;
4204 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4205 +      if (cumulativeFlags.at("muons").at(i).size()){
4206 +        muonFlags = cumulativeFlags.at("muons").at(i);
4207 +        break;
4208 +      }
4209 +    }
4210 +    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4211 +      if(!muonFlags.at(muonIndex)) continue;
4212 +      chosenMuon = & muons->at(muonIndex);
4213 +      break;
4214 +    }
4215 +  }
4216 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4217 +    chosenMuon = & muons->at (0);
4218 +
4219 +  return chosenMuon;
4220 + }
4221 +
4222 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines