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

Comparing UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc (file contents):
Revision 1.31 by ahart, Mon Mar 18 10:21:44 2013 UTC vs.
Revision 1.88 by jbrinson, Mon Jun 24 15:52:58 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 <  muonSFFile_ (cfg.getParameter<std::string> ("muonSFFile")),
23 <  dataPU_ (cfg.getParameter<std::string> ("dataPU")),
24 <  electronSFID_ (cfg.getParameter<std::string> ("electronSFID")),
25 <  muonSF_ (cfg.getParameter<std::string> ("muonSF")),
26 <  dataset_ (cfg.getParameter<std::string> ("dataset")),
27 <  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 +  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 < {
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") {
50      if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
51 <    muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
52 <    electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
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_);
45  std::vector<TFileDirectory> directories;
66  
67    //always get vertex collection so we can assign the primary vertex in the event
68    objectsToGet.push_back("primaryvertexs");
49
50  //always make the plot of number of primary verticex (to check pile-up reweighting)
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 56 | Line 76 | OSUAnalysis::OSUAnalysis (const edm::Par
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 == "event-track pairs")   tempInputCollection = "track-event pairs";
112 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
113 >    if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
114 >    if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
115 >    if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
116 >    if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
117 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
118 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
119 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
120 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
121 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
122 >        int spaceIndex = tempInputCollection.find(" ");
123 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
124 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
125 >      }
126 >      else{
127 >        objectsToGet.push_back(tempInputCollection);
128 >      }
129        objectsToPlot.push_back(tempInputCollection);
130        objectsToCut.push_back(tempInputCollection);
131 <    }
132 <    else{//pair of objects, need to add them both to the things to objectsToGet
133 <      int dashIndex = tempInputCollection.find("-");
134 <      int spaceIndex = tempInputCollection.find(" ");
135 <      int secondWordLength = spaceIndex - dashIndex;
73 <      objectsToGet.push_back(tempInputCollection);
74 <      objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
75 <      objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
76 <      objectsToPlot.push_back(tempInputCollection);
77 <      objectsToPlot.push_back(tempInputCollection.substr(0,dashIndex)+"s");
78 <      objectsToPlot.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
131 >    } else { //pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
132 >      string obj1;
133 >      string obj2;
134 >      getTwoObjs(tempInputCollection, obj1, obj2);
135 >      string obj2ToGet = getObjToGet(obj2);
136        objectsToCut.push_back(tempInputCollection);
137 <      objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
138 <      objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
137 >      objectsToCut.push_back(obj1);
138 >      objectsToCut.push_back(obj2);
139 >      objectsToPlot.push_back(tempInputCollection);
140 >      objectsToPlot.push_back(obj1);
141 >      objectsToPlot.push_back(obj2);
142 >      objectsToGet.push_back(tempInputCollection);
143 >      objectsToGet.push_back(obj1);
144 >      objectsToGet.push_back(obj2ToGet);
145 >    } // end else
146 >
147  
83      }
148  
149      vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
150  
151      for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
152  
153 +      vector<double> defaultValue;
154 +      defaultValue.push_back (-1.0);
155 +
156        histogram tempHistogram;
157        tempHistogram.inputCollection = tempInputCollection;
158        tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
159        tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
160 <      tempHistogram.bins = histogramList_.at(currentHistogram).getParameter<vector<double> >("bins");
160 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
161 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
162 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
163        tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
164  
165        histograms.push_back(tempHistogram);
166  
167      }
168 <  }
168 >  } //   for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++)
169 >
170    //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
171    sort( objectsToPlot.begin(), objectsToPlot.end() );
172    objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
# Line 107 | Line 177 | OSUAnalysis::OSUAnalysis (const edm::Par
177    for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
178  
179      string currentObject = objectsToPlot.at(currentObjectIndex);
180 <    if(currentObject != "muons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
180 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
181  
182      histogram tempIdHisto;
183      histogram tempMomIdHisto;
184      histogram tempGmaIdHisto;
185 +    histogram tempIdVsMomIdHisto;
186 +    histogram tempIdVsGmaIdHisto;
187  
188      tempIdHisto.inputCollection = currentObject;
189      tempMomIdHisto.inputCollection = currentObject;
190      tempGmaIdHisto.inputCollection = currentObject;
191 +    tempIdVsMomIdHisto.inputCollection = currentObject;
192 +    tempIdVsGmaIdHisto.inputCollection = currentObject;
193 +
194 +    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
195 +    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
196  
197      currentObject = currentObject.substr(0, currentObject.size()-1);
198      tempIdHisto.name = currentObject+"GenMatchId";
199      tempMomIdHisto.name = currentObject+"GenMatchMotherId";
200      tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
201 +    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
202 +    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
203  
204      currentObject.at(0) = toupper(currentObject.at(0));
205      tempIdHisto.title = currentObject+" Gen-matched Particle";
206      tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
207      tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
208 +    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
209 +    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
210  
211 <    int maxNum = 24;
211 >
212 >    int maxNum = 25;
213      vector<double> binVector;
214      binVector.push_back(maxNum);
215      binVector.push_back(0);
# Line 139 | Line 221 | OSUAnalysis::OSUAnalysis (const edm::Par
221      tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
222      tempGmaIdHisto.bins = binVector;
223      tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
224 +    binVector.push_back(maxNum);
225 +    binVector.push_back(0);
226 +    binVector.push_back(maxNum);
227 +    tempIdVsMomIdHisto.bins = binVector;
228 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
229 +    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
230 +    tempIdVsGmaIdHisto.bins = binVector;
231 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
232 +    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
233  
234      histograms.push_back(tempIdHisto);
235      histograms.push_back(tempMomIdHisto);
236      histograms.push_back(tempGmaIdHisto);
237 <
237 >    histograms.push_back(tempIdVsMomIdHisto);
238 >    histograms.push_back(tempIdVsGmaIdHisto);
239    }
240  
241  
150
242    channel tempChannel;
243    //loop over all channels (event selections)
244    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
# Line 160 | Line 251 | OSUAnalysis::OSUAnalysis (const edm::Par
251      //set triggers for this channel
252      vector<string> triggerNames;
253      triggerNames.clear();
254 +    vector<string> triggerToVetoNames;
255 +    triggerToVetoNames.clear();
256 +
257      tempChannel.triggers.clear();
258 +    tempChannel.triggersToVeto.clear();
259      if(channels_.at(currentChannel).exists("triggers")){
260        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
261        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
262          tempChannel.triggers.push_back(triggerNames.at(trigger));
263        objectsToGet.push_back("triggers");
264      }
265 <
265 >    if(channels_.at(currentChannel).exists("triggersToVeto")){
266 >      triggerToVetoNames = channels_.at(currentChannel).getParameter<vector<string> >("triggersToVeto");
267 >      for(uint trigger = 0; trigger!= triggerToVetoNames.size(); trigger++)
268 >        tempChannel.triggersToVeto.push_back(triggerToVetoNames.at(trigger));
269 >      objectsToGet.push_back("triggers");
270 >    }
271  
272  
273  
274      //create cutFlow for this channel
275      cutFlows_.push_back (new CutFlow (fs_, channelName));
276 <
277 <    //book a directory in the output file with the name of the channel
278 <    TFileDirectory subDir = fs_->mkdir( channelName );
179 <    directories.push_back(subDir);
180 <
181 <    std::map<std::string, TH1D*> oneDhistoMap;
182 <    oneDHists_.push_back(oneDhistoMap);
183 <    std::map<std::string, TH2D*> twoDhistoMap;
184 <    twoDHists_.push_back(twoDhistoMap);
185 <
186 <
187 <    //book all histograms included in the configuration
188 <    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
189 <      histogram currentHistogram = histograms.at(currentHistogramIndex);
190 <      int numBinsElements = currentHistogram.bins.size();
191 <      int numInputVariables = currentHistogram.inputVariables.size();
192 <
193 <      if(numBinsElements != 3 && numBinsElements !=6) {
194 <        std::cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
195 <        exit(0);
196 <      }
197 <      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
198 <        std::cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
199 <        exit(0);
200 <      }
201 <      else if(numBinsElements == 3){
202 <        oneDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2));
203 <      }
204 <      else if(numBinsElements == 6){
205 <        twoDHists_.at(currentChannel)[currentHistogram.name] = directories.at(currentChannel).make<TH2D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, currentHistogram.bins.at(0), currentHistogram.bins.at(1), currentHistogram.bins.at(2),currentHistogram.bins.at(3),currentHistogram.bins.at(4),currentHistogram.bins.at(5));
206 <
207 <      }
208 <
209 <
210 <      if(currentHistogram.name.find("GenMatch")==std::string::npos) continue;
211 <
212 < // bin      particle type
213 < // ---      -------------
214 < //  0        unmatched
215 < //  1        u
216 < //  2        d
217 < //  3        s
218 < //  4        c
219 < //  5        b
220 < //  6        t
221 < //  7        e
222 < //  8        mu
223 < //  9        tau
224 < // 10        nu
225 < // 11        g
226 < // 12        gamma
227 < // 13        Z
228 < // 14        W
229 < // 15        light meson
230 < // 16        K meson
231 < // 17        D meson
232 < // 18        B meson
233 < // 19        light baryon
234 < // 20        strange baryon
235 < // 21        charm baryon
236 < // 22        bottom baryon
237 < // 23        other
238 <
239 <      vector<TString> labelArray;
240 <      labelArray.push_back("unmatched");
241 <      labelArray.push_back("u");
242 <      labelArray.push_back("d");
243 <      labelArray.push_back("s");
244 <      labelArray.push_back("c");
245 <      labelArray.push_back("b");
246 <      labelArray.push_back("t");
247 <      labelArray.push_back("e");
248 <      labelArray.push_back("#mu");
249 <      labelArray.push_back("#tau");
250 <      labelArray.push_back("#nu");
251 <      labelArray.push_back("g");
252 <      labelArray.push_back("#gamma");
253 <      labelArray.push_back("Z");
254 <      labelArray.push_back("W");
255 <      labelArray.push_back("light meson");
256 <      labelArray.push_back("K meson");
257 <      labelArray.push_back("D meson");
258 <      labelArray.push_back("B meson");
259 <      labelArray.push_back("light baryon");
260 <      labelArray.push_back("strange baryon");
261 <      labelArray.push_back("charm baryon");
262 <      labelArray.push_back("bottom baryon");
263 <      labelArray.push_back("other");
264 <
265 <      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
266 <        oneDHists_.at(currentChannel)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
267 <      }
268 <    }
269 <
270 <    //book a histogram for the number of each object type to be plotted
271 <
272 <    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
273 <      string currentObject = objectsToPlot.at(currentObjectIndex);
274 <      int maxNum = 10;
275 <      if(currentObject == "mcparticles") maxNum = 50;
276 <      else if(currentObject == "primaryvertexs") maxNum = 50;
277 <      else if(currentObject == "muon-muon pairs") currentObject = "dimuonPairs";
278 <      else if(currentObject == "electron-electron pairs") currentObject = "dielectronPairs";
279 <      else if(currentObject == "electron-muon pairs") currentObject = "electronMuonPairs";
280 <
281 <      currentObject.at(0) = toupper(currentObject.at(0));
282 <      string histoName = "num" + currentObject;
283 <
284 <      if(histoName == "numPrimaryvertexs"){
285 <        string newHistoName = histoName + "BeforePileupCorrection";
286 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+" Before Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
287 <        newHistoName = histoName + "AfterPileupCorrection";
288 <        oneDHists_.at(currentChannel)[newHistoName] = directories.at(currentChannel).make<TH1D> (TString(newHistoName),channelLabel+" channel: Number of Selected "+currentObject+ " After Pileup Correction; # "+currentObject, maxNum, 0, maxNum);
289 <      }
290 <      else
291 <        oneDHists_.at(currentChannel)[histoName] = directories.at(currentChannel).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
292 <    }
293 <
294 <
295 <
296 <
297 <
276 >    vector<TFileDirectory> directories; //vector of directories in the output file.
277 >    vector<TFileDirectory> treeDirectories; //vector of directories for trees in the output file.
278 >    vector<string> subSubDirNames;//subdirectories in each channel.
279      //get list of cuts for this channel
280      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
281  
282 +
283      //loop over and parse all cuts
284      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
285        cut tempCut;
286        //store input collection for cut
287        string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
288 +      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
289 +      if(tempInputCollection == "photon-electron pairs") tempInputCollection = "electron-photon pairs";
290 +      if(tempInputCollection == "photon-muon pairs") tempInputCollection = "muon-photon pairs";
291 +      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
292 +      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
293 +      if(tempInputCollection == "jet-photon pairs") tempInputCollection = "photon-jet pairs";
294 +      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
295 +      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
296 +      if(tempInputCollection == "secondary jet-jet pairs")   tempInputCollection = "jet-secondary jet pairs";
297 +      if(tempInputCollection == "secondary jet-muon pairs")   tempInputCollection = "muon-secondary jet pairs";
298 +      if(tempInputCollection == "secondary jet-photon pairs")   tempInputCollection = "photon-secondary jet pairs";
299 +      if(tempInputCollection == "secondary jet-electron pairs")   tempInputCollection = "electron-secondary jet pairs";
300 +      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
301 +      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
302 +      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
303        tempCut.inputCollection = tempInputCollection;
304 <      if(tempInputCollection.find("pairs")==std::string::npos){ //just a single object
305 <        objectsToGet.push_back(tempInputCollection);
304 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
305 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
306 >          int spaceIndex = tempInputCollection.find(" ");
307 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
308 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
309 >        }
310 >        else{
311 >          objectsToGet.push_back(tempInputCollection);
312 >        }
313          objectsToCut.push_back(tempInputCollection);
314        }
315 <      else{//pair of objects, need to add them both to the things to objectsToGet
316 <        int dashIndex = tempInputCollection.find("-");
317 <        int spaceIndex = tempInputCollection.find(" ");
318 <        int secondWordLength = spaceIndex - dashIndex;
319 <        objectsToGet.push_back(tempInputCollection);
316 <        objectsToGet.push_back(tempInputCollection.substr(0,dashIndex)+"s");
317 <        objectsToGet.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
315 >      else{//pair of objects, need to add them both to objectsToGet
316 >        string obj1;
317 >        string obj2;
318 >        getTwoObjs(tempInputCollection, obj1, obj2);
319 >        string obj2ToGet = getObjToGet(obj2);
320          objectsToCut.push_back(tempInputCollection);
321 <        objectsToCut.push_back(tempInputCollection.substr(0,dashIndex)+"s");
322 <        objectsToCut.push_back(tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s");
321 >        objectsToCut.push_back(obj1);
322 >        objectsToCut.push_back(obj2);
323 >        objectsToGet.push_back(tempInputCollection);
324 >        objectsToGet.push_back(obj1);
325 >        objectsToGet.push_back(obj2ToGet);
326  
327        }
328  
# Line 325 | Line 330 | OSUAnalysis::OSUAnalysis (const edm::Par
330  
331        //split cut string into parts and store them
332        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
333 <      std::vector<string> cutStringVector = splitString(cutString);
333 >      vector<string> cutStringVector = splitString(cutString);
334        if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
335 <        std::cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
335 >        cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
336          exit(0);
337        }
338        tempCut.numSubcuts = (cutStringVector.size()+1)/4;
339        for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
340          int indexOffset = 4 * subcutIndex;
341          string currentVariableString = cutStringVector.at(indexOffset);
342 <        if(currentVariableString.find("(")==std::string::npos){
342 >        if(currentVariableString.find("(")==string::npos){
343            tempCut.functions.push_back("");//no function was specified
344            tempCut.variables.push_back(currentVariableString);// variable to cut on
345          }
# Line 345 | Line 350 | OSUAnalysis::OSUAnalysis (const edm::Par
350          }
351          tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
352          tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
353 +        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
354          if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
355        }
356  
357        //get number of objects required to pass cut for event to pass
358        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
359 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
359 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
360        if(numberRequiredVector.size()!=2){
361 <        std::cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
361 >        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
362          exit(0);
363        }
364  
# Line 360 | Line 366 | OSUAnalysis::OSUAnalysis (const edm::Par
366        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
367        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
368  
369 <
369 >      //Set up vectors to store the directories and subDirectories for each channel.
370 >      string subSubDirName;
371        string tempCutName;
372        if(cuts_.at(currentCut).exists("alias")){
373          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
374 +        subSubDirName = "After " + tempCutName + " Cut Applied";
375        }
376        else{
377          //construct string for cutflow table
# Line 371 | Line 379 | OSUAnalysis::OSUAnalysis (const edm::Par
379          string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
380          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
381          tempCutName = cutName;
382 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
383        }
375      tempCut.name = tempCutName;
384  
385 +      tempCut.isVeto = false;
386 +      if(cuts_.at(currentCut).exists("isVeto")){
387 +        bool isVeto = cuts_.at(currentCut).getParameter<bool> ("isVeto");
388 +        if (isVeto == true) tempCut.isVeto = true;
389 +      }
390 +      subSubDirNames.push_back(subSubDirName);
391 +      tempCut.name = tempCutName;
392  
393        tempChannel.cuts.push_back(tempCut);
394  
395  
381
396      }//end loop over cuts
397  
398 +    vector<map<string, TH1D*>> oneDHistsTmp;
399 +    vector<map<string, TH2D*>> twoDHistsTmp;
400 +    //book a directory in the output file with the name of the channel
401 +    TFileDirectory subDir = fs_->mkdir( channelName );
402 +    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
403 +    if(GetPlotsAfterEachCut_){
404 +      for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
405 +        TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
406 +        directories.push_back(subSubDir);
407 +        map<string, TH1D*> oneDhistoMap;
408 +        oneDHistsTmp.push_back(oneDhistoMap);
409 +        map<string, TH2D*> twoDhistoMap;
410 +        twoDHistsTmp.push_back(twoDhistoMap);
411 +      }
412 +      treeDirectories.push_back(subDir);
413 +      oneDHists_.push_back(oneDHistsTmp);
414 +      twoDHists_.push_back(twoDHistsTmp);
415 +    }
416 +    //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
417 +    else{
418 +      map<string, TH1D*> oneDhistoMap;
419 +      oneDHistsTmp.push_back(oneDhistoMap);
420 +      map<string, TH2D*> twoDhistoMap;
421 +      twoDHistsTmp.push_back(twoDhistoMap);
422 +      oneDHists_.push_back(oneDHistsTmp);
423 +      twoDHists_.push_back(twoDHistsTmp);
424 +      directories.push_back(subDir);
425 +      treeDirectories.push_back(subDir);
426 +
427 +    }
428 +
429 +    for(uint currentDir = 0; !useEDMFormat_ && currentDir != treeDirectories.size(); currentDir++){
430 +      TTree* newTree = treeDirectories.at(currentDir).make<TTree> (TString("BNTree_"+channelLabel), TString("BNTree_"+channelLabel));
431 +      BNTrees_.push_back(newTree);
432 +      for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++){
433 +        BranchSpecs currentVar = treeBranches_.at(iBranch);
434 +        vector<float> newVec;
435 +        BNTreeBranchVals_[currentVar.name] = newVec;
436 +        BNTrees_.back()->Branch(TString(currentVar.name), &BNTreeBranchVals_.at(currentVar.name));
437 +      } // end for (uint iBranch = 0; iBranch < treeBranches_.size(); iBranch++)
438 +    }
439 +
440 +    //book all histograms included in the configuration
441 +    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
442 +
443 +      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
444 +
445 +        histogram currentHistogram = histograms.at(currentHistogramIndex);
446 +        int numBinsElements = currentHistogram.bins.size();
447 +        int numInputVariables = currentHistogram.inputVariables.size();
448 +        int numBinEdgesX = currentHistogram.variableBinsX.size();
449 +        int numBinEdgesY = currentHistogram.variableBinsY.size();
450 +
451 +        if(numBinsElements == 1){
452 +          if(numBinEdgesX > 1){
453 +            if(numBinEdgesY > 1)
454 +              numBinsElements = 6;
455 +            else
456 +              numBinsElements = 3;
457 +          }
458 +        }
459 +        if(numBinsElements != 3 && numBinsElements !=6){
460 +          cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
461 +          exit(0);
462 +        }
463 +        else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
464 +          cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
465 +          exit(0);
466 +        }
467 +        else if(numBinsElements == 3){
468 +          if (currentHistogram.bins.size () == 3)
469 +            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));
470 +          else
471 +            {
472 +              oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
473 +            }
474 +        }
475 +        else if(numBinsElements == 6){
476 +          if (currentHistogram.bins.size () == 6)
477 +            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));
478 +          else
479 +            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 ());
480 +        }
481 +
482 +
483 +        if(currentHistogram.name.find("GenMatch")==string::npos) continue;
484 +
485 +        // bin      particle type
486 +        // ---      -------------
487 +        //  0        unmatched
488 +        //  1        u
489 +        //  2        d
490 +        //  3        s
491 +        //  4        c
492 +        //  5        b
493 +        //  6        t
494 +        //  7        e
495 +        //  8        mu
496 +        //  9        tau
497 +        // 10        nu
498 +        // 11        g
499 +        // 12        gamma
500 +        // 13        Z
501 +        // 14        W
502 +        // 15        light meson
503 +        // 16        K meson
504 +        // 17        D meson
505 +        // 18        B meson
506 +        // 19        light baryon
507 +        // 20        strange baryon
508 +        // 21        charm baryon
509 +        // 22        bottom baryon
510 +        // 23        QCD string
511 +        // 24        other
512 +
513 +        vector<TString> labelArray;
514 +        labelArray.push_back("unmatched");
515 +        labelArray.push_back("u");
516 +        labelArray.push_back("d");
517 +        labelArray.push_back("s");
518 +        labelArray.push_back("c");
519 +        labelArray.push_back("b");
520 +        labelArray.push_back("t");
521 +        labelArray.push_back("e");
522 +        labelArray.push_back("#mu");
523 +        labelArray.push_back("#tau");
524 +        labelArray.push_back("#nu");
525 +        labelArray.push_back("g");
526 +        labelArray.push_back("#gamma");
527 +        labelArray.push_back("Z");
528 +        labelArray.push_back("W");
529 +        labelArray.push_back("light meson");
530 +        labelArray.push_back("K meson");
531 +        labelArray.push_back("D meson");
532 +        labelArray.push_back("B meson");
533 +        labelArray.push_back("light baryon");
534 +        labelArray.push_back("strange baryon");
535 +        labelArray.push_back("charm baryon");
536 +        labelArray.push_back("bottom baryon");
537 +        labelArray.push_back("QCD string");
538 +        labelArray.push_back("other");
539 +
540 +        for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
541 +          if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
542 +            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
543 +          }
544 +          else {
545 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
546 +            twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
547 +          }
548 +        }
549 +        if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
550 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
551 +          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
552 +        }
553 +
554 +      }  // end      for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++)
555 +
556 +
557 +      // Book a histogram for the number of each object type to be plotted.
558 +      // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
559 +      for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
560 +        string currentObject = objectsToPlot.at(currentObjectIndex);
561 +        int maxNum = 10;
562 +        if(currentObject == "mcparticles") maxNum = 50;
563 +        else if(currentObject == "primaryvertexs") maxNum = 50;
564 +
565 +        if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
566 +        else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
567 +        else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
568 +        else if(currentObject == "electron-photon pairs")       currentObject = "electronPhotonPairs";
569 +        else if(currentObject == "muon-photon pairs")       currentObject = "muonPhotonPairs";
570 +        else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
571 +        else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
572 +        else if(currentObject == "jet-secondary jet pairs")   currentObject = "jetSecondaryJetPairs";
573 +        else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
574 +        else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
575 +        else if(currentObject == "photon-jet pairs")            currentObject = "photonJetPairs";
576 +        else if(currentObject == "muon-secondary jet pairs")  currentObject = "muonSecondaryJetPairs";
577 +        else if(currentObject == "photon-secondary jet pairs")  currentObject = "photonSecondaryJetPairs";
578 +        else if(currentObject == "electron-secondary jet pairs")  currentObject = "electronSecondaryJetPairs";
579 +        else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
580 +        else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
581 +        else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
582 +        else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
583 +        else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
584 +        else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
585 +        else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
586 +        else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
587 +        else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
588 +        else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
589 +        else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
590 +        else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
591 +
592 +        currentObject.at(0) = toupper(currentObject.at(0));
593 +        string histoName = "num" + currentObject;
594 +
595 +        if(histoName == "numPrimaryvertexs"){
596 +          string newHistoName = histoName + "BeforePileupCorrection";
597 +          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);
598 +          newHistoName = histoName + "AfterPileupCorrection";
599 +          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);
600 +        }
601 +        else
602 +          oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
603 +      }
604 +    }//end of loop over directories
605      channels.push_back(tempChannel);
606      tempChannel.cuts.clear();
386
607    }//end loop over channels
608  
609  
# Line 394 | Line 614 | OSUAnalysis::OSUAnalysis (const edm::Par
614    sort( objectsToCut.begin(), objectsToCut.end() );
615    objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
616  
617 +  produces<map<string, bool> > ("channelDecisions");
618 +
619 + } // end constructor OSUAnalysis::OSUAnalysis()
620  
398 }
621  
622   OSUAnalysis::~OSUAnalysis ()
623   {
624 +
625    // Destroying the CutFlow objects causes the cut flow numbers and time
626    // information to be printed to standard output.
627    for(uint currentChannel = 0; currentChannel != channels_.size(); currentChannel++){
# Line 407 | Line 630 | OSUAnalysis::~OSUAnalysis ()
630   }
631  
632   void
633 < OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
633 > OSUAnalysis::produce (edm::Event &event, const edm::EventSetup &setup)
634   {
635 <
635 >  //cout << "**********************\n\n\n";
636    // Retrieve necessary collections from the event.
637  
638 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
638 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
639      event.getByLabel (triggers_, triggers);
640  
641 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
641 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
642 >    event.getByLabel (trigobjs_, trigobjs);
643 >
644 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
645      event.getByLabel (jets_, jets);
646  
647 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
647 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
648      event.getByLabel (muons_, muons);
649  
650 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
650 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
651      event.getByLabel (electrons_, electrons);
652  
653 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
653 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
654      event.getByLabel (events_, events);
655  
656 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
656 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
657      event.getByLabel (taus_, taus);
658  
659 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
659 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
660      event.getByLabel (mets_, mets);
661  
662 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
662 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
663      event.getByLabel (tracks_, tracks);
664  
665 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
665 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
666      event.getByLabel (genjets_, genjets);
667  
668 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
668 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
669      event.getByLabel (mcparticles_, mcparticles);
670  
671 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
671 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
672      event.getByLabel (primaryvertexs_, primaryvertexs);
673  
674 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
674 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
675      event.getByLabel (bxlumis_, bxlumis);
676  
677 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
677 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
678      event.getByLabel (photons_, photons);
679  
680 <  if (std::find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
680 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
681      event.getByLabel (superclusters_, superclusters);
682  
683 +  if (datasetType_ == "signalMC"){
684 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
685 +      event.getByLabel (stops_, stops);
686 +  }
687 +
688 +  if (useTrackCaloRhoCorr_) {
689 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
690 +    // This rho collection is not available in all BEANs.
691 +    // For description of rho values for different jet reconstruction algorithms, see
692 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
693 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
694 +  }
695 +
696 +  double masterScaleFactor = 1.0;
697 +
698    //get pile-up event weight
699 <  double scaleFactor = 1.00;
700 <  if(doPileupReweighting_ && datasetType_ != "data")
701 <    scaleFactor = puWeight_->at (events->at (0).numTruePV);
699 >  if (doPileupReweighting_ && datasetType_ != "data") {
700 >    //for "data" datasets, the numTruePV is always set to -1
701 >    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  Turning off pile-up reweighting." << endl;
702 >    else masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);
703 >  }
704  
705 +  stopCTauScaleFactor_ = 1.0;
706 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
707 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
708 +  masterScaleFactor *= stopCTauScaleFactor_;
709  
710    //loop over all channels
711  
712 +  auto_ptr<map<string, bool> > channelDecisions (new map<string, bool>);
713    for(uint currentChannelIndex = 0; currentChannelIndex != channels.size(); currentChannelIndex++){
714      channel currentChannel = channels.at(currentChannelIndex);
715  
# Line 469 | Line 717 | OSUAnalysis::analyze (const edm::Event &
717      counterMap passingCounter;
718      cumulativeFlags.clear ();
719  
720 +    for (map<string, vector<float>>::iterator iter = BNTreeBranchVals_.begin();
721 +         iter != BNTreeBranchVals_.end(); iter++) {
722 +      iter->second.clear();  // clear array
723 +    }
724 +
725      bool triggerDecision = true;
726 <    if(currentChannel.triggers.size() != 0){  //triggers specified
727 <      triggerDecision = evaluateTriggers(currentChannel.triggers,triggers.product());
726 >    if(currentChannel.triggers.size() != 0 || currentChannel.triggersToVeto.size() != 0){  //triggers specified
727 >      triggerDecision = evaluateTriggers(currentChannel.triggers, currentChannel.triggersToVeto, triggers.product());
728        cutFlows_.at(currentChannelIndex)->at ("trigger") = triggerDecision;
729      }
730  
731      //loop over all cuts
479
480
481
732      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
733        cut currentCut = currentChannel.cuts.at(currentCutIndex);
484
734        for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
735          string currentObject = objectsToCut.at(currentObjectIndex);
736  
737          //initialize maps to get ready to set cuts
738 <        individualFlags[currentObject].push_back (vector<bool> ());
739 <        cumulativeFlags[currentObject].push_back (vector<bool> ());
738 >        individualFlags[currentObject].push_back (vector<pair<bool,bool> > ());
739 >        cumulativeFlags[currentObject].push_back (vector<pair<bool,bool> > ());
740  
741        }
742        for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
# Line 496 | Line 745 | OSUAnalysis::analyze (const edm::Event &
745          int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
746  
747  
748 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
749 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
748 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
749 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
750 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
751 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
752 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
753          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
754          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
755          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 509 | Line 761 | OSUAnalysis::analyze (const edm::Event &
761          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
762          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
763          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
764 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
765 +
766  
767  
768          else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
769                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
770                                                                     cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
771                                                                     "muon-muon pairs");
772 +
773 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
774 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
775 +                                                                             cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
776 +                                                                             "muon-secondary muon pairs");
777 +
778 +        else if(currentObject == "muon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
779 +                                                                             cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
780 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
781 +                                                                             "muon-secondary jet pairs");
782 +        else if(currentObject == "photon-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
783 +                                                                             cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
784 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
785 +                                                                             "photon-secondary jet pairs");
786 +
787 +        else if(currentObject == "electron-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
788 +                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
789 +                                                                             cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex), \
790 +                                                                             "electron-secondary jet pairs");
791 +
792 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
793 +                                                                                     cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
794 +                                                                                     cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
795 +                                                                                     "electron-secondary electron pairs");
796 +
797          else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
798                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
799                                                                             cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
# Line 523 | Line 802 | OSUAnalysis::analyze (const edm::Event &
802                                                                         cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
803                                                                         cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
804                                                                         "electron-muon pairs");
805 +        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
806 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
807 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
808 +                                                                 "jet-jet pairs");
809 +        else if(currentObject == "jet-secondary jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
810 +                                                                 cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
811 +                                                                 cumulativeFlags.at("secondary jets").at(flagsForPairCutsIndex),\
812 +                                                                 "jet-secondary jet pairs");
813 +        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
814 +                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
815 +                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
816 +                                                                      "electron-jet pairs");
817 +        else if(currentObject == "electron-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),photons.product(), \
818 +                                                                      cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
819 +                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
820 +                                                                      "electron-photon pairs");
821 +        else if(currentObject == "photon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),jets.product(), \
822 +                                                                      cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
823 +                                                                      cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
824 +                                                                      "photon-jet pairs");
825 +        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
826 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
827 +                                                                  cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
828 +                                                                  "muon-jet pairs");
829 +        else if(currentObject == "muon-photon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),photons.product(), \
830 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
831 +                                                                  cumulativeFlags.at("photons").at(flagsForPairCutsIndex), \
832 +                                                                  "muon-photon pairs");
833 +        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
834 +                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
835 +                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
836 +                                                                     "track-event pairs");
837 +        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
838 +                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
839 +                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
840 +                                                                        "electron-track pairs");
841 +        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
842 +                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
843 +                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
844 +                                                                    "muon-track pairs");
845 +        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
846 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
847 +                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
848 +                                                                  "muon-tau pairs");
849 +        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
850 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
851 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
852 +                                                                 "tau-tau pairs");
853 +        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
854 +                                                                   cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
855 +                                                                   cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
856 +                                                                   "tau-track pairs");
857 +        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
858 +                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
859 +                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
860 +                                                                          "electron-trigobj pairs");
861 +        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
862 +                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
863 +                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
864 +                                                                      "muon-trigobj pairs");
865  
866 <
866 >        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
867        }
868  
869  
870  
871      }//end loop over all cuts
533
534
872      //use cumulative flags to apply cuts at event level
873  
874 +    //a vector to store cumulative cut descisions after each cut.
875 +    vector<bool> eventPassedPreviousCuts;
876      bool eventPassedAllCuts = true;
538
877      //apply trigger (true if none were specified)
878      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
879  
542
543
880      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
881  
882        //loop over all objects and count how many passed the cumulative selection up to this point
# Line 548 | Line 884 | OSUAnalysis::analyze (const edm::Event &
884        int numberPassing = 0;
885  
886        for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
887 <          if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
887 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object).first) numberPassing++;
888        }
553
889        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
890        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
556
891        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
892 <
892 >      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
893      }
894 +    double scaleFactor = masterScaleFactor;
895  
896 +    muonScaleFactor_ = electronScaleFactor_ = bTagScaleFactor_ = 1.0;
897 +    if(applyLeptonSF_ && datasetType_ != "data"){
898 +      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
899 +        flagPair muonFlags;
900 +        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
901 +          if (cumulativeFlags.at("muons").at(i).size()){
902 +            muonFlags = cumulativeFlags.at("muons").at(i);
903 +            break;
904 +          }
905 +        }
906 +        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
907 +          if(!muonFlags.at(muonIndex).second) continue;
908 +          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
909 +        }
910 +      }
911 +      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
912 +        flagPair electronFlags;
913 +        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
914 +          if (cumulativeFlags.at("electrons").at(i).size()){
915 +            electronFlags = cumulativeFlags.at("electrons").at(i);
916 +            break;
917 +          }
918 +        }
919 +        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
920 +          if(!electronFlags.at(electronIndex).second) continue;
921 +          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
922 +        }
923 +      }
924 +    }
925 +    if(applyBtagSF_ && datasetType_ != "data"){
926 +     if(cumulativeFlags.find ("jets") != cumulativeFlags.end ()){
927 +       flagPair jetFlags;
928 +        vector<double> jetSFs;
929 +        for (int i = cumulativeFlags.at("jets").size() - 1; i >= 0; i--){
930 +          if (cumulativeFlags.at("jets").at(i).size()){
931 +            jetFlags = cumulativeFlags.at("jets").at(i);
932 +            break;
933 +          }
934 +        }
935 +        for (uint jetIndex = 0; jetIndex != jetFlags.size(); jetIndex++){
936 +          if(!jetFlags.at(jetIndex).second) continue;
937 +          double jetSFTmp = bTagSFWeight_->sflookup(jets->at(jetIndex).btagCombinedSecVertex, jets->at(jetIndex).pt, jets->at(jetIndex).flavour);
938 +          jetSFs.push_back(jetSFTmp);
939 +        }
940 +        bTagScaleFactor_ *= bTagSFWeight_->weight( jetSFs, minBtag_, maxBtag_ );
941 +      }
942 +    }
943 +    scaleFactor *= muonScaleFactor_;
944 +    scaleFactor *= electronScaleFactor_;
945 +    scaleFactor *= bTagScaleFactor_;
946      cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
947  
948 +    if (printEventInfo_) {
949 +      // Write information about event to screen, for testing purposes.
950 +      cout << "Event passed all cuts in channel " <<  currentChannel.name
951 +           << ": run="  << events->at(0).run
952 +           << "  lumi=" << events->at(0).lumi
953 +           << "  event=" << events->at(0).evt
954 +           << endl;
955 +    }
956  
957  
958 <    if(!eventPassedAllCuts)continue;
958 >    //filling histograms
959 >    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
960 >      uint currentDir;
961 >      if (!GetPlotsAfterEachCut_) { currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size(); } //if GetPlotsAfterEachCut_ is false, set currentDir point to the last cut.
962 >      else{
963 >        currentDir = currentCut;
964 >      }
965  
966  
967 <    //if(datasetType_ != "data") {
569 <    //  scaleFactor *= muonSFWeight_->at (chosenMuon ()->eta);
570 <    //  scaleFactor *= electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
571 <    //}
967 >      if(eventPassedPreviousCuts.at(currentDir)){
968  
969 <    //filling histograms
970 <    for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
971 <      histogram currentHistogram = histograms.at(histogramIndex);
969 >        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
970 >          histogram currentHistogram = histograms.at(histogramIndex);
971 >
972 >          if (cumulativeFlags.count(currentHistogram.inputCollection) == 0) cout << "Error: no flags found for collection:  " << currentHistogram.inputCollection << ", will cause a seg fault" << endl;
973 >
974 >          if(currentHistogram.inputVariables.size() == 1){
975 >            TH1D* histo;
976 >            histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
977 >            if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
978 >            else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
979 >            else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
980 >            else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
981 >            else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
982 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
983 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
984 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
985 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
986 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
987 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
988 >             else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
989 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
990 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
991 >             else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill1DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
992 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
993 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
994 >             else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
995 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
996 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
997 >
998 >            else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
999 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
1000 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
1001 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1002 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
1003 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
1004 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1005 >             else if(currentHistogram.inputCollection == "jet-secondary jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1006 >                                                                                                     cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1007 >                                                                                                     cumulativeFlags.at("jet-secondary jet pairs").at(currentDir),scaleFactor);
1008 >
1009 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1010 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1011 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1012 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
1013 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
1014 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1015 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
1016 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1017 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1018 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill1DHistogram(histo,currentHistogram, photons.product(),jets.product(), \
1019 >                                                                                              cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1020 >                                                                                              cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1021 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
1022 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
1023 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1024 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill1DHistogram(histo,currentHistogram, muons.product(),photons.product(), \
1025 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1026 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1027 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),photons.product(), \
1028 >                                                                                          cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir),
1029 >                                                                                          cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1030 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
1031 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1032 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1033 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
1034 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1035 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1036 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
1037 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1038 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1039 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
1040 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1041 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1042 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
1043 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1044 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1045 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
1046 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1047 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1048 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
1049 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1050 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1051 >
1052 >            else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1053 >            else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1054 >            else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1055 >            else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1056 >            else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1057 >            else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1058 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1059 >            else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1060 >            else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1061 >            else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1062 >            else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1063 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1064 >          }
1065 >          else if(currentHistogram.inputVariables.size() == 2){
1066 >            TH2D* histo;
1067 >            histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
1068 >            if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
1069 >            else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
1070 >            else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
1071 >            else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
1072 >            else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1073 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1074 >                                                                                           cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
1075 >            else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
1076 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
1077 >                                                                                                     cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
1078 >            else if(currentHistogram.inputCollection == "muon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1079 >                                                                                                     cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1080 >                                                                                                     cumulativeFlags.at("muon-secondary jet pairs").at(currentDir),scaleFactor);
1081 >            else if(currentHistogram.inputCollection == "electron-secondary jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1082 >                                                                                                     cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1083 >                                                                                                     cumulativeFlags.at("electron-secondary jet pairs").at(currentDir),scaleFactor);
1084 >            else if(currentHistogram.inputCollection == "photon-secondary jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1085 >                                                                                                     cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("secondary jets").at(currentDir), \
1086 >                                                                                                     cumulativeFlags.at("photon-secondary jet pairs").at(currentDir),scaleFactor);
1087 >            else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
1088 >            else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
1089 >            else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1090 >                                                                                                   cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
1091 >                                                                                                   cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
1092 >            else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
1093 >                                                                                         cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1094 >                                                                                         cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
1095 >            else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
1096 >                                                                                                             cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
1097 >                                                                                                             cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
1098 >            else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
1099 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
1100 >                                                                                               cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
1101 >            else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
1102 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1103 >                                                                                              cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
1104 >            else if(currentHistogram.inputCollection == "electron-photon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),photons.product(), \
1105 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1106 >                                                                                              cumulativeFlags.at("electron-photon pairs").at(currentDir),scaleFactor);
1107 >            else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
1108 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1109 >                                                                                          cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
1110 >            else if(currentHistogram.inputCollection == "photon-jet pairs") fill2DHistogram(histo,currentHistogram,photons.product(),jets.product(), \
1111 >                                                                                          cumulativeFlags.at("photons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
1112 >                                                                                          cumulativeFlags.at("photon-jet pairs").at(currentDir),scaleFactor);
1113 >            else if(currentHistogram.inputCollection == "muon-photon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),photons.product(), \
1114 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("photons").at(currentDir), \
1115 >                                                                                          cumulativeFlags.at("muon-photon pairs").at(currentDir),scaleFactor);
1116 >            else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
1117 >                                                                                                cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1118 >                                                                                                cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
1119 >            else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
1120 >                                                                                            cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1121 >                                                                                            cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
1122 >            else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
1123 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1124 >                                                                                          cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
1125 >            else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
1126 >                                                                                         cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
1127 >                                                                                         cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
1128 >            else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
1129 >                                                                                           cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
1130 >                                                                                           cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
1131 >            else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
1132 >                                                                                                  cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1133 >                                                                                                  cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
1134 >            else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
1135 >                                                                                              cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
1136 >                                                                                              cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
1137 >            else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
1138 >            else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
1139 >            else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
1140 >            else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
1141 >            else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
1142 >                                                                                             cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
1143 >                                                                                             cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
1144 >            else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
1145 >            else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
1146 >            else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
1147 >            else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
1148 >            else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
1149 >            else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
1150 >            else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
1151 >            else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
1152 >          }
1153  
577      if(currentHistogram.inputVariables.size() == 1){
578        TH1D* histo;
579        histo = oneDHists_.at(currentChannelIndex).at(currentHistogram.name);
580
581
582
583        if(currentHistogram.inputCollection == "jets") fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
584         else if(currentHistogram.inputCollection == "muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
585        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
586                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
587                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
588        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
589        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
590                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(),\
591                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
592        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
593                                                                                              cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(),
594                                                                                              cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
595        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
596        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
597        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
598        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
599        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
600        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
601        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
602        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
603        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
604        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
605      }
606      else if(currentHistogram.inputVariables.size() == 2){
607        TH2D* histo;
608        histo = twoDHists_.at(currentChannelIndex).at(currentHistogram.name);
609
610
611
612        if(currentHistogram.inputCollection == "jets") fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").back(),scaleFactor);
613        else if(currentHistogram.inputCollection == "muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").back(),scaleFactor);
614        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
615                                                                                       cumulativeFlags.at("muons").back(),cumulativeFlags.at("muons").back(), \
616                                                                                       cumulativeFlags.at("muon-muon pairs").back(),scaleFactor);
617        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").back(),scaleFactor);
618        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
619                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("electrons").back(), \
620                                                                                               cumulativeFlags.at("electron-electron pairs").back(),scaleFactor);
621        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
622                                                                                               cumulativeFlags.at("electrons").back(),cumulativeFlags.at("muons").back(), \
623                                                                                               cumulativeFlags.at("electron-muon pairs").back(),scaleFactor);
624        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").back(),scaleFactor);
625        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").back(),scaleFactor);
626        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").back(),scaleFactor);
627        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").back(),scaleFactor);
628        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").back(),scaleFactor);
629        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").back(),scaleFactor);
630        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").back(),scaleFactor);
631        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").back(),scaleFactor);
632        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").back(),scaleFactor);
633        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").back(),scaleFactor);
634      }
635    }
636
637    //fills histograms with the sizes of collections
638    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
639      string currentObject = objectsToPlot.at(currentObjectIndex);
640
641      string objectToPlot = "";
642
643      if(currentObject == "muon-muon pairs") objectToPlot = "dimuonPairs";
644      else if(currentObject == "electron-electron pairs") objectToPlot = "dielectronPairs";
645      else if(currentObject == "electron-muon pairs") objectToPlot = "electronMuonPairs";
646      else objectToPlot = currentObject;
647      string tempCurrentObject = objectToPlot;
648      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
649      string histoName = "num" + tempCurrentObject;
650
651
652
653
654      //set position of primary vertex in event, in order to calculate quantities relative to it
655      if(std::find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
656        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).back();
657        int numToPlot = 0;
658        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
659          if(lastCutFlags.at(currentFlag)) numToPlot++;
660        }
661        if(objectToPlot == "primaryvertexs"){
662          oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
663          oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1154          }
665        else
666          oneDHists_.at(currentChannelIndex).at(histoName)->Fill(numToPlot,scaleFactor);
667      }
668      else if(objectToPlot == "jets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(jets->size(),scaleFactor);
669      else if(objectToPlot == "muons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size(),scaleFactor);
670      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
671      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size(),scaleFactor);
672      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
673      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
674      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(events->size(),scaleFactor);
675      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(taus->size(),scaleFactor);
676      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mets->size(),scaleFactor);
677      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(tracks->size(),scaleFactor);
678      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(genjets->size(),scaleFactor);
679      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(mcparticles->size(),scaleFactor);
680      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(bxlumis->size(),scaleFactor);
681      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(photons->size(),scaleFactor);
682      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(histoName)->Fill(superclusters->size(),scaleFactor);
683      else if(objectToPlot == "primaryvertexs"){
684        oneDHists_.at(currentChannelIndex).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
685        oneDHists_.at(currentChannelIndex).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
686      }
1155  
688    }
1156  
1157 +        //fills histograms with the sizes of collections
1158 +        for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
1159 +
1160 +          string currentObject = objectsToPlot.at(currentObjectIndex);
1161 +          string objectToPlot = "";
1162 +
1163 +          // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
1164 +          if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
1165 +          else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
1166 +          else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
1167 +          else if(currentObject == "electron-photon pairs")                objectToPlot = "electronPhotonPairs";
1168 +          else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
1169 +          else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
1170 +          else if(currentObject == "muon-photon pairs")                     objectToPlot = "muonPhotonPairs";
1171 +          else if(currentObject == "photon-jet pairs")                     objectToPlot = "photonJetPairs";
1172 +          else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
1173 +          else if(currentObject == "jet-secondary jet pairs")            objectToPlot = "jetSecondaryJetPairs";
1174 +          else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
1175 +          else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
1176 +          else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
1177 +          else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
1178 +          else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
1179 +          else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
1180 +          else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
1181 +          else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
1182 +          else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
1183 +          else if(currentObject == "muon-secondary jet pairs")           objectToPlot = "muonSecondaryJetPairs";
1184 +          else if(currentObject == "electron-secondary jet pairs")       objectToPlot = "electronSecondaryJetPairs";
1185 +          else if(currentObject == "photon-secondary jet pairs")       objectToPlot = "photonSecondaryJetPairs";
1186 +          else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
1187 +          else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
1188 +          else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
1189 +          else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
1190 +          else objectToPlot = currentObject;
1191 +
1192 +          string tempCurrentObject = objectToPlot;
1193 +          tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
1194 +          string histoName = "num" + tempCurrentObject;
1195 +
1196 +
1197 +          if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1198 +            flagPair lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1199 +            int numToPlot = 0;
1200 +            for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1201 +              if(lastCutFlags.at(currentFlag).second) numToPlot++;
1202 +            }
1203 +
1204 +            if(objectToPlot == "primaryvertexs"){
1205 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1206 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1207 +            }
1208 +            else {
1209 +              oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1210 +            }
1211 +          }
1212 +        } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1213  
1214  
1215 +      } // end if(eventPassedPreviousCuts.at(currentDir))
1216 +    } // end loop over cuts
1217  
1218 <  } //end loop over channel
1218 >    if (!useEDMFormat_ && eventPassedAllCuts){
1219 >      // Assign BNTree variables
1220 >      for (uint iBranch = 0; iBranch != treeBranches_.size(); iBranch++) {
1221 >        BranchSpecs brSpecs = treeBranches_.at(iBranch);
1222 >        string coll = brSpecs.inputCollection;
1223 >        if (cumulativeFlags.count(coll) == 0) cout << "Error: no flags found for collection:  " << coll << ", will cause a seg fault" << endl;
1224 >
1225 >        if     (coll == "jets")                assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1226 >        else if(coll == "secondary jets")      assignTreeBranch(brSpecs,jets.product(),          cumulativeFlags.at(coll).back());
1227 >        else if(coll == "muons")               assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1228 >        else if(coll == "secondary muons")     assignTreeBranch(brSpecs,muons.product(),         cumulativeFlags.at(coll).back());
1229 >        else if(coll == "electrons")           assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1230 >        else if(coll == "secondary electrons") assignTreeBranch(brSpecs,electrons.product(),     cumulativeFlags.at(coll).back());
1231 >        else if(coll == "events")              assignTreeBranch(brSpecs,events.product(),        cumulativeFlags.at(coll).back());
1232 >        else if(coll == "taus")                assignTreeBranch(brSpecs,taus.product(),          cumulativeFlags.at(coll).back());
1233 >        else if(coll == "mets")                assignTreeBranch(brSpecs,mets.product(),          cumulativeFlags.at(coll).back());
1234 >        else if(coll == "tracks")              assignTreeBranch(brSpecs,tracks.product(),        cumulativeFlags.at(coll).back());
1235 >        else if(coll == "genjets")             assignTreeBranch(brSpecs,genjets.product(),       cumulativeFlags.at(coll).back());
1236 >        else if(coll == "mcparticles")         assignTreeBranch(brSpecs,mcparticles.product(),   cumulativeFlags.at(coll).back());
1237 >        else if(coll == "primaryvertexs")      assignTreeBranch(brSpecs,primaryvertexs.product(),cumulativeFlags.at(coll).back());
1238 >        else if(coll == "bxlumis")             assignTreeBranch(brSpecs,bxlumis.product(),       cumulativeFlags.at(coll).back());
1239 >        else if(coll == "photons")             assignTreeBranch(brSpecs,photons.product(),       cumulativeFlags.at(coll).back());
1240 >        else if(coll == "superclusters")       assignTreeBranch(brSpecs,superclusters.product(), cumulativeFlags.at(coll).back());
1241 >        else if(coll == "trigobjs")            assignTreeBranch(brSpecs,trigobjs.product(),      cumulativeFlags.at(coll).back());
1242 >        else if(coll == "stops"
1243 >                && datasetType_ == "signalMC") assignTreeBranch(brSpecs,stops.product(),         cumulativeFlags.at(coll).back());
1244 >      } // end loop over branches
1245  
1246 <  masterCutFlow_->fillCutFlow(scaleFactor);
1246 >      if (!BNTrees_.at(currentChannelIndex)) { cout << "ERROR:  Undefined BNTree.  Will likely seg fault." << endl; }
1247 >      BNTrees_.at(currentChannelIndex)->Fill();  // only fill if event has passed cuts
1248 >    }
1249  
1250 +    (*channelDecisions)[currentChannel.name] = eventPassedAllCuts;
1251  
1252 +  } // end loop over channel
1253 +
1254 +  masterCutFlow_->fillCutFlow(masterScaleFactor);
1255 +
1256 +  event.put (channelDecisions, "channelDecisions");
1257 +
1258 + } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1259  
699 }
1260  
1261  
1262   bool
# Line 710 | Line 1270 | OSUAnalysis::evaluateComparison (double
1270    else if(comparison == "==") return testValue == cutValue;
1271    else if(comparison == "=") return testValue == cutValue;
1272    else if(comparison == "!=") return testValue != cutValue;
1273 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1273 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1274  
1275   }
1276  
1277   bool
1278 < OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, const BNtriggerCollection* triggerCollection){
1278 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1279  
1280 +
1281 +  if(comparison == ">")       return testValue >  cutValue;
1282 +  else if(comparison == ">=") return testValue >= cutValue;
1283 +  else if(comparison == "<")  return testValue <  cutValue;
1284 +  else if(comparison == "<=") return testValue <= cutValue;
1285 +  else if(comparison == "==") return testValue == cutValue;
1286 +  else if(comparison == "=") return testValue == cutValue;
1287 +  else if(comparison == "!=") return testValue != cutValue;
1288 +  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1289 +
1290 + }
1291 +
1292 + bool
1293 + OSUAnalysis::evaluateTriggers (vector<string> triggersToTest, vector<string> triggersToVeto, const BNtriggerCollection* triggerCollection){
1294 +
1295 +  //initialize to false until a chosen trigger is passed
1296    bool triggerDecision = false;
1297  
1298 <  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++)
1299 <    {
1300 <      if(trigger->pass != 1) continue;
1301 <      for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1302 <        {
1303 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1304 <            triggerDecision = true;
1305 <          }
1306 <        }
1298 >  if (printAllTriggers_) cout << "Printing list of all available triggers (which this event may or may not pass):" << endl;
1299 >  //loop over all triggers defined in the event
1300 >  for (BNtriggerCollection::const_iterator trigger = triggerCollection->begin (); trigger != triggerCollection->end (); trigger++){
1301 >
1302 >    if (printAllTriggers_) cout << "   " << trigger->name << endl;
1303 >
1304 >    //we're only interested in triggers that actually passed
1305 >    if(trigger->pass != 1) continue;
1306 >
1307 >    //if the event passes one of the veto triggers, exit and return false
1308 >    for(uint triggerName = 0; triggerName != triggersToVeto.size(); triggerName++){
1309 >      if(trigger->name.find(triggersToVeto.at(triggerName))!=string::npos) return false;
1310      }
1311 <  return triggerDecision;
1311 >    //if the event passes one of the chosen triggers, set triggerDecision to true
1312 >    for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++){
1313 >      if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos) triggerDecision = true;
1314 >    }
1315 >  }
1316  
1317 +  printAllTriggers_ = false;  // only print triggers once, not every event
1318 +
1319 +  //if none of the veto triggers fired:
1320 +  //return the OR of all the chosen triggers
1321 +  if (triggersToTest.size() != 0) return triggerDecision;
1322 +  //or if no triggers were defined return true
1323 +  else return true;
1324   }
1325  
1326 < std::vector<std::string>
1326 >
1327 > vector<string>
1328   OSUAnalysis::splitString (string inputString){
1329  
1330 <  std::stringstream stringStream(inputString);
1331 <  std::istream_iterator<std::string> begin(stringStream);
1332 <  std::istream_iterator<std::string> end;
1333 <  std::vector<std::string> stringVector(begin, end);
1330 >  stringstream stringStream(inputString);
1331 >  istream_iterator<string> begin(stringStream);
1332 >  istream_iterator<string> end;
1333 >  vector<string> stringVector(begin, end);
1334    return stringVector;
1335  
1336   }
1337  
1338 +
1339 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1340 +  // Set two object strings from the tempInputCollection string,
1341 +  // For example, if tempInputCollection is "electron-muon pairs",
1342 +  // then obj1 = "electrons" and obj2 = "muons".
1343 +  // Note that the objects have an "s" appended.
1344 +
1345 +  int dashIndex = tempInputCollection.find("-");
1346 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1347 +  int secondWordLength = spaceIndex - dashIndex;
1348 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1349 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1350 +
1351 + }
1352 +
1353 +
1354 + string OSUAnalysis::getObjToGet(string obj) {
1355 +  // Return the string corresponding to the object to get for the given obj string.
1356 +  // Right now this only handles the case in which obj contains "secondary",
1357 +  // e.g, "secondary muons".
1358 +  // Note that "s" is NOT appended.
1359 +
1360 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1361 +  int firstSpaceIndex = obj.find_first_of(" ");
1362 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1363 +
1364 + }
1365 +
1366 +
1367 + //!jet valueLookup
1368   double
1369 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1369 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1370  
1371    double value = 0.0;
1372    if(variable == "energy") value = object->energy;
# Line 864 | Line 1485 | OSUAnalysis::valueLookup (const BNjet* o
1485    else if(variable == "puJetId_loose_simple") value = object->puJetId_loose_simple;
1486    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1487  
1488 +  //user defined variable
1489 +  else if(variable == "disappTrkLeadingJetID") {
1490 +    value = object->pt > 110
1491 +      && fabs(object->eta) < 2.4
1492 +      && object->chargedHadronEnergyFraction > 0.2
1493 +      && object->neutralHadronEnergyFraction < 0.7
1494 +      && object->chargedEmEnergyFraction < 0.5
1495 +      && object->neutralEmEnergyFraction < 0.7;
1496 +  }
1497  
1498 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1498 >  else if(variable == "disappTrkSubLeadingJetID") {
1499 >    value = object->pt > 30
1500 >      && fabs(object->eta) < 4.5
1501 >      && object->neutralHadronEnergyFraction < 0.7
1502 >      && object->chargedEmEnergyFraction < 0.5;
1503 >  }
1504 >
1505 >
1506 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1507  
1508    value = applyFunction(function, value);
1509  
# Line 873 | Line 1511 | OSUAnalysis::valueLookup (const BNjet* o
1511   }
1512  
1513  
1514 <
1514 > //!muon valueLookup
1515   double
1516 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1516 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1517  
1518    double value = 0.0;
1519    if(variable == "energy") value = object->energy;
# Line 1030 | Line 1668 | OSUAnalysis::valueLookup (const BNmuon*
1668    else if(variable == "time_ndof") value = object->time_ndof;
1669  
1670    //user-defined variables
1671 +  else if(variable == "looseID") {
1672 +    value = object->pt > 10
1673 +      && object->isGlobalMuon > 0
1674 +      && object->isTrackerMuon > 0;
1675 +      }
1676    else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1677    else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1678    else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1679    else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1680    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1681    else if(variable == "metMT") {
1682 <    const BNmet *met = chosenMET ();
1040 <    if (met)
1682 >    if (const BNmet *met = chosenMET ())
1683        {
1684 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
1685 <                       p2 (met->px, met->py, 0.0, met->pt);
1044 <
1045 <        value = (p1 + p2).Mt ();
1684 >        double dPhi = deltaPhi (object->phi, met->phi);
1685 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1686        }
1687      else
1688        value = -999;
# Line 1169 | Line 1809 | OSUAnalysis::valueLookup (const BNmuon*
1809    }
1810    else if(variable == "tightIDdisplaced"){
1811      value = object->isGlobalMuon > 0                \
1812 +      && object->isPFMuon > 0                        \
1813        && object->normalizedChi2 < 10                \
1814        && object->numberOfValidMuonHits > 0        \
1815        && object->numberOfMatchedStations > 1        \
# Line 1176 | Line 1817 | OSUAnalysis::valueLookup (const BNmuon*
1817        && object->numberOfLayersWithMeasurement > 5;
1818    }
1819  
1820 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1821  
1822 +  else if(variable == "genMatchedPdgId"){
1823 +    int index = getGenMatchedParticleIndex(object);
1824 +    if(index == -1) value = 0;
1825 +    else value = mcparticles->at(index).id;
1826 +  }
1827  
1828    else if(variable == "genMatchedId"){
1829      int index = getGenMatchedParticleIndex(object);
# Line 1188 | Line 1835 | OSUAnalysis::valueLookup (const BNmuon*
1835      if(index == -1) value = 0;
1836      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1837    }
1838 +  else if(variable == "genMatchedMotherIdReverse"){
1839 +    int index = getGenMatchedParticleIndex(object);
1840 +    if(index == -1) value = 24;
1841 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1842 +  }
1843    else if(variable == "genMatchedGrandmotherId"){
1844      int index = getGenMatchedParticleIndex(object);
1845      if(index == -1) value = 0;
# Line 1198 | Line 1850 | OSUAnalysis::valueLookup (const BNmuon*
1850      }
1851      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1852    }
1853 +  else if(variable == "genMatchedGrandmotherIdReverse"){
1854 +    int index = getGenMatchedParticleIndex(object);
1855 +    if(index == -1) value = 24;
1856 +    else if(fabs(mcparticles->at(index).motherId) == 15){
1857 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1858 +      if(motherIndex == -1) value = 24;
1859 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1860 +    }
1861 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1862 +  }
1863 +  else if(variable == "pfMuonsFromVertex"){
1864 +    double d0Error, dzError;
1865 +
1866 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1867 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1868 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1869 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
1870 +      || fabs (object->correctedDZ / dzError) > 99.0;
1871 +    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1872 +  }
1873  
1874  
1875  
1876 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1876 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1877  
1878    value = applyFunction(function, value);
1879  
1880    return value;
1881   }
1882  
1883 <
1883 > //!electron valueLookup
1884   double
1885 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1885 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1886  
1887    double value = 0.0;
1888    if(variable == "energy") value = object->energy;
# Line 1376 | Line 2048 | OSUAnalysis::valueLookup (const BNelectr
2048    else if(variable == "detIso") value = (object->trackIso) / object->pt;
2049    else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
2050    else if(variable == "metMT") {
2051 <    const BNmet *met = chosenMET ();
1380 <    if (met)
2051 >    if (const BNmet *met = chosenMET ())
2052        {
2053 <        TLorentzVector p1 (object->px, object->py, object->pz, object->energy),
2054 <                       p2 (met->px, met->py, 0.0, met->pt);
1384 <
1385 <        value = (p1 + p2).Mt ();
2053 >        double dPhi = deltaPhi (object->phi, met->phi);
2054 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
2055        }
2056      else
2057        value = -999;
# Line 1474 | Line 2143 | OSUAnalysis::valueLookup (const BNelectr
2143        }
2144    }
2145  
2146 +  else if(variable == "looseID"){
2147 +    value = object->pt > 10
2148 +      && object->mvaNonTrigV0 > 0;
2149 +      }
2150    else if(variable == "correctedD0VertexInEBPositiveCharge"){
2151      if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
2152      else value = -999;
# Line 1546 | Line 2219 | OSUAnalysis::valueLookup (const BNelectr
2219        }
2220    }
2221  
2222 +
2223 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2224 +
2225 +  else if(variable == "genMatchedPdgId"){
2226 +    int index = getGenMatchedParticleIndex(object);
2227 +    if(index == -1) value = 0;
2228 +    else value = mcparticles->at(index).id;
2229 +  }
2230 +
2231 +
2232    else if(variable == "genMatchedId"){
2233      int index = getGenMatchedParticleIndex(object);
2234      if(index == -1) value = 0;
# Line 1556 | Line 2239 | OSUAnalysis::valueLookup (const BNelectr
2239      if(index == -1) value = 0;
2240      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2241    }
2242 +  else if(variable == "genMatchedMotherIdReverse"){
2243 +    int index = getGenMatchedParticleIndex(object);
2244 +    if(index == -1) value = 24;
2245 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2246 +  }
2247    else if(variable == "genMatchedGrandmotherId"){
2248      int index = getGenMatchedParticleIndex(object);
2249      if(index == -1) value = 0;
# Line 1566 | Line 2254 | OSUAnalysis::valueLookup (const BNelectr
2254      }
2255      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2256    }
2257 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2258 +    int index = getGenMatchedParticleIndex(object);
2259 +    if(index == -1) value = 24;
2260 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2261 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2262 +      if(motherIndex == -1) value = 24;
2263 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2264 +    }
2265 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2266 +  }
2267 +  else if(variable == "pfElectronsFromVertex"){
2268 +    double d0Error, dzError;
2269  
2270 +    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2271 +    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2272 +    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2273 +      || fabs (object->correctedD0Vertex / d0Error) > 99.0
2274 +      || fabs (object->correctedDZ / dzError) > 99.0;
2275 +    value = !value;
2276 +  }
2277  
2278  
2279 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2279 >
2280 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2281  
2282    value = applyFunction(function, value);
2283  
2284    return value;
2285   }
2286  
2287 <
2287 > //!event valueLookup
2288   double
2289 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2289 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2290  
2291    double value = 0.0;
2292  
# Line 1647 | Line 2355 | OSUAnalysis::valueLookup (const BNevent*
2355    else if(variable == "id2") value = object->id2;
2356    else if(variable == "evt") value = object->evt;
2357    else if(variable == "puScaleFactor"){
2358 <    if(datasetType_ != "data")
2358 >    if(doPileupReweighting_ && datasetType_ != "data")
2359        value = puWeight_->at (events->at (0).numTruePV);
2360      else
2361        value = 1.0;
2362    }
2363 <  else if(variable == "muonScaleFactor"){
2364 <    if(datasetType_ != "data")
2365 <      value = muonSFWeight_->at (chosenMuon ()->eta);
2366 <    else
2367 <      value = 1.0;
1660 <  }
1661 <  else if(variable == "electronScaleFactor"){
1662 <    if(datasetType_ != "data")
1663 <      value = electronSFWeight_->at (chosenElectron ()->eta, chosenElectron ()->pt);
1664 <    else
1665 <      value = 1.0;
1666 <  }
1667 <
1668 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2363 >  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2364 >  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2365 >  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2366 >  else if(variable == "bTagScaleFactor") value = bTagScaleFactor_;
2367 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2368  
2369    value = applyFunction(function, value);
2370  
2371    return value;
2372   }
2373  
2374 + //!tau valueLookup
2375   double
2376 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2376 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2377  
2378    double value = 0.0;
2379  
# Line 1717 | Line 2417 | OSUAnalysis::valueLookup (const BNtau* o
2417    else if(variable == "HPSdecayModeFinding") value = object->HPSdecayModeFinding;
2418    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2419  
2420 +  else if (variable == "looseHadronicID") {
2421 +    value = object->pt > 10
2422 +      && object->eta < 2.3
2423 +      && object->HPSbyLooseCombinedIsolationDeltaBetaCorr > 0
2424 +      && object->HPSdecayModeFinding > 0
2425 +      && object->HPSagainstElectronLoose > 0
2426 +      && object->HPSagainstMuonTight > 0;
2427 +  }
2428 +
2429 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2430 +
2431 +  else if(variable == "genMatchedPdgId"){
2432 +    int index = getGenMatchedParticleIndex(object);
2433 +    if(index == -1) value = 0;
2434 +    else value = mcparticles->at(index).id;
2435 +  }
2436  
2437    else if(variable == "genMatchedId"){
2438      int index = getGenMatchedParticleIndex(object);
# Line 1728 | Line 2444 | OSUAnalysis::valueLookup (const BNtau* o
2444      if(index == -1) value = 0;
2445      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2446    }
2447 +  else if(variable == "genMatchedMotherIdReverse"){
2448 +    int index = getGenMatchedParticleIndex(object);
2449 +    if(index == -1) value = 24;
2450 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2451 +  }
2452    else if(variable == "genMatchedGrandmotherId"){
2453      int index = getGenMatchedParticleIndex(object);
2454      if(index == -1) value = 0;
# Line 1738 | Line 2459 | OSUAnalysis::valueLookup (const BNtau* o
2459      }
2460      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2461    }
2462 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2463 +    int index = getGenMatchedParticleIndex(object);
2464 +    if(index == -1) value = 24;
2465 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2466 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2467 +      if(motherIndex == -1) value = 24;
2468 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2469 +    }
2470 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2471 +  }
2472  
2473  
2474 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2474 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2475  
2476    value = applyFunction(function, value);
2477  
2478    return value;
2479   }
2480  
2481 + //!met valueLookup
2482   double
2483 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2483 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2484  
2485    double value = 0.0;
2486  
# Line 1812 | Line 2544 | OSUAnalysis::valueLookup (const BNmet* o
2544    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2545    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2546  
2547 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2547 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2548  
2549    value = applyFunction(function, value);
2550  
2551    return value;
2552   }
2553  
2554 + //!track valueLookup
2555   double
2556 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2556 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2557  
2558    double value = 0.0;
2559    double pMag = sqrt(object->pt * object->pt +
2560 <                         object->pz * object->pz);
2560 >                     object->pz * object->pz);
2561  
2562    if(variable == "pt") value = object->pt;
2563    else if(variable == "px") value = object->px;
# Line 1846 | Line 2579 | OSUAnalysis::valueLookup (const BNtrack*
2579  
2580  
2581    //additional BNs info for disappTrks
1849  else if(variable == "isGoodPtResolution") value = object->isGoodPtResolution;
2582    else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2583    else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2584    else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2585    else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2586    else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2587    else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2588 +  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2589    else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2590    else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2591    else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2592 +  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2593 +
2594    //user defined variables
2595    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;
2596    else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2597 <  else if(variable == "caloTotDeltaRp5") value =(object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2598 <  else if(variable == "caloTotDeltaRp5ByP") value =( (object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2599 <  else if(variable == "isIso") value = getTrkIsIso(object, tracks.product());
2600 <  else if(variable == "isMatchedDeadEcal") value = getTrkIsMatchedDeadEcal(object);
2601 <  else if(variable == "ptErrorByPt") value = (object->ptError/object->pt);
2602 <  else if(variable == "ptError") value = object->ptError;
2603 <  else if(variable == "ptRes") value = getTrkPtRes(object);
2597 >  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2598 >  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2599 >  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2600 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2601 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2602 >  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2603 >  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2604 >  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2605 >  else if(variable == "ptError")                    value = object->ptError;
2606 >  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2607 >  else if (variable == "d0wrtPV"){
2608 >    double vx = object->vx - chosenVertex ()->x,
2609 >      vy = object->vy - chosenVertex ()->y,
2610 >      px = object->px,
2611 >      py = object->py,
2612 >      pt = object->pt;
2613 >    value = (-vx * py + vy * px) / pt;
2614 >  }
2615 >  else if (variable == "dZwrtPV"){
2616 >    double vx = object->vx - chosenVertex ()->x,
2617 >      vy = object->vy - chosenVertex ()->y,
2618 >      vz = object->vz - chosenVertex ()->z,
2619 >      px = object->px,
2620 >      py = object->py,
2621 >      pz = object->pz,
2622 >      pt = object->pt;
2623 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2624 >  }
2625 >
2626 >
2627 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2628 >
2629 >  else if(variable == "genMatchedPdgId"){
2630 >    int index = getGenMatchedParticleIndex(object);
2631 >    if(index == -1) value = 0;
2632 >    else value = mcparticles->at(index).id;
2633 >  }
2634  
2635  
2636    else if(variable == "genMatchedId"){
# Line 1878 | Line 2643 | OSUAnalysis::valueLookup (const BNtrack*
2643      if(index == -1) value = 0;
2644      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2645    }
2646 +  else if(variable == "genMatchedMotherIdReverse"){
2647 +    int index = getGenMatchedParticleIndex(object);
2648 +    if(index == -1) value = 24;
2649 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2650 +  }
2651    else if(variable == "genMatchedGrandmotherId"){
2652      int index = getGenMatchedParticleIndex(object);
2653      if(index == -1) value = 0;
# Line 1888 | Line 2658 | OSUAnalysis::valueLookup (const BNtrack*
2658      }
2659      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2660    }
2661 +  else if(variable == "genMatchedGrandmotherIdReverse"){
2662 +    int index = getGenMatchedParticleIndex(object);
2663 +    if(index == -1) value = 24;
2664 +    else if(fabs(mcparticles->at(index).motherId) == 15){
2665 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2666 +      if(motherIndex == -1) value = 24;
2667 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2668 +    }
2669 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2670 +  }
2671  
2672  
2673  
2674 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2674 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2675  
2676    value = applyFunction(function, value);
2677  
2678    return value;
2679   }
2680  
2681 + //!genjet valueLookup
2682   double
2683 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2683 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2684  
2685    double value = 0.0;
2686  
# Line 1919 | Line 2700 | OSUAnalysis::valueLookup (const BNgenjet
2700    else if(variable == "charge") value = object->charge;
2701  
2702  
2703 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2703 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2704  
2705    value = applyFunction(function, value);
2706  
2707    return value;
2708   }
2709  
2710 + //!mcparticle valueLookup
2711   double
2712 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2712 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2713  
2714    double value = 0.0;
2715  
# Line 2052 | Line 2834 | OSUAnalysis::valueLookup (const BNmcpart
2834    }
2835  
2836  
2837 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2837 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2838  
2839    value = applyFunction(function, value);
2840  
2841    return value;
2842   }
2843  
2844 + //!primaryvertex valueLookup
2845   double
2846 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2846 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2847  
2848    double value = 0.0;
2849  
# Line 2079 | Line 2862 | OSUAnalysis::valueLookup (const BNprimar
2862    else if(variable == "isGood") value = object->isGood;
2863  
2864  
2865 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2865 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2866  
2867    value = applyFunction(function, value);
2868  
2869    return value;
2870   }
2871  
2872 + //!bxlumi valueLookup
2873   double
2874 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2874 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2875  
2876    double value = 0.0;
2877  
# Line 2096 | Line 2880 | OSUAnalysis::valueLookup (const BNbxlumi
2880    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2881  
2882  
2883 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2883 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2884  
2885    value = applyFunction(function, value);
2886  
2887    return value;
2888   }
2889  
2890 + //!photon valueLookup
2891   double
2892 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2892 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2893  
2894    double value = 0.0;
2895  
# Line 2179 | Line 2964 | OSUAnalysis::valueLookup (const BNphoton
2964    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2965  
2966  
2967 +
2968 +
2969 +  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2970 +
2971 +  else if(variable == "genMatchedPdgId"){
2972 +    int index = getGenMatchedParticleIndex(object);
2973 +    if(index == -1) value = 0;
2974 +    else value = mcparticles->at(index).id;
2975 +  }
2976 +
2977 +
2978 +
2979    else if(variable == "genMatchedId"){
2980      int index = getGenMatchedParticleIndex(object);
2981      if(index == -1) value = 0;
# Line 2189 | Line 2986 | OSUAnalysis::valueLookup (const BNphoton
2986      if(index == -1) value = 0;
2987      else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2988    }
2989 +  else if(variable == "genMatchedMotherIdReverse"){
2990 +    int index = getGenMatchedParticleIndex(object);
2991 +    if(index == -1) value = 24;
2992 +    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2993 +  }
2994    else if(variable == "genMatchedGrandmotherId"){
2995      int index = getGenMatchedParticleIndex(object);
2996      if(index == -1) value = 0;
# Line 2199 | Line 3001 | OSUAnalysis::valueLookup (const BNphoton
3001      }
3002      else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3003    }
3004 +  else if(variable == "genMatchedGrandmotherIdReverse"){
3005 +    int index = getGenMatchedParticleIndex(object);
3006 +    if(index == -1) value = 24;
3007 +    else if(fabs(mcparticles->at(index).motherId) == 15){
3008 +      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
3009 +      if(motherIndex == -1) value = 24;
3010 +      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
3011 +    }
3012 +    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
3013 +  }
3014  
3015  
3016 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3016 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3017  
3018    value = applyFunction(function, value);
3019  
3020    return value;
3021   }
3022  
3023 + //!supercluster valueLookup
3024   double
3025 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
3025 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
3026  
3027    double value = 0.0;
3028  
# Line 2223 | Line 3036 | OSUAnalysis::valueLookup (const BNsuperc
3036    else if(variable == "theta") value = object->theta;
3037  
3038  
3039 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3039 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3040  
3041    value = applyFunction(function, value);
3042  
3043    return value;
3044   }
3045  
3046 + //!trigobj valueLookup
3047 + double
3048 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
3049 +
3050 +  double value = 0.0;
3051 +
3052 +  if(variable == "pt") value = object->pt;
3053 +  else if(variable == "eta") value = object->eta;
3054 +  else if(variable == "phi") value = object->phi;
3055 +  else if(variable == "px") value = object->px;
3056 +  else if(variable == "py") value = object->py;
3057 +  else if(variable == "pz") value = object->pz;
3058 +  else if(variable == "et") value = object->et;
3059 +  else if(variable == "energy") value = object->energy;
3060 +  else if(variable == "etTotal") value = object->etTotal;
3061 +  else if(variable == "id") value = object->id;
3062 +  else if(variable == "charge") value = object->charge;
3063 +  else if(variable == "isIsolated") value = object->isIsolated;
3064 +  else if(variable == "isMip") value = object->isMip;
3065 +  else if(variable == "isForward") value = object->isForward;
3066 +  else if(variable == "isRPC") value = object->isRPC;
3067 +  else if(variable == "bx") value = object->bx;
3068 +  else if(variable == "filter") {
3069 +    if ((stringValue = object->filter) == "")
3070 +      stringValue = "none";  // stringValue should only be empty if value is filled
3071 +  }
3072 +
3073 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3074 +
3075 +  value = applyFunction(function, value);
3076 +
3077 +  return value;
3078 + }
3079  
3080 + //!muon-muon pair valueLookup
3081   double
3082 < OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function){
3082 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3083  
3084    double value = 0.0;
3085  
3086    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3087 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3088    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3089    else if(variable == "invMass"){
3090      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3091      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3092      value = (fourVector1 + fourVector2).M();
3093    }
3094 +  else if(variable == "pt"){
3095 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3096 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3097 +    value = (fourVector1 + fourVector2).Pt();
3098 +  }
3099    else if(variable == "threeDAngle")
3100      {
3101        TVector3 threeVector1(object1->px, object1->py, object1->pz);
# Line 2273 | Line 3126 | OSUAnalysis::valueLookup (const BNmuon*
3126    else if(variable == "muon2CorrectedD0Vertex"){
3127      value = object2->correctedD0Vertex;
3128    }
3129 < else if(variable == "muon1timeAtIpInOut"){
3129 >  else if(variable == "muon1timeAtIpInOut"){
3130      value = object1->timeAtIpInOut;
3131    }
3132 < else if(variable == "muon2timeAtIpInOut"){
3132 >  else if(variable == "muon2timeAtIpInOut"){
3133      value = object2->timeAtIpInOut;
3134    }
3135 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3135 >  else if(variable == "muon1correctedD0")
3136 >    {
3137 >      value = object1->correctedD0;
3138 >    }
3139 >  else if(variable == "muon2correctedD0")
3140 >    {
3141 >      value = object2->correctedD0;
3142 >    }
3143 >
3144 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3145 >
3146 >  value = applyFunction(function, value);
3147 >
3148 >  return value;
3149 > }
3150 >
3151 > //!muon-photon pair valueLookup
3152 > double
3153 > OSUAnalysis::valueLookup (const BNmuon* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3154 >
3155 >  double value = 0.0;
3156 >
3157 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3158 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3159 >  else if(variable == "photonEta") value = object2->eta;
3160 >  else if(variable == "muonEta") value = object1->eta;
3161 >  else if(variable == "photonPhi") value = object2->phi;
3162 >  else if(variable == "muonPhi") value = object1->phi;
3163 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3164 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3165 >  else if(variable == "muonRelPFdBetaIso") value = (object1->pfIsoR04SumChargedHadronPt + max(0.0, object1->pfIsoR04SumNeutralHadronEt + object1->pfIsoR04SumPhotonEt - 0.5*object1->pfIsoR04SumPUPt)) / object1->pt;
3166 >  else if(variable == "invMass"){
3167 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3168 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3169 >    value = (fourVector1 + fourVector2).M();
3170 >  }
3171 >  else if(variable == "pt"){
3172 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3173 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3174 >    value = (fourVector1 + fourVector2).Pt();
3175 >  }
3176 >  else if(variable == "threeDAngle")
3177 >    {
3178 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3179 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3180 >      value = (threeVector1.Angle(threeVector2));
3181 >    }
3182 >  else if(variable == "alpha")
3183 >    {
3184 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3185 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3186 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3187 >      value = (pi-threeVector1.Angle(threeVector2));
3188 >    }
3189 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3190 >
3191 >  value = applyFunction(function, value);
3192 >
3193 >  return value;
3194 > }
3195 >
3196 > //!electron-photon pair valueLookup
3197 > double
3198 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNphoton* object2, string variable, string function, string &stringValue){
3199 >
3200 >  double value = 0.0;
3201 >
3202 >  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3203 >  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3204 >  else if(variable == "photonEta") value = object2->eta;
3205 >  else if(variable == "electronEta") value = object1->eta;
3206 >  else if(variable == "photonPhi") value = object2->phi;
3207 >  else if(variable == "electronPhi") value = object1->phi;
3208 >  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3209 >  else if(variable == "photonGenMotherId") value = object2->genMotherId;
3210 >  else if(variable == "electronRelPFrhoIso") value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3211 >  else if(variable == "invMass"){
3212 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3213 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3214 >    value = (fourVector1 + fourVector2).M();
3215 >  }
3216 >  else if(variable == "pt"){
3217 >    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3218 >    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3219 >    value = (fourVector1 + fourVector2).Pt();
3220 >  }
3221 >  else if(variable == "threeDAngle")
3222 >    {
3223 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3224 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3225 >      value = (threeVector1.Angle(threeVector2));
3226 >    }
3227 >  else if(variable == "alpha")
3228 >    {
3229 >      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
3230 >      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3231 >      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3232 >      value = (pi-threeVector1.Angle(threeVector2));
3233 >    }
3234 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3235  
3236    value = applyFunction(function, value);
3237  
3238    return value;
3239   }
3240  
3241 + //!electron-electron pair valueLookup
3242   double
3243 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function){
3243 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
3244  
3245    double value = 0.0;
3246  
3247    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3248 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3249    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3250    else if(variable == "invMass"){
3251      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3252      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3253      value = (fourVector1 + fourVector2).M();
3254    }
3255 +  else if(variable == "pt"){
3256 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3257 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3258 +    value = (fourVector1 + fourVector2).Pt();
3259 +  }
3260    else if(variable == "threeDAngle")
3261      {
3262        TVector3 threeVector1(object1->px, object1->py, object1->pz);
# Line 2321 | Line 3280 | OSUAnalysis::valueLookup (const BNelectr
3280    else if(variable == "electron2CorrectedD0Vertex"){
3281      value = object2->correctedD0Vertex;
3282    }
3283 +  else if(variable == "electron1CorrectedD0"){
3284 +    value = object1->correctedD0;
3285 +  }
3286 +  else if(variable == "electron2CorrectedD0"){
3287 +    value = object2->correctedD0;
3288 +  }
3289  
3290 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3290 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3291  
3292    value = applyFunction(function, value);
3293  
3294    return value;
3295   }
3296 <
3296 > //!electron-muon pair valueLookup
3297   double
3298 < OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function){
3298 > OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
3299  
3300    double value = 0.0;
3301  
3302    if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3303 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3304    else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3305    else if(variable == "invMass"){
3306      TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3307      TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3308      value = (fourVector1 + fourVector2).M();
3309    }
3310 +  else if(variable == "pt"){
3311 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3312 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3313 +    value = (fourVector1 + fourVector2).Pt();
3314 +  }
3315    else if(variable == "threeDAngle")
3316      {
3317        TVector3 threeVector1(object1->px, object1->py, object1->pz);
# Line 2376 | Line 3347 | OSUAnalysis::valueLookup (const BNelectr
3347    else if(variable == "muonDetIso"){
3348      value = (object2->trackIsoDR03) / object2->pt;
3349    }
3350 +  else if(variable == "electronRelPFrhoIso"){
3351 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3352 +  }
3353 +  else if(variable == "muonRelPFdBetaIso"){
3354 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3355 +  }
3356 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3357 +  value = applyFunction(function, value);
3358 +
3359 +  return value;
3360 + }
3361 +
3362 + //!electron-jet pair valueLookup
3363 + double
3364 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3365 +
3366 +  double value = 0.0;
3367 +
3368 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3369 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3370 +  else if(variable == "jetEta") value = object2->eta;
3371 +  else if(variable == "jetPhi") value = object2->phi;
3372 +  else if(variable == "electronEta") value = object1->eta;
3373 +  else if(variable == "electronPhi") value = object1->phi;
3374 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3375 +  else if(variable == "invMass"){
3376 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3377 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3378 +    value = (fourVector1 + fourVector2).M();
3379 +  }
3380 +  else if(variable == "pt"){
3381 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3382 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3383 +    value = (fourVector1 + fourVector2).Pt();
3384 +  }
3385 +  else if(variable == "threeDAngle")
3386 +    {
3387 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3388 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3389 +      value = (threeVector1.Angle(threeVector2));
3390 +    }
3391    else if(variable == "chargeProduct"){
3392 <    value = object1->charge * object2->charge;
3392 >    value = object1->charge*object2->charge;
3393    }
3394  
3395 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3396 +  value = applyFunction(function, value);
3397 +
3398 +  return value;
3399 + }
3400 +
3401 + //!photon-jet pair valueLookup
3402 + double
3403 + OSUAnalysis::valueLookup (const BNphoton* object1, const BNjet* object2, string variable, string function, string &stringValue){
3404  
3405 +  double value = 0.0;
3406 +
3407 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3408 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3409 +  else if(variable == "jetEta") value = object2->eta;
3410 +  else if(variable == "jetPhi") value = object2->phi;
3411 +  else if(variable == "photonEta") value = object1->eta;
3412 +  else if(variable == "photonPhi") value = object1->phi;
3413 +  else if(variable == "photonGenMotherId") value = object1->genMotherId;
3414 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3415 +  else if(variable == "invMass"){
3416 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3417 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3418 +    value = (fourVector1 + fourVector2).M();
3419 +  }
3420 +  else if(variable == "pt"){
3421 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3422 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3423 +    value = (fourVector1 + fourVector2).Pt();
3424 +  }
3425 +  else if(variable == "threeDAngle")
3426 +    {
3427 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3428 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3429 +      value = (threeVector1.Angle(threeVector2));
3430 +    }
3431 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3432 +  value = applyFunction(function, value);
3433 +
3434 +  return value;
3435 + }
3436 +
3437 + //!muon-jet pair valueLookup
3438 + double
3439 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3440 +
3441 +  double value = 0.0;
3442 +
3443 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3444 +  else if(variable == "jetEta") value = object2->eta;
3445 +  else if(variable == "jetPhi") value = object2->phi;
3446 +  else if(variable == "muonEta") value = object1->eta;
3447 +  else if(variable == "muonPhi") value = object1->phi;
3448 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3449 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3450 +  else if(variable == "invMass"){
3451 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3452 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3453 +    value = (fourVector1 + fourVector2).M();
3454 +  }
3455 +  else if(variable == "pt"){
3456 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3457 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3458 +    value = (fourVector1 + fourVector2).Pt();
3459 +  }
3460 +  else if(variable == "threeDAngle")
3461 +    {
3462 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3463 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3464 +      value = (threeVector1.Angle(threeVector2));
3465 +    }
3466 +  else if(variable == "chargeProduct"){
3467 +    value = object1->charge*object2->charge;
3468 +  }
3469 +
3470 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3471 +  value = applyFunction(function, value);
3472 +
3473 +  return value;
3474 + }
3475 + //!jet-jet pair valueLookup
3476 + double
3477 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3478 +
3479 +  double value = 0.0;
3480 +
3481 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3482 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3483 +  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3484 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3485 +  else if(variable == "invMass"){
3486 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3487 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3488 +    value = (fourVector1 + fourVector2).M();
3489 +  }
3490 +  else if(variable == "pt"){
3491 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3492 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3493 +    value = (fourVector1 + fourVector2).Pt();
3494 +  }
3495 +  else if(variable == "threeDAngle")
3496 +    {
3497 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3498 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3499 +      value = (threeVector1.Angle(threeVector2));
3500 +    }
3501 +  else if(variable == "chargeProduct"){
3502 +    value = object1->charge*object2->charge;
3503 +  }
3504 +
3505 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3506 +  value = applyFunction(function, value);
3507 +
3508 +  return value;
3509 + }
3510 + //!electron-track pair valueLookup
3511 + double
3512 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3513 +  double electronMass = 0.000511;
3514 +  double value = 0.0;
3515 +  TLorentzVector fourVector1(0, 0, 0, 0);
3516 +  TLorentzVector fourVector2(0, 0, 0, 0);
3517 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3518 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3519 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3520 +  else if(variable == "invMass"){
3521 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3522 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3523 +
3524 +    value = (fourVector1 + fourVector2).M();
3525 +  }
3526 +  else if(variable == "chargeProduct"){
3527 +    value = object1->charge*object2->charge;
3528 +  }
3529    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3530 +  value = applyFunction(function, value);
3531 +  return value;
3532 +
3533 + }
3534 +
3535 +
3536 + //!muon-track pair valueLookup
3537 + double
3538 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3539 +  double pionMass = 0.140;
3540 +  double muonMass = 0.106;
3541 +  double value = 0.0;
3542 +  TLorentzVector fourVector1(0, 0, 0, 0);
3543 +  TLorentzVector fourVector2(0, 0, 0, 0);
3544 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3545 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3546 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3547 +  else if(variable == "invMass"){
3548 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3549 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3550 +
3551 +    value = (fourVector1 + fourVector2).M();
3552 +  }
3553 +  else if(variable == "chargeProduct"){
3554 +    value = object1->charge*object2->charge;
3555 +  }
3556 +
3557 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3558 +  value = applyFunction(function, value);
3559 +  return value;
3560 + }
3561 +
3562 + //!tau-tau pair valueLookup
3563 + double
3564 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3565 +  double value = 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 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3571 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3572 +    value = (fourVector1 + fourVector2).M();
3573 +  }
3574 +
3575 +  else if(variable == "chargeProduct"){
3576 +    value = object1->charge*object2->charge;
3577 +  }
3578 +
3579 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3580 +  value = applyFunction(function, value);
3581 +  return value;
3582 + }
3583 +
3584 + //!muon-tau pair valueLookup
3585 + double
3586 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3587 +  double value = 0.0;
3588 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3589 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3590 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3591 +  else if(variable == "invMass"){
3592 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3593 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3594 +    value = (fourVector1 + fourVector2).M();
3595 +  }
3596 +
3597 +  else if(variable == "chargeProduct"){
3598 +    value = object1->charge*object2->charge;
3599 +  }
3600 +
3601 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3602 +  value = applyFunction(function, value);
3603 +  return value;
3604 + }
3605 +
3606 + //!tau-track pair valueLookup
3607 + double
3608 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3609 +  double value = 0.0;
3610 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3611 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3612 +  else if(variable == "chargeProduct"){
3613 +    value = object1->charge*object2->charge;
3614 +  }
3615 +
3616 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3617 +  value = applyFunction(function, value);
3618 +  return value;
3619 + }
3620 +
3621 +
3622 + //!track-event pair valueLookup
3623 + double
3624 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3625 +
3626 +  double value = 0.0;
3627 +  double pMag = sqrt(object1->pt * object1->pt +
3628 +                     object1->pz * object1->pz);
3629 +
3630 +  if      (variable == "numPV")                      value = object2->numPV;
3631 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3632 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3633 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3634 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3635 +
3636 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3637 +
3638 +  value = applyFunction(function, value);
3639 +
3640 +  return value;
3641 +
3642 + }
3643 +
3644 + //!electron-trigobj pair valueLookup
3645 + double
3646 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3647 +
3648 +  double value = 0.0;
3649 +
3650 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3651 +  else if (variable == "match"){
3652 +    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3653 +      stringValue = object2->filter;
3654 +    else
3655 +      stringValue = "none";
3656 +  }
3657 +
3658 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3659 +
3660 +  value = applyFunction(function, value);
3661 +
3662 +  return value;
3663 +
3664 + }
3665 +
3666 + //!muon-trigobj pair valueLookup
3667 + double
3668 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3669 +
3670 +  double value = 0.0;
3671 +
3672 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3673 +
3674 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3675 +
3676 +  value = applyFunction(function, value);
3677 +
3678 +  return value;
3679 +
3680 + }
3681 +
3682 + //!stop valueLookup
3683 + double
3684 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3685 +
3686 +
3687 +  double value = 0.0;
3688 +
3689 +  if(variable == "ctau") value = object->ctau;
3690 +
3691 +  else if (variable == "d0"){
3692 +    double vx = object->vx - chosenVertex ()->x,
3693 +      vy = object->vy - chosenVertex ()->y,
3694 +      px = object->px,
3695 +      py = object->py,
3696 +      pt = object->pt;
3697 +    value = (-vx * py + vy * px) / pt;
3698 +  }
3699 +
3700 +  else if (variable == "dz"){
3701 +    double vx = object->vx - chosenVertex ()->x,
3702 +      vy = object->vy - chosenVertex ()->y,
3703 +      vz = object->vz - chosenVertex ()->z,
3704 +      px = object->px,
3705 +      py = object->py,
3706 +      pz = object->pz,
3707 +      pt = object->pt;
3708 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3709 +  }
3710 +
3711 +  else if (variable == "minD0"){
3712 +    double minD0=999;
3713 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3714 +      double vx = object->vx - vertex->x,
3715 +        vy = object->vy - vertex->y,
3716 +        px = object->px,
3717 +        py = object->py,
3718 +        pt = object->pt;
3719 +      value = (-vx * py + vy * px) / pt;
3720 +      if(abs(value) < abs(minD0)) minD0 = value;
3721 +    }
3722 +    value = minD0;
3723 +  }
3724 +  else if (variable == "minDz"){
3725 +    double minDz=999;
3726 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3727 +      double vx = object->vx - vertex->x,
3728 +        vy = object->vy - vertex->y,
3729 +        vz = object->vz - vertex->z,
3730 +        px = object->px,
3731 +        py = object->py,
3732 +        pz = object->pz,
3733 +        pt = object->pt;
3734 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3735 +      if(abs(value) < abs(minDz)) minDz = value;
3736 +    }
3737 +    value = minDz;
3738 +  }
3739 +  else if(variable == "distToVertex"){
3740 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3741 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3742 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3743 +  }
3744 +  else if (variable == "minDistToVertex"){
3745 +    double minDistToVertex=999;
3746 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3747 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3748 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3749 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3750 +
3751 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3752 +    }
3753 +    value = minDistToVertex;
3754 +  }
3755 +  else if (variable == "distToVertexDifference"){
3756 +    double minDistToVertex=999;
3757 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3758 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3759 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3760 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3761 +
3762 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3763 +    }
3764 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3765 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3766 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3767 +
3768 +    value = distToChosenVertex - minDistToVertex;
3769 +  }
3770 +
3771 +  else if (variable == "closestVertexRank"){
3772 +    double minDistToVertex=999;
3773 +    int vertex_rank = 0;
3774 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3775 +      vertex_rank++;
3776 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3777 +                      (object->vy-vertex->y)*(object->vy-vertex->y) + \
3778 +                      (object->vz-vertex->z)*(object->vz-vertex->z));
3779 +
3780 +      if(abs(dist) < abs(minDistToVertex)){
3781 +        value = vertex_rank;
3782 +        minDistToVertex = dist;
3783 +      }
3784 +    }
3785 +  }
3786 +
3787 +
3788 +
3789 +
3790 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3791  
3792    value = applyFunction(function, value);
3793  
3794    return value;
3795 +
3796   }
3797  
3798  
3799 +
3800 +
3801   // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3802   // Return true iff no other tracks are found in this cone.
3803   int
# Line 2434 | Line 3843 | OSUAnalysis::getTrkPtTrue (const BNtrack
3843  
3844   }
3845  
3846 + double
3847 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3848 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3849 +  if (!useTrackCaloRhoCorr_) return -99;
3850 +  // if (!rhokt6CaloJetsHandle_) {
3851 +  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3852 +  //   return -99;
3853 +  // }
3854 +  double radDeltaRCone = 0.5;
3855 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3856 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3857 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3858 +  return caloTotRhoCorrCalo;
3859 +
3860 + }
3861 +
3862 +
3863 +
3864 +
3865   //creates a map of the dead Ecal channels in the barrel and endcap
3866   //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
3867   //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
# Line 2466 | Line 3894 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3894    double deltaRLowest = 999;
3895    int value = 0;
3896    if (DeadEcalVec.size() == 0) WriteDeadEcal();
3897 <  for(std::vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3897 >  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3898      double eta = ecal->etaEcal;
3899      double phi = ecal->phiEcal;
3900 <    double deltaRtemp = deltaR(eta, track1->eta, phi, track1->phi);
3900 >    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
3901      if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3902    }
3903    if (deltaRLowest<0.05) {value = 1;}
# Line 2477 | Line 3905 | OSUAnalysis::getTrkIsMatchedDeadEcal (co
3905    return value;
3906   }
3907  
3908 <
3909 <
3908 > // Returns the smallest DeltaR between the object and any generated true particle in the event.
3909 > template <class InputObject>
3910 > double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3911 >  double genDeltaRLowest = 999.;
3912 >  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3913 >    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
3914 >    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
3915 >  }
3916 >  return genDeltaRLowest;
3917 > }
3918  
3919   double
3920   OSUAnalysis::applyFunction(string function, double value){
# Line 2489 | Line 3925 | OSUAnalysis::applyFunction(string functi
3925    else if(function == "log") value = log10(value);
3926  
3927    else if(function == "") value = value;
3928 <  else{std::cout << "WARNING: invalid function '" << function << "'\n";}
3928 >  else{cout << "WARNING: invalid function '" << function << "'\n";}
3929  
3930    return value;
3931  
# Line 2499 | Line 3935 | OSUAnalysis::applyFunction(string functi
3935   template <class InputCollection>
3936   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
3937  
3938 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
3939 +    string obj1, obj2;
3940 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
3941 +    if (inputType==obj1 ||
3942 +        inputType==obj2) {
3943 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
3944 +      // and the inputType is a member of the pair.
3945 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
3946 +      // For example, if currentCut.inputCollection==electron-muon pairs,
3947 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
3948 +      return;
3949 +    }
3950 +  }
3951  
3952    for (uint object = 0; object != inputCollection->size(); object++){
3953  
3954 <
3955 <    bool decision = true;//object passes if this cut doesn't cut on that type of object
2507 <
3954 >    bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
3955 >    bool plotDecision = true;
3956  
3957      if(currentCut.inputCollection == inputType){
3958  
3959        vector<bool> subcutDecisions;
3960        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3961 <        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
3962 <        subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3961 >        string stringValue = "";
3962 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3963 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3964 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3965 >
3966        }
3967 <      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3967 >      if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
3968        else{
3969          bool tempDecision = true;
3970          for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
# Line 2522 | Line 3973 | void OSUAnalysis::setObjectFlags(cut &cu
3973            else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
3974              tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
3975          }
3976 <        decision = tempDecision;
3976 >        cutDecision = tempDecision;
3977        }
3978 +      //invert the cut for plotting if this cut is a veto
3979 +      if(currentCut.isVeto) plotDecision = !cutDecision;
3980 +      else plotDecision = cutDecision;
3981      }
2528    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3982  
3983 +    //if(cutDecision != plotDecision && currentCut.variables.at(0) == "pt") cout << "---------------\n" << cutDecision << " " << plotDecision << endl;
3984 +    individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
3985  
3986 <    //set flags for objects that pass each cut AND all the previous cuts
3987 <    bool previousCumulativeFlag = true;
3986 >    //set flags for objects that pass this cut AND all the previous cuts
3987 >    bool previousCumulativeCutFlag = true;
3988 >    for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3989 >      if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).first) previousCumulativeCutFlag = true;
3990 >      else{ previousCumulativeCutFlag = false; break;}
3991 >    }
3992 >    previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
3993 >    bool previousCumulativePlotFlag = true;
3994      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3995 <      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
3996 <      else{ previousCumulativeFlag = false; break;}
3995 >      if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(object).second) previousCumulativePlotFlag = true;
3996 >      else{ previousCumulativePlotFlag = false; break;}
3997      }
3998 <    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3998 >    previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
3999  
4000 +    //if(inputType == "muons") cout << previousCumulativeCutFlag << " " << previousCumulativePlotFlag << " " << currentCut.variables.at(0) << "\n---------------\n\n";
4001 +    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(previousCumulativeCutFlag,previousCumulativePlotFlag));
4002  
4003    }
4004  
# Line 2544 | Line 4007 | void OSUAnalysis::setObjectFlags(cut &cu
4007  
4008   template <class InputCollection1, class InputCollection2>
4009   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
4010 <                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
4010 >                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, string inputType){
4011  
4012  
4013    bool sameObjects = false;
4014    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4015  
4016 +  // Get the strings for the two objects that make up the pair.
4017 +  string obj1Type, obj2Type;
4018 +  getTwoObjs(inputType, obj1Type, obj2Type);
4019 +  bool isTwoTypesOfObject = true;
4020 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
4021 +
4022 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
4023 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
4024 +  if (currentCut.inputCollection == inputType) {
4025 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
4026 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4027 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(make_pair(false,false));
4028 +    }
4029 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
4030 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
4031 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4032 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(make_pair(false,false));
4033 +      }
4034 +    }
4035 +  }
4036  
4037    int counter = 0;
4038 +
4039    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4040      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4041  
4042        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4043  
4044  
4045 <      bool decision = true;//object passes if this cut doesn't cut on that type of object
4045 >      bool cutDecision = true;//object passes if this cut doesn't cut on that type of object
4046 >      bool plotDecision = true;
4047  
4048        if(currentCut.inputCollection == inputType){
4049  
4050          vector<bool> subcutDecisions;
4051          for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
4052 <          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex));
4053 <          subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4052 >          string stringValue = "";
4053 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
4054 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
4055 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
4056          }
4057  
4058 <        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
4058 >        if(currentCut.numSubcuts == 1) cutDecision = subcutDecisions.at(0);
4059          else{
4060            bool tempDecision = subcutDecisions.at(0);
4061            for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
# Line 2577 | Line 4064 | void OSUAnalysis::setObjectFlags(cut &cu
4064              else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
4065                tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
4066            }
4067 <          decision = tempDecision;
4067 >          cutDecision = tempDecision;
4068          }
4069 +        //invert the cut for plotting if this cut is a veto
4070 +        if(currentCut.isVeto) plotDecision = !cutDecision;
4071 +        else plotDecision = cutDecision;
4072 +      }
4073 +      individualFlags.at(inputType).at(currentCutIndex).push_back(make_pair(cutDecision,plotDecision));
4074 +      if (cutDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4075 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true;
4076 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true;
4077 +      }
4078 +      if (plotDecision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4079 +        individualFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true;
4080 +        individualFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true;
4081        }
2583      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
4082  
4083 <      //set flags for objects that pass each cut AND all the previous cuts
4084 <      bool previousCumulativeFlag = true;
4083 >      //set flags for objects that pass this cut AND all the previous cuts
4084 >      bool previousCumulativeCutFlag = true;
4085        for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4086 <        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
4087 <        else{ previousCumulativeFlag = false; break;}
4086 >        if(previousCumulativeCutFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).first) previousCumulativeCutFlag = true;
4087 >        else{ previousCumulativeCutFlag = false; break;}
4088        }
4089 +      previousCumulativeCutFlag = previousCumulativeCutFlag && cutDecision;
4090 +
4091 +      bool previousCumulativePlotFlag = true;
4092 +      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
4093 +        if(previousCumulativePlotFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter).second) previousCumulativePlotFlag = true;
4094 +        else{ previousCumulativePlotFlag = false; break;}
4095 +      }
4096 +      previousCumulativePlotFlag = previousCumulativePlotFlag && plotDecision;
4097 +      
4098        //apply flags for the components of the composite object as well
4099 <      bool currentCumulativeFlag = true;
4100 <      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
4101 <      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
4102 <      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
4103 <      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
4104 <      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
4099 >      bool currentCumulativeCutFlag = true;
4100 >      bool currentCumulativePlotFlag = true;
4101 >
4102 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag;
4103 >      else if(flags1.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags2.at(object2).first;
4104 >      else if(flags2.size() == 0) currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first;
4105 >      else currentCumulativeCutFlag = previousCumulativeCutFlag && flags1.at(object1).first && flags2.at(object2).first;
4106 >
4107 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag;
4108 >      else if(flags1.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags2.at(object2).second;
4109 >      else if(flags2.size() == 0) currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).second;
4110 >      else currentCumulativePlotFlag = previousCumulativePlotFlag && flags1.at(object1).first && flags2.at(object2).second;
4111 >
4112 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(make_pair(currentCumulativeCutFlag,currentCumulativePlotFlag));
4113 >
4114 >      if (currentCumulativeCutFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4115 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "cut");
4116 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).first = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "cut");
4117 >      }
4118 >
4119 >      if (currentCumulativePlotFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
4120 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1, "plot");
4121 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2).second = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2, "plot");
4122 >      }
4123  
4124        counter++;
2600    }
4125  
4126 +    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
4127 +  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
4128 +
4129 + }
4130 +
4131 +
4132 + bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1, string flagType) {
4133 +  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
4134 +  // all cuts up to currentCutIndex
4135 +  bool previousCumulativeFlag = true;
4136 +  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
4137 +    bool tempFlag = false;
4138 +    if(flagType == "cut") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).first;
4139 +    else if(flagType == "plot") tempFlag = individualFlags.at(obj1Type).at(previousCutIndex).at(object1).second;
4140 +
4141 +    if (previousCumulativeFlag && tempFlag) previousCumulativeFlag = true;
4142 +    else {
4143 +      previousCumulativeFlag = false; break;
4144 +    }
4145    }
4146 +  return previousCumulativeFlag;
4147 + }
4148  
4149  
4150 +
4151 +
4152 + template <class InputCollection>
4153 + void OSUAnalysis::assignTreeBranch(BranchSpecs parameters, InputCollection inputCollection, flagPair flags){
4154 +  // This function is similar to fill1DHistogram(), but instead of filling a histogram it assigns a value to a variable for the BNTree
4155 +
4156 +  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;
4157 +  for (uint object = 0; object != inputCollection->size(); object++) {
4158 +
4159 +    if (!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4160 +
4161 +    string inputVariable = parameters.inputVariable;
4162 +    string function = "";
4163 +    string stringValue = "";
4164 +    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4165 +    BNTreeBranchVals_.at(parameters.name).push_back(value);
4166 +
4167 +  }
4168   }
4169  
4170  
4171   template <class InputCollection>
4172 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4172 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4173 >
4174  
4175    for (uint object = 0; object != inputCollection->size(); object++){
4176  
4177 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4177 >    //cout << "flags.at(object).second: " << flags.at(object).second << endl;
4178 >
4179 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4180  
4181      string currentString = parameters.inputVariables.at(0);
4182      string inputVariable = "";
4183      string function = "";
4184 <    if(currentString.find("(")==std::string::npos){
4184 >    if(currentString.find("(")==string::npos){
4185        inputVariable = currentString;// variable to cut on
4186      }
4187      else{
# Line 2624 | Line 4190 | void OSUAnalysis::fill1DHistogram(TH1* h
4190        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4191      }
4192  
4193 <    double value = valueLookup(&inputCollection->at(object), inputVariable, function);
4193 >    string stringValue = "";
4194 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4195      histo->Fill(value,scaleFactor);
4196  
4197 <  }
4197 >    if (printEventInfo_) {
4198 >      // Write information about event to screen, for testing purposes.
4199 >      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
4200 >    }
4201  
4202 +  }
4203   }
4204  
4205   template <class InputCollection1, class InputCollection2>
4206 < void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4206 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4207  
4208    bool sameObjects = false;
4209    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4210  
4211 <  int pairCounter = 0;
4211 >  int pairCounter = -1;
4212    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4213      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4214  
4215        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4216  
4217 +      pairCounter++;
4218        //only take objects which have passed all cuts and pairs which have passed all cuts
4219 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4220 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4221 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4219 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4220 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4221 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4222  
4223        string currentString = parameters.inputVariables.at(0);
4224        string inputVariable = "";
4225        string function = "";
4226 <      if(currentString.find("(")==std::string::npos){
4226 >      if(currentString.find("(")==string::npos){
4227          inputVariable = currentString;// variable to cut on
4228        }
4229        else{
# Line 2660 | Line 4232 | void OSUAnalysis::fill1DHistogram(TH1* h
4232          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4233        }
4234  
4235 <      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4235 >      string stringValue = "";
4236 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4237        histo->Fill(value,scaleFactor);
4238  
2666      pairCounter++;
4239      }
4240    }
4241  
# Line 2671 | Line 4243 | void OSUAnalysis::fill1DHistogram(TH1* h
4243  
4244  
4245   template <class InputCollection>
4246 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
4246 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection, flagPair flags, double scaleFactor){
4247  
4248    for (uint object = 0; object != inputCollection->size(); object++){
4249  
4250 <    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
4250 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object).second) continue;
4251  
4252 +    string stringValue = "";
4253      string currentString = parameters.inputVariables.at(0);
4254      string inputVariable = "";
4255      string function = "";
4256 <    if(currentString.find("(")==std::string::npos){
4256 >    if(currentString.find("(")==string::npos){
4257        inputVariable = currentString;// variable to cut on
4258      }
4259      else{
# Line 2688 | Line 4261 | void OSUAnalysis::fill2DHistogram(TH2* h
4261        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4262        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4263      }
4264 <    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function);
4264 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4265  
4266      currentString = parameters.inputVariables.at(1);
4267      inputVariable = "";
4268      function = "";
4269 <    if(currentString.find("(")==std::string::npos){
4269 >    if(currentString.find("(")==string::npos){
4270        inputVariable = currentString;// variable to cut on
4271      }
4272      else{
# Line 2702 | Line 4275 | void OSUAnalysis::fill2DHistogram(TH2* h
4275        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4276      }
4277  
4278 <    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function);
4278 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
4279  
4280      histo->Fill(valueX,valueY,scaleFactor);
4281  
# Line 2711 | Line 4284 | void OSUAnalysis::fill2DHistogram(TH2* h
4284   }
4285  
4286   template <class InputCollection1, class InputCollection2>
4287 < void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
4287 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, flagPair flags1, flagPair flags2, flagPair pairFlags, double scaleFactor){
4288  
4289    bool sameObjects = false;
4290    if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
4291  
4292 <  int pairCounter = 0;
4292 >  int pairCounter = -1;
4293    for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
4294      for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
4295  
4296        if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
4297  
4298 +      pairCounter++;
4299 +
4300        //only take objects which have passed all cuts and pairs which have passed all cuts
4301 <      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
4302 <      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
4303 <      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
4301 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1).second) continue;
4302 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2).second) continue;
4303 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter).second) continue;
4304  
4305 +      string stringValue = "";
4306        string currentString = parameters.inputVariables.at(0);
4307        string inputVariable = "";
4308        string function = "";
4309 <      if(currentString.find("(")==std::string::npos){
4309 >      if(currentString.find("(")==string::npos){
4310          inputVariable = currentString;// variable to cut on
4311        }
4312        else{
# Line 2738 | Line 4314 | void OSUAnalysis::fill2DHistogram(TH2* h
4314          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4315          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4316        }
4317 <      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4317 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4318  
4319        currentString = parameters.inputVariables.at(1);
4320        inputVariable = "";
4321        function = "";
4322 <      if(currentString.find("(")==std::string::npos){
4322 >      if(currentString.find("(")==string::npos){
4323          inputVariable = currentString;// variable to cut on
4324        }
4325        else{
# Line 2751 | Line 4327 | void OSUAnalysis::fill2DHistogram(TH2* h
4327          inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
4328          inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
4329        }
4330 <      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function);
4330 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
4331  
4332  
4333        histo->Fill(valueX,valueY,scaleFactor);
4334  
2759      pairCounter++;
2760
4335      }
4336    }
4337  
# Line 2774 | Line 4348 | int OSUAnalysis::getGenMatchedParticleIn
4348  
4349      double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
4350      if(currentDeltaR > 0.05) continue;
4351 < //     cout << std::setprecision(3) << std::setw(20)
4352 < //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4353 < //          << std::setw(20)
4354 < //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4355 < //          << std::setw(20)
4356 < //          << "\tdeltaR = " << currentDeltaR
4357 < //          << std::setprecision(1)
4358 < //          << std::setw(20)
4359 < //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4360 < //          << std::setw(20)
4361 < //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4362 < //          << std::setw(20)
4363 < //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4351 >    //     cout << setprecision(3) << setw(20)
4352 >    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
4353 >    //          << setw(20)
4354 >    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
4355 >    //          << setw(20)
4356 >    //          << "\tdeltaR = " << currentDeltaR
4357 >    //          << setprecision(1)
4358 >    //          << setw(20)
4359 >    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
4360 >    //          << setw(20)
4361 >    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
4362 >    //          << setw(20)
4363 >    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
4364      if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
4365        bestMatchIndex = mcparticle - mcparticles->begin();
4366        bestMatchDeltaR = currentDeltaR;
4367      }
4368  
4369    }
4370 < //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4371 < //   else cout << "no match found..." << endl;
4370 >  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
4371 >  //   else cout << "no match found..." << endl;
4372    return bestMatchIndex;
4373  
4374   }
# Line 2848 | Line 4422 | int OSUAnalysis::findTauMotherIndex(cons
4422   // 20        strange baryon
4423   // 21        charm baryon
4424   // 22        bottom baryon
4425 < // 23        other
4425 > // 23        QCD string
4426 > // 24        other
4427  
4428   int OSUAnalysis::getPdgIdBinValue(int pdgId){
4429  
# Line 2872 | Line 4447 | int OSUAnalysis::getPdgIdBinValue(int pd
4447    else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
4448    else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
4449    else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
4450 +  else if(absPdgId == 92  ) binValue = 23;
4451  
4452 <  else binValue = 23;
4452 >  else binValue = 24;
4453  
4454    return binValue;
4455  
# Line 2883 | Line 4459 | const BNprimaryvertex *
4459   OSUAnalysis::chosenVertex ()
4460   {
4461    const BNprimaryvertex *chosenVertex = 0;
4462 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "primaryvertexs") != objectsToCut.end()) {
4463 <    vector<bool> vertexFlags = cumulativeFlags.at("primaryvertexs").back().size() ? cumulativeFlags.at("primaryvertexs").back() :
4464 <                               cumulativeFlags.at("primaryvertexs").at(cumulativeFlags.at("primaryvertexs").size() - 2);
4462 >  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4463 >    flagPair vertexFlags;
4464 >    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4465 >      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4466 >        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4467 >        break;
4468 >      }
4469 >    }
4470      for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4471 <      if(!vertexFlags.at(vertexIndex)) continue;
4471 >      if(!vertexFlags.at(vertexIndex).first) continue;
4472        chosenVertex = & primaryvertexs->at(vertexIndex);
4473        break;
4474      }
4475    }
4476 <  else {
4477 <    chosenVertex = &primaryvertexs->at(0);
2897 <  }
4476 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4477 >    chosenVertex = & primaryvertexs->at (0);
4478  
4479    return chosenVertex;
4480   }
# Line 2903 | Line 4483 | const BNmet *
4483   OSUAnalysis::chosenMET ()
4484   {
4485    const BNmet *chosenMET = 0;
4486 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "mets") != objectsToCut.end()) {
4487 <    vector<bool> metFlags = cumulativeFlags.at("mets").back().size() ? cumulativeFlags.at("mets").back() :
4488 <                            cumulativeFlags.at("mets").at(cumulativeFlags.at("mets").size() - 2);
4486 >  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4487 >    flagPair metFlags;
4488 >    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4489 >      if (cumulativeFlags.at("mets").at(i).size()){
4490 >        metFlags = cumulativeFlags.at("mets").at(i);
4491 >        break;
4492 >      }
4493 >    }
4494      for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4495 <      if(!metFlags.at(metIndex)) continue;
4495 >      if(!metFlags.at(metIndex).first) continue;
4496        chosenMET = & mets->at(metIndex);
4497        break;
4498      }
4499    }
4500 <  else {
4501 <    chosenMET = &mets->at(0);
2917 <  }
4500 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4501 >    chosenMET = & mets->at (0);
4502  
4503    return chosenMET;
4504   }
# Line 2923 | Line 4507 | const BNelectron *
4507   OSUAnalysis::chosenElectron ()
4508   {
4509    const BNelectron *chosenElectron = 0;
4510 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "electrons") != objectsToCut.end()) {
4511 <    vector<bool> electronFlags = cumulativeFlags.at("electrons").back().size() ? cumulativeFlags.at("electrons").back() :
4512 <                                 cumulativeFlags.at("electrons").at(cumulativeFlags.at("electrons").size() - 2);
4510 >  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4511 >    flagPair electronFlags;
4512 >    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4513 >      if (cumulativeFlags.at("electrons").at(i).size()){
4514 >        electronFlags = cumulativeFlags.at("electrons").at(i);
4515 >        break;
4516 >      }
4517 >    }
4518      for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4519 <      if(!electronFlags.at(electronIndex)) continue;
4519 >      if(!electronFlags.at(electronIndex).first) continue;
4520        chosenElectron = & electrons->at(electronIndex);
4521        break;
4522      }
4523    }
4524 <  else {
4525 <    chosenElectron = &electrons->at(0);
2937 <  }
4524 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4525 >    chosenElectron = & electrons->at (0);
4526  
4527    return chosenElectron;
4528   }
4529  
4530 +
4531   const BNmuon *
4532   OSUAnalysis::chosenMuon ()
4533   {
4534    const BNmuon *chosenMuon = 0;
4535 <  if(std::find(objectsToCut.begin(), objectsToCut.end(), "muons") != objectsToCut.end()) {
4536 <    vector<bool> muonFlags = cumulativeFlags.at("muons").back().size() ? cumulativeFlags.at("muons").back() :
4537 <                             cumulativeFlags.at("muons").at(cumulativeFlags.at("muons").size() - 2);
4535 >  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4536 >    flagPair muonFlags;
4537 >    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4538 >      if (cumulativeFlags.at("muons").at(i).size()){
4539 >        muonFlags = cumulativeFlags.at("muons").at(i);
4540 >        break;
4541 >      }
4542 >    }
4543      for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4544 <      if(!muonFlags.at(muonIndex)) continue;
4544 >      if(!muonFlags.at(muonIndex).first) continue;
4545        chosenMuon = & muons->at(muonIndex);
4546        break;
4547      }
4548    }
4549 <  else {
4550 <    chosenMuon = &muons->at(0);
2957 <  }
4549 >  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4550 >    chosenMuon = & muons->at (0);
4551  
4552    return chosenMuon;
4553   }
4554  
2962
4555   DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines