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.31 by ahart, Mon Mar 18 10:21:44 2013 UTC vs.
Revision 1.106 by wulsin, Mon Jul 22 16:36:08 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 <  muonSFFile_ (cfg.getParameter<std::string> ("muonSFFile")),
22 <  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
23 <  electronSFID_ (cfg.getParameter<std::string> ("electronSFID")),
24 <  muonSF_ (cfg.getParameter<std::string> ("muonSF")),
25 <  dataset_ (cfg.getParameter<std::string> ("dataset")),
26 <  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 +  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 < {
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 > {
43  
44    TH1::SetDefaultSumw2 ();
45  
46    //create pile-up reweighting object, if necessary
47    if(datasetType_ != "data") {
48      if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
49 <    muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
50 <    electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
49 >    if (applyLeptonSF_){
50 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
51 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
52 >    }
53 >    if (applyBtagSF_){
54 >      bTagSFWeight_ = new BtagSFWeight;
55 >    }
56    }
57 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
58 +    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
59 +
60  
61    // Construct Cutflow Objects. These store the results of cut decisions and
62    // handle filling cut flow histograms.
63    masterCutFlow_ = new CutFlow (fs_);
45  std::vector<TFileDirectory> directories;
64  
65    //always get vertex collection so we can assign the primary vertex in the event
66    objectsToGet.push_back("primaryvertexs");
49
50  //always make the plot of number of primary verticex (to check pile-up reweighting)
67    objectsToPlot.push_back("primaryvertexs");
68 +  objectsToFlag.push_back("primaryvertexs");
69 +
70  
71    //always get the MC particles to do GEN-matching
72    objectsToGet.push_back("mcparticles");
# Line 56 | Line 74 | OSUAnalysis::OSUAnalysis (const edm::Par
74    //always get the event collection to do pile-up reweighting
75    objectsToGet.push_back("events");
76  
77 +
78 +  // Parse the tree variable definitions.
79 +  for (uint iBranchSet = 0; !useEDMFormat_ && iBranchSet<treeBranchSets_.size(); iBranchSet++) {
80 +    string tempInputCollection = treeBranchSets_.at(iBranchSet).getParameter<string> ("inputCollection");
81 +    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; }
82 +    objectsToGet.push_back(tempInputCollection);
83 +    objectsToFlag.push_back(tempInputCollection);
84 +
85 +    vector<string> branchList(treeBranchSets_.at(iBranchSet).getParameter<vector<string> >("branches"));
86 +
87 +    for (uint iBranch = 0; iBranch<branchList.size(); iBranch++) {
88 +      BranchSpecs br;
89 +      br.inputCollection = tempInputCollection;
90 +      br.inputVariable = branchList.at(iBranch);
91 +      TString newName = TString(br.inputCollection) + "_" + TString(br.inputVariable);
92 +      br.name = string(newName.Data());
93 +      treeBranches_.push_back(br);
94 +    }
95 +
96 +  } // end   for (uint iBranchSet = 0; iBranchSet<treeBranchSets_.size(); iBranchSet++)
97 +
98 +
99    //parse the histogram definitions
100    for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
101  
102      string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
103      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
104 <    if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
105 <      objectsToGet.push_back(tempInputCollection);
104 >    if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
105 >    if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
106 >    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
107 >    if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
108 >    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
109 >    if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
110 >    if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
111 >    if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
112 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
113 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
114 >    if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
115 >    if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
116 >    if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
117 >    if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
118 >    if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
119 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
120 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
121 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
122 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
123 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
124 >        int spaceIndex = tempInputCollection.find(" ");
125 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
126 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
127 >      }
128 >      else{
129 >        objectsToGet.push_back(tempInputCollection);
130 >      }
131        objectsToPlot.push_back(tempInputCollection);
132 <      objectsToCut.push_back(tempInputCollection);
133 <    }
134 <    else{//pair of objects, need to add them both to the things to objectsToGet
135 <      int dashIndex = tempInputCollection.find("-");
136 <      int spaceIndex = tempInputCollection.find(" ");
137 <      int secondWordLength = spaceIndex - dashIndex;
138 <      objectsToGet.push_back(tempInputCollection);
139 <      objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
140 <      objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
132 >      objectsToFlag.push_back(tempInputCollection);
133 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
134 >      string obj1;
135 >      string obj2;
136 >      getTwoObjs(tempInputCollection, obj1, obj2);
137 >      string obj2ToGet = getObjToGet(obj2);
138 >      objectsToFlag.push_back(tempInputCollection);
139 >      objectsToFlag.push_back(obj1);
140 >      objectsToFlag.push_back(obj2);
141        objectsToPlot.push_back(tempInputCollection);
142 <      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
143 <      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
144 <      objectsToCut.push_back(tempInputCollection);
145 <      objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
146 <      objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
142 >      objectsToPlot.push_back(obj1);
143 >      objectsToPlot.push_back(obj2);
144 >      objectsToGet.push_back(tempInputCollection);
145 >      objectsToGet.push_back(obj1);
146 >      objectsToGet.push_back(obj2ToGet);
147 >    } // end else
148 >      if (find(objectsToPlot.begin(), objectsToPlot.end(), "events") != objectsToPlot.end())
149 >        objectsToGet.push_back("jets");
150  
83      }
151  
152      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
153  
154      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
155  
156 +      vector<double> defaultValue;
157 +      defaultValue.push_back (-1.0);
158 +
159        histogram tempHistogram;
160        tempHistogram.inputCollection = tempInputCollection;
161        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
162        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
163 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
163 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
164 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
165 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
166        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
167  
168        histograms.push_back(tempHistogram);
169  
170      }
171 <  }
171 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
172 >
173    //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
174    sort( objectsToPlot.begin(), objectsToPlot.end() );
175    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
# Line 107 | Line 180 | OSUAnalysis::OSUAnalysis (const edm::Par
180    for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
181  
182      string currentObject = objectsToPlot.at(currentObjectIndex);
183 <    if(currentObject != "muons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
183 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "secondary photons"&& currentObject != "superclusters") continue;
184  
185      histogram tempIdHisto;
186      histogram tempMomIdHisto;
187      histogram tempGmaIdHisto;
188 +    histogram tempIdVsMomIdHisto;
189 +    histogram tempIdVsGmaIdHisto;
190  
191      tempIdHisto.inputCollection = currentObject;
192      tempMomIdHisto.inputCollection = currentObject;
193      tempGmaIdHisto.inputCollection = currentObject;
194 +    tempIdVsMomIdHisto.inputCollection = currentObject;
195 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
196 +
197 +    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
198 +    if(currentObject == "secondary photons") currentObject = "secondaryPhotons";
199 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
200  
201      currentObject = currentObject.substr(0, currentObject.size()-1);
202      tempIdHisto.name = currentObject+"GenMatchId";
203      tempMomIdHisto.name = currentObject+"GenMatchMotherId";
204      tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
205 +    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
206 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
207  
208      currentObject.at(0) = toupper(currentObject.at(0));
209      tempIdHisto.title = currentObject+" Gen-matched Particle";
210      tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
211      tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
212 +    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
213 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
214  
215 <    int maxNum = 24;
215 >
216 >    int maxNum = 25;
217      vector<double> binVector;
218      binVector.push_back(maxNum);
219      binVector.push_back(0);
# Line 139 | Line 225 | OSUAnalysis::OSUAnalysis (const edm::Par
225      tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
226      tempGmaIdHisto.bins = binVector;
227      tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
228 +    binVector.push_back(maxNum);
229 +    binVector.push_back(0);
230 +    binVector.push_back(maxNum);
231 +    tempIdVsMomIdHisto.bins = binVector;
232 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
233 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
234 +    tempIdVsGmaIdHisto.bins = binVector;
235 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
236 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
237  
238      histograms.push_back(tempIdHisto);
239      histograms.push_back(tempMomIdHisto);
240      histograms.push_back(tempGmaIdHisto);
241 <
241 >    histograms.push_back(tempIdVsMomIdHisto);
242 >    histograms.push_back(tempIdVsGmaIdHisto);
243    }
244  
245  
150
246    channel tempChannel;
247    //loop over all channels (event selections)
248    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
# Line 160 | Line 255 | OSUAnalysis::OSUAnalysis (const edm::Par
255      //set triggers for this channel
256      vector<string> triggerNames;
257      triggerNames.clear();
258 +    vector<string> triggerToVetoNames;
259 +    triggerToVetoNames.clear();
260 +
261      tempChannel.triggers.clear();
262 +    tempChannel.triggersToVeto.clear();
263      if(channels_.at(currentChannel).exists("triggers")){
264        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
265        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
266          tempChannel.triggers.push_back(triggerNames.at(trigger));
267        objectsToGet.push_back("triggers");
268      }
269 <
269 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
270 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
271 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
272 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
273 >      objectsToGet.push_back("triggers");
274 >    }
275  
276  
277  
278      //create cutFlow for this channel
279      cutFlows_.push_back (new CutFlow (fs_, channelName));
280 <
281 <    //book a directory in the output file with the name of the channel
282 <    TFileDirectory subDir = fs_->mkdir( channelName );
179 <    directories.push_back(subDir);
180 <
181 <    std::map<std::string, TH1D*> oneDhistoMap;
182 <    oneDHists_.push_back(oneDhistoMap);
183 <    std::map<std::string, TH2D*> twoDhistoMap;
184 <    twoDHists_.push_back(twoDhistoMap);
185 <
186 <
187 <    //book all histograms included in the configuration
188 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
189 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
190 <      int numBinsElements = currentHistogram.bins.size();
191 <      int numInputVariables = currentHistogram.inputVariables.size();
192 <
193 <      if(numBinsElements != 3 && numBinsElements !=6) {
194 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
195 <        exit(0);
196 <      }
197 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
198 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
199 <        exit(0);
200 <      }
201 <      else if(numBinsElements == 3){
202 <        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));
203 <      }
204 <      else if(numBinsElements == 6){
205 <        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));
206 <
207 <      }
208 <
209 <
210 <      if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
211 <
212 < // bin      particle type
213 < // ---      -------------
214 < //  0        unmatched
215 < //  1        u
216 < //  2        d
217 < //  3        s
218 < //  4        c
219 < //  5        b
220 < //  6        t
221 < //  7        e
222 < //  8        mu
223 < //  9        tau
224 < // 10        nu
225 < // 11        g
226 < // 12        gamma
227 < // 13        Z
228 < // 14        W
229 < // 15        light meson
230 < // 16        K meson
231 < // 17        D meson
232 < // 18        B meson
233 < // 19        light baryon
234 < // 20        strange baryon
235 < // 21        charm baryon
236 < // 22        bottom baryon
237 < // 23        other
238 <
239 <      vector<TString> labelArray;
240 <      labelArray.push_back("unmatched");
241 <      labelArray.push_back("u");
242 <      labelArray.push_back("d");
243 <      labelArray.push_back("s");
244 <      labelArray.push_back("c");
245 <      labelArray.push_back("b");
246 <      labelArray.push_back("t");
247 <      labelArray.push_back("e");
248 <      labelArray.push_back("#mu");
249 <      labelArray.push_back("#tau");
250 <      labelArray.push_back("#nu");
251 <      labelArray.push_back("g");
252 <      labelArray.push_back("#gamma");
253 <      labelArray.push_back("Z");
254 <      labelArray.push_back("W");
255 <      labelArray.push_back("light meson");
256 <      labelArray.push_back("K meson");
257 <      labelArray.push_back("D meson");
258 <      labelArray.push_back("B meson");
259 <      labelArray.push_back("light baryon");
260 <      labelArray.push_back("strange baryon");
261 <      labelArray.push_back("charm baryon");
262 <      labelArray.push_back("bottom baryon");
263 <      labelArray.push_back("other");
264 <
265 <      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
266 <        oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
267 <      }
268 <    }
269 <
270 <    //book a histogram for the number of each object type to be plotted
271 <
272 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
273 <      string currentObject = objectsToPlot.at(currentObjectIndex);
274 <      int maxNum = 10;
275 <      if(currentObject == "mcparticles") maxNum = 50;
276 <      else if(currentObject == "primaryvertexs") maxNum = 50;
277 <      else if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
278 <      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
279 <      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
280 <
281 <      currentObject.at(0) = toupper(currentObject.at(0));
282 <      string histoName = "num" + currentObject;
283 <
284 <      if(histoName == "numPrimaryvertexs"){
285 <        string newHistoName = histoName + "BeforePileupCorrection";
286 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
287 <        newHistoName = histoName + "AfterPileupCorrection";
288 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
289 <      }
290 <      else
291 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
292 <    }
293 <
294 <
295 <
296 <
297 <
280 >    vector<TFileDirectory> directories; //vector of directories in the output file.
281 >    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
282 >    vector<string> subSubDirNames;//subdirectories in each channel.
283      //get list of cuts for this channel
284      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
285  
286 +
287      //loop over and parse all cuts
288      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
289        cut tempCut;
290        //store input collection for cut
291        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
292 +      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
293 +      if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
294 +      if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
295 +      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
296 +      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
297 +      if(tempInputCollection == "event-muon pairs") tempInputCollection = "muon-event pairs";
298 +      if(tempInputCollection == "jet-met pairs")  tempInputCollection = "met-jet pairs";
299 +      if(tempInputCollection == "track-jet pairs")  tempInputCollection = "track-jet pairs";
300 +      if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
301 +      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
302 +      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
303 +      if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
304 +      if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
305 +      if(tempInputCollection == "secondary photon-muon pairs")   tempInputCollection = "muon-secondary photon pairs";
306 +      if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
307 +      if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
308 +      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
309 +      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
310 +      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
311        tempCut.inputCollection = tempInputCollection;
312 <      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
313 <        objectsToGet.push_back(tempInputCollection);
312 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
313 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
314 >          int spaceIndex = tempInputCollection.find(" ");
315 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
316 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
317 >        }
318 >        else{
319 >          objectsToGet.push_back(tempInputCollection);
320 >        }
321          objectsToCut.push_back(tempInputCollection);
322 +        objectsToFlag.push_back(tempInputCollection);
323        }
324 <      else{//pair of objects, need to add them both to the things to objectsToGet
325 <        int dashIndex = tempInputCollection.find("-");
326 <        int spaceIndex = tempInputCollection.find(" ");
327 <        int secondWordLength = spaceIndex - dashIndex;
328 <        objectsToGet.push_back(tempInputCollection);
316 <        objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
317 <        objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
324 >      else{//pair of objects, need to add them both to objectsToGet
325 >        string obj1;
326 >        string obj2;
327 >        getTwoObjs(tempInputCollection, obj1, obj2);
328 >        string obj2ToGet = getObjToGet(obj2);
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");
330 >        objectsToCut.push_back(obj1);
331 >        objectsToCut.push_back(obj2);
332 >        objectsToFlag.push_back(tempInputCollection);
333 >        objectsToFlag.push_back(obj1);
334 >        objectsToFlag.push_back(obj2);
335 >        objectsToGet.push_back(tempInputCollection);
336 >        objectsToGet.push_back(obj1);
337 >        objectsToGet.push_back(obj2ToGet);
338  
339        }
340  
# Line 325 | Line 342 | OSUAnalysis::OSUAnalysis (const edm::Par
342  
343        //split cut string into parts and store them
344        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
345 <      std::vector<string> cutStringVector = splitString(cutString);
345 >      vector<string> cutStringVector = splitString(cutString);
346        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
347 <        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
347 >        clog << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
348          exit(0);
349        }
350        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
351        for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
352          int indexOffset = 4 * subcutIndex;
353          string currentVariableString = cutStringVector.at(indexOffset);
354 <        if(currentVariableString.find("(")==std::string::npos){
354 >        if(currentVariableString.find("(")==string::npos){
355            tempCut.functions.push_back("");//no function was specified
356            tempCut.variables.push_back(currentVariableString);// variable to cut on
357          }
# Line 345 | Line 362 | OSUAnalysis::OSUAnalysis (const edm::Par
362          }
363          tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
364          tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
365 +        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
366          if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
367        }
368  
369        //get number of objects required to pass cut for event to pass
370        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
371 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
371 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
372        if(numberRequiredVector.size()!=2){
373 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
373 >        clog << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
374          exit(0);
375        }
376  
# Line 360 | Line 378 | OSUAnalysis::OSUAnalysis (const edm::Par
378        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
379        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
380  
381 <
381 >      //Set up vectors to store the directories and subDirectories for each channel.
382 >      string subSubDirName;
383        string tempCutName;
384        if(cuts_.at(currentCut).exists("alias")){
385          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
386 +        subSubDirName = "After " + tempCutName + " Cut Applied";
387        }
388        else{
389          //construct string for cutflow table
# Line 371 | Line 391 | OSUAnalysis::OSUAnalysis (const edm::Par
391          string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
392          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
393          tempCutName = cutName;
394 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
395        }
375      tempCut.name = tempCutName;
396  
397 +      tempCut.isVeto = false;
398 +      if(cuts_.at(currentCut).exists("isVeto")){
399 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
400 +        if (isVeto == true) tempCut.isVeto = true;
401 +      }
402 +      subSubDirNames.push_back(subSubDirName);
403 +      tempCut.name = tempCutName;
404  
405        tempChannel.cuts.push_back(tempCut);
406  
407  
381
408      }//end loop over cuts
409  
410 +    vector<map<string, TH1D*>> oneDHistsTmp;
411 +    vector<map<string, TH2D*>> twoDHistsTmp;
412 +    //book a directory in the output file with the name of the channel
413 +    TFileDirectory subDir = fs_->mkdir( channelName );
414 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
415 +    if(GetPlotsAfterEachCut_){
416 +      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
417 +        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
418 +        directories.push_back(subSubDir);
419 +        map<string, TH1D*> oneDhistoMap;
420 +        oneDHistsTmp.push_back(oneDhistoMap);
421 +        map<string, TH2D*> twoDhistoMap;
422 +        twoDHistsTmp.push_back(twoDhistoMap);
423 +      }
424 +      treeDirectories.push_back(subDir);
425 +      oneDHists_.push_back(oneDHistsTmp);
426 +      twoDHists_.push_back(twoDHistsTmp);
427 +    }
428 +    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
429 +    else{
430 +      map<string, TH1D*> oneDhistoMap;
431 +      oneDHistsTmp.push_back(oneDhistoMap);
432 +      map<string, TH2D*> twoDhistoMap;
433 +      twoDHistsTmp.push_back(twoDhistoMap);
434 +      oneDHists_.push_back(oneDHistsTmp);
435 +      twoDHists_.push_back(twoDHistsTmp);
436 +      directories.push_back(subDir);
437 +      treeDirectories.push_back(subDir);
438 +
439 +    }
440 +
441 +    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
442 +      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
443 +      BNTrees_.push_back(newTree);
444 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
445 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
446 +        vector<float> newVec;
447 +        BNTreeBranchVals_[currentVar.name] = newVec;
448 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
449 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
450 +    }
451 +
452 +    //book all histograms included in the configuration
453 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
454 +
455 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
456 +
457 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
458 +        int numBinsElements = currentHistogram.bins.size();
459 +        int numInputVariables = currentHistogram.inputVariables.size();
460 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
461 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
462 +
463 +        if(numBinsElements == 1){
464 +          if(numBinEdgesX > 1){
465 +            if(numBinEdgesY > 1)
466 +              numBinsElements = 6;
467 +            else
468 +              numBinsElements = 3;
469 +          }
470 +        }
471 +        if(numBinsElements != 3 && numBinsElements !=6){
472 +          clog << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
473 +          exit(0);
474 +        }
475 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
476 +          clog << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
477 +          exit(0);
478 +        }
479 +        else if(numBinsElements == 3){
480 +          if (currentHistogram.bins.size () == 3)
481 +            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));
482 +          else
483 +            {
484 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
485 +            }
486 +        }
487 +        else if(numBinsElements == 6){
488 +          if (currentHistogram.bins.size () == 6)
489 +            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));
490 +          else
491 +            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 ());
492 +        }
493 +
494 +
495 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
496 +
497 +        // bin      particle type
498 +        // ---      -------------
499 +        //  0        unmatched
500 +        //  1        u
501 +        //  2        d
502 +        //  3        s
503 +        //  4        c
504 +        //  5        b
505 +        //  6        t
506 +        //  7        e
507 +        //  8        mu
508 +        //  9        tau
509 +        // 10        nu
510 +        // 11        g
511 +        // 12        gamma
512 +        // 13        Z
513 +        // 14        W
514 +        // 15        light meson
515 +        // 16        K meson
516 +        // 17        D meson
517 +        // 18        B meson
518 +        // 19        light baryon
519 +        // 20        strange baryon
520 +        // 21        charm baryon
521 +        // 22        bottom baryon
522 +        // 23        QCD string
523 +        // 24        other
524 +
525 +        vector<TString> labelArray;
526 +        labelArray.push_back("unmatched");
527 +        labelArray.push_back("u");
528 +        labelArray.push_back("d");
529 +        labelArray.push_back("s");
530 +        labelArray.push_back("c");
531 +        labelArray.push_back("b");
532 +        labelArray.push_back("t");
533 +        labelArray.push_back("e");
534 +        labelArray.push_back("#mu");
535 +        labelArray.push_back("#tau");
536 +        labelArray.push_back("#nu");
537 +        labelArray.push_back("g");
538 +        labelArray.push_back("#gamma");
539 +        labelArray.push_back("Z");
540 +        labelArray.push_back("W");
541 +        labelArray.push_back("light meson");
542 +        labelArray.push_back("K meson");
543 +        labelArray.push_back("D meson");
544 +        labelArray.push_back("B meson");
545 +        labelArray.push_back("light baryon");
546 +        labelArray.push_back("strange baryon");
547 +        labelArray.push_back("charm baryon");
548 +        labelArray.push_back("bottom baryon");
549 +        labelArray.push_back("QCD string");
550 +        labelArray.push_back("other");
551 +
552 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
553 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
554 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
555 +          }
556 +          else {
557 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
558 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
559 +          }
560 +        }
561 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
562 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
563 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
564 +        }
565 +
566 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
567 +
568 +
569 +      // Book a histogram for the number of each object type to be plotted.
570 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
571 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
572 +        string currentObject = objectsToPlot.at(currentObjectIndex);
573 +        int maxNum = 10;
574 +        if(currentObject == "mcparticles") maxNum = 50;
575 +        else if(currentObject == "primaryvertexs") maxNum = 50;
576 +
577 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
578 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
579 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
580 +        else if(currentObject == "electron-photon pairs")     currentObject = "electronPhotonPairs";
581 +        else if(currentObject == "muon-photon pairs")         currentObject = "muonPhotonPairs";
582 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
583 +        else if(currentObject == "secondary photons")            currentObject = "secondaryPhotons";
584 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
585 +        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
586 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
587 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
588 +        else if(currentObject == "muon-event pairs")            currentObject = "muonEventPairs";
589 +        else if(currentObject == "photon-jet pairs")            currentObject = "photonJetPairs";
590 +        else if(currentObject == "met-jet pairs")             currentObject = "metJetPairs";
591 +        else if(currentObject == "track-jet pairs")           currentObject = "trackJetPairs";
592 +        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
593 +        else if(currentObject == "muon-secondary photon pairs")  currentObject = "muonSecondaryPhotonPairs";
594 +        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
595 +        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
596 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
597 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
598 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
599 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
600 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
601 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
602 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
603 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
604 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
605 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
606 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
607 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
608 +
609 +        currentObject.at(0) = toupper(currentObject.at(0));
610 +        string histoName = "num" + currentObject;
611 +
612 +        if(histoName == "numPrimaryvertexs"){
613 +          string newHistoName = histoName + "BeforePileupCorrection";
614 +          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);
615 +          newHistoName = histoName + "AfterPileupCorrection";
616 +          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);
617 +        }
618 +        else
619 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
620 +      }
621 +    }//end of loop over directories
622      channels.push_back(tempChannel);
623      tempChannel.cuts.clear();
386
624    }//end loop over channels
625  
626  
# Line 393 | Line 630 | OSUAnalysis::OSUAnalysis (const edm::Par
630    //make unique vector of objects we need to cut on
631    sort( objectsToCut.begin(), objectsToCut.end() );
632    objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
633 +  //make unique vector of objects we need to set flags for
634 +  sort( objectsToFlag.begin(), objectsToFlag.end() );
635 +  objectsToFlag.erase( unique( objectsToFlag.begin(), objectsToFlag.end() ), objectsToFlag.end() );
636 +
637 +  produces<map<string, bool> > ("channelDecisions");
638 +
639 +  if (printEventInfo_) {
640 +    findEventsLog = new ofstream();  
641 +    findEventsLog->open("findEvents.txt");  
642 +    clog << "Listing run:lumi:event in file findEvents.txt for events that pass full selection (of any channel)." << endl;  
643 +  } else {
644 +    findEventsLog = 0;
645 +  }  
646  
647 +  isFirstEvent_ = true;  
648 +
649 + } // end constructor OSUAnalysis::OSUAnalysis()
650  
398 }
651  
652   OSUAnalysis::~OSUAnalysis ()
653   {
654 +
655    // Destroying the CutFlow objects causes the cut flow numbers and time
656    // information to be printed to standard output.
657    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
658      delete cutFlows_.at(currentChannel);
659    }
660 +
661 +  if (printEventInfo_ && findEventsLog) findEventsLog->close();  
662 +
663 +  clog << "=============================================" << endl;  
664 +  clog << "Successfully completed OSUAnalysis." << endl;  
665 +  clog << "=============================================" << endl;  
666 +
667   }
668  
669   void
670 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
670 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
671   {
412
672    // Retrieve necessary collections from the event.
673  
674 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
674 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
675      event.getByLabel (triggers_, triggers);
676  
677 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
677 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
678 >    event.getByLabel (trigobjs_, trigobjs);
679 >
680 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
681      event.getByLabel (jets_, jets);
682  
683 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
683 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
684      event.getByLabel (muons_, muons);
685  
686 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
686 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
687      event.getByLabel (electrons_, electrons);
688  
689 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
689 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
690      event.getByLabel (events_, events);
691  
692 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
692 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
693      event.getByLabel (taus_, taus);
694  
695 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
695 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
696      event.getByLabel (mets_, mets);
697  
698 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
698 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
699      event.getByLabel (tracks_, tracks);
700  
701 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
701 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
702      event.getByLabel (genjets_, genjets);
703  
704 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
704 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
705      event.getByLabel (mcparticles_, mcparticles);
706  
707 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
707 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
708      event.getByLabel (primaryvertexs_, primaryvertexs);
709  
710 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
710 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
711      event.getByLabel (bxlumis_, bxlumis);
712  
713 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
713 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
714      event.getByLabel (photons_, photons);
715  
716 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
716 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
717      event.getByLabel (superclusters_, superclusters);
718  
719 +  if (datasetType_ == "signalMC"){
720 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
721 +      event.getByLabel (stops_, stops);
722 +  }
723 +
724 +  if (useTrackCaloRhoCorr_) {
725 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
726 +    // This rho collection is not available in all BEANs.
727 +    // For description of rho values for different jet reconstruction algorithms, see
728 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
729 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
730 +  }
731 +
732 +  double masterScaleFactor = 1.0;
733 +
734    //get pile-up event weight
735 <  double scaleFactor = 1.00;
736 <  if(doPileupReweighting_ && datasetType_ != "data")
737 <    scaleFactor = puWeight_->at (events->at (0).numTruePV);
735 >  if (doPileupReweighting_ && datasetType_ != "data") {
736 >    //for "data" datasets, the numTruePV is always set to -1
737 >    if (events->at(0).numTruePV < 0 && isFirstEvent_) clog << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
738 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
739 >  }
740  
741 +  stopCTauScaleFactor_ = 1.0;
742 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
743 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
744 +  masterScaleFactor *= stopCTauScaleFactor_;
745  
746    //loop over all channels
747  
748 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
749    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
750      channel currentChannel = channels.at(currentChannelIndex);
751  
# Line 469 | Line 753 | OSUAnalysis::analyze (const edm::Event &
753      counterMap passingCounter;
754      cumulativeFlags.clear ();
755  
756 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
757 +         iter != BNTreeBranchVals_.end(); iter++) {
758 +      iter->second.clear();  // clear array
759 +    }
760 +
761      bool triggerDecision = true;
762 <    if(currentChannel.triggers.size() != 0){  //triggers specified
763 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
762 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
763 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
764        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
765      }
766  
767      //loop over all cuts
479
480
481
768      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
769        cut currentCut = currentChannel.cuts.at(currentCutIndex);
770  
771 <      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
772 <        string currentObject = objectsToCut.at(currentObjectIndex);
771 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
772 >        string currentObject = objectsToFlag.at(currentObjectIndex);
773  
774          //initialize maps to get ready to set cuts
775 <        individualFlags[currentObject].push_back (vector<bool> ());
776 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
775 >        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
776 >        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
777  
778        }
779 <      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
780 <        string currentObject = objectsToCut.at(currentObjectIndex);
779 >
780 >      //set flags for all relevant objects
781 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToFlag.size(); currentObjectIndex++){
782 >        string currentObject = objectsToFlag.at(currentObjectIndex);
783  
784          int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
785  
786  
787 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
788 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
787 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
788 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
789 >        else if(currentObject == "secondary photons")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"secondary photons");
790 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
791 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
792 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
793          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
794          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
795          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 509 | Line 801 | OSUAnalysis::analyze (const edm::Event &
801          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
802          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
803          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
804 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
805 +
806  
807  
808          else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
809                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
810                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
811                                                                     "muon-muon pairs");
812 +
813 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
814 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
815 +                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
816 +                                                                             "muon-secondary muon pairs");
817 +
818 +        else if(currentObject == "muon-secondary photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
819 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
820 +                                                                             cumulativeFlags.at("secondary photons").at(flagsForPairCutsIndex), \
821 +                                                                             "muon-secondary photon pairs");
822 +        else if(currentObject == "muon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
823 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
824 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
825 +                                                                             "muon-secondary jet pairs");
826 +        else if(currentObject == "photon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
827 +                                                                             cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
828 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
829 +                                                                             "photon-secondary jet pairs");
830 +
831 +        else if(currentObject == "electron-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
832 +                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
833 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
834 +                                                                             "electron-secondary jet pairs");
835 +
836 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
837 +                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
838 +                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
839 +                                                                                     "electron-secondary electron pairs");
840 +
841          else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
842                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
843                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
# Line 523 | Line 846 | OSUAnalysis::analyze (const edm::Event &
846                                                                         cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
847                                                                         cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
848                                                                         "electron-muon pairs");
849 +        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
850 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
851 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
852 +                                                                 "jet-jet pairs");
853 +        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
854 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
855 +                                                                 cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex),\
856 +                                                                 "jet-secondary jet pairs");
857 +        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
858 +                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
859 +                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
860 +                                                                      "electron-jet pairs");
861 +        else if(currentObject == "electron-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), \
862 +                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
863 +                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
864 +                                                                      "electron-photon pairs");
865 +        else if(currentObject == "photon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
866 +                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
867 +                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
868 +                                                                      "photon-jet pairs");
869 +        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
870 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
871 +                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
872 +                                                                  "muon-jet pairs");
873 +        else if(currentObject == "muon-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),events.product(), \
874 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
875 +                                                                  cumulativeFlags.at("events").at(flagsForPairCutsIndex), \
876 +                                                                  "muon-event pairs");
877 +        else if(currentObject == "met-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,mets.product(),jets.product(), \
878 +                                                                  cumulativeFlags.at("mets").at(flagsForPairCutsIndex), \
879 +                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
880 +                                                                  "met-jet pairs");
881 +        else if(currentObject == "track-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),jets.product(), \
882 +                                                                 cumulativeFlags.at("tracks").at(flagsForPairCutsIndex), \
883 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
884 +                                                                 "track-jet pairs");
885 +        else if(currentObject == "muon-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
886 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
887 +                                                                  cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
888 +                                                                  "muon-photon pairs");
889 +        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
890 +                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
891 +                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
892 +                                                                     "track-event pairs");
893 +        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
894 +                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
895 +                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
896 +                                                                        "electron-track pairs");
897 +        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
898 +                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
899 +                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
900 +                                                                    "muon-track pairs");
901 +        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
902 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
903 +                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
904 +                                                                  "muon-tau pairs");
905 +        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
906 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
907 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
908 +                                                                 "tau-tau pairs");
909 +        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
910 +                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
911 +                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
912 +                                                                   "tau-track pairs");
913 +        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
914 +                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
915 +                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
916 +                                                                          "electron-trigobj pairs");
917 +        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
918 +                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
919 +                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
920 +                                                                      "muon-trigobj pairs");
921  
922 <
922 >        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
923        }
924  
925  
926  
927      }//end loop over all cuts
533
534
928      //use cumulative flags to apply cuts at event level
929  
930 +    //a vector to store cumulative cut descisions after each cut.
931 +    vector<bool> eventPassedPreviousCuts;
932      bool eventPassedAllCuts = true;
538
933      //apply trigger (true if none were specified)
934      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
935  
542
543
936      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
937  
938        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 548 | Line 940 | OSUAnalysis::analyze (const edm::Event &
940        int numberPassing = 0;
941  
942        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
943 <          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
943 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
944        }
553
945        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
946        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
556
947        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
948 +      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
949 +    }
950 +    //applying all appropriate scale factors
951 +    double scaleFactor = masterScaleFactor;
952 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
953 +
954 +    if(applyLeptonSF_ && datasetType_ != "data"){
955 +      //only apply SFs if we've cut on this object
956 +      if(find(objectsToCut.begin(),objectsToCut.end(),"muons") != objectsToCut.end ()){
957 +        flagPair muonFlags;
958 +        //get the last valid flags in the flag map
959 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
960 +          if (cumulativeFlags.at("muons").at(i).size()){
961 +            muonFlags = cumulativeFlags.at("muons").at(i);
962 +            break;
963 +          }
964 +        }
965 +        //apply the weight for each of those objects
966 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
967 +          if(!muonFlags.at(muonIndex).second) continue;
968 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
969 +        }
970 +      }
971 +      //only apply SFs if we've cut on this object
972 +      if(find(objectsToCut.begin(),objectsToCut.end(),"electrons") != objectsToCut.end ()){
973 +        flagPair electronFlags;
974 +        //get the last valid flags in the flag map
975 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
976 +          if (cumulativeFlags.at("electrons").at(i).size()){
977 +            electronFlags = cumulativeFlags.at("electrons").at(i);
978 +            break;
979 +          }
980 +        }
981 +        //apply the weight for each of those objects
982 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
983 +          if(!electronFlags.at(electronIndex).second) continue;
984 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
985 +        }
986 +      }
987 +    }
988 +    if(applyBtagSF_ && datasetType_ != "data"){
989 +      //only apply SFs if we've cut on this object
990 +      if(find(objectsToCut.begin(),objectsToCut.end(),"jets") != objectsToCut.end ()){
991 +        flagPair jetFlags;
992 +        vector<double> jetSFs;
993 +        //get the last valid flags in the flag map
994 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
995 +          if (cumulativeFlags.at("jets").at(i).size()){
996 +            jetFlags = cumulativeFlags.at("jets").at(i);
997 +            break;
998 +          }
999 +        }
1000 +        //apply the weight for each of those objects
1001 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
1002 +          if(!jetFlags.at(jetIndex).second) continue;
1003 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour, jets->at(jetIndex).eta);
1004 +          jetSFs.push_back(jetSFTmp);
1005 +        }
1006 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_);
1007 +      }
1008 +    }
1009 +    scaleFactor *= muonScaleFactor_;
1010 +    scaleFactor *= electronScaleFactor_;
1011 +    scaleFactor *= bTagScaleFactor_;
1012 +    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
1013 +
1014 +    if (printEventInfo_ && eventPassedAllCuts) {
1015 +      // Write information about event to screen, for testing purposes.
1016 +      clog << "Event passed all cuts in channel " <<  currentChannel.name
1017 +           << ":  run:lumi:evt=  "  << events->at(0).run
1018 +           << ":" << events->at(0).lumi
1019 +           << ":" << events->at(0).evt
1020 +           << endl;
1021 +      if (findEventsLog) {
1022 +        (*findEventsLog) << events->at(0).run
1023 +                         << ":" << events->at(0).lumi
1024 +                         << ":" << events->at(0).evt << endl;
1025 +      }
1026  
1027      }
1028  
561    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
1029  
1030 +    //filling histograms
1031 +    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
1032 +      uint currentDir;
1033 +      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
1034 +      else{
1035 +        currentDir = currentCut;
1036 +      }
1037  
1038  
1039 <    if(!eventPassedAllCuts)continue;
1039 >      if(eventPassedPreviousCuts.at(currentDir)){
1040  
1041 +        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1042 +          histogram currentHistogram = histograms.at(histogramIndex);
1043  
1044 <    //if(datasetType_ != "data") {
569 <    //  scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
570 <    //  scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
571 <    //}
1044 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) clog << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
1045  
1046 <    //filling histograms
1047 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
1048 <      histogram currentHistogram = histograms.at(histogramIndex);
1046 >          if(currentHistogram.inputVariables.size() == 1){
1047 >            TH1D* histo;
1048 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1049 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1050 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1051 >            else if(currentHistogram.inputCollection == "secondary photons")  fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1052 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1053 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1054 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1055 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1056 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1057 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1058 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1059 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1060 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1061 >             else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1062 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary photons").at(currentDir), \
1063 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1064 >             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1065 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1066 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1067 >             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1068 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1069 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1070 >             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1071 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1072 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1073 >
1074 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1075 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
1076 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
1077 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1078 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
1079 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
1080 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1081 >             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1082 >                                                                                                     cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1083 >                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1084 >
1085 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1086 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1087 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1088 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
1089 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
1090 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1091 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
1092 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1093 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1094 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(), \
1095 >                                                                                              cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1096 >                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1097 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
1098 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1099 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1100 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill1DHistogram(histo,currentHistogram, muons.product(),events.product(), \
1101 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1102 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1103 >            else if(currentHistogram.inputCollection == "met-jet pairs")  fill1DHistogram(histo,currentHistogram, mets.product(),jets.product(), \
1104 >                                                                                          cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1105 >                                                                                          cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1106 >            else if(currentHistogram.inputCollection == "track-jet pairs")  fill1DHistogram(histo,currentHistogram,tracks.product(),jets.product(), \
1107 >                                                                                          cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1108 >                                                                                          cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1109 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(), \
1110 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1111 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1112 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(), \
1113 >                                                                                          cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1114 >                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1115 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1116 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1117 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1118 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1119 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1120 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1121 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1122 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1123 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1124 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1125 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1126 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1127 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1128 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1129 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1130 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1131 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1132 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1133 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1134 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1135 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1136 >
1137 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1138 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1139 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1140 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1141 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1142 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1143 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1144 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1145 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1146 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1147 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1148 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1149 >          }
1150 >          else if(currentHistogram.inputVariables.size() == 2){
1151 >            TH2D* histo;
1152 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1153 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1154 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1155 >            else if(currentHistogram.inputCollection == "secondary photons")  fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("secondary photons").at(currentDir),scaleFactor);
1156 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1157 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1158 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1159 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1160 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1161 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1162 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1163 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1164 >            else if(currentHistogram.inputCollection == "muon-secondary photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1165 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary photons").at(currentDir), \
1166 >                                                                                                     cumulativeFlags.at("muon-secondary photon pairs").at(currentDir),scaleFactor);
1167 >            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1168 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1169 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1170 >            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1171 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1172 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1173 >            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1174 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1175 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1176 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1177 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1178 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1179 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1180 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1181 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1182 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1183 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1184 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1185 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1186 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1187 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1188 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1189 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1190 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1191 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1192 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1193 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(), \
1194 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1195 >                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1196 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1197 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1198 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1199 >            else if(currentHistogram.inputCollection == "muon-event pairs") fill2DHistogram(histo,currentHistogram,muons.product(),events.product(), \
1200 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("events").at(currentDir), \
1201 >                                                                                          cumulativeFlags.at("muon-event pairs").at(currentDir),scaleFactor);
1202 >            else if(currentHistogram.inputCollection == "met-jet pairs") fill2DHistogram(histo,currentHistogram,mets.product(),jets.product(), \
1203 >                                                                                         cumulativeFlags.at("mets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1204 >                                                                                         cumulativeFlags.at("met-jet pairs").at(currentDir),scaleFactor);
1205 >            else if(currentHistogram.inputCollection == "track-jet pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),jets.product(),
1206 >                                                                                         cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1207 >                                                                                         cumulativeFlags.at("track-jet pairs").at(currentDir),scaleFactor);
1208 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1209 >                                                                                          cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1210 >                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1211 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1212 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1213 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1214 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1215 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1216 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1217 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1218 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1219 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1220 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1221 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1222 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1223 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1224 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1225 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1226 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1227 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1228 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1229 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1230 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1231 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1232 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1233 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
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("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1241 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1242 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1243 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1244 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1245 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1246 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1247 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1248 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1249 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1250 >          }
1251  
577      if(currentHistogram.inputVariables.size() == 1){
578        TH1D* histo;
579        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
580
581
582
583        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
584         else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
585        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
586                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
587                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
588        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
589        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
590                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
591                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
592        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
593                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
594                                                                                              cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
595        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
596        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
597        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
598        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
599        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
600        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
601        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
602        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
603        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
604        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
605      }
606      else if(currentHistogram.inputVariables.size() == 2){
607        TH2D* histo;
608        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
609
610
611
612        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
613        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
614        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
615                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
616                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
617        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
618        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
619                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
620                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
621        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
622                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
623                                                                                               cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
624        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
625        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
626        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
627        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
628        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
629        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
630        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
631        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
632        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
633        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
634      }
635    }
636
637    //fills histograms with the sizes of collections
638    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
639      string currentObject = objectsToPlot.at(currentObjectIndex);
640
641      string objectToPlot = "";
642
643      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
644      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
645      else if(currentObject == "electron-muon pairs") objectToPlot = "electronMuonPairs";
646      else objectToPlot = currentObject;
647      string tempCurrentObject = objectToPlot;
648      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
649      string histoName = "num" + tempCurrentObject;
650
651
652
653
654      //set position of primary vertex in event, in order to calculate quantities relative to it
655      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
656        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
657        int numToPlot = 0;
658        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
659          if(lastCutFlags.at(currentFlag)) numToPlot++;
660        }
661        if(objectToPlot == "primaryvertexs"){
662          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
663          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1252          }
665        else
666          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
667      }
668      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
669      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
670      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
671      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
672      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
673      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
674      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
675      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
676      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
677      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
678      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
679      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
680      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
681      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
682      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
683      else if(objectToPlot == "primaryvertexs"){
684        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
685        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
686      }
1253  
688    }
1254  
1255 +        //fills histograms with the sizes of collections
1256 +        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1257  
1258 +          string currentObject = objectsToPlot.at(currentObjectIndex);
1259 +          string objectToPlot = "";
1260  
1261 +          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1262 +          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1263 +          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1264 +          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1265 +          else if(currentObject == "electron-photon pairs")              objectToPlot = "electronPhotonPairs";
1266 +          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1267 +          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1268 +          else if(currentObject == "muon-event pairs")                     objectToPlot = "muonEventPairs";
1269 +          else if(currentObject == "muon-photon pairs")                     objectToPlot = "muonPhotonPairs";
1270 +          else if(currentObject == "photon-jet pairs")                     objectToPlot = "photonJetPairs";
1271 +          else if(currentObject == "met-jet pairs")                      objectToPlot = "metJetPairs";
1272 +          else if(currentObject == "track-jet pairs")                    objectToPlot = "trackJetPairs";
1273 +          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1274 +          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1275 +          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1276 +          else if(currentObject == "secondary photons")                     objectToPlot = "secondaryPhotons";
1277 +          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1278 +          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1279 +          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1280 +          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1281 +          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1282 +          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1283 +          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1284 +          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1285 +          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1286 +          else if(currentObject == "muon-secondary photon pairs")           objectToPlot = "muonSecondaryJetPairs";
1287 +          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1288 +          else if(currentObject == "photon-secondary jet pairs")         objectToPlot = "photonSecondaryJetPairs";
1289 +          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1290 +          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1291 +          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1292 +          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1293 +          else objectToPlot = currentObject;
1294 +
1295 +          string tempCurrentObject = objectToPlot;
1296 +          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1297 +          string histoName = "num" + tempCurrentObject;
1298 +
1299 +
1300 +          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1301 +            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1302 +            int numToPlot = 0;
1303 +            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1304 +              if(lastCutFlags.at(currentFlag).second) numToPlot++;
1305 +            }
1306 +
1307 +            if(objectToPlot == "primaryvertexs"){
1308 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1309 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1310 +            }
1311 +            else {
1312 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1313 +            }
1314 +          }
1315 +        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1316  
693  } //end loop over channel
1317  
1318 <  masterCutFlow_->fillCutFlow(scaleFactor);
1318 >      } // end if(eventPassedPreviousCuts.at(currentDir))
1319 >    } // end loop over cuts
1320  
1321 +    if (!useEDMFormat_ && eventPassedAllCuts){
1322 +      // Assign BNTree variables
1323 +      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1324 +        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1325 +        string coll = brSpecs.inputCollection;
1326 +        if (cumulativeFlags.count(coll) == 0) clog << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1327 +
1328 +        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1329 +        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1330 +        else if(coll == "secondary photons")      assignTreeBranch(brSpecs,photons.product(),          cumulativeFlags.at(coll).back());
1331 +        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1332 +        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1333 +        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1334 +        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1335 +        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1336 +        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1337 +        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1338 +        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1339 +        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1340 +        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1341 +        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1342 +        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1343 +        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1344 +        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1345 +        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1346 +        else if(coll == "stops"
1347 +                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1348 +      } // end loop over branches
1349  
1350 +      if (!BNTrees_.at(currentChannelIndex)) { clog << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1351 +      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1352 +    }
1353 +
1354 +    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1355 +
1356 +  } // end loop over channel
1357 +
1358 +  masterCutFlow_->fillCutFlow(masterScaleFactor);
1359 +
1360 +  event.put (channelDecisions, "channelDecisions");
1361 +
1362 +  isFirstEvent_ = false;  
1363 +
1364 + } // end void OSUAnalysis::produce (const edm::Event &event, const edm::EventSetup &setup)
1365  
699 }
1366  
1367  
1368   bool
# Line 710 | Line 1376 | OSUAnalysis::evaluateComparison (double
1376    else if(comparison == "==") return testValue == cutValue;
1377    else if(comparison == "=") return testValue == cutValue;
1378    else if(comparison == "!=") return testValue != cutValue;
1379 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1379 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1380 >
1381 > }
1382 >
1383 > bool
1384 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1385 >
1386 >
1387 >  if(comparison == ">")       return testValue >  cutValue;
1388 >  else if(comparison == ">=") return testValue >= cutValue;
1389 >  else if(comparison == "<")  return testValue <  cutValue;
1390 >  else if(comparison == "<=") return testValue <= cutValue;
1391 >  else if(comparison == "==") return testValue == cutValue;
1392 >  else if(comparison == "=") return testValue == cutValue;
1393 >  else if(comparison == "!=") return testValue != cutValue;
1394 >  else {clog << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1395  
1396   }
1397  
1398   bool
1399 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1399 > OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1400  
1401 +  //initialize to false until a chosen trigger is passed
1402    bool triggerDecision = false;
1403  
1404 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1405 <    {
1406 <      if(trigger->pass != 1) continue;
1407 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1408 <        {
1409 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1410 <            triggerDecision = true;
1411 <          }
1412 <        }
1404 >  if (printAllTriggers_) clog << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1405 >  //loop over all triggers defined in the event
1406 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1407 >
1408 >    if (printAllTriggers_) clog << "   " << trigger->name << endl;
1409 >
1410 >    //we're only interested in triggers that actually passed
1411 >    if(trigger->pass != 1) continue;
1412 >
1413 >    //if the event passes one of the veto triggers, exit and return false
1414 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1415 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1416 >    }
1417 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1418 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1419 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1420      }
1421 <  return triggerDecision;
1421 >  }
1422 >
1423 >  printAllTriggers_ = false;  // only print triggers once, not every event
1424  
1425 +  //if none of the veto triggers fired:
1426 +  //return the OR of all the chosen triggers
1427 +  if (triggersToTest.size() != 0) return triggerDecision;
1428 +  //or if no triggers were defined return true
1429 +  else return true;
1430   }
1431  
1432 < std::vector<std::string>
1432 >
1433 > vector<string>
1434   OSUAnalysis::splitString (string inputString){
1435  
1436 <  std::stringstream stringStream(inputString);
1437 <  std::istream_iterator<std::string> begin(stringStream);
1438 <  std::istream_iterator<std::string> end;
1439 <  std::vector<std::string> stringVector(begin, end);
1436 >  stringstream stringStream(inputString);
1437 >  istream_iterator<string> begin(stringStream);
1438 >  istream_iterator<string> end;
1439 >  vector<string> stringVector(begin, end);
1440    return stringVector;
1441  
1442   }
1443  
1444 +
1445 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1446 +  // Set two object strings from the tempInputCollection string,
1447 +  // For example, if tempInputCollection is "electron-muon pairs",
1448 +  // then obj1 = "electrons" and obj2 = "muons".
1449 +  // Note that the objects have an "s" appended.
1450 +
1451 +  int dashIndex = tempInputCollection.find("-");
1452 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1453 +  int secondWordLength = spaceIndex - dashIndex;
1454 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1455 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1456 +
1457 + }
1458 +
1459 +
1460 + string OSUAnalysis::getObjToGet(string obj) {
1461 +  // Return the string corresponding to the object to get for the given obj string.
1462 +  // Right now this only handles the case in which obj contains "secondary",
1463 +  // e.g, "secondary muons".
1464 +  // Note that "s" is NOT appended.
1465 +
1466 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1467 +  int firstSpaceIndex = obj.find_first_of(" ");
1468 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1469 +
1470 + }
1471 +
1472 +
1473 + //!jet valueLookup
1474   double
1475 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1475 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1476  
1477    double value = 0.0;
1478    if(variable == "energy") value = object->energy;
# Line 864 | Line 1591 | OSUAnalysis::valueLookup (const BNjet* o
1591    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1592    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1593  
1594 +  //user defined variable
1595 +  else if(variable == "disappTrkLeadingJetID") {
1596 +    value = object->pt > 110
1597 +      && fabs(object->eta) < 2.4
1598 +      && object->chargedHadronEnergyFraction > 0.2
1599 +      && object->neutralHadronEnergyFraction < 0.7
1600 +      && object->chargedEmEnergyFraction < 0.5
1601 +      && object->neutralEmEnergyFraction < 0.7;
1602 +  }
1603 +
1604 +  else if(variable == "disappTrkSubLeadingJetID") {
1605 +    value = object->pt > 30
1606 +      && fabs(object->eta) < 4.5
1607 +      && object->neutralHadronEnergyFraction < 0.7
1608 +      && object->chargedEmEnergyFraction < 0.5;
1609 +  }
1610 +
1611 +  else if(variable == "dPhiMet") {
1612 +    if (const BNmet *met = chosenMET ()) {
1613 +      value = deltaPhi (object->phi, met->phi);
1614 +    } else value = -999;
1615 +  }
1616  
1617 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1617 >
1618 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1619  
1620    value = applyFunction(function, value);
1621  
1622    return value;
1623 < }
874 <
1623 > } // end jet valueLookup
1624  
1625  
1626 + //!muon valueLookup
1627   double
1628 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1628 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1629  
1630    double value = 0.0;
1631    if(variable == "energy") value = object->energy;
# Line 967 | Line 1717 | OSUAnalysis::valueLookup (const BNmuon*
1717    else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1718    else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1719    else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1720 +  else if(variable == "chargedHadronIsoDR04") value = object->chargedHadronIsoDR04;
1721 +  else if(variable == "neutralHadronIsoDR04") value = object->neutralHadronIsoDR04;
1722 +  else if(variable == "photonIsoDR04") value = object->photonIsoDR04;
1723 +  else if(variable == "puChargedHadronIsoDR04") value = object->puChargedHadronIsoDR04;
1724    else if(variable == "rhoPrime") value = object->rhoPrime;
1725    else if(variable == "AEffDr03") value = object->AEffDr03;
1726    else if(variable == "AEffDr04") value = object->AEffDr04;
# Line 974 | Line 1728 | OSUAnalysis::valueLookup (const BNmuon*
1728    else if(variable == "pfIsoR03SumNeutralHadronEt") value = object->pfIsoR03SumNeutralHadronEt;
1729    else if(variable == "pfIsoR03SumPhotonEt") value = object->pfIsoR03SumPhotonEt;
1730    else if(variable == "pfIsoR03SumPUPt") value = object->pfIsoR03SumPUPt;
1731 +  else if(variable == "relpfIsoR04SumExceptChargedHad") value = (object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)/ object->pt;
1732 +  else if(variable == "relpfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt/object->pt;
1733 +  else if(variable == "relpfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt/object->pt;
1734 +  else if(variable == "relpfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt/object->pt;
1735 +  else if(variable == "relpfIsoR04SumPUPt") value = object->pfIsoR04SumPUPt/object->pt;
1736    else if(variable == "pfIsoR04SumChargedHadronPt") value = object->pfIsoR04SumChargedHadronPt;
1737    else if(variable == "pfIsoR04SumNeutralHadronEt") value = object->pfIsoR04SumNeutralHadronEt;
1738    else if(variable == "pfIsoR04SumPhotonEt") value = object->pfIsoR04SumPhotonEt;
# Line 1030 | Line 1789 | OSUAnalysis::valueLookup (const BNmuon*
1789    else if(variable == "time_ndof") value = object->time_ndof;
1790  
1791    //user-defined variables
1792 +  else if(variable == "looseID") {
1793 +    value = object->pt > 10 &&
1794 +      (object->isGlobalMuon  > 0 ||
1795 +       object->isTrackerMuon > 0);
1796 +  }
1797    else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1798    else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1799    else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1800    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1801 +  else if(variable == "relPFdBetaIsoPseudo") value = (object->pfIsoR04SumChargedHadronPt + object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt) / object->pt;
1802    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1803    else if(variable == "metMT") {
1804 <    const BNmet *met = chosenMET ();
1040 <    if (met)
1804 >    if (const BNmet *met = chosenMET ())
1805        {
1806 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1807 <                       p2 (met->px, met->py, 0.0, met->pt);
1044 <
1045 <        value = (p1 + p2).Mt ();
1806 >        double dPhi = deltaPhi (object->phi, met->phi);
1807 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1808        }
1809      else
1810        value = -999;
# Line 1169 | Line 1931 | OSUAnalysis::valueLookup (const BNmuon*
1931    }
1932    else if(variable == "tightIDdisplaced"){
1933      value = object->isGlobalMuon > 0                \
1934 +      && object->isPFMuon > 0                        \
1935        && object->normalizedChi2 < 10                \
1936        && object->numberOfValidMuonHits > 0        \
1937        && object->numberOfMatchedStations > 1        \
# Line 1176 | Line 1939 | OSUAnalysis::valueLookup (const BNmuon*
1939        && object->numberOfLayersWithMeasurement > 5;
1940    }
1941  
1942 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1943  
1944 +  else if(variable == "genMatchedPdgId"){
1945 +    int index = getGenMatchedParticleIndex(object);
1946 +    if(index == -1) value = 0;
1947 +    else value = mcparticles->at(index).id;
1948 +  }
1949  
1950    else if(variable == "genMatchedId"){
1951      int index = getGenMatchedParticleIndex(object);
# Line 1188 | Line 1957 | OSUAnalysis::valueLookup (const BNmuon*
1957      if(index == -1) value = 0;
1958      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1959    }
1960 +  else if(variable == "genMatchedMotherIdReverse"){
1961 +    int index = getGenMatchedParticleIndex(object);
1962 +    if(index == -1) value = 24;
1963 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1964 +  }
1965    else if(variable == "genMatchedGrandmotherId"){
1966      int index = getGenMatchedParticleIndex(object);
1967      if(index == -1) value = 0;
# Line 1198 | Line 1972 | OSUAnalysis::valueLookup (const BNmuon*
1972      }
1973      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1974    }
1975 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1976 +    int index = getGenMatchedParticleIndex(object);
1977 +    if(index == -1) value = 24;
1978 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1979 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1980 +      if(motherIndex == -1) value = 24;
1981 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1982 +    }
1983 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1984 +  }
1985 +  else if(variable == "pfMuonsFromVertex"){
1986 +    double d0Error, dzError;
1987 +
1988 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1989 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1990 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1991 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1992 +      || fabs (object->correctedDZ / dzError) > 99.0;
1993 +    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1994 +  }
1995  
1996  
1997  
1998 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1998 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1999  
2000    value = applyFunction(function, value);
2001  
2002    return value;
2003 < }
2003 > } // end muon valueLookup
2004  
2005  
2006 + //!electron valueLookup
2007   double
2008 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
2008 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
2009  
2010    double value = 0.0;
2011    if(variable == "energy") value = object->energy;
# Line 1375 | Line 2170 | OSUAnalysis::valueLookup (const BNelectr
2170    else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2171    else if(variable == "detIso") value = (object->trackIso) / object->pt;
2172    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2173 +  else if(variable == "relPFrhoIsoEB") value = object->isEB ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2174 +  else if(variable == "relPFrhoIsoEE") value = object->isEE ? ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt : -999;
2175    else if(variable == "metMT") {
2176 <    const BNmet *met = chosenMET ();
1380 <    if (met)
2176 >    if (const BNmet *met = chosenMET ())
2177        {
2178 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
2179 <                       p2 (met->px, met->py, 0.0, met->pt);
1384 <
1385 <        value = (p1 + p2).Mt ();
2178 >        double dPhi = deltaPhi (object->phi, met->phi);
2179 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2180        }
2181      else
2182        value = -999;
# Line 1449 | Line 2243 | OSUAnalysis::valueLookup (const BNelectr
2243      else value = -999;
2244    }
2245  
2246 +  else if(variable == "looseID"){
2247 +    if (object->isEB)
2248 +      {
2249 +        value = fabs(object->delEtaIn) < 0.007 \
2250 +          && fabs (object->delPhiIn) < 0.15 \
2251 +          && object->scSigmaIEtaIEta < 0.01 \
2252 +          && object->hadOverEm < 0.12 \
2253 +          && fabs (object->correctedD0Vertex) < 0.02 \
2254 +          && fabs (object->correctedDZ) < 0.2 \
2255 +          && object->absInvEMinusInvPin < 0.05 \
2256 +          && object->passConvVeto;
2257 +      }
2258 +    else
2259 +      {
2260 +        value = fabs(object->delEtaIn) < 0.009 \
2261 +          && fabs (object->delPhiIn) < 0.10 \
2262 +          && object->scSigmaIEtaIEta < 0.03 \
2263 +          && object->hadOverEm < 0.10 \
2264 +          && fabs (object->correctedD0Vertex) < 0.02 \
2265 +          && fabs (object->correctedDZ) < 0.2 \
2266 +          && object->absInvEMinusInvPin < 0.05 \
2267 +          && object->passConvVeto;
2268 +      }
2269 +  }
2270 +
2271    else if(variable == "tightID"){
2272      if (object->isEB)
2273        {
# Line 1474 | Line 2293 | OSUAnalysis::valueLookup (const BNelectr
2293        }
2294    }
2295  
2296 +  else if(variable == "looseID_MVA"){
2297 +    value = object->pt > 10
2298 +      && object->mvaNonTrigV0 > 0;
2299 +      }
2300    else if(variable == "correctedD0VertexInEBPositiveCharge"){
2301      if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2302      else value = -999;
# Line 1546 | Line 2369 | OSUAnalysis::valueLookup (const BNelectr
2369        }
2370    }
2371  
2372 +
2373 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2374 +
2375 +  else if(variable == "genMatchedPdgId"){
2376 +    int index = getGenMatchedParticleIndex(object);
2377 +    if(index == -1) value = 0;
2378 +    else value = mcparticles->at(index).id;
2379 +  }
2380 +
2381 +
2382    else if(variable == "genMatchedId"){
2383      int index = getGenMatchedParticleIndex(object);
2384      if(index == -1) value = 0;
# Line 1556 | Line 2389 | OSUAnalysis::valueLookup (const BNelectr
2389      if(index == -1) value = 0;
2390      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2391    }
2392 +  else if(variable == "genMatchedMotherIdReverse"){
2393 +    int index = getGenMatchedParticleIndex(object);
2394 +    if(index == -1) value = 24;
2395 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2396 +  }
2397    else if(variable == "genMatchedGrandmotherId"){
2398      int index = getGenMatchedParticleIndex(object);
2399      if(index == -1) value = 0;
# Line 1566 | Line 2404 | OSUAnalysis::valueLookup (const BNelectr
2404      }
2405      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2406    }
2407 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2408 +    int index = getGenMatchedParticleIndex(object);
2409 +    if(index == -1) value = 24;
2410 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2411 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2412 +      if(motherIndex == -1) value = 24;
2413 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2414 +    }
2415 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2416 +  }
2417 +  else if(variable == "pfElectronsFromVertex"){
2418 +    double d0Error, dzError;
2419  
2420 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2421 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2422 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2423 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2424 +      || fabs (object->correctedDZ / dzError) > 99.0;
2425 +    value = !value;
2426 +  }
2427  
2428  
2429 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2429 >
2430 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2431  
2432    value = applyFunction(function, value);
2433  
2434    return value;
2435 < }
2435 > } // end electron valueLookup
2436  
2437  
2438 + //!event valueLookup
2439   double
2440 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2440 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2441  
2442    double value = 0.0;
2443  
# Line 1586 | Line 2445 | OSUAnalysis::valueLookup (const BNevent*
2445    else if(variable == "pthat") value = object->pthat;
2446    else if(variable == "qScale") value = object->qScale;
2447    else if(variable == "alphaQCD") value = object->alphaQCD;
2448 +  else if(variable == "Ht") value = getHt(jets.product());
2449    else if(variable == "alphaQED") value = object->alphaQED;
2450    else if(variable == "scalePDF") value = object->scalePDF;
2451    else if(variable == "x1") value = object->x1;
# Line 1647 | Line 2507 | OSUAnalysis::valueLookup (const BNevent*
2507    else if(variable == "id2") value = object->id2;
2508    else if(variable == "evt") value = object->evt;
2509    else if(variable == "puScaleFactor"){
2510 <    if(datasetType_ != "data")
2510 >    if(doPileupReweighting_ && datasetType_ != "data")
2511        value = puWeight_->at (events->at (0).numTruePV);
2512      else
2513        value = 1.0;
2514    }
2515 <  else if(variable == "muonScaleFactor"){
2516 <    if(datasetType_ != "data")
2517 <      value = muonSFWeight_->at (chosenMuon ()->eta);
2518 <    else
2519 <      value = 1.0;
2520 <  }
2521 <  else if(variable == "electronScaleFactor"){
2522 <    if(datasetType_ != "data")
2523 <      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
2524 <    else
2525 <      value = 1.0;
2515 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2516 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2517 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2518 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2519 >  else if(variable == "ht") value = chosenHT ();
2520 >  else if(variable == "leadMuPairInvMass"){
2521 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2522 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2523 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2524 >    value = (p0 + p1).M ();
2525 >  }
2526 >  else if(variable == "leadMuPairPt"){
2527 >    pair<const BNmuon *, const BNmuon *> muPair = leadMuonPair ();
2528 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2529 >             pt1 (muPair.second->px, muPair.second->py);
2530 >    pt0 += pt1;
2531 >    value = pt0.Mod ();
2532 >  }
2533 >  else if(variable == "leadElPairInvMass"){
2534 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2535 >    TLorentzVector p0 (muPair.first->px, muPair.first->py, muPair.first->pz, muPair.first->energy),
2536 >                   p1 (muPair.second->px, muPair.second->py, muPair.second->pz, muPair.second->energy);
2537 >    value = (p0 + p1).M ();
2538 >  }
2539 >  else if(variable == "leadElPairPt"){
2540 >    pair<const BNelectron *, const BNelectron *> muPair = leadElectronPair ();
2541 >    TVector2 pt0 (muPair.first->px, muPair.first->py),
2542 >             pt1 (muPair.second->px, muPair.second->py);
2543 >    pt0 += pt1;
2544 >    value = pt0.Mod ();
2545    }
2546 <
1668 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2546 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2547  
2548    value = applyFunction(function, value);
2549  
2550    return value;
2551 < }
2551 > } // end event valueLookup
2552 >
2553  
2554 + //!tau valueLookup
2555   double
2556 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2556 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2557  
2558    double value = 0.0;
2559  
# Line 1717 | Line 2597 | OSUAnalysis::valueLookup (const BNtau* o
2597    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2598    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2599  
2600 +  else if (variable == "looseHadronicID") {
2601 +    value = object->pt > 10
2602 +      && object->eta < 2.3
2603 +      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2604 +      && object->HPSdecayModeFinding > 0
2605 +      && object->HPSagainstElectronLoose > 0
2606 +      && object->HPSagainstMuonTight > 0;
2607 +  }
2608 +
2609 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2610 +
2611 +  else if(variable == "genMatchedPdgId"){
2612 +    int index = getGenMatchedParticleIndex(object);
2613 +    if(index == -1) value = 0;
2614 +    else value = mcparticles->at(index).id;
2615 +  }
2616  
2617    else if(variable == "genMatchedId"){
2618      int index = getGenMatchedParticleIndex(object);
# Line 1728 | Line 2624 | OSUAnalysis::valueLookup (const BNtau* o
2624      if(index == -1) value = 0;
2625      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2626    }
2627 +  else if(variable == "genMatchedMotherIdReverse"){
2628 +    int index = getGenMatchedParticleIndex(object);
2629 +    if(index == -1) value = 24;
2630 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2631 +  }
2632    else if(variable == "genMatchedGrandmotherId"){
2633      int index = getGenMatchedParticleIndex(object);
2634      if(index == -1) value = 0;
# Line 1738 | Line 2639 | OSUAnalysis::valueLookup (const BNtau* o
2639      }
2640      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2641    }
2642 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2643 +    int index = getGenMatchedParticleIndex(object);
2644 +    if(index == -1) value = 24;
2645 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2646 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2647 +      if(motherIndex == -1) value = 24;
2648 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2649 +    }
2650 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2651 +  }
2652  
2653  
2654 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2654 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2655  
2656    value = applyFunction(function, value);
2657  
2658    return value;
2659 < }
2659 > } // end tau valueLookup
2660  
2661 +
2662 + //!met valueLookup
2663   double
2664 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2664 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2665  
2666    double value = 0.0;
2667  
# Line 1812 | Line 2725 | OSUAnalysis::valueLookup (const BNmet* o
2725    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2726    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2727  
2728 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2728 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2729  
2730    value = applyFunction(function, value);
2731  
2732    return value;
2733 < }
2733 > } // end met valueLookup
2734  
2735 +
2736 + //!track valueLookup
2737   double
2738 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2738 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2739  
2740    double value = 0.0;
2741    double pMag = sqrt(object->pt * object->pt +
2742 <                         object->pz * object->pz);
2742 >                     object->pz * object->pz);
2743  
2744    if(variable == "pt") value = object->pt;
2745    else if(variable == "px") value = object->px;
# Line 1844 | Line 2759 | OSUAnalysis::valueLookup (const BNtrack*
2759    else if(variable == "numValidHits") value = object->numValidHits;
2760    else if(variable == "isHighPurity") value = object->isHighPurity;
2761  
1847
2762    //additional BNs info for disappTrks
2763 <  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2764 <  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2765 <  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2766 <  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2767 <  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2768 <  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2769 <  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2770 <  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
1857 <  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2763 >  else if(variable == "caloEMDeltaRp3")     value = object->caloEMDeltaRp3;
2764 >  else if(variable == "caloHadDeltaRp3")    value = object->caloHadDeltaRp3;
2765 >  else if(variable == "caloEMDeltaRp4")     value = object->caloEMDeltaRp4;
2766 >  else if(variable == "caloHadDeltaRp4")    value = object->caloHadDeltaRp4;
2767 >  else if(variable == "caloEMDeltaRp5")     value = object->caloEMDeltaRp5;
2768 >  else if(variable == "caloHadDeltaRp5")    value = object->caloHadDeltaRp5;
2769 >  else if(variable == "nHitsMissingOuter")  value = object->nHitsMissingOuter;
2770 >  else if(variable == "nHitsMissingInner")  value = object->nHitsMissingInner;
2771    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2772 +  else if(variable == "depTrkRp3")          value = object->depTrkRp3;
2773 +  else if(variable == "trkRelIsoRp3")       value = (object->depTrkRp3 - object->pt) / object->pt;
2774 +  else if(variable == "trkRelIsoRp5")       value = (object->depTrkRp5 - object->pt) / object->pt;
2775 +  else if(variable == "depEcalRp3")         value = object->depEcalRp3;
2776 +  else if(variable == "depHcalRp3")         value = object->depHcalRp3;
2777 +  else if(variable == "depHoRp3")           value = object->depHoRp3;
2778 +  else if(variable == "nTracksRp3")         value = object->nTracksRp3;
2779 +  else if(variable == "trackerVetoPtRp3")   value = object->trackerVetoPtRp3;
2780 +  else if(variable == "emVetoEtRp3")        value = object->emVetoEtRp3;
2781 +  else if(variable == "hadVetoEtRp3")       value = object->hadVetoEtRp3;
2782 +  else if(variable == "hoVetoEtRp3")        value = object->hoVetoEtRp3;
2783 +  else if(variable == "depTrkRp5")          value = object->depTrkRp5;
2784 +  else if(variable == "depEcalRp5")         value = object->depEcalRp5;
2785 +  else if(variable == "depHcalRp5")         value = object->depHcalRp5;
2786 +  else if(variable == "depHoRp5")           value = object->depHoRp5;
2787 +  else if(variable == "nTracksRp5")         value = object->nTracksRp5;
2788 +  else if(variable == "trackerVetoPtRp5")   value = object->trackerVetoPtRp5;
2789 +  else if(variable == "emVetoEtRp5")        value = object->emVetoEtRp5;
2790 +  else if(variable == "hadVetoEtRp5")       value = object->hadVetoEtRp5;
2791 +  else if(variable == "hoVetoEtRp5")        value = object->hoVetoEtRp5;
2792 +
2793    //user defined variables
2794    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;
2795    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2796 <  else if(variable == "caloTotDeltaRp5") value =(object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2797 <  else if(variable == "caloTotDeltaRp5ByP") value =( (object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2798 <  else if(variable == "isIso") value = getTrkIsIso(object, tracks.product());
2799 <  else if(variable == "isMatchedDeadEcal") value = getTrkIsMatchedDeadEcal(object);
2800 <  else if(variable == "ptErrorByPt") value = (object->ptError/object->pt);
2801 <  else if(variable == "ptError") value = object->ptError;
2802 <  else if(variable == "ptRes") value = getTrkPtRes(object);
2796 >  else if(variable == "depTrkRp5MinusPt"){
2797 >    if ( (object->depTrkRp5 - object->pt) < 0 ) {
2798 > //       cout << "Warning:  found track with depTrkRp5 < pt:  depTrkRp5=" << object->depTrkRp5
2799 > //         << "; pt=" << object->pt
2800 > //         << "; object->depTrkRp5 - object->pt = " << object->depTrkRp5 - object->pt
2801 > //         << endl;  
2802 >           value = 0;
2803 >         }
2804 >         else value =  (object->depTrkRp5 - object->pt);
2805 >  }
2806 >  else if(variable == "depTrkRp3MinusPt"){
2807 >    if ( (object->depTrkRp3 - object->pt) < 0 ) {
2808 >      value = 0;
2809 >    }
2810 >    else value =  (object->depTrkRp3 - object->pt);
2811 >  }
2812 >
2813 >  else if(variable == "dPhiMet") {
2814 >    if (const BNmet *met = chosenMET ()) {
2815 >      value = deltaPhi (object->phi, met->phi);
2816 >    } else value = -999;
2817 >  }
2818 >  
2819 >  
2820 >  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2821 >  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2822 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2823 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2824 >  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2825 >  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2826 >  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2827 >  else if(variable == "ptError")                    value = object->ptError;
2828 >  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2829 >  else if (variable == "d0wrtPV"){
2830 >    double vx = object->vx - chosenVertex ()->x,
2831 >      vy = object->vy - chosenVertex ()->y,
2832 >      px = object->px,
2833 >      py = object->py,
2834 >      pt = object->pt;
2835 >    value = (-vx * py + vy * px) / pt;
2836 >  }
2837 >  else if (variable == "dZwrtPV"){
2838 >    double vx = object->vx - chosenVertex ()->x,
2839 >      vy = object->vy - chosenVertex ()->y,
2840 >      vz = object->vz - chosenVertex ()->z,
2841 >      px = object->px,
2842 >      py = object->py,
2843 >      pz = object->pz,
2844 >      pt = object->pt;
2845 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2846 >  }
2847 >
2848 >
2849 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2850 >
2851 >  else if(variable == "genMatchedPdgId"){
2852 >    int index = getGenMatchedParticleIndex(object);
2853 >    if(index == -1) value = 0;
2854 >    else value = mcparticles->at(index).id;
2855 >  }
2856  
2857  
2858    else if(variable == "genMatchedId"){
# Line 1878 | Line 2865 | OSUAnalysis::valueLookup (const BNtrack*
2865      if(index == -1) value = 0;
2866      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2867    }
2868 +  else if(variable == "genMatchedMotherIdReverse"){
2869 +    int index = getGenMatchedParticleIndex(object);
2870 +    if(index == -1) value = 24;
2871 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2872 +  }
2873    else if(variable == "genMatchedGrandmotherId"){
2874      int index = getGenMatchedParticleIndex(object);
2875      if(index == -1) value = 0;
# Line 1888 | Line 2880 | OSUAnalysis::valueLookup (const BNtrack*
2880      }
2881      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2882    }
2883 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2884 +    int index = getGenMatchedParticleIndex(object);
2885 +    if(index == -1) value = 24;
2886 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2887 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2888 +      if(motherIndex == -1) value = 24;
2889 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2890 +    }
2891 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2892 +  }
2893  
2894  
2895  
2896 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2896 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2897  
2898    value = applyFunction(function, value);
2899  
2900    return value;
2901 < }
2901 > } // end track valueLookup
2902  
2903 +
2904 + //!genjet valueLookup
2905   double
2906 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2906 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2907  
2908    double value = 0.0;
2909  
# Line 1919 | Line 2923 | OSUAnalysis::valueLookup (const BNgenjet
2923    else if(variable == "charge") value = object->charge;
2924  
2925  
2926 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2926 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2927  
2928    value = applyFunction(function, value);
2929  
2930    return value;
2931   }
2932  
2933 + //!mcparticle valueLookup
2934   double
2935 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2935 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2936  
2937    double value = 0.0;
2938  
# Line 2052 | Line 3057 | OSUAnalysis::valueLookup (const BNmcpart
3057    }
3058  
3059  
3060 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3060 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3061  
3062    value = applyFunction(function, value);
3063  
3064    return value;
3065 < }
3065 > } // end mcparticle valueLookup
3066  
3067 +
3068 + //!primaryvertex valueLookup
3069   double
3070 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
3070 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
3071  
3072    double value = 0.0;
3073  
# Line 2079 | Line 3086 | OSUAnalysis::valueLookup (const BNprimar
3086    else if(variable == "isGood") value = object->isGood;
3087  
3088  
3089 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3089 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3090  
3091    value = applyFunction(function, value);
3092  
3093    return value;
3094   }
3095  
3096 + //!bxlumi valueLookup
3097   double
3098 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
3098 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
3099  
3100    double value = 0.0;
3101  
# Line 2096 | Line 3104 | OSUAnalysis::valueLookup (const BNbxlumi
3104    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
3105  
3106  
3107 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3107 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3108  
3109    value = applyFunction(function, value);
3110  
3111    return value;
3112   }
3113  
3114 + //!photon valueLookup
3115   double
3116 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
3116 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
3117  
3118    double value = 0.0;
3119  
# Line 2179 | Line 3188 | OSUAnalysis::valueLookup (const BNphoton
3188    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
3189  
3190  
3191 +
3192 +
3193 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
3194 +
3195 +  else if(variable == "genMatchedPdgId"){
3196 +    int index = getGenMatchedParticleIndex(object);
3197 +    if(index == -1) value = 0;
3198 +    else value = mcparticles->at(index).id;
3199 +  }
3200 +
3201 +
3202 +
3203    else if(variable == "genMatchedId"){
3204      int index = getGenMatchedParticleIndex(object);
3205      if(index == -1) value = 0;
# Line 2189 | Line 3210 | OSUAnalysis::valueLookup (const BNphoton
3210      if(index == -1) value = 0;
3211      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
3212    }
3213 +  else if(variable == "genMatchedMotherIdReverse"){
3214 +    int index = getGenMatchedParticleIndex(object);
3215 +    if(index == -1) value = 24;
3216 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
3217 +  }
3218    else if(variable == "genMatchedGrandmotherId"){
3219      int index = getGenMatchedParticleIndex(object);
3220      if(index == -1) value = 0;
# Line 2199 | Line 3225 | OSUAnalysis::valueLookup (const BNphoton
3225      }
3226      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3227    }
3228 +  else if(variable == "genMatchedGrandmotherIdReverse"){
3229 +    int index = getGenMatchedParticleIndex(object);
3230 +    if(index == -1) value = 24;
3231 +    else if(fabs(mcparticles->at(index).motherId) == 15){
3232 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3233 +      if(motherIndex == -1) value = 24;
3234 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3235 +    }
3236 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3237 +  }
3238  
3239  
3240 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3240 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3241  
3242    value = applyFunction(function, value);
3243  
3244    return value;
3245 < }
3245 > } // end photon valueLookup
3246 >
3247  
3248 + //!supercluster valueLookup
3249   double
3250 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
3250 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
3251  
3252    double value = 0.0;
3253  
# Line 2223 | Line 3261 | OSUAnalysis::valueLookup (const BNsuperc
3261    else if(variable == "theta") value = object->theta;
3262  
3263  
3264 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3264 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3265  
3266    value = applyFunction(function, value);
3267  
3268    return value;
3269   }
3270  
3271 + //!trigobj valueLookup
3272 + double
3273 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3274 +
3275 +  double value = 0.0;
3276 +
3277 +  if(variable == "pt") value = object->pt;
3278 +  else if(variable == "eta") value = object->eta;
3279 +  else if(variable == "phi") value = object->phi;
3280 +  else if(variable == "px") value = object->px;
3281 +  else if(variable == "py") value = object->py;
3282 +  else if(variable == "pz") value = object->pz;
3283 +  else if(variable == "et") value = object->et;
3284 +  else if(variable == "energy") value = object->energy;
3285 +  else if(variable == "etTotal") value = object->etTotal;
3286 +  else if(variable == "id") value = object->id;
3287 +  else if(variable == "charge") value = object->charge;
3288 +  else if(variable == "isIsolated") value = object->isIsolated;
3289 +  else if(variable == "isMip") value = object->isMip;
3290 +  else if(variable == "isForward") value = object->isForward;
3291 +  else if(variable == "isRPC") value = object->isRPC;
3292 +  else if(variable == "bx") value = object->bx;
3293 +  else if(variable == "filter") {
3294 +    if ((stringValue = object->filter) == "")
3295 +      stringValue = "none";  // stringValue should only be empty if value is filled
3296 +  }
3297 +
3298 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3299 +
3300 +  value = applyFunction(function, value);
3301 +
3302 +  return value;
3303 + }
3304  
3305 + //!muon-muon pair valueLookup
3306   double
3307 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
3307 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3308  
3309    double value = 0.0;
3310  
3311    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3312 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3313    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3314    else if(variable == "invMass"){
3315      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3316      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3317      value = (fourVector1 + fourVector2).M();
3318    }
3319 +  else if(variable == "pt"){
3320 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3321 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3322 +    value = (fourVector1 + fourVector2).Pt();
3323 +  }
3324    else if(variable == "threeDAngle")
3325      {
3326        TVector3 threeVector1(object1->px, object1->py, object1->pz);
# Line 2273 | Line 3351 | OSUAnalysis::valueLookup (const BNmuon*
3351    else if(variable == "muon2CorrectedD0Vertex"){
3352      value = object2->correctedD0Vertex;
3353    }
3354 < else if(variable == "muon1timeAtIpInOut"){
3354 >  else if(variable == "muon1timeAtIpInOut"){
3355      value = object1->timeAtIpInOut;
3356    }
3357 < else if(variable == "muon2timeAtIpInOut"){
3357 >  else if(variable == "muon2timeAtIpInOut"){
3358      value = object2->timeAtIpInOut;
3359    }
3360 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3360 >  else if(variable == "muon1correctedD0")
3361 >    {
3362 >      value = object1->correctedD0;
3363 >    }
3364 >  else if(variable == "muon2correctedD0")
3365 >    {
3366 >      value = object2->correctedD0;
3367 >    }
3368 >
3369 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3370 >
3371 >  value = applyFunction(function, value);
3372 >
3373 >  return value;
3374 > } // end muon-muon pair valueLookup
3375 >
3376 >
3377 > //!muon-photon pair valueLookup
3378 > double
3379 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3380 >
3381 >  double value = 0.0;
3382 >
3383 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3384 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3385 >  else if(variable == "photonEta") value = object2->eta;
3386 >  else if(variable == "photonPt") value = object2->pt;
3387 >  else if(variable == "muonEta") value = object1->eta;
3388 >  else if(variable == "photonPhi") value = object2->phi;
3389 >  else if(variable == "muonPhi") value = object1->phi;
3390 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3391 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3392 >  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3393 >  else if(variable == "invMass"){
3394 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3395 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3396 >    value = (fourVector1 + fourVector2).M();
3397 >  }
3398 >  else if(variable == "pt"){
3399 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3400 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3401 >    value = (fourVector1 + fourVector2).Pt();
3402 >  }
3403 >  else if(variable == "threeDAngle")
3404 >    {
3405 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3406 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3407 >      value = (threeVector1.Angle(threeVector2));
3408 >    }
3409 >  else if(variable == "alpha")
3410 >    {
3411 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3412 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3413 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3414 >      value = (pi-threeVector1.Angle(threeVector2));
3415 >    }
3416 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3417  
3418    value = applyFunction(function, value);
3419  
3420    return value;
3421   }
3422  
3423 + //!electron-photon pair valueLookup
3424   double
3425 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
3425 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3426  
3427    double value = 0.0;
3428  
3429    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3430 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3431 +  else if(variable == "photonEta") value = object2->eta;
3432 +  else if(variable == "photonPt") value = object2->pt;
3433 +  else if(variable == "electronEta") value = object1->eta;
3434 +  else if(variable == "photonPhi") value = object2->phi;
3435 +  else if(variable == "electronPhi") value = object1->phi;
3436    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3437 +  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3438 +  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3439    else if(variable == "invMass"){
3440      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3441      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3442      value = (fourVector1 + fourVector2).M();
3443    }
3444 +  else if(variable == "pt"){
3445 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3446 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3447 +    value = (fourVector1 + fourVector2).Pt();
3448 +  }
3449 +  else if(variable == "threeDAngle")
3450 +    {
3451 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3452 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3453 +      value = (threeVector1.Angle(threeVector2));
3454 +    }
3455 +  else if(variable == "alpha")
3456 +    {
3457 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3458 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3459 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3460 +      value = (pi-threeVector1.Angle(threeVector2));
3461 +    }
3462 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3463 +
3464 +  value = applyFunction(function, value);
3465 +
3466 +  return value;
3467 + }
3468 +
3469 + //!electron-electron pair valueLookup
3470 + double
3471 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3472 +
3473 +  double value = 0.0;
3474 +
3475 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3476 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3477 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3478 +  else if(variable == "invMass"){
3479 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3480 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3481 +    value = (fourVector1 + fourVector2).M();
3482 +  }
3483 +  else if(variable == "pt"){
3484 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3485 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3486 +    value = (fourVector1 + fourVector2).Pt();
3487 +  }
3488    else if(variable == "threeDAngle")
3489      {
3490        TVector3 threeVector1(object1->px, object1->py, object1->pz);
# Line 2321 | Line 3508 | OSUAnalysis::valueLookup (const BNelectr
3508    else if(variable == "electron2CorrectedD0Vertex"){
3509      value = object2->correctedD0Vertex;
3510    }
3511 +  else if(variable == "electron1CorrectedD0"){
3512 +    value = object1->correctedD0;
3513 +  }
3514 +  else if(variable == "electron2CorrectedD0"){
3515 +    value = object2->correctedD0;
3516 +  }
3517  
3518 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3518 >  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3519  
3520    value = applyFunction(function, value);
3521  
3522    return value;
3523   }
3524  
3525 + //!electron-muon pair valueLookup
3526   double
3527 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3527 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3528  
3529    double value = 0.0;
3530  
3531    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3532 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3533    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3534    else if(variable == "invMass"){
3535      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3536      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3537      value = (fourVector1 + fourVector2).M();
3538    }
3539 +  else if(variable == "pt"){
3540 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3541 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3542 +    value = (fourVector1 + fourVector2).Pt();
3543 +  }
3544    else if(variable == "threeDAngle")
3545      {
3546        TVector3 threeVector1(object1->px, object1->py, object1->pz);
# Line 2376 | Line 3576 | OSUAnalysis::valueLookup (const BNelectr
3576    else if(variable == "muonDetIso"){
3577      value = (object2->trackIsoDR03) / object2->pt;
3578    }
3579 +  else if(variable == "electronRelPFrhoIso"){
3580 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3581 +  }
3582 +  else if(variable == "muonRelPFdBetaIso"){
3583 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3584 +  }
3585 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3586 +  value = applyFunction(function, value);
3587 +
3588 +  return value;
3589 + } // end electron-muon pair valueLookup
3590 +
3591 +
3592 + //!electron-jet pair valueLookup
3593 + double
3594 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3595 +
3596 +  double value = 0.0;
3597 +
3598 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3599 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3600 +  else if(variable == "jetEta") value = object2->eta;
3601 +  else if(variable == "jetPhi") value = object2->phi;
3602 +  else if(variable == "electronEta") value = object1->eta;
3603 +  else if(variable == "electronPhi") value = object1->phi;
3604 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3605 +  else if(variable == "invMass"){
3606 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3607 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3608 +    value = (fourVector1 + fourVector2).M();
3609 +  }
3610 +  else if(variable == "pt"){
3611 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3612 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3613 +    value = (fourVector1 + fourVector2).Pt();
3614 +  }
3615 +  else if(variable == "threeDAngle")
3616 +    {
3617 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3618 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3619 +      value = (threeVector1.Angle(threeVector2));
3620 +    }
3621    else if(variable == "chargeProduct"){
3622 <    value = object1->charge * object2->charge;
3622 >    value = object1->charge*object2->charge;
3623    }
3624  
3625 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3626 +  value = applyFunction(function, value);
3627  
3628 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3628 >  return value;
3629 > }
3630 >
3631 > //!photon-jet pair valueLookup
3632 > double
3633 > OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3634  
3635 +  double value = 0.0;
3636 +
3637 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3638 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3639 +  else if(variable == "jetEta") value = object2->eta;
3640 +  else if(variable == "jetPhi") value = object2->phi;
3641 +  else if(variable == "photonEta") value = object1->eta;
3642 +  else if(variable == "photonPhi") value = object1->phi;
3643 +  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3644 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3645 +  else if(variable == "invMass"){
3646 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3647 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3648 +    value = (fourVector1 + fourVector2).M();
3649 +  }
3650 +  else if(variable == "pt"){
3651 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3652 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3653 +    value = (fourVector1 + fourVector2).Pt();
3654 +  }
3655 +  else if(variable == "threeDAngle")
3656 +    {
3657 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3658 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3659 +      value = (threeVector1.Angle(threeVector2));
3660 +    }
3661 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3662    value = applyFunction(function, value);
3663  
3664    return value;
3665   }
3666  
3667 + // track-jet pair valueLookup
3668 + double
3669 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNjet* object2, string variable, string function, string &stringValue){
3670 +
3671 +  double value = 0.0;
3672 +
3673 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3674 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3675 +
3676 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3677 +  value = applyFunction(function, value);
3678 +
3679 +  return value;
3680 +
3681 + }
3682 +
3683 +
3684 +
3685 + // met-jet pair valueLookup
3686 + double
3687 + OSUAnalysis::valueLookup (const BNmet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3688 +
3689 +  double value = 0.0;
3690 +
3691 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3692 +
3693 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3694 +  value = applyFunction(function, value);
3695 +
3696 +  return value;
3697 +
3698 + }  
3699 +
3700 +
3701 +
3702 + //!muon-jet pair valueLookup
3703 + double
3704 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3705 +
3706 +  double value = 0.0;
3707 +
3708 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3709 +  else if(variable == "jetEta") value = object2->eta;
3710 +  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3711 +  else if(variable == "jetPt") value = object2->pt;
3712 +  else if(variable == "jetPhi") value = object2->phi;
3713 +  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3714 +  else if(variable == "muonEta") value = object1->eta;
3715 +  else if(variable == "muonPt") value = object1->pt;
3716 +  else if(variable == "muonPhi") value = object1->phi;
3717 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);          
3718 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3719 +  else if(variable == "invMass"){
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).M();
3723 +  }
3724 +  else if(variable == "pt"){
3725 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3726 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3727 +    value = (fourVector1 + fourVector2).Pt();
3728 +  }
3729 +  else if(variable == "threeDAngle")
3730 +    {
3731 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3732 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3733 +      value = (threeVector1.Angle(threeVector2));
3734 +    }
3735 +  else if(variable == "chargeProduct"){
3736 +    value = object1->charge*object2->charge;
3737 +  }
3738 +
3739 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3740 +  value = applyFunction(function, value);
3741 +
3742 +  return value;
3743 + }
3744 +
3745 + //!muon-event valueLookup
3746 + double
3747 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNevent* object2, string variable, string function, string &stringValue){
3748 +
3749 +  double value = 0.0;
3750 +
3751 +  if(variable == "muonEta") value = object1->eta;
3752 +  else if(variable == "muonPt") value = object1->pt;
3753 +  else if(variable == "muonPhi") value = object1->phi;
3754 +  else if(variable == "Ht") value = getHt(jets.product());
3755 +  else if(variable == "pthat")   value = object2->pthat;
3756 +  else if(variable == "relPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3757 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3758 +  value = applyFunction(function, value);
3759 +
3760 +  return value;
3761 + }
3762 + //!jet-jet pair valueLookup
3763 + double
3764 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3765 +
3766 +  double value = 0.0;
3767 +
3768 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3769 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3770 +  else if(variable == "deltaPt") value = object1->pt - object2->pt;
3771 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3772 +  else if(variable == "invMass"){
3773 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3774 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3775 +    value = (fourVector1 + fourVector2).M();
3776 +  }
3777 +  else if(variable == "pt"){
3778 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3779 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3780 +    value = (fourVector1 + fourVector2).Pt();
3781 +  }
3782 +  else if(variable == "threeDAngle")
3783 +    {
3784 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3785 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3786 +      value = (threeVector1.Angle(threeVector2));
3787 +    }
3788 +  else if(variable == "chargeProduct"){
3789 +    value = object1->charge*object2->charge;
3790 +  }
3791 +
3792 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3793 +  value = applyFunction(function, value);
3794 +
3795 +  return value;
3796 + }
3797 +
3798 + //!electron-track pair valueLookup
3799 + double
3800 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3801 +  double electronMass = 0.000511;
3802 +  double value = 0.0;
3803 +  TLorentzVector fourVector1(0, 0, 0, 0);
3804 +  TLorentzVector fourVector2(0, 0, 0, 0);
3805 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3806 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3807 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3808 +  else if(variable == "invMass"){
3809 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3810 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3811 +
3812 +    value = (fourVector1 + fourVector2).M();
3813 +  }
3814 +  else if(variable == "chargeProduct"){
3815 +    value = object1->charge*object2->charge;
3816 +  }
3817 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3818 +  value = applyFunction(function, value);
3819 +  return value;
3820 +
3821 + }
3822 +
3823 +
3824 + //!muon-track pair valueLookup
3825 + double
3826 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3827 +  double pionMass = 0.140;
3828 +  double muonMass = 0.106;
3829 +  double value = 0.0;
3830 +  TLorentzVector fourVector1(0, 0, 0, 0);
3831 +  TLorentzVector fourVector2(0, 0, 0, 0);
3832 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3833 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3834 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3835 +  else if(variable == "invMass"){
3836 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3837 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3838 +
3839 +    value = (fourVector1 + fourVector2).M();
3840 +  }
3841 +  else if(variable == "chargeProduct"){
3842 +    value = object1->charge*object2->charge;
3843 +  }
3844 +
3845 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3846 +  value = applyFunction(function, value);
3847 +  return value;
3848 + }
3849 +
3850 + //!tau-tau pair valueLookup
3851 + double
3852 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3853 +  double value = 0.0;
3854 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3855 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3856 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3857 +  else if(variable == "invMass"){
3858 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3859 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3860 +    value = (fourVector1 + fourVector2).M();
3861 +  }
3862 +
3863 +  else if(variable == "chargeProduct"){
3864 +    value = object1->charge*object2->charge;
3865 +  }
3866 +
3867 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3868 +  value = applyFunction(function, value);
3869 +  return value;
3870 + }
3871 +
3872 + //!muon-tau pair valueLookup
3873 + double
3874 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3875 +  double value = 0.0;
3876 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3877 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3878 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3879 +  else if(variable == "invMass"){
3880 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3881 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3882 +    value = (fourVector1 + fourVector2).M();
3883 +  }
3884 +
3885 +  else if(variable == "chargeProduct"){
3886 +    value = object1->charge*object2->charge;
3887 +  }
3888 +
3889 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3890 +  value = applyFunction(function, value);
3891 +  return value;
3892 + }
3893 +
3894 + //!tau-track pair valueLookup
3895 + double
3896 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3897 +  double value = 0.0;
3898 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3899 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3900 +  else if(variable == "chargeProduct"){
3901 +    value = object1->charge*object2->charge;
3902 +  }
3903 +
3904 +  else{clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3905 +  value = applyFunction(function, value);
3906 +  return value;
3907 + }
3908 +
3909 +
3910 + //!track-event pair valueLookup
3911 + double
3912 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3913 +
3914 +  double value = 0.0;
3915 +  double pMag = sqrt(object1->pt * object1->pt +
3916 +                     object1->pz * object1->pz);
3917 +
3918 +  if      (variable == "numPV")                      value = object2->numPV;
3919 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3920 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3921 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3922 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3923 +
3924 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3925 +
3926 +  value = applyFunction(function, value);
3927 +
3928 +  return value;
3929 +
3930 + }
3931 +
3932 + //!electron-trigobj pair valueLookup
3933 + double
3934 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3935 +
3936 +  double value = 0.0;
3937 +
3938 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3939 +  else if (variable == "match"){
3940 +    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3941 +      stringValue = object2->filter;
3942 +    else
3943 +      stringValue = "none";
3944 +  }
3945 +
3946 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3947 +
3948 +  value = applyFunction(function, value);
3949 +
3950 +  return value;
3951 +
3952 + }
3953 +
3954 + //!muon-trigobj pair valueLookup
3955 + double
3956 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3957 +
3958 +  double value = 0.0;
3959 +
3960 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3961 +
3962 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3963 +
3964 +  value = applyFunction(function, value);
3965 +
3966 +  return value;
3967 +
3968 + }
3969 +
3970 + //!stop valueLookup
3971 + double
3972 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3973 +
3974 +
3975 +  double value = 0.0;
3976 +
3977 +  if(variable == "ctau") value = object->ctau;
3978 +
3979 +  else if (variable == "d0"){
3980 +    double vx = object->vx - chosenVertex ()->x,
3981 +      vy = object->vy - chosenVertex ()->y,
3982 +      px = object->px,
3983 +      py = object->py,
3984 +      pt = object->pt;
3985 +    value = (-vx * py + vy * px) / pt;
3986 +  }
3987 +
3988 +  else if (variable == "dz"){
3989 +    double vx = object->vx - chosenVertex ()->x,
3990 +      vy = object->vy - chosenVertex ()->y,
3991 +      vz = object->vz - chosenVertex ()->z,
3992 +      px = object->px,
3993 +      py = object->py,
3994 +      pz = object->pz,
3995 +      pt = object->pt;
3996 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3997 +  }
3998 +
3999 +  else if (variable == "minD0"){
4000 +    double minD0=999;
4001 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4002 +      double vx = object->vx - vertex->x,
4003 +        vy = object->vy - vertex->y,
4004 +        px = object->px,
4005 +        py = object->py,
4006 +        pt = object->pt;
4007 +      value = (-vx * py + vy * px) / pt;
4008 +      if(abs(value) < abs(minD0)) minD0 = value;
4009 +    }
4010 +    value = minD0;
4011 +  }
4012 +  else if (variable == "minDz"){
4013 +    double minDz=999;
4014 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4015 +      double vx = object->vx - vertex->x,
4016 +        vy = object->vy - vertex->y,
4017 +        vz = object->vz - vertex->z,
4018 +        px = object->px,
4019 +        py = object->py,
4020 +        pz = object->pz,
4021 +        pt = object->pt;
4022 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
4023 +      if(abs(value) < abs(minDz)) minDz = value;
4024 +    }
4025 +    value = minDz;
4026 +  }
4027 +  else if(variable == "distToVertex"){
4028 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4029 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4030 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4031 +  }
4032 +  else if (variable == "minDistToVertex"){
4033 +    double minDistToVertex=999;
4034 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4035 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4036 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4037 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
4038 +
4039 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4040 +    }
4041 +    value = minDistToVertex;
4042 +  }
4043 +  else if (variable == "distToVertexDifference"){
4044 +    double minDistToVertex=999;
4045 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4046 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4047 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
4048 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
4049 +
4050 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
4051 +    }
4052 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
4053 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
4054 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
4055 +
4056 +    value = distToChosenVertex - minDistToVertex;
4057 +  }
4058 +
4059 +  else if (variable == "closestVertexRank"){
4060 +    double minDistToVertex=999;
4061 +    int vertex_rank = 0;
4062 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
4063 +      vertex_rank++;
4064 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
4065 +                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
4066 +                      (object->vz-vertex->z)*(object->vz-vertex->z));
4067 +
4068 +      if(abs(dist) < abs(minDistToVertex)){
4069 +        value = vertex_rank;
4070 +        minDistToVertex = dist;
4071 +      }
4072 +    }
4073 +  }
4074 +
4075 +  else if (variable == "decaysToTau"){
4076 +    value = abs (object->daughter0Id) == 15 || abs (object->daughter1Id) == 15;
4077 +  }
4078 +
4079 +
4080 +
4081 +
4082 +  else { clog << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
4083 +
4084 +  value = applyFunction(function, value);
4085 +
4086 +  return value;
4087 +
4088 + } // end stop valueLookup
4089 +
4090 +
4091 +
4092 +
4093  
4094   // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
4095   // Return true iff no other tracks are found in this cone.
# Line 2402 | Line 4104 | OSUAnalysis::getTrkIsIso (const BNtrack*
4104  
4105   }
4106  
4107 + //calculate the scalar sum of Jet Pt in the event.
4108 + double
4109 + OSUAnalysis::getHt (const BNjetCollection* jetColl){
4110 +  double Ht = 0;
4111 +  for(BNjetCollection::const_iterator jet = jetColl->begin(); jet !=jetColl->end(); jet++){
4112 +    Ht += abs(jet->pt);
4113 +  }
4114 +  return Ht;
4115 + }
4116  
4117   double
4118   OSUAnalysis::getTrkPtRes (const BNtrack* track1){
# Line 2434 | Line 4145 | OSUAnalysis::getTrkPtTrue (const BNtrack
4145  
4146   }
4147  
4148 + double
4149 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
4150 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
4151 +  if (!useTrackCaloRhoCorr_) return -99;
4152 +  // if (!rhokt6CaloJetsHandle_) {
4153 +  //   clog << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
4154 +  //   return -99;
4155 +  // }
4156 +  double radDeltaRCone = 0.5;
4157 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
4158 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
4159 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
4160 +  return caloTotRhoCorrCalo;
4161 +
4162 + }
4163 +
4164 +
4165 +
4166 +
4167   //creates a map of the dead Ecal channels in the barrel and endcap
4168   //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
4169   //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
# Line 2442 | Line 4172 | OSUAnalysis::WriteDeadEcal (){
4172    double etaEcal, phiEcal;
4173    ifstream DeadEcalFile(deadEcalFile_);
4174    if(!DeadEcalFile) {
4175 <    cout << "Error: DeadEcalFile has not been found." << endl;
4175 >    clog << "Error: DeadEcalFile has not been found." << endl;
4176      return;
4177    }
4178    if(DeadEcalVec.size()!= 0){
4179 <    cout << "Error: DeadEcalVec has a nonzero size" << endl;
4179 >    clog << "Error: DeadEcalVec has a nonzero size" << endl;
4180      return;
4181    }
4182    while(!DeadEcalFile.eof())
# Line 2457 | Line 4187 | OSUAnalysis::WriteDeadEcal (){
4187        newChan.phiEcal = phiEcal;
4188        DeadEcalVec.push_back(newChan);
4189      }
4190 <  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
4190 >  if(DeadEcalVec.size() == 0) clog << "Warning: No dead Ecal channels have been found." << endl;
4191   }
4192  
4193   //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
# Line 2466 | Line 4196 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
4196    double deltaRLowest = 999;
4197    int value = 0;
4198    if (DeadEcalVec.size() == 0) WriteDeadEcal();
4199 <  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4199 >  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
4200      double eta = ecal->etaEcal;
4201      double phi = ecal->phiEcal;
4202 <    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
4202 >    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
4203      if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
4204    }
4205    if (deltaRLowest<0.05) {value = 1;}
# Line 2477 | Line 4207 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
4207    return value;
4208   }
4209  
4210 <
4211 <
4210 > // Returns the smallest DeltaR between the object and any generated true particle in the event.
4211 > template <class InputObject>
4212 > double OSUAnalysis::getGenDeltaRLowest(InputObject object){
4213 >  double genDeltaRLowest = 999.;
4214 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
4215 >    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
4216 >    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
4217 >  }
4218 >  return genDeltaRLowest;
4219 > }
4220  
4221   double
4222   OSUAnalysis::applyFunction(string function, double value){
# Line 2489 | Line 4227 | OSUAnalysis::applyFunction(string functi
4227    else if(function == "log") value = log10(value);
4228  
4229    else if(function == "") value = value;
4230 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
4230 >  else{clog << "WARNING: invalid function '" << function << "'\n";}
4231  
4232    return value;
4233  
# Line 2499 | Line 4237 | OSUAnalysis::applyFunction(string functi
4237   template <class InputCollection>
4238   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
4239  
4240 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
4241 +    string obj1, obj2;
4242 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
4243 +    if (inputType==obj1 ||
4244 +        inputType==obj2) {
4245 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
4246 +      // and the inputType is a member of the pair.
4247 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
4248 +      // For example, if currentCut.inputCollection==electron-muon pairs,
4249 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
4250 +      return;
4251 +    }
4252 +  }
4253  
4254    for (uint object = 0; object != inputCollection->size(); object++){
4255  
4256 <
4257 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
2507 <
4256 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4257 >    bool plotDecision = true;
4258  
4259      if(currentCut.inputCollection == inputType){
4260  
4261        vector<bool> subcutDecisions;
4262        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4263 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4264 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4263 >        string stringValue = "";
4264 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4265 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4266 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4267 >
4268        }
4269 <      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4269 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4270        else{
4271          bool tempDecision = true;
4272          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
# Line 2522 | Line 4275 | void OSUAnalysis::setObjectFlags(cut &cu
4275            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
4276              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
4277          }
4278 <        decision = tempDecision;
4278 >        cutDecision = tempDecision;
4279        }
4280 +      //invert the cut for plotting if this cut is a veto
4281 +      if(currentCut.isVeto) plotDecision = !cutDecision;
4282 +      else plotDecision = cutDecision;
4283      }
2528    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4284  
4285 +    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4286  
4287 <    //set flags for objects that pass each cut AND all the previous cuts
4288 <    bool previousCumulativeFlag = true;
4287 >    //set flags for objects that pass this cut AND all the previous cuts
4288 >    bool previousCumulativeCutFlag = true;
4289      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4290 <      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
4291 <      else{ previousCumulativeFlag = false; break;}
4290 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
4291 >      else{ previousCumulativeCutFlag = false; break;}
4292      }
4293 <    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
4293 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4294 >    bool previousCumulativePlotFlag = true;
4295 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4296 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
4297 >      else{ previousCumulativePlotFlag = false; break;}
4298 >    }
4299 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4300  
4301 +    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4302  
4303    }
4304  
# Line 2544 | Line 4307 | void OSUAnalysis::setObjectFlags(cut &cu
4307  
4308   template <class InputCollection1, class InputCollection2>
4309   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
4310 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
4310 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, string inputType){
4311  
4312  
4313    bool sameObjects = false;
4314    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4315  
4316 +  // Get the strings for the two objects that make up the pair.
4317 +  string obj1Type, obj2Type;
4318 +  getTwoObjs(inputType, obj1Type, obj2Type);
4319 +  bool isTwoTypesOfObject = true;
4320 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
4321 +
4322 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
4323 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4324 +  if (currentCut.inputCollection == inputType) {
4325 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4326 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4327 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4328 +    }
4329 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4330 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4331 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4332 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4333 +      }
4334 +    }
4335 +  }
4336  
4337    int counter = 0;
4338 +
4339    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4340      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4341  
4342        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4343  
4344  
4345 <      bool decision = true;//object passes if this cut doesn't cut on that type of object
4345 >      bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4346 >      bool plotDecision = true;
4347  
4348        if(currentCut.inputCollection == inputType){
4349  
4350          vector<bool> subcutDecisions;
4351          for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4352 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4353 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4352 >          string stringValue = "";
4353 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4354 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4355 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4356          }
4357  
4358 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4358 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4359          else{
4360            bool tempDecision = subcutDecisions.at(0);
4361            for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
# Line 2577 | Line 4364 | void OSUAnalysis::setObjectFlags(cut &cu
4364              else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4365                tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4366            }
4367 <          decision = tempDecision;
4367 >          cutDecision = tempDecision;
4368          }
4369 +        //invert the cut for plotting if this cut is a veto
4370 +        if(currentCut.isVeto) plotDecision = !cutDecision;
4371 +        else plotDecision = cutDecision;
4372 +      }
4373 +      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4374 +      if (cutDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4375 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4376 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4377 +      }
4378 +      if (plotDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4379 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4380 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4381 +      }
4382 +
4383 +      //set flags for objects that pass this cut AND all the previous cuts
4384 +      bool previousCumulativeCutFlag = true;
4385 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4386 +        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4387 +        else{ previousCumulativeCutFlag = false; break;}
4388        }
4389 <      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4389 >      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4390  
4391 <      //set flags for objects that pass each cut AND all the previous cuts
2586 <      bool previousCumulativeFlag = true;
4391 >      bool previousCumulativePlotFlag = true;
4392        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4393 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
4394 <        else{ previousCumulativeFlag = false; break;}
4393 >        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4394 >        else{ previousCumulativePlotFlag = false; break;}
4395        }
4396 +      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4397 +      
4398        //apply flags for the components of the composite object as well
4399 <      bool currentCumulativeFlag = true;
4400 <      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
4401 <      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
4402 <      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
4403 <      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
4404 <      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
4399 >      bool currentCumulativeCutFlag = true;
4400 >      bool currentCumulativePlotFlag = true;
4401 >
4402 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4403 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4404 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4405 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4406 >
4407 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4408 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4409 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4410 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4411 >
4412 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));
4413 >
4414 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4415 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4416 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4417 >      }
4418 >
4419 >      if (currentCumulativePlotFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4420 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4421 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4422 >      }
4423  
4424        counter++;
2600    }
4425  
4426 +    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4427 +  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4428 +
4429 + }
4430 +
4431 +
4432 + bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4433 +  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4434 +  // all cuts up to currentCutIndex
4435 +  bool previousCumulativeFlag = true;
4436 +  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4437 +    bool tempFlag = false;
4438 +    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4439 +    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4440 +
4441 +    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4442 +    else {
4443 +      previousCumulativeFlag = false; break;
4444 +    }
4445    }
4446 +  return previousCumulativeFlag;
4447 + }
4448 +
4449  
4450  
4451 +
4452 + template <class InputCollection>
4453 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4454 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4455 +
4456 +  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;
4457 +  for (uint object = 0; object != inputCollection->size(); object++) {
4458 +
4459 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4460 +
4461 +    string inputVariable = parameters.inputVariable;
4462 +    string function = "";
4463 +    string stringValue = "";
4464 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4465 +    BNTreeBranchVals_.at(parameters.name).push_back(value);
4466 +
4467 +  }
4468   }
4469  
4470  
4471   template <class InputCollection>
4472 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4472 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4473 >
4474  
4475    for (uint object = 0; object != inputCollection->size(); object++){
4476  
4477 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4477 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4478  
4479      string currentString = parameters.inputVariables.at(0);
4480      string inputVariable = "";
4481      string function = "";
4482 <    if(currentString.find("(")==std::string::npos){
4482 >    if(currentString.find("(")==string::npos){
4483        inputVariable = currentString;// variable to cut on
4484      }
4485      else{
# Line 2624 | Line 4488 | void OSUAnalysis::fill1DHistogram(TH1* h
4488        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4489      }
4490  
4491 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
4491 >    string stringValue = "";
4492 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4493      histo->Fill(value,scaleFactor);
4494  
4495 <  }
4495 >    if (printEventInfo_) {
4496 >      // Write information about event to screen, for testing purposes.
4497 >      clog << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
4498 >    }
4499  
4500 +  }
4501   }
4502  
4503   template <class InputCollection1, class InputCollection2>
4504 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4504 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4505  
4506    bool sameObjects = false;
4507    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4508  
4509 <  int pairCounter = 0;
4509 >  int pairCounter = -1;
4510    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4511      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4512  
4513        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4514  
4515 +      pairCounter++;
4516        //only take objects which have passed all cuts and pairs which have passed all cuts
4517 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4518 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4519 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4517 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4518 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4519 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4520  
4521        string currentString = parameters.inputVariables.at(0);
4522        string inputVariable = "";
4523        string function = "";
4524 <      if(currentString.find("(")==std::string::npos){
4524 >      if(currentString.find("(")==string::npos){
4525          inputVariable = currentString;// variable to cut on
4526        }
4527        else{
# Line 2660 | Line 4530 | void OSUAnalysis::fill1DHistogram(TH1* h
4530          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4531        }
4532  
4533 <      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4533 >      string stringValue = "";
4534 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4535        histo->Fill(value,scaleFactor);
4536  
2666      pairCounter++;
4537      }
4538    }
4539  
# Line 2671 | Line 4541 | void OSUAnalysis::fill1DHistogram(TH1* h
4541  
4542  
4543   template <class InputCollection>
4544 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4544 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4545  
4546    for (uint object = 0; object != inputCollection->size(); object++){
4547  
4548 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4548 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4549  
4550 +    string stringValue = "";
4551      string currentString = parameters.inputVariables.at(0);
4552      string inputVariable = "";
4553      string function = "";
4554 <    if(currentString.find("(")==std::string::npos){
4554 >    if(currentString.find("(")==string::npos){
4555        inputVariable = currentString;// variable to cut on
4556      }
4557      else{
# Line 2688 | Line 4559 | void OSUAnalysis::fill2DHistogram(TH2* h
4559        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4560        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4561      }
4562 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
4562 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4563  
4564      currentString = parameters.inputVariables.at(1);
4565      inputVariable = "";
4566      function = "";
4567 <    if(currentString.find("(")==std::string::npos){
4567 >    if(currentString.find("(")==string::npos){
4568        inputVariable = currentString;// variable to cut on
4569      }
4570      else{
# Line 2702 | Line 4573 | void OSUAnalysis::fill2DHistogram(TH2* h
4573        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4574      }
4575  
4576 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
4576 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4577  
4578      histo->Fill(valueX,valueY,scaleFactor);
4579  
# Line 2711 | Line 4582 | void OSUAnalysis::fill2DHistogram(TH2* h
4582   }
4583  
4584   template <class InputCollection1, class InputCollection2>
4585 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4585 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4586  
4587    bool sameObjects = false;
4588    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4589  
4590 <  int pairCounter = 0;
4590 >  int pairCounter = -1;
4591    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4592      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4593  
4594        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4595  
4596 +      pairCounter++;
4597 +
4598        //only take objects which have passed all cuts and pairs which have passed all cuts
4599 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4600 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4601 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4599 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4600 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4601 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4602  
4603 +      string stringValue = "";
4604        string currentString = parameters.inputVariables.at(0);
4605        string inputVariable = "";
4606        string function = "";
4607 <      if(currentString.find("(")==std::string::npos){
4607 >      if(currentString.find("(")==string::npos){
4608          inputVariable = currentString;// variable to cut on
4609        }
4610        else{
# Line 2738 | Line 4612 | void OSUAnalysis::fill2DHistogram(TH2* h
4612          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4613          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4614        }
4615 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4615 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4616  
4617        currentString = parameters.inputVariables.at(1);
4618        inputVariable = "";
4619        function = "";
4620 <      if(currentString.find("(")==std::string::npos){
4620 >      if(currentString.find("(")==string::npos){
4621          inputVariable = currentString;// variable to cut on
4622        }
4623        else{
# Line 2751 | Line 4625 | void OSUAnalysis::fill2DHistogram(TH2* h
4625          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4626          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4627        }
4628 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4628 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4629  
4630  
4631        histo->Fill(valueX,valueY,scaleFactor);
4632  
2759      pairCounter++;
2760
4633      }
4634    }
4635  
# Line 2774 | Line 4646 | int OSUAnalysis::getGenMatchedParticleIn
4646  
4647      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4648      if(currentDeltaR > 0.05) continue;
4649 < //     cout << std::setprecision(3) << std::setw(20)
4650 < //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4651 < //          << std::setw(20)
4652 < //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4653 < //          << std::setw(20)
4654 < //          << "\tdeltaR = " << currentDeltaR
4655 < //          << std::setprecision(1)
4656 < //          << std::setw(20)
4657 < //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4658 < //          << std::setw(20)
4659 < //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4660 < //          << std::setw(20)
4661 < //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4649 >    //     clog << setprecision(3) << setw(20)
4650 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4651 >    //          << setw(20)
4652 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4653 >    //          << setw(20)
4654 >    //          << "\tdeltaR = " << currentDeltaR
4655 >    //          << setprecision(1)
4656 >    //          << setw(20)
4657 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4658 >    //          << setw(20)
4659 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4660 >    //          << setw(20)
4661 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4662      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4663        bestMatchIndex = mcparticle - mcparticles->begin();
4664        bestMatchDeltaR = currentDeltaR;
4665      }
4666  
4667    }
4668 < //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4669 < //   else cout << "no match found..." << endl;
4668 >  //   if(bestMatchDeltaR != 999)  clog << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4669 >  //   else clog << "no match found..." << endl;
4670    return bestMatchIndex;
4671  
4672   }
# Line 2848 | Line 4720 | int OSUAnalysis::findTauMotherIndex(cons
4720   // 20        strange baryon
4721   // 21        charm baryon
4722   // 22        bottom baryon
4723 < // 23        other
4723 > // 23        QCD string
4724 > // 24        other
4725  
4726   int OSUAnalysis::getPdgIdBinValue(int pdgId){
4727  
# Line 2872 | Line 4745 | int OSUAnalysis::getPdgIdBinValue(int pd
4745    else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4746    else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4747    else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4748 +  else if(absPdgId == 92  ) binValue = 23;
4749  
4750 <  else binValue = 23;
4750 >  else binValue = 24;
4751  
4752    return binValue;
4753  
# Line 2883 | Line 4757 | const BNprimaryvertex *
4757   OSUAnalysis::chosenVertex ()
4758   {
4759    const BNprimaryvertex *chosenVertex = 0;
4760 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
4761 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
4762 <                               cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
4760 >  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4761 >    flagPair vertexFlags;
4762 >    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4763 >      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4764 >        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4765 >        break;
4766 >      }
4767 >    }
4768      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4769 <      if(!vertexFlags.at(vertexIndex)) continue;
4769 >      if(!vertexFlags.at(vertexIndex).first) continue;
4770        chosenVertex = & primaryvertexs->at(vertexIndex);
4771        break;
4772      }
4773    }
4774 <  else {
4775 <    chosenVertex = &primaryvertexs->at(0);
2897 <  }
4774 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4775 >    chosenVertex = & primaryvertexs->at (0);
4776  
4777    return chosenVertex;
4778   }
# Line 2903 | Line 4781 | const BNmet *
4781   OSUAnalysis::chosenMET ()
4782   {
4783    const BNmet *chosenMET = 0;
4784 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
4785 <    vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
4786 <                            cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
4784 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4785 >    flagPair metFlags;
4786 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4787 >      if (cumulativeFlags.at("mets").at(i).size()){
4788 >        metFlags = cumulativeFlags.at("mets").at(i);
4789 >        break;
4790 >      }
4791 >    }
4792      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4793 <      if(!metFlags.at(metIndex)) continue;
4793 >      if(!metFlags.at(metIndex).first) continue;
4794        chosenMET = & mets->at(metIndex);
4795        break;
4796      }
4797    }
4798 <  else {
4799 <    chosenMET = &mets->at(0);
2917 <  }
4798 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4799 >    chosenMET = & mets->at (0);
4800  
4801    return chosenMET;
4802   }
# Line 2923 | Line 4805 | const BNelectron *
4805   OSUAnalysis::chosenElectron ()
4806   {
4807    const BNelectron *chosenElectron = 0;
4808 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
4809 <    vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
4810 <                                 cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
4808 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4809 >    flagPair electronFlags;
4810 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4811 >      if (cumulativeFlags.at("electrons").at(i).size()){
4812 >        electronFlags = cumulativeFlags.at("electrons").at(i);
4813 >        break;
4814 >      }
4815 >    }
4816      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4817 <      if(!electronFlags.at(electronIndex)) continue;
4817 >      if(!electronFlags.at(electronIndex).first) continue;
4818        chosenElectron = & electrons->at(electronIndex);
4819        break;
4820      }
4821    }
4822 <  else {
4823 <    chosenElectron = &electrons->at(0);
2937 <  }
4822 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4823 >    chosenElectron = & electrons->at (0);
4824  
4825    return chosenElectron;
4826   }
4827  
4828 +
4829   const BNmuon *
4830   OSUAnalysis::chosenMuon ()
4831   {
4832    const BNmuon *chosenMuon = 0;
4833 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
4834 <    vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
4835 <                             cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
4833 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4834 >    flagPair muonFlags;
4835 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4836 >      if (cumulativeFlags.at("muons").at(i).size()){
4837 >        muonFlags = cumulativeFlags.at("muons").at(i);
4838 >        break;
4839 >      }
4840 >    }
4841      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4842 <      if(!muonFlags.at(muonIndex)) continue;
4842 >      if(!muonFlags.at(muonIndex).first) continue;
4843        chosenMuon = & muons->at(muonIndex);
4844        break;
4845      }
4846    }
4847 <  else {
4848 <    chosenMuon = &muons->at(0);
2957 <  }
4847 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4848 >    chosenMuon = & muons->at (0);
4849  
4850    return chosenMuon;
4851   }
4852  
4853 + double
4854 + OSUAnalysis::chosenHT ()
4855 + {
4856 +  double chosenHT = 0.0;
4857 +  if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
4858 +    flagPair jetFlags;
4859 +    for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
4860 +      if (cumulativeFlags.at("jets").at(i).size()){
4861 +        jetFlags = cumulativeFlags.at("jets").at(i);
4862 +        break;
4863 +      }
4864 +    }
4865 +    for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
4866 +      if(!jetFlags.at(jetIndex).first) continue;
4867 +      chosenHT += jets->at(jetIndex).pt;
4868 +    }
4869 +  }
4870 +
4871 +  return chosenHT;
4872 + }
4873 +
4874 + pair<const BNmuon *, const BNmuon *>
4875 + OSUAnalysis::leadMuonPair ()
4876 + {
4877 +  pair<const BNmuon *, const BNmuon *> leadMuonPair;
4878 +  leadMuonPair.first = leadMuonPair.second = 0;
4879 +
4880 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4881 +    flagPair muonFlags;
4882 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4883 +      if (cumulativeFlags.at("muons").at(i).size()){
4884 +        muonFlags = cumulativeFlags.at("muons").at(i);
4885 +        break;
4886 +      }
4887 +    }
4888 +    for (uint muonIndex0 = 0; muonIndex0 != muonFlags.size(); muonIndex0++){
4889 +      if(!muonFlags.at(muonIndex0).first) continue;
4890 +      for (uint muonIndex1 = muonIndex0 + 1; muonIndex1 < muonFlags.size(); muonIndex1++){
4891 +        if(!muonFlags.at(muonIndex1).first) continue;
4892 +        const BNmuon *mu0 = & muons->at(muonIndex0);
4893 +        const BNmuon *mu1 = & muons->at(muonIndex1);
4894 +        if(leadMuonPair.first == 0 || leadMuonPair.second == 0){
4895 +          leadMuonPair.first = mu0;
4896 +          leadMuonPair.second = mu1;
4897 +        }
4898 +        else{
4899 +          TVector2 newPt0 (mu0->px, mu0->py),
4900 +                   newPt1 (mu1->px, mu1->py),
4901 +                   oldPt0 (leadMuonPair.first->px, leadMuonPair.first->py),
4902 +                   oldPt1 (leadMuonPair.second->px, leadMuonPair.second->py);
4903 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
4904 +            {
4905 +              leadMuonPair.first = mu0;
4906 +              leadMuonPair.second = mu1;
4907 +            }
4908 +        }
4909 +      }
4910 +    }
4911 +  }
4912 +
4913 +  return leadMuonPair;
4914 + }
4915 +
4916 + pair<const BNelectron *, const BNelectron *>
4917 + OSUAnalysis::leadElectronPair ()
4918 + {
4919 +  pair<const BNelectron *, const BNelectron *> leadElectronPair;
4920 +  leadElectronPair.first = leadElectronPair.second = 0;
4921 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4922 +    flagPair electronFlags;
4923 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4924 +      if (cumulativeFlags.at("electrons").at(i).size()){
4925 +        electronFlags = cumulativeFlags.at("electrons").at(i);
4926 +        break;
4927 +      }
4928 +    }
4929 +    for (uint electronIndex0 = 0; electronIndex0 != electronFlags.size(); electronIndex0++){
4930 +      if(!electronFlags.at(electronIndex0).first) continue;
4931 +      for (uint electronIndex1 = electronIndex0 + 1; electronIndex1 < electronFlags.size(); electronIndex1++){
4932 +        if(!electronFlags.at(electronIndex1).first) continue;
4933 +        const BNelectron *el0 = & electrons->at(electronIndex0);
4934 +        const BNelectron *el1 = & electrons->at(electronIndex1);
4935 +        if(leadElectronPair.first == 0 || leadElectronPair.second == 0){
4936 +          leadElectronPair.first = el0;
4937 +          leadElectronPair.second = el1;
4938 +        }
4939 +        else{
4940 +          TVector2 newPt0 (el0->px, el0->py),
4941 +                   newPt1 (el1->px, el1->py),
4942 +                   oldPt0 (leadElectronPair.first->px, leadElectronPair.first->py),
4943 +                   oldPt1 (leadElectronPair.second->px, leadElectronPair.second->py);
4944 +          if(newPt0.Mod () + newPt1.Mod () > oldPt0.Mod() + oldPt1.Mod ())
4945 +            {
4946 +              leadElectronPair.first = el0;
4947 +              leadElectronPair.second = el1;
4948 +            }
4949 +        }
4950 +      }
4951 +    }
4952 +  }
4953 +
4954 +  return leadElectronPair;
4955 + }
4956  
4957   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines