CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
ImpactParameterCalibration Class Reference

#include <RecoBTag/ImpactParameterCalibration/src/ImpactParameterCalibration.cc>

Inheritance diagram for ImpactParameterCalibration:
edm::EDAnalyzer

Public Member Functions

 ImpactParameterCalibration (const edm::ParameterSet &)
 
 ~ImpactParameterCalibration ()
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
virtual void beginJob ()
 
virtual void endJob ()
 
TrackProbabilityCalibrationfromXml (edm::FileInPath xmlCalibration)
 
virtual void initFromFirstES (const edm::EventSetup &)
 

Static Private Member Functions

static TrackProbabilityCategoryData createCategory (double pmin, double pmax, double etamin, double etamax, int nhitmin, int nhitmax, int npixelhitsmin, int npixelhitsmax, double cmin, double cmax, int withFirst)
 

Private Attributes

edm::ParameterSet config
 
TrackProbabilityCalibrationm_calibration [2]
 
edm::InputTag m_iptaginfo
 
bool m_needInitFromES
 
edm::InputTag m_pv
 
unsigned int maxLoop
 
unsigned int minLoop
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
typedef WorkerT< EDAnalyzerWorkerType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDAnalyzer
CurrentProcessingContext const * currentContext () const
 

Detailed Description

Description: <one line="" class="" summary>="">

Implementation: <Notes on="" implementation>="">

Definition at line 66 of file ImpactParameterCalibration.cc.

Constructor & Destructor Documentation

ImpactParameterCalibration::ImpactParameterCalibration ( const edm::ParameterSet iConfig)
explicit

Definition at line 110 of file ImpactParameterCalibration.cc.

References gather_cfg::cout, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), m_iptaginfo, m_needInitFromES, m_pv, maxLoop, and minLoop.

110  :config(iConfig)
111 {
112  m_needInitFromES = false;
113  m_iptaginfo = iConfig.getParameter<edm::InputTag>("tagInfoSrc");
114  m_pv = iConfig.getParameter<edm::InputTag>("primaryVertexSrc");
115  bool createOnlyOne = iConfig.getUntrackedParameter<bool>("createOnlyOneCalibration", false);
116  minLoop=0;
117  maxLoop=1;
118  if (createOnlyOne == true){
119  int whichCalib = iConfig.getUntrackedParameter<int>("dimension", 2);
120  if (whichCalib==2){
121  std::cout <<" Writing only 2D calibrations"<<std::endl;
122  minLoop=1;
123  maxLoop=1;
124  }else if (whichCalib==3){
125  std::cout <<" Writing only 3D calibrations"<<std::endl;
126  minLoop=0;
127  maxLoop=0;
128  }else {
129  std::cout <<" Dimension not found: "<<whichCalib<<"; it must be either 2 or 3"<<std::endl;
130  }
131  }
132 
133 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
tuple cout
Definition: gather_cfg.py:41
ImpactParameterCalibration::~ImpactParameterCalibration ( )

Definition at line 136 of file ImpactParameterCalibration.cc.

137 {
138 }

Member Function Documentation

void ImpactParameterCalibration::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
privatevirtual

Implements edm::EDAnalyzer.

Definition at line 142 of file ImpactParameterCalibration.cc.

References gather_cfg::cout, TrackProbabilityCalibration::data, eta(), newFWLiteAna::found, edm::Event::getByLabel(), i, initFromFirstES(), collect_tpl::input, j, m_calibration, m_iptaginfo, m_needInitFromES, m_pv, maxLoop, minLoop, L1TEmulatorMonitor_cff::p, dt_dqm_sourceclient_common_cff::reco, and edm::RefVector< C, T, F >::size().

143 {
144  if(m_needInitFromES) initFromFirstES(iSetup);
145  using namespace edm;
146  using namespace reco;
147 
149  iEvent.getByLabel(m_iptaginfo, ipHandle);
150  const TrackIPTagInfoCollection & ip = *(ipHandle.product());
151 
152 // cout << "Found " << ip.size() << " TagInfo" << endl;
153 
154  Handle<reco::VertexCollection> primaryVertex;
155  iEvent.getByLabel(m_pv,primaryVertex);
156 
157  vector<TrackProbabilityCalibration::Entry>::iterator found;
158  vector<TrackProbabilityCalibration::Entry>::iterator it_begin;
159  vector<TrackProbabilityCalibration::Entry>::iterator it_end;
160 
161 
162  TrackIPTagInfoCollection::const_iterator it = ip.begin();
163  for(; it != ip.end(); it++)
164  {
165  TrackRefVector selTracks=it->selectedTracks();
166 // if(it->primaryVertex().isNull()) continue;
167  if(primaryVertex.product()->size() == 0)
168  {
169  std::cout << "No PV in the event!!" << std::endl;
170  continue;
171  }
172  const Vertex & pv = *(primaryVertex.product()->begin());
173 
174  for(unsigned int i=minLoop; i <= maxLoop;i++)
175  {
176  it_begin=m_calibration[i]->data.begin();
177  it_end=m_calibration[i]->data.end();
178 
179  for(unsigned int j=0;j<selTracks.size(); j++)
180  {
181  double ipsig;
182  if (i==0) ipsig = it->impactParameterData()[j].ip3d.significance();
183  else ipsig = it->impactParameterData()[j].ip2d.significance();
184  TrackClassMatch::Input input(*selTracks[j],*it->jet(),pv);
185  if(ipsig < 0)
186  {
187  found = std::find_if(it_begin,it_end,bind1st(TrackClassMatch(),input));
188 // std::cout << ip[j].significance() << std::endl;
189  if(found!=it_end)
190  found->histogram.fill(-ipsig);
191  else
192  {std::cout << "No category for this track!!" << std::endl;
193  std::cout << "p " <<(*selTracks[j]).p () << std::endl;
194  std::cout << "eta " << (*selTracks[j]).eta() << std::endl;
195  std::cout << "NHit " << (*selTracks[j]).numberOfValidHits() << std::endl;
196  std::cout << "NPixHit " << (*selTracks[j]).hitPattern().numberOfValidPixelHits() << std::endl;
197  std::cout << "FPIXHIT " << (*selTracks[j]).hitPattern().hasValidHitInFirstPixelBarrel() << std::endl;}
198 
199  }
200  }
201  }
202  }
203 
204 
205 
206 }
int i
Definition: DBlmapReader.cc:9
TrackProbabilityCalibration * m_calibration[2]
T eta() const
int j
Definition: DBlmapReader.cc:9
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
virtual void initFromFirstES(const edm::EventSetup &)
tuple input
Definition: collect_tpl.py:10
size_type size() const
Size of the RefVector.
Definition: RefVector.h:84
tuple cout
Definition: gather_cfg.py:41
void ImpactParameterCalibration::beginJob ( void  )
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 247 of file ImpactParameterCalibration.cc.

References ecalBxOrbitNumberGrapher_cfg::categories, TrackProbabilityCalibration::Entry::category, config, createCategory(), TrackProbabilityCalibration::data, fromXml(), edm::ParameterSet::getParameter(), estimatePileup::hist, TrackProbabilityCalibration::Entry::histogram, i, j, m_calibration, m_needInitFromES, maxLoop, minLoop, and v.

248 {
249  using namespace edm;
252 
253  CalibratedHistogram hist(config.getParameter<int>("nBins"),0,config.getParameter<double>("maxSignificance"));
254 
255  std::string categories = config.getParameter<std::string>("inputCategories");
256 
257  if(categories == "HardCoded")
258  {
259  vector<TrackProbabilityCategoryData> v;
260  //TrackProbabilityCategoryData {pMin, pMax, etaMin, etaMax,
261  //nHitsMin, nHitsMax, nPixelHitsMin, nPixelHitsMax, chiMin,chiMax, withFirstPixel;
262  //trackQuality;
263  v.push_back(createCategory(0, 5000, 0 , 2.5, 8 , 50, 1, 1, 0 , 5 , 0));
264  v.push_back(createCategory(0, 5000, 0 , 2.5, 8 , 50, 2, 8, 2.5, 5 , 0));
265  v.push_back(createCategory(0, 8 , 0 , 0.8, 8 , 50, 3, 8, 0 , 2.5, 0));
266  v.push_back(createCategory(0, 8 , 0.8, 1.6, 8 , 50, 3, 8, 0 , 2.5, 0));
267  v.push_back(createCategory(0, 8 , 1.6, 2.5, 8 , 50, 3, 8, 0 , 2.5, 0));
268  v.push_back(createCategory(0, 8 , 0 , 2.5, 8 , 50, 2, 8, 0 , 2.5, 0));
269  v.push_back(createCategory(8, 5000, 0 , 0.8, 8 , 50, 3, 8, 0 , 2.5, 0));
270  v.push_back(createCategory(8, 5000, 0.8, 1.6, 8 , 50, 3, 8, 0 , 2.5, 0));
271  v.push_back(createCategory(8, 5000, 1.6, 2.5, 8 , 50, 3, 8, 0 , 2.5, 0));
272  v.push_back(createCategory(8, 5000, 0 , 2.5, 8 , 50, 2 ,2, 0 , 2.5, 0));
273  for(unsigned int i=minLoop;i <=maxLoop ;i++)
274  for(unsigned int j=0;j<v.size() ; j++)
275  {
277  e.category=v[j];
278  e.histogram=hist;
279  m_calibration[i]->data.push_back(e);
280  }
281 
282  }
283  if(categories == "RootXML")
284  {
285  bool resetHistogram = config.getParameter<bool>("resetHistograms");
286  const TrackProbabilityCalibration * ca[2];
287  ca[0] = fromXml(config.getParameter<edm::FileInPath>("calibFile3d"));
288  ca[1] = fromXml(config.getParameter<edm::FileInPath>("calibFile2d"));
289 
290  for(unsigned int i=minLoop;i <=maxLoop ;i++)
291  for(unsigned int j=0;j<ca[i]->data.size() ; j++)
292  {
294  e.category=ca[i]->data[j].category;
295 
296  if(resetHistogram)
297  e.histogram=hist;
298  else
299  e.histogram=ca[i]->data[j].histogram;
300 
301  m_calibration[i]->data.push_back(e);
302  }
303 
304  delete ca[0];
305  delete ca[1];
306 
307  }
308  if(categories == "EventSetup")
309  {
310  m_needInitFromES=true;
311  }
312 
313 
314 
315 /* edm::FileInPath f2d(m_xmlfilename2D);
316  edm::FileInPath f3d(m_xmlfilename3D);
317  calibrationNew = new AlgorithmCalibration<TrackClassFilterCategory,CalibratedHistogramXML>((f3d.fullPath()).c_str());
318  calibration2dNew = new AlgorithmCalibration<TrackClassFilterCategory,CalibratedHistogramXML>((f2d.fullPath()).c_str());
319  vector<float> * bins =0;
320  if(m_resetData)
321  {
322  if(m_newBinning) bins = new vector<float>(CalibratedHistogram::constantBinning(m_nBin,0,m_range));
323  vector<pair<TrackClassFilterCategory, CalibratedHistogramXML> > data = calibrationNew->categoriesWithData();
324  vector<pair<TrackClassFilterCategory, CalibratedHistogramXML> > data2d = calibration2dNew->categoriesWithData();
325  std::cout << data.size() << std::endl;
326  for(unsigned int i = 0 ; i < data.size();i++)
327  {
328  data[i].second.reset();
329  if(bins) data[i].second.setUpperLimits(*bins);
330  }
331  for(unsigned int i = 0 ; i < data2d.size();i++)
332  {
333  data2d[i].second.reset();
334  if(bins) data2d[i].second.setUpperLimits(*bins);
335  }
336 
337  }
338  if(bins) delete bins;
339 
340 */
341 
342 
343 }
TrackProbabilityCalibration * fromXml(edm::FileInPath xmlCalibration)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
TrackProbabilityCalibration * m_calibration[2]
static TrackProbabilityCategoryData createCategory(double pmin, double pmax, double etamin, double etamax, int nhitmin, int nhitmax, int npixelhitsmin, int npixelhitsmax, double cmin, double cmax, int withFirst)
int j
Definition: DBlmapReader.cc:9
PhysicsTools::Calibration::HistogramF histogram
mathSSE::Vec4< T > v
static TrackProbabilityCategoryData ImpactParameterCalibration::createCategory ( double  pmin,
double  pmax,
double  etamin,
double  etamax,
int  nhitmin,
int  nhitmax,
int  npixelhitsmin,
int  npixelhitsmax,
double  cmin,
double  cmax,
int  withFirst 
)
inlinestaticprivate

Definition at line 82 of file ImpactParameterCalibration.cc.

References trackerHits::c, TrackProbabilityCategoryData::chiMax, TrackProbabilityCategoryData::chiMin, TrackProbabilityCategoryData::etaMax, TrackProbabilityCategoryData::etaMin, TrackProbabilityCategoryData::nHitsMax, TrackProbabilityCategoryData::nHitsMin, TrackProbabilityCategoryData::nPixelHitsMax, TrackProbabilityCategoryData::nPixelHitsMin, TrackProbabilityCategoryData::pMax, TrackProbabilityCategoryData::pMin, and TrackProbabilityCategoryData::withFirstPixel.

Referenced by beginJob().

87  {
89  c.pMin=pmin;
90  c.pMax=pmax;
91  c.etaMin=etamin;
92  c.etaMax=etamax;
93  c.nHitsMin=nhitmin;
94  c.nHitsMax=nhitmax;
95  c.nPixelHitsMin=npixelhitsmin;
96  c.nPixelHitsMax=npixelhitsmax;
97  c.chiMin=cmin;
98  c.chiMax=cmax;
99  c.withFirstPixel=withFirst;
100  return c;
101  }
void ImpactParameterCalibration::endJob ( void  )
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 380 of file ImpactParameterCalibration.cc.

References cond::service::PoolDBOutputService::beginOfTime(), config, cond::service::PoolDBOutputService::createNewIOV(), cond::service::PoolDBOutputService::endOfTime(), edm::ParameterSet::getParameter(), edm::Service< T >::isAvailable(), m_calibration, maxLoop, minLoop, indexGen::ofile, and findQualityFiles::size.

380  {
381 
382  if(config.getParameter<bool>("writeToDB"))
383  {
385  if( !mydbservice.isAvailable() ) return;
386  if(minLoop == 0 ) mydbservice->createNewIOV<TrackProbabilityCalibration>(m_calibration[0], mydbservice->beginOfTime(), mydbservice->endOfTime(),"BTagTrackProbability3DRcd");
387  if(maxLoop == 1) mydbservice->createNewIOV<TrackProbabilityCalibration>(m_calibration[1], mydbservice->beginOfTime(), mydbservice->endOfTime(),"BTagTrackProbability2DRcd");
388  }
389 
390 
391  if(config.getParameter<bool>("writeToRootXML"))
392  {
393  if(maxLoop == 1 ){
394  std::ofstream of2("2d.xml");
395  TBufferXML b2(TBuffer::kWrite);
396  of2 << b2.ConvertToXML(const_cast<void*>(static_cast<const void*>(m_calibration[1])),
397  TClass::GetClass("TrackProbabilityCalibration"),
398  kTRUE, kFALSE);
399  of2.close();
400  }
401  if(minLoop == 0 ){
402  std::ofstream of3("3d.xml");
403  TBufferXML b3(TBuffer::kWrite);
404  of3 << b3.ConvertToXML(const_cast<void*>(static_cast<const void*>(m_calibration[0])),
405  TClass::GetClass("TrackProbabilityCalibration"),
406  kTRUE, kFALSE);
407  of3.close();
408  }
409  }
410 
411 
412  if(config.getParameter<bool>("writeToBinary"))
413  {
414  if(maxLoop == 1 ){
415 
416  std::ofstream ofile("2d.dat");
417  TBufferFile buffer(TBuffer::kWrite);
418  buffer.StreamObject(const_cast<void*>(static_cast<const void*>(m_calibration[1])),
419  TClass::GetClass("TrackProbabilityCalibration"));
420  Int_t size = buffer.Length();
421  ofile.write(buffer.Buffer(),size);
422  ofile.close();
423  }
424  if(minLoop == 0 ){
425  std::ofstream ofile3("3d.dat");
426  TBufferFile buffer3(TBuffer::kWrite);
427  buffer3.StreamObject(const_cast<void*>(static_cast<const void*>(m_calibration[0])),
428  TClass::GetClass("TrackProbabilityCalibration"));
429  Int_t size3 = buffer3.Length();
430  ofile3.write(buffer3.Buffer(),size3);
431  ofile3.close();
432  }
433  }
434 
435 
436 
437 
438 
439 }
T getParameter(std::string const &) const
TrackProbabilityCalibration * m_calibration[2]
bool isAvailable() const
Definition: Service.h:47
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
tuple ofile
Definition: indexGen.py:101
tuple size
Write out results.
TrackProbabilityCalibration * ImpactParameterCalibration::fromXml ( edm::FileInPath  xmlCalibration)
private

Definition at line 345 of file ImpactParameterCalibration.cc.

References edm::hlt::Exception, edm::FileInPath::fullPath(), and xmlFile().

Referenced by beginJob().

346 {
347  std::ifstream xmlFile(xmlCalibration.fullPath().c_str());
348  if (!xmlFile.good())
349  throw cms::Exception("BTauFakeMVAJetTagConditions")
350  << "File \"" << xmlCalibration.fullPath()
351  << "\" could not be opened for reading."
352  << std::endl;
353  std::ostringstream ss;
354  ss << xmlFile.rdbuf();
355  xmlFile.close();
356  TClass *classType = 0;
357  void *ptr = TBufferXML(TBuffer::kRead).ConvertFromXMLAny(
358  ss.str().c_str(), &classType, kTRUE, kFALSE);
359  if (!ptr)
360  throw cms::Exception("ImpactParameterCalibration")
361  << "Unknown error parsing XML serialization"
362  << std::endl;
363 
364  if (std::strcmp(classType->GetName(),
365  "TrackProbabilityCalibration")) {
366  classType->Destructor(ptr);
367  throw cms::Exception("ImpactParameterCalibration")
368  << "Serialized object has wrong C++ type."
369  << std::endl;
370  }
371 
372  return static_cast<TrackProbabilityCalibration*>(ptr);
373 }
bool xmlFile(const std::string fParam)
std::string fullPath() const
Definition: FileInPath.cc:170
void ImpactParameterCalibration::initFromFirstES ( const edm::EventSetup iSetup)
privatevirtual

Definition at line 214 of file ImpactParameterCalibration.cc.

References TrackProbabilityCalibration::Entry::category, config, TrackProbabilityCalibration::data, edm::EventSetup::get(), edm::ParameterSet::getParameter(), estimatePileup::hist, TrackProbabilityCalibration::Entry::histogram, i, j, m_calibration, maxLoop, and minLoop.

Referenced by analyze().

215 {
216  using namespace edm;
217 
218  CalibratedHistogram hist(config.getParameter<int>("nBins"),0,config.getParameter<double>("maxSignificance"));
219  bool resetHistogram = config.getParameter<bool>("resetHistograms");
221  iSetup.get<BTagTrackProbability2DRcd>().get(calib2DHandle);
223  iSetup.get<BTagTrackProbability3DRcd>().get(calib3DHandle);
224  const TrackProbabilityCalibration * ca[2];
225  ca[0] = calib3DHandle.product();
226  ca[1] = calib2DHandle.product();
227  for(unsigned int i=minLoop;i <=maxLoop ;i++)
228  for(unsigned int j=0;j<ca[i]->data.size() ; j++)
229  {
231  e.category=ca[i]->data[j].category;
232 
233  if(resetHistogram)
234  e.histogram=hist;
235  else
236  e.histogram=ca[i]->data[j].histogram;
237 
238  m_calibration[i]->data.push_back(e);
239  }
240 
241 
242 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
TrackProbabilityCalibration * m_calibration[2]
int j
Definition: DBlmapReader.cc:9
PhysicsTools::Calibration::HistogramF histogram
const T & get() const
Definition: EventSetup.h:55

Member Data Documentation

edm::ParameterSet ImpactParameterCalibration::config
private

Definition at line 78 of file ImpactParameterCalibration.cc.

Referenced by beginJob(), endJob(), and initFromFirstES().

TrackProbabilityCalibration* ImpactParameterCalibration::m_calibration[2]
private

Definition at line 103 of file ImpactParameterCalibration.cc.

Referenced by analyze(), beginJob(), endJob(), and initFromFirstES().

edm::InputTag ImpactParameterCalibration::m_iptaginfo
private

Definition at line 104 of file ImpactParameterCalibration.cc.

Referenced by analyze(), and ImpactParameterCalibration().

bool ImpactParameterCalibration::m_needInitFromES
private

Definition at line 79 of file ImpactParameterCalibration.cc.

Referenced by analyze(), beginJob(), and ImpactParameterCalibration().

edm::InputTag ImpactParameterCalibration::m_pv
private

Definition at line 105 of file ImpactParameterCalibration.cc.

Referenced by analyze(), and ImpactParameterCalibration().

unsigned int ImpactParameterCalibration::maxLoop
private
unsigned int ImpactParameterCalibration::minLoop
private