CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BTagPerformanceHarvester.cc
Go to the documentation of this file.
7 
8 using namespace edm;
9 using namespace std;
10 using namespace RecoBTag;
11 
13  etaRanges(pSet.getParameter< vector<double> >("etaRanges")),
14  ptRanges(pSet.getParameter< vector<double> >("ptRanges")),
15  produceEps(pSet.getParameter< bool >("produceEps")),
16  producePs(pSet.getParameter< bool >("producePs")),
17  moduleConfig(pSet.getParameter< vector<edm::ParameterSet> >("tagConfig")),
18  flavPlots_(pSet.getParameter< std::string >("flavPlots")),
19  makeDiffPlots_(pSet.getParameter< bool >("differentialPlots"))
20 {
21  //mcPlots_ : 1=b+c+l+ni; 2=all+1; 3=1+d+u+s+g; 4=3+all . Default is 2. Don't use 0.
22  if(flavPlots_.find("dusg")<15){
23  if(flavPlots_.find("all")<15) mcPlots_ = 4;
24  else mcPlots_ = 3;
25  }
26  else if(flavPlots_.find("bcl")<15){
27  if(flavPlots_.find("all")<15) mcPlots_ = 2;
28  else mcPlots_ = 1;
29  }
30  else mcPlots_ = 0;
31 
32  for (vector<edm::ParameterSet>::const_iterator iModule = moduleConfig.begin();
33  iModule != moduleConfig.end(); ++iModule) {
34  const string& dataFormatType = iModule->exists("type") ?
35  iModule->getParameter<string>("type") :
36  "JetTag";
37  if (dataFormatType == "JetTag") {
38  const InputTag& moduleLabel = iModule->getParameter<InputTag>("label");
39  jetTagInputTags.push_back(moduleLabel);
40  binJetTagPlotters.push_back(vector<JetTagPlotter*>()) ;
41  if (mcPlots_ && makeDiffPlots_){
42  differentialPlots.push_back(vector<BTagDifferentialPlot*>());
43  }
44  }
45  else if(dataFormatType == "TagCorrelation") {
46  const InputTag& label1 = iModule->getParameter<InputTag>("label1");
47  const InputTag& label2 = iModule->getParameter<InputTag>("label2");
48  tagCorrelationInputTags.push_back(std::pair<edm::InputTag, edm::InputTag>(label1, label2));
49  binTagCorrelationPlotters.push_back(vector<TagCorrelationPlotter*>());
50  }
51  else {
52  tagInfoInputTags.push_back(vector<edm::InputTag>());
53  tiDataFormatType.push_back(dataFormatType);
54  binTagInfoPlotters.push_back(vector<BaseTagInfoPlotter*>()) ;
55  }
56  }
57 
58 }
59 
60 EtaPtBin BTagPerformanceHarvester::getEtaPtBin(const int& iEta, const int& iPt)
61 {
62  // DEFINE BTagBin:
63  bool etaActive_ , ptActive_;
64  double etaMin_, etaMax_, ptMin_, ptMax_ ;
65 
66  if ( iEta != -1 ) {
67  etaActive_ = true ;
68  etaMin_ = etaRanges[iEta] ;
69  etaMax_ = etaRanges[iEta+1] ;
70  }
71  else {
72  etaActive_ = false ;
73  etaMin_ = etaRanges[0] ;
74  etaMax_ = etaRanges[etaRanges.size() - 1] ;
75  }
76 
77  if ( iPt != -1 ) {
78  ptActive_ = true ;
79  ptMin_ = ptRanges[iPt] ;
80  ptMax_ = ptRanges[iPt+1] ;
81  }
82  else {
83  ptActive_ = false ;
84  ptMin_ = ptRanges[0] ;
85  ptMax_ = ptRanges[ptRanges.size() - 1] ;
86  }
87  return EtaPtBin(etaActive_ , etaMin_ , etaMax_ ,
88  ptActive_ , ptMin_ , ptMax_ );
89 }
90 
92 {
93  for (vector<vector<JetTagPlotter*> >::iterator iJetLabel = binJetTagPlotters.begin();
94  iJetLabel != binJetTagPlotters.end(); ++iJetLabel)
95  for (vector<JetTagPlotter*>::iterator iPlotter = iJetLabel->begin(); iPlotter != iJetLabel->end(); ++iPlotter)
96  delete *iPlotter;
97 
98  if (mcPlots_ && makeDiffPlots_) {
99  for(vector<vector<BTagDifferentialPlot*> >::iterator iJetLabel = differentialPlots.begin();
100  iJetLabel != differentialPlots.end(); ++iJetLabel)
101  for (vector<BTagDifferentialPlot *>::iterator iPlotter = iJetLabel->begin();
102  iPlotter != iJetLabel->end(); ++ iPlotter)
103  delete *iPlotter;
104  }
105 
106  for (vector<vector<TagCorrelationPlotter*> >::iterator iJetLabel = binTagCorrelationPlotters.begin();
107  iJetLabel != binTagCorrelationPlotters.end(); ++iJetLabel)
108  for (vector<TagCorrelationPlotter* >::iterator iPlotter = iJetLabel->begin(); iPlotter != iJetLabel->end(); ++iPlotter)
109  delete *iPlotter;
110 
111 
112  for (vector<vector<BaseTagInfoPlotter*> >::iterator iJetLabel = binTagInfoPlotters.begin();
113  iJetLabel != binTagInfoPlotters.end(); ++iJetLabel)
114  for (vector<BaseTagInfoPlotter*>::iterator iPlotter = iJetLabel->begin(); iPlotter != iJetLabel->end(); ++iPlotter)
115  delete *iPlotter;
116 
117 }
118 
120 {
121 
122  //
123  // Book all histograms.
124  //
125 
126  // iterate over ranges:
127  const int iEtaStart = -1 ; // this will be the inactive one
128  const int iEtaEnd = etaRanges.size() - 1 ;
129  const int iPtStart = -1 ; // this will be the inactive one
130  const int iPtEnd = ptRanges.size() - 1 ;
131  setTDRStyle();
132 
133  TagInfoPlotterFactory theFactory;
134  int iTag = -1; int iTagCorr = -1; int iInfoTag = -1;
135  for (vector<edm::ParameterSet>::const_iterator iModule = moduleConfig.begin();
136  iModule != moduleConfig.end(); ++iModule) {
137 
138  const string& dataFormatType = iModule->exists("type") ?
139  iModule->getParameter<string>("type") :
140  "JetTag";
141  if (dataFormatType == "JetTag") {
142  iTag++;
143  const string& folderName = iModule->getParameter<string>("folder");
144 
145  // Contains plots for each bin of rapidity and pt.
146  vector<BTagDifferentialPlot*> * differentialPlotsConstantEta = new vector<BTagDifferentialPlot*> () ;
147  vector<BTagDifferentialPlot*> * differentialPlotsConstantPt = new vector<BTagDifferentialPlot*> () ;
148  if (mcPlots_ && makeDiffPlots_){
149  // the constant b-efficiency for the differential plots versus pt and eta
150  const double& effBConst =
151  iModule->getParameter<edm::ParameterSet>("parameters").getParameter<double>("effBConst");
152 
153  // the objects for the differential plots vs. eta,pt for
154  for ( int iEta = iEtaStart ; iEta < iEtaEnd ; iEta++ ) {
155  BTagDifferentialPlot * etaConstDifferentialPlot = new BTagDifferentialPlot
156  (effBConst, BTagDifferentialPlot::constETA, folderName, mcPlots_);
157  differentialPlotsConstantEta->push_back ( etaConstDifferentialPlot );
158  }
159 
160  for ( int iPt = iPtStart ; iPt < iPtEnd ; iPt++ ) {
161  // differentialPlots for this pt bin
162  BTagDifferentialPlot * ptConstDifferentialPlot = new BTagDifferentialPlot
163  (effBConst, BTagDifferentialPlot::constPT, folderName, mcPlots_);
164  differentialPlotsConstantPt->push_back ( ptConstDifferentialPlot );
165  }
166  }
167  // eta loop
168  for ( int iEta = iEtaStart ; iEta < iEtaEnd ; iEta++ ) {
169  // pt loop
170  for ( int iPt = iPtStart ; iPt < iPtEnd ; iPt++ ) {
171 
172  const EtaPtBin& etaPtBin = getEtaPtBin(iEta, iPt);
173 
174  // Instantiate the genertic b tag plotter
175  JetTagPlotter *jetTagPlotter = new JetTagPlotter(folderName, etaPtBin,
176  iModule->getParameter<edm::ParameterSet>("parameters"),mcPlots_,true, ibook);
177  binJetTagPlotters.at(iTag).push_back ( jetTagPlotter ) ;
178 
179  // Add to the corresponding differential plotters
180  if (mcPlots_ && makeDiffPlots_){
181  (*differentialPlotsConstantEta)[iEta+1]->addBinPlotter ( jetTagPlotter ) ;
182  (*differentialPlotsConstantPt )[iPt+1] ->addBinPlotter ( jetTagPlotter ) ;
183  }
184  }
185  }
186  // the objects for the differential plots vs. eta, pt: collect all from constant eta and constant pt
187  if (mcPlots_ && makeDiffPlots_){
188  differentialPlots.at(iTag).reserve(differentialPlotsConstantEta->size()+differentialPlotsConstantPt->size()) ;
189  differentialPlots.at(iTag).insert(differentialPlots.at(iTag).end(), differentialPlotsConstantEta->begin(), differentialPlotsConstantEta->end());
190  differentialPlots.at(iTag).insert(differentialPlots.at(iTag).end(), differentialPlotsConstantPt->begin(), differentialPlotsConstantPt->end());
191 
192  edm::LogInfo("Info")
193  << "====>>>> ## sizeof differentialPlots = " << differentialPlots.size();
194 
195  // the intermediate ones are no longer needed
196  delete differentialPlotsConstantEta ;
197  delete differentialPlotsConstantPt ;
198  }
199  } else if(dataFormatType == "TagCorrelation") {
200  iTagCorr++;
201  const InputTag& label1 = iModule->getParameter<InputTag>("label1");
202  const InputTag& label2 = iModule->getParameter<InputTag>("label2");
203 
204  // eta loop
205  for ( int iEta = iEtaStart ; iEta != iEtaEnd ; ++iEta) {
206  // pt loop
207  for( int iPt = iPtStart ; iPt != iPtEnd ; ++iPt) {
208  const EtaPtBin& etaPtBin = getEtaPtBin(iEta, iPt);
209  // Instantiate the generic b tag correlation plotter
210  TagCorrelationPlotter* tagCorrelationPlotter = new TagCorrelationPlotter(label1.label(), label2.label(), etaPtBin,
211  iModule->getParameter<edm::ParameterSet>("parameters"),
212  mcPlots_, ibook);
213  binTagCorrelationPlotters.at(iTagCorr).push_back(tagCorrelationPlotter);
214  }
215  }
216  } else {
217  iInfoTag++;
218  // tag info retrievel is deferred (needs availability of EventSetup)
219  const InputTag& moduleLabel = iModule->getParameter<InputTag>("label");
220  const string& folderName = iModule->getParameter<string>("folder");
221  // eta loop
222  for ( int iEta = iEtaStart ; iEta < iEtaEnd ; iEta++ ) {
223  // pt loop
224  for ( int iPt = iPtStart ; iPt < iPtEnd ; iPt++ ) {
225  const EtaPtBin& etaPtBin = getEtaPtBin(iEta, iPt);
226 
227  // Instantiate the tagInfo plotter
228 
229  BaseTagInfoPlotter *jetTagPlotter = theFactory.buildPlotter(dataFormatType, moduleLabel.label(),
230  etaPtBin, iModule->getParameter<edm::ParameterSet>("parameters"), folderName,
231  mcPlots_, true, ibook);
232  binTagInfoPlotters.at(iInfoTag).push_back ( jetTagPlotter ) ;
233  binTagInfoPlottersToModuleConfig.insert(make_pair(jetTagPlotter, iModule - moduleConfig.begin()));
234  }
235  }
236  edm::LogInfo("Info")
237  << "====>>>> ## sizeof differentialPlots = " << differentialPlots.size();
238  }
239  }
240 
242 
243  setTDRStyle();
244  for (unsigned int iJetLabel = 0; iJetLabel != binJetTagPlotters.size(); ++iJetLabel) {
245  int plotterSize = binJetTagPlotters[iJetLabel].size();
246  for (int iPlotter = 0; iPlotter != plotterSize; ++iPlotter) {
247  binJetTagPlotters[iJetLabel][iPlotter]->finalize(ibook, iget);
248  if (producePs) (*binJetTagPlotters[iJetLabel][iPlotter]).psPlot(psBaseName);
249  if (produceEps) (*binJetTagPlotters[iJetLabel][iPlotter]).epsPlot(epsBaseName);
250  }
251 
252  if(makeDiffPlots_) {
253  for (vector<BTagDifferentialPlot *>::iterator iPlotter = differentialPlots[iJetLabel].begin();
254  iPlotter != differentialPlots[iJetLabel].end(); ++ iPlotter) {
255  (*iPlotter)->process(ibook);
256  if (producePs) (*iPlotter)->psPlot(psBaseName);
257  if (produceEps) (*iPlotter)->epsPlot(epsBaseName);
258  }
259  }
260  }
261  for (vector<vector<BaseTagInfoPlotter*> >::iterator iJetLabel = binTagInfoPlotters.begin();
262  iJetLabel != binTagInfoPlotters.end(); ++iJetLabel) {
263  for (vector<BaseTagInfoPlotter*>::iterator iPlotter = iJetLabel->begin(); iPlotter != iJetLabel->end(); ++iPlotter) {
264  (*iPlotter)->finalize(ibook, iget);
265  if (producePs) (*iPlotter)->psPlot(psBaseName);
266  if (produceEps) (*iPlotter)->epsPlot(epsBaseName);
267  }
268  }
269 }
270 
271 
272 //define this as a plug-in
std::vector< std::pair< edm::InputTag, edm::InputTag > > tagCorrelationInputTags
BaseTagInfoPlotter * buildPlotter(const std::string &dataFormatType, const std::string &tagName, const EtaPtBin &etaPtBin, const edm::ParameterSet &pSet, const std::string &folderName, const unsigned int &mc, const bool &wf, DQMStore::IBooker &ibook)
BTagPerformanceHarvester(const edm::ParameterSet &pSet)
std::vector< std::vector< edm::InputTag > > tagInfoInputTags
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
EtaPtBin getEtaPtBin(const int &iEta, const int &iPt)
std::map< BaseTagInfoPlotter *, size_t > binTagInfoPlottersToModuleConfig
std::vector< edm::InputTag > jetTagInputTags
list EtaPtBin
Definition: histoStyle.py:59
std::vector< std::vector< BaseTagInfoPlotter * > > binTagInfoPlotters
std::string const & label() const
Definition: InputTag.h:43
std::vector< std::vector< JetTagPlotter * > > binJetTagPlotters
void setTDRStyle()
Definition: plotscripts.py:87
#define begin
Definition: vmac.h:30
std::vector< std::vector< TagCorrelationPlotter * > > binTagCorrelationPlotters
std::vector< std::string > tiDataFormatType
std::vector< edm::ParameterSet > moduleConfig
volatile std::atomic< bool > shutdown_flag false
std::vector< std::vector< BTagDifferentialPlot * > > differentialPlots
std::vector< double > etaRanges
std::vector< double > ptRanges