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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines