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.93 by wulsin, Wed Jul 3 07:42:46 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 +  useEDMFormat_   (cfg.getParameter<bool>("useEDMFormat")),
32 +  treeBranchSets_   (cfg.getParameter<vector<edm::ParameterSet> >("treeBranchSets")),
33 +  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
34 +  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
35 +  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
36 +  applyBtagSF_ (cfg.getParameter<bool> ("applyBtagSF")),
37 +  minBtag_ (cfg.getParameter<int> ("minBtag")),
38 +  maxBtag_ (cfg.getParameter<int> ("maxBtag")),
39 +  printEventInfo_      (cfg.getParameter<bool> ("printEventInfo")),
40 +  printAllTriggers_    (cfg.getParameter<bool> ("printAllTriggers")),
41 +  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
42 +  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
43 +  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
44 + {
45  
46 +  TH1::SetDefaultSumw2 ();
47  
48 <  channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels"))
48 >  //create pile-up reweighting object, if necessary
49 >  if(datasetType_ != "data") {
50 >    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
51 >    if (applyLeptonSF_){
52 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
53 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
54 >    }
55 >    if (applyBtagSF_){
56 >      bTagSFWeight_ = new BtagSFWeight;
57 >    }
58 >  }
59 >  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
60 >    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
61  
23 {
24  TH1::SetDefaultSumw2 ();
62  
63    // Construct Cutflow Objects. These store the results of cut decisions and
64    // handle filling cut flow histograms.
65    masterCutFlow_ = new CutFlow (fs_);
66 <  std::vector<TFileDirectory> directories;
66 >
67 >  //always get vertex collection so we can assign the primary vertex in the event
68 >  objectsToGet.push_back("primaryvertexs");
69 >  objectsToPlot.push_back("primaryvertexs");
70 >  objectsToCut.push_back("primaryvertexs");
71 >
72 >
73 >  //always get the MC particles to do GEN-matching
74 >  objectsToGet.push_back("mcparticles");
75 >
76 >  //always get the event collection to do pile-up reweighting
77 >  objectsToGet.push_back("events");
78 >
79 >
80 >  // Parse the tree variable definitions.
81 >  for (uint iBranchSet = 0; !useEDMFormat_ && iBranchSet<treeBranchSets_.size(); iBranchSet++) {
82 >    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
83 >    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; }
84 >    objectsToGet.push_back(tempInputCollection);
85 >    objectsToCut.push_back(tempInputCollection);
86 >
87 >    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
88 >
89 >    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
90 >      BranchSpecs br;
91 >      br.inputCollection = tempInputCollection;
92 >      br.inputVariable = branchList.at(iBranch);
93 >      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);
94 >      br.name = string(newName.Data());
95 >      treeBranches_.push_back(br);
96 >    }
97 >
98 >  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++)
99 >
100 >
101 >  //parse the histogram definitions
102 >  for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
103 >
104 >    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
105 >    if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
106 >    if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
107 >    if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
108 >    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
109 >    if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
110 >    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
111 >    if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
112 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
113 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
114 >    if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
115 >    if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
116 >    if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
117 >    if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
118 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
119 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
120 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
121 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
122 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
123 >        int spaceIndex = tempInputCollection.find(" ");
124 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
125 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
126 >      }
127 >      else{
128 >        objectsToGet.push_back(tempInputCollection);
129 >      }
130 >      objectsToPlot.push_back(tempInputCollection);
131 >      objectsToCut.push_back(tempInputCollection);
132 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
133 >      string obj1;
134 >      string obj2;
135 >      getTwoObjs(tempInputCollection, obj1, obj2);
136 >      string obj2ToGet = getObjToGet(obj2);
137 >      objectsToCut.push_back(tempInputCollection);
138 >      objectsToCut.push_back(obj1);
139 >      objectsToCut.push_back(obj2);
140 >      objectsToPlot.push_back(tempInputCollection);
141 >      objectsToPlot.push_back(obj1);
142 >      objectsToPlot.push_back(obj2);
143 >      objectsToGet.push_back(tempInputCollection);
144 >      objectsToGet.push_back(obj1);
145 >      objectsToGet.push_back(obj2ToGet);
146 >    } // end else
147 >
148 >
149 >
150 >    vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
151 >
152 >    for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
153 >
154 >      vector<double> defaultValue;
155 >      defaultValue.push_back (-1.0);
156 >
157 >      histogram tempHistogram;
158 >      tempHistogram.inputCollection = tempInputCollection;
159 >      tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
160 >      tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
161 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
162 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
163 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
164 >      tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
165 >
166 >      histograms.push_back(tempHistogram);
167 >
168 >    }
169 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
170 >
171 >  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
172 >  sort( objectsToPlot.begin(), objectsToPlot.end() );
173 >  objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
174 >
175 >
176 >
177 >  //add histograms with the gen-matched id, mother id, and grandmother id
178 >  for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
179 >
180 >    string currentObject = objectsToPlot.at(currentObjectIndex);
181 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
182 >
183 >    histogram tempIdHisto;
184 >    histogram tempMomIdHisto;
185 >    histogram tempGmaIdHisto;
186 >    histogram tempIdVsMomIdHisto;
187 >    histogram tempIdVsGmaIdHisto;
188 >
189 >    tempIdHisto.inputCollection = currentObject;
190 >    tempMomIdHisto.inputCollection = currentObject;
191 >    tempGmaIdHisto.inputCollection = currentObject;
192 >    tempIdVsMomIdHisto.inputCollection = currentObject;
193 >    tempIdVsGmaIdHisto.inputCollection = currentObject;
194 >
195 >    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
196 >    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
197 >
198 >    currentObject = currentObject.substr(0, currentObject.size()-1);
199 >    tempIdHisto.name = currentObject+"GenMatchId";
200 >    tempMomIdHisto.name = currentObject+"GenMatchMotherId";
201 >    tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
202 >    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
203 >    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
204 >
205 >    currentObject.at(0) = toupper(currentObject.at(0));
206 >    tempIdHisto.title = currentObject+" Gen-matched Particle";
207 >    tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
208 >    tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
209 >    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
210 >    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
211 >
212 >
213 >    int maxNum = 25;
214 >    vector<double> binVector;
215 >    binVector.push_back(maxNum);
216 >    binVector.push_back(0);
217 >    binVector.push_back(maxNum);
218 >
219 >    tempIdHisto.bins = binVector;
220 >    tempIdHisto.inputVariables.push_back("genMatchedId");
221 >    tempMomIdHisto.bins = binVector;
222 >    tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
223 >    tempGmaIdHisto.bins = binVector;
224 >    tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
225 >    binVector.push_back(maxNum);
226 >    binVector.push_back(0);
227 >    binVector.push_back(maxNum);
228 >    tempIdVsMomIdHisto.bins = binVector;
229 >    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
230 >    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
231 >    tempIdVsGmaIdHisto.bins = binVector;
232 >    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
233 >    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
234 >
235 >    histograms.push_back(tempIdHisto);
236 >    histograms.push_back(tempMomIdHisto);
237 >    histograms.push_back(tempGmaIdHisto);
238 >    histograms.push_back(tempIdVsMomIdHisto);
239 >    histograms.push_back(tempIdVsGmaIdHisto);
240 >  }
241  
242  
243    channel tempChannel;
# Line 41 | Line 252 | OSUAnalysis::OSUAnalysis (const edm::Par
252      //set triggers for this channel
253      vector<string> triggerNames;
254      triggerNames.clear();
255 +    vector<string> triggerToVetoNames;
256 +    triggerToVetoNames.clear();
257 +
258      tempChannel.triggers.clear();
259 +    tempChannel.triggersToVeto.clear();
260      if(channels_.at(currentChannel).exists("triggers")){
261        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
262        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
263          tempChannel.triggers.push_back(triggerNames.at(trigger));
264 <      allNecessaryObjects.push_back("triggers");
264 >      objectsToGet.push_back("triggers");
265 >    }
266 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
267 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
268 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
269 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
270 >      objectsToGet.push_back("triggers");
271      }
272  
273  
274 +
275      //create cutFlow for this channel
276      cutFlows_.push_back (new CutFlow (fs_, channelName));
277 <
278 <    //book a directory in the output file with the name of the channel
279 <    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 <
277 >    vector<TFileDirectory> directories; //vector of directories in the output file.
278 >    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
279 >    vector<string> subSubDirNames;//subdirectories in each channel.
280      //get list of cuts for this channel
281      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
282  
105    vector<string> tempInputCollections;
106
283  
284      //loop over and parse all cuts
285      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
110
286        cut tempCut;
287 <     //store input collection for cut
288 <      string inputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
289 <      tempCut.inputCollection = inputCollection;
287 >      //store input collection for cut
288 >      string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
289 >      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
290 >      if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
291 >      if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
292 >      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
293 >      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
294 >      if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
295 >      if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
296 >      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
297 >      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
298 >      if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
299 >      if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
300 >      if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
301 >      if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
302 >      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
303 >      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
304 >      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
305 >      tempCut.inputCollection = tempInputCollection;
306 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
307 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
308 >          int spaceIndex = tempInputCollection.find(" ");
309 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
310 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
311 >        }
312 >        else{
313 >          objectsToGet.push_back(tempInputCollection);
314 >        }
315 >        objectsToCut.push_back(tempInputCollection);
316 >      }
317 >      else{//pair of objects, need to add them both to objectsToGet
318 >        string obj1;
319 >        string obj2;
320 >        getTwoObjs(tempInputCollection, obj1, obj2);
321 >        string obj2ToGet = getObjToGet(obj2);
322 >        objectsToCut.push_back(tempInputCollection);
323 >        objectsToCut.push_back(obj1);
324 >        objectsToCut.push_back(obj2);
325 >        objectsToGet.push_back(tempInputCollection);
326 >        objectsToGet.push_back(obj1);
327 >        objectsToGet.push_back(obj2ToGet);
328 >
329 >      }
330 >
331  
116      tempInputCollections.push_back(inputCollection);
117      allNecessaryObjects.push_back(inputCollection);
332  
333        //split cut string into parts and store them
334        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
335 <      std::vector<string> cutStringVector = splitString(cutString);
336 <      tempCut.variable = cutStringVector.at(0);// variable to cut on
337 <      tempCut.comparativeOperator = cutStringVector.at(1);// comparison to make
338 <      tempCut.cutValue = atof(cutStringVector.at(2).c_str());// threshold value to pass cut
335 >      vector<string> cutStringVector = splitString(cutString);
336 >      if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
337 >        cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
338 >        exit(0);
339 >      }
340 >      tempCut.numSubcuts = (cutStringVector.size()+1)/4;
341 >      for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
342 >        int indexOffset = 4 * subcutIndex;
343 >        string currentVariableString = cutStringVector.at(indexOffset);
344 >        if(currentVariableString.find("(")==string::npos){
345 >          tempCut.functions.push_back("");//no function was specified
346 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
347 >        }
348 >        else{
349 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
350 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
351 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
352 >        }
353 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
354 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
355 >        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
356 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
357 >      }
358  
359        //get number of objects required to pass cut for event to pass
360        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
361 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
361 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
362 >      if(numberRequiredVector.size()!=2){
363 >        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
364 >        exit(0);
365 >      }
366  
130      // determine number required if comparison contains "="
367        int numberRequiredInt = atoi(numberRequiredVector.at(1).c_str());
132      if(numberRequiredVector.at(0) == ">") numberRequiredInt++;
133      else if(numberRequiredVector.at(0) == "<") numberRequiredInt--;
134
368        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
369        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
370  
371 <      if(cuts_.at(currentCut).exists("function")){
372 <        tempCut.function = cuts_.at(currentCut).getParameter<string> ("function");
140 <      }
141 <      else tempCut.function = "";
371 >      //Set up vectors to store the directories and subDirectories for each channel.
372 >      string subSubDirName;
373        string tempCutName;
374        if(cuts_.at(currentCut).exists("alias")){
375          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
376 +        subSubDirName = "After " + tempCutName + " Cut Applied";
377        }
378        else{
379          //construct string for cutflow table
380          bool plural = numberRequiredInt != 1;
381 <        string collectionString = plural ? inputCollection : inputCollection.substr(0, inputCollection.size()-1);
381 >        string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
382          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
383          tempCutName = cutName;
384 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
385        }
153      tempCut.name = tempCutName;
386  
387 +      tempCut.isVeto = false;
388 +      if(cuts_.at(currentCut).exists("isVeto")){
389 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
390 +        if (isVeto == true) tempCut.isVeto = true;
391 +      }
392 +      subSubDirNames.push_back(subSubDirName);
393 +      tempCut.name = tempCutName;
394  
395        tempChannel.cuts.push_back(tempCut);
396  
397  
398      }//end loop over cuts
399  
400 <    //make unique vector of all objects that this channel cuts on (so we know to set flags for those)
401 <    sort( tempInputCollections.begin(), tempInputCollections.end() );
402 <    tempInputCollections.erase( unique( tempInputCollections.begin(), tempInputCollections.end() ), tempInputCollections.end() );
403 <    tempChannel.inputCollections = tempInputCollections;
400 >    vector<map<string, TH1D*>> oneDHistsTmp;
401 >    vector<map<string, TH2D*>> twoDHistsTmp;
402 >    //book a directory in the output file with the name of the channel
403 >    TFileDirectory subDir = fs_->mkdir( channelName );
404 >    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
405 >    if(GetPlotsAfterEachCut_){
406 >      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
407 >        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
408 >        directories.push_back(subSubDir);
409 >        map<string, TH1D*> oneDhistoMap;
410 >        oneDHistsTmp.push_back(oneDhistoMap);
411 >        map<string, TH2D*> twoDhistoMap;
412 >        twoDHistsTmp.push_back(twoDhistoMap);
413 >      }
414 >      treeDirectories.push_back(subDir);
415 >      oneDHists_.push_back(oneDHistsTmp);
416 >      twoDHists_.push_back(twoDHistsTmp);
417 >    }
418 >    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
419 >    else{
420 >      map<string, TH1D*> oneDhistoMap;
421 >      oneDHistsTmp.push_back(oneDhistoMap);
422 >      map<string, TH2D*> twoDhistoMap;
423 >      twoDHistsTmp.push_back(twoDhistoMap);
424 >      oneDHists_.push_back(oneDHistsTmp);
425 >      twoDHists_.push_back(twoDHistsTmp);
426 >      directories.push_back(subDir);
427 >      treeDirectories.push_back(subDir);
428 >
429 >    }
430 >
431 >    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
432 >      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
433 >      BNTrees_.push_back(newTree);
434 >      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
435 >        BranchSpecs currentVar = treeBranches_.at(iBranch);
436 >        vector<float> newVec;
437 >        BNTreeBranchVals_[currentVar.name] = newVec;
438 >        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
439 >      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
440 >    }
441 >
442 >    //book all histograms included in the configuration
443 >    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
444  
445 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
446 +
447 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
448 +        int numBinsElements = currentHistogram.bins.size();
449 +        int numInputVariables = currentHistogram.inputVariables.size();
450 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
451 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
452 +
453 +        if(numBinsElements == 1){
454 +          if(numBinEdgesX > 1){
455 +            if(numBinEdgesY > 1)
456 +              numBinsElements = 6;
457 +            else
458 +              numBinsElements = 3;
459 +          }
460 +        }
461 +        if(numBinsElements != 3 && numBinsElements !=6){
462 +          cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
463 +          exit(0);
464 +        }
465 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
466 +          cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
467 +          exit(0);
468 +        }
469 +        else if(numBinsElements == 3){
470 +          if (currentHistogram.bins.size () == 3)
471 +            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));
472 +          else
473 +            {
474 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
475 +            }
476 +        }
477 +        else if(numBinsElements == 6){
478 +          if (currentHistogram.bins.size () == 6)
479 +            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));
480 +          else
481 +            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 ());
482 +        }
483 +
484 +
485 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
486 +
487 +        // bin      particle type
488 +        // ---      -------------
489 +        //  0        unmatched
490 +        //  1        u
491 +        //  2        d
492 +        //  3        s
493 +        //  4        c
494 +        //  5        b
495 +        //  6        t
496 +        //  7        e
497 +        //  8        mu
498 +        //  9        tau
499 +        // 10        nu
500 +        // 11        g
501 +        // 12        gamma
502 +        // 13        Z
503 +        // 14        W
504 +        // 15        light meson
505 +        // 16        K meson
506 +        // 17        D meson
507 +        // 18        B meson
508 +        // 19        light baryon
509 +        // 20        strange baryon
510 +        // 21        charm baryon
511 +        // 22        bottom baryon
512 +        // 23        QCD string
513 +        // 24        other
514 +
515 +        vector<TString> labelArray;
516 +        labelArray.push_back("unmatched");
517 +        labelArray.push_back("u");
518 +        labelArray.push_back("d");
519 +        labelArray.push_back("s");
520 +        labelArray.push_back("c");
521 +        labelArray.push_back("b");
522 +        labelArray.push_back("t");
523 +        labelArray.push_back("e");
524 +        labelArray.push_back("#mu");
525 +        labelArray.push_back("#tau");
526 +        labelArray.push_back("#nu");
527 +        labelArray.push_back("g");
528 +        labelArray.push_back("#gamma");
529 +        labelArray.push_back("Z");
530 +        labelArray.push_back("W");
531 +        labelArray.push_back("light meson");
532 +        labelArray.push_back("K meson");
533 +        labelArray.push_back("D meson");
534 +        labelArray.push_back("B meson");
535 +        labelArray.push_back("light baryon");
536 +        labelArray.push_back("strange baryon");
537 +        labelArray.push_back("charm baryon");
538 +        labelArray.push_back("bottom baryon");
539 +        labelArray.push_back("QCD string");
540 +        labelArray.push_back("other");
541 +
542 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
543 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
544 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
545 +          }
546 +          else {
547 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
548 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
549 +          }
550 +        }
551 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
552 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
553 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
554 +        }
555 +
556 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
557 +
558 +
559 +      // Book a histogram for the number of each object type to be plotted.
560 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
561 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
562 +        string currentObject = objectsToPlot.at(currentObjectIndex);
563 +        int maxNum = 10;
564 +        if(currentObject == "mcparticles") maxNum = 50;
565 +        else if(currentObject == "primaryvertexs") maxNum = 50;
566 +
567 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
568 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
569 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
570 +        else if(currentObject == "electron-photon pairs")     currentObject = "electronPhotonPairs";
571 +        else if(currentObject == "muon-photon pairs")         currentObject = "muonPhotonPairs";
572 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
573 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
574 +        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
575 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
576 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
577 +        else if(currentObject == "photon-jet pairs")          currentObject = "photonJetPairs";
578 +        else if(currentObject == "met-jet pairs")             currentObject = "metJetPairs";
579 +        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
580 +        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
581 +        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
582 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
583 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
584 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
585 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
586 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
587 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
588 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
589 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
590 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
591 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
592 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
593 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
594 +
595 +        currentObject.at(0) = toupper(currentObject.at(0));
596 +        string histoName = "num" + currentObject;
597 +
598 +        if(histoName == "numPrimaryvertexs"){
599 +          string newHistoName = histoName + "BeforePileupCorrection";
600 +          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);
601 +          newHistoName = histoName + "AfterPileupCorrection";
602 +          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);
603 +        }
604 +        else
605 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
606 +      }
607 +    }//end of loop over directories
608      channels.push_back(tempChannel);
609      tempChannel.cuts.clear();
168
610    }//end loop over channels
611  
171  //make unique vector of objects we need to cut on (so we make sure to get them from the event)
172  sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
173  allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
612  
613 +  //make unique vector of objects we need to get from the event
614 +  sort( objectsToGet.begin(), objectsToGet.end() );
615 +  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
616 +  //make unique vector of objects we need to cut on
617 +  sort( objectsToCut.begin(), objectsToCut.end() );
618 +  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
619 +
620 +  produces<map<string, bool> > ("channelDecisions");
621 +
622 + } // end constructor OSUAnalysis::OSUAnalysis()
623  
176 }
624  
625   OSUAnalysis::~OSUAnalysis ()
626   {
627 +
628    // Destroying the CutFlow objects causes the cut flow numbers and time
629    // information to be printed to standard output.
630    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
631      delete cutFlows_.at(currentChannel);
632    }
633 +
634 +  cout << "=============================================" << endl;  
635 +  cout << "Successfully completed OSUAnalysis." << endl;  
636 +  cout << "=============================================" << endl;  
637 +
638   }
639  
640   void
641 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
641 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
642   {
190
191
643    // Retrieve necessary collections from the event.
644 <  edm::Handle<BNtriggerCollection> triggers;
645 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
644 >
645 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
646      event.getByLabel (triggers_, triggers);
647  
648 <  edm::Handle<BNjetCollection> jets;
649 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())
648 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
649 >    event.getByLabel (trigobjs_, trigobjs);
650 >
651 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
652      event.getByLabel (jets_, jets);
653  
654 <  edm::Handle<BNmuonCollection> muons;
202 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())
654 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
655      event.getByLabel (muons_, muons);
656  
657 <  edm::Handle<BNelectronCollection> electrons;
206 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())
657 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
658      event.getByLabel (electrons_, electrons);
659  
660 <  edm::Handle<BNeventCollection> events;
210 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())
660 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
661      event.getByLabel (events_, events);
662  
663 <  edm::Handle<BNtauCollection> taus;
214 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())
663 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
664      event.getByLabel (taus_, taus);
665  
666 <  edm::Handle<BNmetCollection> mets;
218 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())
666 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
667      event.getByLabel (mets_, mets);
668  
669 <  edm::Handle<BNtrackCollection> tracks;
222 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())
669 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
670      event.getByLabel (tracks_, tracks);
671  
672 <  edm::Handle<BNgenjetCollection> genjets;
226 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())
672 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
673      event.getByLabel (genjets_, genjets);
674  
675 <  edm::Handle<BNmcparticleCollection> mcparticles;
230 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())
675 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
676      event.getByLabel (mcparticles_, mcparticles);
677  
678 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
234 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())
678 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
679      event.getByLabel (primaryvertexs_, primaryvertexs);
680  
681 <  edm::Handle<BNbxlumiCollection> bxlumis;
238 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())
681 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
682      event.getByLabel (bxlumis_, bxlumis);
683  
684 <  edm::Handle<BNphotonCollection> photons;
242 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())
684 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
685      event.getByLabel (photons_, photons);
686  
687 <  edm::Handle<BNsuperclusterCollection> superclusters;
246 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())
687 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
688      event.getByLabel (superclusters_, superclusters);
689  
690 +  if (datasetType_ == "signalMC"){
691 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
692 +      event.getByLabel (stops_, stops);
693 +  }
694 +
695 +  if (useTrackCaloRhoCorr_) {
696 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
697 +    // This rho collection is not available in all BEANs.
698 +    // For description of rho values for different jet reconstruction algorithms, see
699 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
700 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
701 +  }
702 +
703 +  double masterScaleFactor = 1.0;
704 +
705 +  //get pile-up event weight
706 +  if (doPileupReweighting_ && datasetType_ != "data") {
707 +    //for "data" datasets, the numTruePV is always set to -1
708 +    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
709 +    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
710 +  }
711 +
712 +  stopCTauScaleFactor_ = 1.0;
713 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
714 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
715 +  masterScaleFactor *= stopCTauScaleFactor_;
716  
717    //loop over all channels
718  
719 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
720    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
721      channel currentChannel = channels.at(currentChannelIndex);
722  
723      flagMap individualFlags;
256    flagMap cumulativeFlags;
724      counterMap passingCounter;
725 +    cumulativeFlags.clear ();
726 +
727 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
728 +         iter != BNTreeBranchVals_.end(); iter++) {
729 +      iter->second.clear();  // clear array
730 +    }
731  
732      bool triggerDecision = true;
733 <    if(currentChannel.triggers.size() != 0){  //triggers specified
734 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
733 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
734 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
735        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
736      }
737  
738      //loop over all cuts
739      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
740        cut currentCut = currentChannel.cuts.at(currentCutIndex);
741 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
742 +        string currentObject = objectsToCut.at(currentObjectIndex);
743  
744 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
744 >        //initialize maps to get ready to set cuts
745 >        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
746 >        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
747 >
748 >      }
749 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
750 >        string currentObject = objectsToCut.at(currentObjectIndex);
751  
752 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
272 <        individualFlags[currentObject].push_back (vector<bool> ());
273 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
752 >        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
753  
754 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
755 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
754 >
755 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
756 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
757 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
758 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
759 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
760          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
761          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
762          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 285 | Line 768 | OSUAnalysis::analyze (const edm::Event &
768          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
769          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
770          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
771 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
772  
773  
290      }
291
774  
775 +        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
776 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
777 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
778 +                                                                   "muon-muon pairs");
779 +
780 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
781 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
782 +                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
783 +                                                                             "muon-secondary muon pairs");
784 +
785 +        else if(currentObject == "muon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
786 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
787 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
788 +                                                                             "muon-secondary jet pairs");
789 +        else if(currentObject == "photon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
790 +                                                                             cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
791 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
792 +                                                                             "photon-secondary jet pairs");
793 +
794 +        else if(currentObject == "electron-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
795 +                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
796 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
797 +                                                                             "electron-secondary jet pairs");
798 +
799 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
800 +                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
801 +                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
802 +                                                                                     "electron-secondary electron pairs");
803 +
804 +        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
805 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
806 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
807 +                                                                           "electron-electron pairs");
808 +        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
809 +                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
810 +                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
811 +                                                                       "electron-muon pairs");
812 +        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
813 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
814 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
815 +                                                                 "jet-jet pairs");
816 +        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
817 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
818 +                                                                 cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex),\
819 +                                                                 "jet-secondary jet pairs");
820 +        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
821 +                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
822 +                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
823 +                                                                      "electron-jet pairs");
824 +        else if(currentObject == "electron-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), \
825 +                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
826 +                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
827 +                                                                      "electron-photon pairs");
828 +        else if(currentObject == "photon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
829 +                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
830 +                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
831 +                                                                      "photon-jet pairs");
832 +        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
833 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
834 +                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
835 +                                                                  "muon-jet pairs");
836 +        else if(currentObject == "met-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
837 +                                                                  cumulativeFlags.at("mets").at(flagsForPairCutsIndex), \
838 +                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
839 +                                                                  "met-jet pairs");
840 +        else if(currentObject == "muon-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
841 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
842 +                                                                  cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
843 +                                                                  "muon-photon pairs");
844 +        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
845 +                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
846 +                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
847 +                                                                     "track-event pairs");
848 +        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
849 +                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
850 +                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
851 +                                                                        "electron-track pairs");
852 +        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
853 +                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
854 +                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
855 +                                                                    "muon-track pairs");
856 +        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
857 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
858 +                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
859 +                                                                  "muon-tau pairs");
860 +        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
861 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
862 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
863 +                                                                 "tau-tau pairs");
864 +        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
865 +                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
866 +                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
867 +                                                                   "tau-track pairs");
868 +        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
869 +                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
870 +                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
871 +                                                                          "electron-trigobj pairs");
872 +        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
873 +                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
874 +                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
875 +                                                                      "muon-trigobj pairs");
876  
877 <    }//end loop over all cuts
878 <
877 >        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
878 >      }
879  
880  
881  
882 +    }//end loop over all cuts
883      //use cumulative flags to apply cuts at event level
884  
885 +    //a vector to store cumulative cut descisions after each cut.
886 +    vector<bool> eventPassedPreviousCuts;
887      bool eventPassedAllCuts = true;
302
888      //apply trigger (true if none were specified)
889      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
890  
306
891      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
892  
893        //loop over all objects and count how many passed the cumulative selection up to this point
894        cut currentCut = currentChannel.cuts.at(currentCutIndex);
895        int numberPassing = 0;
896  
897 <      for (uint object = 0; object != cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).size() ; object++)
898 <          if(cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).at(object)) numberPassing++;
899 <
316 <
897 >      for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
898 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
899 >      }
900        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
901        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
319
902        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
903 +      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
904 +    }
905 +    double scaleFactor = masterScaleFactor;
906  
907 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
908 +    if(applyLeptonSF_ && datasetType_ != "data"){
909 +      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
910 +        flagPair muonFlags;
911 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
912 +          if (cumulativeFlags.at("muons").at(i).size()){
913 +            muonFlags = cumulativeFlags.at("muons").at(i);
914 +            break;
915 +          }
916 +        }
917 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
918 +          if(!muonFlags.at(muonIndex).second) continue;
919 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
920 +        }
921 +      }
922 +      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
923 +        flagPair electronFlags;
924 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
925 +          if (cumulativeFlags.at("electrons").at(i).size()){
926 +            electronFlags = cumulativeFlags.at("electrons").at(i);
927 +            break;
928 +          }
929 +        }
930 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
931 +          if(!electronFlags.at(electronIndex).second) continue;
932 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
933 +        }
934 +      }
935 +    }
936 +    if(applyBtagSF_ && datasetType_ != "data"){
937 +     if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
938 +       flagPair jetFlags;
939 +        vector<double> jetSFs;
940 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
941 +          if (cumulativeFlags.at("jets").at(i).size()){
942 +            jetFlags = cumulativeFlags.at("jets").at(i);
943 +            break;
944 +          }
945 +        }
946 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
947 +          if(!jetFlags.at(jetIndex).second) continue;
948 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour);
949 +          jetSFs.push_back(jetSFTmp);
950 +        }
951 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_, maxBtag_ );
952 +      }
953 +    }
954 +    scaleFactor *= muonScaleFactor_;
955 +    scaleFactor *= electronScaleFactor_;
956 +    scaleFactor *= bTagScaleFactor_;
957 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
958 +
959 +    if (printEventInfo_) {
960 +      // Write information about event to screen, for testing purposes.
961 +      cout << "Event passed all cuts in channel " <<  currentChannel.name
962 +           << ": run="  << events->at(0).run
963 +           << "  lumi=" << events->at(0).lumi
964 +           << "  event=" << events->at(0).evt
965 +           << endl;
966      }
967  
324    cutFlows_.at(currentChannelIndex)->fillCutFlow();
968  
969 +    //filling histograms
970 +    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
971 +      uint currentDir;
972 +      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
973 +      else{
974 +        currentDir = currentCut;
975 +      }
976  
977  
978 <    if(!eventPassedAllCuts)continue;
978 >      if(eventPassedPreviousCuts.at(currentDir)){
979  
980 +        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
981 +          histogram currentHistogram = histograms.at(histogramIndex);
982  
983 <    TVector3 vertexPosition;
332 <    vector<bool> vertexFlags = cumulativeFlags["primaryvertexs"].back();
983 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) cout << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
984  
985 <    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
986 <      if(!vertexFlags.at(vertexIndex)) continue;
985 >          if(currentHistogram.inputVariables.size() == 1){
986 >            TH1D* histo;
987 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
988 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
989 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
990 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
991 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
992 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
993 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
994 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
995 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
996 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
997 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
998 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
999 >             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1000 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1001 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1002 >             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1003 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1004 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1005 >             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1006 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1007 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1008 >
1009 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1010 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
1011 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
1012 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1013 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
1014 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
1015 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1016 >             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1017 >                                                                                                     cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1018 >                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1019 >
1020 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1021 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1022 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1023 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
1024 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
1025 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1026 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
1027 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1028 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1029 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(), \
1030 >                                                                                              cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1031 >                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1032 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
1033 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1034 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1035 >            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
1036 >                                                                                          cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1037 >                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1038 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(), \
1039 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1040 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1041 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(), \
1042 >                                                                                          cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1043 >                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1044 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1045 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1046 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1047 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1048 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1049 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1050 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1051 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1052 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1053 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1054 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1055 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1056 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1057 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1058 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1059 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1060 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1061 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1062 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1063 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1064 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1065 >
1066 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1067 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1068 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1069 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1070 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1071 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1072 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1073 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1074 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1075 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1076 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1077 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1078 >          }
1079 >          else if(currentHistogram.inputVariables.size() == 2){
1080 >            TH2D* histo;
1081 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1082 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1083 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1084 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1085 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1086 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1087 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1088 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1089 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1090 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1091 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1092 >            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1093 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1094 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1095 >            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1096 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1097 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1098 >            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1099 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1100 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1101 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1102 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1103 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1104 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1105 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1106 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1107 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1108 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1109 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1110 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1111 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1112 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1113 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1114 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1115 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1116 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1117 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1118 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(), \
1119 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1120 >                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1121 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1122 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1123 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1124 >            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1125 >                                                                                         cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1126 >                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1127 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1128 >                                                                                          cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1129 >                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1130 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1131 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1132 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1133 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1134 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1135 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1136 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1137 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1138 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1139 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1140 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1141 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1142 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1143 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1144 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1145 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1146 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1147 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1148 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1149 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1150 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1151 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1152 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1153 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1154 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1155 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1156 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1157 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1158 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1159 >                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1160 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1161 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1162 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1163 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1164 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1165 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1166 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1167 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1168 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1169 >          }
1170  
1171 <      vertexPosition.SetXYZ (primaryvertexs->at(vertexIndex).x,primaryvertexs->at(vertexIndex).y,primaryvertexs->at(vertexIndex).z);
338 <      break;
339 <    }
1171 >        }
1172  
341    vector<bool> mcparticleFlags = cumulativeFlags["mcparticles"].back();
1173  
1174 <    for (uint mcparticleIndex = 0; mcparticleIndex != mcparticleFlags.size(); mcparticleIndex++){
1175 <      if(!mcparticleFlags.at(mcparticleIndex)) continue;
1174 >        //fills histograms with the sizes of collections
1175 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1176  
1177 <      double vx = mcparticles->at(mcparticleIndex).vx - vertexPosition.X (),
1178 <             vy = mcparticles->at(mcparticleIndex).vy - vertexPosition.Y (),
348 <             vz = mcparticles->at(mcparticleIndex).vz - vertexPosition.Z (),
349 <             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));
359 <    }
1177 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1178 >          string objectToPlot = "";
1179  
1180 <    vector<bool> electronFlags = cumulativeFlags["electrons"].back();
1181 <    int electronCounter = 0;
1180 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1181 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1182 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1183 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1184 >          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1185 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1186 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1187 >          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1188 >          else if(currentObject == "muon-photon pairs")                  objectToPlot = "muonPhotonPairs";
1189 >          else if(currentObject == "photon-jet pairs")                   objectToPlot = "photonJetPairs";
1190 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1191 >          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1192 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1193 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1194 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1195 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1196 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1197 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1198 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1199 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1200 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1201 >          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1202 >          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1203 >          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1204 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1205 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1206 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1207 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1208 >          else objectToPlot = currentObject;
1209 >
1210 >          string tempCurrentObject = objectToPlot;
1211 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1212 >          string histoName = "num" + tempCurrentObject;
1213 >
1214 >
1215 >          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1216 >            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1217 >            int numToPlot = 0;
1218 >            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1219 >              if(lastCutFlags.at(currentFlag).second) numToPlot++;
1220 >            }
1221 >
1222 >            if(objectToPlot == "primaryvertexs"){
1223 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1224 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1225 >            }
1226 >            else {
1227 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1228 >            }
1229 >          }
1230 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1231  
364    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
365      if(!electronFlags.at(electronIndex)) continue;
1232  
1233 +      } // end if(eventPassedPreviousCuts.at(currentDir))
1234 +    } // end loop over cuts
1235  
1236 <      electronCounter++;
1237 <      oneDHists_.at(currentChannelIndex)["electronPt"]->Fill (electrons->at(electronIndex).pt);
1238 <      oneDHists_.at(currentChannelIndex)["electronEta"]->Fill (electrons->at(electronIndex).eta);
1239 <      oneDHists_.at(currentChannelIndex)["electronD0"]->Fill (electrons->at(electronIndex).correctedD0Vertex);
1240 <      oneDHists_.at(currentChannelIndex)["electronDz"]->Fill (electrons->at(electronIndex).correctedDZ);
1241 <      oneDHists_.at(currentChannelIndex)["electronAbsD0"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex));
1242 <      oneDHists_.at(currentChannelIndex)["electronDZ"]->Fill (electrons->at(electronIndex).correctedDZ);
1243 <      oneDHists_.at(currentChannelIndex)["electronAbsDZ"]->Fill (fabs(electrons->at(electronIndex).correctedDZ));
1244 <      oneDHists_.at(currentChannelIndex)["electronD0Sig"]->Fill (electrons->at(electronIndex).correctedD0Vertex / electrons->at(electronIndex).tkD0err);
1245 <      oneDHists_.at(currentChannelIndex)["electronAbsD0Sig"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex) / electrons->at(electronIndex).tkD0err);
1246 <      oneDHists_.at(currentChannelIndex)["electronIso"]->Fill (electrons->at(electronIndex).puChargedHadronIso / electrons->at(electronIndex).pt);
1247 <      oneDHists_.at(currentChannelIndex)["electronFbrem"]->Fill (electrons->at(electronIndex).fbrem);
1248 <      oneDHists_.at(currentChannelIndex)["electronMVATrig"]->Fill (electrons->at(electronIndex).mvaTrigV0);
1249 <      oneDHists_.at(currentChannelIndex)["electronMVANonTrig"]->Fill (electrons->at(electronIndex).mvaNonTrigV0);
1236 >    if (!useEDMFormat_ && eventPassedAllCuts){
1237 >      // Assign BNTree variables
1238 >      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1239 >        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1240 >        string coll = brSpecs.inputCollection;
1241 >        if (cumulativeFlags.count(coll) == 0) cout << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1242 >
1243 >        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1244 >        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1245 >        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1246 >        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1247 >        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1248 >        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1249 >        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1250 >        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1251 >        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1252 >        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1253 >        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1254 >        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1255 >        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1256 >        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1257 >        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1258 >        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1259 >        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1260 >        else if(coll == "stops"
1261 >                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1262 >      } // end loop over branches
1263  
1264 +      if (!BNTrees_.at(currentChannelIndex)) { cout << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1265 +      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1266      }
384    oneDHists_.at(currentChannelIndex)["numElectrons"]->Fill (electronCounter);
1267  
1268 +    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1269  
1270 <    vector<bool> muonFlags = cumulativeFlags["muons"].back();
388 <    int muonCounter = 0;
1270 >  } // end loop over channel
1271  
1272 +  masterCutFlow_->fillCutFlow(masterScaleFactor);
1273  
1274 <    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);
407 <
1274 >  event.put (channelDecisions, "channelDecisions");
1275  
1276 + } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1277  
1278  
1279  
1280 <  } //end loop over channel
1280 > bool
1281 > OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
1282  
414  masterCutFlow_->fillCutFlow();
1283  
1284 +  if(comparison == ">")       return testValue >  cutValue;
1285 +  else if(comparison == ">=") return testValue >= cutValue;
1286 +  else if(comparison == "<")  return testValue <  cutValue;
1287 +  else if(comparison == "<=") return testValue <= cutValue;
1288 +  else if(comparison == "==") return testValue == cutValue;
1289 +  else if(comparison == "=") return testValue == cutValue;
1290 +  else if(comparison == "!=") return testValue != cutValue;
1291 +  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1292  
1293   }
1294  
419
1295   bool
1296 < OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
1296 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1297  
1298  
1299    if(comparison == ">")       return testValue >  cutValue;
# Line 426 | Line 1301 | OSUAnalysis::evaluateComparison (double
1301    else if(comparison == "<")  return testValue <  cutValue;
1302    else if(comparison == "<=") return testValue <= cutValue;
1303    else if(comparison == "==") return testValue == cutValue;
1304 +  else if(comparison == "=") return testValue == cutValue;
1305    else if(comparison == "!=") return testValue != cutValue;
1306 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1306 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1307  
1308   }
1309  
1310   bool
1311 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1311 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1312  
1313 +  //initialize to false until a chosen trigger is passed
1314    bool triggerDecision = false;
1315  
1316 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1317 <    {
1318 <      if(trigger->pass != 1) continue;
1319 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1320 <        {
1321 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1322 <            triggerDecision = true;
1323 <          }
1324 <        }
1316 >  if (printAllTriggers_) cout << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1317 >  //loop over all triggers defined in the event
1318 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1319 >
1320 >    if (printAllTriggers_) cout << "   " << trigger->name << endl;
1321 >
1322 >    //we're only interested in triggers that actually passed
1323 >    if(trigger->pass != 1) continue;
1324 >
1325 >    //if the event passes one of the veto triggers, exit and return false
1326 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1327 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1328      }
1329 <  return triggerDecision;
1329 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1330 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1331 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1332 >    }
1333 >  }
1334  
1335 +  printAllTriggers_ = false;  // only print triggers once, not every event
1336 +
1337 +  //if none of the veto triggers fired:
1338 +  //return the OR of all the chosen triggers
1339 +  if (triggersToTest.size() != 0) return triggerDecision;
1340 +  //or if no triggers were defined return true
1341 +  else return true;
1342   }
1343  
1344 < std::vector<std::string>
1344 >
1345 > vector<string>
1346   OSUAnalysis::splitString (string inputString){
1347  
1348 <  std::stringstream stringStream(inputString);
1349 <  std::istream_iterator<std::string> begin(stringStream);
1350 <  std::istream_iterator<std::string> end;
1351 <  std::vector<std::string> stringVector(begin, end);
1348 >  stringstream stringStream(inputString);
1349 >  istream_iterator<string> begin(stringStream);
1350 >  istream_iterator<string> end;
1351 >  vector<string> stringVector(begin, end);
1352    return stringVector;
1353  
1354   }
1355  
1356 +
1357 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1358 +  // Set two object strings from the tempInputCollection string,
1359 +  // For example, if tempInputCollection is "electron-muon pairs",
1360 +  // then obj1 = "electrons" and obj2 = "muons".
1361 +  // Note that the objects have an "s" appended.
1362 +
1363 +  int dashIndex = tempInputCollection.find("-");
1364 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1365 +  int secondWordLength = spaceIndex - dashIndex;
1366 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1367 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1368 +
1369 + }
1370 +
1371 +
1372 + string OSUAnalysis::getObjToGet(string obj) {
1373 +  // Return the string corresponding to the object to get for the given obj string.
1374 +  // Right now this only handles the case in which obj contains "secondary",
1375 +  // e.g, "secondary muons".
1376 +  // Note that "s" is NOT appended.
1377 +
1378 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1379 +  int firstSpaceIndex = obj.find_first_of(" ");
1380 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1381 +
1382 + }
1383 +
1384 +
1385 + //!jet valueLookup
1386   double
1387 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1387 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1388  
1389    double value = 0.0;
1390    if(variable == "energy") value = object->energy;
# Line 581 | Line 1503 | OSUAnalysis::valueLookup (const BNjet* o
1503    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1504    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1505  
1506 +  //user defined variable
1507 +  else if(variable == "disappTrkLeadingJetID") {
1508 +    value = object->pt > 110
1509 +      && fabs(object->eta) < 2.4
1510 +      && object->chargedHadronEnergyFraction > 0.2
1511 +      && object->neutralHadronEnergyFraction < 0.7
1512 +      && object->chargedEmEnergyFraction < 0.5
1513 +      && object->neutralEmEnergyFraction < 0.7;
1514 +  }
1515 +
1516 +  else if(variable == "disappTrkSubLeadingJetID") {
1517 +    value = object->pt > 30
1518 +      && fabs(object->eta) < 4.5
1519 +      && object->neutralHadronEnergyFraction < 0.7
1520 +      && object->chargedEmEnergyFraction < 0.5;
1521 +  }
1522 +
1523 +  else if(variable == "dPhiMet") {
1524 +    if (const BNmet *met = chosenMET ()) {
1525 +      value = deltaPhi (object->phi, met->phi);
1526 +    } else value = -999;
1527 +  }
1528  
1529 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1529 >
1530 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1531  
1532    value = applyFunction(function, value);
1533  
1534    return value;
1535 < }
591 <
1535 > } // end jet valueLookup
1536  
1537  
1538 + //!muon valueLookup
1539   double
1540 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1540 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1541  
1542    double value = 0.0;
1543    if(variable == "energy") value = object->energy;
# Line 608 | Line 1553 | OSUAnalysis::valueLookup (const BNmuon*
1553    else if(variable == "ecalIso") value = object->ecalIso;
1554    else if(variable == "hcalIso") value = object->hcalIso;
1555    else if(variable == "caloIso") value = object->caloIso;
1556 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
1556 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
1557    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
1558    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
1559    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 746 | Line 1691 | OSUAnalysis::valueLookup (const BNmuon*
1691    else if(variable == "numberOfMatchedStations") value = object->numberOfMatchedStations;
1692    else if(variable == "time_ndof") value = object->time_ndof;
1693  
1694 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1694 >  //user-defined variables
1695 >  else if(variable == "looseID") {
1696 >    value = object->pt > 10 &&
1697 >      (object->isGlobalMuon  > 0 ||
1698 >       object->isTrackerMuon > 0);
1699 >  }
1700 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1701 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1702 >  else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1703 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1704 >  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1705 >  else if(variable == "metMT") {
1706 >    if (const BNmet *met = chosenMET ())
1707 >      {
1708 >        double dPhi = deltaPhi (object->phi, met->phi);
1709 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1710 >      }
1711 >    else
1712 >      value = -999;
1713 >  }
1714 >
1715 >
1716 >
1717 >  else if(variable == "correctedD0VertexInEBPlus"){
1718 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1719 >    else value = -999;
1720 >  }
1721 >  else if(variable == "correctedD0VertexOutEBPlus"){
1722 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1723 >    else value = -999;
1724 >  }
1725 >  else if(variable == "correctedD0VertexEEPlus"){
1726 >    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1727 >    else value = -999;
1728 >  }
1729 >
1730 >  else if(variable == "correctedD0BeamspotInEBPlus"){
1731 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1732 >    else value = -999;
1733 >  }
1734 >  else if(variable == "correctedD0BeamspotOutEBPlus"){
1735 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1736 >    else value = -999;
1737 >  }
1738 >  else if(variable == "correctedD0BeamspotEEPlus"){
1739 >    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1740 >    else value = -999;
1741 >  }
1742 >
1743 >  else if(variable == "correctedD0VertexInEBMinus"){
1744 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1745 >    else value = -999;
1746 >  }
1747 >  else if(variable == "correctedD0VertexOutEBMinus"){
1748 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1749 >    else value = -999;
1750 >  }
1751 >  else if(variable == "correctedD0VertexEEMinus"){
1752 >    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1753 >    else value = -999;
1754 >  }
1755 >
1756 >  else if(variable == "correctedD0BeamspotInEBMinus"){
1757 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1758 >    else value = -999;
1759 >  }
1760 >  else if(variable == "correctedD0BeamspotOutEBMinus"){
1761 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1762 >    else value = -999;
1763 >  }
1764 >  else if(variable == "correctedD0BeamspotEEMinus"){
1765 >    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1766 >    else value = -999;
1767 >  }
1768 >
1769 >
1770 >  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1771 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1772 >    else value = -999;
1773 >  }
1774 >  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1775 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1776 >    else value = -999;
1777 >  }
1778 >  else if(variable == "correctedD0VertexEEPositiveCharge"){
1779 >    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1780 >    else value = -999;
1781 >  }
1782 >
1783 >  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1784 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1785 >    else value = -999;
1786 >  }
1787 >  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1788 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1789 >    else value = -999;
1790 >  }
1791 >  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1792 >    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1793 >    else value = -999;
1794 >  }
1795 >
1796 >  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1797 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1798 >    else value = -999;
1799 >  }
1800 >  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1801 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1802 >    else value = -999;
1803 >  }
1804 >  else if(variable == "correctedD0VertexEENegativeCharge"){
1805 >    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1806 >    else value = -999;
1807 >  }
1808 >
1809 >  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1810 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1811 >    else value = -999;
1812 >  }
1813 >  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1814 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1815 >    else value = -999;
1816 >  }
1817 >  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1818 >    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1819 >    else value = -999;
1820 >  }
1821 >
1822 >
1823 >  else if(variable == "tightID") {
1824 >    value = object->isGlobalMuon > 0                \
1825 >      && object->isPFMuon > 0                        \
1826 >      && object->normalizedChi2 < 10                \
1827 >      && object->numberOfValidMuonHits > 0        \
1828 >      && object->numberOfMatchedStations > 1        \
1829 >      && fabs(object->correctedD0Vertex) < 0.2        \
1830 >      && fabs(object->correctedDZ) < 0.5        \
1831 >      && object->numberOfValidPixelHits > 0                \
1832 >      && object->numberOfLayersWithMeasurement > 5;
1833 >  }
1834 >  else if(variable == "tightIDdisplaced"){
1835 >    value = object->isGlobalMuon > 0                \
1836 >      && object->isPFMuon > 0                        \
1837 >      && object->normalizedChi2 < 10                \
1838 >      && object->numberOfValidMuonHits > 0        \
1839 >      && object->numberOfMatchedStations > 1        \
1840 >      && object->numberOfValidPixelHits > 0        \
1841 >      && object->numberOfLayersWithMeasurement > 5;
1842 >  }
1843 >
1844 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1845 >
1846 >  else if(variable == "genMatchedPdgId"){
1847 >    int index = getGenMatchedParticleIndex(object);
1848 >    if(index == -1) value = 0;
1849 >    else value = mcparticles->at(index).id;
1850 >  }
1851 >
1852 >  else if(variable == "genMatchedId"){
1853 >    int index = getGenMatchedParticleIndex(object);
1854 >    if(index == -1) value = 0;
1855 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
1856 >  }
1857 >  else if(variable == "genMatchedMotherId"){
1858 >    int index = getGenMatchedParticleIndex(object);
1859 >    if(index == -1) value = 0;
1860 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1861 >  }
1862 >  else if(variable == "genMatchedMotherIdReverse"){
1863 >    int index = getGenMatchedParticleIndex(object);
1864 >    if(index == -1) value = 24;
1865 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1866 >  }
1867 >  else if(variable == "genMatchedGrandmotherId"){
1868 >    int index = getGenMatchedParticleIndex(object);
1869 >    if(index == -1) value = 0;
1870 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1871 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1872 >      if(motherIndex == -1) value = 0;
1873 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1874 >    }
1875 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1876 >  }
1877 >  else if(variable == "genMatchedGrandmotherIdReverse"){
1878 >    int index = getGenMatchedParticleIndex(object);
1879 >    if(index == -1) value = 24;
1880 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1881 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1882 >      if(motherIndex == -1) value = 24;
1883 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1884 >    }
1885 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1886 >  }
1887 >  else if(variable == "pfMuonsFromVertex"){
1888 >    double d0Error, dzError;
1889 >
1890 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1891 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1892 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1893 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1894 >      || fabs (object->correctedDZ / dzError) > 99.0;
1895 >    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1896 >  }
1897 >
1898 >
1899 >
1900 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1901  
1902    value = applyFunction(function, value);
1903  
1904    return value;
1905 < }
1905 > } // end muon valueLookup
1906  
1907  
1908 + //!electron valueLookup
1909   double
1910 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1910 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1911  
1912    double value = 0.0;
1913    if(variable == "energy") value = object->energy;
# Line 915 | Line 2067 | OSUAnalysis::valueLookup (const BNelectr
2067    else if(variable == "eidHyperTight4MC") value = object->eidHyperTight4MC;
2068    else if(variable == "passConvVeto") value = object->passConvVeto;
2069  
2070 +  //user-defined variables
2071 +  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2072 +  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2073 +  else if(variable == "detIso") value = (object->trackIso) / object->pt;
2074 +  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2075 +  else if(variable == "metMT") {
2076 +    if (const BNmet *met = chosenMET ())
2077 +      {
2078 +        double dPhi = deltaPhi (object->phi, met->phi);
2079 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2080 +      }
2081 +    else
2082 +      value = -999;
2083 +  }
2084  
2085 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2085 >  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
2086 >    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
2087 >    else value = -999;
2088 >  }
2089 >  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
2090 >    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
2091 >    else value = -999;
2092 >  }
2093 >
2094 >  else if(variable == "correctedD0VertexInEBPlus"){
2095 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
2096 >    else value = -999;
2097 >  }
2098 >  else if(variable == "correctedD0VertexOutEBPlus"){
2099 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
2100 >    else value = -999;
2101 >  }
2102 >  else if(variable == "correctedD0VertexEEPlus"){
2103 >    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
2104 >    else value = -999;
2105 >  }
2106 >
2107 >  else if(variable == "correctedD0BeamspotInEBPlus"){
2108 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
2109 >    else value = -999;
2110 >  }
2111 >  else if(variable == "correctedD0BeamspotOutEBPlus"){
2112 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
2113 >    else value = -999;
2114 >  }
2115 >  else if(variable == "correctedD0BeamspotEEPlus"){
2116 >    if(object->isEE && object->eta > 0) value = object->correctedD0;
2117 >    else value = -999;
2118 >  }
2119 >
2120 >  else if(variable == "correctedD0VertexInEBMinus"){
2121 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
2122 >    else value = -999;
2123 >  }
2124 >  else if(variable == "correctedD0VertexOutEBMinus"){
2125 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
2126 >    else value = -999;
2127 >  }
2128 >  else if(variable == "correctedD0VertexEEMinus"){
2129 >    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
2130 >    else value = -999;
2131 >  }
2132 >
2133 >  else if(variable == "correctedD0BeamspotInEBMinus"){
2134 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
2135 >    else value = -999;
2136 >  }
2137 >  else if(variable == "correctedD0BeamspotOutEBMinus"){
2138 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
2139 >    else value = -999;
2140 >  }
2141 >  else if(variable == "correctedD0BeamspotEEMinus"){
2142 >    if(object->isEE && object->eta < 0) value = object->correctedD0;
2143 >    else value = -999;
2144 >  }
2145 >
2146 >  else if(variable == "tightID"){
2147 >    if (object->isEB)
2148 >      {
2149 >        value = fabs(object->delEtaIn) < 0.004 \
2150 >          && fabs (object->delPhiIn) < 0.03 \
2151 >          && object->scSigmaIEtaIEta < 0.01 \
2152 >          && object->hadOverEm < 0.12 \
2153 >          && fabs (object->correctedD0Vertex) < 0.02 \
2154 >          && fabs (object->correctedDZ) < 0.1 \
2155 >          && object->absInvEMinusInvPin < 0.05 \
2156 >          && object->passConvVeto;
2157 >      }
2158 >    else
2159 >      {
2160 >        value = fabs(object->delEtaIn) < 0.005 \
2161 >          && fabs (object->delPhiIn) < 0.02 \
2162 >          && object->scSigmaIEtaIEta < 0.03 \
2163 >          && object->hadOverEm < 0.10 \
2164 >          && fabs (object->correctedD0Vertex) < 0.02 \
2165 >          && fabs (object->correctedDZ) < 0.1 \
2166 >          && object->absInvEMinusInvPin < 0.05 \
2167 >          && object->passConvVeto;
2168 >      }
2169 >  }
2170 >
2171 >  else if(variable == "looseID"){
2172 >    value = object->pt > 10
2173 >      && object->mvaNonTrigV0 > 0;
2174 >      }
2175 >  else if(variable == "correctedD0VertexInEBPositiveCharge"){
2176 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2177 >    else value = -999;
2178 >  }
2179 >  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
2180 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2181 >    else value = -999;
2182 >  }
2183 >  else if(variable == "correctedD0VertexEEPositiveCharge"){
2184 >    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
2185 >    else value = -999;
2186 >  }
2187 >
2188 >  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
2189 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
2190 >    else value = -999;
2191 >  }
2192 >  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
2193 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
2194 >    else value = -999;
2195 >  }
2196 >  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
2197 >    if(object->isEE && object->charge > 0) value = object->correctedD0;
2198 >    else value = -999;
2199 >  }
2200 >
2201 >  else if(variable == "correctedD0VertexInEBNegativeCharge"){
2202 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2203 >    else value = -999;
2204 >  }
2205 >  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
2206 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
2207 >    else value = -999;
2208 >  }
2209 >  else if(variable == "correctedD0VertexEENegativeCharge"){
2210 >    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
2211 >    else value = -999;
2212 >  }
2213 >
2214 >  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
2215 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
2216 >    else value = -999;
2217 >  }
2218 >  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
2219 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
2220 >    else value = -999;
2221 >  }
2222 >  else if(variable == "correctedD0BeamspotEENegativeCharge"){
2223 >    if(object->isEE && object->charge < 0) value = object->correctedD0;
2224 >    else value = -999;
2225 >  }
2226 >
2227 >
2228 >  else if(variable == "tightIDdisplaced"){
2229 >    if (object->isEB)
2230 >      {
2231 >        value = fabs(object->delEtaIn) < 0.004 \
2232 >          && fabs (object->delPhiIn) < 0.03 \
2233 >          && object->scSigmaIEtaIEta < 0.01 \
2234 >          && object->hadOverEm < 0.12 \
2235 >          && object->absInvEMinusInvPin < 0.05;
2236 >      }
2237 >    else
2238 >      {
2239 >        value = fabs (object->delEtaIn) < 0.005 \
2240 >          && fabs (object->delPhiIn) < 0.02 \
2241 >          && object->scSigmaIEtaIEta < 0.03 \
2242 >          && object->hadOverEm < 0.10 \
2243 >          && object->absInvEMinusInvPin < 0.05;
2244 >      }
2245 >  }
2246 >
2247 >
2248 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2249 >
2250 >  else if(variable == "genMatchedPdgId"){
2251 >    int index = getGenMatchedParticleIndex(object);
2252 >    if(index == -1) value = 0;
2253 >    else value = mcparticles->at(index).id;
2254 >  }
2255 >
2256 >
2257 >  else if(variable == "genMatchedId"){
2258 >    int index = getGenMatchedParticleIndex(object);
2259 >    if(index == -1) value = 0;
2260 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2261 >  }
2262 >  else if(variable == "genMatchedMotherId"){
2263 >    int index = getGenMatchedParticleIndex(object);
2264 >    if(index == -1) value = 0;
2265 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2266 >  }
2267 >  else if(variable == "genMatchedMotherIdReverse"){
2268 >    int index = getGenMatchedParticleIndex(object);
2269 >    if(index == -1) value = 24;
2270 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2271 >  }
2272 >  else if(variable == "genMatchedGrandmotherId"){
2273 >    int index = getGenMatchedParticleIndex(object);
2274 >    if(index == -1) value = 0;
2275 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2276 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2277 >      if(motherIndex == -1) value = 0;
2278 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2279 >    }
2280 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2281 >  }
2282 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2283 >    int index = getGenMatchedParticleIndex(object);
2284 >    if(index == -1) value = 24;
2285 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2286 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2287 >      if(motherIndex == -1) value = 24;
2288 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2289 >    }
2290 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2291 >  }
2292 >  else if(variable == "pfElectronsFromVertex"){
2293 >    double d0Error, dzError;
2294 >
2295 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2296 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2297 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2298 >      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2299 >      || fabs (object->correctedDZ / dzError) > 99.0;
2300 >    value = !value;
2301 >  }
2302 >
2303 >
2304 >
2305 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2306  
2307    value = applyFunction(function, value);
2308  
2309    return value;
2310 < }
2310 > } // end electron valueLookup
2311  
2312  
2313 + //!event valueLookup
2314   double
2315 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2315 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2316  
2317    double value = 0.0;
2318  
# Line 993 | Line 2380 | OSUAnalysis::valueLookup (const BNevent*
2380    else if(variable == "id1") value = object->id1;
2381    else if(variable == "id2") value = object->id2;
2382    else if(variable == "evt") value = object->evt;
2383 <
2384 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2383 >  else if(variable == "puScaleFactor"){
2384 >    if(doPileupReweighting_ && datasetType_ != "data")
2385 >      value = puWeight_->at (events->at (0).numTruePV);
2386 >    else
2387 >      value = 1.0;
2388 >  }
2389 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2390 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2391 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2392 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2393 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2394  
2395    value = applyFunction(function, value);
2396  
2397    return value;
2398 < }
2398 > } // end event valueLookup
2399  
2400 +
2401 + //!tau valueLookup
2402   double
2403 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2403 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2404  
2405    double value = 0.0;
2406  
# Line 1046 | Line 2444 | OSUAnalysis::valueLookup (const BNtau* o
2444    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2445    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2446  
2447 +  else if (variable == "looseHadronicID") {
2448 +    value = object->pt > 10
2449 +      && object->eta < 2.3
2450 +      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2451 +      && object->HPSdecayModeFinding > 0
2452 +      && object->HPSagainstElectronLoose > 0
2453 +      && object->HPSagainstMuonTight > 0;
2454 +  }
2455 +
2456 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2457 +
2458 +  else if(variable == "genMatchedPdgId"){
2459 +    int index = getGenMatchedParticleIndex(object);
2460 +    if(index == -1) value = 0;
2461 +    else value = mcparticles->at(index).id;
2462 +  }
2463 +
2464 +  else if(variable == "genMatchedId"){
2465 +    int index = getGenMatchedParticleIndex(object);
2466 +    if(index == -1) value = 0;
2467 +    else value = getPdgIdBinValue(mcparticles->at(index).id);
2468 +  }
2469 +  else if(variable == "genMatchedMotherId"){
2470 +    int index = getGenMatchedParticleIndex(object);
2471 +    if(index == -1) value = 0;
2472 +    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2473 +  }
2474 +  else if(variable == "genMatchedMotherIdReverse"){
2475 +    int index = getGenMatchedParticleIndex(object);
2476 +    if(index == -1) value = 24;
2477 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2478 +  }
2479 +  else if(variable == "genMatchedGrandmotherId"){
2480 +    int index = getGenMatchedParticleIndex(object);
2481 +    if(index == -1) value = 0;
2482 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2483 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2484 +      if(motherIndex == -1) value = 0;
2485 +      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2486 +    }
2487 +    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2488 +  }
2489 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2490 +    int index = getGenMatchedParticleIndex(object);
2491 +    if(index == -1) value = 24;
2492 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2493 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2494 +      if(motherIndex == -1) value = 24;
2495 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2496 +    }
2497 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2498 +  }
2499  
2500 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2500 >
2501 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2502  
2503    value = applyFunction(function, value);
2504  
2505    return value;
2506 < }
2506 > } // end tau valueLookup
2507  
2508 +
2509 + //!met valueLookup
2510   double
2511 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2511 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2512  
2513    double value = 0.0;
2514  
# Line 1119 | Line 2572 | OSUAnalysis::valueLookup (const BNmet* o
2572    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2573    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2574  
2575 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2575 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2576  
2577    value = applyFunction(function, value);
2578  
2579    return value;
2580 < }
2580 > } // end met valueLookup
2581 >
2582  
2583 + //!track valueLookup
2584   double
2585 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2585 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2586  
2587    double value = 0.0;
2588 +  double pMag = sqrt(object->pt * object->pt +
2589 +                     object->pz * object->pz);
2590  
2591    if(variable == "pt") value = object->pt;
2592    else if(variable == "px") value = object->px;
# Line 1149 | Line 2606 | OSUAnalysis::valueLookup (const BNtrack*
2606    else if(variable == "numValidHits") value = object->numValidHits;
2607    else if(variable == "isHighPurity") value = object->isHighPurity;
2608  
2609 +  //additional BNs info for disappTrks
2610 +  else if(variable == "caloEMDeltaRp3")     value = object->caloEMDeltaRp3;
2611 +  else if(variable == "caloHadDeltaRp3")    value = object->caloHadDeltaRp3;
2612 +  else if(variable == "caloEMDeltaRp4")     value = object->caloEMDeltaRp4;
2613 +  else if(variable == "caloHadDeltaRp4")    value = object->caloHadDeltaRp4;
2614 +  else if(variable == "caloEMDeltaRp5")     value = object->caloEMDeltaRp5;
2615 +  else if(variable == "caloHadDeltaRp5")    value = object->caloHadDeltaRp5;
2616 +  else if(variable == "nHitsMissingOuter")  value = object->nHitsMissingOuter;
2617 +  else if(variable == "nHitsMissingInner")  value = object->nHitsMissingInner;
2618 +  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2619 +  else if(variable == "depTrkRp3")          value = object->depTrkRp3;
2620 +  else if(variable == "depEcalRp3")         value = object->depEcalRp3;
2621 +  else if(variable == "depHcalRp3")         value = object->depHcalRp3;
2622 +  else if(variable == "depHoRp3")           value = object->depHoRp3;
2623 +  else if(variable == "nTracksRp3")         value = object->nTracksRp3;
2624 +  else if(variable == "trackerVetoPtRp3")   value = object->trackerVetoPtRp3;
2625 +  else if(variable == "emVetoEtRp3")        value = object->emVetoEtRp3;
2626 +  else if(variable == "hadVetoEtRp3")       value = object->hadVetoEtRp3;
2627 +  else if(variable == "hoVetoEtRp3")        value = object->hoVetoEtRp3;
2628 +  else if(variable == "depTrkRp5")          value = object->depTrkRp5;
2629 +  else if(variable == "depEcalRp5")         value = object->depEcalRp5;
2630 +  else if(variable == "depHcalRp5")         value = object->depHcalRp5;
2631 +  else if(variable == "depHoRp5")           value = object->depHoRp5;
2632 +  else if(variable == "nTracksRp5")         value = object->nTracksRp5;
2633 +  else if(variable == "trackerVetoPtRp5")   value = object->trackerVetoPtRp5;
2634 +  else if(variable == "emVetoEtRp5")        value = object->emVetoEtRp5;
2635 +  else if(variable == "hadVetoEtRp5")       value = object->hadVetoEtRp5;
2636 +  else if(variable == "hoVetoEtRp5")        value = object->hoVetoEtRp5;
2637 +
2638 +  //user defined variables
2639 +  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;
2640 +  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2641 +  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2642 +  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2643 +  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2644 +  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2645 +  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2646 +  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2647 +  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2648 +  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2649 +  else if(variable == "ptError")                    value = object->ptError;
2650 +  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2651 +  else if (variable == "d0wrtPV"){
2652 +    double vx = object->vx - chosenVertex ()->x,
2653 +      vy = object->vy - chosenVertex ()->y,
2654 +      px = object->px,
2655 +      py = object->py,
2656 +      pt = object->pt;
2657 +    value = (-vx * py + vy * px) / pt;
2658 +  }
2659 +  else if (variable == "dZwrtPV"){
2660 +    double vx = object->vx - chosenVertex ()->x,
2661 +      vy = object->vy - chosenVertex ()->y,
2662 +      vz = object->vz - chosenVertex ()->z,
2663 +      px = object->px,
2664 +      py = object->py,
2665 +      pz = object->pz,
2666 +      pt = object->pt;
2667 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2668 +  }
2669 +
2670 +
2671 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2672 +
2673 +  else if(variable == "genMatchedPdgId"){
2674 +    int index = getGenMatchedParticleIndex(object);
2675 +    if(index == -1) value = 0;
2676 +    else value = mcparticles->at(index).id;
2677 +  }
2678  
2679 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2679 >
2680 >  else if(variable == "genMatchedId"){
2681 >    int index = getGenMatchedParticleIndex(object);
2682 >    if(index == -1) value = 0;
2683 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2684 >  }
2685 >  else if(variable == "genMatchedMotherId"){
2686 >    int index = getGenMatchedParticleIndex(object);
2687 >    if(index == -1) value = 0;
2688 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2689 >  }
2690 >  else if(variable == "genMatchedMotherIdReverse"){
2691 >    int index = getGenMatchedParticleIndex(object);
2692 >    if(index == -1) value = 24;
2693 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2694 >  }
2695 >  else if(variable == "genMatchedGrandmotherId"){
2696 >    int index = getGenMatchedParticleIndex(object);
2697 >    if(index == -1) value = 0;
2698 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2699 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2700 >      if(motherIndex == -1) value = 0;
2701 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2702 >    }
2703 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2704 >  }
2705 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2706 >    int index = getGenMatchedParticleIndex(object);
2707 >    if(index == -1) value = 24;
2708 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2709 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2710 >      if(motherIndex == -1) value = 24;
2711 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2712 >    }
2713 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2714 >  }
2715 >
2716 >
2717 >
2718 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2719  
2720    value = applyFunction(function, value);
2721  
2722    return value;
2723 < }
2723 > } // end track valueLookup
2724 >
2725  
2726 + //!genjet valueLookup
2727   double
2728 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2728 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2729  
2730    double value = 0.0;
2731  
# Line 1178 | Line 2745 | OSUAnalysis::valueLookup (const BNgenjet
2745    else if(variable == "charge") value = object->charge;
2746  
2747  
2748 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2748 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2749  
2750    value = applyFunction(function, value);
2751  
2752    return value;
2753   }
2754  
2755 + //!mcparticle valueLookup
2756   double
2757 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2757 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2758  
2759    double value = 0.0;
2760  
# Line 1275 | Line 2843 | OSUAnalysis::valueLookup (const BNmcpart
2843    else if(variable == "grandMother11Status") value = object->grandMother11Status;
2844    else if(variable == "grandMother11Charge") value = object->grandMother11Charge;
2845  
2846 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2846 >  //user-defined variables
2847 >  else if (variable == "d0"){
2848 >    double vx = object->vx - chosenVertex ()->x,
2849 >      vy = object->vy - chosenVertex ()->y,
2850 >      px = object->px,
2851 >      py = object->py,
2852 >      pt = object->pt;
2853 >    value = (-vx * py + vy * px) / pt;
2854 >  }
2855 >  else if (variable == "dz"){
2856 >    double vx = object->vx - chosenVertex ()->x,
2857 >      vy = object->vy - chosenVertex ()->y,
2858 >      vz = object->vz - chosenVertex ()->z,
2859 >      px = object->px,
2860 >      py = object->py,
2861 >      pz = object->pz,
2862 >      pt = object->pt;
2863 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2864 >  }
2865 >  else if(variable == "v0"){
2866 >    value = sqrt(object->vx*object->vx + object->vy*object->vy);
2867 >  }
2868 >  else if(variable == "deltaV0"){
2869 >    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
2870 >  }
2871 >  else if (variable == "deltaVx"){
2872 >    value = object->vx - chosenVertex ()->x;
2873 >  }
2874 >  else if (variable == "deltaVy"){
2875 >    value = object->vy - chosenVertex ()->y;
2876 >  }
2877 >  else if (variable == "deltaVz"){
2878 >    value = object->vz - chosenVertex ()->z;
2879 >  }
2880 >
2881 >
2882 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2883  
2884    value = applyFunction(function, value);
2885  
2886    return value;
2887 < }
2887 > } // end mcparticle valueLookup
2888 >
2889  
2890 + //!primaryvertex valueLookup
2891   double
2892 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2892 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2893  
2894    double value = 0.0;
2895  
# Line 1302 | Line 2908 | OSUAnalysis::valueLookup (const BNprimar
2908    else if(variable == "isGood") value = object->isGood;
2909  
2910  
2911 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2911 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2912  
2913    value = applyFunction(function, value);
2914  
2915    return value;
2916   }
2917  
2918 + //!bxlumi valueLookup
2919   double
2920 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2920 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2921  
2922    double value = 0.0;
2923  
# Line 1319 | Line 2926 | OSUAnalysis::valueLookup (const BNbxlumi
2926    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2927  
2928  
2929 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2929 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2930  
2931    value = applyFunction(function, value);
2932  
2933    return value;
2934   }
2935  
2936 + //!photon valueLookup
2937   double
2938 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2938 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2939  
2940    double value = 0.0;
2941  
# Line 1402 | Line 3010 | OSUAnalysis::valueLookup (const BNphoton
3010    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
3011  
3012  
3013 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3013 >
3014 >
3015 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3016 >
3017 >  else if(variable == "genMatchedPdgId"){
3018 >    int index = getGenMatchedParticleIndex(object);
3019 >    if(index == -1) value = 0;
3020 >    else value = mcparticles->at(index).id;
3021 >  }
3022 >
3023 >
3024 >
3025 >  else if(variable == "genMatchedId"){
3026 >    int index = getGenMatchedParticleIndex(object);
3027 >    if(index == -1) value = 0;
3028 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
3029 >  }
3030 >  else if(variable == "genMatchedMotherId"){
3031 >    int index = getGenMatchedParticleIndex(object);
3032 >    if(index == -1) value = 0;
3033 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
3034 >  }
3035 >  else if(variable == "genMatchedMotherIdReverse"){
3036 >    int index = getGenMatchedParticleIndex(object);
3037 >    if(index == -1) value = 24;
3038 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
3039 >  }
3040 >  else if(variable == "genMatchedGrandmotherId"){
3041 >    int index = getGenMatchedParticleIndex(object);
3042 >    if(index == -1) value = 0;
3043 >    else if(fabs(mcparticles->at(index).motherId) == 15){
3044 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3045 >      if(motherIndex == -1) value = 0;
3046 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3047 >    }
3048 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3049 >  }
3050 >  else if(variable == "genMatchedGrandmotherIdReverse"){
3051 >    int index = getGenMatchedParticleIndex(object);
3052 >    if(index == -1) value = 24;
3053 >    else if(fabs(mcparticles->at(index).motherId) == 15){
3054 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3055 >      if(motherIndex == -1) value = 24;
3056 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3057 >    }
3058 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3059 >  }
3060 >
3061 >
3062 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3063  
3064    value = applyFunction(function, value);
3065  
3066    return value;
3067 < }
3067 > } // end photon valueLookup
3068 >
3069  
3070 + //!supercluster valueLookup
3071   double
3072 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
3072 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
3073  
3074    double value = 0.0;
3075  
# Line 1424 | Line 3083 | OSUAnalysis::valueLookup (const BNsuperc
3083    else if(variable == "theta") value = object->theta;
3084  
3085  
3086 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3087 +
3088 +  value = applyFunction(function, value);
3089 +
3090 +  return value;
3091 + }
3092 +
3093 + //!trigobj valueLookup
3094 + double
3095 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3096 +
3097 +  double value = 0.0;
3098 +
3099 +  if(variable == "pt") value = object->pt;
3100 +  else if(variable == "eta") value = object->eta;
3101 +  else if(variable == "phi") value = object->phi;
3102 +  else if(variable == "px") value = object->px;
3103 +  else if(variable == "py") value = object->py;
3104 +  else if(variable == "pz") value = object->pz;
3105 +  else if(variable == "et") value = object->et;
3106 +  else if(variable == "energy") value = object->energy;
3107 +  else if(variable == "etTotal") value = object->etTotal;
3108 +  else if(variable == "id") value = object->id;
3109 +  else if(variable == "charge") value = object->charge;
3110 +  else if(variable == "isIsolated") value = object->isIsolated;
3111 +  else if(variable == "isMip") value = object->isMip;
3112 +  else if(variable == "isForward") value = object->isForward;
3113 +  else if(variable == "isRPC") value = object->isRPC;
3114 +  else if(variable == "bx") value = object->bx;
3115 +  else if(variable == "filter") {
3116 +    if ((stringValue = object->filter) == "")
3117 +      stringValue = "none";  // stringValue should only be empty if value is filled
3118 +  }
3119 +
3120 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3121 +
3122 +  value = applyFunction(function, value);
3123 +
3124 +  return value;
3125 + }
3126 +
3127 + //!muon-muon pair valueLookup
3128 + double
3129 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3130 +
3131 +  double value = 0.0;
3132 +
3133 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3134 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3135 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3136 +  else if(variable == "invMass"){
3137 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3138 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3139 +    value = (fourVector1 + fourVector2).M();
3140 +  }
3141 +  else if(variable == "pt"){
3142 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3143 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3144 +    value = (fourVector1 + fourVector2).Pt();
3145 +  }
3146 +  else if(variable == "threeDAngle")
3147 +    {
3148 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3149 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3150 +      value = (threeVector1.Angle(threeVector2));
3151 +    }
3152 +  else if(variable == "alpha")
3153 +    {
3154 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3155 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3156 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3157 +      value = (pi-threeVector1.Angle(threeVector2));
3158 +    }
3159 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3160 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3161 +  else if(variable == "d0Sign"){
3162 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3163 +    if(d0Sign < 0) value = -0.5;
3164 +    else if (d0Sign > 0) value = 0.5;
3165 +    else value = -999;
3166 +  }
3167 +  else if(variable == "chargeProduct"){
3168 +    value = object1->charge*object2->charge;
3169 +  }
3170 +  else if(variable == "muon1CorrectedD0Vertex"){
3171 +    value = object1->correctedD0Vertex;
3172 +  }
3173 +  else if(variable == "muon2CorrectedD0Vertex"){
3174 +    value = object2->correctedD0Vertex;
3175 +  }
3176 +  else if(variable == "muon1timeAtIpInOut"){
3177 +    value = object1->timeAtIpInOut;
3178 +  }
3179 +  else if(variable == "muon2timeAtIpInOut"){
3180 +    value = object2->timeAtIpInOut;
3181 +  }
3182 +  else if(variable == "muon1correctedD0")
3183 +    {
3184 +      value = object1->correctedD0;
3185 +    }
3186 +  else if(variable == "muon2correctedD0")
3187 +    {
3188 +      value = object2->correctedD0;
3189 +    }
3190 +
3191 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3192 +
3193 +  value = applyFunction(function, value);
3194 +
3195 +  return value;
3196 + } // end muon-muon pair valueLookup
3197 +
3198 +
3199 + //!muon-photon pair valueLookup
3200 + double
3201 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3202 +
3203 +  double value = 0.0;
3204 +
3205 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3206 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3207 +  else if(variable == "photonEta") value = object2->eta;
3208 +  else if(variable == "muonEta") value = object1->eta;
3209 +  else if(variable == "photonPhi") value = object2->phi;
3210 +  else if(variable == "muonPhi") value = object1->phi;
3211 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3212 +  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3213 +  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3214 +  else if(variable == "invMass"){
3215 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3216 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3217 +    value = (fourVector1 + fourVector2).M();
3218 +  }
3219 +  else if(variable == "pt"){
3220 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3221 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3222 +    value = (fourVector1 + fourVector2).Pt();
3223 +  }
3224 +  else if(variable == "threeDAngle")
3225 +    {
3226 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3227 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3228 +      value = (threeVector1.Angle(threeVector2));
3229 +    }
3230 +  else if(variable == "alpha")
3231 +    {
3232 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3233 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3234 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3235 +      value = (pi-threeVector1.Angle(threeVector2));
3236 +    }
3237 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3238 +
3239 +  value = applyFunction(function, value);
3240 +
3241 +  return value;
3242 + }
3243 +
3244 + //!electron-photon pair valueLookup
3245 + double
3246 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3247 +
3248 +  double value = 0.0;
3249 +
3250 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3251 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3252 +  else if(variable == "photonEta") value = object2->eta;
3253 +  else if(variable == "electronEta") value = object1->eta;
3254 +  else if(variable == "photonPhi") value = object2->phi;
3255 +  else if(variable == "electronPhi") value = object1->phi;
3256 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3257 +  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3258 +  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3259 +  else if(variable == "invMass"){
3260 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3261 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3262 +    value = (fourVector1 + fourVector2).M();
3263 +  }
3264 +  else if(variable == "pt"){
3265 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3266 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3267 +    value = (fourVector1 + fourVector2).Pt();
3268 +  }
3269 +  else if(variable == "threeDAngle")
3270 +    {
3271 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3272 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3273 +      value = (threeVector1.Angle(threeVector2));
3274 +    }
3275 +  else if(variable == "alpha")
3276 +    {
3277 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3278 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3279 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3280 +      value = (pi-threeVector1.Angle(threeVector2));
3281 +    }
3282 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3283 +
3284 +  value = applyFunction(function, value);
3285 +
3286 +  return value;
3287 + }
3288 +
3289 + //!electron-electron pair valueLookup
3290 + double
3291 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3292 +
3293 +  double value = 0.0;
3294 +
3295 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3296 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3297 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3298 +  else if(variable == "invMass"){
3299 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3300 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3301 +    value = (fourVector1 + fourVector2).M();
3302 +  }
3303 +  else if(variable == "pt"){
3304 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3305 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3306 +    value = (fourVector1 + fourVector2).Pt();
3307 +  }
3308 +  else if(variable == "threeDAngle")
3309 +    {
3310 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3311 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3312 +      value = (threeVector1.Angle(threeVector2));
3313 +    }
3314 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3315 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3316 +  else if(variable == "d0Sign"){
3317 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3318 +    if(d0Sign < 0) value = -0.5;
3319 +    else if (d0Sign > 0) value = 0.5;
3320 +    else value = -999;
3321 +  }
3322 +  else if(variable == "chargeProduct"){
3323 +    value = object1->charge*object2->charge;
3324 +  }
3325 +  else if(variable == "electron1CorrectedD0Vertex"){
3326 +    value = object1->correctedD0Vertex;
3327 +  }
3328 +  else if(variable == "electron2CorrectedD0Vertex"){
3329 +    value = object2->correctedD0Vertex;
3330 +  }
3331 +  else if(variable == "electron1CorrectedD0"){
3332 +    value = object1->correctedD0;
3333 +  }
3334 +  else if(variable == "electron2CorrectedD0"){
3335 +    value = object2->correctedD0;
3336 +  }
3337 +
3338 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3339 +
3340 +  value = applyFunction(function, value);
3341 +
3342 +  return value;
3343 + }
3344 +
3345 + //!electron-muon pair valueLookup
3346 + double
3347 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3348 +
3349 +  double value = 0.0;
3350 +
3351 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3352 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3353 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3354 +  else if(variable == "invMass"){
3355 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3356 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3357 +    value = (fourVector1 + fourVector2).M();
3358 +  }
3359 +  else if(variable == "pt"){
3360 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3361 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3362 +    value = (fourVector1 + fourVector2).Pt();
3363 +  }
3364 +  else if(variable == "threeDAngle")
3365 +    {
3366 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3367 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3368 +      value = (threeVector1.Angle(threeVector2));
3369 +    }
3370 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3371 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3372 +  else if(variable == "d0Sign"){
3373 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3374 +    if(d0Sign < 0) value = -0.5;
3375 +    else if (d0Sign > 0) value = 0.5;
3376 +    else value = -999;
3377 +  }
3378 +  else if(variable == "chargeProduct"){
3379 +    value = object1->charge*object2->charge;
3380 +  }
3381 +  else if(variable == "electronCorrectedD0Vertex"){
3382 +    value = object1->correctedD0Vertex;
3383 +  }
3384 +  else if(variable == "muonCorrectedD0Vertex"){
3385 +    value = object2->correctedD0Vertex;
3386 +  }
3387 +  else if(variable == "electronCorrectedD0"){
3388 +    value = object1->correctedD0;
3389 +  }
3390 +  else if(variable == "muonCorrectedD0"){
3391 +    value = object2->correctedD0;
3392 +  }
3393 +  else if(variable == "electronDetIso"){
3394 +    value = (object1->trackIso) / object1->pt;
3395 +  }
3396 +  else if(variable == "muonDetIso"){
3397 +    value = (object2->trackIsoDR03) / object2->pt;
3398 +  }
3399 +  else if(variable == "electronRelPFrhoIso"){
3400 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3401 +  }
3402 +  else if(variable == "muonRelPFdBetaIso"){
3403 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3404 +  }
3405 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3406 +  value = applyFunction(function, value);
3407 +
3408 +  return value;
3409 + } // end electron-muon pair valueLookup
3410 +
3411 +
3412 + //!electron-jet pair valueLookup
3413 + double
3414 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3415 +
3416 +  double value = 0.0;
3417 +
3418 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3419 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3420 +  else if(variable == "jetEta") value = object2->eta;
3421 +  else if(variable == "jetPhi") value = object2->phi;
3422 +  else if(variable == "electronEta") value = object1->eta;
3423 +  else if(variable == "electronPhi") value = object1->phi;
3424 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3425 +  else if(variable == "invMass"){
3426 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3427 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3428 +    value = (fourVector1 + fourVector2).M();
3429 +  }
3430 +  else if(variable == "pt"){
3431 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3432 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3433 +    value = (fourVector1 + fourVector2).Pt();
3434 +  }
3435 +  else if(variable == "threeDAngle")
3436 +    {
3437 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3438 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3439 +      value = (threeVector1.Angle(threeVector2));
3440 +    }
3441 +  else if(variable == "chargeProduct"){
3442 +    value = object1->charge*object2->charge;
3443 +  }
3444 +
3445 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3446 +  value = applyFunction(function, value);
3447 +
3448 +  return value;
3449 + }
3450 +
3451 + //!photon-jet pair valueLookup
3452 + double
3453 + OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3454 +
3455 +  double value = 0.0;
3456 +
3457 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3458 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3459 +  else if(variable == "jetEta") value = object2->eta;
3460 +  else if(variable == "jetPhi") value = object2->phi;
3461 +  else if(variable == "photonEta") value = object1->eta;
3462 +  else if(variable == "photonPhi") value = object1->phi;
3463 +  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3464 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3465 +  else if(variable == "invMass"){
3466 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3467 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3468 +    value = (fourVector1 + fourVector2).M();
3469 +  }
3470 +  else if(variable == "pt"){
3471 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3472 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3473 +    value = (fourVector1 + fourVector2).Pt();
3474 +  }
3475 +  else if(variable == "threeDAngle")
3476 +    {
3477 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3478 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3479 +      value = (threeVector1.Angle(threeVector2));
3480 +    }
3481 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3482 +  value = applyFunction(function, value);
3483 +
3484 +  return value;
3485 + }
3486 +
3487 + // met-jet pair valueLookup
3488 + double
3489 + OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3490 +
3491 +  double value = 0.0;
3492 +
3493 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3494 +
3495 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3496 +  value = applyFunction(function, value);
3497 +
3498 +  return value;
3499 +
3500 + }  
3501 +
3502 +
3503 +
3504 + //!muon-jet pair valueLookup
3505 + double
3506 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3507 +
3508 +  double value = 0.0;
3509 +
3510 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3511 +  else if(variable == "jetEta") value = object2->eta;
3512 +  else if(variable == "jetPhi") value = object2->phi;
3513 +  else if(variable == "muonEta") value = object1->eta;
3514 +  else if(variable == "muonPhi") value = object1->phi;
3515 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3516 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3517 +  else if(variable == "invMass"){
3518 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3519 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3520 +    value = (fourVector1 + fourVector2).M();
3521 +  }
3522 +  else if(variable == "pt"){
3523 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3524 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3525 +    value = (fourVector1 + fourVector2).Pt();
3526 +  }
3527 +  else if(variable == "threeDAngle")
3528 +    {
3529 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3530 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3531 +      value = (threeVector1.Angle(threeVector2));
3532 +    }
3533 +  else if(variable == "chargeProduct"){
3534 +    value = object1->charge*object2->charge;
3535 +  }
3536 +
3537 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3538 +  value = applyFunction(function, value);
3539 +
3540 +  return value;
3541 + }
3542 + //!jet-jet pair valueLookup
3543 + double
3544 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3545 +
3546 +  double value = 0.0;
3547 +
3548 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3549 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3550 +  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3551 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3552 +  else if(variable == "invMass"){
3553 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3554 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3555 +    value = (fourVector1 + fourVector2).M();
3556 +  }
3557 +  else if(variable == "pt"){
3558 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3559 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3560 +    value = (fourVector1 + fourVector2).Pt();
3561 +  }
3562 +  else if(variable == "threeDAngle")
3563 +    {
3564 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3565 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3566 +      value = (threeVector1.Angle(threeVector2));
3567 +    }
3568 +  else if(variable == "chargeProduct"){
3569 +    value = object1->charge*object2->charge;
3570 +  }
3571 +
3572 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3573 +  value = applyFunction(function, value);
3574 +
3575 +  return value;
3576 + }
3577 +
3578 + //!electron-track pair valueLookup
3579 + double
3580 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3581 +  double electronMass = 0.000511;
3582 +  double value = 0.0;
3583 +  TLorentzVector fourVector1(0, 0, 0, 0);
3584 +  TLorentzVector fourVector2(0, 0, 0, 0);
3585 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3586 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3587 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3588 +  else if(variable == "invMass"){
3589 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3590 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3591 +
3592 +    value = (fourVector1 + fourVector2).M();
3593 +  }
3594 +  else if(variable == "chargeProduct"){
3595 +    value = object1->charge*object2->charge;
3596 +  }
3597 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3598 +  value = applyFunction(function, value);
3599 +  return value;
3600 +
3601 + }
3602 +
3603 +
3604 + //!muon-track pair valueLookup
3605 + double
3606 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3607 +  double pionMass = 0.140;
3608 +  double muonMass = 0.106;
3609 +  double value = 0.0;
3610 +  TLorentzVector fourVector1(0, 0, 0, 0);
3611 +  TLorentzVector fourVector2(0, 0, 0, 0);
3612 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3613 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3614 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3615 +  else if(variable == "invMass"){
3616 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3617 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3618 +
3619 +    value = (fourVector1 + fourVector2).M();
3620 +  }
3621 +  else if(variable == "chargeProduct"){
3622 +    value = object1->charge*object2->charge;
3623 +  }
3624 +
3625 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3626 +  value = applyFunction(function, value);
3627 +  return value;
3628 + }
3629 +
3630 + //!tau-tau pair valueLookup
3631 + double
3632 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3633 +  double value = 0.0;
3634 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3635 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3636 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3637 +  else if(variable == "invMass"){
3638 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3639 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3640 +    value = (fourVector1 + fourVector2).M();
3641 +  }
3642 +
3643 +  else if(variable == "chargeProduct"){
3644 +    value = object1->charge*object2->charge;
3645 +  }
3646 +
3647    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3648 +  value = applyFunction(function, value);
3649 +  return value;
3650 + }
3651 +
3652 + //!muon-tau pair valueLookup
3653 + double
3654 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3655 +  double value = 0.0;
3656 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3657 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3658 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3659 +  else if(variable == "invMass"){
3660 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3661 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3662 +    value = (fourVector1 + fourVector2).M();
3663 +  }
3664 +
3665 +  else if(variable == "chargeProduct"){
3666 +    value = object1->charge*object2->charge;
3667 +  }
3668 +
3669 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3670 +  value = applyFunction(function, value);
3671 +  return value;
3672 + }
3673 +
3674 + //!tau-track pair valueLookup
3675 + double
3676 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3677 +  double value = 0.0;
3678 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3679 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3680 +  else if(variable == "chargeProduct"){
3681 +    value = object1->charge*object2->charge;
3682 +  }
3683 +
3684 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3685 +  value = applyFunction(function, value);
3686 +  return value;
3687 + }
3688 +
3689 +
3690 + //!track-event pair valueLookup
3691 + double
3692 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3693 +
3694 +  double value = 0.0;
3695 +  double pMag = sqrt(object1->pt * object1->pt +
3696 +                     object1->pz * object1->pz);
3697 +
3698 +  if      (variable == "numPV")                      value = object2->numPV;
3699 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3700 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3701 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3702 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3703 +
3704 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3705  
3706    value = applyFunction(function, value);
3707  
3708    return value;
3709 +
3710   }
3711  
3712 + //!electron-trigobj pair valueLookup
3713 + double
3714 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3715 +
3716 +  double value = 0.0;
3717 +
3718 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3719 +  else if (variable == "match"){
3720 +    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3721 +      stringValue = object2->filter;
3722 +    else
3723 +      stringValue = "none";
3724 +  }
3725 +
3726 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3727 +
3728 +  value = applyFunction(function, value);
3729 +
3730 +  return value;
3731 +
3732 + }
3733 +
3734 + //!muon-trigobj pair valueLookup
3735 + double
3736 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3737 +
3738 +  double value = 0.0;
3739 +
3740 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3741 +
3742 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3743 +
3744 +  value = applyFunction(function, value);
3745 +
3746 +  return value;
3747 +
3748 + }
3749 +
3750 + //!stop valueLookup
3751 + double
3752 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3753 +
3754 +
3755 +  double value = 0.0;
3756 +
3757 +  if(variable == "ctau") value = object->ctau;
3758 +
3759 +  else if (variable == "d0"){
3760 +    double vx = object->vx - chosenVertex ()->x,
3761 +      vy = object->vy - chosenVertex ()->y,
3762 +      px = object->px,
3763 +      py = object->py,
3764 +      pt = object->pt;
3765 +    value = (-vx * py + vy * px) / pt;
3766 +  }
3767 +
3768 +  else if (variable == "dz"){
3769 +    double vx = object->vx - chosenVertex ()->x,
3770 +      vy = object->vy - chosenVertex ()->y,
3771 +      vz = object->vz - chosenVertex ()->z,
3772 +      px = object->px,
3773 +      py = object->py,
3774 +      pz = object->pz,
3775 +      pt = object->pt;
3776 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3777 +  }
3778 +
3779 +  else if (variable == "minD0"){
3780 +    double minD0=999;
3781 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3782 +      double vx = object->vx - vertex->x,
3783 +        vy = object->vy - vertex->y,
3784 +        px = object->px,
3785 +        py = object->py,
3786 +        pt = object->pt;
3787 +      value = (-vx * py + vy * px) / pt;
3788 +      if(abs(value) < abs(minD0)) minD0 = value;
3789 +    }
3790 +    value = minD0;
3791 +  }
3792 +  else if (variable == "minDz"){
3793 +    double minDz=999;
3794 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3795 +      double vx = object->vx - vertex->x,
3796 +        vy = object->vy - vertex->y,
3797 +        vz = object->vz - vertex->z,
3798 +        px = object->px,
3799 +        py = object->py,
3800 +        pz = object->pz,
3801 +        pt = object->pt;
3802 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3803 +      if(abs(value) < abs(minDz)) minDz = value;
3804 +    }
3805 +    value = minDz;
3806 +  }
3807 +  else if(variable == "distToVertex"){
3808 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3809 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3810 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3811 +  }
3812 +  else if (variable == "minDistToVertex"){
3813 +    double minDistToVertex=999;
3814 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3815 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3816 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3817 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3818 +
3819 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3820 +    }
3821 +    value = minDistToVertex;
3822 +  }
3823 +  else if (variable == "distToVertexDifference"){
3824 +    double minDistToVertex=999;
3825 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3826 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3827 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3828 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3829 +
3830 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3831 +    }
3832 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3833 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3834 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3835 +
3836 +    value = distToChosenVertex - minDistToVertex;
3837 +  }
3838 +
3839 +  else if (variable == "closestVertexRank"){
3840 +    double minDistToVertex=999;
3841 +    int vertex_rank = 0;
3842 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3843 +      vertex_rank++;
3844 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3845 +                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
3846 +                      (object->vz-vertex->z)*(object->vz-vertex->z));
3847 +
3848 +      if(abs(dist) < abs(minDistToVertex)){
3849 +        value = vertex_rank;
3850 +        minDistToVertex = dist;
3851 +      }
3852 +    }
3853 +  }
3854 +
3855 +
3856 +
3857 +
3858 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3859 +
3860 +  value = applyFunction(function, value);
3861 +
3862 +  return value;
3863 +
3864 + } // end stop valueLookup
3865 +
3866 +
3867 +
3868 +
3869 +
3870 + // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3871 + // Return true iff no other tracks are found in this cone.
3872 + int
3873 + OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
3874 +  for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
3875 +    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
3876 +    double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
3877 +    if(deltaRtrk < 0.5) return 0;
3878 +  }
3879 +  return 1;
3880 +
3881 + }
3882 +
3883 +
3884 + double
3885 + OSUAnalysis::getTrkPtRes (const BNtrack* track1){
3886 +
3887 +  double ptTrue = getTrkPtTrue(track1, mcparticles.product());
3888 +  double PtRes = (track1->pt - ptTrue) / ptTrue;
3889 +
3890 +  return PtRes;
3891 +
3892 + }
3893 +
3894 +
3895 + double
3896 + OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
3897 +  double value = -99;
3898 +  double genDeltaRLowest = 999;
3899 +
3900 +  for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
3901 +    double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
3902 +    if (genDeltaRtemp < genDeltaRLowest) {
3903 +      genDeltaRLowest = genDeltaRtemp;
3904 +      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
3905 +        double ptTrue = genPart->pt;
3906 +        value = ptTrue;
3907 +      }
3908 +    }
3909 +  }
3910 +
3911 +  return value;
3912 +
3913 + }
3914 +
3915 + double
3916 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3917 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3918 +  if (!useTrackCaloRhoCorr_) return -99;
3919 +  // if (!rhokt6CaloJetsHandle_) {
3920 +  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3921 +  //   return -99;
3922 +  // }
3923 +  double radDeltaRCone = 0.5;
3924 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3925 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3926 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3927 +  return caloTotRhoCorrCalo;
3928 +
3929 + }
3930 +
3931 +
3932 +
3933 +
3934 + //creates a map of the dead Ecal channels in the barrel and endcap
3935 + //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
3936 + //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
3937 + void
3938 + OSUAnalysis::WriteDeadEcal (){
3939 +  double etaEcal, phiEcal;
3940 +  ifstream DeadEcalFile(deadEcalFile_);
3941 +  if(!DeadEcalFile) {
3942 +    cout << "Error: DeadEcalFile has not been found." << endl;
3943 +    return;
3944 +  }
3945 +  if(DeadEcalVec.size()!= 0){
3946 +    cout << "Error: DeadEcalVec has a nonzero size" << endl;
3947 +    return;
3948 +  }
3949 +  while(!DeadEcalFile.eof())
3950 +    {
3951 +      DeadEcalFile >> etaEcal >> phiEcal;
3952 +      DeadEcal newChan;
3953 +      newChan.etaEcal = etaEcal;
3954 +      newChan.phiEcal = phiEcal;
3955 +      DeadEcalVec.push_back(newChan);
3956 +    }
3957 +  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
3958 + }
3959 +
3960 + //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
3961 + int
3962 + OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
3963 +  double deltaRLowest = 999;
3964 +  int value = 0;
3965 +  if (DeadEcalVec.size() == 0) WriteDeadEcal();
3966 +  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3967 +    double eta = ecal->etaEcal;
3968 +    double phi = ecal->phiEcal;
3969 +    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
3970 +    if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3971 +  }
3972 +  if (deltaRLowest<0.05) {value = 1;}
3973 +  else {value = 0;}
3974 +  return value;
3975 + }
3976 +
3977 + // Returns the smallest DeltaR between the object and any generated true particle in the event.
3978 + template <class InputObject>
3979 + double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3980 +  double genDeltaRLowest = 999.;
3981 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3982 +    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
3983 +    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
3984 +  }
3985 +  return genDeltaRLowest;
3986 + }
3987  
3988   double
3989   OSUAnalysis::applyFunction(string function, double value){
3990  
3991 <  if(function == "abs") value = abs(value);
3991 >  if(function == "abs") value = fabs(value);
3992 >  else if(function == "fabs") value = fabs(value);
3993 >  else if(function == "log10") value = log10(value);
3994 >  else if(function == "log") value = log10(value);
3995  
3996 +  else if(function == "") value = value;
3997 +  else{cout << "WARNING: invalid function '" << function << "'\n";}
3998  
3999    return value;
4000  
# Line 1446 | Line 4004 | OSUAnalysis::applyFunction(string functi
4004   template <class InputCollection>
4005   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
4006  
4007 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
4008 +    string obj1, obj2;
4009 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
4010 +    if (inputType==obj1 ||
4011 +        inputType==obj2) {
4012 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
4013 +      // and the inputType is a member of the pair.
4014 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
4015 +      // For example, if currentCut.inputCollection==electron-muon pairs,
4016 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
4017 +      return;
4018 +    }
4019 +  }
4020  
4021    for (uint object = 0; object != inputCollection->size(); object++){
4022  
4023 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
4023 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4024 >    bool plotDecision = true;
4025  
4026      if(currentCut.inputCollection == inputType){
4027  
4028 <      double value = valueLookup(&inputCollection->at(object), currentCut.variable, currentCut.function);
4028 >      vector<bool> subcutDecisions;
4029 >      for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4030 >        string stringValue = "";
4031 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4032 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4033 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4034  
4035 <      decision = evaluateComparison(value,currentCut.comparativeOperator,currentCut.cutValue);
4035 >      }
4036 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4037 >      else{
4038 >        bool tempDecision = true;
4039 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4040 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4041 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4042 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4043 >            tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4044 >        }
4045 >        cutDecision = tempDecision;
4046 >      }
4047 >      //invert the cut for plotting if this cut is a veto
4048 >      if(currentCut.isVeto) plotDecision = !cutDecision;
4049 >      else plotDecision = cutDecision;
4050      }
1460    individualFlags[inputType].at(currentCutIndex).push_back(decision);
4051  
4052 +    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4053  
4054 <    //set flags for objects that pass each cut AND all the previous cuts
4055 <    bool previousCumulativeFlag = true;
4054 >    //set flags for objects that pass this cut AND all the previous cuts
4055 >    bool previousCumulativeCutFlag = true;
4056 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4057 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4058 >      else{ previousCumulativeCutFlag = false; break;}
4059 >    }
4060 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4061 >    bool previousCumulativePlotFlag = true;
4062      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4063 <      if(previousCumulativeFlag && individualFlags[inputType].at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4064 <      else{ previousCumulativeFlag = false; break;}
4063 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4064 >      else{ previousCumulativePlotFlag = false; break;}
4065      }
4066 <    cumulativeFlags[inputType].at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4066 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4067 >
4068 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4069  
4070    }
4071  
4072   }
4073  
4074  
4075 + template <class InputCollection1, class InputCollection2>
4076 + void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
4077 +                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, string inputType){
4078 +
4079 +
4080 +  bool sameObjects = false;
4081 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4082 +
4083 +  // Get the strings for the two objects that make up the pair.
4084 +  string obj1Type, obj2Type;
4085 +  getTwoObjs(inputType, obj1Type, obj2Type);
4086 +  bool isTwoTypesOfObject = true;
4087 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
4088 +
4089 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
4090 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4091 +  if (currentCut.inputCollection == inputType) {
4092 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4093 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4094 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4095 +    }
4096 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4097 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4098 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4099 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4100 +      }
4101 +    }
4102 +  }
4103 +
4104 +  int counter = 0;
4105 +
4106 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4107 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4108  
4109 +      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4110  
4111  
4112 < DEFINE_FWK_MODULE(OSUAnalysis);
4112 >      bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4113 >      bool plotDecision = true;
4114 >
4115 >      if(currentCut.inputCollection == inputType){
4116 >
4117 >        vector<bool> subcutDecisions;
4118 >        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4119 >          string stringValue = "";
4120 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4121 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4122 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4123 >        }
4124 >
4125 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4126 >        else{
4127 >          bool tempDecision = subcutDecisions.at(0);
4128 >          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
4129 >            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
4130 >              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
4131 >            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4132 >              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4133 >          }
4134 >          cutDecision = tempDecision;
4135 >        }
4136 >        //invert the cut for plotting if this cut is a veto
4137 >        if(currentCut.isVeto) plotDecision = !cutDecision;
4138 >        else plotDecision = cutDecision;
4139 >      }
4140 >      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4141 >      if (cutDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4142 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4143 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4144 >      }
4145 >      if (plotDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4146 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4147 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4148 >      }
4149 >
4150 >      //set flags for objects that pass this cut AND all the previous cuts
4151 >      bool previousCumulativeCutFlag = true;
4152 >      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4153 >        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4154 >        else{ previousCumulativeCutFlag = false; break;}
4155 >      }
4156 >      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4157 >
4158 >      bool previousCumulativePlotFlag = true;
4159 >      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4160 >        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4161 >        else{ previousCumulativePlotFlag = false; break;}
4162 >      }
4163 >      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4164 >      
4165 >      //apply flags for the components of the composite object as well
4166 >      bool currentCumulativeCutFlag = true;
4167 >      bool currentCumulativePlotFlag = true;
4168 >
4169 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4170 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4171 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4172 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4173 >
4174 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4175 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4176 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4177 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4178 >
4179 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));
4180 >
4181 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4182 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4183 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4184 >      }
4185 >
4186 >      if (currentCumulativePlotFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4187 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4188 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4189 >      }
4190 >
4191 >      counter++;
4192 >
4193 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4194 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4195 >
4196 > }
4197 >
4198 >
4199 > bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4200 >  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4201 >  // all cuts up to currentCutIndex
4202 >  bool previousCumulativeFlag = true;
4203 >  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4204 >    bool tempFlag = false;
4205 >    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4206 >    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4207 >
4208 >    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4209 >    else {
4210 >      previousCumulativeFlag = false; break;
4211 >    }
4212 >  }
4213 >  return previousCumulativeFlag;
4214 > }
4215 >
4216 >
4217 >
4218 >
4219 > template <class InputCollection>
4220 > void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4221 >  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4222 >
4223 >  if (BNTreeBranchVals_.count(parameters.name)==0) cout << "Error[assignTreeBranch]:  trying to assign value to " << parameters.name << " that does not have a branch set up.  Will likely seg fault." << endl;
4224 >  for (uint object = 0; object != inputCollection->size(); object++) {
4225 >
4226 >    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4227 >
4228 >    string inputVariable = parameters.inputVariable;
4229 >    string function = "";
4230 >    string stringValue = "";
4231 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4232 >    BNTreeBranchVals_.at(parameters.name).push_back(value);
4233 >
4234 >  }
4235 > }
4236 >
4237 >
4238 > template <class InputCollection>
4239 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4240 >
4241 >
4242 >  for (uint object = 0; object != inputCollection->size(); object++){
4243 >
4244 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4245 >
4246 >    string currentString = parameters.inputVariables.at(0);
4247 >    string inputVariable = "";
4248 >    string function = "";
4249 >    if(currentString.find("(")==string::npos){
4250 >      inputVariable = currentString;// variable to cut on
4251 >    }
4252 >    else{
4253 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4254 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4255 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4256 >    }
4257 >
4258 >    string stringValue = "";
4259 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4260 >    histo->Fill(value,scaleFactor);
4261 >
4262 >    if (printEventInfo_) {
4263 >      // Write information about event to screen, for testing purposes.
4264 >      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
4265 >    }
4266 >
4267 >  }
4268 > }
4269 >
4270 > template <class InputCollection1, class InputCollection2>
4271 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4272 >
4273 >  bool sameObjects = false;
4274 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4275 >
4276 >  int pairCounter = -1;
4277 >  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4278 >    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4279 >
4280 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4281 >
4282 >      pairCounter++;
4283 >      //only take objects which have passed all cuts and pairs which have passed all cuts
4284 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4285 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4286 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4287 >
4288 >      string currentString = parameters.inputVariables.at(0);
4289 >      string inputVariable = "";
4290 >      string function = "";
4291 >      if(currentString.find("(")==string::npos){
4292 >        inputVariable = currentString;// variable to cut on
4293 >      }
4294 >      else{
4295 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4296 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4297 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4298 >      }
4299 >
4300 >      string stringValue = "";
4301 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4302 >      histo->Fill(value,scaleFactor);
4303 >
4304 >    }
4305 >  }
4306 >
4307 > }
4308 >
4309 >
4310 > template <class InputCollection>
4311 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4312 >
4313 >  for (uint object = 0; object != inputCollection->size(); object++){
4314 >
4315 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4316 >
4317 >    string stringValue = "";
4318 >    string currentString = parameters.inputVariables.at(0);
4319 >    string inputVariable = "";
4320 >    string function = "";
4321 >    if(currentString.find("(")==string::npos){
4322 >      inputVariable = currentString;// variable to cut on
4323 >    }
4324 >    else{
4325 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4326 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4327 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4328 >    }
4329 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4330 >
4331 >    currentString = parameters.inputVariables.at(1);
4332 >    inputVariable = "";
4333 >    function = "";
4334 >    if(currentString.find("(")==string::npos){
4335 >      inputVariable = currentString;// variable to cut on
4336 >    }
4337 >    else{
4338 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4339 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4340 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4341 >    }
4342 >
4343 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4344 >
4345 >    histo->Fill(valueX,valueY,scaleFactor);
4346 >
4347 >  }
4348 >
4349 > }
4350 >
4351 > template <class InputCollection1, class InputCollection2>
4352 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4353 >
4354 >  bool sameObjects = false;
4355 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4356 >
4357 >  int pairCounter = -1;
4358 >  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4359 >    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4360 >
4361 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4362 >
4363 >      pairCounter++;
4364 >
4365 >      //only take objects which have passed all cuts and pairs which have passed all cuts
4366 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4367 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4368 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4369 >
4370 >      string stringValue = "";
4371 >      string currentString = parameters.inputVariables.at(0);
4372 >      string inputVariable = "";
4373 >      string function = "";
4374 >      if(currentString.find("(")==string::npos){
4375 >        inputVariable = currentString;// variable to cut on
4376 >      }
4377 >      else{
4378 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4379 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4380 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4381 >      }
4382 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4383 >
4384 >      currentString = parameters.inputVariables.at(1);
4385 >      inputVariable = "";
4386 >      function = "";
4387 >      if(currentString.find("(")==string::npos){
4388 >        inputVariable = currentString;// variable to cut on
4389 >      }
4390 >      else{
4391 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4392 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4393 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4394 >      }
4395 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4396 >
4397 >
4398 >      histo->Fill(valueX,valueY,scaleFactor);
4399 >
4400 >    }
4401 >  }
4402 >
4403 > }
4404 >
4405 >
4406 > template <class InputObject>
4407 > int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
4408 >
4409 >  int bestMatchIndex = -1;
4410 >  double bestMatchDeltaR = 999;
4411 >
4412 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4413 >
4414 >    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4415 >    if(currentDeltaR > 0.05) continue;
4416 >    //     cout << setprecision(3) << setw(20)
4417 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4418 >    //          << setw(20)
4419 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4420 >    //          << setw(20)
4421 >    //          << "\tdeltaR = " << currentDeltaR
4422 >    //          << setprecision(1)
4423 >    //          << setw(20)
4424 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4425 >    //          << setw(20)
4426 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4427 >    //          << setw(20)
4428 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4429 >    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4430 >      bestMatchIndex = mcparticle - mcparticles->begin();
4431 >      bestMatchDeltaR = currentDeltaR;
4432 >    }
4433 >
4434 >  }
4435 >  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4436 >  //   else cout << "no match found..." << endl;
4437 >  return bestMatchIndex;
4438 >
4439 > }
4440  
4441  
4442 + int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
4443 +
4444 +  int bestMatchIndex = -1;
4445 +  double bestMatchDeltaR = 999;
4446 +
4447 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4448 +
4449 +    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
4450 +
4451 +    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
4452 +    if(currentDeltaR > 0.05) continue;
4453 +
4454 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4455 +      bestMatchIndex = mcparticle - mcparticles->begin();
4456 +      bestMatchDeltaR = currentDeltaR;
4457 +    }
4458 +
4459 +  }
4460 +
4461 +  return bestMatchIndex;
4462 + }
4463 +
4464 +
4465 + // bin      particle type
4466 + // ---      -------------
4467 + //  0        unmatched
4468 + //  1        u
4469 + //  2        d
4470 + //  3        s
4471 + //  4        c
4472 + //  5        b
4473 + //  6        t
4474 + //  7        e
4475 + //  8        mu
4476 + //  9        tau
4477 + // 10        nu
4478 + // 11        g
4479 + // 12        gamma
4480 + // 13        Z
4481 + // 14        W
4482 + // 15        light meson
4483 + // 16        K meson
4484 + // 17        D meson
4485 + // 18        B meson
4486 + // 19        light baryon
4487 + // 20        strange baryon
4488 + // 21        charm baryon
4489 + // 22        bottom baryon
4490 + // 23        QCD string
4491 + // 24        other
4492 +
4493 + int OSUAnalysis::getPdgIdBinValue(int pdgId){
4494 +
4495 +  int binValue = -999;
4496 +  int absPdgId = fabs(pdgId);
4497 +  if(pdgId == -1) binValue = 0;
4498 +  else if(absPdgId <= 6 ) binValue = absPdgId;
4499 +  else if(absPdgId == 11 ) binValue = 7;
4500 +  else if(absPdgId == 13 ) binValue = 8;
4501 +  else if(absPdgId == 15 ) binValue = 9;
4502 +  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
4503 +  else if(absPdgId == 21 ) binValue = 11;
4504 +  else if(absPdgId == 22 ) binValue = 12;
4505 +  else if(absPdgId == 23 ) binValue = 13;
4506 +  else if(absPdgId == 24 ) binValue = 14;
4507 +  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
4508 +  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
4509 +  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
4510 +  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
4511 +  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
4512 +  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4513 +  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4514 +  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4515 +  else if(absPdgId == 92  ) binValue = 23;
4516 +
4517 +  else binValue = 24;
4518 +
4519 +  return binValue;
4520 +
4521 + }
4522 +
4523 + const BNprimaryvertex *
4524 + OSUAnalysis::chosenVertex ()
4525 + {
4526 +  const BNprimaryvertex *chosenVertex = 0;
4527 +  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4528 +    flagPair vertexFlags;
4529 +    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4530 +      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4531 +        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4532 +        break;
4533 +      }
4534 +    }
4535 +    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4536 +      if(!vertexFlags.at(vertexIndex).first) continue;
4537 +      chosenVertex = & primaryvertexs->at(vertexIndex);
4538 +      break;
4539 +    }
4540 +  }
4541 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4542 +    chosenVertex = & primaryvertexs->at (0);
4543 +
4544 +  return chosenVertex;
4545 + }
4546 +
4547 + const BNmet *
4548 + OSUAnalysis::chosenMET ()
4549 + {
4550 +  const BNmet *chosenMET = 0;
4551 +  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4552 +    flagPair metFlags;
4553 +    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4554 +      if (cumulativeFlags.at("mets").at(i).size()){
4555 +        metFlags = cumulativeFlags.at("mets").at(i);
4556 +        break;
4557 +      }
4558 +    }
4559 +    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4560 +      if(!metFlags.at(metIndex).first) continue;
4561 +      chosenMET = & mets->at(metIndex);
4562 +      break;
4563 +    }
4564 +  }
4565 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4566 +    chosenMET = & mets->at (0);
4567 +
4568 +  return chosenMET;
4569 + }
4570 +
4571 + const BNelectron *
4572 + OSUAnalysis::chosenElectron ()
4573 + {
4574 +  const BNelectron *chosenElectron = 0;
4575 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4576 +    flagPair electronFlags;
4577 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4578 +      if (cumulativeFlags.at("electrons").at(i).size()){
4579 +        electronFlags = cumulativeFlags.at("electrons").at(i);
4580 +        break;
4581 +      }
4582 +    }
4583 +    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4584 +      if(!electronFlags.at(electronIndex).first) continue;
4585 +      chosenElectron = & electrons->at(electronIndex);
4586 +      break;
4587 +    }
4588 +  }
4589 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4590 +    chosenElectron = & electrons->at (0);
4591 +
4592 +  return chosenElectron;
4593 + }
4594 +
4595 +
4596 + const BNmuon *
4597 + OSUAnalysis::chosenMuon ()
4598 + {
4599 +  const BNmuon *chosenMuon = 0;
4600 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4601 +    flagPair muonFlags;
4602 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4603 +      if (cumulativeFlags.at("muons").at(i).size()){
4604 +        muonFlags = cumulativeFlags.at("muons").at(i);
4605 +        break;
4606 +      }
4607 +    }
4608 +    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4609 +      if(!muonFlags.at(muonIndex).first) continue;
4610 +      chosenMuon = & muons->at(muonIndex);
4611 +      break;
4612 +    }
4613 +  }
4614 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4615 +    chosenMuon = & muons->at (0);
4616 +
4617 +  return chosenMuon;
4618 + }
4619 +
4620 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines