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.28 by jbrinson, Thu Mar 14 10:06:38 2013 UTC vs.
Revision 1.113 by lantonel, Wed Jul 31 09:24:14 2013 UTC

# Line 1 | Line 1
1   #include "OSUT3Analysis/AnaTools/plugins/OSUAnalysis.h"
2
2   OSUAnalysis::OSUAnalysis (const edm::ParameterSet &cfg) :
3    // Retrieve parameters from the configuration file.
4    jets_ (cfg.getParameter<edm::InputTag> ("jets")),
# Line 11 | Line 10 | OSUAnalysis::OSUAnalysis (const edm::Par
10    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
11    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
12    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
13 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
14    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
15    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
16    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
17    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
18    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
19 <  puFile_ (cfg.getParameter<std::string> ("puFile")),
20 <  deadEcalFile_ (cfg.getParameter<std::string> ("deadEcalFile")),
21 <  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
22 <  dataset_ (cfg.getParameter<std::string> ("dataset")),
23 <  datasetType_ (cfg.getParameter<std::string> ("datasetType")),
19 >  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
20 >  puFile_ (cfg.getParameter<string> ("puFile")),
21 >  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
22 >  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
23 >  dataPU_ (cfg.getParameter<string> ("dataPU")),
24 >  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
25 >  muonSF_ (cfg.getParameter<string> ("muonSF")),
26 >  dataset_ (cfg.getParameter<string> ("dataset")),
27 >  datasetType_ (cfg.getParameter<string> ("datasetType")),
28    channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
29    histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
30 <  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents"))
30 >  useEDMFormat_   (cfg.getParameter<bool>("useEDMFormat")),
31 >  treeBranchSets_   (cfg.getParameter<vector<edm::ParameterSet> >("treeBranchSets")),
32 >  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
33 >  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
34 >  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
35 >  applyBtagSF_ (cfg.getParameter<bool> ("applyBtagSF")),
36 >  minBtag_ (cfg.getParameter<int> ("minBtag")),
37 >  printEventInfo_      (cfg.getParameter<bool> ("printEventInfo")),
38 >  printAllTriggers_    (cfg.getParameter<bool> ("printAllTriggers")),
39 >  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
40 >  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
41 >  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut")),
42 >  verbose_ (cfg.getParameter<int> ("verbose"))
43 > {
44  
45 < {
45 >  if (verbose_) printEventInfo_ = true;  
46 >  if (verbose_) clog << "Beginning OSUAnalysis::OSUAnalysis constructor." << endl;  
47  
48 <  TH1::SetDefaultSumw2 ();
48 >  TH1::SetDefaultSumw2();
49  
50    //create pile-up reweighting object, if necessary
51 <  //  if(datasetType_ != "data") puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
51 >  if(datasetType_ != "data") {
52 >    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
53 >    if (applyLeptonSF_){
54 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
55 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
56 >    }
57 >    if (applyBtagSF_){
58 >      bTagSFWeight_ = new BtagSFWeight;
59 >    }
60 >  }
61 >  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
62 >    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at(0), stopCTau_.at(1), stops_);
63 >
64  
65    // Construct Cutflow Objects. These store the results of cut decisions and
66    // handle filling cut flow histograms.
67    masterCutFlow_ = new CutFlow (fs_);
38  std::vector<TFileDirectory> directories;
68  
69    //always get vertex collection so we can assign the primary vertex in the event
70 <  
42 < objectsToGet.push_back("primaryvertexs");
43 <  //always make the plot of number of primary verticex (to check pile-up reweighting)
70 >  objectsToGet.push_back("primaryvertexs");
71    objectsToPlot.push_back("primaryvertexs");
72 +  objectsToFlag.push_back("primaryvertexs");
73 +
74  
75    //always get the MC particles to do GEN-matching
76    objectsToGet.push_back("mcparticles");
# Line 49 | Line 78 | objectsToGet.push_back("primaryvertexs")
78    //always get the event collection to do pile-up reweighting
79    objectsToGet.push_back("events");
80  
81 +
82 +  // Parse the tree variable definitions.
83 +  for (uint iBranchSet = 0; !useEDMFormat_ && iBranchSet<treeBranchSets_.size(); iBranchSet++) {
84 +    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
85 +    if(tempInputCollection.find("pairs")!=string::npos) { clog << "Warning:  tree filling is not configured for pairs of objects, so will not work for collection: " << tempInputCollection << endl; }
86 +    objectsToGet.push_back(tempInputCollection);
87 +    objectsToFlag.push_back(tempInputCollection);
88 +
89 +    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
90 +
91 +    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
92 +      BranchSpecs br;
93 +      br.inputCollection = tempInputCollection;
94 +      br.inputVariable = branchList.at(iBranch);
95 +      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);
96 +      br.name = string(newName.Data());
97 +      treeBranches_.push_back(br);
98 +      if (verbose_>3) clog << "   Adding branch to BNTree: " << br.name << endl;  
99 +    }
100 +
101 +  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++)
102 +
103 +
104    //parse the histogram definitions
105    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
106  
107      string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
108      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
109 <    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
110 <      objectsToGet.push_back(tempInputCollection);
109 >    if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
110 >    if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
111 >    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
112 >    if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
113 >    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
114 >    if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
115 >    if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
116 >    if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
117 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
118 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
119 >    if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
120 >    if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
121 >    if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
122 >    if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
123 >    if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
124 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
125 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
126 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
127 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
128 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
129 >        int spaceIndex = tempInputCollection.find(" ");
130 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
131 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
132 >      }
133 >      else{
134 >        objectsToGet.push_back(tempInputCollection);
135 >      }
136        objectsToPlot.push_back(tempInputCollection);
137 <      objectsToCut.push_back(tempInputCollection);
138 <    }
139 <    else{//pair of objects, need to add them both to the things to objectsToGet
140 <      int dashIndex = tempInputCollection.find("-");
141 <      int spaceIndex = tempInputCollection.find(" ");
142 <      int secondWordLength = spaceIndex - dashIndex;
143 <      objectsToGet.push_back(tempInputCollection);
144 <      objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
145 <      objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
137 >      objectsToFlag.push_back(tempInputCollection);
138 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
139 >      string obj1;
140 >      string obj2;
141 >      getTwoObjs(tempInputCollection, obj1, obj2);
142 >      string obj2ToGet = getObjToGet(obj2);
143 >      objectsToFlag.push_back(tempInputCollection);
144 >      objectsToFlag.push_back(obj1);
145 >      objectsToFlag.push_back(obj2);
146        objectsToPlot.push_back(tempInputCollection);
147 <      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
148 <      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
149 <      objectsToCut.push_back(tempInputCollection);
150 <      objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
151 <      objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
152 <
153 <      }
154 <
155 <    vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
147 >      objectsToPlot.push_back(obj1);
148 >      objectsToPlot.push_back(obj2);
149 >      objectsToGet.push_back(tempInputCollection);
150 >      objectsToGet.push_back(obj1);
151 >      objectsToGet.push_back(obj2ToGet);
152 >    } // end else
153 >    if (find(objectsToPlot.begin(), objectsToPlot.end(), "events") != objectsToPlot.end())
154 >      objectsToGet.push_back("jets");
155 >    
156      
157 +    vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
158 +
159      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
160  
161 +      vector<double> defaultValue;
162 +      defaultValue.push_back (-1.0);
163 +
164        histogram tempHistogram;
165        tempHistogram.inputCollection = tempInputCollection;
166        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
167        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
168 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
168 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
169 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
170 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
171        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
172 <      
172 >
173        histograms.push_back(tempHistogram);
174  
175      }
176 <  }
176 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
177 >
178    //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
179    sort( objectsToPlot.begin(), objectsToPlot.end() );
180    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
# Line 100 | Line 185 | objectsToGet.push_back("primaryvertexs")
185    for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
186  
187      string currentObject = objectsToPlot.at(currentObjectIndex);
188 <    if(currentObject != "muons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
188 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "secondary photons"&& currentObject != "superclusters") continue;
189  
190      histogram tempIdHisto;
191      histogram tempMomIdHisto;
192      histogram tempGmaIdHisto;
193 +    histogram tempIdVsMomIdHisto;
194 +    histogram tempIdVsGmaIdHisto;
195  
196      tempIdHisto.inputCollection = currentObject;
197      tempMomIdHisto.inputCollection = currentObject;
198      tempGmaIdHisto.inputCollection = currentObject;
199 +    tempIdVsMomIdHisto.inputCollection = currentObject;
200 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
201 +
202 +    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
203 +    if(currentObject == "secondary photons") currentObject = "secondaryPhotons";
204 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
205  
206      currentObject = currentObject.substr(0, currentObject.size()-1);
207      tempIdHisto.name = currentObject+"GenMatchId";
208      tempMomIdHisto.name = currentObject+"GenMatchMotherId";
209      tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
210 +    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
211 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
212  
213      currentObject.at(0) = toupper(currentObject.at(0));
214      tempIdHisto.title = currentObject+" Gen-matched Particle";
215      tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
216      tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
217 +    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
218 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
219  
220 <    int maxNum = 24;
220 >
221 >    int maxNum = 25;
222      vector<double> binVector;
223      binVector.push_back(maxNum);
224      binVector.push_back(0);
# Line 132 | Line 230 | objectsToGet.push_back("primaryvertexs")
230      tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
231      tempGmaIdHisto.bins = binVector;
232      tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
233 +    binVector.push_back(maxNum);
234 +    binVector.push_back(0);
235 +    binVector.push_back(maxNum);
236 +    tempIdVsMomIdHisto.bins = binVector;
237 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
238 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
239 +    tempIdVsGmaIdHisto.bins = binVector;
240 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
241 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
242  
243      histograms.push_back(tempIdHisto);
244      histograms.push_back(tempMomIdHisto);
245      histograms.push_back(tempGmaIdHisto);
246 <    
246 >    histograms.push_back(tempIdVsMomIdHisto);
247 >    histograms.push_back(tempIdVsGmaIdHisto);
248    }
249  
250  
143
251    channel tempChannel;
252    //loop over all channels (event selections)
253    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
# Line 149 | Line 256 | objectsToGet.push_back("primaryvertexs")
256      string channelName  (channels_.at(currentChannel).getParameter<string>("name"));
257      tempChannel.name = channelName;
258      TString channelLabel = channelName;
259 +    if (verbose_) clog << "Processing channel:  " << channelName << endl;  
260  
261      //set triggers for this channel
262      vector<string> triggerNames;
263      triggerNames.clear();
264 +    vector<string> triggerToVetoNames;
265 +    triggerToVetoNames.clear();
266 +
267      tempChannel.triggers.clear();
268 +    tempChannel.triggersToVeto.clear();
269      if(channels_.at(currentChannel).exists("triggers")){
270        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
271        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
272          tempChannel.triggers.push_back(triggerNames.at(trigger));
273        objectsToGet.push_back("triggers");
274      }
275 <
275 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
276 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
277 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
278 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
279 >      objectsToGet.push_back("triggers");
280 >    }
281  
282  
283  
284      //create cutFlow for this channel
285      cutFlows_.push_back (new CutFlow (fs_, channelName));
286 <
287 <    //book a directory in the output file with the name of the channel
288 <    TFileDirectory subDir = fs_->mkdir( channelName );
172 <    directories.push_back(subDir);
173 <
174 <    std::map<std::string, TH1D*> oneDhistoMap;
175 <    oneDHists_.push_back(oneDhistoMap);
176 <    std::map<std::string, TH2D*> twoDhistoMap;
177 <    twoDHists_.push_back(twoDhistoMap);
178 <
179 <
180 <    //book all histograms included in the configuration
181 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
182 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
183 <      int numBinsElements = currentHistogram.bins.size();
184 <      int numInputVariables = currentHistogram.inputVariables.size();
185 <
186 <      if(numBinsElements != 3 && numBinsElements !=6) {
187 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
188 <        exit(0);
189 <      }
190 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
191 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
192 <        exit(0);
193 <      }
194 <      else if(numBinsElements == 3){
195 <        oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
196 <      }
197 <      else if(numBinsElements == 6){
198 <        twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2),currentHistogram.bins.at(3),currentHistogram.bins.at(4),currentHistogram.bins.at(5));
199 <
200 <      }
201 <
202 <
203 <      if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
204 <
205 < // bin      particle type
206 < // ---      -------------
207 < //  0        unmatched
208 < //  1        u
209 < //  2        d
210 < //  3        s
211 < //  4        c
212 < //  5        b
213 < //  6        t
214 < //  7        e
215 < //  8        mu
216 < //  9        tau
217 < // 10        nu
218 < // 11        g
219 < // 12        gamma
220 < // 13        Z
221 < // 14        W
222 < // 15        light meson
223 < // 16        K meson
224 < // 17        D meson
225 < // 18        B meson
226 < // 19        light baryon
227 < // 20        strange baryon
228 < // 21        charm baryon
229 < // 22        bottom baryon
230 < // 23        other
231 <
232 <      vector<TString> labelArray;
233 <      labelArray.push_back("unmatched");
234 <      labelArray.push_back("u");
235 <      labelArray.push_back("d");
236 <      labelArray.push_back("s");
237 <      labelArray.push_back("c");
238 <      labelArray.push_back("b");
239 <      labelArray.push_back("t");
240 <      labelArray.push_back("e");
241 <      labelArray.push_back("#mu");
242 <      labelArray.push_back("#tau");
243 <      labelArray.push_back("#nu");
244 <      labelArray.push_back("g");
245 <      labelArray.push_back("#gamma");
246 <      labelArray.push_back("Z");
247 <      labelArray.push_back("W");
248 <      labelArray.push_back("light meson");
249 <      labelArray.push_back("K meson");
250 <      labelArray.push_back("D meson");
251 <      labelArray.push_back("B meson");
252 <      labelArray.push_back("light baryon");
253 <      labelArray.push_back("strange baryon");
254 <      labelArray.push_back("charm baryon");
255 <      labelArray.push_back("bottom baryon");
256 <      labelArray.push_back("other");
257 <
258 <      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
259 <        oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
260 <      }
261 <    }
262 <
263 <    //book a histogram for the number of each object type to be plotted
264 <
265 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
266 <      string currentObject = objectsToPlot.at(currentObjectIndex);
267 <      int maxNum = 10;
268 <      if(currentObject == "mcparticles") maxNum = 50;
269 <      else if(currentObject == "primaryvertexs") maxNum = 50;
270 <      else if(currentObject == "muon-muon pairs")
271 <        {
272 <          currentObject = "dimuonPairs";
273 <        }
274 <      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
275 <      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
276 <
277 <      currentObject.at(0) = toupper(currentObject.at(0));
278 <      string histoName = "num" + currentObject;
279 <
280 <      if(histoName == "numPrimaryvertexs"){
281 <        string newHistoName = histoName + "BeforePileupCorrection";
282 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);    
283 <        newHistoName = histoName + "AfterPileupCorrection";
284 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
285 <      }
286 <      else
287 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
288 <    }
289 <
290 <
291 <    
292 <
293 <
286 >    vector<TFileDirectory> directories; //vector of directories in the output file.
287 >    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
288 >    vector<string> subSubDirNames;//subdirectories in each channel.
289      //get list of cuts for this channel
290      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
291  
292 +
293      //loop over and parse all cuts
294      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
295        cut tempCut;
296        //store input collection for cut
297        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
298 +      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
299 +      if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
300 +      if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
301 +      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
302 +      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
303 +      if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
304 +      if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
305 +      if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
306 +      if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
307 +      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
308 +      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
309 +      if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
310 +      if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
311 +      if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
312 +      if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
313 +      if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
314 +      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
315 +      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
316 +      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
317        tempCut.inputCollection = tempInputCollection;
318 <      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
319 <        objectsToGet.push_back(tempInputCollection);
320 <        objectsToCut.push_back(tempInputCollection);
321 <      }
322 <      else{//pair of objects, need to add them both to the things to objectsToGet
323 <        int dashIndex = tempInputCollection.find("-");
324 <        int spaceIndex = tempInputCollection.find(" ");
325 <        int secondWordLength = spaceIndex - dashIndex;
326 <        objectsToGet.push_back(tempInputCollection);
327 <        objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
328 <        objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
329 <        objectsToCut.push_back(tempInputCollection);
330 <        objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
331 <        objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
318 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
319 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
320 >          int spaceIndex = tempInputCollection.find(" ");
321 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
322 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
323 >        }
324 >        else{
325 >          objectsToGet.push_back(tempInputCollection);
326 >        }
327 >        objectsToCut.push_back(tempInputCollection);
328 >        objectsToFlag.push_back(tempInputCollection);
329 >      }
330 >      else{//pair of objects, need to add them both to objectsToGet
331 >        string obj1;
332 >        string obj2;
333 >        getTwoObjs(tempInputCollection, obj1, obj2);
334 >        string obj2ToGet = getObjToGet(obj2);
335 >        objectsToCut.push_back(tempInputCollection);
336 >        objectsToCut.push_back(obj1);
337 >        objectsToCut.push_back(obj2);
338 >        objectsToFlag.push_back(tempInputCollection);
339 >        objectsToFlag.push_back(obj1);
340 >        objectsToFlag.push_back(obj2);
341 >        objectsToGet.push_back(tempInputCollection);
342 >        objectsToGet.push_back(obj1);
343 >        objectsToGet.push_back(obj2ToGet);
344  
345        }
346  
# Line 321 | Line 348 | objectsToGet.push_back("primaryvertexs")
348  
349        //split cut string into parts and store them
350        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
351 <      std::vector<string> cutStringVector = splitString(cutString);
351 >      vector<string> cutStringVector = splitString(cutString);
352        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
353 <        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
354 <        exit(0);
353 >        clog << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
354 >        exit(0);
355        }
356        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
357        for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
358 <        int indexOffset = 4 * subcutIndex;
359 <        string currentVariableString = cutStringVector.at(indexOffset);
360 <        if(currentVariableString.find("(")==std::string::npos){
361 <          tempCut.functions.push_back("");//no function was specified
362 <          tempCut.variables.push_back(currentVariableString);// variable to cut on
363 <        }
364 <        else{
365 <          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
366 <          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
367 <          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
368 <        }
369 <        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
370 <        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
371 <        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
358 >        int indexOffset = 4 * subcutIndex;
359 >        string currentVariableString = cutStringVector.at(indexOffset);
360 >        if(currentVariableString.find("(")==string::npos){
361 >          tempCut.functions.push_back("");//no function was specified
362 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
363 >        }
364 >        else{
365 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
366 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
367 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
368 >        }
369 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
370 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
371 >        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
372 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
373        }
374  
375        //get number of objects required to pass cut for event to pass
376        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
377 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
377 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
378        if(numberRequiredVector.size()!=2){
379 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
379 >        clog << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
380          exit(0);
381        }
382  
# Line 356 | Line 384 | objectsToGet.push_back("primaryvertexs")
384        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
385        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
386  
387 <
387 >      //Set up vectors to store the directories and subDirectories for each channel.
388 >      string subSubDirName;
389        string tempCutName;
390        if(cuts_.at(currentCut).exists("alias")){
391          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
392 +        subSubDirName = "After " + tempCutName + " Cut Applied";
393        }
394        else{
395          //construct string for cutflow table
# Line 367 | Line 397 | objectsToGet.push_back("primaryvertexs")
397          string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
398          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
399          tempCutName = cutName;
400 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
401        }
371      tempCut.name = tempCutName;
402  
403 +      tempCut.isVeto = false;
404 +      if(cuts_.at(currentCut).exists("isVeto")){
405 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
406 +        if (isVeto == true) tempCut.isVeto = true;
407 +      }
408 +      subSubDirNames.push_back(subSubDirName);
409 +      tempCut.name = tempCutName;
410 +      if (verbose_) clog << "Setting up cut, index: " << currentCut << ", input collection: " << tempInputCollection<< ", name: " << tempCut.name << endl;  
411  
412        tempChannel.cuts.push_back(tempCut);
413  
414  
377
415      }//end loop over cuts
416  
417 +    vector<map<string, TH1D*>> oneDHistsTmp;
418 +    vector<map<string, TH2D*>> twoDHistsTmp;
419 +    //book a directory in the output file with the name of the channel
420 +    TFileDirectory subDir = fs_->mkdir( channelName );
421 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
422 +    if(GetPlotsAfterEachCut_){
423 +      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
424 +        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
425 +        directories.push_back(subSubDir);
426 +        map<string, TH1D*> oneDhistoMap;
427 +        oneDHistsTmp.push_back(oneDhistoMap);
428 +        map<string, TH2D*> twoDhistoMap;
429 +        twoDHistsTmp.push_back(twoDhistoMap);
430 +      }
431 +      treeDirectories.push_back(subDir);
432 +      oneDHists_.push_back(oneDHistsTmp);
433 +      twoDHists_.push_back(twoDHistsTmp);
434 +    }
435 +    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
436 +    else{
437 +      map<string, TH1D*> oneDhistoMap;
438 +      oneDHistsTmp.push_back(oneDhistoMap);
439 +      map<string, TH2D*> twoDhistoMap;
440 +      twoDHistsTmp.push_back(twoDhistoMap);
441 +      oneDHists_.push_back(oneDHistsTmp);
442 +      twoDHists_.push_back(twoDHistsTmp);
443 +      directories.push_back(subDir);
444 +      treeDirectories.push_back(subDir);
445 +
446 +    }
447 +
448 +    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
449 +      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
450 +      BNTrees_.push_back(newTree);
451 +      BNTrees_.back()->Branch("event_runInt",  &BNTreeBranchVals_runInt_,  "event_runInt/I");      
452 +      BNTrees_.back()->Branch("event_lumiInt", &BNTreeBranchVals_lumiInt_, "event_lumiInt/I");      
453 +      BNTrees_.back()->Branch("event_evtLong", &BNTreeBranchVals_evtLong_, "event_evtLong/L");      
454 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
455 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
456 +        vector<float> newVec;
457 +        BNTreeBranchVals_[currentVar.name] = newVec;
458 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
459 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
460 +    }
461 +
462 +    //book all histograms included in the configuration
463 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
464 +
465 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
466 +
467 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
468 +        int numBinsElements = currentHistogram.bins.size();
469 +        int numInputVariables = currentHistogram.inputVariables.size();
470 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
471 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
472 +
473 +        if(numBinsElements == 1){
474 +          if(numBinEdgesX > 1){
475 +            if(numBinEdgesY > 1)
476 +              numBinsElements = 6;
477 +            else
478 +              numBinsElements = 3;
479 +          }
480 +        }
481 +        if(numBinsElements != 3 && numBinsElements !=6){
482 +          clog << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
483 +          exit(0);
484 +        }
485 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
486 +          clog << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
487 +          exit(0);
488 +        }
489 +        else if(numBinsElements == 3){
490 +          if (currentHistogram.bins.size () == 3)
491 +            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));
492 +          else
493 +            {
494 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
495 +            }
496 +        }
497 +        else if(numBinsElements == 6){
498 +          if (currentHistogram.bins.size () == 6)
499 +            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));
500 +          else
501 +            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 ());
502 +        }
503 +
504 +
505 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
506 +
507 +        // bin      particle type
508 +        // ---      -------------
509 +        //  0        unmatched
510 +        //  1        u
511 +        //  2        d
512 +        //  3        s
513 +        //  4        c
514 +        //  5        b
515 +        //  6        t
516 +        //  7        e
517 +        //  8        mu
518 +        //  9        tau
519 +        // 10        nu
520 +        // 11        g
521 +        // 12        gamma
522 +        // 13        Z
523 +        // 14        W
524 +        // 15        light meson
525 +        // 16        K meson
526 +        // 17        D meson
527 +        // 18        B meson
528 +        // 19        light baryon
529 +        // 20        strange baryon
530 +        // 21        charm baryon
531 +        // 22        bottom baryon
532 +        // 23        QCD string
533 +        // 24        other
534 +
535 +        vector<TString> labelArray;
536 +        labelArray.push_back("unmatched");
537 +        labelArray.push_back("u");
538 +        labelArray.push_back("d");
539 +        labelArray.push_back("s");
540 +        labelArray.push_back("c");
541 +        labelArray.push_back("b");
542 +        labelArray.push_back("t");
543 +        labelArray.push_back("e");
544 +        labelArray.push_back("#mu");
545 +        labelArray.push_back("#tau");
546 +        labelArray.push_back("#nu");
547 +        labelArray.push_back("g");
548 +        labelArray.push_back("#gamma");
549 +        labelArray.push_back("Z");
550 +        labelArray.push_back("W");
551 +        labelArray.push_back("light meson");
552 +        labelArray.push_back("K meson");
553 +        labelArray.push_back("D meson");
554 +        labelArray.push_back("B meson");
555 +        labelArray.push_back("light baryon");
556 +        labelArray.push_back("strange baryon");
557 +        labelArray.push_back("charm baryon");
558 +        labelArray.push_back("bottom baryon");
559 +        labelArray.push_back("QCD string");
560 +        labelArray.push_back("other");
561 +
562 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
563 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
564 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
565 +          }
566 +          else {
567 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
568 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
569 +          }
570 +        }
571 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
572 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
573 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
574 +        }
575 +
576 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
577 +
578 +
579 +      // Book a histogram for the number of each object type to be plotted.
580 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
581 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
582 +        string currentObject = objectsToPlot.at(currentObjectIndex);
583 +        int maxNum = 10;
584 +        if(currentObject == "mcparticles") maxNum = 50;
585 +        else if(currentObject == "primaryvertexs") maxNum = 50;
586 +
587 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
588 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
589 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
590 +        else if(currentObject == "electron-photon pairs")     currentObject = "electronPhotonPairs";
591 +        else if(currentObject == "muon-photon pairs")         currentObject = "muonPhotonPairs";
592 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
593 +        else if(currentObject == "secondary photons")            currentObject = "secondaryPhotons";
594 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
595 +        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
596 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
597 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
598 +        else if(currentObject == "muon-event pairs")            currentObject = "muonEventPairs";
599 +        else if(currentObject == "photon-jet pairs")            currentObject = "photonJetPairs";
600 +        else if(currentObject == "met-jet pairs")             currentObject = "metJetPairs";
601 +        else if(currentObject == "track-jet pairs")           currentObject = "trackJetPairs";
602 +        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
603 +        else if(currentObject == "muon-secondary photon pairs")  currentObject = "muonSecondaryPhotonPairs";
604 +        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
605 +        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
606 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
607 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
608 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
609 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
610 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
611 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
612 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
613 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
614 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
615 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
616 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
617 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
618 +        else if(currentObject == "electron-mcparticle pairs")   currentObject = "electronMCparticlePairs";
619 +
620 +
621 +        currentObject.at(0) = toupper(currentObject.at(0));
622 +        string histoName = "num" + currentObject;
623 +
624 +        if(histoName == "numPrimaryvertexs"){
625 +          string newHistoName = histoName + "BeforePileupCorrection";
626 +          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);
627 +          newHistoName = histoName + "AfterPileupCorrection";
628 +          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);
629 +        }
630 +        else
631 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
632 +      }
633 +
634 +      if (verbose_) {
635 +        clog << "List of 1D histograms booked for channel " << channelName << " and directory " << currentDir << ":" << endl;
636 +        for(map<string, TH1D*>::iterator
637 +              iter = oneDHists_.at(currentChannel).at(currentDir).begin();
638 +            iter  != oneDHists_.at(currentChannel).at(currentDir).end();
639 +            iter++) {
640 +          clog << " " << iter->first
641 +               << ":  name=" << iter->second->GetName()
642 +               << ", title=" << iter->second->GetTitle()
643 +               << ", bins=(" << iter->second->GetNbinsX()
644 +               << "," << iter->second->GetXaxis()->GetXmin()
645 +               << "," << iter->second->GetXaxis()->GetXmax()
646 +               << ")" << endl;
647 +        }  
648 +        clog << "List of 2D histograms booked for channel " << channelName << " and directory " << currentDir << ":" << endl;
649 +        for(map<string, TH2D*>::iterator
650 +              iter = twoDHists_.at(currentChannel).at(currentDir).begin();
651 +            iter  != twoDHists_.at(currentChannel).at(currentDir).end();
652 +            iter++) {
653 +          clog << " " << iter->first
654 +               << ":  name=" << iter->second->GetName()
655 +               << ", title=" << iter->second->GetTitle()
656 +               << ", binsX=(" << iter->second->GetNbinsX()
657 +               << "," << iter->second->GetXaxis()->GetXmin()
658 +               << "," << iter->second->GetXaxis()->GetXmax()
659 +               << ")"
660 +               << ", binsY=(" << iter->second->GetNbinsY()
661 +               << "," << iter->second->GetYaxis()->GetXmin()
662 +               << "," << iter->second->GetYaxis()->GetXmax()
663 +               << ")"
664 +               << endl;
665 +        }  
666 +      }
667 +
668 +    }//end of loop over directories
669      channels.push_back(tempChannel);
670      tempChannel.cuts.clear();
382
671    }//end loop over channels
672  
673  
674 +  // Create the cutflow histogram and fill with 0 weight, in case no events are found in the input file.  
675 +  for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
676 +    channel currentChannel = channels.at(currentChannelIndex);
677 +    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
678 +      cutFlows_.at(currentChannelIndex)->at("trigger") = true;  
679 +    }
680 +    for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
681 +      cut currentCut = currentChannel.cuts.at(currentCutIndex);
682 +      cutFlows_.at(currentChannelIndex)->at (currentCut.name) = true;
683 +    }
684 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(0);  // fill cutflow with 0 weight, just to create the cutflow histograms  
685 +  }
686 +
687    //make unique vector of objects we need to get from the event
688    sort( objectsToGet.begin(), objectsToGet.end() );
689    objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
690    //make unique vector of objects we need to cut on
691    sort( objectsToCut.begin(), objectsToCut.end() );
692    objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
693 +  //make unique vector of objects we need to set flags for
694 +  sort( objectsToFlag.begin(), objectsToFlag.end() );
695 +  objectsToFlag.erase( unique( objectsToFlag.begin(), objectsToFlag.end() ), objectsToFlag.end() );
696 +
697 +  // Move all paired objects to the end of the list, so that the flags for single objects are always set before those of paired objects.  
698 +  for (uint i=0; i<objectsToFlag.size(); i++) {
699 +    if (objectsToFlag.at(i).find("pairs")!=string::npos) { // if it contains "pairs"
700 +      objectsToFlag.push_back(objectsToFlag.at(i));  
701 +      objectsToFlag.erase(objectsToFlag.begin()+i);  
702 +    }
703 +  }
704  
705 +  if (verbose_) {
706 +    clog << "List of channels:" << endl;
707 +    for (uint i=0; i<channels.size(); i++) {
708 +      clog << " " << channels.at(i).name << endl;
709 +    }
710 +    clog << "List of objects to get:" << endl;
711 +    for (uint i=0; i<objectsToGet.size(); i++) {
712 +      clog << " " << objectsToGet.at(i) << endl;
713 +    }
714 +    clog << "List of objects to plot:" << endl;
715 +    for (uint i=0; i<objectsToPlot.size(); i++) {
716 +      clog << " " << objectsToPlot.at(i) << endl;
717 +    }
718 +    clog << "List of objects to cut:" << endl;
719 +    for (uint i=0; i<objectsToCut.size(); i++) {
720 +      clog << " " << objectsToCut.at(i) << endl;
721 +    }
722 +    clog << "List of objects to flag:" << endl;
723 +    for (uint i=0; i<objectsToFlag.size(); i++) {
724 +      clog << " " << objectsToFlag.at(i) << endl;
725 +    }
726 +  }
727 +
728 +  produces<map<string, bool> > ("channelDecisions");
729 +
730 +  if (printEventInfo_) {
731 +    findEventsLog = new ofstream();  
732 +    findEventsLog->open("findEvents.txt");  
733 +    clog << "Listing run:lumi:event in file findEvents.txt for events that pass full selection (of any channel)." << endl;  
734 +  } else {
735 +    findEventsLog = 0;
736 +  }  
737 +
738 +  isFirstEvent_ = true;  
739 +
740 +  if (verbose_) clog << "Finished OSUAnalysis::OSUAnalysis constructor." << endl;  
741 +
742 +
743 +  } // end constructor OSUAnalysis::OSUAnalysis()
744  
394 }
745  
746   OSUAnalysis::~OSUAnalysis ()
747   {
748 +
749 +  if (verbose_) clog << "Beginning OSUAnalysis::OSUAnalysis destructor." << endl;  
750 +
751    // Destroying the CutFlow objects causes the cut flow numbers and time
752    // information to be printed to standard output.
753    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
754      delete cutFlows_.at(currentChannel);
755    }
756 +
757 +  if (printEventInfo_ && findEventsLog) findEventsLog->close();  
758 +
759 +  clog << "=============================================" << endl;  
760 +  clog << "Successfully completed OSUAnalysis." << endl;  
761 +  clog << "=============================================" << endl;  
762 +
763 +  if (verbose_) clog << "Finished OSUAnalysis::OSUAnalysis destructor." << endl;  
764 +
765   }
766  
767   void
768 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
768 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
769   {
408
770    // Retrieve necessary collections from the event.
771  
772 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
772 >  if (verbose_) clog << "Beginning OSUAnalysis::produce." << endl;  
773 >
774 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
775      event.getByLabel (triggers_, triggers);
776  
777 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
777 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
778 >    event.getByLabel (trigobjs_, trigobjs);
779 >
780 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
781      event.getByLabel (jets_, jets);
782  
783 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
783 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
784      event.getByLabel (muons_, muons);
785  
786 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
786 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
787      event.getByLabel (electrons_, electrons);
788  
789 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
789 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
790      event.getByLabel (events_, events);
791  
792 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
792 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
793      event.getByLabel (taus_, taus);
794  
795 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
795 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
796      event.getByLabel (mets_, mets);
797  
798 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
798 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
799      event.getByLabel (tracks_, tracks);
800  
801 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
801 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
802      event.getByLabel (genjets_, genjets);
803  
804 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
805 <        event.getByLabel (mcparticles_, mcparticles);
440 <    
804 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
805 >    event.getByLabel (mcparticles_, mcparticles);
806  
807 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
807 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
808      event.getByLabel (primaryvertexs_, primaryvertexs);
809  
810 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
810 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
811      event.getByLabel (bxlumis_, bxlumis);
812  
813 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
813 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
814      event.getByLabel (photons_, photons);
815  
816 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
816 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
817      event.getByLabel (superclusters_, superclusters);
818  
819 +  if (datasetType_ == "signalMC"){
820 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
821 +      event.getByLabel (stops_, stops);
822 +  }
823  
824 <  //get pile-up event weight
825 <  double puScaleFactor = 1.00;
826 <  //  if(datasetType_ != "data"){
827 <  // puScaleFactor = puWeight_->at (events->at (0).numTruePV);
828 <    //    cout << puScaleFactor << endl;
829 <  //}
824 >  if (useTrackCaloRhoCorr_) {
825 >    // Used only for pile-up correction of by-hand calculation of isolation energy.
826 >    // This rho collection is not available in all BEANs.
827 >    // For description of rho values for different jet reconstruction algorithms, see
828 >    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
829 >    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
830 >  }
831 >
832 >  double masterScaleFactor = 1.0;
833  
834 +  //get pile-up event weight
835 +  if (doPileupReweighting_ && datasetType_ != "data") {
836 +    //for "data" datasets, the numTruePV is always set to -1
837 +    if (events->at(0).numTruePV < 0 && isFirstEvent_) clog << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
838 +    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
839 +  }
840  
841 +  stopCTauScaleFactor_ = 1.0;
842 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
843 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
844 +  masterScaleFactor *= stopCTauScaleFactor_;
845  
846    //loop over all channels
847  
848 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
849    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
850      channel currentChannel = channels.at(currentChannelIndex);
851 +    if (verbose_>1) clog << " Processing channel " << currentChannel.name << endl;
852  
853      flagMap individualFlags;
470    flagMap cumulativeFlags;
854      counterMap passingCounter;
855 +    cumulativeFlags.clear ();
856 +
857 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
858 +         iter != BNTreeBranchVals_.end(); iter++) {
859 +      iter->second.clear();  // clear array
860 +    }
861  
862      bool triggerDecision = true;
863 <    if(currentChannel.triggers.size() != 0){  //triggers specified
864 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
863 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
864 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
865        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
866      }
867  
868      //loop over all cuts
480
481
482
869      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
870        cut currentCut = currentChannel.cuts.at(currentCutIndex);
871 +      if (verbose_>2) clog << "  Processing cut, index: " << currentCutIndex << ", input collection: " << currentCut.inputCollection << ", name: " << currentCut.name << endl;  
872  
873 <      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
874 <        string currentObject = objectsToCut.at(currentObjectIndex);
488 <
489 <        //initialize maps to get ready to set cuts
490 <        individualFlags[currentObject].push_back (vector<bool> ());
491 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
492 <
493 <      }
494 <      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
495 <        string currentObject = objectsToCut.at(currentObjectIndex);
496 <
497 <        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
498 <
499 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
500 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
501 <        else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
502 <        else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
503 <        else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
504 <        else if(currentObject == "mets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
505 <        else if(currentObject == "tracks") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
506 <        else if(currentObject == "genjets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
507 <        else if(currentObject == "mcparticles") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
508 <        else if(currentObject == "primaryvertexs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
509 <        else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
510 <        else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
511 <        else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
512 <
513 <        
514 <        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
515 <                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
516 <                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
517 <                                                                   "muon-muon pairs");
518 <        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
519 <                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
520 <                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
521 <                                                                           "electron-electron pairs");
522 <        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
523 <                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
524 <                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
525 <                                                                       "electron-muon pairs");
873 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
874 >        string currentObject = objectsToFlag.at(currentObjectIndex);
875  
876 +        //initialize maps to get ready to set cuts
877 +        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
878 +        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
879  
880        }
881  
882 +      //set flags for all relevant objects
883 +      for(int currentObjectIndex = -1; currentObjectIndex != int(objectsToFlag.size()); currentObjectIndex++){
884 +        string currentObject;  
885 +        if (currentObjectIndex < 0) currentObject = currentCut.inputCollection;  // In the first loop, set the flags for the collection that the cut is acting on.  That way other paired collections can access the correct flag for the current cut.  
886 +        else currentObject = objectsToFlag.at(currentObjectIndex);
887 +        if (currentObjectIndex >= 0 && currentObject == currentCut.inputCollection) continue;  // Flags have already been set for the inputCollection object, so should not be set again.  
888 +
889 +        // single object collections
890 +        if     (currentObject == "jets")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
891 +        else if(currentObject == "secondary jets")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
892 +        else if(currentObject == "secondary photons")   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"secondary photons");
893 +        else if(currentObject == "muons")               setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
894 +        else if(currentObject == "secondary muons")     setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
895 +        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
896 +        else if(currentObject == "electrons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
897 +        else if(currentObject == "events")              setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
898 +        else if(currentObject == "taus")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
899 +        else if(currentObject == "mets")                setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),"mets");
900 +        else if(currentObject == "tracks")              setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),"tracks");
901 +        else if(currentObject == "genjets")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,genjets.product(),"genjets");
902 +        else if(currentObject == "mcparticles")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mcparticles.product(),"mcparticles");
903 +        else if(currentObject == "primaryvertexs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,primaryvertexs.product(),"primaryvertexs");
904 +        else if(currentObject == "bxlumis")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
905 +        else if(currentObject == "photons")             setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
906 +        else if(currentObject == "superclusters")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
907 +        else if(currentObject == "trigobjs")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
908 +
909 +
910 +        // paired object collections  
911 +        else if(currentObject == "muon-muon pairs")                   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), "muon-muon pairs");
912 +        else if(currentObject == "muon-secondary muon pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), "muon-secondary muon pairs");
913 +
914 +        else if(currentObject == "muon-secondary photon pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), "muon-secondary photon pairs");
915 +        else if(currentObject == "muon-secondary jet pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), "muon-secondary jet pairs");
916 +        else if(currentObject == "photon-secondary jet pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), "photon-secondary jet pairs");
917 +        else if(currentObject == "electron-secondary jet pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), "electron-secondary jet pairs");
918 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), "electron-secondary electron pairs");
919 +
920 +        else if(currentObject == "electron-electron pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), "electron-electron pairs");
921 +        else if(currentObject == "electron-muon pairs")     setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), "electron-muon pairs");
922 +        else if(currentObject == "jet-jet pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), "jet-jet pairs");
923 +        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), "jet-secondary jet pairs");
924 +        else if(currentObject == "electron-jet pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), "electron-jet pairs");
925 +        else if(currentObject == "electron-photon pairs")   setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), "electron-photon pairs");
926 +        else if(currentObject == "photon-jet pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), "photon-jet pairs");
927 +        else if(currentObject == "muon-jet pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), "muon-jet pairs");
928 +        else if(currentObject == "muon-event pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),events.product(), "muon-event pairs");
929 +        else if(currentObject == "met-jet pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),jets.product(), "met-jet pairs");
930 +        else if(currentObject == "track-jet pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),jets.product(), "track-jet pairs");
931 +        else if(currentObject == "muon-photon pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), "muon-photon pairs");
932 +        else if(currentObject == "track-event pairs")       setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(), "track-event pairs");
933 +        else if(currentObject == "electron-track pairs")    setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),"electron-track pairs");
934 +        else if(currentObject == "muon-track pairs")        setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),"muon-track pairs");
935 +        else if(currentObject == "muon-tau pairs")          setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),"muon-tau pairs");
936 +        else if(currentObject == "tau-tau pairs")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),"tau-tau pairs");
937 +        else if(currentObject == "tau-track pairs")         setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),"tau-track pairs");
938 +        else if(currentObject == "electron-trigobj pairs")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),"electron-trigobj pairs");
939 +        else if(currentObject == "muon-trigobj pairs")      setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),"muon-trigobj pairs");
940 +        else if(currentObject == "electron-mcparticle pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),mcparticles.product(),"electron-mcparticle pairs");
941  
942 +        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
943 +      }
944  
945      }//end loop over all cuts
946  
947  
535    //use cumulative flags to apply cuts at event level
948  
949 +    //use cumulative flags to apply cuts at event level
950 +    vector<bool> eventPassedPreviousCuts;    //a vector to store cumulative cut descisions after each cut.
951      bool eventPassedAllCuts = true;
952 <
539 <    //apply trigger (true if none were specified)
540 <    eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
541 <
542 <
952 >    eventPassedAllCuts = eventPassedAllCuts && triggerDecision;    //apply trigger (true if none were specified)
953  
954      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
955  
956        //loop over all objects and count how many passed the cumulative selection up to this point
957        cut currentCut = currentChannel.cuts.at(currentCutIndex);
958        int numberPassing = 0;
959 +      int numberPassingPrev = 0;  // number of objects that pass cuts up to the previous one
960  
961        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
962 <          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
962 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
963 >      }
964 >      bool cutDecision;
965 >      if (!currentCut.isVeto) {
966 >        cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
967 >      } else {
968 >        int prevCutIndex = currentCutIndex - 1;
969 >        if (prevCutIndex<0) {
970 >          numberPassingPrev = cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size();  // count all objects in collection if cut is the first
971 >        } else {
972 >          for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(prevCutIndex).size() ; object++){
973 >            if (cumulativeFlags.at(currentCut.inputCollection).at(prevCutIndex).at(object).first) {
974 >              numberPassingPrev++;
975 >              if (verbose_>1) clog << " object passed previous cut" << endl;  
976 >            }
977 >          }  
978 >        }  
979 >        int numberFailCut = numberPassingPrev - numberPassing;
980 >        cutDecision = evaluateComparison(numberFailCut,currentCut.eventComparativeOperator,currentCut.numberRequired);  
981        }
982  
554      bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
983        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
556
984        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
985 +      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
986 +      if (verbose_>1) clog << " Event passed cuts up to cut index " << currentCutIndex << endl;  
987  
988      }
989 +    //applying all appropriate scale factors
990 +    double scaleFactor = masterScaleFactor;
991 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
992 +
993 +    if(applyLeptonSF_ && datasetType_ != "data"){
994 +      //only apply SFs if we've cut on this object
995 +      if(find(objectsToCut.begin(),objectsToCut.end(),"muons") != objectsToCut.end ()){
996 +        flagPair muonFlags;
997 +        //get the last valid flags in the flag map
998 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
999 +          if (cumulativeFlags.at("muons").at(i).size()){
1000 +            muonFlags = cumulativeFlags.at("muons").at(i);
1001 +            break;
1002 +          }
1003 +        }
1004 +        //apply the weight for each of those objects
1005 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
1006 +          if(!muonFlags.at(muonIndex).second) continue;
1007 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
1008 +        }
1009 +      }
1010 +      //only apply SFs if we've cut on this object
1011 +      if(find(objectsToCut.begin(),objectsToCut.end(),"electrons") != objectsToCut.end ()){
1012 +        flagPair electronFlags;
1013 +        //get the last valid flags in the flag map
1014 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
1015 +          if (cumulativeFlags.at("electrons").at(i).size()){
1016 +            electronFlags = cumulativeFlags.at("electrons").at(i);
1017 +            break;
1018 +          }
1019 +        }
1020 +        //apply the weight for each of those objects
1021 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
1022 +          if(!electronFlags.at(electronIndex).second) continue;
1023 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
1024 +        }
1025 +      }
1026 +    }
1027 +    if(applyBtagSF_ && datasetType_ != "data"){
1028 +      //only apply SFs if we've cut on this object
1029 +      if(find(objectsToCut.begin(),objectsToCut.end(),"jets") != objectsToCut.end ()){
1030 +        flagPair jetFlags;
1031 +        vector<double> jetSFs;
1032 +        //get the last valid flags in the flag map
1033 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
1034 +          if (cumulativeFlags.at("jets").at(i).size()){
1035 +            jetFlags = cumulativeFlags.at("jets").at(i);
1036 +            break;
1037 +          }
1038 +        }
1039 +        //apply the weight for each of those objects
1040 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
1041 +          if(!jetFlags.at(jetIndex).second) continue;
1042 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour, jets->at(jetIndex).eta);
1043 +          jetSFs.push_back(jetSFTmp);
1044 +        }
1045 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_);
1046 +      }
1047 +    }
1048 +    scaleFactor *= muonScaleFactor_;
1049 +    scaleFactor *= electronScaleFactor_;
1050 +    scaleFactor *= bTagScaleFactor_;
1051 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
1052 +    if (verbose_>1) clog << " Scale factors applied:  "
1053 +                         << " muonScaleFactor_ = " << muonScaleFactor_
1054 +                         << ", electronScaleFactor_ = " << electronScaleFactor_
1055 +                         << ", bTagScaleFactor_ = " << bTagScaleFactor_
1056 +                         << ", total scale factor = " << scaleFactor
1057 +                         << endl;  
1058 +
1059 +
1060 +    if (printEventInfo_ && eventPassedAllCuts) {
1061 +      // Write information about event to screen, for testing purposes.
1062 +      clog << "Event passed all cuts in channel " <<  currentChannel.name
1063 +           << ":  run:lumi:evt=  "  << events->at(0).run
1064 +           << ":" << events->at(0).lumi
1065 +           << ":" << events->at(0).evt
1066 +           << endl;
1067 +      if (findEventsLog) {
1068 +        (*findEventsLog) << events->at(0).run
1069 +                         << ":" << events->at(0).lumi
1070 +                         << ":" << events->at(0).evt << endl;
1071 +      }
1072  
1073 <    cutFlows_.at(currentChannelIndex)->fillCutFlow(puScaleFactor);
1073 >    }
1074  
1075  
1076 +    //filling histograms
1077 +    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the cuts in each channel; if GetPlotsAfterEachCut_ is false, only the last cut will be used.
1078  
1079 <    if(!eventPassedAllCuts)continue;
1079 >      if (verbose_>2) clog << "  Filling histograms for currentcut = " << currentCut << endl;  
1080  
1081 +      uint currentDir;
1082 +      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
1083 +      else{
1084 +        currentDir = currentCut;
1085 +      }
1086  
568    
1087  
1088 <    //set position of primary vertex in event, in order to calculate quantities relative to it
571 <    if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
572 <      vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back();
573 <      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
574 <        if(!vertexFlags.at(vertexIndex)) continue;
575 <        chosenPrimaryVertex = & primaryvertexs->at(vertexIndex);
576 <        break;
577 <      }
578 <    }
579 <    else {
580 <      chosenPrimaryVertex = & primaryvertexs->at(0);
581 <    }
1088 >      if(eventPassedPreviousCuts.at(currentDir)){
1089  
1090 +        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1091 +          histogram currentHistogram = histograms.at(histogramIndex);
1092  
1093 +          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) clog << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
1094  
1095 <    //filling histograms
586 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
587 <      histogram currentHistogram = histograms.at(histogramIndex);
1095 >          if (verbose_>1) clog << " Filling histogram " << currentHistogram.name << " for collection " << currentHistogram.inputCollection << endl;  
1096  
1097 <      if(currentHistogram.inputVariables.size() == 1){
1098 <        TH1D* histo;
1099 <        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
1100 <
1101 <
1102 <
1103 <        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
1104 <        else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
1105 <        else if(currentHistogram.inputCollection == "muon-muon pairs")
1106 <          {
1107 <            fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1108 <                            cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
1109 <                            
1110 <                            cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
1111 <
1112 <          }
1113 <        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
1114 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
1115 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
1116 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
1117 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
1118 <                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
1119 <                                                                                              cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
1120 <        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
1121 <        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
1122 <        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
1123 <        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
1124 <        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
1125 <        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
1126 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
1127 <        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
1128 <        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
1129 <        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
1130 <      }
1131 <      else if(currentHistogram.inputVariables.size() == 2){
1132 <        TH2D* histo;
1133 <        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
1134 <
1135 <
1136 <
1137 <        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),puScaleFactor);
1138 <        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),puScaleFactor);
1139 <        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1140 <                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
1141 <                                                                                       cumulativeFlags.at("muon-muon pairs").back(),puScaleFactor);
1142 <        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),puScaleFactor);
1143 <        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1144 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
1145 <                                                                                               cumulativeFlags.at("electron-electron pairs").back(),puScaleFactor);
1146 <        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1147 <                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
1148 <                                                                                               cumulativeFlags.at("electron-muon pairs").back(),puScaleFactor);
1149 <        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),puScaleFactor);
1150 <        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),puScaleFactor);
1151 <        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),puScaleFactor);
1152 <        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),puScaleFactor);
1153 <        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),puScaleFactor);
1154 <        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),puScaleFactor);
1155 <        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),puScaleFactor);
1156 <        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),puScaleFactor);
1157 <        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),puScaleFactor);
1158 <        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),puScaleFactor);
1159 <      }
1160 <    }
1161 <
1162 <    //fills histograms with the sizes of collections
1163 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1164 <      string currentObject = objectsToPlot.at(currentObjectIndex);
1165 <
1166 <      string objectToPlot = "";
1167 <
1168 <      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
1169 <      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
1170 <      else if(currentObject == "electron-muon pairs") objectToPlot = "electronMuonPairs";
1171 <      else objectToPlot = currentObject;
1172 <      string tempCurrentObject = objectToPlot;
1173 <      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1174 <      string histoName = "num" + tempCurrentObject;
1175 <
1176 <
1177 <
1178 <
1179 <      //set position of primary vertex in event, in order to calculate quantities relative to it
1180 <      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1181 <        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
1182 <        int numToPlot = 0;
1183 <        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1184 <          if(lastCutFlags.at(currentFlag)) numToPlot++;
1185 <        }
1186 <        if(objectToPlot == "primaryvertexs"){
1187 <          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1188 <          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),puScaleFactor);
1189 <        }
1190 <        else
1191 <          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,puScaleFactor);        
1192 <      }
1193 <      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),puScaleFactor);
1194 <      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),puScaleFactor);
1195 <      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,puScaleFactor);
1196 <      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),puScaleFactor);
1197 <      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,puScaleFactor);
1198 <      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),puScaleFactor);
1199 <      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),puScaleFactor);
1200 <      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),puScaleFactor);
1201 <      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),puScaleFactor);
1202 <      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),puScaleFactor);
1203 <      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),puScaleFactor);
1204 <      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),puScaleFactor);
1205 <      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),puScaleFactor);
1206 <      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),puScaleFactor);
1207 <      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),puScaleFactor);
1208 <      else if(objectToPlot == "primaryvertexs"){
1209 <        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1210 <        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),puScaleFactor);
1211 <      }
1097 >          if(currentHistogram.inputVariables.size() == 1){
1098 >            TH1D* histo;
1099 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1100 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1101 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1102 >            else if(currentHistogram.inputCollection == "secondary photons")  fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1103 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1104 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1105 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1106 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1107 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1108 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1109 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1110 >             else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1111 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1112 >             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1113 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1114 >             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1115 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1116 >             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1117 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1118 >
1119 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1120 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1121 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1122 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1123 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1124 >             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1125 >                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1126 >
1127 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1128 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1129 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(),
1130 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1131 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(),
1132 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1133 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(),
1134 >                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1135 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(),
1136 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1137 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill1DHistogram(histo,currentHistogram, muons.product(),events.product(),
1138 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1139 >            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, mets.product(),jets.product(),
1140 >                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1141 >            else if(currentHistogram.inputCollection == "track-jet pairs")  fill1DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1142 >                                                                                          cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1143 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(),
1144 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1145 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(),
1146 >                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1147 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1148 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1149 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1150 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1151 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1152 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1153 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1154 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1155 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1156 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1157 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1158 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1159 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1160 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1161 >
1162 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1163 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1164 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1165 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1166 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1167 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1168 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1169 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1170 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1171 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1172 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1173 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1174 >          }
1175 >          else if(currentHistogram.inputVariables.size() == 2){
1176 >            TH2D* histo;
1177 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1178 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1179 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1180 >            else if(currentHistogram.inputCollection == "secondary photons")  fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1181 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1182 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1183 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1184 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1185 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(),
1186 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1187 >            else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1188 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1189 >            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1190 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1191 >            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1192 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1193 >            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1194 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1195 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1196 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1197 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1198 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1199 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(),
1200 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1201 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),
1202 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1203 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(),
1204 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1205 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(),
1206 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1207 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(),
1208 >                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1209 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(),
1210 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1211 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill2DHistogram(histo,currentHistogram,muons.product(),events.product(),
1212 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1213 >            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,mets.product(),jets.product(),
1214 >                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1215 >            else if(currentHistogram.inputCollection == "track-jet pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1216 >                                                                                         cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1217 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(),
1218 >                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1219 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(),
1220 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1221 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1222 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1223 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1224 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1225 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1226 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1227 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1228 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1229 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1230 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1231 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1232 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1233 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1234 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1235 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1236 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1237 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1238 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1239 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1240 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1241 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1242 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1243 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1244 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1245 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1246 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1247 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1248 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1249 >          }
1250 >
1251 >        }
1252 >
1253 >
1254 >        //fills histograms with the sizes of collections
1255 >        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1256 >
1257 >          string currentObject = objectsToPlot.at(currentObjectIndex);
1258 >          string objectToPlot = "";
1259 >
1260 >          if (verbose_) clog << "Filling histogram of number of selected objects in collection: " << currentObject << endl;  
1261 >
1262 >          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1263 >          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1264 >          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1265 >          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1266 >          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1267 >          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1268 >          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1269 >          else if(currentObject == "muon-event pairs")                   objectToPlot = "muonEventPairs";
1270 >          else if(currentObject == "muon-photon pairs")                  objectToPlot = "muonPhotonPairs";
1271 >          else if(currentObject == "photon-jet pairs")                   objectToPlot = "photonJetPairs";
1272 >          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1273 >          else if(currentObject == "track-jet pairs")                    objectToPlot = "trackJetPairs";
1274 >          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1275 >          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1276 >          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1277 >          else if(currentObject == "secondary photons")                  objectToPlot = "secondaryPhotons";
1278 >          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1279 >          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1280 >          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1281 >          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1282 >          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1283 >          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1284 >          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1285 >          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1286 >          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1287 >          else if(currentObject == "muon-secondary photon pairs")        objectToPlot = "muonSecondaryJetPairs";
1288 >          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1289 >          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1290 >          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1291 >          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1292 >          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1293 >          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1294 >          else if(currentObject == "electron-mcparticle pairs")          objectToPlot = "electronMCparticlePairs";
1295 >          else objectToPlot = currentObject;
1296 >
1297 >          string tempCurrentObject = objectToPlot;
1298 >          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1299 >          string histoName = "num" + tempCurrentObject;
1300 >
1301 >
1302 >          if(find(objectsToPlot.begin(), objectsToPlot.end(), currentObject) != objectsToPlot.end()) {
1303 >            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1304 >            int numToPlot = 0;
1305 >            for (uint iObj = 0; iObj != lastCutFlags.size(); iObj++){  // loop over all the objects  
1306 >              if(lastCutFlags.at(iObj).second) {
1307 >                numToPlot++;  
1308 >                if (verbose_>3) clog << "   Found object " << iObj << " in collection " << currentObject << " to plot." << endl;
1309 >              }
1310 >            }
1311 >
1312 >            if(objectToPlot == "primaryvertexs"){
1313 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1314 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1315 >            }
1316 >            else {
1317 >              if (printEventInfo_) clog << "Number of selected " << objectToPlot << " to plot:  " << numToPlot << endl;  
1318 >              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1319 >            }
1320 >          }
1321 >
1322 >        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1323 >
1324 >
1325 >      } // end if(eventPassedPreviousCuts.at(currentDir))
1326 >    } // end loop over cuts
1327  
1328 +    if (!useEDMFormat_ && eventPassedAllCuts){
1329 +      // Assign BNTree variables
1330 +      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1331 +        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1332 +        string coll = brSpecs.inputCollection;
1333 +        if (cumulativeFlags.count(coll) == 0) clog << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1334 +
1335 +        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1336 +        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1337 +        else if(coll == "secondary photons")      assignTreeBranch(brSpecs,photons.product(),          cumulativeFlags.at(coll).back());
1338 +        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1339 +        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1340 +        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1341 +        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1342 +        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1343 +        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1344 +        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1345 +        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1346 +        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1347 +        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1348 +        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1349 +        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1350 +        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1351 +        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1352 +        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1353 +        else if(coll == "stops"
1354 +                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1355 +      } // end loop over branches
1356 +      // set the evtLong, runInt, and lumiInt variables separately, since they are not type float  
1357 +      BNTreeBranchVals_evtLong_ = events->at(0).evt;
1358 +      BNTreeBranchVals_runInt_  = events->at(0).run;
1359 +      BNTreeBranchVals_lumiInt_ = events->at(0).lumi;
1360 +
1361 +      if (!BNTrees_.at(currentChannelIndex)) { clog << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1362 +      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1363      }
1364  
1365 +    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1366  
1367 +  } // end loop over channel
1368  
1369 +  masterCutFlow_->fillCutFlow(masterScaleFactor);
1370  
1371 <  } //end loop over channel
1371 >  event.put (channelDecisions, "channelDecisions");
1372  
1373 <  masterCutFlow_->fillCutFlow(puScaleFactor);
1373 >  isFirstEvent_ = false;  
1374  
1375 +  if (verbose_) clog << "Finished OSUAnalysis::produce." << endl;  
1376  
1377 + } // end void OSUAnalysis::produce (const edm::Event &event, const edm::EventSetup &setup)
1378  
716 }
1379  
1380  
1381   bool
# Line 727 | Line 1389 | OSUAnalysis::evaluateComparison (double
1389    else if(comparison == "==") return testValue == cutValue;
1390    else if(comparison == "=") return testValue == cutValue;
1391    else if(comparison == "!=") return testValue != cutValue;
1392 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1392 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1393 >
1394 > }
1395 >
1396 > bool
1397 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1398 >
1399 >
1400 >  if(comparison == ">")       return testValue >  cutValue;
1401 >  else if(comparison == ">=") return testValue >= cutValue;
1402 >  else if(comparison == "<")  return testValue <  cutValue;
1403 >  else if(comparison == "<=") return testValue <= cutValue;
1404 >  else if(comparison == "==") return testValue == cutValue;
1405 >  else if(comparison == "=")  return testValue == cutValue;
1406 >  else if(comparison == "!=") return testValue != cutValue;
1407 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1408  
1409   }
1410  
1411   bool
1412 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1412 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1413  
1414 +  //initialize to false until a chosen trigger is passed
1415    bool triggerDecision = false;
1416  
1417 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1418 <    {
1419 <      if(trigger->pass != 1) continue;
1420 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1421 <        {
1422 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1423 <            triggerDecision = true;
1424 <          }
1425 <        }
1417 >  if (printAllTriggers_) clog << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1418 >  //loop over all triggers defined in the event
1419 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1420 >
1421 >    if (printAllTriggers_) clog << "   " << trigger->name << endl;
1422 >
1423 >    //we're only interested in triggers that actually passed
1424 >    if(trigger->pass != 1) continue;
1425 >
1426 >    //if the event passes one of the veto triggers, exit and return false
1427 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1428 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1429 >    }
1430 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1431 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1432 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1433      }
1434 <  return triggerDecision;
1434 >  }
1435  
1436 +  printAllTriggers_ = false;  // only print triggers once, not every event
1437 +
1438 +  //if none of the veto triggers fired:
1439 +  //return the OR of all the chosen triggers
1440 +  if (triggersToTest.size() != 0) return triggerDecision;
1441 +  //or if no triggers were defined return true
1442 +  else return true;
1443   }
1444  
1445 < std::vector<std::string>
1445 >
1446 > vector<string>
1447   OSUAnalysis::splitString (string inputString){
1448  
1449 <  std::stringstream stringStream(inputString);
1450 <  std::istream_iterator<std::string> begin(stringStream);
1451 <  std::istream_iterator<std::string> end;
1452 <  std::vector<std::string> stringVector(begin, end);
1449 >  stringstream stringStream(inputString);
1450 >  istream_iterator<string> begin(stringStream);
1451 >  istream_iterator<string> end;
1452 >  vector<string> stringVector(begin, end);
1453    return stringVector;
1454  
1455   }
1456  
1457 +
1458 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1459 +  // Set two object strings from the tempInputCollection string,
1460 +  // For example, if tempInputCollection is "electron-muon pairs",
1461 +  // then obj1 = "electrons" and obj2 = "muons".
1462 +  // Note that the objects have an "s" appended.
1463 +
1464 +  int dashIndex = tempInputCollection.find("-");
1465 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1466 +  int secondWordLength = spaceIndex - dashIndex;
1467 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1468 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1469 +
1470 + }
1471 +
1472 +
1473 + string OSUAnalysis::getObjToGet(string obj) {
1474 +  // Return the string corresponding to the object to get for the given obj string.
1475 +  // Right now this only handles the case in which obj contains "secondary",
1476 +  // e.g, "secondary muons".
1477 +  // Note that "s" is NOT appended.
1478 +
1479 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1480 +  int firstSpaceIndex = obj.find_first_of(" ");
1481 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1482 +
1483 + }
1484 +
1485 +
1486 + //!jet valueLookup
1487   double
1488 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1488 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1489  
1490    double value = 0.0;
1491    if(variable == "energy") value = object->energy;
# Line 881 | Line 1604 | OSUAnalysis::valueLookup (const BNjet* o
1604    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1605    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1606  
1607 +  //user defined variable
1608 +  else if(variable == "disappTrkLeadingJetID") {
1609 +    value = object->pt > 110
1610 +      && fabs(object->eta) < 2.4
1611 +      && object->chargedHadronEnergyFraction > 0.2
1612 +      && object->neutralHadronEnergyFraction < 0.7
1613 +      && object->chargedEmEnergyFraction < 0.5
1614 +      && object->neutralEmEnergyFraction < 0.7;
1615 +  }
1616  
1617 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1617 >  else if(variable == "disappTrkSubLeadingJetID") {
1618 >    value = object->pt > 30
1619 >      && fabs(object->eta) < 4.5
1620 >      && object->neutralHadronEnergyFraction < 0.7
1621 >      && object->chargedEmEnergyFraction < 0.5;
1622 >  }
1623 >
1624 >  else if(variable == "dPhiMet") {
1625 >    if (const BNmet *met = chosenMET ()) {
1626 >      value = deltaPhi (object->phi, met->phi);
1627 >    } else value = -999;
1628 >  }
1629 >
1630 >
1631 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1632  
1633    value = applyFunction(function, value);
1634  
1635    return value;
1636 < }
891 <
1636 > } // end jet valueLookup
1637  
1638  
1639 + //!muon valueLookup
1640   double
1641 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1641 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1642  
1643    double value = 0.0;
1644    if(variable == "energy") value = object->energy;
# Line 984 | Line 1730 | OSUAnalysis::valueLookup (const BNmuon*
1730    else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1731    else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1732    else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1733 +  else if(variable == "chargedHadronIsoDR04") value = object->chargedHadronIsoDR04;
1734 +  else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1735 +  else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1736 +  else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1737    else if(variable == "rhoPrime") value = object->rhoPrime;
1738    else if(variable == "AEffDr03") value = object->AEffDr03;
1739    else if(variable == "AEffDr04") value = object->AEffDr04;
# Line 991 | Line 1741 | OSUAnalysis::valueLookup (const BNmuon*
1741    else if(variable == "pfIsoR03SumNeutralHadronEt") value = object->pfIsoR03SumNeutralHadronEt;
1742    else if(variable == "pfIsoR03SumPhotonEt") value = object->pfIsoR03SumPhotonEt;
1743    else if(variable == "pfIsoR03SumPUPt") value = object->pfIsoR03SumPUPt;
1744 +  else if(variable == "relpfIsoR04SumExceptChargedHad") value = (object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)/ object->pt;
1745 +  else if(variable == "relpfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt/object->pt;
1746 +  else if(variable == "relpfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt/object->pt;
1747 +  else if(variable == "relpfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt/object->pt;
1748 +  else if(variable == "relpfIsoR04SumPUPt") value = object->pfIsoR04SumPUPt/object->pt;
1749    else if(variable == "pfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt;
1750    else if(variable == "pfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt;
1751    else if(variable == "pfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt;
# Line 1047 | Line 1802 | OSUAnalysis::valueLookup (const BNmuon*
1802    else if(variable == "time_ndof") value = object->time_ndof;
1803  
1804    //user-defined variables
1805 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenPrimaryVertex->xError, chosenPrimaryVertex->yError));
1806 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenPrimaryVertex->xError, chosenPrimaryVertex->yError));
1805 >  else if(variable == "looseID") {
1806 >    value = object->pt > 10 &&
1807 >      (object->isGlobalMuon  > 0 ||
1808 >       object->isTrackerMuon > 0);
1809 >  }
1810 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1811 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1812    else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1813 <  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1813 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1814 >  else if(variable == "relPFdBetaIsoPseudo") value = (object->pfIsoR04SumChargedHadronPt + object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt) / object->pt;
1815    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1816 +  else if(variable == "metMT") {
1817 +    if (const BNmet *met = chosenMET ())
1818 +      {
1819 +        double dPhi = deltaPhi (object->phi, met->phi);
1820 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1821 +      }
1822 +    else
1823 +      value = -999;
1824 +  }
1825  
1826  
1827  
# Line 1162 | Line 1932 | OSUAnalysis::valueLookup (const BNmuon*
1932  
1933  
1934    else if(variable == "tightID") {
1935 <    value = object->isGlobalMuon > 0            \
1936 <      && object->isPFMuon > 0                   \
1937 <      && object->normalizedChi2 < 10            \
1938 <      && object->numberOfValidMuonHits > 0      \
1939 <      && object->numberOfMatchedStations > 1    \
1940 <      && fabs(object->correctedD0Vertex) < 0.2  \
1941 <      && fabs(object->correctedDZ) < 0.5        \
1942 <      && object->numberOfValidPixelHits > 0             \
1935 >    value = object->isGlobalMuon > 0                \
1936 >      && object->isPFMuon > 0                        \
1937 >      && object->normalizedChi2 < 10                \
1938 >      && object->numberOfValidMuonHits > 0        \
1939 >      && object->numberOfMatchedStations > 1        \
1940 >      && fabs(object->correctedD0Vertex) < 0.2        \
1941 >      && fabs(object->correctedDZ) < 0.5        \
1942 >      && object->numberOfValidPixelHits > 0                \
1943        && object->numberOfLayersWithMeasurement > 5;
1944    }
1945    else if(variable == "tightIDdisplaced"){
1946 <    value = object->isGlobalMuon > 0            \
1947 <      && object->normalizedChi2 < 10            \
1948 <      && object->numberOfValidMuonHits > 0      \
1949 <      && object->numberOfMatchedStations > 1    \
1950 <      && object->numberOfValidPixelHits > 0     \
1946 >    value = object->isGlobalMuon > 0                \
1947 >      && object->isPFMuon > 0                        \
1948 >      && object->normalizedChi2 < 10                \
1949 >      && object->numberOfValidMuonHits > 0        \
1950 >      && object->numberOfMatchedStations > 1        \
1951 >      && object->numberOfValidPixelHits > 0        \
1952        && object->numberOfLayersWithMeasurement > 5;
1953    }
1954  
1955 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1956  
1957 +  else if(variable == "genMatchedPdgId"){
1958 +    int index = getGenMatchedParticleIndex(object);
1959 +    if(index == -1) value = 0;
1960 +    else value = mcparticles->at(index).id;
1961 +  }
1962  
1963    else if(variable == "genMatchedId"){
1964      int index = getGenMatchedParticleIndex(object);
# Line 1193 | Line 1970 | OSUAnalysis::valueLookup (const BNmuon*
1970      if(index == -1) value = 0;
1971      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1972    }
1973 +  else if(variable == "genMatchedMotherIdReverse"){
1974 +    int index = getGenMatchedParticleIndex(object);
1975 +    if(index == -1) value = 24;
1976 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1977 +  }
1978    else if(variable == "genMatchedGrandmotherId"){
1979      int index = getGenMatchedParticleIndex(object);
1980      if(index == -1) value = 0;
# Line 1203 | Line 1985 | OSUAnalysis::valueLookup (const BNmuon*
1985      }
1986      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1987    }
1988 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1989 +    int index = getGenMatchedParticleIndex(object);
1990 +    if(index == -1) value = 24;
1991 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1992 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1993 +      if(motherIndex == -1) value = 24;
1994 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1995 +    }
1996 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1997 +  }
1998 +  else if(variable == "pfMuonsFromVertex"){
1999 +    double d0Error, dzError;
2000 +
2001 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2002 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2003 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2004 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2005 +      || fabs (object->correctedDZ / dzError) > 99.0;
2006 +    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
2007 +  }
2008  
2009  
2010  
2011 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2011 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2012  
2013    value = applyFunction(function, value);
2014  
2015    return value;
2016 < }
2016 > } // end muon valueLookup
2017  
2018  
2019 + //!electron valueLookup
2020   double
2021 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
2021 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
2022  
2023    double value = 0.0;
2024    if(variable == "energy") value = object->energy;
# Line 1376 | Line 2179 | OSUAnalysis::valueLookup (const BNelectr
2179    else if(variable == "passConvVeto") value = object->passConvVeto;
2180  
2181    //user-defined variables
2182 <  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenPrimaryVertex->xError, chosenPrimaryVertex->yError));
2183 <  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenPrimaryVertex->xError, chosenPrimaryVertex->yError));
2182 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2183 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2184    else if(variable == "detIso") value = (object->trackIso) / object->pt;
2185    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2186 <
2186 >  else if(variable == "relPFrhoIsoEB") value = object->isEB ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2187 >  else if(variable == "relPFrhoIsoEE") value = object->isEE ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2188 >  else if(variable == "metMT") {
2189 >    if (const BNmet *met = chosenMET ())
2190 >      {
2191 >        double dPhi = deltaPhi (object->phi, met->phi);
2192 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2193 >      }
2194 >    else
2195 >      value = -999;
2196 >  }
2197  
2198    else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
2199      if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
# Line 1391 | Line 2204 | OSUAnalysis::valueLookup (const BNelectr
2204      else value = -999;
2205    }
2206  
1394
2207    else if(variable == "correctedD0VertexInEBPlus"){
2208      if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
2209      else value = -999;
# Line 1444 | Line 2256 | OSUAnalysis::valueLookup (const BNelectr
2256      else value = -999;
2257    }
2258  
2259 +  else if(variable == "looseID"){
2260 +    if (object->isEB)
2261 +      {
2262 +        value = fabs(object->delEtaIn) < 0.007 \
2263 +          && fabs (object->delPhiIn) < 0.15 \
2264 +          && object->scSigmaIEtaIEta < 0.01 \
2265 +          && object->hadOverEm < 0.12 \
2266 +          && fabs (object->correctedD0Vertex) < 0.02 \
2267 +          && fabs (object->correctedDZ) < 0.2 \
2268 +          && object->absInvEMinusInvPin < 0.05 \
2269 +          && object->passConvVeto;
2270 +      }
2271 +    else
2272 +      {
2273 +        value = fabs(object->delEtaIn) < 0.009 \
2274 +          && fabs (object->delPhiIn) < 0.10 \
2275 +          && object->scSigmaIEtaIEta < 0.03 \
2276 +          && object->hadOverEm < 0.10 \
2277 +          && fabs (object->correctedD0Vertex) < 0.02 \
2278 +          && fabs (object->correctedDZ) < 0.2 \
2279 +          && object->absInvEMinusInvPin < 0.05 \
2280 +          && object->passConvVeto;
2281 +      }
2282 +  }
2283  
2284 +  else if(variable == "tightID"){
2285 +    if (object->isEB)
2286 +      {
2287 +        value = fabs(object->delEtaIn) < 0.004 \
2288 +          && fabs (object->delPhiIn) < 0.03 \
2289 +          && object->scSigmaIEtaIEta < 0.01 \
2290 +          && object->hadOverEm < 0.12 \
2291 +          && fabs (object->correctedD0Vertex) < 0.02 \
2292 +          && fabs (object->correctedDZ) < 0.1 \
2293 +          && object->absInvEMinusInvPin < 0.05 \
2294 +          && object->passConvVeto;
2295 +      }
2296 +    else
2297 +      {
2298 +        value = fabs(object->delEtaIn) < 0.005 \
2299 +          && fabs (object->delPhiIn) < 0.02 \
2300 +          && object->scSigmaIEtaIEta < 0.03 \
2301 +          && object->hadOverEm < 0.10 \
2302 +          && fabs (object->correctedD0Vertex) < 0.02 \
2303 +          && fabs (object->correctedDZ) < 0.1 \
2304 +          && object->absInvEMinusInvPin < 0.05 \
2305 +          && object->passConvVeto;
2306 +      }
2307 +  }
2308 +
2309 +  else if(variable == "looseID_MVA"){
2310 +    value = object->pt > 10
2311 +      && object->mvaNonTrigV0 > 0;
2312 +      }
2313    else if(variable == "correctedD0VertexInEBPositiveCharge"){
2314      if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2315      else value = -999;
# Line 1501 | Line 2366 | OSUAnalysis::valueLookup (const BNelectr
2366    else if(variable == "tightIDdisplaced"){
2367      if (object->isEB)
2368        {
2369 <        value = fabs(object->delEtaIn) < 0.004 \
2370 <          && fabs (object->delPhiIn) < 0.03 \
2369 >        value = fabs(object->delEtaIn) < 0.004 \
2370 >          && fabs (object->delPhiIn) < 0.03 \
2371            && object->scSigmaIEtaIEta < 0.01 \
2372            && object->hadOverEm < 0.12 \
2373 <          && object->absInvEMinusInvPin < 0.05;
2373 >          && object->absInvEMinusInvPin < 0.05;
2374        }
2375      else
2376        {
2377 <        value = fabs (object->delEtaIn) < 0.005 \
2378 <          && fabs (object->delPhiIn) < 0.02 \
2377 >        value = fabs (object->delEtaIn) < 0.005 \
2378 >          && fabs (object->delPhiIn) < 0.02 \
2379            && object->scSigmaIEtaIEta < 0.03 \
2380            && object->hadOverEm < 0.10 \
2381 <          && object->absInvEMinusInvPin < 0.05;
2381 >          && object->absInvEMinusInvPin < 0.05;
2382        }
2383    }
2384  
2385 +
2386 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2387 +
2388 +  else if(variable == "genMatchedPdgId"){
2389 +    int index = getGenMatchedParticleIndex(object);
2390 +    if(index == -1) value = 0;
2391 +    else value = mcparticles->at(index).id;
2392 +  }
2393 +
2394 +
2395    else if(variable == "genMatchedId"){
2396      int index = getGenMatchedParticleIndex(object);
2397      if(index == -1) value = 0;
# Line 1527 | Line 2402 | OSUAnalysis::valueLookup (const BNelectr
2402      if(index == -1) value = 0;
2403      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2404    }
2405 +  else if(variable == "genMatchedMotherIdReverse"){
2406 +    int index = getGenMatchedParticleIndex(object);
2407 +    if(index == -1) value = 24;
2408 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2409 +  }
2410    else if(variable == "genMatchedGrandmotherId"){
2411      int index = getGenMatchedParticleIndex(object);
2412      if(index == -1) value = 0;
# Line 1537 | Line 2417 | OSUAnalysis::valueLookup (const BNelectr
2417      }
2418      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2419    }
2420 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2421 +    int index = getGenMatchedParticleIndex(object);
2422 +    if(index == -1) value = 24;
2423 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2424 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2425 +      if(motherIndex == -1) value = 24;
2426 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2427 +    }
2428 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2429 +  }
2430 +  else if(variable == "pfElectronsFromVertex"){
2431 +    double d0Error, dzError;
2432 +
2433 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2434 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2435 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2436 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2437 +      || fabs (object->correctedDZ / dzError) > 99.0;
2438 +    value = !value;
2439 +  }
2440  
2441  
2442  
2443 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2443 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2444  
2445    value = applyFunction(function, value);
2446  
2447    return value;
2448 < }
2448 > } // end electron valueLookup
2449  
2450  
2451 + //!event valueLookup
2452   double
2453 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2453 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2454  
2455    double value = 0.0;
2456  
# Line 1617 | Line 2518 | OSUAnalysis::valueLookup (const BNevent*
2518    else if(variable == "id1") value = object->id1;
2519    else if(variable == "id2") value = object->id2;
2520    else if(variable == "evt") value = object->evt;
2521 <
2522 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2521 >  else if(variable == "puScaleFactor"){
2522 >    if(doPileupReweighting_ && datasetType_ != "data")
2523 >      value = puWeight_->at (events->at (0).numTruePV);
2524 >    else
2525 >      value = 1.0;
2526 >  }
2527 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2528 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2529 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2530 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2531 >
2532 >  else if(variable == "unfilteredHt") value = getHt(jets.product());
2533 >  else if(variable == "ht") value = chosenHT ();
2534 >
2535 >  else if(variable == "leadMuPairInvMass"){
2536 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2537 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2538 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2539 >    value = (p0 + p1).M ();
2540 >  }
2541 >  else if(variable == "leadMuPairPt"){
2542 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2543 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2544 >             pt1 (muPair.second->px, muPair.second->py);
2545 >    pt0 += pt1;
2546 >    value = pt0.Mod ();
2547 >  }
2548 >  else if(variable == "leadElPairInvMass"){
2549 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2550 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2551 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2552 >    value = (p0 + p1).M ();
2553 >  }
2554 >  else if(variable == "leadElPairPt"){
2555 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2556 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2557 >             pt1 (muPair.second->px, muPair.second->py);
2558 >    pt0 += pt1;
2559 >    value = pt0.Mod ();
2560 >  }
2561 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2562  
2563    value = applyFunction(function, value);
2564  
2565    return value;
2566 < }
2566 > } // end event valueLookup
2567 >
2568  
2569 + //!tau valueLookup
2570   double
2571 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2571 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2572  
2573    double value = 0.0;
2574  
# Line 1670 | Line 2612 | OSUAnalysis::valueLookup (const BNtau* o
2612    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2613    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2614  
2615 +  else if (variable == "looseHadronicID") {
2616 +    value = object->pt > 10
2617 +      && object->eta < 2.3
2618 +      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2619 +      && object->HPSdecayModeFinding > 0
2620 +      && object->HPSagainstElectronLoose > 0
2621 +      && object->HPSagainstMuonTight > 0;
2622 +  }
2623 +
2624 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2625 +
2626 +  else if(variable == "genMatchedPdgId"){
2627 +    int index = getGenMatchedParticleIndex(object);
2628 +    if(index == -1) value = 0;
2629 +    else value = mcparticles->at(index).id;
2630 +  }
2631  
2632    else if(variable == "genMatchedId"){
2633      int index = getGenMatchedParticleIndex(object);
# Line 1681 | Line 2639 | OSUAnalysis::valueLookup (const BNtau* o
2639      if(index == -1) value = 0;
2640      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2641    }
2642 +  else if(variable == "genMatchedMotherIdReverse"){
2643 +    int index = getGenMatchedParticleIndex(object);
2644 +    if(index == -1) value = 24;
2645 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2646 +  }
2647    else if(variable == "genMatchedGrandmotherId"){
2648      int index = getGenMatchedParticleIndex(object);
2649      if(index == -1) value = 0;
# Line 1691 | Line 2654 | OSUAnalysis::valueLookup (const BNtau* o
2654      }
2655      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2656    }
2657 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2658 +    int index = getGenMatchedParticleIndex(object);
2659 +    if(index == -1) value = 24;
2660 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2661 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2662 +      if(motherIndex == -1) value = 24;
2663 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2664 +    }
2665 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2666 +  }
2667  
2668  
2669 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2669 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2670  
2671    value = applyFunction(function, value);
2672  
2673    return value;
2674 < }
2674 > } // end tau valueLookup
2675  
2676 +
2677 + //!met valueLookup
2678   double
2679 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2679 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2680  
2681    double value = 0.0;
2682  
# Line 1765 | Line 2740 | OSUAnalysis::valueLookup (const BNmet* o
2740    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2741    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2742  
2743 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2743 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2744  
2745    value = applyFunction(function, value);
2746  
2747    return value;
2748 < }
2748 > } // end met valueLookup
2749  
2750 +
2751 + //!track valueLookup
2752   double
2753 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2753 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2754  
2755    double value = 0.0;
2756    double pMag = sqrt(object->pt * object->pt +
2757 <                         object->pz * object->pz);
2758 <  
2757 >                     object->pz * object->pz);
2758 >
2759    if(variable == "pt") value = object->pt;
2760    else if(variable == "px") value = object->px;
2761    else if(variable == "py") value = object->py;
# Line 1797 | Line 2774 | OSUAnalysis::valueLookup (const BNtrack*
2774    else if(variable == "numValidHits") value = object->numValidHits;
2775    else if(variable == "isHighPurity") value = object->isHighPurity;
2776  
2777 <
2778 <  //additional BNs info for disappTrks  
2779 <  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2780 <  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2781 <  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2782 <  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2783 <  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2784 <  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2785 <  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
1809 <  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
1810 <  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2777 >  //additional BNs info for disappTrks
2778 >  else if(variable == "caloEMDeltaRp3")     value = object->caloEMDeltaRp3;
2779 >  else if(variable == "caloHadDeltaRp3")    value = object->caloHadDeltaRp3;
2780 >  else if(variable == "caloEMDeltaRp4")     value = object->caloEMDeltaRp4;
2781 >  else if(variable == "caloHadDeltaRp4")    value = object->caloHadDeltaRp4;
2782 >  else if(variable == "caloEMDeltaRp5")     value = object->caloEMDeltaRp5;
2783 >  else if(variable == "caloHadDeltaRp5")    value = object->caloHadDeltaRp5;
2784 >  else if(variable == "nHitsMissingOuter")  value = object->nHitsMissingOuter;
2785 >  else if(variable == "nHitsMissingInner")  value = object->nHitsMissingInner;
2786    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2787 +  else if(variable == "depTrkRp3")          value = object->depTrkRp3;
2788 +  else if(variable == "trkRelIsoRp3")     { value = (object->depTrkRp3 - object->pt) / object->pt; if (value<0) value = 0; }
2789 +  else if(variable == "trkRelIsoRp5")     { value = (object->depTrkRp5 - object->pt) / object->pt; if (value<0) value = 0; }
2790 +  else if(variable == "depEcalRp3")         value = object->depEcalRp3;
2791 +  else if(variable == "depHcalRp3")         value = object->depHcalRp3;
2792 +  else if(variable == "depHoRp3")           value = object->depHoRp3;
2793 +  else if(variable == "nTracksRp3")         value = object->nTracksRp3;
2794 +  else if(variable == "trackerVetoPtRp3")   value = object->trackerVetoPtRp3;
2795 +  else if(variable == "emVetoEtRp3")        value = object->emVetoEtRp3;
2796 +  else if(variable == "hadVetoEtRp3")       value = object->hadVetoEtRp3;
2797 +  else if(variable == "hoVetoEtRp3")        value = object->hoVetoEtRp3;
2798 +  else if(variable == "depTrkRp5")          value = object->depTrkRp5;
2799 +  else if(variable == "depEcalRp5")         value = object->depEcalRp5;
2800 +  else if(variable == "depHcalRp5")         value = object->depHcalRp5;
2801 +  else if(variable == "depHoRp5")           value = object->depHoRp5;
2802 +  else if(variable == "nTracksRp5")         value = object->nTracksRp5;
2803 +  else if(variable == "trackerVetoPtRp5")   value = object->trackerVetoPtRp5;
2804 +  else if(variable == "emVetoEtRp5")        value = object->emVetoEtRp5;
2805 +  else if(variable == "hadVetoEtRp5")       value = object->hadVetoEtRp5;
2806 +  else if(variable == "hoVetoEtRp5")        value = object->hoVetoEtRp5;
2807 +
2808    //user defined variables
2809    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;
2810    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2811 <  else if(variable == "caloTotDeltaRp5") value =(object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2812 <  else if(variable == "caloTotDeltaRp5ByP") value =( (object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2813 <  else if(variable == "isIso") value = getTrkIsIso(object, tracks.product());
2814 <  else if(variable == "isMatchedDeadEcal") value = getTrkIsMatchedDeadEcal(object);
2815 <  else if(variable == "ptErrorByPt") value = (object->ptError/object->pt);
2816 <  else if(variable == "ptError") value = object->ptError;
2817 <  else if(variable == "ptRes") value = getTrkPtRes(object);  
2811 >  else if(variable == "depTrkRp5MinusPt"){
2812 >    if ( (object->depTrkRp5 - object->pt) < 0 ) {
2813 > //       clog << "Warning:  found track with depTrkRp5 < pt:  depTrkRp5=" << object->depTrkRp5
2814 > //         << "; pt=" << object->pt
2815 > //         << "; object->depTrkRp5 - object->pt = " << object->depTrkRp5 - object->pt
2816 > //         << endl;  
2817 >           value = 0;
2818 >         }
2819 >         else value =  (object->depTrkRp5 - object->pt);
2820 >  }
2821 >  else if(variable == "depTrkRp3MinusPt"){
2822 >    if ( (object->depTrkRp3 - object->pt) < 0 ) {
2823 >      value = 0;
2824 >    }
2825 >    else value =  (object->depTrkRp3 - object->pt);
2826 >  }
2827 >
2828 >  else if(variable == "dPhiMet") {
2829 >    if (const BNmet *met = chosenMET ()) {
2830 >      value = deltaPhi (object->phi, met->phi);
2831 >    } else value = -999;
2832 >  }
2833 >  
2834 >  
2835 >  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2836 >  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2837 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2838 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2839 >  else if(variable == "depTrkRp5RhoCorr")           value = getTrkDepTrkRp5RhoCorr(object);
2840 >  else if(variable == "depTrkRp3RhoCorr")           value = getTrkDepTrkRp3RhoCorr(object);
2841 >
2842 >  else if(variable == "depTrkRp5MinusPtRhoCorr")    {
2843 >    if ( (getTrkDepTrkRp5RhoCorr(object) - object->pt) < 0 ) value = 0;
2844 >    else {value = (getTrkDepTrkRp5RhoCorr(object) - object->pt );}
2845 >  }
2846 >  
2847 >  else if(variable == "depTrkRp3MinusPtRhoCorr")    
2848 >    {
2849 >      if ( (getTrkDepTrkRp3RhoCorr(object) - object->pt) < 0 ) value = 0;
2850 >      else {value = (getTrkDepTrkRp3RhoCorr(object) - object->pt );}
2851 >    }
2852 >
2853 >  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2854 >  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2855 >  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2856 >  else if(variable == "ptError")                    value = object->ptError;
2857 >  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2858 >  else if (variable == "d0wrtPV"){
2859 >    double vx = object->vx - chosenVertex ()->x,
2860 >      vy = object->vy - chosenVertex ()->y,
2861 >      px = object->px,
2862 >      py = object->py,
2863 >      pt = object->pt;
2864 >    value = (-vx * py + vy * px) / pt;
2865 >  }
2866 >  else if (variable == "dZwrtPV"){
2867 >    double vx = object->vx - chosenVertex ()->x,
2868 >      vy = object->vy - chosenVertex ()->y,
2869 >      vz = object->vz - chosenVertex ()->z,
2870 >      px = object->px,
2871 >      py = object->py,
2872 >      pz = object->pz,
2873 >      pt = object->pt;
2874 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2875 >  }
2876 >
2877 >  else if(variable == "deltaRMinSubLeadJet") {
2878 >    // calculate minimum deltaR between track and any other subleading jet  
2879 >    double trkJetDeltaRMin = 99.;  
2880 >    for (uint ijet = 0; ijet<jets->size(); ijet++) {
2881 >      string empty = "";  
2882 >      double isSubLeadingJet = valueLookup(&jets->at(ijet), "disappTrkSubLeadingJetID", "", empty);  
2883 >      if (!isSubLeadingJet) continue;  // only consider jets that pass the subleading jet ID criteria  
2884 >      double jetEta = valueLookup(&jets->at(ijet), "eta", "", empty);
2885 >      double jetPhi = valueLookup(&jets->at(ijet), "phi", "", empty);
2886 >      double trkJetDeltaR = deltaR(object->eta, object->phi, jetEta, jetPhi);  
2887 >      if (trkJetDeltaR < trkJetDeltaRMin) trkJetDeltaRMin = trkJetDeltaR;
2888 >    }
2889 >    value = trkJetDeltaRMin;  
2890 >  }  
2891 >  
2892 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2893 >
2894 >  else if(variable == "genMatchedPdgId"){
2895 >    int index = getGenMatchedParticleIndex(object);
2896 >    if(index == -1) value = 0;
2897 >    else value = mcparticles->at(index).id;
2898 >  }
2899  
2900  
2901    else if(variable == "genMatchedId"){
# Line 1831 | Line 2908 | OSUAnalysis::valueLookup (const BNtrack*
2908      if(index == -1) value = 0;
2909      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2910    }
2911 +  else if(variable == "genMatchedMotherIdReverse"){
2912 +    int index = getGenMatchedParticleIndex(object);
2913 +    if(index == -1) value = 24;
2914 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2915 +  }
2916    else if(variable == "genMatchedGrandmotherId"){
2917      int index = getGenMatchedParticleIndex(object);
2918      if(index == -1) value = 0;
# Line 1841 | Line 2923 | OSUAnalysis::valueLookup (const BNtrack*
2923      }
2924      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2925    }
2926 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2927 +    int index = getGenMatchedParticleIndex(object);
2928 +    if(index == -1) value = 24;
2929 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2930 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2931 +      if(motherIndex == -1) value = 24;
2932 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2933 +    }
2934 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2935 +  }
2936  
2937  
2938  
2939 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2939 >  else{clog << "WARNING: invalid variable '" << variable << "' for BNtrack collection.\n"; value = -999;}
2940  
2941    value = applyFunction(function, value);
2942  
2943    return value;
2944 < }
2944 > } // end track valueLookup
2945 >
2946  
2947 + //!genjet valueLookup
2948   double
2949 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2949 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2950  
2951    double value = 0.0;
2952  
# Line 1872 | Line 2966 | OSUAnalysis::valueLookup (const BNgenjet
2966    else if(variable == "charge") value = object->charge;
2967  
2968  
2969 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2969 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2970  
2971    value = applyFunction(function, value);
2972  
2973    return value;
2974   }
2975  
2976 + //!mcparticle valueLookup
2977   double
2978 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2978 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2979  
2980    double value = 0.0;
2981  
# Line 1971 | Line 3066 | OSUAnalysis::valueLookup (const BNmcpart
3066  
3067    //user-defined variables
3068    else if (variable == "d0"){
3069 <    double vx = object->vx - chosenPrimaryVertex->x,
3070 <      vy = object->vy - chosenPrimaryVertex->y,
3069 >    double vx = object->vx - chosenVertex ()->x,
3070 >      vy = object->vy - chosenVertex ()->y,
3071        px = object->px,
3072        py = object->py,
3073        pt = object->pt;
3074      value = (-vx * py + vy * px) / pt;
3075    }
3076    else if (variable == "dz"){
3077 <    double vx = object->vx - chosenPrimaryVertex->x,
3078 <      vy = object->vy - chosenPrimaryVertex->y,
3079 <      vz = object->vz - chosenPrimaryVertex->z,
3077 >    double vx = object->vx - chosenVertex ()->x,
3078 >      vy = object->vy - chosenVertex ()->y,
3079 >      vz = object->vz - chosenVertex ()->z,
3080        px = object->px,
3081        py = object->py,
3082        pz = object->pz,
# Line 1992 | Line 3087 | OSUAnalysis::valueLookup (const BNmcpart
3087      value = sqrt(object->vx*object->vx + object->vy*object->vy);
3088    }
3089    else if(variable == "deltaV0"){
3090 <    value = sqrt((object->vx-chosenPrimaryVertex->x)*(object->vx-chosenPrimaryVertex->x) + (object->vy-chosenPrimaryVertex->y)*(object->vy-chosenPrimaryVertex->y));
3090 >    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
3091    }
3092    else if (variable == "deltaVx"){
3093 <    value = object->vx - chosenPrimaryVertex->x;
3093 >    value = object->vx - chosenVertex ()->x;
3094    }
3095    else if (variable == "deltaVy"){
3096 <    value = object->vy - chosenPrimaryVertex->y;
3096 >    value = object->vy - chosenVertex ()->y;
3097    }
3098    else if (variable == "deltaVz"){
3099 <    value = object->vz - chosenPrimaryVertex->z;
3099 >    value = object->vz - chosenVertex ()->z;
3100    }
3101  
3102  
3103 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3103 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3104  
3105    value = applyFunction(function, value);
3106  
3107    return value;
3108 < }
3108 > } // end mcparticle valueLookup
3109 >
3110  
3111 + //!primaryvertex valueLookup
3112   double
3113 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
3113 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
3114  
3115    double value = 0.0;
3116  
# Line 2032 | Line 3129 | OSUAnalysis::valueLookup (const BNprimar
3129    else if(variable == "isGood") value = object->isGood;
3130  
3131  
3132 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3132 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3133  
3134    value = applyFunction(function, value);
3135  
3136    return value;
3137   }
3138  
3139 + //!bxlumi valueLookup
3140   double
3141 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
3141 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
3142  
3143    double value = 0.0;
3144  
# Line 2049 | Line 3147 | OSUAnalysis::valueLookup (const BNbxlumi
3147    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
3148  
3149  
3150 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3150 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3151  
3152    value = applyFunction(function, value);
3153  
3154    return value;
3155   }
3156  
3157 + //!photon valueLookup
3158   double
3159 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
3159 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
3160  
3161    double value = 0.0;
3162  
# Line 2132 | Line 3231 | OSUAnalysis::valueLookup (const BNphoton
3231    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
3232  
3233  
3234 +
3235 +
3236 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3237 +
3238 +  else if(variable == "genMatchedPdgId"){
3239 +    int index = getGenMatchedParticleIndex(object);
3240 +    if(index == -1) value = 0;
3241 +    else value = mcparticles->at(index).id;
3242 +  }
3243 +
3244 +
3245 +
3246    else if(variable == "genMatchedId"){
3247      int index = getGenMatchedParticleIndex(object);
3248      if(index == -1) value = 0;
# Line 2142 | Line 3253 | OSUAnalysis::valueLookup (const BNphoton
3253      if(index == -1) value = 0;
3254      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
3255    }
3256 +  else if(variable == "genMatchedMotherIdReverse"){
3257 +    int index = getGenMatchedParticleIndex(object);
3258 +    if(index == -1) value = 24;
3259 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
3260 +  }
3261    else if(variable == "genMatchedGrandmotherId"){
3262      int index = getGenMatchedParticleIndex(object);
3263      if(index == -1) value = 0;
# Line 2152 | Line 3268 | OSUAnalysis::valueLookup (const BNphoton
3268      }
3269      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3270    }
3271 +  else if(variable == "genMatchedGrandmotherIdReverse"){
3272 +    int index = getGenMatchedParticleIndex(object);
3273 +    if(index == -1) value = 24;
3274 +    else if(fabs(mcparticles->at(index).motherId) == 15){
3275 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3276 +      if(motherIndex == -1) value = 24;
3277 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3278 +    }
3279 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3280 +  }
3281  
3282  
3283 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3283 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3284  
3285    value = applyFunction(function, value);
3286  
3287    return value;
3288 < }
3288 > } // end photon valueLookup
3289 >
3290  
3291 + //!supercluster valueLookup
3292   double
3293 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
3293 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
3294  
3295    double value = 0.0;
3296  
# Line 2176 | Line 3304 | OSUAnalysis::valueLookup (const BNsuperc
3304    else if(variable == "theta") value = object->theta;
3305  
3306  
3307 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3307 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3308  
3309    value = applyFunction(function, value);
3310  
3311    return value;
3312   }
3313  
3314 + //!trigobj valueLookup
3315 + double
3316 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3317 +
3318 +  double value = 0.0;
3319 +
3320 +  if(variable == "pt") value = object->pt;
3321 +  else if(variable == "eta") value = object->eta;
3322 +  else if(variable == "phi") value = object->phi;
3323 +  else if(variable == "px") value = object->px;
3324 +  else if(variable == "py") value = object->py;
3325 +  else if(variable == "pz") value = object->pz;
3326 +  else if(variable == "et") value = object->et;
3327 +  else if(variable == "energy") value = object->energy;
3328 +  else if(variable == "etTotal") value = object->etTotal;
3329 +  else if(variable == "id") value = object->id;
3330 +  else if(variable == "charge") value = object->charge;
3331 +  else if(variable == "isIsolated") value = object->isIsolated;
3332 +  else if(variable == "isMip") value = object->isMip;
3333 +  else if(variable == "isForward") value = object->isForward;
3334 +  else if(variable == "isRPC") value = object->isRPC;
3335 +  else if(variable == "bx") value = object->bx;
3336 +  else if(variable == "filter") {
3337 +    if ((stringValue = object->filter) == "")
3338 +      stringValue = "none";  // stringValue should only be empty if value is filled
3339 +  }
3340 +
3341 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3342 +
3343 +  value = applyFunction(function, value);
3344  
3345 +  return value;
3346 + }
3347 +
3348 + //!muon-muon pair valueLookup
3349   double
3350 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
3350 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3351  
3352    double value = 0.0;
3353  
3354    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3355 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3356    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3357    else if(variable == "invMass"){
3358      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3359      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3360 <
3361 <    value = (fourVector1 + fourVector2).M();}
3362 <
3360 >    value = (fourVector1 + fourVector2).M();
3361 >  }
3362 >  else if(variable == "pt"){
3363 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3364 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3365 >    value = (fourVector1 + fourVector2).Pt();
3366 >  }
3367    else if(variable == "threeDAngle")
3368      {
3369        TVector3 threeVector1(object1->px, object1->py, object1->pz);
# Line 2208 | Line 3375 | OSUAnalysis::valueLookup (const BNmuon*
3375        static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3376        TVector3 threeVector1(object1->px, object1->py, object1->pz);
3377        TVector3 threeVector2(object2->px, object2->py, object2->pz);
3378 <      value = (pi-threeVector1.Angle( threeVector2));
3378 >      value = (pi-threeVector1.Angle(threeVector2));
3379      }
2213
2214  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2215
2216
3380    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3381    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3382    else if(variable == "d0Sign"){
# Line 2222 | Line 3385 | OSUAnalysis::valueLookup (const BNmuon*
3385      else if (d0Sign > 0) value = 0.5;
3386      else value = -999;
3387    }
3388 +  else if(variable == "chargeProduct"){
3389 +    value = object1->charge*object2->charge;
3390 +  }
3391    else if(variable == "muon1CorrectedD0Vertex"){
3392      value = object1->correctedD0Vertex;
3393    }
3394    else if(variable == "muon2CorrectedD0Vertex"){
3395      value = object2->correctedD0Vertex;
3396    }
3397 < else if(variable == "muon1timeAtIpInOut"){
3397 >  else if(variable == "muon1timeAtIpInOut"){
3398      value = object1->timeAtIpInOut;
3399    }
3400 < else if(variable == "muon2timeAtIpInOut"){
3400 >  else if(variable == "muon2timeAtIpInOut"){
3401      value = object2->timeAtIpInOut;
3402    }
3403 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3403 >  else if(variable == "muon1correctedD0")
3404 >    {
3405 >      value = object1->correctedD0;
3406 >    }
3407 >  else if(variable == "muon2correctedD0")
3408 >    {
3409 >      value = object2->correctedD0;
3410 >    }
3411  
3412 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3413 +
3414 +  value = applyFunction(function, value);
3415  
3416 +  return value;
3417 + } // end muon-muon pair valueLookup
3418  
3419  
3420 <
3420 > //!muon-photon pair valueLookup
3421 > double
3422 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3423  
3424 +  double value = 0.0;
3425  
3426 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3427 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3428 +  else if(variable == "photonEta") value = object2->eta;
3429 +  else if(variable == "photonPt") value = object2->pt;
3430 +  else if(variable == "muonEta") value = object1->eta;
3431 +  else if(variable == "photonPhi") value = object2->phi;
3432 +  else if(variable == "muonPhi") value = object1->phi;
3433 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3434 +  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3435 +  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3436 +  else if(variable == "invMass"){
3437 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3438 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3439 +    value = (fourVector1 + fourVector2).M();
3440 +  }
3441 +  else if(variable == "pt"){
3442 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3443 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3444 +    value = (fourVector1 + fourVector2).Pt();
3445 +  }
3446 +  else if(variable == "threeDAngle")
3447 +    {
3448 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3449 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3450 +      value = (threeVector1.Angle(threeVector2));
3451 +    }
3452 +  else if(variable == "alpha")
3453 +    {
3454 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3455 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3456 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3457 +      value = (pi-threeVector1.Angle(threeVector2));
3458 +    }
3459 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3460  
3461    value = applyFunction(function, value);
3462  
3463    return value;
3464   }
3465  
3466 + //!electron-photon pair valueLookup
3467   double
3468 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
3468 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3469  
3470    double value = 0.0;
3471  
3472    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3473 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3474 +  else if(variable == "photonEta") value = object2->eta;
3475 +  else if(variable == "photonPt") value = object2->pt;
3476 +  else if(variable == "electronEta") value = object1->eta;
3477 +  else if(variable == "photonPhi") value = object2->phi;
3478 +  else if(variable == "electronPhi") value = object1->phi;
3479    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3480 +  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3481 +  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3482    else if(variable == "invMass"){
3483      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3484      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3485 <
3486 <    value = (fourVector1 + fourVector2).M();}
3487 < else if(variable == "threeDAngle")
3485 >    value = (fourVector1 + fourVector2).M();
3486 >  }
3487 >  else if(variable == "pt"){
3488 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3489 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3490 >    value = (fourVector1 + fourVector2).Pt();
3491 >  }
3492 >  else if(variable == "threeDAngle")
3493      {
3494        TVector3 threeVector1(object1->px, object1->py, object1->pz);
3495        TVector3 threeVector2(object2->px, object2->py, object2->pz);
3496        value = (threeVector1.Angle(threeVector2));
3497      }
3498 <  
3499 <
3500 <
3498 >  else if(variable == "alpha")
3499 >    {
3500 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3501 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3502 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3503 >      value = (pi-threeVector1.Angle(threeVector2));
3504 >    }
3505 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3506  
3507 <  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2274 <  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3507 >  value = applyFunction(function, value);
3508  
3509 <  else if(variable == "d0Sign") value = object1->correctedD0Vertex*object2->correctedD0Vertex/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3509 >  return value;
3510 > }
3511  
3512 + //!electron-electron pair valueLookup
3513 + double
3514 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3515  
3516 +  double value = 0.0;
3517  
3518 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3519 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3520 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3521 +  else if(variable == "invMass"){
3522 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3523 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3524 +    value = (fourVector1 + fourVector2).M();
3525 +  }
3526 +  else if(variable == "pt"){
3527 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3528 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3529 +    value = (fourVector1 + fourVector2).Pt();
3530 +  }
3531 +  else if(variable == "threeDAngle")
3532 +    {
3533 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3534 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3535 +      value = (threeVector1.Angle(threeVector2));
3536 +    }
3537 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3538 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3539    else if(variable == "d0Sign"){
3540      double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
3541      if(d0Sign < 0) value = -0.5;
3542      else if (d0Sign > 0) value = 0.5;
3543      else value = -999;
3544    }
3545 +  else if(variable == "chargeProduct"){
3546 +    value = object1->charge*object2->charge;
3547 +  }
3548    else if(variable == "electron1CorrectedD0Vertex"){
3549      value = object1->correctedD0Vertex;
3550    }
3551    else if(variable == "electron2CorrectedD0Vertex"){
3552      value = object2->correctedD0Vertex;
3553    }
3554 +  else if(variable == "electron1CorrectedD0"){
3555 +    value = object1->correctedD0;
3556 +  }
3557 +  else if(variable == "electron2CorrectedD0"){
3558 +    value = object2->correctedD0;
3559 +  }
3560  
3561 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3561 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3562  
3563    value = applyFunction(function, value);
3564  
3565    return value;
3566   }
3567  
3568 + //!electron-muon pair valueLookup
3569   double
3570 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3570 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3571  
3572    double value = 0.0;
3573  
3574    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3575 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3576    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3577    else if(variable == "invMass"){
3578      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3579      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3580 <
3581 <    value = (fourVector1 + fourVector2).M();}
3582 < else if(variable == "threeDAngle")
3580 >    value = (fourVector1 + fourVector2).M();
3581 >  }
3582 >  else if(variable == "pt"){
3583 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3584 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3585 >    value = (fourVector1 + fourVector2).Pt();
3586 >  }
3587 >  else if(variable == "threeDAngle")
3588      {
3589        TVector3 threeVector1(object1->px, object1->py, object1->pz);
3590        TVector3 threeVector2(object2->px, object2->py, object2->pz);
3591        value = (threeVector1.Angle(threeVector2));
3592      }
2318
2319
3593    else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
3594    else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
3595    else if(variable == "d0Sign"){
# Line 2325 | Line 3598 | OSUAnalysis::valueLookup (const BNelectr
3598      else if (d0Sign > 0) value = 0.5;
3599      else value = -999;
3600    }
3601 +  else if(variable == "chargeProduct"){
3602 +    value = object1->charge*object2->charge;
3603 +  }
3604    else if(variable == "electronCorrectedD0Vertex"){
3605      value = object1->correctedD0Vertex;
3606    }
# Line 2337 | Line 3613 | OSUAnalysis::valueLookup (const BNelectr
3613    else if(variable == "muonCorrectedD0"){
3614      value = object2->correctedD0;
3615    }
3616 +  else if(variable == "electronDetIso"){
3617 +    value = (object1->trackIso) / object1->pt;
3618 +  }
3619 +  else if(variable == "muonDetIso"){
3620 +    value = (object2->trackIsoDR03) / object2->pt;
3621 +  }
3622 +  else if(variable == "electronRelPFrhoIso"){
3623 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3624 +  }
3625 +  else if(variable == "muonRelPFdBetaIso"){
3626 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3627 +  }
3628 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3629 +  value = applyFunction(function, value);
3630 +
3631 +  return value;
3632 + } // end electron-muon pair valueLookup
3633 +
3634 +
3635 + //!electron-jet pair valueLookup
3636 + double
3637 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3638 +
3639 +  double value = 0.0;
3640 +
3641 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3642 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3643 +  else if(variable == "jetEta") value = object2->eta;
3644 +  else if(variable == "jetPhi") value = object2->phi;
3645 +  else if(variable == "electronEta") value = object1->eta;
3646 +  else if(variable == "electronPhi") value = object1->phi;
3647 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3648 +  else if(variable == "invMass"){
3649 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3650 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3651 +    value = (fourVector1 + fourVector2).M();
3652 +  }
3653 +  else if(variable == "pt"){
3654 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3655 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3656 +    value = (fourVector1 + fourVector2).Pt();
3657 +  }
3658 +  else if(variable == "threeDAngle")
3659 +    {
3660 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3661 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3662 +      value = (threeVector1.Angle(threeVector2));
3663 +    }
3664 +  else if(variable == "chargeProduct"){
3665 +    value = object1->charge*object2->charge;
3666 +  }
3667 +
3668 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3669 +  value = applyFunction(function, value);
3670 +
3671 +  return value;
3672 + }
3673 +
3674 + //!electron-mcparticle pair valueLookup
3675 + double
3676 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmcparticle* object2, string variable, string function, string &stringValue){
3677 +
3678 +  double value = 0.0;
3679 +
3680 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3681 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3682 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3683 +  else if(variable == "threeDAngle")
3684 +    {
3685 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3686 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3687 +      value = (threeVector1.Angle(threeVector2));
3688 +    }
3689 +  else if(variable == "chargeProduct"){
3690 +    value = object1->charge*object2->charge;
3691 +  }
3692 +
3693 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3694 +  value = applyFunction(function, value);
3695 +
3696 +  return value;
3697 + }
3698 +
3699 +
3700 + //!photon-jet pair valueLookup
3701 + double
3702 + OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3703 +
3704 +  double value = 0.0;
3705 +
3706 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3707 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3708 +  else if(variable == "jetEta") value = object2->eta;
3709 +  else if(variable == "jetPhi") value = object2->phi;
3710 +  else if(variable == "photonEta") value = object1->eta;
3711 +  else if(variable == "photonPhi") value = object1->phi;
3712 +  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3713 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3714 +  else if(variable == "invMass"){
3715 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3716 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3717 +    value = (fourVector1 + fourVector2).M();
3718 +  }
3719 +  else if(variable == "pt"){
3720 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3721 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3722 +    value = (fourVector1 + fourVector2).Pt();
3723 +  }
3724 +  else if(variable == "threeDAngle")
3725 +    {
3726 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3727 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3728 +      value = (threeVector1.Angle(threeVector2));
3729 +    }
3730 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3731 +  value = applyFunction(function, value);
3732 +
3733 +  return value;
3734 + }
3735 +
3736 + // track-jet pair valueLookup
3737 + double
3738 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNjet* object2, string variable, string function, string &stringValue){
3739 +
3740 +  double value = 0.0;
3741 +
3742 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3743 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3744 +
3745 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3746 +  value = applyFunction(function, value);
3747 +
3748 +  return value;
3749 +
3750 + }
3751 +
3752 +
3753 +
3754 + // met-jet pair valueLookup
3755 + double
3756 + OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3757 +
3758 +  double value = 0.0;
3759 +
3760 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3761 +
3762 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3763 +  value = applyFunction(function, value);
3764 +
3765 +  return value;
3766 +
3767 + }  
3768 +
3769 +
3770 +
3771 + //!muon-jet pair valueLookup
3772 + double
3773 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3774 +
3775 +  double value = 0.0;
3776 +
3777 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3778 +  else if(variable == "jetEta") value = object2->eta;
3779 +  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3780 +  else if(variable == "jetPt") value = object2->pt;
3781 +  else if(variable == "jetPhi") value = object2->phi;
3782 +  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3783 +  else if(variable == "muonEta") value = object1->eta;
3784 +  else if(variable == "muonPt") value = object1->pt;
3785 +  else if(variable == "muonPhi") value = object1->phi;
3786 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3787 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3788 +  else if(variable == "invMass"){
3789 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3790 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3791 +    value = (fourVector1 + fourVector2).M();
3792 +  }
3793 +  else if(variable == "pt"){
3794 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3795 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3796 +    value = (fourVector1 + fourVector2).Pt();
3797 +  }
3798 +  else if(variable == "threeDAngle")
3799 +    {
3800 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3801 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3802 +      value = (threeVector1.Angle(threeVector2));
3803 +    }
3804 +  else if(variable == "chargeProduct"){
3805 +    value = object1->charge*object2->charge;
3806 +  }
3807  
3808 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3809 +  value = applyFunction(function, value);
3810  
3811 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3811 >  return value;
3812 > }
3813 >
3814 > //!muon-event valueLookup
3815 > double
3816 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNevent* object2, string variable, string function, string &stringValue){
3817  
3818 +  double value = 0.0;
3819 +
3820 +  if(variable == "muonEta") value = object1->eta;
3821 +  else if(variable == "muonPt") value = object1->pt;
3822 +  else if(variable == "muonPhi") value = object1->phi;
3823 +  else if(variable == "Ht") value = getHt(jets.product());
3824 +  else if(variable == "pthat")   value = object2->pthat;
3825 +  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3826 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3827    value = applyFunction(function, value);
3828  
3829    return value;
3830   }
3831 + //!jet-jet pair valueLookup
3832 + double
3833 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3834 +
3835 +  double value = 0.0;
3836 +
3837 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3838 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3839 +  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3840 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3841 +  else if(variable == "invMass"){
3842 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3843 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3844 +    value = (fourVector1 + fourVector2).M();
3845 +  }
3846 +  else if(variable == "pt"){
3847 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3848 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3849 +    value = (fourVector1 + fourVector2).Pt();
3850 +  }
3851 +  else if(variable == "threeDAngle")
3852 +    {
3853 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3854 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3855 +      value = (threeVector1.Angle(threeVector2));
3856 +    }
3857 +  else if(variable == "chargeProduct"){
3858 +    value = object1->charge*object2->charge;
3859 +  }
3860 +
3861 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3862 +  value = applyFunction(function, value);
3863  
3864 +  return value;
3865 + }
3866  
3867 < // Calculate the number of tracks in cone of DeltaR<0.5 around track1.  
3868 < // Return true iff no other tracks are found in this cone.  
3869 < int
3867 > //!electron-track pair valueLookup
3868 > double
3869 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3870 >  double electronMass = 0.000511;
3871 >  double value = 0.0;
3872 >  TLorentzVector fourVector1(0, 0, 0, 0);
3873 >  TLorentzVector fourVector2(0, 0, 0, 0);
3874 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3875 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3876 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3877 >  else if(variable == "invMass"){
3878 >    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3879 >    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3880 >
3881 >    value = (fourVector1 + fourVector2).M();
3882 >  }
3883 >  else if(variable == "chargeProduct"){
3884 >    value = object1->charge*object2->charge;
3885 >  }
3886 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3887 >  value = applyFunction(function, value);
3888 >  return value;
3889 >
3890 > }
3891 >
3892 >
3893 > //!muon-track pair valueLookup
3894 > double
3895 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3896 >  double pionMass = 0.140;
3897 >  double muonMass = 0.106;
3898 >  double value = 0.0;
3899 >  TLorentzVector fourVector1(0, 0, 0, 0);
3900 >  TLorentzVector fourVector2(0, 0, 0, 0);
3901 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3902 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3903 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3904 >  else if(variable == "invMass"){
3905 >    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3906 >    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3907 >
3908 >    value = (fourVector1 + fourVector2).M();
3909 >  }
3910 >  else if(variable == "chargeProduct"){
3911 >    value = object1->charge*object2->charge;
3912 >  }
3913 >
3914 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3915 >  value = applyFunction(function, value);
3916 >  return value;
3917 > }
3918 >
3919 > //!tau-tau pair valueLookup
3920 > double
3921 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3922 >  double value = 0.0;
3923 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3924 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3925 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3926 >  else if(variable == "invMass"){
3927 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3928 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3929 >    value = (fourVector1 + fourVector2).M();
3930 >  }
3931 >
3932 >  else if(variable == "chargeProduct"){
3933 >    value = object1->charge*object2->charge;
3934 >  }
3935 >
3936 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3937 >  value = applyFunction(function, value);
3938 >  return value;
3939 > }
3940 >
3941 > //!muon-tau pair valueLookup
3942 > double
3943 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3944 >  double value = 0.0;
3945 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3946 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3947 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3948 >  else if(variable == "invMass"){
3949 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3950 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3951 >    value = (fourVector1 + fourVector2).M();
3952 >  }
3953 >
3954 >  else if(variable == "chargeProduct"){
3955 >    value = object1->charge*object2->charge;
3956 >  }
3957 >
3958 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3959 >  value = applyFunction(function, value);
3960 >  return value;
3961 > }
3962 >
3963 > //!tau-track pair valueLookup
3964 > double
3965 > OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3966 >  double value = 0.0;
3967 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3968 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3969 >  else if(variable == "chargeProduct"){
3970 >    value = object1->charge*object2->charge;
3971 >  }
3972 >
3973 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3974 >  value = applyFunction(function, value);
3975 >  return value;
3976 > }
3977 >
3978 >
3979 > //!track-event pair valueLookup
3980 > double
3981 > OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3982 >
3983 >  double value = 0.0;
3984 >  double pMag = sqrt(object1->pt * object1->pt +
3985 >                     object1->pz * object1->pz);
3986 >
3987 >  if      (variable == "numPV")                      value = object2->numPV;
3988 >  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3989 >  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3990 >  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3991 >  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3992 >
3993 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3994 >
3995 >  value = applyFunction(function, value);
3996 >
3997 >  return value;
3998 >
3999 > }
4000 >
4001 > //!electron-trigobj pair valueLookup
4002 > double
4003 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
4004 >
4005 >  double value = 0.0;
4006 >
4007 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4008 >  else if (variable == "match"){
4009 >    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
4010 >      stringValue = object2->filter;
4011 >    else
4012 >      stringValue = "none";
4013 >  }
4014 >
4015 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4016 >
4017 >  value = applyFunction(function, value);
4018 >
4019 >  return value;
4020 >
4021 > }
4022 >
4023 > //!muon-trigobj pair valueLookup
4024 > double
4025 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
4026 >
4027 >  double value = 0.0;
4028 >
4029 >  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
4030 >
4031 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4032 >
4033 >  value = applyFunction(function, value);
4034 >
4035 >  return value;
4036 >
4037 > }
4038 >
4039 > //!stop valueLookup
4040 > double
4041 > OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
4042 >
4043 >
4044 >  double value = 0.0;
4045 >
4046 >  if(variable == "ctau") value = object->ctau;
4047 >
4048 >  else if (variable == "d0"){
4049 >    double vx = object->vx - chosenVertex ()->x,
4050 >      vy = object->vy - chosenVertex ()->y,
4051 >      px = object->px,
4052 >      py = object->py,
4053 >      pt = object->pt;
4054 >    value = (-vx * py + vy * px) / pt;
4055 >  }
4056 >
4057 >  else if (variable == "dz"){
4058 >    double vx = object->vx - chosenVertex ()->x,
4059 >      vy = object->vy - chosenVertex ()->y,
4060 >      vz = object->vz - chosenVertex ()->z,
4061 >      px = object->px,
4062 >      py = object->py,
4063 >      pz = object->pz,
4064 >      pt = object->pt;
4065 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
4066 >  }
4067 >
4068 >  else if (variable == "minD0"){
4069 >    double minD0=999;
4070 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4071 >      double vx = object->vx - vertex->x,
4072 >        vy = object->vy - vertex->y,
4073 >        px = object->px,
4074 >        py = object->py,
4075 >        pt = object->pt;
4076 >      value = (-vx * py + vy * px) / pt;
4077 >      if(abs(value) < abs(minD0)) minD0 = value;
4078 >    }
4079 >    value = minD0;
4080 >  }
4081 >  else if (variable == "minDz"){
4082 >    double minDz=999;
4083 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4084 >      double vx = object->vx - vertex->x,
4085 >        vy = object->vy - vertex->y,
4086 >        vz = object->vz - vertex->z,
4087 >        px = object->px,
4088 >        py = object->py,
4089 >        pz = object->pz,
4090 >        pt = object->pt;
4091 >      value = vz - (vx * px + vy * py)/pt * (pz/pt);
4092 >      if(abs(value) < abs(minDz)) minDz = value;
4093 >    }
4094 >    value = minDz;
4095 >  }
4096 >  else if(variable == "distToVertex"){
4097 >    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4098 >                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4099 >                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4100 >  }
4101 >  else if (variable == "minDistToVertex"){
4102 >    double minDistToVertex=999;
4103 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4104 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4105 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4106 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
4107 >
4108 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4109 >    }
4110 >    value = minDistToVertex;
4111 >  }
4112 >  else if (variable == "distToVertexDifference"){
4113 >    double minDistToVertex=999;
4114 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4115 >      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4116 >                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4117 >                   (object->vz-vertex->z)*(object->vz-vertex->z));
4118 >
4119 >      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4120 >    }
4121 >    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4122 >                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4123 >                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4124 >
4125 >    value = distToChosenVertex - minDistToVertex;
4126 >  }
4127 >
4128 >  else if (variable == "closestVertexRank"){
4129 >    double minDistToVertex=999;
4130 >    int vertex_rank = 0;
4131 >    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4132 >      vertex_rank++;
4133 >      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4134 >                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
4135 >                      (object->vz-vertex->z)*(object->vz-vertex->z));
4136 >
4137 >      if(abs(dist) < abs(minDistToVertex)){
4138 >        value = vertex_rank;
4139 >        minDistToVertex = dist;
4140 >      }
4141 >    }
4142 >  }
4143 >
4144 >  else if (variable == "decaysToTau"){
4145 >    value = abs (object->daughter0Id) == 15 || abs (object->daughter1Id) == 15;
4146 >  }
4147 >
4148 >
4149 >
4150 >
4151 >  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4152 >
4153 >  value = applyFunction(function, value);
4154 >
4155 >  return value;
4156 >
4157 > } // end stop valueLookup
4158 >
4159 >
4160 >
4161 >
4162 >
4163 > // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
4164 > // Return true iff no other tracks are found in this cone.
4165 > int
4166   OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
4167    for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
4168 <    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.  
4168 >    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
4169      double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
4170      if(deltaRtrk < 0.5) return 0;
4171    }
4172    return 1;
4173 <  
4173 >
4174   }
4175  
4176 + //calculate the scalar sum of Jet Pt in the event.
4177 + double
4178 + OSUAnalysis::getHt (const BNjetCollection* jetColl){
4179 +  double Ht = 0;
4180 +  for(BNjetCollection::const_iterator jet = jetColl->begin(); jet !=jetColl->end(); jet++){
4181 +    Ht += abs(jet->pt);
4182 +  }
4183 +  return Ht;
4184 + }
4185  
4186 < double
4186 > double
4187   OSUAnalysis::getTrkPtRes (const BNtrack* track1){
4188  
4189    double ptTrue = getTrkPtTrue(track1, mcparticles.product());
4190    double PtRes = (track1->pt - ptTrue) / ptTrue;
4191  
4192    return PtRes;
4193 <  
4193 >
4194   }
4195  
4196  
4197 < double
4197 > double
4198   OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
4199    double value = -99;
4200    double genDeltaRLowest = 999;
# Line 2381 | Line 4203 | OSUAnalysis::getTrkPtTrue (const BNtrack
4203      double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
4204      if (genDeltaRtemp < genDeltaRLowest) {
4205        genDeltaRLowest = genDeltaRtemp;
4206 <      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.  
4207 <        double ptTrue = genPart->pt;
4208 <        value = ptTrue;
4206 >      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
4207 >        double ptTrue = genPart->pt;
4208 >        value = ptTrue;
4209        }
4210 <    }
4210 >    }
4211    }
4212  
4213    return value;
4214  
4215   }
4216  
4217 + double
4218 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
4219 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
4220 +  if (!useTrackCaloRhoCorr_) return -99;
4221 +  // if (!rhokt6CaloJetsHandle_) {
4222 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
4223 +  //   return -99;
4224 +  // }
4225 +  double radDeltaRCone = 0.5;
4226 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
4227 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
4228 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
4229 +  return caloTotRhoCorrCalo;
4230 +
4231 + }
4232 +
4233 + double
4234 + OSUAnalysis::getTrkDepTrkRp5RhoCorr(const BNtrack* track) {
4235 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.              
4236 +  if (!useTrackCaloRhoCorr_) return -99;
4237 +  // if (!rhokt6CaloJetsHandle_) {                                                                                                    
4238 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;                        
4239 +  //   return -99;                                                                                                                    
4240 +  // }                                                                                                                                
4241 +  double radDeltaRCone = 0.5;
4242 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.                                                                                                          
4243 +  double rawDepTrkRp5 = track->depTrkRp5;
4244 + double depTrkRp5RhoCorr = TMath::Max(0., rawDepTrkRp5 - rhoCorr_kt6CaloJets);
4245 + return depTrkRp5RhoCorr;
4246 +
4247 + }
4248 +
4249 + double
4250 + OSUAnalysis::getTrkDepTrkRp3RhoCorr(const BNtrack* track) {
4251 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.                                                
4252 +  if (!useTrackCaloRhoCorr_) return -99;
4253 +  // if (!rhokt6CaloJetsHandle_) {                                                                                                                                      
4254 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;                                                          
4255 +  //   return -99;                                                                                                                                                      
4256 +  // }                                                                                                                                                                  
4257 +  double radDeltaRCone = 0.3;
4258 + // Define effective area as pi*r^2, where r is radius of DeltaR cone
4259 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  
4260 +  double rawDepTrkRp3 = track->depTrkRp3;
4261 +  double depTrkRp3RhoCorr = TMath::Max(0., rawDepTrkRp3 - rhoCorr_kt6CaloJets);
4262 +  return depTrkRp3RhoCorr;
4263 +  
4264 + }
4265 +
4266 +
4267 +
4268 +
4269   //creates a map of the dead Ecal channels in the barrel and endcap
4270   //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
4271   //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
4272 < void
4272 > void
4273   OSUAnalysis::WriteDeadEcal (){
4274    double etaEcal, phiEcal;
4275    ifstream DeadEcalFile(deadEcalFile_);
4276    if(!DeadEcalFile) {
4277 <    cout << "Error: DeadEcalFile has not been found." << endl;
4278 <    return;
4279 <  }
4280 <  if(DeadEcalVec.size()!= 0){
4281 <    cout << "Error: DeadEcalVec has a nonzero size" << endl;
4277 >    clog << "Error: DeadEcalFile has not been found." << endl;
4278 >    return;
4279 >  }
4280 >  if(DeadEcalVec.size()!= 0){
4281 >    clog << "Error: DeadEcalVec has a nonzero size" << endl;
4282      return;
4283 <  }
4283 >  }
4284    while(!DeadEcalFile.eof())
4285      {
4286        DeadEcalFile >> etaEcal >> phiEcal;
# Line 2415 | Line 4289 | OSUAnalysis::WriteDeadEcal (){
4289        newChan.phiEcal = phiEcal;
4290        DeadEcalVec.push_back(newChan);
4291      }
4292 <  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
4292 >  if(DeadEcalVec.size() == 0) clog << "Warning: No dead Ecal channels have been found." << endl;
4293   }
4294  
4295   //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
4296 < int
4296 > int
4297   OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
4298    double deltaRLowest = 999;
4299    int value = 0;
4300    if (DeadEcalVec.size() == 0) WriteDeadEcal();
4301 <  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4301 >  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4302      double eta = ecal->etaEcal;
4303      double phi = ecal->phiEcal;
4304 <    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
4304 >    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
4305      if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
4306    }
4307    if (deltaRLowest<0.05) {value = 1;}
# Line 2435 | Line 4309 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
4309    return value;
4310   }
4311  
4312 <
4313 <
4312 > // Returns the smallest DeltaR between the object and any generated true particle in the event.
4313 > template <class InputObject>
4314 > double OSUAnalysis::getGenDeltaRLowest(InputObject object){
4315 >  double genDeltaRLowest = 999.;
4316 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4317 >    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
4318 >    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
4319 >  }
4320 >  return genDeltaRLowest;
4321 > }
4322  
4323   double
4324   OSUAnalysis::applyFunction(string function, double value){
# Line 2447 | Line 4329 | OSUAnalysis::applyFunction(string functi
4329    else if(function == "log") value = log10(value);
4330  
4331    else if(function == "") value = value;
4332 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
4332 >  else{clog << "WARNING: invalid function '" << function << "'\n";}
4333  
4334    return value;
4335  
# Line 2457 | Line 4339 | OSUAnalysis::applyFunction(string functi
4339   template <class InputCollection>
4340   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
4341  
4342 +  if (verbose_>2) clog << "  Beginning setObjectFlags for cut " << currentCutIndex << ": " << currentCut.name
4343 +                       << ", inputType=" << inputType
4344 +                       << endl;  
4345 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
4346 +    string obj1, obj2;
4347 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
4348 +    if (inputType==obj1 ||
4349 +        inputType==obj2) {
4350 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
4351 +      // and the inputType is a member of the pair.
4352 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
4353 +      // For example, if currentCut.inputCollection==electron-muon pairs,
4354 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
4355 +      return;
4356 +    }
4357 +  }
4358  
4359    for (uint object = 0; object != inputCollection->size(); object++){
4360  
4361 <
4362 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
2465 <
4361 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4362 >    bool plotDecision = true;
4363  
4364      if(currentCut.inputCollection == inputType){
4365  
4366        vector<bool> subcutDecisions;
4367        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4368 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4369 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4368 >        string stringValue = "";
4369 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4370 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4371 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4372 >
4373        }
4374 <      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4374 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4375        else{
4376 <        bool tempDecision = true;
4377 <        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4378 <          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4379 <            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4380 <          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4376 >        bool tempDecision = true;
4377 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4378 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4379 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4380 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4381              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4382 <        }
4383 <        decision = tempDecision;
4382 >        }
4383 >        cutDecision = tempDecision;
4384        }
4385 +      //invert the cut if this cut is a veto
4386 +      if(currentCut.isVeto) cutDecision = !cutDecision;
4387 +      plotDecision = cutDecision;
4388      }
2486    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4389  
4390 +    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4391  
4392 <    //set flags for objects that pass each cut AND all the previous cuts
4393 <    bool previousCumulativeFlag = true;
4392 >    //set flags for objects that pass this cut AND all the previous cuts
4393 >    bool previousCumulativeCutFlag = true;
4394 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4395 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4396 >      else{ previousCumulativeCutFlag = false; break;}
4397 >    }
4398 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4399 >    bool previousCumulativePlotFlag = true;
4400      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4401 <      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4402 <      else{ previousCumulativeFlag = false; break;}
4401 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4402 >      else{ previousCumulativePlotFlag = false; break;}
4403      }
4404 <    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4404 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4405  
4406 +    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4407  
4408    }
4409  
4410 < }
4410 > } // end void OSUAnalysis::setObjectFlags
4411  
4412  
4413   template <class InputCollection1, class InputCollection2>
4414 < void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
4415 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
4416 <
4414 > void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags,
4415 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, string inputType){
4416 >  // This function sets the flags for the paired object collection.  
4417 >  // If the cut is applying on the given paired object collection, then the flags for the single object collections are also set.
4418 >  // If not, then the flags for the paired object collection are taken as the AND of the flags for each single object collection.  
4419 >
4420 >  if (verbose_>2) clog << "  Beginning setObjectFlags for cut=" << currentCut.name
4421 >                       << ", inputType=" << inputType
4422 >                       << endl;  
4423  
4424    bool sameObjects = false;
4425 <  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4425 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;  // FIXME:  is sameObjects just the not of isTwoTypesOfObject?  If so, it's redundant.  
4426 >
4427 >  // Get the strings for the two objects that make up the pair.
4428 >  string obj1Type, obj2Type;
4429 >  getTwoObjs(inputType, obj1Type, obj2Type);
4430 >  bool isTwoTypesOfObject = true;
4431 >  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
4432 >
4433 >  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
4434 >  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4435 >  if (currentCut.inputCollection == inputType) {
4436 >    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4437 >      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4438 >      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4439 >    }
4440 >    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4441 >      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4442 >        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4443 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4444 >      }
4445 >    }
4446 >  }
4447  
4448 +  int counter = 0;
4449  
2512  int counter = 0;  
4450    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4451      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4452 <      
4452 >
4453        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4454  
4455  
4456 <      bool decision = true;//object passes if this cut doesn't cut on that type of object
4456 >      bool cutDecision  = true;//object passes if this cut doesn't cut on that type of object
4457 >      bool plotDecision = true;
4458  
4459 +      // Determine whether each pair passes the cut, only if inputCollection is the same as the inputType.  
4460        if(currentCut.inputCollection == inputType){
4461  
4462 <        vector<bool> subcutDecisions;
4463 <        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4464 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4465 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4466 <        }
4462 >        vector<bool> subcutDecisions;
4463 >        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4464 >          string stringValue = "";
4465 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4466 >          if (verbose_>1) clog << currentCut.variables.at(subcutIndex) << " = " << value
4467 >                               << endl;  
4468 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4469 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4470 >        }
4471  
4472 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4473 <        else{
4474 <          bool tempDecision = true;
4475 <          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
4476 <            if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
4477 <              tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
4478 <            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4479 <              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4480 <          }
4481 <          decision = tempDecision;
4472 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4473 >        else{
4474 >          bool tempDecision = subcutDecisions.at(0);
4475 >          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
4476 >            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
4477 >              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
4478 >            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4479 >              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4480 >          }
4481 >          cutDecision = tempDecision;
4482 >        }
4483 >        //invert the cut if this cut is a veto
4484 >        if (currentCut.isVeto) cutDecision = !cutDecision;
4485 >        plotDecision = cutDecision;
4486 >
4487 >        if (verbose_>1) clog << " cutDecision = " << cutDecision
4488 >                             << "; for currentCut.inputCollection = " << currentCut.inputCollection
4489 >                             << "; object1 (" << obj1Type << ") = " << object1
4490 >                             << "; object2 (" << obj2Type << ") = " << object2
4491 >                             << endl;  
4492 >        
4493 >        if (cutDecision) {  // only set the flags for the individual objects if the pair object is being cut on
4494 >          individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4495 >          individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4496          }
4497 +        if (plotDecision) {  // only set the flags for the individual objects if the pair object is being cut on
4498 +          individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4499 +          individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4500 +        }
4501 +        
4502 +
4503 +      } // if(currentCut.inputCollection == inputType){
4504 +
4505 +      // The individualFlags will be true if the inputCollection is not the same as the inputType.
4506 +      // They are also independent of the previous flags on the single objects.  
4507 +      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));  
4508 +
4509 +
4510 +
4511 +      // ************************************
4512 +      // Determine cumulative flags
4513 +      // ************************************
4514 +      // determine whether this paired object passes this cut AND all previous cuts
4515 +      bool previousCumulativeCutFlag = true;
4516 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4517 +        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4518 +        else{ previousCumulativeCutFlag = false; break;}
4519        }
4520 <      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4521 <      
4522 <      //set flags for objects that pass each cut AND all the previous cuts
2544 <      bool previousCumulativeFlag = true;
4520 >      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4521 >
4522 >      bool previousCumulativePlotFlag = true;
4523        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4524 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
4525 <        else{ previousCumulativeFlag = false; break;}
4524 >        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4525 >        else{ previousCumulativePlotFlag = false; break;}
4526 >      }
4527 >      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4528 >      
4529 >      // Get the index for the flags of each of the single objects in the pair.  Usually this is the index of the previous cut, i.e., currentCutIndex-1.    
4530 >      int cutIdxFlagsObj1 = max(int(currentCutIndex-1),0);
4531 >      int cutIdxFlagsObj2 = max(int(currentCutIndex-1),0);
4532 >      // If the inputCollection of the cut is not equal to the inputType but the inputCollection includes objects that are contained in inputType, then use the currentCutIndex for those collections.
4533 >      // For example, if the inputType is jet-jet pairs, and the inputCollection is track-jet pairs, then use currentCutIndex for cutIdxFlagsObj{1,2}, i.e., for both jets.  
4534 >      // For example, if the inputType is jets, and the inputCollection is track-jet pairs, then use currentCutIndex for cutIdxFlagsObj2 (jets) and currentCutIndex-1 for cutIdxFlagsObj1 (tracks).  
4535 >      if (currentCut.inputCollection != inputType) {  
4536 >        if (currentCut.inputCollection.find(obj1Type)!=string::npos) cutIdxFlagsObj1 = currentCutIndex;
4537 >        if (currentCut.inputCollection.find(obj2Type)!=string::npos) cutIdxFlagsObj2 = currentCutIndex;
4538 >      }  
4539 >      flagPair flags1 = cumulativeFlags.at(obj1Type).at(cutIdxFlagsObj1);  // flag for input collection 1
4540 >      flagPair flags2 = cumulativeFlags.at(obj2Type).at(cutIdxFlagsObj2);  // flag for input collection 2
4541 >      
4542 >      // The cumulative flag is only true if the paired object cumulative flag is true, and if the single object cumulative flags are true.  
4543 >      bool currentCumulativeCutFlag = true;
4544 >      bool currentCumulativePlotFlag = true;
4545 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4546 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4547 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4548 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4549 >
4550 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4551 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4552 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4553 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4554 >
4555 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));  // Set the flag for the paired object
4556 >
4557 >
4558 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // Set the flags for the individual objects if the paired object is being cut on.  
4559 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first  = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4560 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first  = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4561 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4562 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4563 >
4564 >        if (verbose_>1) clog << " previousCumulativeCutFlag for object1 = " << getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object1, "cut") << endl;  
4565 >        if (verbose_>1) clog << " previousCumulativeCutFlag for object2 = " << getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut") << endl;  
4566 >
4567        }
2549      //apply flags for the components of the composite object as well
2550      bool currentCumulativeFlag = true;
2551      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
2552      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
2553      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
2554      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
2555      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
4568  
4569 <      counter++;      
4569 >      counter++;
4570 >
4571 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4572 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4573 >
4574 > } // end void OSUAnalysis::setObjectFlags
4575 >
4576 >
4577 > bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4578 >  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4579 >  // all cuts up to currentCutIndex
4580 >  bool previousCumulativeFlag = true;
4581 >  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4582 >    bool tempFlag = false;
4583 >    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4584 >    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4585 >
4586 >    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4587 >    else {
4588 >      previousCumulativeFlag = false; break;
4589      }
2559    
4590    }
4591 +  return previousCumulativeFlag;
4592 + }
4593 +
4594 +
4595 +
4596 +
4597 + template <class InputCollection>
4598 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4599 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4600 +
4601 +  if (BNTreeBranchVals_.count(parameters.name)==0) clog << "Error[assignTreeBranch]:  trying to assign value to " << parameters.name << " that does not have a branch set up.  Will likely seg fault." << endl;
4602 +  for (uint object = 0; object != inputCollection->size(); object++) {
4603 +
4604 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4605  
4606 +    string inputVariable = parameters.inputVariable;
4607 +    string function = "";
4608 +    string stringValue = "";
4609 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4610 +    BNTreeBranchVals_.at(parameters.name).push_back(value);
4611  
4612 +  }
4613   }
4614  
4615  
4616   template <class InputCollection>
4617 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
4617 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4618 >
4619 >  if (verbose_>2) clog << "  Filling histogram for " << parameters.name << endl;  
4620  
4621    for (uint object = 0; object != inputCollection->size(); object++){
4622  
4623 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4623 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4624  
4625      string currentString = parameters.inputVariables.at(0);
4626      string inputVariable = "";
4627      string function = "";
4628 <    if(currentString.find("(")==std::string::npos){
4629 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
4628 >    if(currentString.find("(")==string::npos){
4629 >      inputVariable = currentString;// variable to cut on
4630      }
4631      else{
4632 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4633 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4634 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4632 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4633 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4634 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4635      }
4636  
4637 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
4638 <    histo->Fill(value,puScaleFactor);
4637 >    string stringValue = "";
4638 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4639 >    histo->Fill(value,scaleFactor);
4640 >
4641 >    if (printEventInfo_) {
4642 >      // Write information about event to screen, for testing purposes.
4643 >      clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << " (object number " << object << ")" << endl;
4644 >    }
4645  
4646    }
2589
4647   }
4648  
4649   template <class InputCollection1, class InputCollection2>
4650 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
4650 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2,
4651 >                                  flagPair pairFlags, double scaleFactor){
4652  
4653    bool sameObjects = false;
4654    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4655  
4656 <  int pairCounter = 0;  
4656 >  int pairCounter = -1;
4657    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4658      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4659 <      
4659 >
4660        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4661  
4662 <      //only take objects which have passed all cuts and pairs which have passed all cuts
4663 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
2606 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
2607 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4662 >      pairCounter++;
4663 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4664  
4665        string currentString = parameters.inputVariables.at(0);
4666        string inputVariable = "";
4667        string function = "";
4668 <      if(currentString.find("(")==std::string::npos){
4669 <        inputVariable = currentString;// variable to cut on                                                                                                          
4668 >      if(currentString.find("(")==string::npos){
4669 >        inputVariable = currentString;// variable to cut on
4670        }
4671        else{
4672 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4673 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4674 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4672 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4673 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4674 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4675        }
2620      
2621      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
2622      histo->Fill(value,puScaleFactor);
4676  
4677 <      pairCounter++;      
4677 >      string stringValue = "";
4678 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4679 >      histo->Fill(value,scaleFactor);
4680 >
4681 >      if (printEventInfo_) {
4682 >        // Write information about event to screen, for testing purposes.
4683 >        clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value
4684 >             << " (object1 number " << object1 << "), "
4685 >             << " (object2 number " << object2 << ")"
4686 >             << endl;
4687 >      }
4688 >      
4689      }
4690    }
4691  
# Line 2629 | Line 4693 | void OSUAnalysis::fill1DHistogram(TH1* h
4693  
4694  
4695   template <class InputCollection>
4696 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double puScaleFactor){
4696 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4697  
4698    for (uint object = 0; object != inputCollection->size(); object++){
4699  
4700 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4700 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4701  
4702 +    string stringValue = "";
4703      string currentString = parameters.inputVariables.at(0);
4704      string inputVariable = "";
4705      string function = "";
4706 <    if(currentString.find("(")==std::string::npos){
4707 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
4706 >    if(currentString.find("(")==string::npos){
4707 >      inputVariable = currentString;// variable to cut on
4708      }
4709      else{
4710 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4711 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4712 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4710 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4711 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4712 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4713      }
4714 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
4714 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4715  
4716      currentString = parameters.inputVariables.at(1);
4717      inputVariable = "";
4718      function = "";
4719 <    if(currentString.find("(")==std::string::npos){
4720 <      inputVariable = currentString;// variable to cut on                                                                                                                                        
4719 >    if(currentString.find("(")==string::npos){
4720 >      inputVariable = currentString;// variable to cut on
4721      }
4722      else{
4723 <      function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4724 <      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4725 <      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4723 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
4724 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4725 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4726      }
4727  
4728 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
4728 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4729  
4730 <    histo->Fill(valueX,valueY,puScaleFactor);
4730 >    histo->Fill(valueX,valueY,scaleFactor);
4731  
4732    }
4733  
4734   }
4735  
4736   template <class InputCollection1, class InputCollection2>
4737 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double puScaleFactor){
4737 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2,
4738 >                                  flagPair pairFlags, double scaleFactor){
4739  
4740    bool sameObjects = false;
4741    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4742  
4743 <  int pairCounter = 0;  
4743 >  int pairCounter = -1;
4744    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4745      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4746 <      
4746 >
4747        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4748  
4749 <      //only take objects which have passed all cuts and pairs which have passed all cuts
2684 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
2685 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
2686 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4749 >      pairCounter++;
4750  
4751 +      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4752 +
4753 +      string stringValue = "";
4754        string currentString = parameters.inputVariables.at(0);
4755        string inputVariable = "";
4756        string function = "";
4757 <      if(currentString.find("(")==std::string::npos){
4758 <        inputVariable = currentString;// variable to cut on                                                                                                          
4757 >      if(currentString.find("(")==string::npos){
4758 >        inputVariable = currentString;// variable to cut on
4759        }
4760        else{
4761 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4762 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4763 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4761 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4762 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4763 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4764        }
4765 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4765 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4766  
4767        currentString = parameters.inputVariables.at(1);
4768        inputVariable = "";
4769        function = "";
4770 <      if(currentString.find("(")==std::string::npos){
4771 <        inputVariable = currentString;// variable to cut on                                                                                                          
4770 >      if(currentString.find("(")==string::npos){
4771 >        inputVariable = currentString;// variable to cut on
4772        }
4773        else{
4774 <        function = currentString.substr(0,currentString.find("("));//function comes before the "("                                                                                          
4775 <        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string                                                                                                    
4776 <        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"                                                                                                    
4774 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
4775 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4776 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4777        }
4778 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
2713 <
4778 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4779  
2715      histo->Fill(valueX,valueY,puScaleFactor);
4780  
4781 <      pairCounter++;      
4781 >      histo->Fill(valueX,valueY,scaleFactor);
4782  
4783      }
4784    }
# Line 2732 | Line 4796 | int OSUAnalysis::getGenMatchedParticleIn
4796  
4797      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4798      if(currentDeltaR > 0.05) continue;
4799 <
4799 >    //     clog << setprecision(3) << setw(20)
4800 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4801 >    //          << setw(20)
4802 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4803 >    //          << setw(20)
4804 >    //          << "\tdeltaR = " << currentDeltaR
4805 >    //          << setprecision(1)
4806 >    //          << setw(20)
4807 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4808 >    //          << setw(20)
4809 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4810 >    //          << setw(20)
4811 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4812      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4813        bestMatchIndex = mcparticle - mcparticles->begin();
4814        bestMatchDeltaR = currentDeltaR;
4815      }
4816  
4817    }
4818 <
4818 >  //   if(bestMatchDeltaR != 999)  clog << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4819 >  //   else clog << "no match found..." << endl;
4820    return bestMatchIndex;
4821  
4822   }
# Line 2793 | Line 4870 | int OSUAnalysis::findTauMotherIndex(cons
4870   // 20        strange baryon
4871   // 21        charm baryon
4872   // 22        bottom baryon
4873 < // 23        other
4873 > // 23        QCD string
4874 > // 24        other
4875  
4876   int OSUAnalysis::getPdgIdBinValue(int pdgId){
4877  
4878    int binValue = -999;
4879 <  int absPdgId = fabs(pdgId);  
4879 >  int absPdgId = fabs(pdgId);
4880    if(pdgId == -1) binValue = 0;
4881    else if(absPdgId <= 6 ) binValue = absPdgId;
4882    else if(absPdgId == 11 ) binValue = 7;
# Line 2817 | Line 4895 | int OSUAnalysis::getPdgIdBinValue(int pd
4895    else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4896    else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4897    else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4898 +  else if(absPdgId == 92  ) binValue = 23;
4899  
4900 <  else binValue = 23;
4900 >  else binValue = 24;
4901  
4902    return binValue;
4903  
4904   }
4905  
4906 + const BNprimaryvertex *
4907 + OSUAnalysis::chosenVertex ()
4908 + {
4909 +  const BNprimaryvertex *chosenVertex = 0;
4910 +  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4911 +    flagPair vertexFlags;
4912 +    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4913 +      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4914 +        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4915 +        break;
4916 +      }
4917 +    }
4918 +    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4919 +      if(!vertexFlags.at(vertexIndex).first) continue;
4920 +      chosenVertex = & primaryvertexs->at(vertexIndex);
4921 +      break;
4922 +    }
4923 +  }
4924 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4925 +    chosenVertex = & primaryvertexs->at (0);
4926  
4927 < DEFINE_FWK_MODULE(OSUAnalysis);
4927 >  return chosenVertex;
4928 > }
4929 >
4930 > const BNmet *
4931 > OSUAnalysis::chosenMET ()
4932 > {
4933 >  const BNmet *chosenMET = 0;
4934 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4935 >    flagPair metFlags;
4936 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4937 >      if (cumulativeFlags.at("mets").at(i).size()){
4938 >        metFlags = cumulativeFlags.at("mets").at(i);
4939 >        break;
4940 >      }
4941 >    }
4942 >    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4943 >      if(!metFlags.at(metIndex).first) continue;
4944 >      chosenMET = & mets->at(metIndex);
4945 >      break;
4946 >    }
4947 >  }
4948 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4949 >    chosenMET = & mets->at (0);
4950 >
4951 >  return chosenMET;
4952 > }
4953 >
4954 > const BNelectron *
4955 > OSUAnalysis::chosenElectron ()
4956 > {
4957 >  const BNelectron *chosenElectron = 0;
4958 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4959 >    flagPair electronFlags;
4960 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4961 >      if (cumulativeFlags.at("electrons").at(i).size()){
4962 >        electronFlags = cumulativeFlags.at("electrons").at(i);
4963 >        break;
4964 >      }
4965 >    }
4966 >    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4967 >      if(!electronFlags.at(electronIndex).first) continue;
4968 >      chosenElectron = & electrons->at(electronIndex);
4969 >      break;
4970 >    }
4971 >  }
4972 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4973 >    chosenElectron = & electrons->at (0);
4974 >
4975 >  return chosenElectron;
4976 > }
4977 >
4978 >
4979 > const BNmuon *
4980 > OSUAnalysis::chosenMuon ()
4981 > {
4982 >  const BNmuon *chosenMuon = 0;
4983 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4984 >    flagPair muonFlags;
4985 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4986 >      if (cumulativeFlags.at("muons").at(i).size()){
4987 >        muonFlags = cumulativeFlags.at("muons").at(i);
4988 >        break;
4989 >      }
4990 >    }
4991 >    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4992 >      if(!muonFlags.at(muonIndex).first) continue;
4993 >      chosenMuon = & muons->at(muonIndex);
4994 >      break;
4995 >    }
4996 >  }
4997 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4998 >    chosenMuon = & muons->at (0);
4999 >
5000 >  return chosenMuon;
5001 > }
5002  
5003 + double
5004 + OSUAnalysis::chosenHT ()
5005 + {
5006 +  double chosenHT = 0.0;
5007 +  if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
5008 +    flagPair jetFlags;
5009 +    for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
5010 +      if (cumulativeFlags.at("jets").at(i).size()){
5011 +        jetFlags = cumulativeFlags.at("jets").at(i);
5012 +        break;
5013 +      }
5014 +    }
5015 +    for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
5016 +      if(!jetFlags.at(jetIndex).first) continue;
5017 +      chosenHT += jets->at(jetIndex).pt;
5018 +    }
5019 +  }
5020 +
5021 +  return chosenHT;
5022 + }
5023 +
5024 + pair<const BNmuon *, const BNmuon *>
5025 + OSUAnalysis::leadMuonPair ()
5026 + {
5027 +  pair<const BNmuon *, const BNmuon *> leadMuonPair;
5028 +  leadMuonPair.first = leadMuonPair.second = 0;
5029 +
5030 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
5031 +    flagPair muonFlags;
5032 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
5033 +      if (cumulativeFlags.at("muons").at(i).size()){
5034 +        muonFlags = cumulativeFlags.at("muons").at(i);
5035 +        break;
5036 +      }
5037 +    }
5038 +    for (uint muonIndex0 = 0; muonIndex0 != muonFlags.size(); muonIndex0++){
5039 +      if(!muonFlags.at(muonIndex0).first) continue;
5040 +      for (uint muonIndex1 = muonIndex0 + 1; muonIndex1 < muonFlags.size(); muonIndex1++){
5041 +        if(!muonFlags.at(muonIndex1).first) continue;
5042 +        const BNmuon *mu0 = & muons->at(muonIndex0);
5043 +        const BNmuon *mu1 = & muons->at(muonIndex1);
5044 +        if(leadMuonPair.first == 0 || leadMuonPair.second == 0){
5045 +          leadMuonPair.first = mu0;
5046 +          leadMuonPair.second = mu1;
5047 +        }
5048 +        else{
5049 +          TVector2 newPt0 (mu0->px, mu0->py),
5050 +                   newPt1 (mu1->px, mu1->py),
5051 +                   oldPt0 (leadMuonPair.first->px, leadMuonPair.first->py),
5052 +                   oldPt1 (leadMuonPair.second->px, leadMuonPair.second->py);
5053 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
5054 +            {
5055 +              leadMuonPair.first = mu0;
5056 +              leadMuonPair.second = mu1;
5057 +            }
5058 +        }
5059 +      }
5060 +    }
5061 +  }
5062 +
5063 +  return leadMuonPair;
5064 + }
5065 +
5066 + pair<const BNelectron *, const BNelectron *>
5067 + OSUAnalysis::leadElectronPair ()
5068 + {
5069 +  pair<const BNelectron *, const BNelectron *> leadElectronPair;
5070 +  leadElectronPair.first = leadElectronPair.second = 0;
5071 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
5072 +    flagPair electronFlags;
5073 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
5074 +      if (cumulativeFlags.at("electrons").at(i).size()){
5075 +        electronFlags = cumulativeFlags.at("electrons").at(i);
5076 +        break;
5077 +      }
5078 +    }
5079 +    for (uint electronIndex0 = 0; electronIndex0 != electronFlags.size(); electronIndex0++){
5080 +      if(!electronFlags.at(electronIndex0).first) continue;
5081 +      for (uint electronIndex1 = electronIndex0 + 1; electronIndex1 < electronFlags.size(); electronIndex1++){
5082 +        if(!electronFlags.at(electronIndex1).first) continue;
5083 +        const BNelectron *el0 = & electrons->at(electronIndex0);
5084 +        const BNelectron *el1 = & electrons->at(electronIndex1);
5085 +        if(leadElectronPair.first == 0 || leadElectronPair.second == 0){
5086 +          leadElectronPair.first = el0;
5087 +          leadElectronPair.second = el1;
5088 +        }
5089 +        else{
5090 +          TVector2 newPt0 (el0->px, el0->py),
5091 +                   newPt1 (el1->px, el1->py),
5092 +                   oldPt0 (leadElectronPair.first->px, leadElectronPair.first->py),
5093 +                   oldPt1 (leadElectronPair.second->px, leadElectronPair.second->py);
5094 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
5095 +            {
5096 +              leadElectronPair.first = el0;
5097 +              leadElectronPair.second = el1;
5098 +            }
5099 +        }
5100 +      }
5101 +    }
5102 +  }
5103 +
5104 +  return leadElectronPair;
5105 + }
5106  
5107 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines