ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc
(Generate patch)

Comparing UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc (file contents):
Revision 1.28 by jbrinson, Thu Mar 14 10:06:38 2013 UTC vs.
Revision 1.90 by wulsin, Wed Jun 26 06:17:12 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines