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

Comparing UserCode/OSUT3Analysis/AnaTools/plugins/OSUAnalysis.cc (file contents):
Revision 1.8 by ahart, Wed Jan 30 22:29:59 2013 UTC vs.
Revision 1.69 by wulsin, Wed May 29 09:51:03 2013 UTC

# Line 11 | Line 11 | OSUAnalysis::OSUAnalysis (const edm::Par
11    tracks_ (cfg.getParameter<edm::InputTag> ("tracks")),
12    genjets_ (cfg.getParameter<edm::InputTag> ("genjets")),
13    mcparticles_ (cfg.getParameter<edm::InputTag> ("mcparticles")),
14 +  stops_ (cfg.getParameter<edm::InputTag> ("stops")),
15    primaryvertexs_ (cfg.getParameter<edm::InputTag> ("primaryvertexs")),
16    bxlumis_ (cfg.getParameter<edm::InputTag> ("bxlumis")),
17    photons_ (cfg.getParameter<edm::InputTag> ("photons")),
18    superclusters_ (cfg.getParameter<edm::InputTag> ("superclusters")),
19    triggers_ (cfg.getParameter<edm::InputTag> ("triggers")),
20 +  trigobjs_ (cfg.getParameter<edm::InputTag> ("trigobjs")),
21 +  puFile_ (cfg.getParameter<string> ("puFile")),
22 +  deadEcalFile_ (cfg.getParameter<string> ("deadEcalFile")),
23 +  muonSFFile_ (cfg.getParameter<string> ("muonSFFile")),
24 +  dataPU_ (cfg.getParameter<string> ("dataPU")),
25 +  electronSFID_ (cfg.getParameter<string> ("electronSFID")),
26 +  muonSF_ (cfg.getParameter<string> ("muonSF")),
27 +  dataset_ (cfg.getParameter<string> ("dataset")),
28 +  datasetType_ (cfg.getParameter<string> ("datasetType")),
29 +  channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels")),
30 +  histogramSets_ (cfg.getParameter<vector<edm::ParameterSet> >("histogramSets")),
31 +  plotAllObjectsInPassingEvents_ (cfg.getParameter<bool> ("plotAllObjectsInPassingEvents")),
32 +  doPileupReweighting_ (cfg.getParameter<bool> ("doPileupReweighting")),
33 +  applyLeptonSF_ (cfg.getParameter<bool> ("applyLeptonSF")),
34 +  printEventInfo_ (cfg.getParameter<bool> ("printEventInfo")),
35 +  useTrackCaloRhoCorr_ (cfg.getParameter<bool> ("useTrackCaloRhoCorr")),
36 +  stopCTau_ (cfg.getParameter<vector<double> > ("stopCTau")),
37 +  GetPlotsAfterEachCut_ (cfg.getParameter<bool> ("GetPlotsAfterEachCut"))
38 + {
39  
40 +  TH1::SetDefaultSumw2 ();
41  
42 <  channels_  (cfg.getParameter<vector<edm::ParameterSet> >("channels"))
42 >  //create pile-up reweighting object, if necessary
43 >  if(datasetType_ != "data") {
44 >    if(doPileupReweighting_) puWeight_ = new PUWeight (puFile_, dataPU_, dataset_);
45 >    if (applyLeptonSF_){
46 >      muonSFWeight_ = new MuonSFWeight (muonSFFile_, muonSF_);
47 >      electronSFWeight_ = new ElectronSFWeight ("53X", electronSFID_);
48 >    }
49 >  }
50 >  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
51 >    stopCTauWeight_ = new StopCTauWeight (stopCTau_.at (0), stopCTau_.at (1), stops_);
52  
23 {
24  TH1::SetDefaultSumw2 ();
53  
54    // Construct Cutflow Objects. These store the results of cut decisions and
55    // handle filling cut flow histograms.
56    masterCutFlow_ = new CutFlow (fs_);
57 <  std::vector<TFileDirectory> directories;
57 >
58 >  //always get vertex collection so we can assign the primary vertex in the event
59 >  objectsToGet.push_back("primaryvertexs");
60 >
61 >  //always make the plot of number of primary vertices (to check pile-up reweighting)
62 >  objectsToPlot.push_back("primaryvertexs");
63 >
64 >  //always get the MC particles to do GEN-matching
65 >  objectsToGet.push_back("mcparticles");
66 >
67 >  //always get the event collection to do pile-up reweighting
68 >  objectsToGet.push_back("events");
69 >
70 >  //parse the histogram definitions
71 >  for(uint currentHistogramSet = 0; currentHistogramSet != histogramSets_.size(); currentHistogramSet++){
72 >
73 >    string tempInputCollection = histogramSets_.at(currentHistogramSet).getParameter<string> ("inputCollection");
74 >    if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
75 >    if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
76 >    if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
77 >    if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
78 >    if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
79 >    if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
80 >    if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
81 >    if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
82 >    if(tempInputCollection.find("pairs")==string::npos){ //just a single object
83 >      if(tempInputCollection.find("secondary")!=string::npos){//secondary object
84 >        int spaceIndex = tempInputCollection.find(" ");
85 >        int secondWordLength = tempInputCollection.size() - spaceIndex;
86 >        objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
87 >      }
88 >      else{
89 >        objectsToGet.push_back(tempInputCollection);
90 >      }
91 >      objectsToPlot.push_back(tempInputCollection);
92 >      objectsToCut.push_back(tempInputCollection);
93 >    }
94 >    else{//pair of objects, need to add the pair and the individual objects to the lists of things to Get/Plot/Cut
95 >      string obj1;
96 >      string obj2;
97 >      getTwoObjs(tempInputCollection, obj1, obj2);
98 >      string obj2ToGet = getObjToGet(obj2);
99 >      objectsToCut.push_back(tempInputCollection);
100 >      objectsToCut.push_back(obj1);
101 >      objectsToCut.push_back(obj2);
102 >      objectsToPlot.push_back(tempInputCollection);
103 >      objectsToPlot.push_back(obj1);
104 >      objectsToPlot.push_back(obj2);
105 >      objectsToGet.push_back(tempInputCollection);
106 >      objectsToGet.push_back(obj1);
107 >      objectsToGet.push_back(obj2ToGet);
108 >
109 >    }
110 >
111 >    vector<edm::ParameterSet> histogramList_  (histogramSets_.at(currentHistogramSet).getParameter<vector<edm::ParameterSet> >("histograms"));
112 >
113 >    for(uint currentHistogram = 0; currentHistogram != histogramList_.size(); currentHistogram++){
114 >
115 >      vector<double> defaultValue;
116 >      defaultValue.push_back (-1.0);
117 >
118 >      histogram tempHistogram;
119 >      tempHistogram.inputCollection = tempInputCollection;
120 >      tempHistogram.name = histogramList_.at(currentHistogram).getParameter<string>("name");
121 >      tempHistogram.title = histogramList_.at(currentHistogram).getParameter<string>("title");
122 >      tempHistogram.bins = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("bins", defaultValue);
123 >      tempHistogram.variableBinsX = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsX", defaultValue);
124 >      tempHistogram.variableBinsY = histogramList_.at(currentHistogram).getUntrackedParameter<vector<double> >("variableBinsY", defaultValue);
125 >      tempHistogram.inputVariables = histogramList_.at(currentHistogram).getParameter<vector<string> >("inputVariables");
126 >
127 >      histograms.push_back(tempHistogram);
128 >
129 >    }
130 >  }
131 >  //make unique vector of objects we need to plot (so we can book a histogram with the number of each object)
132 >  sort( objectsToPlot.begin(), objectsToPlot.end() );
133 >  objectsToPlot.erase( unique( objectsToPlot.begin(), objectsToPlot.end() ), objectsToPlot.end() );
134 >
135 >
136 >
137 >  //add histograms with the gen-matched id, mother id, and grandmother id
138 >  for(uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
139 >
140 >    string currentObject = objectsToPlot.at(currentObjectIndex);
141 >    if(currentObject != "muons" && currentObject != "secondary muons" && currentObject != "secondary electrons" && currentObject != "electrons" && currentObject != "taus" && currentObject != "tracks" && currentObject != "photons" && currentObject != "superclusters") continue;
142 >
143 >    histogram tempIdHisto;
144 >    histogram tempMomIdHisto;
145 >    histogram tempGmaIdHisto;
146 >    histogram tempIdVsMomIdHisto;
147 >    histogram tempIdVsGmaIdHisto;
148 >
149 >    tempIdHisto.inputCollection = currentObject;
150 >    tempMomIdHisto.inputCollection = currentObject;
151 >    tempGmaIdHisto.inputCollection = currentObject;
152 >    tempIdVsMomIdHisto.inputCollection = currentObject;
153 >    tempIdVsGmaIdHisto.inputCollection = currentObject;
154 >
155 >    if(currentObject == "secondary muons") currentObject = "secondaryMuons";
156 >    if(currentObject == "secondary electrons") currentObject = "secondaryElectrons";
157 >
158 >    currentObject = currentObject.substr(0, currentObject.size()-1);
159 >    tempIdHisto.name = currentObject+"GenMatchId";
160 >    tempMomIdHisto.name = currentObject+"GenMatchMotherId";
161 >    tempGmaIdHisto.name = currentObject+"GenMatchGrandmotherId";
162 >    tempIdVsMomIdHisto.name = currentObject+"GenMatchIdVsMotherId";
163 >    tempIdVsGmaIdHisto.name = currentObject+"GenMatchIdVsGrandmotherId";
164 >
165 >    currentObject.at(0) = toupper(currentObject.at(0));
166 >    tempIdHisto.title = currentObject+" Gen-matched Particle";
167 >    tempMomIdHisto.title = currentObject+" Gen-matched Particle's Mother";
168 >    tempGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother";
169 >    tempIdVsMomIdHisto.title = currentObject+" Gen-matched Particle's Mother vs. Particle;Particle;Mother";
170 >    tempIdVsGmaIdHisto.title = currentObject+" Gen-matched Particle's Grandmother vs. Particle;Particle;Grandmother";
171 >
172 >
173 >    int maxNum = 25;
174 >    vector<double> binVector;
175 >    binVector.push_back(maxNum);
176 >    binVector.push_back(0);
177 >    binVector.push_back(maxNum);
178 >
179 >    tempIdHisto.bins = binVector;
180 >    tempIdHisto.inputVariables.push_back("genMatchedId");
181 >    tempMomIdHisto.bins = binVector;
182 >    tempMomIdHisto.inputVariables.push_back("genMatchedMotherId");
183 >    tempGmaIdHisto.bins = binVector;
184 >    tempGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherId");
185 >    binVector.push_back(maxNum);
186 >    binVector.push_back(0);
187 >    binVector.push_back(maxNum);
188 >    tempIdVsMomIdHisto.bins = binVector;
189 >    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedId");
190 >    tempIdVsMomIdHisto.inputVariables.push_back("genMatchedMotherIdReverse");
191 >    tempIdVsGmaIdHisto.bins = binVector;
192 >    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedId");
193 >    tempIdVsGmaIdHisto.inputVariables.push_back("genMatchedGrandmotherIdReverse");
194 >
195 >    histograms.push_back(tempIdHisto);
196 >    histograms.push_back(tempMomIdHisto);
197 >    histograms.push_back(tempGmaIdHisto);
198 >    histograms.push_back(tempIdVsMomIdHisto);
199 >    histograms.push_back(tempIdVsGmaIdHisto);
200 >  }
201  
202  
203    channel tempChannel;
# Line 46 | Line 217 | OSUAnalysis::OSUAnalysis (const edm::Par
217        triggerNames   = channels_.at(currentChannel).getParameter<vector<string> >("triggers");
218        for(uint trigger = 0; trigger!= triggerNames.size(); trigger++)
219          tempChannel.triggers.push_back(triggerNames.at(trigger));
220 <      allNecessaryObjects.push_back("triggers");
220 >      objectsToGet.push_back("triggers");
221      }
222  
223  
53    //create cutFlow for this channel
54    cutFlows_.push_back (new CutFlow (fs_, channelName));
55
56    //book a directory in the output file with the name of the channel
57    TFileDirectory subDir = fs_->mkdir( channelName );
58    directories.push_back(subDir);
59    std::map<std::string, TH1D*> histoMap;
60    oneDHists_.push_back(histoMap);
61
62    //gen histograms
63    oneDHists_.at(currentChannel)["genD0"] = directories.at(currentChannel).make<TH1D> ("genD0",channelLabel+" channel: Gen d_{0}; d_{0} [cm] ", 1000, -1, 1);
64    oneDHists_.at(currentChannel)["genAbsD0"] = directories.at(currentChannel).make<TH1D> ("genAbsD0",channelLabel+" channel: Gen d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
65    oneDHists_.at(currentChannel)["genDZ"] = directories.at(currentChannel).make<TH1D> ("genDZ",channelLabel+" channel: Gen d_{z}; d_{z} [cm] ", 1000, -10, 10);
66    oneDHists_.at(currentChannel)["genAbsDZ"] = directories.at(currentChannel).make<TH1D> ("genAbsDZ",channelLabel+" channel: Gen d_{z}; |d_{z}| [cm] ", 1000, 0, 10);
67
68    //muon histograms
69    allNecessaryObjects.push_back("muons");
70    oneDHists_.at(currentChannel)["muonPt"]  = directories.at(currentChannel).make<TH1D> ("muonPt",channelLabel+" channel: Muon Transverse Momentum; p_{T} [GeV]", 100, 0, 500);
71    oneDHists_.at(currentChannel)["muonEta"] = directories.at(currentChannel).make<TH1D> ("muonEta",channelLabel+" channel: Muon Eta; #eta", 100, -5, 5);
72    oneDHists_.at(currentChannel)["muonD0"] = directories.at(currentChannel).make<TH1D> ("muonD0",channelLabel+" channel: Muon d_{0}; d_{0} [cm] ", 1000, -1, 1);
73    oneDHists_.at(currentChannel)["muonDz"] = directories.at(currentChannel).make<TH1D> ("muonDz",channelLabel+" channel: Muon d_{z}; d_{z} [cm] ", 1000, -20, 20);
74    oneDHists_.at(currentChannel)["muonAbsD0"] = directories.at(currentChannel).make<TH1D> ("muonAbsD0",channelLabel+" channel: Muon d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
75    oneDHists_.at(currentChannel)["muonDZ"] = directories.at(currentChannel).make<TH1D> ("muonDZ",channelLabel+" channel: Muon d_{z}; d_{z} [cm] ", 1000, -10, 10);
76    oneDHists_.at(currentChannel)["muonAbsDZ"] = directories.at(currentChannel).make<TH1D> ("muonAbsDZ",channelLabel+" channel: Muon d_{z}; |d_{z}| [cm] ", 1000, 0, 10);
77    oneDHists_.at(currentChannel)["muonD0Sig"] = directories.at(currentChannel).make<TH1D> ("muonD0Sig",channelLabel+" channel: Muon d_{0} Significance; d_{0} / #sigma_{d_{0}} ", 1000, -10.0, 10.0);
78    oneDHists_.at(currentChannel)["muonAbsD0Sig"] = directories.at(currentChannel).make<TH1D> ("muonAbsD0Sig",channelLabel+" channel: Muon d_{0} Significance; |d_{0}| / #sigma_{d_{0}} ", 1000, 0, 10.0);
79    oneDHists_.at(currentChannel)["muonIso"] = directories.at(currentChannel).make<TH1D> ("muonIso",channelLabel+" channel: Muon Combined Relative Isolation; rel. iso. ", 1000, 0, 1);
80    oneDHists_.at(currentChannel)["numMuons"] = directories.at(currentChannel).make<TH1D> ("numMuons",channelLabel+" channel: Number of Selected Muons; # muons", 10, 0, 10);
81
82
83    //electron histograms
84    allNecessaryObjects.push_back("electrons");
85    oneDHists_.at(currentChannel)["electronPt"]  = directories.at(currentChannel).make<TH1D> ("electronPt",channelLabel+" channel: Electron Transverse Momentum; p_{T} [GeV]", 100, 0, 500);
86    oneDHists_.at(currentChannel)["electronEta"] = directories.at(currentChannel).make<TH1D> ("electronEta",channelLabel+" channel: Electron Eta; #eta", 50, -5, 5);
87    oneDHists_.at(currentChannel)["electronD0"] = directories.at(currentChannel).make<TH1D> ("electronD0",channelLabel+" channel: Electron d_{0}; d_{0} [cm] ", 1000, -1, 1);
88    oneDHists_.at(currentChannel)["electronDz"] = directories.at(currentChannel).make<TH1D> ("electronDz",channelLabel+" channel: Electron d_{z}; d_{z} [cm] ", 1000, -20, 20);
89    oneDHists_.at(currentChannel)["electronAbsD0"] = directories.at(currentChannel).make<TH1D> ("electronAbsD0",channelLabel+" channel: Electron d_{0}; |d_{0}| [cm] ", 1000, 0, 1);
90    oneDHists_.at(currentChannel)["electronDZ"] = directories.at(currentChannel).make<TH1D> ("electronDZ",channelLabel+" channel: Electron d_{z}; d_{z} [cm] ", 1000, -10, 10);
91    oneDHists_.at(currentChannel)["electronAbsDZ"] = directories.at(currentChannel).make<TH1D> ("electronAbsDZ",channelLabel+" channel: Electron d_{z}; |d_{z}| [cm] ", 1000, 0, 10);
92    oneDHists_.at(currentChannel)["electronD0Sig"] = directories.at(currentChannel).make<TH1D> ("electronD0Sig",channelLabel+" channel: Electron d_{0} Significance; d_{0} / #sigma_{d_{0}} ", 1000, -10.0, 10.0);
93    oneDHists_.at(currentChannel)["electronAbsD0Sig"] = directories.at(currentChannel).make<TH1D> ("electronAbsD0Sig",channelLabel+" channel: Electron d_{0} Significance; |d_{0}| / #sigma_{d_{0}} ", 1000, 0, 10.0);
94    oneDHists_.at(currentChannel)["electronIso"] = directories.at(currentChannel).make<TH1D> ("electronIso",channelLabel+" channel: Electron Combined Relative Isolation; rel. iso. ", 1000, 0, 1);
95    oneDHists_.at(currentChannel)["electronFbrem"] = directories.at(currentChannel).make<TH1D> ("electronFbrem",channelLabel+" channel: Electron Brem. Energy Fraction; fbrem", 1000, 0, 2);
96    oneDHists_.at(currentChannel)["electronMVATrig"] = directories.at(currentChannel).make<TH1D> ("electronMVATrig",channelLabel+" channel: Electron ID MVA Output", 100, -1, 1);
97    oneDHists_.at(currentChannel)["electronMVANonTrig"] = directories.at(currentChannel).make<TH1D> ("electronMVANonTrig",channelLabel+" channel: Electron ID MVA Output", 100, -1, 1);
98    oneDHists_.at(currentChannel)["numElectrons"] = directories.at(currentChannel).make<TH1D> ("numElectrons",channelLabel+" channel: Number of Selected Electrons; # electrons", 10, 0, 10);
99
224  
225  
226 +    //create cutFlow for this channel
227 +    cutFlows_.push_back (new CutFlow (fs_, channelName));
228 +    vector<TFileDirectory> directories; //vector of directories in the output file.
229 +    vector<string> subSubDirNames;//subdirectories in each channel.
230      //get list of cuts for this channel
231      vector<edm::ParameterSet> cuts_  (channels_.at(currentChannel).getParameter<vector<edm::ParameterSet> >("cuts"));
232  
105    vector<string> tempInputCollections;
106
233  
234      //loop over and parse all cuts
235      for(uint currentCut = 0; currentCut != cuts_.size(); currentCut++){
110
236        cut tempCut;
237 <     //store input collection for cut
238 <      string inputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
239 <      tempCut.inputCollection = inputCollection;
237 >      //store input collection for cut
238 >      string tempInputCollection = cuts_.at(currentCut).getParameter<string> ("inputCollection");
239 >      if(tempInputCollection == "muon-electron pairs") tempInputCollection = "electron-muon pairs";
240 >      if(tempInputCollection == "jet-electron pairs") tempInputCollection = "electron-jet pairs";
241 >      if(tempInputCollection == "jet-muon pairs") tempInputCollection = "muon-jet pairs";
242 >      if(tempInputCollection == "event-track pairs")   tempInputCollection = "track-event pairs";
243 >      if(tempInputCollection == "secondary muon-muon pairs")   tempInputCollection = "muon-secondary muon pairs";
244 >      if(tempInputCollection == "secondary electron-electron pairs")   tempInputCollection = "electron-secondary electron pairs";
245 >      if(tempInputCollection == "trigobj-electron pairs")   tempInputCollection = "electron-trigobj pairs";
246 >      if(tempInputCollection == "trigobj-muon pairs")   tempInputCollection = "muon-trigobj pairs";
247 >      tempCut.inputCollection = tempInputCollection;
248 >      if(tempInputCollection.find("pairs")==string::npos){ //just a single object
249 >        if(tempInputCollection.find("secondary")!=string::npos){//secondary object
250 >          int spaceIndex = tempInputCollection.find(" ");
251 >          int secondWordLength = tempInputCollection.size() - spaceIndex;
252 >          objectsToGet.push_back(tempInputCollection.substr(spaceIndex+1,secondWordLength));
253 >        }
254 >        else{
255 >          objectsToGet.push_back(tempInputCollection);
256 >        }
257 >        objectsToCut.push_back(tempInputCollection);
258 >      }
259 >      else{//pair of objects, need to add them both to objectsToGet
260 >        string obj1;
261 >        string obj2;
262 >        getTwoObjs(tempInputCollection, obj1, obj2);
263 >        string obj2ToGet = getObjToGet(obj2);
264 >        objectsToCut.push_back(tempInputCollection);
265 >        objectsToCut.push_back(obj1);
266 >        objectsToCut.push_back(obj2);
267 >        objectsToGet.push_back(tempInputCollection);
268 >        objectsToGet.push_back(obj1);
269 >        objectsToGet.push_back(obj2ToGet);
270 >
271 >      }
272 >
273  
116      tempInputCollections.push_back(inputCollection);
117      allNecessaryObjects.push_back(inputCollection);
274  
275        //split cut string into parts and store them
276        string cutString = cuts_.at(currentCut).getParameter<string> ("cutString");
277 <      std::vector<string> cutStringVector = splitString(cutString);
278 <      tempCut.variable = cutStringVector.at(0);// variable to cut on
279 <      tempCut.comparativeOperator = cutStringVector.at(1);// comparison to make
280 <      tempCut.cutValue = atof(cutStringVector.at(2).c_str());// threshold value to pass cut
277 >      vector<string> cutStringVector = splitString(cutString);
278 >      if(cutStringVector.size()!=3 && cutStringVector.size() % 4 !=3){
279 >        cout << "Error: Didn't find the expected number elements in the following cut string: '" << cutString << "'\n";
280 >        exit(0);
281 >      }
282 >      tempCut.numSubcuts = (cutStringVector.size()+1)/4;
283 >      for(int subcutIndex = 0; subcutIndex != tempCut.numSubcuts; subcutIndex++){//loop over all the pieces of the cut combined using &,|
284 >        int indexOffset = 4 * subcutIndex;
285 >        string currentVariableString = cutStringVector.at(indexOffset);
286 >        if(currentVariableString.find("(")==string::npos){
287 >          tempCut.functions.push_back("");//no function was specified
288 >          tempCut.variables.push_back(currentVariableString);// variable to cut on
289 >        }
290 >        else{
291 >          tempCut.functions.push_back(currentVariableString.substr(0,currentVariableString.find("(")));//function comes before the "("
292 >          string tempVariable = currentVariableString.substr(currentVariableString.find("(")+1);//get rest of string
293 >          tempCut.variables.push_back(tempVariable.substr(0,tempVariable.size()-1));//remove trailing ")"
294 >        }
295 >        tempCut.comparativeOperators.push_back(cutStringVector.at(indexOffset+1));// comparison to make
296 >        tempCut.cutValues.push_back(atof(cutStringVector.at(indexOffset+2).c_str()));// threshold value to pass cut
297 >        tempCut.cutStringValues.push_back(cutStringVector.at(indexOffset+2));// string value to pass cut
298 >        if(subcutIndex != 0) tempCut.logicalOperators.push_back(cutStringVector.at(indexOffset-1)); // logical comparison (and, or)
299 >      }
300  
301        //get number of objects required to pass cut for event to pass
302        string numberRequiredString = cuts_.at(currentCut).getParameter<string> ("numberRequired");
303 <      std::vector<string> numberRequiredVector = splitString(numberRequiredString);
303 >      vector<string> numberRequiredVector = splitString(numberRequiredString);
304 >      if(numberRequiredVector.size()!=2){
305 >        cout << "Error: Didn't find two elements in the following number requirement string: '" << numberRequiredString << "'\n";
306 >        exit(0);
307 >      }
308  
130      // determine number required if comparison contains "="
309        int numberRequiredInt = atoi(numberRequiredVector.at(1).c_str());
132      if(numberRequiredVector.at(0) == ">") numberRequiredInt++;
133      else if(numberRequiredVector.at(0) == "<") numberRequiredInt--;
134
310        tempCut.numberRequired = numberRequiredInt;// number of objects required to pass the cut
311        tempCut.eventComparativeOperator = numberRequiredVector.at(0);// comparison to make
312  
313 <      if(cuts_.at(currentCut).exists("function")){
314 <        tempCut.function = cuts_.at(currentCut).getParameter<string> ("function");
140 <      }
141 <      else tempCut.function = "";
313 >      //Set up vectors to store the directories and subDIrectories for each channel.
314 >      string subSubDirName;
315        string tempCutName;
316        if(cuts_.at(currentCut).exists("alias")){
317          tempCutName = cuts_.at(currentCut).getParameter<string> ("alias");
318 +        subSubDirName = "After " + cuts_.at(currentCut).getParameter<string> ("alias") + " Cut Applied";
319        }
320        else{
321          //construct string for cutflow table
322          bool plural = numberRequiredInt != 1;
323 <        string collectionString = plural ? inputCollection : inputCollection.substr(0, inputCollection.size()-1);
323 >        string collectionString = plural ? tempInputCollection : tempInputCollection.substr(0, tempInputCollection.size()-1);
324          string cutName =  numberRequiredString + " " + collectionString + " with " + cutString;
325          tempCutName = cutName;
326 +        subSubDirName = "After " + numberRequiredString + " " + collectionString + " with " + cutString + " Cut Applied";
327        }
153      tempCut.name = tempCutName;
328  
329 +      subSubDirNames.push_back(subSubDirName);
330 +      tempCut.name = tempCutName;
331  
332        tempChannel.cuts.push_back(tempCut);
333  
334  
335      }//end loop over cuts
336  
337 <    //make unique vector of all objects that this channel cuts on (so we know to set flags for those)
338 <    sort( tempInputCollections.begin(), tempInputCollections.end() );
339 <    tempInputCollections.erase( unique( tempInputCollections.begin(), tempInputCollections.end() ), tempInputCollections.end() );
340 <    tempChannel.inputCollections = tempInputCollections;
337 >    vector<map<string, TH1D*>> oneDHistsTmp;
338 >    vector<map<string, TH2D*>> twoDHistsTmp;
339 >    //book a directory in the output file with the name of the channel
340 >    TFileDirectory subDir = fs_->mkdir( channelName );
341 >    //loop over the cuts to set up subdirectory for each cut if GetPlotsAfterEachCut_ is true.
342 >    if(GetPlotsAfterEachCut_){
343 >       for( uint currentDir=0; currentDir != subSubDirNames.size(); currentDir++){
344 >            TFileDirectory subSubDir = subDir.mkdir( subSubDirNames[currentDir] );
345 >            directories.push_back(subSubDir);
346 >            map<string, TH1D*> oneDhistoMap;
347 >            oneDHistsTmp.push_back(oneDhistoMap);
348 >            map<string, TH2D*> twoDhistoMap;
349 >            twoDHistsTmp.push_back(twoDhistoMap);
350 >      }
351 >      oneDHists_.push_back(oneDHistsTmp);
352 >      twoDHists_.push_back(twoDHistsTmp);
353 >    }
354 >   //only set up directories with names of the channels if GetPlotsAfterEachCut_ is false.
355 >   else{
356 >      map<string, TH1D*> oneDhistoMap;
357 >      oneDHistsTmp.push_back(oneDhistoMap);
358 >      map<string, TH2D*> twoDhistoMap;
359 >      twoDHistsTmp.push_back(twoDhistoMap);
360 >      oneDHists_.push_back(oneDHistsTmp);
361 >      twoDHists_.push_back(twoDHistsTmp);
362 >      directories.push_back(subDir);
363 >   }
364 >    //book all histograms included in the configuration
365 >    for(uint currentDir = 0; currentDir != directories.size(); currentDir++){//loop over all the directories.
366 >    for(uint currentHistogramIndex = 0; currentHistogramIndex != histograms.size(); currentHistogramIndex++){
367 >      histogram currentHistogram = histograms.at(currentHistogramIndex);
368 >      int numBinsElements = currentHistogram.bins.size();
369 >      int numInputVariables = currentHistogram.inputVariables.size();
370 >      int numBinEdgesX = currentHistogram.variableBinsX.size();
371 >      int numBinEdgesY = currentHistogram.variableBinsY.size();
372 >
373 >      if(numBinsElements == 1){
374 >        if(numBinEdgesX > 1){
375 >          if(numBinEdgesY > 1)
376 >            numBinsElements = 6;
377 >          else
378 >            numBinsElements = 3;
379 >        }
380 >      }
381 >      if(numBinsElements != 3 && numBinsElements !=6){
382 >        cout << "Error: Didn't find correct number of bin specifications for histogram named '" << currentHistogram.name << "'\n";
383 >        exit(0);
384 >      }
385 >      else if((numBinsElements == 3 && numInputVariables !=1) || (numBinsElements == 6 && numInputVariables!=2)){
386 >        cout << "Error: Didn't find correct number of input variables for histogram named '" << currentHistogram.name << "'\n";
387 >        exit(0);
388 >      }
389 >      else if(numBinsElements == 3){
390 >        if (currentHistogram.bins.size () == 3)
391 >          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));
392 >        else
393 >          {
394 >            oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name] = directories.at(currentDir).make<TH1D> (TString(currentHistogram.name),channelLabel+" channel: "+currentHistogram.title, numBinEdgesX - 1, currentHistogram.variableBinsX.data ());
395 >          }
396 >      }
397 >      else if(numBinsElements == 6){
398 >        if (currentHistogram.bins.size () == 6)
399 >          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));
400 >        else
401 >          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 ());
402 >      }
403 >
404 >
405 >      if(currentHistogram.name.find("GenMatch")==string::npos) continue;
406 >
407 >      // bin      particle type
408 >      // ---      -------------
409 >      //  0        unmatched
410 >      //  1        u
411 >      //  2        d
412 >      //  3        s
413 >      //  4        c
414 >      //  5        b
415 >      //  6        t
416 >      //  7        e
417 >      //  8        mu
418 >      //  9        tau
419 >      // 10        nu
420 >      // 11        g
421 >      // 12        gamma
422 >      // 13        Z
423 >      // 14        W
424 >      // 15        light meson
425 >      // 16        K meson
426 >      // 17        D meson
427 >      // 18        B meson
428 >      // 19        light baryon
429 >      // 20        strange baryon
430 >      // 21        charm baryon
431 >      // 22        bottom baryon
432 >      // 23        QCD string
433 >      // 24        other
434 >
435 >      vector<TString> labelArray;
436 >      labelArray.push_back("unmatched");
437 >      labelArray.push_back("u");
438 >      labelArray.push_back("d");
439 >      labelArray.push_back("s");
440 >      labelArray.push_back("c");
441 >      labelArray.push_back("b");
442 >      labelArray.push_back("t");
443 >      labelArray.push_back("e");
444 >      labelArray.push_back("#mu");
445 >      labelArray.push_back("#tau");
446 >      labelArray.push_back("#nu");
447 >      labelArray.push_back("g");
448 >      labelArray.push_back("#gamma");
449 >      labelArray.push_back("Z");
450 >      labelArray.push_back("W");
451 >      labelArray.push_back("light meson");
452 >      labelArray.push_back("K meson");
453 >      labelArray.push_back("D meson");
454 >      labelArray.push_back("B meson");
455 >      labelArray.push_back("light baryon");
456 >      labelArray.push_back("strange baryon");
457 >      labelArray.push_back("charm baryon");
458 >      labelArray.push_back("bottom baryon");
459 >      labelArray.push_back("QCD string");
460 >      labelArray.push_back("other");
461 >
462 >      for(int bin = 0; bin !=currentHistogram.bins.at(0); bin++){
463 >        if(currentHistogram.name.find("GenMatchIdVsMotherId")==string::npos && currentHistogram.name.find("GenMatchIdVsGrandmotherId")==string::npos) {
464 >          oneDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
465 >        }
466 >        else {
467 >          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->SetBinLabel(bin+1,labelArray.at(currentHistogram.bins.at(0)-bin-1));
468 >          twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->SetBinLabel(bin+1,labelArray.at(bin));
469 >        }
470 >      }
471 >      if(currentHistogram.name.find("GenMatchIdVsMotherId")!=string::npos || currentHistogram.name.find("GenMatchIdVsGrandmotherId")!=string::npos) {
472 >        twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetXaxis()->CenterTitle();
473 >        twoDHists_.at(currentChannel).at(currentDir)[currentHistogram.name]->GetYaxis()->CenterTitle();
474 >      }
475  
476 +    }
477 +
478 +    // Book a histogram for the number of each object type to be plotted.
479 +    // Name of objectToPlot here must match the name specified in OSUAnalysis::analyze().
480 +    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
481 +      string currentObject = objectsToPlot.at(currentObjectIndex);
482 +      int maxNum = 10;
483 +      if(currentObject == "mcparticles") maxNum = 50;
484 +      else if(currentObject == "primaryvertexs") maxNum = 50;
485 +
486 +      if(currentObject == "muon-muon pairs")                currentObject = "dimuonPairs";
487 +      else if(currentObject == "electron-electron pairs")   currentObject = "dielectronPairs";
488 +      else if(currentObject == "electron-muon pairs")       currentObject = "electronMuonPairs";
489 +      else if(currentObject == "secondary jets")            currentObject = "secondaryJets";
490 +      else if(currentObject == "jet-jet pairs")             currentObject = "dijetPairs";
491 +      else if(currentObject == "electron-jet pairs")        currentObject = "electronJetPairs";
492 +      else if(currentObject == "muon-jet pairs")            currentObject = "muonJetPairs";
493 +      else if(currentObject == "track-event pairs")         currentObject = "trackEventPairs";
494 +      else if(currentObject == "electron-track pairs")      currentObject = "electronTrackPairs";
495 +      else if(currentObject == "muon-track pairs")          currentObject = "muonTrackPairs";
496 +      else if(currentObject == "muon-tau pairs")            currentObject = "muonTauPairs";
497 +      else if(currentObject == "tau-tau pairs")             currentObject = "ditauPairs";
498 +      else if(currentObject == "tau-track pairs")           currentObject = "tauTrackPairs";
499 +      else if(currentObject == "muon-secondary muon pairs") currentObject = "muonSecondaryMuonPairs";
500 +      else if(currentObject == "secondary muons")           currentObject = "secondaryMuons";
501 +      else if(currentObject == "electron-secondary electron pairs") currentObject = "electronSecondaryElectronPairs";
502 +      else if(currentObject == "secondary electrons")       currentObject = "secondaryElectrons";
503 +      else if(currentObject == "electron-trigobj pairs")    currentObject = "electronTrigobjPairs";
504 +      else if(currentObject == "muon-trigobj pairs")        currentObject = "muonTrigobjPairs";
505 +
506 +      currentObject.at(0) = toupper(currentObject.at(0));
507 +      string histoName = "num" + currentObject;
508 +
509 +      if(histoName == "numPrimaryvertexs"){
510 +        string newHistoName = histoName + "BeforePileupCorrection";
511 +        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);
512 +        newHistoName = histoName + "AfterPileupCorrection";
513 +        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);
514 +      }
515 +      else
516 +        oneDHists_.at(currentChannel).at(currentDir)[histoName] = directories.at(currentDir).make<TH1D> (TString(histoName),channelLabel+" channel: Number of Selected "+currentObject+"; # "+currentObject, maxNum, 0, maxNum);
517 +    }
518 +   }//end of loop over directories
519      channels.push_back(tempChannel);
520      tempChannel.cuts.clear();
168
521    }//end loop over channels
522  
523 <  //make unique vector of objects we need to cut on (so we make sure to get them from the event)
524 <  sort( allNecessaryObjects.begin(), allNecessaryObjects.end() );
525 <  allNecessaryObjects.erase( unique( allNecessaryObjects.begin(), allNecessaryObjects.end() ), allNecessaryObjects.end() );
523 >
524 >  //make unique vector of objects we need to get from the event
525 >  sort( objectsToGet.begin(), objectsToGet.end() );
526 >  objectsToGet.erase( unique( objectsToGet.begin(), objectsToGet.end() ), objectsToGet.end() );
527 >  //make unique vector of objects we need to cut on
528 >  sort( objectsToCut.begin(), objectsToCut.end() );
529 >  objectsToCut.erase( unique( objectsToCut.begin(), objectsToCut.end() ), objectsToCut.end() );
530  
531  
532   }
# Line 188 | Line 544 | void
544   OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
545   {
546  
191
547    // Retrieve necessary collections from the event.
548 <  edm::Handle<BNtriggerCollection> triggers;
549 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "triggers") != allNecessaryObjects.end())
548 >
549 >  if (find(objectsToGet.begin(), objectsToGet.end(), "triggers") != objectsToGet.end())
550      event.getByLabel (triggers_, triggers);
551  
552 <  edm::Handle<BNjetCollection> jets;
553 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "jets") != allNecessaryObjects.end())
552 >  if (find(objectsToGet.begin(), objectsToGet.end(), "trigobjs") != objectsToGet.end())
553 >    event.getByLabel (trigobjs_, trigobjs);
554 >
555 >  if (find(objectsToGet.begin(), objectsToGet.end(), "jets") != objectsToGet.end())
556      event.getByLabel (jets_, jets);
557  
558 <  edm::Handle<BNmuonCollection> muons;
202 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "muons") != allNecessaryObjects.end())
558 >  if (find(objectsToGet.begin(), objectsToGet.end(), "muons") != objectsToGet.end())
559      event.getByLabel (muons_, muons);
560  
561 <  edm::Handle<BNelectronCollection> electrons;
206 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "electrons") != allNecessaryObjects.end())
561 >  if (find(objectsToGet.begin(), objectsToGet.end(), "electrons") != objectsToGet.end())
562      event.getByLabel (electrons_, electrons);
563  
564 <  edm::Handle<BNeventCollection> events;
210 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "events") != allNecessaryObjects.end())
564 >  if (find(objectsToGet.begin(), objectsToGet.end(), "events") != objectsToGet.end())
565      event.getByLabel (events_, events);
566  
567 <  edm::Handle<BNtauCollection> taus;
214 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "taus") != allNecessaryObjects.end())
567 >  if (find(objectsToGet.begin(), objectsToGet.end(), "taus") != objectsToGet.end())
568      event.getByLabel (taus_, taus);
569  
570 <  edm::Handle<BNmetCollection> mets;
218 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mets") != allNecessaryObjects.end())
570 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mets") != objectsToGet.end())
571      event.getByLabel (mets_, mets);
572  
573 <  edm::Handle<BNtrackCollection> tracks;
222 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "tracks") != allNecessaryObjects.end())
573 >  if (find(objectsToGet.begin(), objectsToGet.end(), "tracks") != objectsToGet.end())
574      event.getByLabel (tracks_, tracks);
575  
576 <  edm::Handle<BNgenjetCollection> genjets;
226 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "genjets") != allNecessaryObjects.end())
576 >  if (find(objectsToGet.begin(), objectsToGet.end(), "genjets") != objectsToGet.end())
577      event.getByLabel (genjets_, genjets);
578  
579 <  edm::Handle<BNmcparticleCollection> mcparticles;
230 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "mcparticles") != allNecessaryObjects.end())
579 >  if (find(objectsToGet.begin(), objectsToGet.end(), "mcparticles") != objectsToGet.end())
580      event.getByLabel (mcparticles_, mcparticles);
581  
582 <  edm::Handle<BNprimaryvertexCollection> primaryvertexs;
234 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "primaryvertexs") != allNecessaryObjects.end())
582 >  if (find(objectsToGet.begin(), objectsToGet.end(), "primaryvertexs") != objectsToGet.end())
583      event.getByLabel (primaryvertexs_, primaryvertexs);
584  
585 <  edm::Handle<BNbxlumiCollection> bxlumis;
238 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "bxlumis") != allNecessaryObjects.end())
585 >  if (find(objectsToGet.begin(), objectsToGet.end(), "bxlumis") != objectsToGet.end())
586      event.getByLabel (bxlumis_, bxlumis);
587  
588 <  edm::Handle<BNphotonCollection> photons;
242 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "photons") != allNecessaryObjects.end())
588 >  if (find(objectsToGet.begin(), objectsToGet.end(), "photons") != objectsToGet.end())
589      event.getByLabel (photons_, photons);
590  
591 <  edm::Handle<BNsuperclusterCollection> superclusters;
246 <  if (std::find(allNecessaryObjects.begin(), allNecessaryObjects.end(), "superclusters") != allNecessaryObjects.end())
591 >  if (find(objectsToGet.begin(), objectsToGet.end(), "superclusters") != objectsToGet.end())
592      event.getByLabel (superclusters_, superclusters);
593  
594 +  if (datasetType_ == "signalMC"){
595 +    if (find(objectsToGet.begin(), objectsToGet.end(), "stops") != objectsToGet.end())
596 +      event.getByLabel (stops_, stops);
597 +  }
598 +
599 +  if (useTrackCaloRhoCorr_) {
600 +    // Used only for pile-up correction of by-hand calculation of isolation energy.
601 +    // This rho collection is not available in all BEANs.
602 +    // For description of rho values for different jet reconstruction algorithms, see
603 +    // https://twiki.cern.ch/twiki/bin/view/CMS/JetAlgorithms#Algorithms
604 +    event.getByLabel ("kt6CaloJets","rho", rhokt6CaloJetsHandle_);
605 +  }
606 +
607 +  double masterScaleFactor = 1.0;
608 +
609 +  //get pile-up event weight
610 +  if (doPileupReweighting_ && datasetType_ != "data") {
611 +    if (events->at(0).numTruePV < 0) cout << "WARNING[OSUAnalysis::analyze]: Event has numTruePV<0.  This will give an incorrect pile-up weight." << endl;  
612 +    masterScaleFactor *= puWeight_->at (events->at (0).numTruePV);  
613 +  }
614 +
615 +  stopCTauScaleFactor_ = 1.0;
616 +  if (datasetType_ == "signalMC" && regex_match (dataset_, regex ("stop.*to.*_.*mm.*")))
617 +    stopCTauScaleFactor_ = stopCTauWeight_->at (event);
618 +  masterScaleFactor *= stopCTauScaleFactor_;
619  
620    //loop over all channels
621  
# Line 253 | Line 623 | OSUAnalysis::analyze (const edm::Event &
623      channel currentChannel = channels.at(currentChannelIndex);
624  
625      flagMap individualFlags;
256    flagMap cumulativeFlags;
626      counterMap passingCounter;
627 +    cumulativeFlags.clear ();
628  
629      bool triggerDecision = true;
630      if(currentChannel.triggers.size() != 0){  //triggers specified
# Line 265 | Line 635 | OSUAnalysis::analyze (const edm::Event &
635      //loop over all cuts
636      for(uint currentCutIndex = 0; currentCutIndex != currentChannel.cuts.size(); currentCutIndex++){
637        cut currentCut = currentChannel.cuts.at(currentCutIndex);
638 +      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
639 +        string currentObject = objectsToCut.at(currentObjectIndex);
640  
641 <      for(uint currentObjectIndex = 0; currentObjectIndex != allNecessaryObjects.size(); currentObjectIndex++){
270 <
271 <        string currentObject = allNecessaryObjects.at(currentObjectIndex);
641 >        //initialize maps to get ready to set cuts
642          individualFlags[currentObject].push_back (vector<bool> ());
643          cumulativeFlags[currentObject].push_back (vector<bool> ());
644  
645 <        if(currentObject == "jets") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
646 <        else if(currentObject == "muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
645 >      }
646 >      for(uint currentObjectIndex = 0; currentObjectIndex != objectsToCut.size(); currentObjectIndex++){
647 >        string currentObject = objectsToCut.at(currentObjectIndex);
648 >
649 >        int flagsForPairCutsIndex = max(int(currentCutIndex-1),0);
650 >
651 >
652 >        if     (currentObject == "jets")            setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"jets");
653 >        else if(currentObject == "secondary jets")  setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),"secondary jets");
654 >        else if(currentObject == "muons")           setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"muons");
655 >        else if(currentObject == "secondary muons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),"secondary muons");
656 >        else if(currentObject == "secondary electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"secondary electrons");
657          else if(currentObject == "electrons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),"electrons");
658          else if(currentObject == "events") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,events.product(),"events");
659          else if(currentObject == "taus") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),"taus");
# Line 285 | Line 665 | OSUAnalysis::analyze (const edm::Event &
665          else if(currentObject == "bxlumis") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,bxlumis.product(),"bxlumis");
666          else if(currentObject == "photons") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,photons.product(),"photons");
667          else if(currentObject == "superclusters") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,superclusters.product(),"superclusters");
668 +        else if(currentObject == "trigobjs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,trigobjs.product(),"trigobjs");
669  
670  
290      }
291
671  
672 +        else if(currentObject == "muon-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
673 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
674 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
675 +                                                                   "muon-muon pairs");
676 +
677 +        else if(currentObject == "muon-secondary muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),muons.product(), \
678 +                                                                   cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
679 +                                                                   cumulativeFlags.at("secondary muons").at(flagsForPairCutsIndex), \
680 +                                                                   "muon-secondary muon pairs");
681 +
682 +        else if(currentObject == "electron-secondary electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
683 +                                                                   cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
684 +                                                                   cumulativeFlags.at("secondary electrons").at(flagsForPairCutsIndex), \
685 +                                                                   "electron-secondary electron pairs");
686 +
687 +        else if(currentObject == "electron-electron pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),electrons.product(), \
688 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
689 +                                                                           cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
690 +                                                                           "electron-electron pairs");
691 +        else if(currentObject == "electron-muon pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),muons.product(), \
692 +                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
693 +                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
694 +                                                                       "electron-muon pairs");
695 +        else if(currentObject == "jet-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,jets.product(),jets.product(), \
696 +                                                                           cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
697 +                                                                           cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
698 +                                                                           "jet-jet pairs");
699 +        else if(currentObject == "electron-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),jets.product(), \
700 +                                                                       cumulativeFlags.at("electrons").at(flagsForPairCutsIndex), \
701 +                                                                       cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
702 +                                                                       "electron-jet pairs");
703 +        else if(currentObject == "muon-jet pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),jets.product(), \
704 +                                                                       cumulativeFlags.at("muons").at(flagsForPairCutsIndex), \
705 +                                                                       cumulativeFlags.at("jets").at(flagsForPairCutsIndex), \
706 +                                                                       "muon-jet pairs");
707 +        else if(currentObject == "track-event pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,tracks.product(),events.product(),
708 +                                                                     cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
709 +                                                                     cumulativeFlags.at("events").at(flagsForPairCutsIndex),
710 +                                                                     "track-event pairs");
711 +        else if(currentObject == "electron-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),tracks.product(),
712 +                                                                        cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
713 +                                                                        cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
714 +                                                                        "electron-track pairs");
715 +        else if(currentObject == "muon-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),tracks.product(),
716 +                                                                    cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
717 +                                                                    cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
718 +                                                                    "muon-track pairs");
719 +        else if(currentObject == "muon-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),taus.product(),
720 +                                                                  cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
721 +                                                                  cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
722 +                                                                  "muon-tau pairs");
723 +        else if(currentObject == "tau-tau pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus.product(),taus.product(),
724 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
725 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
726 +                                                                 "tau-tau pairs");
727 +        else if(currentObject == "tau-track pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,taus .product(),tracks.product(),
728 +                                                                 cumulativeFlags.at("taus").at(flagsForPairCutsIndex),
729 +                                                                 cumulativeFlags.at("tracks").at(flagsForPairCutsIndex),
730 +                                                                 "tau-track pairs");
731 +        else if(currentObject == "electron-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,electrons.product(),trigobjs.product(),
732 +                                                                          cumulativeFlags.at("electrons").at(flagsForPairCutsIndex),
733 +                                                                          cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
734 +                                                                          "electron-trigobj pairs");
735 +        else if(currentObject == "muon-trigobj pairs") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,muons.product(),trigobjs.product(),
736 +                                                                      cumulativeFlags.at("muons").at(flagsForPairCutsIndex),
737 +                                                                      cumulativeFlags.at("trigobjs").at(flagsForPairCutsIndex),
738 +                                                                      "muon-trigobj pairs");
739  
740 <    }//end loop over all cuts
741 <
740 >        if(currentObject == "stops" && datasetType_ == "signalMC") setObjectFlags(currentCut,currentCutIndex,individualFlags,cumulativeFlags,stops.product(),"stops");
741 >      }
742  
743  
744  
745 +    }//end loop over all cuts
746      //use cumulative flags to apply cuts at event level
747  
748      bool eventPassedAllCuts = true;
749 <
749 >    //a vector to store cumulative cut descisions after each cut.
750 >    vector<bool> eventPassedPreviousCuts;
751      //apply trigger (true if none were specified)
752      eventPassedAllCuts = eventPassedAllCuts && triggerDecision;
753  
# Line 310 | Line 758 | OSUAnalysis::analyze (const edm::Event &
758        cut currentCut = currentChannel.cuts.at(currentCutIndex);
759        int numberPassing = 0;
760  
761 <      for (uint object = 0; object != cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).size() ; object++)
762 <          if(cumulativeFlags[currentCut.inputCollection].at(currentCutIndex).at(object)) numberPassing++;
763 <
316 <
761 >      for (uint object = 0; object != cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).size() ; object++){
762 >        if(cumulativeFlags.at(currentCut.inputCollection).at(currentCutIndex).at(object)) numberPassing++;
763 >      }
764        bool cutDecision = evaluateComparison(numberPassing,currentCut.eventComparativeOperator,currentCut.numberRequired);
765        cutFlows_.at(currentChannelIndex)->at (currentCut.name) = cutDecision;
319
766        eventPassedAllCuts = eventPassedAllCuts && cutDecision;
767 <
767 >      eventPassedPreviousCuts.push_back(eventPassedAllCuts);
768      }
769 +    double scaleFactor = masterScaleFactor;
770  
771 <    cutFlows_.at(currentChannelIndex)->fillCutFlow();
772 <
773 <
774 <
775 <    if(!eventPassedAllCuts)continue;
776 <
777 <
778 <    TVector3 vertexPosition;
779 <    vector<bool> vertexFlags = cumulativeFlags["primaryvertexs"].back();
780 <
781 <    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
782 <      if(!vertexFlags.at(vertexIndex)) continue;
783 <
784 <      vertexPosition.SetXYZ (primaryvertexs->at(vertexIndex).x,primaryvertexs->at(vertexIndex).y,primaryvertexs->at(vertexIndex).z);
785 <      break;
771 >    muonScaleFactor_ = electronScaleFactor_ = 1.0;
772 >    if(applyLeptonSF_ && datasetType_ != "data"){
773 >      if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
774 >        vector<bool> muonFlags;
775 >        for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
776 >          if (cumulativeFlags.at("muons").at(i).size()){
777 >            muonFlags = cumulativeFlags.at("muons").at(i);
778 >            break;
779 >          }
780 >        }
781 >        for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
782 >          if(!muonFlags.at(muonIndex)) continue;
783 >          muonScaleFactor_ *= muonSFWeight_->at (muons->at(muonIndex).eta);
784 >        }
785 >      }
786 >      if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
787 >        vector<bool> electronFlags;
788 >        for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
789 >          if (cumulativeFlags.at("electrons").at(i).size()){
790 >            electronFlags = cumulativeFlags.at("electrons").at(i);
791 >            break;
792 >          }
793 >        }
794 >        for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
795 >          if(!electronFlags.at(electronIndex)) continue;
796 >          electronScaleFactor_ *= electronSFWeight_->at (electrons->at(electronIndex).eta, electrons->at(electronIndex).pt);
797 >        }
798 >      }
799      }
800 +    scaleFactor *= muonScaleFactor_;
801 +    scaleFactor *= electronScaleFactor_;
802  
803 <    vector<bool> mcparticleFlags = cumulativeFlags["mcparticles"].back();
804 <
343 <    for (uint mcparticleIndex = 0; mcparticleIndex != mcparticleFlags.size(); mcparticleIndex++){
344 <      if(!mcparticleFlags.at(mcparticleIndex)) continue;
803 >    cutFlows_.at(currentChannelIndex)->fillCutFlow(scaleFactor);
804 >    if(!(GetPlotsAfterEachCut_ || eventPassedAllCuts)) continue;
805  
806 <      double vx = mcparticles->at(mcparticleIndex).vx - vertexPosition.X (),
807 <             vy = mcparticles->at(mcparticleIndex).vy - vertexPosition.Y (),
808 <             vz = mcparticles->at(mcparticleIndex).vz - vertexPosition.Z (),
809 <             px = mcparticles->at(mcparticleIndex).px,
810 <             py = mcparticles->at(mcparticleIndex).py,
811 <             pt = mcparticles->at(mcparticleIndex).pt,
812 <             d0;
353 <
354 <      d0 = (-vx * py + vy * px) / pt;
355 <      oneDHists_.at(currentChannelIndex)["genD0"]->Fill (d0);
356 <      oneDHists_.at(currentChannelIndex)["genAbsD0"]->Fill (fabs (d0));
357 <      oneDHists_.at(currentChannelIndex)["genDZ"]->Fill (vz);
358 <      oneDHists_.at(currentChannelIndex)["genAbsDZ"]->Fill (fabs (vz));
806 >    if (printEventInfo_) {
807 >      // Write information about event to screen, for testing purposes.
808 >      cout << "Event passed all cuts in channel " <<  currentChannel.name
809 >           << ": run="  << events->at(0).run
810 >           << "  lumi=" << events->at(0).lumi
811 >           << "  event=" << events->at(0).evt
812 >           << endl;
813      }
814 <
815 <    vector<bool> electronFlags = cumulativeFlags["electrons"].back();
816 <    int electronCounter = 0;
817 <
818 <    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
819 <      if(!electronFlags.at(electronIndex)) continue;
820 <
821 <
822 <      electronCounter++;
823 <      oneDHists_.at(currentChannelIndex)["electronPt"]->Fill (electrons->at(electronIndex).pt);
824 <      oneDHists_.at(currentChannelIndex)["electronEta"]->Fill (electrons->at(electronIndex).eta);
825 <      oneDHists_.at(currentChannelIndex)["electronD0"]->Fill (electrons->at(electronIndex).correctedD0Vertex);
826 <      oneDHists_.at(currentChannelIndex)["electronDz"]->Fill (electrons->at(electronIndex).correctedDZ);
827 <      oneDHists_.at(currentChannelIndex)["electronAbsD0"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex));
828 <      oneDHists_.at(currentChannelIndex)["electronDZ"]->Fill (electrons->at(electronIndex).correctedDZ);
829 <      oneDHists_.at(currentChannelIndex)["electronAbsDZ"]->Fill (fabs(electrons->at(electronIndex).correctedDZ));
830 <      oneDHists_.at(currentChannelIndex)["electronD0Sig"]->Fill (electrons->at(electronIndex).correctedD0Vertex / electrons->at(electronIndex).tkD0err);
831 <      oneDHists_.at(currentChannelIndex)["electronAbsD0Sig"]->Fill (fabs(electrons->at(electronIndex).correctedD0Vertex) / electrons->at(electronIndex).tkD0err);
832 <      oneDHists_.at(currentChannelIndex)["electronIso"]->Fill (electrons->at(electronIndex).puChargedHadronIso / electrons->at(electronIndex).pt);
833 <      oneDHists_.at(currentChannelIndex)["electronFbrem"]->Fill (electrons->at(electronIndex).fbrem);
834 <      oneDHists_.at(currentChannelIndex)["electronMVATrig"]->Fill (electrons->at(electronIndex).mvaTrigV0);
835 <      oneDHists_.at(currentChannelIndex)["electronMVANonTrig"]->Fill (electrons->at(electronIndex).mvaNonTrigV0);
836 <
814 >    //filling histograms
815 >    for(uint currentCut = 0; currentCut != oneDHists_.at(currentChannelIndex).size(); currentCut++){//loop over all the directories in each channel.
816 >        uint currentDir;
817 >        if(!GetPlotsAfterEachCut_){ currentDir =  currentChannel.cuts.size() - oneDHists_.at(currentChannelIndex).size();}//if GetPlotsAfterEachCut_ is true, set currentDir point to the lat cut.
818 >        else{
819 >          currentDir = currentCut;
820 >        }
821 >        if(eventPassedPreviousCuts.at(currentDir)){
822 >        for (uint histogramIndex = 0; histogramIndex != histograms.size(); histogramIndex++){
823 >          histogram currentHistogram = histograms.at(histogramIndex);
824 >
825 >      if(currentHistogram.inputVariables.size() == 1){
826 >        TH1D* histo;
827 >        histo = oneDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
828 >        if     (currentHistogram.inputCollection == "jets")            fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
829 >        else if(currentHistogram.inputCollection == "secondary jets")  fill1DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
830 >        else if(currentHistogram.inputCollection == "muons")           fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
831 >        else if(currentHistogram.inputCollection == "secondary muons") fill1DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
832 >        else if(currentHistogram.inputCollection == "secondary electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
833 >        else if(currentHistogram.inputCollection == "muon-muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
834 >                                                                                       cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
835 >                                                                                       cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
836 >        else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill1DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
837 >                                                                                       cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
838 >                                                                                       cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
839 >        else if(currentHistogram.inputCollection == "electrons") fill1DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
840 >        else if(currentHistogram.inputCollection == "electron-electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(),\
841 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir),\
842 >                                                                                               cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
843 >        else if(currentHistogram.inputCollection == "jet-jet pairs") fill1DHistogram(histo,currentHistogram,jets.product(),jets.product(),\
844 >                                                                                               cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir),\
845 >                                                                                               cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
846 >        else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill1DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
847 >                                                                                       cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
848 >                                                                                       cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
849 >        else if(currentHistogram.inputCollection == "electron-muon pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),muons.product(), \
850 >                                                                                           cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir),
851 >                                                                                           cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
852 >        else if(currentHistogram.inputCollection == "electron-jet pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),jets.product(), \
853 >                                                                                           cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
854 >                                                                                           cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
855 >        else if(currentHistogram.inputCollection == "muon-jet pairs") fill1DHistogram(histo,currentHistogram, muons.product(),jets.product(), \
856 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir),
857 >                                                                                           cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
858 >        else if(currentHistogram.inputCollection == "electron-track pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),tracks.product(),
859 >                                                                                            cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
860 >                                                                                            cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
861 >        else if(currentHistogram.inputCollection == "muon-track pairs") fill1DHistogram(histo,currentHistogram, muons.product(),tracks.product(),
862 >                                                                                        cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
863 >                                                                                        cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
864 >        else if(currentHistogram.inputCollection == "muon-tau pairs") fill1DHistogram(histo,currentHistogram, muons.product(),taus.product(),
865 >                                                                                      cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
866 >                                                                                      cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
867 >        else if(currentHistogram.inputCollection == "tau-tau pairs") fill1DHistogram(histo,currentHistogram, taus.product(),taus.product(),
868 >                                                                                     cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
869 >                                                                                     cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
870 >        else if(currentHistogram.inputCollection == "tau-track pairs") fill1DHistogram(histo,currentHistogram, taus.product(),tracks.product(),
871 >                                                                                     cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
872 >                                                                                     cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
873 >        else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill1DHistogram(histo,currentHistogram, electrons.product(),trigobjs.product(),
874 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
875 >                                                                                              cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
876 >        else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill1DHistogram(histo,currentHistogram, muons.product(),trigobjs.product(),
877 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
878 >                                                                                          cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
879 >
880 >        else if(currentHistogram.inputCollection == "events") fill1DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
881 >        else if(currentHistogram.inputCollection == "taus") fill1DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
882 >        else if(currentHistogram.inputCollection == "mets") fill1DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
883 >        else if(currentHistogram.inputCollection == "tracks") fill1DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
884 >        else if(currentHistogram.inputCollection == "genjets") fill1DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
885 >        else if(currentHistogram.inputCollection == "mcparticles") fill1DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
886 >        else if(currentHistogram.inputCollection == "primaryvertexs") fill1DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
887 >        else if(currentHistogram.inputCollection == "bxlumis") fill1DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
888 >        else if(currentHistogram.inputCollection == "photons") fill1DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
889 >        else if(currentHistogram.inputCollection == "superclusters") fill1DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
890 >        else if(currentHistogram.inputCollection == "trigobjs") fill1DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
891 >        else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill1DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
892 >      }
893 >      else if(currentHistogram.inputVariables.size() == 2){
894 >        TH2D* histo;
895 >        histo = twoDHists_.at(currentChannelIndex).at(currentCut).at(currentHistogram.name);
896 >        if     (currentHistogram.inputCollection == "jets")            fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("jets").at(currentDir),scaleFactor);
897 >        else if(currentHistogram.inputCollection == "secondary jets")  fill2DHistogram(histo,currentHistogram,jets.product(),cumulativeFlags.at("secondary jets").at(currentDir),scaleFactor);
898 >        else if(currentHistogram.inputCollection == "muons")           fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("muons").at(currentDir),scaleFactor);
899 >        else if(currentHistogram.inputCollection == "secondary muons") fill2DHistogram(histo,currentHistogram,muons.product(),cumulativeFlags.at("secondary muons").at(currentDir),scaleFactor);
900 >        else if(currentHistogram.inputCollection == "muon-muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
901 >                                                                                       cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
902 >                                                                                       cumulativeFlags.at("muon-muon pairs").at(currentDir),scaleFactor);
903 >        else if(currentHistogram.inputCollection == "muon-secondary muon pairs") fill2DHistogram(histo,currentHistogram,muons.product(),muons.product(), \
904 >                                                                                       cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("secondary muons").at(currentDir), \
905 >                                                                                       cumulativeFlags.at("muon-secondary muon pairs").at(currentDir),scaleFactor);
906 >        else if(currentHistogram.inputCollection == "electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("electrons").at(currentDir),scaleFactor);
907 >        else if(currentHistogram.inputCollection == "secondary electrons") fill2DHistogram(histo,currentHistogram,electrons.product(),cumulativeFlags.at("secondary electrons").at(currentDir),scaleFactor);
908 >        else if(currentHistogram.inputCollection == "electron-electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
909 >                                                                                               cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("electrons").at(currentDir), \
910 >                                                                                               cumulativeFlags.at("electron-electron pairs").at(currentDir),scaleFactor);
911 >        else if(currentHistogram.inputCollection == "jet-jet pairs") fill2DHistogram(histo,currentHistogram,jets.product(),jets.product(), \
912 >                                                                                               cumulativeFlags.at("jets").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
913 >                                                                                               cumulativeFlags.at("jet-jet pairs").at(currentDir),scaleFactor);
914 >        else if(currentHistogram.inputCollection == "electron-secondary electron pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),electrons.product(), \
915 >                                                                                       cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("secondary electrons").at(currentDir), \
916 >                                                                                       cumulativeFlags.at("electron-secondary electron pairs").at(currentDir),scaleFactor);
917 >        else if(currentHistogram.inputCollection == "electron-muon pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),muons.product(), \
918 >                                                                                           cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("muons").at(currentDir), \
919 >                                                                                           cumulativeFlags.at("electron-muon pairs").at(currentDir),scaleFactor);
920 >        else if(currentHistogram.inputCollection == "electron-jet pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),jets.product(), \
921 >                                                                                           cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
922 >                                                                                           cumulativeFlags.at("electron-jet pairs").at(currentDir),scaleFactor);
923 >        else if(currentHistogram.inputCollection == "muon-jet pairs") fill2DHistogram(histo,currentHistogram,muons.product(),jets.product(), \
924 >                                                                                           cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("jets").at(currentDir), \
925 >                                                                                           cumulativeFlags.at("muon-jet pairs").at(currentDir),scaleFactor);
926 >        else if(currentHistogram.inputCollection == "electron-track pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),tracks.product(),
927 >                                                                                            cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
928 >                                                                                            cumulativeFlags.at("electron-track pairs").at(currentDir),scaleFactor);
929 >        else if(currentHistogram.inputCollection == "muon-track pairs") fill2DHistogram(histo,currentHistogram,muons.product(),tracks.product(),
930 >                                                                                        cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
931 >                                                                                        cumulativeFlags.at("muon-track pairs").at(currentDir),scaleFactor);
932 >        else if(currentHistogram.inputCollection == "muon-tau pairs") fill2DHistogram(histo,currentHistogram,muons.product(),taus.product(),
933 >                                                                                      cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
934 >                                                                                      cumulativeFlags.at("muon-tau pairs").at(currentDir),scaleFactor);
935 >        else if(currentHistogram.inputCollection == "tau-tau pairs") fill2DHistogram(histo,currentHistogram,taus.product(),taus.product(),
936 >                                                                                     cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("taus").at(currentDir),
937 >                                                                                     cumulativeFlags.at("tau-tau pairs").at(currentDir),scaleFactor);
938 >        else if(currentHistogram.inputCollection == "tau-track pairs") fill2DHistogram(histo,currentHistogram,taus.product(),tracks.product(),
939 >                                                                                     cumulativeFlags.at("taus").at(currentDir),cumulativeFlags.at("tracks").at(currentDir),
940 >                                                                                     cumulativeFlags.at("tau-track pairs").at(currentDir),scaleFactor);
941 >        else if(currentHistogram.inputCollection == "electron-trigobj pairs") fill2DHistogram(histo,currentHistogram,electrons.product(),trigobjs.product(),
942 >                                                                                              cumulativeFlags.at("electrons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
943 >                                                                                              cumulativeFlags.at("electron-trigobj pairs").at(currentDir),scaleFactor);
944 >        else if(currentHistogram.inputCollection == "muon-trigobj pairs") fill2DHistogram(histo,currentHistogram,muons.product(),trigobjs.product(),
945 >                                                                                          cumulativeFlags.at("muons").at(currentDir),cumulativeFlags.at("trigobjs").at(currentDir),
946 >                                                                                          cumulativeFlags.at("muon-trigobj pairs").at(currentDir),scaleFactor);
947 >        else if(currentHistogram.inputCollection == "events") fill2DHistogram(histo,currentHistogram,events.product(),cumulativeFlags.at("events").at(currentDir),scaleFactor);
948 >        else if(currentHistogram.inputCollection == "taus") fill2DHistogram(histo,currentHistogram,taus.product(),cumulativeFlags.at("taus").at(currentDir),scaleFactor);
949 >        else if(currentHistogram.inputCollection == "mets") fill2DHistogram(histo,currentHistogram,mets.product(),cumulativeFlags.at("mets").at(currentDir),scaleFactor);
950 >        else if(currentHistogram.inputCollection == "tracks") fill2DHistogram(histo,currentHistogram,tracks.product(),cumulativeFlags.at("tracks").at(currentDir),scaleFactor);
951 >        else if(currentHistogram.inputCollection == "track-event pairs") fill2DHistogram(histo,currentHistogram,tracks.product(),events.product(),
952 >                                                                                         cumulativeFlags.at("tracks").at(currentDir),cumulativeFlags.at("events").at(currentDir),
953 >                                                                                         cumulativeFlags.at("track-event pairs").at(currentDir),scaleFactor);
954 >        else if(currentHistogram.inputCollection == "genjets") fill2DHistogram(histo,currentHistogram,genjets.product(),cumulativeFlags.at("genjets").at(currentDir),scaleFactor);
955 >        else if(currentHistogram.inputCollection == "mcparticles") fill2DHistogram(histo,currentHistogram,mcparticles.product(),cumulativeFlags.at("mcparticles").at(currentDir),scaleFactor);
956 >        else if(currentHistogram.inputCollection == "primaryvertexs") fill2DHistogram(histo,currentHistogram,primaryvertexs.product(),cumulativeFlags.at("primaryvertexs").at(currentDir),scaleFactor);
957 >        else if(currentHistogram.inputCollection == "bxlumis") fill2DHistogram(histo,currentHistogram,bxlumis.product(),cumulativeFlags.at("bxlumis").at(currentDir),scaleFactor);
958 >        else if(currentHistogram.inputCollection == "photons") fill2DHistogram(histo,currentHistogram,photons.product(),cumulativeFlags.at("photons").at(currentDir),scaleFactor);
959 >        else if(currentHistogram.inputCollection == "superclusters") fill2DHistogram(histo,currentHistogram,superclusters.product(),cumulativeFlags.at("superclusters").at(currentDir),scaleFactor);
960 >        else if(currentHistogram.inputCollection == "trigobjs") fill2DHistogram(histo,currentHistogram,trigobjs.product(),cumulativeFlags.at("trigobjs").at(currentDir),scaleFactor);
961 >        else if(currentHistogram.inputCollection == "stops" && datasetType_ == "signalMC") fill2DHistogram(histo,currentHistogram,stops.product(),cumulativeFlags.at("stops").at(currentDir),scaleFactor);
962 >      }
963      }
384    oneDHists_.at(currentChannelIndex)["numElectrons"]->Fill (electronCounter);
964  
965  
387    vector<bool> muonFlags = cumulativeFlags["muons"].back();
388    int muonCounter = 0;
966  
967 +    //fills histograms with the sizes of collections
968 +    for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++){
969  
970 <    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
971 <      if(!muonFlags.at(muonIndex)) continue;
393 <      muonCounter++;
970 >      string currentObject = objectsToPlot.at(currentObjectIndex);
971 >      string objectToPlot = "";
972  
973 <      oneDHists_.at(currentChannelIndex)["muonPt"]->Fill (muons->at(muonIndex).pt);
974 <      oneDHists_.at(currentChannelIndex)["muonEta"]->Fill (muons->at(muonIndex).eta);
975 <      oneDHists_.at(currentChannelIndex)["muonD0"]->Fill (muons->at(muonIndex).correctedD0Vertex);
976 <      oneDHists_.at(currentChannelIndex)["muonDz"]->Fill (muons->at(muonIndex).correctedDZ);
977 <      oneDHists_.at(currentChannelIndex)["muonAbsD0"]->Fill (fabs(muons->at(muonIndex).correctedD0Vertex));
978 <      oneDHists_.at(currentChannelIndex)["muonDZ"]->Fill (muons->at(muonIndex).correctedDZ);
979 <      oneDHists_.at(currentChannelIndex)["muonAbsDZ"]->Fill (fabs(muons->at(muonIndex).correctedDZ));
980 <      oneDHists_.at(currentChannelIndex)["muonD0Sig"]->Fill (muons->at(muonIndex).correctedD0Vertex / muons->at(muonIndex).tkD0err);
981 <      oneDHists_.at(currentChannelIndex)["muonAbsD0Sig"]->Fill (fabs(muons->at(muonIndex).correctedD0Vertex) / muons->at(muonIndex).tkD0err);
982 <      oneDHists_.at(currentChannelIndex)["muonIso"]->Fill (muons->at(muonIndex).puChargedHadronIso / muons->at(muonIndex).pt);
973 >      // Name of objectToPlot here must match the name specified in OSUAnalysis::OSUAnalysis().
974 >      if(currentObject == "muon-muon pairs")                         objectToPlot = "dimuonPairs";
975 >      else if(currentObject == "electron-electron pairs")            objectToPlot = "dielectronPairs";
976 >      else if(currentObject == "electron-muon pairs")                objectToPlot = "electronMuonPairs";
977 >      else if(currentObject == "electron-jet pairs")                 objectToPlot = "electronJetPairs";
978 >      else if(currentObject == "muon-jet pairs")                     objectToPlot = "muonJetPairs";
979 >      else if(currentObject == "jet-jet pairs")                      objectToPlot = "dijetPairs";
980 >      else if(currentObject == "secondary jets")                     objectToPlot = "secondaryJets";
981 >      else if(currentObject == "electron-track pairs")               objectToPlot = "electronTrackPairs";
982 >      else if(currentObject == "muon-track pairs")                   objectToPlot = "muonTrackPairs";
983 >      else if(currentObject == "muon-tau pairs")                     objectToPlot = "muonTauPairs";
984 >      else if(currentObject == "tau-tau pairs")                      objectToPlot = "ditauPairs";
985 >      else if(currentObject == "tau-track pairs")                    objectToPlot = "tauTrackPairs";
986 >      else if(currentObject == "track-event pairs")                  objectToPlot = "trackEventPairs";
987 >      else if(currentObject == "muon-secondary muon pairs")          objectToPlot = "muonSecondaryMuonPairs";
988 >      else if(currentObject == "secondary muons")                    objectToPlot = "secondaryMuons";
989 >      else if(currentObject == "electron-secondary electron pairs")  objectToPlot = "electronSecondaryElectronPairs";
990 >      else if(currentObject == "secondary electrons")                objectToPlot = "secondaryElectrons";
991 >      else if(currentObject == "electron-trigobj pairs")             objectToPlot = "electronTrigobjPairs";
992 >      else if(currentObject == "muon-trigobj pairs")                 objectToPlot = "muonTrigobjPairs";
993 >      else objectToPlot = currentObject;
994 >
995 >      string tempCurrentObject = objectToPlot;
996 >      tempCurrentObject.at(0) = toupper(tempCurrentObject.at(0));
997 >      string histoName = "num" + tempCurrentObject;
998 >
999 >      //set position of primary vertex in event, in order to calculate quantities relative to it
1000 >      if(find(objectsToCut.begin(), objectsToCut.end(), currentObject) != objectsToCut.end()) {
1001 >        vector<bool> lastCutFlags = cumulativeFlags.at(currentObject).at(currentDir);
1002 >        int numToPlot = 0;
1003 >        for (uint currentFlag = 0; currentFlag != lastCutFlags.size(); currentFlag++){
1004 >          if(lastCutFlags.at(currentFlag)) numToPlot++;
1005 >        }
1006 >        if(objectToPlot == "primaryvertexs"){
1007 >          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1008 >          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1009 >        }
1010 >        else {
1011 >          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(numToPlot,scaleFactor);
1012 >        }
1013 >      }
1014 >      else if(objectToPlot == "jets")           oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(jets->size(),scaleFactor);
1015 >      else if(objectToPlot == "secondaryJets")  oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(jets->size(),scaleFactor);
1016 >      else if(objectToPlot == "muons")          oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size(),scaleFactor);
1017 >      else if(objectToPlot == "secondaryMuons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size(),scaleFactor);
1018 >      else if(objectToPlot == "dimuonPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
1019 >      else if(objectToPlot == "muonSecondaryMuonPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*(muons->size()-1)/2,scaleFactor);
1020 >      else if(objectToPlot == "electrons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size(),scaleFactor);
1021 >      else if(objectToPlot == "secondaryElectrons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size(),scaleFactor);
1022 >      else if(objectToPlot == "dielectronPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
1023 >      else if(objectToPlot == "electronSecondaryElectronPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*(electrons->size()-1)/2,scaleFactor);
1024 >      else if(objectToPlot == "electronMuonPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*muons->size(),scaleFactor);
1025 >      else if(objectToPlot == "electronJetPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*jets->size(),scaleFactor);
1026 >      else if(objectToPlot == "muonJetPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*jets->size(),scaleFactor);
1027 >      else if(objectToPlot == "electronTrackPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*tracks->size(),scaleFactor);
1028 >      else if(objectToPlot == "electronTrigobjPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(electrons->size()*trigobjs->size(),scaleFactor);
1029 >      else if(objectToPlot == "muonTrigobjPairs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(muons->size()*trigobjs->size(),scaleFactor);
1030 >      else if(objectToPlot == "events") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(events->size(),scaleFactor);
1031 >      else if(objectToPlot == "taus") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(taus->size(),scaleFactor);
1032 >      else if(objectToPlot == "mets") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(mets->size(),scaleFactor);
1033 >      else if(objectToPlot == "tracks") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(tracks->size(),scaleFactor);
1034 >      else if(objectToPlot == "genjets") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(genjets->size(),scaleFactor);
1035 >      else if(objectToPlot == "mcparticles") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(mcparticles->size(),scaleFactor);
1036 >      else if(objectToPlot == "bxlumis") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(bxlumis->size(),scaleFactor);
1037 >      else if(objectToPlot == "photons") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(photons->size(),scaleFactor);
1038 >      else if(objectToPlot == "superclusters") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(superclusters->size(),scaleFactor);
1039 >      else if(objectToPlot == "trigobjs") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(trigobjs->size(),scaleFactor);
1040 >      else if(objectToPlot == "primaryvertexs"){
1041 >        oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"BeforePileupCorrection")->Fill(primaryvertexs->size());
1042 >        oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName+"AfterPileupCorrection")->Fill(primaryvertexs->size(),scaleFactor);
1043 >      }
1044 >      if(objectToPlot == "stops" && datasetType_ == "signalMC") oneDHists_.at(currentChannelIndex).at(currentCut).at(histoName)->Fill(stops->size(),scaleFactor);
1045 >
1046 >     } // end for (uint currentObjectIndex = 0; currentObjectIndex != objectsToPlot.size(); currentObjectIndex++)
1047      }
1048 <    oneDHists_.at(currentChannelIndex)["numMuons"]->Fill (muonCounter);
1048 >  }
1049 >  } //end loop over channel
1050  
1051 +  masterCutFlow_->fillCutFlow(masterScaleFactor);
1052  
1053 + } // end void OSUAnalysis::analyze (const edm::Event &event, const edm::EventSetup &setup)
1054  
1055  
1056  
1057 <  } //end loop over channel
1057 > bool
1058 > OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
1059  
414  masterCutFlow_->fillCutFlow();
1060  
1061 +  if(comparison == ">")       return testValue >  cutValue;
1062 +  else if(comparison == ">=") return testValue >= cutValue;
1063 +  else if(comparison == "<")  return testValue <  cutValue;
1064 +  else if(comparison == "<=") return testValue <= cutValue;
1065 +  else if(comparison == "==") return testValue == cutValue;
1066 +  else if(comparison == "=") return testValue == cutValue;
1067 +  else if(comparison == "!=") return testValue != cutValue;
1068 +  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1069  
1070   }
1071  
419
1072   bool
1073 < OSUAnalysis::evaluateComparison (double testValue, string comparison, double cutValue){
1073 > OSUAnalysis::evaluateComparison (string testValue, string comparison, string cutValue){
1074  
1075  
1076    if(comparison == ">")       return testValue >  cutValue;
# Line 426 | Line 1078 | OSUAnalysis::evaluateComparison (double
1078    else if(comparison == "<")  return testValue <  cutValue;
1079    else if(comparison == "<=") return testValue <= cutValue;
1080    else if(comparison == "==") return testValue == cutValue;
1081 +  else if(comparison == "=") return testValue == cutValue;
1082    else if(comparison == "!=") return testValue != cutValue;
1083 <  else {std::cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1083 >  else {cout << "WARNING: invalid comparison operator '" << comparison << "'\n"; return false;}
1084  
1085   }
1086  
# Line 441 | Line 1094 | OSUAnalysis::evaluateTriggers (vector<st
1094        if(trigger->pass != 1) continue;
1095        for(uint triggerName = 0; triggerName != triggersToTest.size(); triggerName++)
1096          {
1097 <          if(trigger->name.find(triggersToTest.at(triggerName))!=std::string::npos){
1097 >          if(trigger->name.find(triggersToTest.at(triggerName))!=string::npos){
1098              triggerDecision = true;
1099            }
1100          }
# Line 450 | Line 1103 | OSUAnalysis::evaluateTriggers (vector<st
1103  
1104   }
1105  
1106 < std::vector<std::string>
1106 > vector<string>
1107   OSUAnalysis::splitString (string inputString){
1108  
1109 <  std::stringstream stringStream(inputString);
1110 <  std::istream_iterator<std::string> begin(stringStream);
1111 <  std::istream_iterator<std::string> end;
1112 <  std::vector<std::string> stringVector(begin, end);
1109 >  stringstream stringStream(inputString);
1110 >  istream_iterator<string> begin(stringStream);
1111 >  istream_iterator<string> end;
1112 >  vector<string> stringVector(begin, end);
1113    return stringVector;
1114  
1115   }
1116  
1117 +
1118 + void OSUAnalysis::getTwoObjs(string tempInputCollection, string& obj1, string& obj2) {
1119 +  // Set two object strings from the tempInputCollection string,
1120 +  // For example, if tempInputCollection is "electron-muon pairs",
1121 +  // then obj1 = "electrons" and obj2 = "muons".
1122 +  // Note that the objects have an "s" appended.
1123 +
1124 +  int dashIndex = tempInputCollection.find("-");
1125 +  int spaceIndex = tempInputCollection.find_last_of(" ");
1126 +  int secondWordLength = spaceIndex - dashIndex;
1127 +  obj1 = tempInputCollection.substr(0,dashIndex) + "s";
1128 +  obj2 = tempInputCollection.substr(dashIndex+1,secondWordLength-1)+"s";
1129 +
1130 + }
1131 +
1132 +
1133 + string OSUAnalysis::getObjToGet(string obj) {
1134 +  // Return the string corresponding to the object to get for the given obj string.
1135 +  // Right now this only handles the case in which obj contains "secondary",
1136 +  // e.g, "secondary muons".
1137 +  // Note that "s" is NOT appended.
1138 +
1139 +  if (obj.find("secondary")==string::npos) return obj;  // "secondary" is not found
1140 +  int firstSpaceIndex = obj.find_first_of(" ");
1141 +  return obj.substr(firstSpaceIndex+1,obj.length()-1);
1142 +
1143 + }
1144 +
1145 +
1146 + //!jet valueLookup
1147   double
1148 < OSUAnalysis::valueLookup (const BNjet* object, string variable, string function){
1148 > OSUAnalysis::valueLookup (const BNjet* object, string variable, string function, string &stringValue){
1149  
1150    double value = 0.0;
1151    if(variable == "energy") value = object->energy;
# Line 582 | Line 1265 | OSUAnalysis::valueLookup (const BNjet* o
1265    else if(variable == "puJetId_loose_cutbased") value = object->puJetId_loose_cutbased;
1266  
1267  
1268 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1268 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1269  
1270    value = applyFunction(function, value);
1271  
# Line 590 | Line 1273 | OSUAnalysis::valueLookup (const BNjet* o
1273   }
1274  
1275  
1276 <
1276 > //!muon valueLookup
1277   double
1278 < OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function){
1278 > OSUAnalysis::valueLookup (const BNmuon* object, string variable, string function, string &stringValue){
1279  
1280    double value = 0.0;
1281    if(variable == "energy") value = object->energy;
# Line 608 | Line 1291 | OSUAnalysis::valueLookup (const BNmuon*
1291    else if(variable == "ecalIso") value = object->ecalIso;
1292    else if(variable == "hcalIso") value = object->hcalIso;
1293    else if(variable == "caloIso") value = object->caloIso;
1294 <  else if(variable == "trackIsoDR03") value = object->trackIsoDR03;
1294 >  else if(variable == "trackIsDR03") value = object->trackIsoDR03;
1295    else if(variable == "ecalIsoDR03") value = object->ecalIsoDR03;
1296    else if(variable == "hcalIsoDR03") value = object->hcalIsoDR03;
1297    else if(variable == "caloIsoDR03") value = object->caloIsoDR03;
# Line 746 | Line 1429 | OSUAnalysis::valueLookup (const BNmuon*
1429    else if(variable == "numberOfMatchedStations") value = object->numberOfMatchedStations;
1430    else if(variable == "time_ndof") value = object->time_ndof;
1431  
1432 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1432 >  //user-defined variables
1433 >  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1434 >  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1435 >  else if(variable == "detIso") value = (object->trackIsoDR03) / object->pt;
1436 >  else if(variable == "relPFdBetaIso") value = (object->pfIsoR04SumChargedHadronPt + max(0.0, object->pfIsoR04SumNeutralHadronEt + object->pfIsoR04SumPhotonEt - 0.5*object->pfIsoR04SumPUPt)) / object->pt;
1437 >  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIso + max(0.0, object->neutralHadronIso + object->photonIso - object->AEffDr03*object->rhoPrime) ) / object->pt;
1438 >  else if(variable == "metMT") {
1439 >    if (const BNmet *met = chosenMET ())
1440 >      {
1441 >        double dPhi = deltaPhi (object->phi, met->phi);
1442 >        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1443 >      }
1444 >    else
1445 >      value = -999;
1446 >  }
1447 >
1448 >
1449 >
1450 >  else if(variable == "correctedD0VertexInEBPlus"){
1451 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1452 >    else value = -999;
1453 >  }
1454 >  else if(variable == "correctedD0VertexOutEBPlus"){
1455 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1456 >    else value = -999;
1457 >  }
1458 >  else if(variable == "correctedD0VertexEEPlus"){
1459 >    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0Vertex;
1460 >    else value = -999;
1461 >  }
1462 >
1463 >  else if(variable == "correctedD0BeamspotInEBPlus"){
1464 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1465 >    else value = -999;
1466 >  }
1467 >  else if(variable == "correctedD0BeamspotOutEBPlus"){
1468 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1469 >    else value = -999;
1470 >  }
1471 >  else if(variable == "correctedD0BeamspotEEPlus"){
1472 >    if(fabs(object->eta) > 1.479 && object->eta > 0) value = object->correctedD0;
1473 >    else value = -999;
1474 >  }
1475 >
1476 >  else if(variable == "correctedD0VertexInEBMinus"){
1477 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1478 >    else value = -999;
1479 >  }
1480 >  else if(variable == "correctedD0VertexOutEBMinus"){
1481 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1482 >    else value = -999;
1483 >  }
1484 >  else if(variable == "correctedD0VertexEEMinus"){
1485 >    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0Vertex;
1486 >    else value = -999;
1487 >  }
1488 >
1489 >  else if(variable == "correctedD0BeamspotInEBMinus"){
1490 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1491 >    else value = -999;
1492 >  }
1493 >  else if(variable == "correctedD0BeamspotOutEBMinus"){
1494 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1495 >    else value = -999;
1496 >  }
1497 >  else if(variable == "correctedD0BeamspotEEMinus"){
1498 >    if(fabs(object->eta) > 1.479 && object->eta < 0) value = object->correctedD0;
1499 >    else value = -999;
1500 >  }
1501 >
1502 >
1503 >  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1504 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1505 >    else value = -999;
1506 >  }
1507 >  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1508 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1509 >    else value = -999;
1510 >  }
1511 >  else if(variable == "correctedD0VertexEEPositiveCharge"){
1512 >    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0Vertex;
1513 >    else value = -999;
1514 >  }
1515 >
1516 >  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1517 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1518 >    else value = -999;
1519 >  }
1520 >  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1521 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1522 >    else value = -999;
1523 >  }
1524 >  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1525 >    if(fabs(object->eta) > 1.479 && object->charge > 0) value = object->correctedD0;
1526 >    else value = -999;
1527 >  }
1528 >
1529 >  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1530 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1531 >    else value = -999;
1532 >  }
1533 >  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1534 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1535 >    else value = -999;
1536 >  }
1537 >  else if(variable == "correctedD0VertexEENegativeCharge"){
1538 >    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0Vertex;
1539 >    else value = -999;
1540 >  }
1541 >
1542 >  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1543 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1544 >    else value = -999;
1545 >  }
1546 >  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1547 >    if(fabs(object->eta) < 1.479 && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1548 >    else value = -999;
1549 >  }
1550 >  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1551 >    if(fabs(object->eta) > 1.479 && object->charge < 0) value = object->correctedD0;
1552 >    else value = -999;
1553 >  }
1554 >
1555 >
1556 >  else if(variable == "tightID") {
1557 >    value = object->isGlobalMuon > 0                \
1558 >      && object->isPFMuon > 0                        \
1559 >      && object->normalizedChi2 < 10                \
1560 >                                  && object->numberOfValidMuonHits > 0        \
1561 >      && object->numberOfMatchedStations > 1        \
1562 >      && fabs(object->correctedD0Vertex) < 0.2        \
1563 >      && fabs(object->correctedDZ) < 0.5        \
1564 >      && object->numberOfValidPixelHits > 0                \
1565 >      && object->numberOfLayersWithMeasurement > 5;
1566 >  }
1567 >  else if(variable == "tightIDdisplaced"){
1568 >    value = object->isGlobalMuon > 0                \
1569 >      && object->isPFMuon > 0                        \
1570 >      && object->normalizedChi2 < 10                \
1571 >                                  && object->numberOfValidMuonHits > 0        \
1572 >      && object->numberOfMatchedStations > 1        \
1573 >      && object->numberOfValidPixelHits > 0        \
1574 >      && object->numberOfLayersWithMeasurement > 5;
1575 >  }
1576 >
1577 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1578 >
1579 >  else if(variable == "genMatchedPdgId"){
1580 >    int index = getGenMatchedParticleIndex(object);
1581 >    if(index == -1) value = 0;
1582 >    else value = mcparticles->at(index).id;
1583 >  }
1584 >
1585 >  else if(variable == "genMatchedId"){
1586 >    int index = getGenMatchedParticleIndex(object);
1587 >    if(index == -1) value = 0;
1588 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
1589 >  }
1590 >  else if(variable == "genMatchedMotherId"){
1591 >    int index = getGenMatchedParticleIndex(object);
1592 >    if(index == -1) value = 0;
1593 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1594 >  }
1595 >  else if(variable == "genMatchedMotherIdReverse"){
1596 >    int index = getGenMatchedParticleIndex(object);
1597 >    if(index == -1) value = 24;
1598 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).motherId);
1599 >  }
1600 >  else if(variable == "genMatchedGrandmotherId"){
1601 >    int index = getGenMatchedParticleIndex(object);
1602 >    if(index == -1) value = 0;
1603 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1604 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1605 >      if(motherIndex == -1) value = 0;
1606 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1607 >    }
1608 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1609 >  }
1610 >  else if(variable == "genMatchedGrandmotherIdReverse"){
1611 >    int index = getGenMatchedParticleIndex(object);
1612 >    if(index == -1) value = 24;
1613 >    else if(fabs(mcparticles->at(index).motherId) == 15){
1614 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
1615 >      if(motherIndex == -1) value = 24;
1616 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
1617 >    }
1618 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
1619 >  }
1620 >  else if(variable == "pfMuonsFromVertex"){
1621 >    double d0Error, dzError;
1622 >
1623 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1624 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
1625 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
1626 >         || fabs (object->correctedD0Vertex / d0Error) > 99.0
1627 >         || fabs (object->correctedDZ / dzError) > 99.0;
1628 >    value = (object->isStandAloneMuon && !object->isTrackerMuon && !object->isGlobalMuon) || !value;
1629 >  }
1630 >
1631 >
1632 >
1633 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1634  
1635    value = applyFunction(function, value);
1636  
1637    return value;
1638   }
1639  
1640 <
1640 > //!electron valueLookup
1641   double
1642 < OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function){
1642 > OSUAnalysis::valueLookup (const BNelectron* object, string variable, string function, string &stringValue){
1643  
1644    double value = 0.0;
1645    if(variable == "energy") value = object->energy;
# Line 915 | Line 1799 | OSUAnalysis::valueLookup (const BNelectr
1799    else if(variable == "eidHyperTight4MC") value = object->eidHyperTight4MC;
1800    else if(variable == "passConvVeto") value = object->passConvVeto;
1801  
1802 +  //user-defined variables
1803 +  else if(variable == "correctedD0VertexErr") value =  hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1804 +  else if(variable == "correctedD0VertexSig") value =  object->correctedD0Vertex / hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
1805 +  else if(variable == "detIso") value = (object->trackIso) / object->pt;
1806 +  else if(variable == "relPFrhoIso") value = ( object->chargedHadronIsoDR03 + max(0.0, object->neutralHadronIsoDR03 + object->photonIsoDR03 - object->AEffDr03*object->rhoPrime) ) / object->pt;
1807 +  else if(variable == "metMT") {
1808 +    if (const BNmet *met = chosenMET ())
1809 +      {
1810 +        double dPhi = deltaPhi (object->phi, met->phi);
1811 +        value = sqrt (2 * object->pt * met->pt * (1 - cos (dPhi)));
1812 +      }
1813 +    else
1814 +      value = -999;
1815 +  }
1816  
1817 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
1817 >  else if(variable == "correctedD0VertexEEPositiveChargeLowPt"){
1818 >    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt > 45) value = object->correctedD0Vertex;
1819 >    else value = -999;
1820 >  }
1821 >  else if(variable == "correctedD0VertexEEPositiveChargeHighPt"){
1822 >    if(fabs(object->eta) > 1.479 && object->charge > 0 && object->pt < 45) value = object->correctedD0Vertex;
1823 >    else value = -999;
1824 >  }
1825 >
1826 >  else if(variable == "correctedD0VertexInEBPlus"){
1827 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1828 >    else value = -999;
1829 >  }
1830 >  else if(variable == "correctedD0VertexOutEBPlus"){
1831 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0Vertex;
1832 >    else value = -999;
1833 >  }
1834 >  else if(variable == "correctedD0VertexEEPlus"){
1835 >    if(object->isEE && object->eta > 0) value = object->correctedD0Vertex;
1836 >    else value = -999;
1837 >  }
1838 >
1839 >  else if(variable == "correctedD0BeamspotInEBPlus"){
1840 >    if(fabs(object->eta) < 0.8 && object->eta > 0) value = object->correctedD0;
1841 >    else value = -999;
1842 >  }
1843 >  else if(variable == "correctedD0BeamspotOutEBPlus"){
1844 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta > 0) value = object->correctedD0;
1845 >    else value = -999;
1846 >  }
1847 >  else if(variable == "correctedD0BeamspotEEPlus"){
1848 >    if(object->isEE && object->eta > 0) value = object->correctedD0;
1849 >    else value = -999;
1850 >  }
1851 >
1852 >  else if(variable == "correctedD0VertexInEBMinus"){
1853 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1854 >    else value = -999;
1855 >  }
1856 >  else if(variable == "correctedD0VertexOutEBMinus"){
1857 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0Vertex;
1858 >    else value = -999;
1859 >  }
1860 >  else if(variable == "correctedD0VertexEEMinus"){
1861 >    if(object->isEE && object->eta < 0) value = object->correctedD0Vertex;
1862 >    else value = -999;
1863 >  }
1864 >
1865 >  else if(variable == "correctedD0BeamspotInEBMinus"){
1866 >    if(fabs(object->eta) < 0.8 && object->eta < 0) value = object->correctedD0;
1867 >    else value = -999;
1868 >  }
1869 >  else if(variable == "correctedD0BeamspotOutEBMinus"){
1870 >    if(object->isEB && fabs(object->eta) > 0.8 && object->eta < 0) value = object->correctedD0;
1871 >    else value = -999;
1872 >  }
1873 >  else if(variable == "correctedD0BeamspotEEMinus"){
1874 >    if(object->isEE && object->eta < 0) value = object->correctedD0;
1875 >    else value = -999;
1876 >  }
1877 >
1878 >  else if(variable == "tightID"){
1879 >    if (object->isEB)
1880 >      {
1881 >        value = fabs(object->delEtaIn) < 0.004 \
1882 >          && fabs (object->delPhiIn) < 0.03 \
1883 >          && object->scSigmaIEtaIEta < 0.01 \
1884 >          && object->hadOverEm < 0.12 \
1885 >          && fabs (object->correctedD0Vertex) < 0.02 \
1886 >          && fabs (object->correctedDZ) < 0.1 \
1887 >          && object->absInvEMinusInvPin < 0.05 \
1888 >          && object->passConvVeto;
1889 >      }
1890 >    else
1891 >      {
1892 >        value = fabs(object->delEtaIn) < 0.005 \
1893 >          && fabs (object->delPhiIn) < 0.02 \
1894 >          && object->scSigmaIEtaIEta < 0.03 \
1895 >          && object->hadOverEm < 0.10 \
1896 >          && fabs (object->correctedD0Vertex) < 0.02 \
1897 >          && fabs (object->correctedDZ) < 0.1 \
1898 >          && object->absInvEMinusInvPin < 0.05 \
1899 >          && object->passConvVeto;
1900 >      }
1901 >  }
1902 >
1903 >  else if(variable == "correctedD0VertexInEBPositiveCharge"){
1904 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1905 >    else value = -999;
1906 >  }
1907 >  else if(variable == "correctedD0VertexOutEBPositiveCharge"){
1908 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0Vertex;
1909 >    else value = -999;
1910 >  }
1911 >  else if(variable == "correctedD0VertexEEPositiveCharge"){
1912 >    if(object->isEE && object->charge > 0) value = object->correctedD0Vertex;
1913 >    else value = -999;
1914 >  }
1915 >
1916 >  else if(variable == "correctedD0BeamspotInEBPositiveCharge"){
1917 >    if(fabs(object->eta) < 0.8 && object->charge > 0) value = object->correctedD0;
1918 >    else value = -999;
1919 >  }
1920 >  else if(variable == "correctedD0BeamspotOutEBPositiveCharge"){
1921 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge > 0) value = object->correctedD0;
1922 >    else value = -999;
1923 >  }
1924 >  else if(variable == "correctedD0BeamspotEEPositiveCharge"){
1925 >    if(object->isEE && object->charge > 0) value = object->correctedD0;
1926 >    else value = -999;
1927 >  }
1928 >
1929 >  else if(variable == "correctedD0VertexInEBNegativeCharge"){
1930 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1931 >    else value = -999;
1932 >  }
1933 >  else if(variable == "correctedD0VertexOutEBNegativeCharge"){
1934 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0Vertex;
1935 >    else value = -999;
1936 >  }
1937 >  else if(variable == "correctedD0VertexEENegativeCharge"){
1938 >    if(object->isEE && object->charge < 0) value = object->correctedD0Vertex;
1939 >    else value = -999;
1940 >  }
1941 >
1942 >  else if(variable == "correctedD0BeamspotInEBNegativeCharge"){
1943 >    if(fabs(object->eta) < 0.8 && object->charge < 0) value = object->correctedD0;
1944 >    else value = -999;
1945 >  }
1946 >  else if(variable == "correctedD0BeamspotOutEBNegativeCharge"){
1947 >    if(object->isEB && fabs(object->eta) > 0.8 && object->charge < 0) value = object->correctedD0;
1948 >    else value = -999;
1949 >  }
1950 >  else if(variable == "correctedD0BeamspotEENegativeCharge"){
1951 >    if(object->isEE && object->charge < 0) value = object->correctedD0;
1952 >    else value = -999;
1953 >  }
1954 >
1955 >
1956 >  else if(variable == "tightIDdisplaced"){
1957 >    if (object->isEB)
1958 >      {
1959 >        value = fabs(object->delEtaIn) < 0.004 \
1960 >          && fabs (object->delPhiIn) < 0.03 \
1961 >          && object->scSigmaIEtaIEta < 0.01 \
1962 >          && object->hadOverEm < 0.12 \
1963 >          && object->absInvEMinusInvPin < 0.05;
1964 >      }
1965 >    else
1966 >      {
1967 >        value = fabs (object->delEtaIn) < 0.005 \
1968 >          && fabs (object->delPhiIn) < 0.02 \
1969 >          && object->scSigmaIEtaIEta < 0.03 \
1970 >          && object->hadOverEm < 0.10 \
1971 >          && object->absInvEMinusInvPin < 0.05;
1972 >      }
1973 >  }
1974 >
1975 >
1976 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
1977 >
1978 >  else if(variable == "genMatchedPdgId"){
1979 >    int index = getGenMatchedParticleIndex(object);
1980 >    if(index == -1) value = 0;
1981 >    else value = mcparticles->at(index).id;
1982 >  }
1983 >
1984 >
1985 >  else if(variable == "genMatchedId"){
1986 >    int index = getGenMatchedParticleIndex(object);
1987 >    if(index == -1) value = 0;
1988 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
1989 >  }
1990 >  else if(variable == "genMatchedMotherId"){
1991 >    int index = getGenMatchedParticleIndex(object);
1992 >    if(index == -1) value = 0;
1993 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
1994 >  }
1995 >  else if(variable == "genMatchedMotherIdReverse"){
1996 >    int index = getGenMatchedParticleIndex(object);
1997 >    if(index == -1) value = 24;
1998 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
1999 >  }
2000 >  else if(variable == "genMatchedGrandmotherId"){
2001 >    int index = getGenMatchedParticleIndex(object);
2002 >    if(index == -1) value = 0;
2003 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2004 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2005 >      if(motherIndex == -1) value = 0;
2006 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2007 >    }
2008 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2009 >  }
2010 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2011 >    int index = getGenMatchedParticleIndex(object);
2012 >    if(index == -1) value = 24;
2013 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2014 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2015 >      if(motherIndex == -1) value = 24;
2016 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2017 >    }
2018 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2019 >  }
2020 >  else if(variable == "pfElectronsFromVertex"){
2021 >    double d0Error, dzError;
2022 >
2023 >    d0Error = hypot (object->tkD0err, hypot (chosenVertex ()->xError, chosenVertex ()->yError));
2024 >    dzError = hypot (object->tkDZerr, chosenVertex ()->zError);
2025 >    value = fabs (object->correctedD0Vertex) > 0.2 || fabs (object->correctedDZ) > 0.5
2026 >         || fabs (object->correctedD0Vertex / d0Error) > 99.0
2027 >         || fabs (object->correctedDZ / dzError) > 99.0;
2028 >    value = !value;
2029 >  }
2030 >
2031 >
2032 >
2033 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2034  
2035    value = applyFunction(function, value);
2036  
2037    return value;
2038   }
2039  
2040 <
2040 > //!event valueLookup
2041   double
2042 < OSUAnalysis::valueLookup (const BNevent* object, string variable, string function){
2042 > OSUAnalysis::valueLookup (const BNevent* object, string variable, string function, string &stringValue){
2043  
2044    double value = 0.0;
2045  
# Line 993 | Line 2107 | OSUAnalysis::valueLookup (const BNevent*
2107    else if(variable == "id1") value = object->id1;
2108    else if(variable == "id2") value = object->id2;
2109    else if(variable == "evt") value = object->evt;
2110 +  else if(variable == "puScaleFactor"){
2111 +    if(doPileupReweighting_ && datasetType_ != "data")
2112 +      value = puWeight_->at (events->at (0).numTruePV);
2113 +    else
2114 +      value = 1.0;
2115 +  }
2116 +  else if(variable == "muonScaleFactor") value = muonScaleFactor_;
2117 +  else if(variable == "electronScaleFactor") value = electronScaleFactor_;
2118 +  else if(variable == "stopCTauScaleFactor") value = stopCTauScaleFactor_;
2119  
2120 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2120 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2121  
2122    value = applyFunction(function, value);
2123  
2124    return value;
2125   }
2126  
2127 + //!tau valueLookup
2128   double
2129 < OSUAnalysis::valueLookup (const BNtau* object, string variable, string function){
2129 > OSUAnalysis::valueLookup (const BNtau* object, string variable, string function, string &stringValue){
2130  
2131    double value = 0.0;
2132  
# Line 1047 | Line 2171 | OSUAnalysis::valueLookup (const BNtau* o
2171    else if(variable == "leadingTrackValid") value = object->leadingTrackValid;
2172  
2173  
2174 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2174 >
2175 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2176 >
2177 >  else if(variable == "genMatchedPdgId"){
2178 >    int index = getGenMatchedParticleIndex(object);
2179 >    if(index == -1) value = 0;
2180 >    else value = mcparticles->at(index).id;
2181 >  }
2182 >
2183 >  else if(variable == "genMatchedId"){
2184 >    int index = getGenMatchedParticleIndex(object);
2185 >    if(index == -1) value = 0;
2186 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2187 >  }
2188 >  else if(variable == "genMatchedMotherId"){
2189 >    int index = getGenMatchedParticleIndex(object);
2190 >    if(index == -1) value = 0;
2191 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2192 >  }
2193 >  else if(variable == "genMatchedMotherIdReverse"){
2194 >    int index = getGenMatchedParticleIndex(object);
2195 >    if(index == -1) value = 24;
2196 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2197 >  }
2198 >  else if(variable == "genMatchedGrandmotherId"){
2199 >    int index = getGenMatchedParticleIndex(object);
2200 >    if(index == -1) value = 0;
2201 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2202 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2203 >      if(motherIndex == -1) value = 0;
2204 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2205 >    }
2206 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2207 >  }
2208 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2209 >    int index = getGenMatchedParticleIndex(object);
2210 >    if(index == -1) value = 24;
2211 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2212 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2213 >      if(motherIndex == -1) value = 24;
2214 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2215 >    }
2216 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2217 >  }
2218 >
2219 >
2220 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2221  
2222    value = applyFunction(function, value);
2223  
2224    return value;
2225   }
2226  
2227 + //!met valueLookup
2228   double
2229 < OSUAnalysis::valueLookup (const BNmet* object, string variable, string function){
2229 > OSUAnalysis::valueLookup (const BNmet* object, string variable, string function, string &stringValue){
2230  
2231    double value = 0.0;
2232  
# Line 1119 | Line 2290 | OSUAnalysis::valueLookup (const BNmet* o
2290    else if(variable == "pfT1jet10pt") value = object->pfT1jet10pt;
2291    else if(variable == "pfT1jet10phi") value = object->pfT1jet10phi;
2292  
2293 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2293 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2294  
2295    value = applyFunction(function, value);
2296  
2297    return value;
2298   }
2299  
2300 + //!track valueLookup
2301   double
2302 < OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function){
2302 > OSUAnalysis::valueLookup (const BNtrack* object, string variable, string function, string &stringValue){
2303  
2304    double value = 0.0;
2305 +  double pMag = sqrt(object->pt * object->pt +
2306 +                     object->pz * object->pz);
2307  
2308    if(variable == "pt") value = object->pt;
2309    else if(variable == "px") value = object->px;
# Line 1150 | Line 2324 | OSUAnalysis::valueLookup (const BNtrack*
2324    else if(variable == "isHighPurity") value = object->isHighPurity;
2325  
2326  
2327 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2327 >  //additional BNs info for disappTrks
2328 >  else if(variable == "caloEMDeltaRp3") value = object->caloEMDeltaRp3;
2329 >  else if(variable == "caloHadDeltaRp3") value = object->caloHadDeltaRp3;
2330 >  else if(variable == "caloEMDeltaRp4") value = object->caloEMDeltaRp4;
2331 >  else if(variable == "caloHadDeltaRp4") value = object->caloHadDeltaRp4;
2332 >  else if(variable == "caloEMDeltaRp5") value = object->caloEMDeltaRp5;
2333 >  else if(variable == "caloHadDeltaRp5") value = object->caloHadDeltaRp5;
2334 >  else if(variable == "nTracksRp5") value = object->nTracksRp5;
2335 >  else if(variable == "nHitsMissingOuter") value = object->nHitsMissingOuter;
2336 >  else if(variable == "nHitsMissingInner") value = object->nHitsMissingInner;
2337 >  else if(variable == "nHitsMissingMiddle") value = object->nHitsMissingMiddle;
2338 >  else if(variable == "depTrkRp5") value = object->depTrkRp5;
2339 >
2340 >  //user defined variables
2341 >  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;
2342 >  else if(variable == "dZwrtBS") value = object->dZ - events->at(0).BSz;
2343 >  else if(variable == "depTrkRp5MinusPt")           value =  (object->depTrkRp5 - object->pt);
2344 >  else if(variable == "caloTotDeltaRp5")            value =  (object->caloHadDeltaRp5 + object->caloEMDeltaRp5);
2345 >  else if(variable == "caloTotDeltaRp5ByP")         value = ((object->caloHadDeltaRp5 + object->caloEMDeltaRp5)/pMag);
2346 >  else if(variable == "caloTotDeltaRp5RhoCorr")     value = getTrkCaloTotRhoCorr(object);
2347 >  else if(variable == "caloTotDeltaRp5ByPRhoCorr")  value = getTrkCaloTotRhoCorr(object) / pMag;
2348 >  else if(variable == "isIso")                      value = getTrkIsIso(object, tracks.product());
2349 >  else if(variable == "isMatchedDeadEcal")          value = getTrkIsMatchedDeadEcal(object);
2350 >  else if(variable == "ptErrorByPt")                value = (object->ptError/object->pt);
2351 >  else if(variable == "ptError")                    value = object->ptError;
2352 >  else if(variable == "ptRes")                      value = getTrkPtRes(object);
2353 >  else if (variable == "d0wrtPV"){
2354 >    double vx = object->vx - chosenVertex ()->x,
2355 >      vy = object->vy - chosenVertex ()->y,
2356 >      px = object->px,
2357 >      py = object->py,
2358 >      pt = object->pt;
2359 >    value = (-vx * py + vy * px) / pt;
2360 >  }
2361 >  else if (variable == "dZwrtPV"){
2362 >    double vx = object->vx - chosenVertex ()->x,
2363 >      vy = object->vy - chosenVertex ()->y,
2364 >      vz = object->vz - chosenVertex ()->z,
2365 >      px = object->px,
2366 >      py = object->py,
2367 >      pz = object->pz,
2368 >      pt = object->pt;
2369 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2370 >  }
2371 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2372 >
2373 >  else if(variable == "genMatchedPdgId"){
2374 >    int index = getGenMatchedParticleIndex(object);
2375 >    if(index == -1) value = 0;
2376 >    else value = mcparticles->at(index).id;
2377 >  }
2378 >
2379 >
2380 >  else if(variable == "genMatchedId"){
2381 >    int index = getGenMatchedParticleIndex(object);
2382 >    if(index == -1) value = 0;
2383 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2384 >  }
2385 >  else if(variable == "genMatchedMotherId"){
2386 >    int index = getGenMatchedParticleIndex(object);
2387 >    if(index == -1) value = 0;
2388 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2389 >  }
2390 >  else if(variable == "genMatchedMotherIdReverse"){
2391 >    int index = getGenMatchedParticleIndex(object);
2392 >    if(index == -1) value = 24;
2393 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2394 >  }
2395 >  else if(variable == "genMatchedGrandmotherId"){
2396 >    int index = getGenMatchedParticleIndex(object);
2397 >    if(index == -1) value = 0;
2398 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2399 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2400 >      if(motherIndex == -1) value = 0;
2401 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2402 >    }
2403 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2404 >  }
2405 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2406 >    int index = getGenMatchedParticleIndex(object);
2407 >    if(index == -1) value = 24;
2408 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2409 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2410 >      if(motherIndex == -1) value = 24;
2411 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2412 >    }
2413 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2414 >  }
2415 >
2416 >
2417 >
2418 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2419  
2420    value = applyFunction(function, value);
2421  
2422    return value;
2423   }
2424  
2425 + //!genjet valueLookup
2426   double
2427 < OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function){
2427 > OSUAnalysis::valueLookup (const BNgenjet* object, string variable, string function, string &stringValue){
2428  
2429    double value = 0.0;
2430  
# Line 1178 | Line 2444 | OSUAnalysis::valueLookup (const BNgenjet
2444    else if(variable == "charge") value = object->charge;
2445  
2446  
2447 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2447 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2448  
2449    value = applyFunction(function, value);
2450  
2451    return value;
2452   }
2453  
2454 + //!mcparticle valueLookup
2455   double
2456 < OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function){
2456 > OSUAnalysis::valueLookup (const BNmcparticle* object, string variable, string function, string &stringValue){
2457  
2458    double value = 0.0;
2459  
# Line 1275 | Line 2542 | OSUAnalysis::valueLookup (const BNmcpart
2542    else if(variable == "grandMother11Status") value = object->grandMother11Status;
2543    else if(variable == "grandMother11Charge") value = object->grandMother11Charge;
2544  
2545 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2545 >  //user-defined variables
2546 >  else if (variable == "d0"){
2547 >    double vx = object->vx - chosenVertex ()->x,
2548 >      vy = object->vy - chosenVertex ()->y,
2549 >      px = object->px,
2550 >      py = object->py,
2551 >      pt = object->pt;
2552 >    value = (-vx * py + vy * px) / pt;
2553 >  }
2554 >  else if (variable == "dz"){
2555 >    double vx = object->vx - chosenVertex ()->x,
2556 >      vy = object->vy - chosenVertex ()->y,
2557 >      vz = object->vz - chosenVertex ()->z,
2558 >      px = object->px,
2559 >      py = object->py,
2560 >      pz = object->pz,
2561 >      pt = object->pt;
2562 >    value = vz - (vx * px + vy * py)/pt * (pz/pt);
2563 >  }
2564 >  else if(variable == "v0"){
2565 >    value = sqrt(object->vx*object->vx + object->vy*object->vy);
2566 >  }
2567 >  else if(variable == "deltaV0"){
2568 >    value = sqrt((object->vx-chosenVertex ()->x)*(object->vx-chosenVertex ()->x) + (object->vy-chosenVertex ()->y)*(object->vy-chosenVertex ()->y));
2569 >  }
2570 >  else if (variable == "deltaVx"){
2571 >    value = object->vx - chosenVertex ()->x;
2572 >  }
2573 >  else if (variable == "deltaVy"){
2574 >    value = object->vy - chosenVertex ()->y;
2575 >  }
2576 >  else if (variable == "deltaVz"){
2577 >    value = object->vz - chosenVertex ()->z;
2578 >  }
2579 >
2580 >
2581 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2582  
2583    value = applyFunction(function, value);
2584  
2585    return value;
2586   }
2587  
2588 + //!primaryvertex valueLookup
2589   double
2590 < OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function){
2590 > OSUAnalysis::valueLookup (const BNprimaryvertex* object, string variable, string function, string &stringValue){
2591  
2592    double value = 0.0;
2593  
# Line 1302 | Line 2606 | OSUAnalysis::valueLookup (const BNprimar
2606    else if(variable == "isGood") value = object->isGood;
2607  
2608  
2609 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2609 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2610  
2611    value = applyFunction(function, value);
2612  
2613    return value;
2614   }
2615  
2616 + //!bxlumi valueLookup
2617   double
2618 < OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function){
2618 > OSUAnalysis::valueLookup (const BNbxlumi* object, string variable, string function, string &stringValue){
2619  
2620    double value = 0.0;
2621  
# Line 1319 | Line 2624 | OSUAnalysis::valueLookup (const BNbxlumi
2624    else if(variable == "bx_LUMI_now") value = object->bx_LUMI_now;
2625  
2626  
2627 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2627 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2628  
2629    value = applyFunction(function, value);
2630  
2631    return value;
2632   }
2633  
2634 + //!photon valueLookup
2635   double
2636 < OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function){
2636 > OSUAnalysis::valueLookup (const BNphoton* object, string variable, string function, string &stringValue){
2637  
2638    double value = 0.0;
2639  
# Line 1402 | Line 2708 | OSUAnalysis::valueLookup (const BNphoton
2708    else if(variable == "seedRecoFlag") value = object->seedRecoFlag;
2709  
2710  
2711 <  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2711 >
2712 >
2713 >  else if(variable == "genDeltaRLowest") value = getGenDeltaRLowest(object);
2714 >
2715 >  else if(variable == "genMatchedPdgId"){
2716 >    int index = getGenMatchedParticleIndex(object);
2717 >    if(index == -1) value = 0;
2718 >    else value = mcparticles->at(index).id;
2719 >  }
2720 >
2721 >
2722 >
2723 >  else if(variable == "genMatchedId"){
2724 >    int index = getGenMatchedParticleIndex(object);
2725 >    if(index == -1) value = 0;
2726 >    else value = getPdgIdBinValue(mcparticles->at(index).id);
2727 >  }
2728 >  else if(variable == "genMatchedMotherId"){
2729 >    int index = getGenMatchedParticleIndex(object);
2730 >    if(index == -1) value = 0;
2731 >    else value = getPdgIdBinValue(mcparticles->at(index).motherId);
2732 >  }
2733 >  else if(variable == "genMatchedMotherIdReverse"){
2734 >    int index = getGenMatchedParticleIndex(object);
2735 >    if(index == -1) value = 24;
2736 >    else value = 24 -getPdgIdBinValue(mcparticles->at(index).motherId);
2737 >  }
2738 >  else if(variable == "genMatchedGrandmotherId"){
2739 >    int index = getGenMatchedParticleIndex(object);
2740 >    if(index == -1) value = 0;
2741 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2742 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2743 >      if(motherIndex == -1) value = 0;
2744 >      else value = getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2745 >    }
2746 >    else value = getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2747 >  }
2748 >  else if(variable == "genMatchedGrandmotherIdReverse"){
2749 >    int index = getGenMatchedParticleIndex(object);
2750 >    if(index == -1) value = 24;
2751 >    else if(fabs(mcparticles->at(index).motherId) == 15){
2752 >      int motherIndex = findTauMotherIndex(&mcparticles->at(index));
2753 >      if(motherIndex == -1) value = 24;
2754 >      else value = 24 - getPdgIdBinValue(mcparticles->at(motherIndex).motherId);
2755 >    }
2756 >    else value = 24 - getPdgIdBinValue(mcparticles->at(index).grandMotherId);
2757 >  }
2758 >
2759 >
2760 >  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2761  
2762    value = applyFunction(function, value);
2763  
2764    return value;
2765   }
2766  
2767 + //!supercluster valueLookup
2768   double
2769 < OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function){
2769 > OSUAnalysis::valueLookup (const BNsupercluster* object, string variable, string function, string &stringValue){
2770  
2771    double value = 0.0;
2772  
# Line 1424 | Line 2780 | OSUAnalysis::valueLookup (const BNsuperc
2780    else if(variable == "theta") value = object->theta;
2781  
2782  
2783 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2784 +
2785 +  value = applyFunction(function, value);
2786 +
2787 +  return value;
2788 + }
2789 +
2790 + //!trigobj valueLookup
2791 + double
2792 + OSUAnalysis::valueLookup (const BNtrigobj* object, string variable, string function, string &stringValue){
2793 +
2794 +  double value = 0.0;
2795 +
2796 +  if(variable == "pt") value = object->pt;
2797 +  else if(variable == "eta") value = object->eta;
2798 +  else if(variable == "phi") value = object->phi;
2799 +  else if(variable == "px") value = object->px;
2800 +  else if(variable == "py") value = object->py;
2801 +  else if(variable == "pz") value = object->pz;
2802 +  else if(variable == "et") value = object->et;
2803 +  else if(variable == "energy") value = object->energy;
2804 +  else if(variable == "etTotal") value = object->etTotal;
2805 +  else if(variable == "id") value = object->id;
2806 +  else if(variable == "charge") value = object->charge;
2807 +  else if(variable == "isIsolated") value = object->isIsolated;
2808 +  else if(variable == "isMip") value = object->isMip;
2809 +  else if(variable == "isForward") value = object->isForward;
2810 +  else if(variable == "isRPC") value = object->isRPC;
2811 +  else if(variable == "bx") value = object->bx;
2812 +  else if(variable == "filter") {
2813 +    if ((stringValue = object->filter) == "")
2814 +      stringValue = "none";  // stringValue should only be empty if value is filled
2815 +  }
2816 +
2817 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2818 +
2819 +  value = applyFunction(function, value);
2820 +
2821 +  return value;
2822 + }
2823 +
2824 + //!muon-muon pair valueLookup
2825 + double
2826 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNmuon* object2, string variable, string function, string &stringValue){
2827 +
2828 +  double value = 0.0;
2829 +
2830 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2831 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2832 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2833 +  else if(variable == "invMass"){
2834 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2835 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2836 +    value = (fourVector1 + fourVector2).M();
2837 +  }
2838 +  else if(variable == "pt"){
2839 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2840 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2841 +    value = (fourVector1 + fourVector2).Pt();
2842 +  }
2843 +  else if(variable == "threeDAngle")
2844 +    {
2845 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2846 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2847 +      value = (threeVector1.Angle(threeVector2));
2848 +    }
2849 +  else if(variable == "alpha")
2850 +    {
2851 +      static const double pi = 3.1415926535897932384626433832795028841971693993751058;
2852 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2853 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2854 +      value = (pi-threeVector1.Angle(threeVector2));
2855 +    }
2856 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2857 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2858 +  else if(variable == "d0Sign"){
2859 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2860 +    if(d0Sign < 0) value = -0.5;
2861 +    else if (d0Sign > 0) value = 0.5;
2862 +    else value = -999;
2863 +  }
2864 +  else if(variable == "chargeProduct"){
2865 +    value = object1->charge*object2->charge;
2866 +  }
2867 +  else if(variable == "muon1CorrectedD0Vertex"){
2868 +    value = object1->correctedD0Vertex;
2869 +  }
2870 +  else if(variable == "muon2CorrectedD0Vertex"){
2871 +    value = object2->correctedD0Vertex;
2872 +  }
2873 +  else if(variable == "muon1timeAtIpInOut"){
2874 +    value = object1->timeAtIpInOut;
2875 +  }
2876 +  else if(variable == "muon2timeAtIpInOut"){
2877 +    value = object2->timeAtIpInOut;
2878 +  }
2879 +  else if(variable == "muon1correctedD0")
2880 +    {
2881 +      value = object1->correctedD0;
2882 +    }
2883 +  else if(variable == "muon2correctedD0")
2884 +    {
2885 +      value = object2->correctedD0;
2886 +    }
2887 +
2888 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2889 +
2890 +  value = applyFunction(function, value);
2891 +
2892 +  return value;
2893 + }
2894 +
2895 + //!electron-electron pair valueLookup
2896 + double
2897 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNelectron* object2, string variable, string function, string &stringValue){
2898 +
2899 +  double value = 0.0;
2900 +
2901 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2902 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2903 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2904 +  else if(variable == "invMass"){
2905 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2906 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2907 +    value = (fourVector1 + fourVector2).M();
2908 +  }
2909 +  else if(variable == "pt"){
2910 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2911 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2912 +    value = (fourVector1 + fourVector2).Pt();
2913 +  }
2914 +  else if(variable == "threeDAngle")
2915 +    {
2916 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2917 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2918 +      value = (threeVector1.Angle(threeVector2));
2919 +    }
2920 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2921 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2922 +  else if(variable == "d0Sign"){
2923 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2924 +    if(d0Sign < 0) value = -0.5;
2925 +    else if (d0Sign > 0) value = 0.5;
2926 +    else value = -999;
2927 +  }
2928 +  else if(variable == "chargeProduct"){
2929 +    value = object1->charge*object2->charge;
2930 +  }
2931 +  else if(variable == "electron1CorrectedD0Vertex"){
2932 +    value = object1->correctedD0Vertex;
2933 +  }
2934 +  else if(variable == "electron2CorrectedD0Vertex"){
2935 +    value = object2->correctedD0Vertex;
2936 +  }
2937 +  else if(variable == "electron1CorrectedD0"){
2938 +    value = object1->correctedD0;
2939 +  }
2940 +  else if(variable == "electron2CorrectedD0"){
2941 +    value = object2->correctedD0;
2942 +  }
2943 +
2944 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
2945 +
2946 +  value = applyFunction(function, value);
2947 +
2948 +  return value;
2949 + }
2950 + //!electron-muon pair valueLookup
2951 + double
2952 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNmuon* object2, string variable, string function, string &stringValue){
2953 +
2954 +  double value = 0.0;
2955 +
2956 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
2957 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
2958 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
2959 +  else if(variable == "invMass"){
2960 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2961 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2962 +    value = (fourVector1 + fourVector2).M();
2963 +  }
2964 +  else if(variable == "pt"){
2965 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
2966 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
2967 +    value = (fourVector1 + fourVector2).Pt();
2968 +  }
2969 +  else if(variable == "threeDAngle")
2970 +    {
2971 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
2972 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
2973 +      value = (threeVector1.Angle(threeVector2));
2974 +    }
2975 +  else if(variable == "deltaCorrectedD0Vertex") value = object1->correctedD0Vertex - object2->correctedD0Vertex;
2976 +  else if(variable == "deltaAbsCorrectedD0Vertex") value = fabs(object1->correctedD0Vertex) - fabs(object2->correctedD0Vertex);
2977 +  else if(variable == "d0Sign"){
2978 +    double d0Sign = (object1->correctedD0Vertex*object2->correctedD0Vertex)/fabs(object1->correctedD0Vertex*object2->correctedD0Vertex);
2979 +    if(d0Sign < 0) value = -0.5;
2980 +    else if (d0Sign > 0) value = 0.5;
2981 +    else value = -999;
2982 +  }
2983 +  else if(variable == "chargeProduct"){
2984 +    value = object1->charge*object2->charge;
2985 +  }
2986 +  else if(variable == "electronCorrectedD0Vertex"){
2987 +    value = object1->correctedD0Vertex;
2988 +  }
2989 +  else if(variable == "muonCorrectedD0Vertex"){
2990 +    value = object2->correctedD0Vertex;
2991 +  }
2992 +  else if(variable == "electronCorrectedD0"){
2993 +    value = object1->correctedD0;
2994 +  }
2995 +  else if(variable == "muonCorrectedD0"){
2996 +    value = object2->correctedD0;
2997 +  }
2998 +  else if(variable == "electronDetIso"){
2999 +    value = (object1->trackIso) / object1->pt;
3000 +  }
3001 +  else if(variable == "muonDetIso"){
3002 +    value = (object2->trackIsoDR03) / object2->pt;
3003 +  }
3004 +  else if(variable == "electronRelPFrhoIso"){
3005 +    value = ( object1->chargedHadronIsoDR03 + max(0.0, object1->neutralHadronIsoDR03 + object1->photonIsoDR03 - object1->AEffDr03*object1->rhoPrime) ) / object1->pt;
3006 +  }
3007 +  else if(variable == "muonRelPFdBetaIso"){
3008 +    value = (object2->pfIsoR04SumChargedHadronPt + max(0.0, object2->pfIsoR04SumNeutralHadronEt + object2->pfIsoR04SumPhotonEt - 0.5*object2->pfIsoR04SumPUPt)) / object2->pt;
3009 +  }
3010 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3011 +  value = applyFunction(function, value);
3012 +
3013 +  return value;
3014 + }
3015 +
3016 + //!electron-jet pair valueLookup
3017 + double
3018 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNjet* object2, string variable, string function, string &stringValue){
3019 +
3020 +  double value = 0.0;
3021 +
3022 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3023 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3024 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3025 +  else if(variable == "invMass"){
3026 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3027 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3028 +    value = (fourVector1 + fourVector2).M();
3029 +  }
3030 +  else if(variable == "pt"){
3031 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3032 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3033 +    value = (fourVector1 + fourVector2).Pt();
3034 +  }
3035 +  else if(variable == "threeDAngle")
3036 +    {
3037 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3038 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3039 +      value = (threeVector1.Angle(threeVector2));
3040 +    }
3041 +  else if(variable == "chargeProduct"){
3042 +    value = object1->charge*object2->charge;
3043 +  }
3044 +
3045 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3046 +  value = applyFunction(function, value);
3047 +
3048 +  return value;
3049 + }
3050 +
3051 + //!muon-jet pair valueLookup
3052 + double
3053 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNjet* object2, string variable, string function, string &stringValue){
3054 +
3055 +  double value = 0.0;
3056 +
3057 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3058 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3059 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3060 +  else if(variable == "invMass"){
3061 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3062 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3063 +    value = (fourVector1 + fourVector2).M();
3064 +  }
3065 +  else if(variable == "pt"){
3066 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3067 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3068 +    value = (fourVector1 + fourVector2).Pt();
3069 +  }
3070 +  else if(variable == "threeDAngle")
3071 +    {
3072 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3073 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3074 +      value = (threeVector1.Angle(threeVector2));
3075 +    }
3076 +  else if(variable == "chargeProduct"){
3077 +    value = object1->charge*object2->charge;
3078 +  }
3079 +
3080 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3081 +  value = applyFunction(function, value);
3082 +
3083 +  return value;
3084 + }
3085 +
3086 + //!jet-jet pair valueLookup
3087 + double
3088 + OSUAnalysis::valueLookup (const BNjet* object1, const BNjet* object2, string variable, string function, string &stringValue){
3089 +
3090 +  double value = 0.0;
3091 +
3092 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3093 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3094 +  else if(variable == "absDeltaPt") value = fabs(object1->pt - object2->pt);
3095 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3096 +  else if(variable == "invMass"){
3097 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3098 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3099 +    value = (fourVector1 + fourVector2).M();
3100 +  }
3101 +  else if(variable == "pt"){
3102 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3103 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3104 +    value = (fourVector1 + fourVector2).Pt();
3105 +  }
3106 +  else if(variable == "threeDAngle")
3107 +    {
3108 +      TVector3 threeVector1(object1->px, object1->py, object1->pz);
3109 +      TVector3 threeVector2(object2->px, object2->py, object2->pz);
3110 +      value = (threeVector1.Angle(threeVector2));
3111 +    }
3112 +  else if(variable == "chargeProduct"){
3113 +    value = object1->charge*object2->charge;
3114 +  }
3115 +
3116 +  else{cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3117 +  value = applyFunction(function, value);
3118 +
3119 +  return value;
3120 + }
3121 + //!electron-track pair valueLookup
3122 + double
3123 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3124 +  double electronMass = 0.000511;
3125 +  double value = 0.0;
3126 +  TLorentzVector fourVector1(0, 0, 0, 0);
3127 +  TLorentzVector fourVector2(0, 0, 0, 0);
3128 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3129 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3130 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3131 +  else if(variable == "invMass"){
3132 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, electronMass);
3133 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, electronMass );
3134 +
3135 +    value = (fourVector1 + fourVector2).M();
3136 +  }
3137 +  else if(variable == "chargeProduct"){
3138 +    value = object1->charge*object2->charge;
3139 +  }
3140 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3141 +  value = applyFunction(function, value);
3142 +  return value;
3143 +
3144 + }
3145 +
3146 +
3147 + //!muon-track pair valueLookup
3148 + double
3149 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3150 +  double pionMass = 0.140;
3151 +  double muonMass = 0.106;
3152 +  double value = 0.0;
3153 +  TLorentzVector fourVector1(0, 0, 0, 0);
3154 +  TLorentzVector fourVector2(0, 0, 0, 0);
3155 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3156 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3157 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3158 +  else if(variable == "invMass"){
3159 +    fourVector1.SetPtEtaPhiM(object1->pt, object1->eta, object1->phi, muonMass);
3160 +    fourVector2.SetPtEtaPhiM(object2->pt, object2->eta, object2->phi, pionMass );
3161 +
3162 +    value = (fourVector1 + fourVector2).M();
3163 +  }
3164 +  else if(variable == "chargeProduct"){
3165 +    value = object1->charge*object2->charge;
3166 +  }
3167 +
3168 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3169 +  value = applyFunction(function, value);
3170 +  return value;
3171 + }
3172 +
3173 + //!tau-tau pair valueLookup
3174 + double
3175 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtau* object2, string variable, string function, string &stringValue){
3176 +  double value = 0.0;
3177 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3178 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3179 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3180 +  else if(variable == "invMass"){
3181 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3182 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3183 +    value = (fourVector1 + fourVector2).M();
3184 +  }
3185 +
3186 +  else if(variable == "chargeProduct"){
3187 +    value = object1->charge*object2->charge;
3188 +  }
3189 +
3190 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3191 +  value = applyFunction(function, value);
3192 +  return value;
3193 + }
3194 +
3195 + //!muon-tau pair valueLookup
3196 + double
3197 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtau* object2, string variable, string function, string &stringValue){
3198 +  double value = 0.0;
3199 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3200 +  else if(variable == "deltaEta") value = fabs(object1->eta - object2->eta);
3201 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3202 +  else if(variable == "invMass"){
3203 +    TLorentzVector fourVector1(object1->px, object1->py, object1->pz, object1->energy);
3204 +    TLorentzVector fourVector2(object2->px, object2->py, object2->pz, object2->energy);
3205 +    value = (fourVector1 + fourVector2).M();
3206 +  }
3207 +
3208 +  else if(variable == "chargeProduct"){
3209 +    value = object1->charge*object2->charge;
3210 +  }
3211 +
3212 +  else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3213 +  value = applyFunction(function, value);
3214 +  return value;
3215 + }
3216 +
3217 + //!tau-track pair valueLookup
3218 + double
3219 + OSUAnalysis::valueLookup (const BNtau* object1, const BNtrack* object2, string variable, string function, string &stringValue){
3220 +  double value = 0.0;
3221 +  if(variable == "deltaPhi") value = fabs(deltaPhi(object1->phi,object2->phi));
3222 +  else if(variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3223 +  else if(variable == "chargeProduct"){
3224 +    value = object1->charge*object2->charge;
3225 +  }
3226 +
3227    else{std::cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999;}
3228 +  value = applyFunction(function, value);
3229 +  return value;
3230 + }
3231 +
3232 +
3233 + //!track-event pair valueLookup
3234 + double
3235 + OSUAnalysis::valueLookup (const BNtrack* object1, const BNevent* object2, string variable, string function, string &stringValue){
3236 +
3237 +  double value = 0.0;
3238 +  double pMag = sqrt(object1->pt * object1->pt +
3239 +                     object1->pz * object1->pz);
3240 +
3241 +  if      (variable == "numPV")                      value = object2->numPV;
3242 +  else if (variable == "caloTotDeltaRp5")            value =  (object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5);
3243 +  else if (variable == "caloTotDeltaRp5ByP")         value = ((object1->caloHadDeltaRp5 + object1->caloEMDeltaRp5)/pMag);
3244 +  else if (variable == "caloTotDeltaRp5_RhoCorr")    value = getTrkCaloTotRhoCorr(object1);
3245 +  else if (variable == "caloTotDeltaRp5ByP_RhoCorr") value = getTrkCaloTotRhoCorr(object1) / pMag;
3246 +
3247 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3248 +
3249 +  value = applyFunction(function, value);
3250 +
3251 +  return value;
3252 +
3253 + }
3254 +
3255 + //!electron-trigobj pair valueLookup
3256 + double
3257 + OSUAnalysis::valueLookup (const BNelectron* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3258 +
3259 +  double value = 0.0;
3260 +
3261 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3262 +  else if (variable == "match"){
3263 +    if (deltaR(object1->eta,object1->phi,object2->eta,object2->phi) < 0.2 && abs(object2->id) == 11)
3264 +      stringValue = object2->filter;
3265 +    else
3266 +      stringValue = "none";
3267 +  }
3268 +
3269 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3270  
3271    value = applyFunction(function, value);
3272  
3273    return value;
3274 +
3275 + }
3276 +
3277 + //!muon-trigobj pair valueLookup
3278 + double
3279 + OSUAnalysis::valueLookup (const BNmuon* object1, const BNtrigobj* object2, string variable, string function, string &stringValue){
3280 +
3281 +  double value = 0.0;
3282 +
3283 +  if (variable == "deltaR") value = deltaR(object1->eta,object1->phi,object2->eta,object2->phi);
3284 +
3285 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3286 +
3287 +  value = applyFunction(function, value);
3288 +
3289 +  return value;
3290 +
3291 + }
3292 +
3293 + //!stop valueLookup
3294 + double
3295 + OSUAnalysis::valueLookup (const BNstop* object, string variable, string function, string &stringValue){
3296 +
3297 +
3298 +  double value = 0.0;
3299 +
3300 +  if(variable == "ctau") value = object->ctau;
3301 +
3302 +  else if (variable == "d0"){
3303 +    double vx = object->vx - chosenVertex ()->x,
3304 +      vy = object->vy - chosenVertex ()->y,
3305 +      px = object->px,
3306 +      py = object->py,
3307 +      pt = object->pt;
3308 +    value = (-vx * py + vy * px) / pt;
3309 +  }
3310 +
3311 +  else if (variable == "dz"){
3312 +    double vx = object->vx - chosenVertex ()->x,
3313 +      vy = object->vy - chosenVertex ()->y,
3314 +      vz = object->vz - chosenVertex ()->z,
3315 +      px = object->px,
3316 +      py = object->py,
3317 +      pz = object->pz,
3318 +      pt = object->pt;
3319 +    value = vz - (vx * px + vy * py)/pt * (pz/pt);
3320 +  }
3321 +
3322 +  else if (variable == "minD0"){
3323 +    double minD0=999;
3324 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3325 +      double vx = object->vx - vertex->x,
3326 +        vy = object->vy - vertex->y,
3327 +        px = object->px,
3328 +        py = object->py,
3329 +        pt = object->pt;
3330 +      value = (-vx * py + vy * px) / pt;
3331 +      if(abs(value) < abs(minD0)) minD0 = value;
3332 +    }
3333 +    value = minD0;
3334 +  }
3335 +  else if (variable == "minDz"){
3336 +    double minDz=999;
3337 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3338 +      double vx = object->vx - vertex->x,
3339 +        vy = object->vy - vertex->y,
3340 +        vz = object->vz - vertex->z,
3341 +        px = object->px,
3342 +        py = object->py,
3343 +        pz = object->pz,
3344 +        pt = object->pt;
3345 +      value = vz - (vx * px + vy * py)/pt * (pz/pt);
3346 +      if(abs(value) < abs(minDz)) minDz = value;
3347 +    }
3348 +    value = minDz;
3349 +  }
3350 +  else if(variable == "distToVertex"){
3351 +    value = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3352 +                 (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3353 +                 (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3354 +  }
3355 +  else if (variable == "minDistToVertex"){
3356 +    double minDistToVertex=999;
3357 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3358 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3359 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3360 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3361 +
3362 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3363 +    }
3364 +    value = minDistToVertex;
3365 +  }
3366 +  else if (variable == "distToVertexDifference"){
3367 +    double minDistToVertex=999;
3368 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3369 +      value = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3370 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3371 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3372 +
3373 +      if(abs(value) < abs(minDistToVertex)) minDistToVertex = value;
3374 +    }
3375 +    double distToChosenVertex = sqrt((object->vx-chosenVertex()->x)*(object->vx-chosenVertex()->x) + \
3376 +                                     (object->vy-chosenVertex()->y)*(object->vy-chosenVertex()->y) + \
3377 +                                     (object->vz-chosenVertex()->z)*(object->vz-chosenVertex()->z));
3378 +
3379 +    value = distToChosenVertex - minDistToVertex;
3380 +  }
3381 +
3382 +  else if (variable == "closestVertexRank"){
3383 +    double minDistToVertex=999;
3384 +    int vertex_rank = 0;
3385 +    for(BNprimaryvertexCollection::const_iterator vertex = primaryvertexs->begin (); vertex != primaryvertexs->end (); vertex++){
3386 +      vertex_rank++;
3387 +      int dist = sqrt((object->vx-vertex->x)*(object->vx-vertex->x) + \
3388 +                   (object->vy-vertex->y)*(object->vy-vertex->y) + \
3389 +                   (object->vz-vertex->z)*(object->vz-vertex->z));
3390 +
3391 +      if(abs(dist) < abs(minDistToVertex)){
3392 +        value = vertex_rank;
3393 +        minDistToVertex = dist;
3394 +      }
3395 +    }
3396 +  }
3397 +
3398 +
3399 +
3400 +
3401 +  else { cout << "WARNING: invalid variable '" << variable << "'\n"; value = -999; }
3402 +
3403 +  value = applyFunction(function, value);
3404 +
3405 +  return value;
3406 +
3407 + }
3408 +
3409 +
3410 +
3411 +
3412 + // Calculate the number of tracks in cone of DeltaR<0.5 around track1.
3413 + // Return true iff no other tracks are found in this cone.
3414 + int
3415 + OSUAnalysis::getTrkIsIso (const BNtrack* track1, const BNtrackCollection* trackColl){
3416 +  for(BNtrackCollection::const_iterator track2 = trackColl->begin(); track2 !=trackColl->end(); track2++){
3417 +    if(track1->eta == track2->eta && track1->phi == track2->phi) continue; // Do not compare the track to itself.
3418 +    double deltaRtrk = deltaR(track1->eta, track1->phi, track2->eta, track2->phi);
3419 +    if(deltaRtrk < 0.5) return 0;
3420 +  }
3421 +  return 1;
3422 +
3423 + }
3424 +
3425 +
3426 + double
3427 + OSUAnalysis::getTrkPtRes (const BNtrack* track1){
3428 +
3429 +  double ptTrue = getTrkPtTrue(track1, mcparticles.product());
3430 +  double PtRes = (track1->pt - ptTrue) / ptTrue;
3431 +
3432 +  return PtRes;
3433 +
3434 + }
3435 +
3436 +
3437 + double
3438 + OSUAnalysis::getTrkPtTrue (const BNtrack* track1, const BNmcparticleCollection* genPartColl){
3439 +  double value = -99;
3440 +  double genDeltaRLowest = 999;
3441 +
3442 +  for (BNmcparticleCollection::const_iterator genPart = genPartColl->begin(); genPart !=genPartColl->end(); genPart++){
3443 +    double genDeltaRtemp = deltaR(genPart->eta, genPart->phi,track1->eta, track1->phi);
3444 +    if (genDeltaRtemp < genDeltaRLowest) {
3445 +      genDeltaRLowest = genDeltaRtemp;
3446 +      if (genDeltaRLowest < 0.05) {   // Only consider it truth-matched if DeltaR<0.15.
3447 +        double ptTrue = genPart->pt;
3448 +        value = ptTrue;
3449 +      }
3450 +    }
3451 +  }
3452 +
3453 +  return value;
3454 +
3455 + }
3456 +
3457 + double
3458 + OSUAnalysis::getTrkCaloTotRhoCorr(const BNtrack* track) {
3459 +  // Return the pile-up (rho) corrected isolation energy, i.e., the total calorimeter energy around the candidate track.
3460 +  if (!useTrackCaloRhoCorr_) return -99;
3461 +  // if (!rhokt6CaloJetsHandle_) {
3462 +  //   cout << "ERROR [getTrkCaloTotRhoCorr]:  The collection rhokt6CaloJetsHandle is not available!" << endl;
3463 +  //   return -99;
3464 +  // }
3465 +  double radDeltaRCone = 0.5;
3466 +  double rhoCorr_kt6CaloJets = *rhokt6CaloJetsHandle_ * TMath::Pi() * pow(radDeltaRCone, 2);  // Define effective area as pi*r^2, where r is radius of DeltaR cone.
3467 +  double rawCaloTot = track->caloHadDeltaRp5 + track->caloEMDeltaRp5;
3468 +  double caloTotRhoCorrCalo = TMath::Max(0., rawCaloTot - rhoCorr_kt6CaloJets);
3469 +  return caloTotRhoCorrCalo;
3470 +
3471 + }
3472 +
3473 +
3474 +
3475 +
3476 + //creates a map of the dead Ecal channels in the barrel and endcap
3477 + //to see how the map of dead Ecal channels is created look at function getChannelStatusMaps() here:
3478 + //http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/jbrinson/DisappTrk/OSUT3Analysis/AnaTools/src/OSUAnalysis.cc?revision=1.88&view=markup
3479 + void
3480 + OSUAnalysis::WriteDeadEcal (){
3481 +  double etaEcal, phiEcal;
3482 +  ifstream DeadEcalFile(deadEcalFile_);
3483 +  if(!DeadEcalFile) {
3484 +    cout << "Error: DeadEcalFile has not been found." << endl;
3485 +    return;
3486 +  }
3487 +  if(DeadEcalVec.size()!= 0){
3488 +    cout << "Error: DeadEcalVec has a nonzero size" << endl;
3489 +    return;
3490 +  }
3491 +  while(!DeadEcalFile.eof())
3492 +    {
3493 +      DeadEcalFile >> etaEcal >> phiEcal;
3494 +      DeadEcal newChan;
3495 +      newChan.etaEcal = etaEcal;
3496 +      newChan.phiEcal = phiEcal;
3497 +      DeadEcalVec.push_back(newChan);
3498 +    }
3499 +  if(DeadEcalVec.size() == 0) cout << "Warning: No dead Ecal channels have been found." << endl;
3500 + }
3501 +
3502 + //if a track is found within dR<0.05 of a dead Ecal channel value = 1, otherwise value = 0
3503 + int
3504 + OSUAnalysis::getTrkIsMatchedDeadEcal (const BNtrack* track1){
3505 +  double deltaRLowest = 999;
3506 +  int value = 0;
3507 +  if (DeadEcalVec.size() == 0) WriteDeadEcal();
3508 +  for(vector<DeadEcal>::const_iterator ecal = DeadEcalVec.begin(); ecal != DeadEcalVec.end(); ++ecal){
3509 +    double eta = ecal->etaEcal;
3510 +    double phi = ecal->phiEcal;
3511 +    double deltaRtemp = deltaR(eta, phi, track1->eta, track1->phi);
3512 +    if(deltaRtemp < deltaRLowest) deltaRLowest = deltaRtemp;
3513 +  }
3514 +  if (deltaRLowest<0.05) {value = 1;}
3515 +  else {value = 0;}
3516 +  return value;
3517   }
3518  
3519 + // Returns the smallest DeltaR between the object and any generated true particle in the event.
3520 + template <class InputObject>
3521 + double OSUAnalysis::getGenDeltaRLowest(InputObject object){
3522 +  double genDeltaRLowest = 999.;
3523 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3524 +    double deltaRtemp = deltaR(mcparticle->eta, mcparticle->phi, object->eta, object->phi);
3525 +    if (deltaRtemp < genDeltaRLowest) genDeltaRLowest = deltaRtemp;
3526 +  }
3527 +  return genDeltaRLowest;
3528 + }
3529  
3530   double
3531   OSUAnalysis::applyFunction(string function, double value){
3532  
3533 <  if(function == "abs") value = abs(value);
3533 >  if(function == "abs") value = fabs(value);
3534 >  else if(function == "fabs") value = fabs(value);
3535 >  else if(function == "log10") value = log10(value);
3536 >  else if(function == "log") value = log10(value);
3537  
3538 +  else if(function == "") value = value;
3539 +  else{cout << "WARNING: invalid function '" << function << "'\n";}
3540  
3541    return value;
3542  
# Line 1446 | Line 3546 | OSUAnalysis::applyFunction(string functi
3546   template <class InputCollection>
3547   void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, InputCollection inputCollection, string inputType){
3548  
3549 +  if (currentCut.inputCollection.find("pair")!=string::npos)  {
3550 +    string obj1, obj2;
3551 +    getTwoObjs(currentCut.inputCollection, obj1, obj2);
3552 +    if (inputType==obj1 ||
3553 +          inputType==obj2) {
3554 +      // Do not add a cut to individualFlags or cumulativeFlags, if the cut is on a paired collection,
3555 +      // and the inputType is a member of the pair.
3556 +      // The cut will instead be applied when the setObjectFlags() is called for the paired collection.
3557 +      // For example, if currentCut.inputCollection==electron-muon pairs,
3558 +      // then the flags should not be set here when inputType==muons or inputType==electrons.
3559 +      return;
3560 +    }
3561 +  }
3562  
3563    for (uint object = 0; object != inputCollection->size(); object++){
3564  
# Line 1453 | Line 3566 | void OSUAnalysis::setObjectFlags(cut &cu
3566  
3567      if(currentCut.inputCollection == inputType){
3568  
3569 <      double value = valueLookup(&inputCollection->at(object), currentCut.variable, currentCut.function);
3569 >      vector<bool> subcutDecisions;
3570 >      for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3571 >        string stringValue = "";
3572 >        double value = valueLookup(&inputCollection->at(object), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3573 >        if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3574 >        else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3575  
3576 <      decision = evaluateComparison(value,currentCut.comparativeOperator,currentCut.cutValue);
3576 >      }
3577 >      if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3578 >      else{
3579 >        bool tempDecision = true;
3580 >        for( int subcutIndex = 0;subcutIndex != currentCut.numSubcuts-1; subcutIndex++){
3581 >          if(currentCut.logicalOperators.at(subcutIndex) == "&" || currentCut.logicalOperators.at(subcutIndex) == "&&")
3582 >            tempDecision = subcutDecisions.at(subcutIndex) && subcutDecisions.at(subcutIndex+1);
3583 >          else if(currentCut.logicalOperators.at(subcutIndex) == "|"|| currentCut.logicalOperators.at(subcutIndex) == "||")
3584 >            tempDecision = subcutDecisions.at(subcutIndex) || subcutDecisions.at(subcutIndex+1);
3585 >        }
3586 >        decision = tempDecision;
3587 >      }
3588      }
1460    individualFlags[inputType].at(currentCutIndex).push_back(decision);
3589  
3590 +    individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3591  
3592      //set flags for objects that pass each cut AND all the previous cuts
3593      bool previousCumulativeFlag = true;
3594      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3595 <      if(previousCumulativeFlag && individualFlags[inputType].at(previousCutIndex).at(object)) previousCumulativeFlag = true;
3595 >      if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(object)) previousCumulativeFlag = true;
3596        else{ previousCumulativeFlag = false; break;}
3597      }
3598 <    cumulativeFlags[inputType].at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3598 >    cumulativeFlags.at(inputType).at(currentCutIndex).push_back(previousCumulativeFlag && decision);
3599  
3600    }
3601  
3602   }
3603  
3604  
3605 + template <class InputCollection1, class InputCollection2>
3606 + void OSUAnalysis::setObjectFlags(cut &currentCut, uint currentCutIndex, flagMap &individualFlags, flagMap &cumulativeFlags, \
3607 +                                 InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, string inputType){
3608 +
3609 +
3610 +  bool sameObjects = false;
3611 +  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3612 +
3613 +  // Get the strings for the two objects that make up the pair.
3614 +  string obj1Type, obj2Type;
3615 +  getTwoObjs(inputType, obj1Type, obj2Type);
3616 +  bool isTwoTypesOfObject = true;
3617 +  if (obj1Type==obj2Type) isTwoTypesOfObject = false;
3618 +
3619 +  // Initialize the flags for individual objects to all be false, if the cut is on the pair.
3620 +  // Set them to true later, if any paired object passes (in which case both of its constituents should pass).
3621 +  if (currentCut.inputCollection == inputType) {
3622 +    for (uint object1 = 0; object1 != inputCollection1->size(); object1++) {
3623 +      individualFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3624 +      cumulativeFlags.at(obj1Type).at(currentCutIndex).push_back(false);
3625 +    }
3626 +    if (isTwoTypesOfObject) { // Only initialize the second object if it is different from the first.
3627 +      for (uint object2 = 0; object2 != inputCollection2->size(); object2++)  {
3628 +        individualFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3629 +        cumulativeFlags.at(obj2Type).at(currentCutIndex).push_back(false);
3630 +      }
3631 +    }
3632 +  }
3633  
3634 +  int counter = 0;
3635  
3636 +  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3637 +    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3638  
3639 < DEFINE_FWK_MODULE(OSUAnalysis);
3639 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3640 >
3641 >
3642 >      bool decision = true;//object passes if this cut doesn't cut on that type of object
3643 >
3644 >      if(currentCut.inputCollection == inputType){
3645 >
3646 >        vector<bool> subcutDecisions;
3647 >        for( int subcutIndex = 0; subcutIndex != currentCut.numSubcuts; subcutIndex++){
3648 >          string stringValue = "";
3649 >          double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), currentCut.variables.at(subcutIndex), currentCut.functions.at(subcutIndex), stringValue);
3650 >          if (stringValue == "") subcutDecisions.push_back(evaluateComparison(value,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutValues.at(subcutIndex)));
3651 >          else subcutDecisions.push_back(evaluateComparison(stringValue,currentCut.comparativeOperators.at(subcutIndex),currentCut.cutStringValues.at(subcutIndex)));
3652 >        }
3653 >
3654 >        if(currentCut.numSubcuts == 1) decision = subcutDecisions.at(0);
3655 >        else{
3656 >          bool tempDecision = subcutDecisions.at(0);
3657 >          for( int subcutIndex = 1; subcutIndex < currentCut.numSubcuts; subcutIndex++){
3658 >            if(currentCut.logicalOperators.at(subcutIndex-1) == "&" || currentCut.logicalOperators.at(subcutIndex-1) == "&&")
3659 >              tempDecision = tempDecision && subcutDecisions.at(subcutIndex);
3660 >            else if(currentCut.logicalOperators.at(subcutIndex-1) == "|"|| currentCut.logicalOperators.at(subcutIndex-1) == "||")
3661 >              tempDecision = tempDecision || subcutDecisions.at(subcutIndex);
3662 >          }
3663 >          decision = tempDecision;
3664 >        }
3665 >      }
3666 >      // if (decision) isPassObj1.at(object1) = true;
3667 >      // if (decision) isPassObj2.at(object2) = true;
3668 >      individualFlags.at(inputType).at(currentCutIndex).push_back(decision);
3669 >      if (decision && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3670 >        individualFlags.at(obj1Type).at(currentCutIndex).at(object1) = true;
3671 >        individualFlags.at(obj2Type).at(currentCutIndex).at(object2) = true;
3672 >      }
3673 >
3674 >      //set flags for objects that pass each cut AND all the previous cuts
3675 >      bool previousCumulativeFlag = true;
3676 >      for(uint previousCutIndex = 0; previousCutIndex != currentCutIndex; previousCutIndex++){
3677 >        if(previousCumulativeFlag && individualFlags.at(inputType).at(previousCutIndex).at(counter)) previousCumulativeFlag = true;
3678 >        else{ previousCumulativeFlag = false; break;}
3679 >      }
3680 >      //apply flags for the components of the composite object as well
3681 >      bool currentCumulativeFlag = true;
3682 >      if(flags1.size() == 0 && flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision;
3683 >      else if(flags1.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags2.at(object2);
3684 >      else if(flags2.size() == 0) currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1);
3685 >      else currentCumulativeFlag = previousCumulativeFlag && decision && flags1.at(object1) && flags2.at(object2);
3686 >      cumulativeFlags.at(inputType).at(currentCutIndex).push_back(currentCumulativeFlag);
3687 >      if (currentCumulativeFlag && currentCut.inputCollection == inputType) {  // only set the flags for the individual objects if the pair object is being cut on
3688 >        cumulativeFlags.at(obj1Type).at(currentCutIndex).at(object1) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj1Type, object1);
3689 >        cumulativeFlags.at(obj2Type).at(currentCutIndex).at(object2) = true && getPreviousCumulativeFlags(currentCutIndex, individualFlags, obj2Type, object2);
3690 >      }
3691 >      counter++;
3692 >
3693 >    } // end   for (uint object2 = 0; object2 != inputCollection2->size(); object2++)
3694 >  }  // end   for (uint object1 = 0; object1 != inputCollection1->size(); object1++)
3695 >
3696 > }
3697 >
3698 >
3699 > bool OSUAnalysis::getPreviousCumulativeFlags(uint currentCutIndex, flagMap &individualFlags, string obj1Type, uint object1) {
3700 >  // Return true iff for the collection obj1Type, the element with index object1 has individal flags set to true for
3701 >  // all cuts up to currentCutIndex
3702 >  bool previousCumulativeFlag = true;
3703 >  for (uint previousCutIndex = 0; previousCutIndex < currentCutIndex; previousCutIndex++) {
3704 >    if (previousCumulativeFlag && individualFlags.at(obj1Type).at(previousCutIndex).at(object1)) previousCumulativeFlag = true;
3705 >    else {
3706 >      previousCumulativeFlag = false; break;
3707 >    }
3708 >  }
3709 >  return previousCumulativeFlag;
3710 > }
3711 >
3712 >
3713 > template <class InputCollection>
3714 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3715 >
3716 >  for (uint object = 0; object != inputCollection->size(); object++){
3717 >
3718 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3719 >
3720 >    string currentString = parameters.inputVariables.at(0);
3721 >    string inputVariable = "";
3722 >    string function = "";
3723 >    if(currentString.find("(")==string::npos){
3724 >      inputVariable = currentString;// variable to cut on
3725 >    }
3726 >    else{
3727 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3728 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3729 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3730 >    }
3731 >
3732 >    string stringValue = "";
3733 >    double value = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3734 >    histo->Fill(value,scaleFactor);
3735 >    if (printEventInfo_) {
3736 >      // Write information about event to screen, for testing purposes.
3737 >      cout << "  Info for event:  value for histogram " << histo->GetName() << ":  " << value << endl;
3738 >    }
3739 >
3740 >  }
3741 > }
3742 >
3743 > template <class InputCollection1, class InputCollection2>
3744 > void OSUAnalysis::fill1DHistogram(TH1* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3745 >
3746 >  bool sameObjects = false;
3747 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3748 >
3749 >  int pairCounter = -1;
3750 >  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3751 >    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3752 >
3753 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3754 >
3755 >      pairCounter++;
3756 >      //only take objects which have passed all cuts and pairs which have passed all cuts
3757 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3758 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3759 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3760 >
3761 >      string currentString = parameters.inputVariables.at(0);
3762 >      string inputVariable = "";
3763 >      string function = "";
3764 >      if(currentString.find("(")==string::npos){
3765 >        inputVariable = currentString;// variable to cut on
3766 >      }
3767 >      else{
3768 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3769 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3770 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3771 >      }
3772 >
3773 >      string stringValue = "";
3774 >      double value = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3775 >      histo->Fill(value,scaleFactor);
3776 >
3777 >    }
3778 >  }
3779 >
3780 > }
3781 >
3782 >
3783 > template <class InputCollection>
3784 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection inputCollection,vector<bool> flags, double scaleFactor){
3785 >
3786 >  for (uint object = 0; object != inputCollection->size(); object++){
3787 >
3788 >    if(!plotAllObjectsInPassingEvents_ && !flags.at(object)) continue;
3789 >
3790 >    string stringValue = "";
3791 >    string currentString = parameters.inputVariables.at(0);
3792 >    string inputVariable = "";
3793 >    string function = "";
3794 >    if(currentString.find("(")==string::npos){
3795 >      inputVariable = currentString;// variable to cut on
3796 >    }
3797 >    else{
3798 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3799 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3800 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3801 >    }
3802 >    double valueX = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3803 >
3804 >    currentString = parameters.inputVariables.at(1);
3805 >    inputVariable = "";
3806 >    function = "";
3807 >    if(currentString.find("(")==string::npos){
3808 >      inputVariable = currentString;// variable to cut on
3809 >    }
3810 >    else{
3811 >      function = currentString.substr(0,currentString.find("("));//function comes before the "("
3812 >      inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3813 >      inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3814 >    }
3815 >
3816 >    double valueY = valueLookup(&inputCollection->at(object), inputVariable, function, stringValue);
3817 >
3818 >    histo->Fill(valueX,valueY,scaleFactor);
3819 >
3820 >  }
3821 >
3822 > }
3823 >
3824 > template <class InputCollection1, class InputCollection2>
3825 > void OSUAnalysis::fill2DHistogram(TH2* histo, histogram parameters, InputCollection1 inputCollection1, InputCollection2 inputCollection2, vector<bool> flags1, vector<bool> flags2, vector<bool> pairFlags, double scaleFactor){
3826 >
3827 >  bool sameObjects = false;
3828 >  if(typeid(InputCollection1).name() == typeid(InputCollection2).name()) sameObjects = true;
3829 >
3830 >  int pairCounter = -1;
3831 >  for (uint object1 = 0; object1 != inputCollection1->size(); object1++){
3832 >    for (uint object2 = 0; object2 != inputCollection2->size(); object2++){
3833 >
3834 >      if(sameObjects && object1 >= object2) continue;//account for duplicate pairs if both collections are the same
3835 >
3836 >      pairCounter++;
3837 >
3838 >      //only take objects which have passed all cuts and pairs which have passed all cuts
3839 >      if(!plotAllObjectsInPassingEvents_ && !flags1.at(object1)) continue;
3840 >      if(!plotAllObjectsInPassingEvents_ && !flags2.at(object2)) continue;
3841 >      if(!plotAllObjectsInPassingEvents_ && !pairFlags.at(pairCounter)) continue;
3842 >
3843 >      string stringValue = "";
3844 >      string currentString = parameters.inputVariables.at(0);
3845 >      string inputVariable = "";
3846 >      string function = "";
3847 >      if(currentString.find("(")==string::npos){
3848 >        inputVariable = currentString;// variable to cut on
3849 >      }
3850 >      else{
3851 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3852 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3853 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3854 >      }
3855 >      double valueX = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3856 >
3857 >      currentString = parameters.inputVariables.at(1);
3858 >      inputVariable = "";
3859 >      function = "";
3860 >      if(currentString.find("(")==string::npos){
3861 >        inputVariable = currentString;// variable to cut on
3862 >      }
3863 >      else{
3864 >        function = currentString.substr(0,currentString.find("("));//function comes before the "("
3865 >        inputVariable = currentString.substr(currentString.find("(")+1);//get rest of string
3866 >        inputVariable = inputVariable.substr(0,inputVariable.size()-1);//remove trailing ")"
3867 >      }
3868 >      double valueY = valueLookup(&inputCollection1->at(object1), &inputCollection2->at(object2), inputVariable, function, stringValue);
3869  
3870  
3871 +      histo->Fill(valueX,valueY,scaleFactor);
3872 +
3873 +    }
3874 +  }
3875 +
3876 + }
3877 +
3878 +
3879 + template <class InputObject>
3880 + int OSUAnalysis::getGenMatchedParticleIndex(InputObject object){
3881 +
3882 +  int bestMatchIndex = -1;
3883 +  double bestMatchDeltaR = 999;
3884 +
3885 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3886 +
3887 +    double currentDeltaR = deltaR(object->eta,object->phi,mcparticle->eta,mcparticle->phi);
3888 +    if(currentDeltaR > 0.05) continue;
3889 +    //     cout << setprecision(3) << setw(20)
3890 +    //          << "\tcurrentParticle:  eta = " << mcparticles->at(mcparticle - mcparticles->begin()).eta
3891 +    //          << setw(20)
3892 +    //          << "\tphi = " << mcparticles->at(mcparticle - mcparticles->begin()).phi
3893 +    //          << setw(20)
3894 +    //          << "\tdeltaR = " << currentDeltaR
3895 +    //          << setprecision(1)
3896 +    //          << setw(20)
3897 +    //          << "\tid = " << mcparticles->at(mcparticle - mcparticles->begin()).id
3898 +    //          << setw(20)
3899 +    //          << "\tmotherId = " << mcparticles->at(mcparticle - mcparticles->begin()).motherId
3900 +    //          << setw(20)
3901 +    //          << "\tstatus = " << mcparticles->at(mcparticle - mcparticles->begin()).status<< endl;
3902 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
3903 +      bestMatchIndex = mcparticle - mcparticles->begin();
3904 +      bestMatchDeltaR = currentDeltaR;
3905 +    }
3906 +
3907 +  }
3908 +  //   if(bestMatchDeltaR != 999)  cout << "bestMatch:  deltaR = " << bestMatchDeltaR << "   id = " << mcparticles->at(bestMatchIndex).id << "   motherId = " << mcparticles->at(bestMatchIndex).motherId << endl;
3909 +  //   else cout << "no match found..." << endl;
3910 +  return bestMatchIndex;
3911 +
3912 + }
3913 +
3914 +
3915 + int OSUAnalysis::findTauMotherIndex(const BNmcparticle* tau){
3916 +
3917 +  int bestMatchIndex = -1;
3918 +  double bestMatchDeltaR = 999;
3919 +
3920 +  for(BNmcparticleCollection::const_iterator mcparticle = mcparticles->begin (); mcparticle != mcparticles->end (); mcparticle++){
3921 +
3922 +    if(fabs(mcparticle->id) != 15 || mcparticle->status !=3) continue;
3923 +
3924 +    double currentDeltaR = deltaR(tau->eta,tau->phi,mcparticle->eta,mcparticle->phi);
3925 +    if(currentDeltaR > 0.05) continue;
3926 +
3927 +    if(currentDeltaR < bestMatchDeltaR && mcparticles->at(mcparticle - mcparticles->begin()).id != mcparticles->at(mcparticle - mcparticles->begin()).motherId){
3928 +      bestMatchIndex = mcparticle - mcparticles->begin();
3929 +      bestMatchDeltaR = currentDeltaR;
3930 +    }
3931 +
3932 +  }
3933 +
3934 +  return bestMatchIndex;
3935 + }
3936 +
3937 +
3938 + // bin      particle type
3939 + // ---      -------------
3940 + //  0        unmatched
3941 + //  1        u
3942 + //  2        d
3943 + //  3        s
3944 + //  4        c
3945 + //  5        b
3946 + //  6        t
3947 + //  7        e
3948 + //  8        mu
3949 + //  9        tau
3950 + // 10        nu
3951 + // 11        g
3952 + // 12        gamma
3953 + // 13        Z
3954 + // 14        W
3955 + // 15        light meson
3956 + // 16        K meson
3957 + // 17        D meson
3958 + // 18        B meson
3959 + // 19        light baryon
3960 + // 20        strange baryon
3961 + // 21        charm baryon
3962 + // 22        bottom baryon
3963 + // 23        QCD string
3964 + // 24        other
3965 +
3966 + int OSUAnalysis::getPdgIdBinValue(int pdgId){
3967 +
3968 +  int binValue = -999;
3969 +  int absPdgId = fabs(pdgId);
3970 +  if(pdgId == -1) binValue = 0;
3971 +  else if(absPdgId <= 6 ) binValue = absPdgId;
3972 +  else if(absPdgId == 11 ) binValue = 7;
3973 +  else if(absPdgId == 13 ) binValue = 8;
3974 +  else if(absPdgId == 15 ) binValue = 9;
3975 +  else if(absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) binValue = 10;
3976 +  else if(absPdgId == 21 ) binValue = 11;
3977 +  else if(absPdgId == 22 ) binValue = 12;
3978 +  else if(absPdgId == 23 ) binValue = 13;
3979 +  else if(absPdgId == 24 ) binValue = 14;
3980 +  else if(absPdgId > 100 && absPdgId < 300 && absPdgId != 130  ) binValue = 15;
3981 +  else if( absPdgId == 130 || (absPdgId > 300 && absPdgId < 400)  ) binValue = 16;
3982 +  else if(absPdgId > 400 && absPdgId < 500  ) binValue = 17;
3983 +  else if(absPdgId > 500 && absPdgId < 600  ) binValue = 18;
3984 +  else if(absPdgId > 1000 && absPdgId < 3000  ) binValue = 19;
3985 +  else if(absPdgId > 3000 && absPdgId < 4000  ) binValue = 20;
3986 +  else if(absPdgId > 4000 && absPdgId < 5000  ) binValue = 21;
3987 +  else if(absPdgId > 5000 && absPdgId < 6000  ) binValue = 22;
3988 +  else if(absPdgId == 92  ) binValue = 23;
3989 +
3990 +  else binValue = 24;
3991 +
3992 +  return binValue;
3993 +
3994 + }
3995 +
3996 + const BNprimaryvertex *
3997 + OSUAnalysis::chosenVertex ()
3998 + {
3999 +  const BNprimaryvertex *chosenVertex = 0;
4000 +  if(cumulativeFlags.find ("primaryvertexs") != cumulativeFlags.end ()){
4001 +    vector<bool> vertexFlags;
4002 +    for (int i = cumulativeFlags.at("primaryvertexs").size() - 1; i >= 0; i--){
4003 +      if (cumulativeFlags.at("primaryvertexs").at(i).size()){
4004 +        vertexFlags = cumulativeFlags.at("primaryvertexs").at(i);
4005 +        break;
4006 +      }
4007 +    }
4008 +    for (uint vertexIndex = 0; vertexIndex != vertexFlags.size(); vertexIndex++){
4009 +      if(!vertexFlags.at(vertexIndex)) continue;
4010 +      chosenVertex = & primaryvertexs->at(vertexIndex);
4011 +      break;
4012 +    }
4013 +  }
4014 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "primaryvertexs") != objectsToGet.end ())
4015 +    chosenVertex = & primaryvertexs->at (0);
4016 +
4017 +  return chosenVertex;
4018 + }
4019 +
4020 + const BNmet *
4021 + OSUAnalysis::chosenMET ()
4022 + {
4023 +  const BNmet *chosenMET = 0;
4024 +  if(cumulativeFlags.find ("mets") != cumulativeFlags.end ()){
4025 +    vector<bool> metFlags;
4026 +    for (int i = cumulativeFlags.at("mets").size() - 1; i >= 0; i--){
4027 +      if (cumulativeFlags.at("mets").at(i).size()){
4028 +        metFlags = cumulativeFlags.at("mets").at(i);
4029 +        break;
4030 +      }
4031 +    }
4032 +    for (uint metIndex = 0; metIndex != metFlags.size(); metIndex++){
4033 +      if(!metFlags.at(metIndex)) continue;
4034 +      chosenMET = & mets->at(metIndex);
4035 +      break;
4036 +    }
4037 +  }
4038 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "mets") != objectsToGet.end ())
4039 +    chosenMET = & mets->at (0);
4040 +
4041 +  return chosenMET;
4042 + }
4043 +
4044 + const BNelectron *
4045 + OSUAnalysis::chosenElectron ()
4046 + {
4047 +  const BNelectron *chosenElectron = 0;
4048 +  if(cumulativeFlags.find ("electrons") != cumulativeFlags.end ()){
4049 +    vector<bool> electronFlags;
4050 +    for (int i = cumulativeFlags.at("electrons").size() - 1; i >= 0; i--){
4051 +      if (cumulativeFlags.at("electrons").at(i).size()){
4052 +        electronFlags = cumulativeFlags.at("electrons").at(i);
4053 +        break;
4054 +      }
4055 +    }
4056 +    for (uint electronIndex = 0; electronIndex != electronFlags.size(); electronIndex++){
4057 +      if(!electronFlags.at(electronIndex)) continue;
4058 +      chosenElectron = & electrons->at(electronIndex);
4059 +      break;
4060 +    }
4061 +  }
4062 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "electrons") != objectsToGet.end ())
4063 +    chosenElectron = & electrons->at (0);
4064 +
4065 +  return chosenElectron;
4066 + }
4067 +
4068 + const BNmuon *
4069 + OSUAnalysis::chosenMuon ()
4070 + {
4071 +  const BNmuon *chosenMuon = 0;
4072 +  if(cumulativeFlags.find ("muons") != cumulativeFlags.end ()){
4073 +    vector<bool> muonFlags;
4074 +    for (int i = cumulativeFlags.at("muons").size() - 1; i >= 0; i--){
4075 +      if (cumulativeFlags.at("muons").at(i).size()){
4076 +        muonFlags = cumulativeFlags.at("muons").at(i);
4077 +        break;
4078 +      }
4079 +    }
4080 +    for (uint muonIndex = 0; muonIndex != muonFlags.size(); muonIndex++){
4081 +      if(!muonFlags.at(muonIndex)) continue;
4082 +      chosenMuon = & muons->at(muonIndex);
4083 +      break;
4084 +    }
4085 +  }
4086 +  else if (find (objectsToGet.begin (), objectsToGet.end (), "muons") != objectsToGet.end ())
4087 +    chosenMuon = & muons->at (0);
4088 +
4089 +  return chosenMuon;
4090 + }
4091 +
4092 + DEFINE_FWK_MODULE(OSUAnalysis);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines