CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
CorrPCCProducer Class Reference
Inheritance diagram for CorrPCCProducer:
one::DQMEDAnalyzer< T > one::dqmimplementation::DQMBaseClass< T... >

Public Member Functions

 CorrPCCProducer (const edm::ParameterSet &)
 
 ~CorrPCCProducer () override
 
- Public Member Functions inherited from one::DQMEDAnalyzer< T >
 DQMEDAnalyzer ()=default
 
 DQMEDAnalyzer (DQMEDAnalyzer< T... > const &)=delete
 
 DQMEDAnalyzer (DQMEDAnalyzer< T... > &&)=delete
 
 ~DQMEDAnalyzer () override=default
 

Private Member Functions

void beginLuminosityBlock (edm::LuminosityBlock const &lumiSeg, const edm::EventSetup &iSetup) final
 
void bookHistograms (DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
 
void calculateCorrections (std::vector< float >, std::vector< float > &, float &)
 
void endJob () final
 
void endLuminosityBlock (edm::LuminosityBlock const &lumiSeg, const edm::EventSetup &iSetup) final
 
void endRun (edm::Run const &runSeg, const edm::EventSetup &iSetup) final
 
void endRunProduce (edm::Run &runSeg, const edm::EventSetup &iSetup) final
 
void estimateType1Frac (std::vector< float >, float &)
 
void evaluateCorrectionResiduals (std::vector< float >)
 
float getMaximum (std::vector< float >)
 
void makeCorrectionTemplate ()
 
void resetBlock ()
 

Private Attributes

unsigned int approxLumiBlockSize_
 
std::vector< float > correctionScaleFactors_
 
std::vector< float > correctionTemplate_
 
TH1F * corrlumiAvg_h
 
unsigned int countLumi_
 
std::vector< float > errOnLumiByBX_
 
std::vector< float > events_
 
TFile * histoFile
 
TList * hlist
 
unsigned int iBlock =0
 
TH1F * lumiAvg_h
 
std::map< std::pair< unsigned int, unsigned int >, unsigned int > lumiInfoCounter
 
std::map< std::pair< unsigned int, unsigned int >, LumiInfo * > lumiInfoMap
 
std::map< std::pair< unsigned int, unsigned int >, LumiInfo * >::iterator lumiInfoMapIterator
 
std::map< unsigned int, LumiInfo * > lumiInfoMapPerLS
 
edm::EDGetTokenT< LumiInfolumiInfoToken
 
std::vector< unsigned int > lumiSections
 
unsigned int maxLS =3500
 
float mean_type1_residual
 
float mean_type1_residual_unc
 
float mean_type2_residual
 
float mean_type2_residual_unc
 
unsigned int minimumNumberOfEvents
 
unsigned int nTrain
 
float overallCorrection_
 
LumiCorrectionspccCorrections
 
std::string pccSrc_
 
edm::Service< cond::service::PoolDBOutputServicepoolDbService
 
std::string prodInst_
 
std::vector< float > rawlumiBX_
 
TH1F * scaleFactorAvg_h
 
unsigned int thisLS
 
std::vector< float > totalLumiByBX_
 
std::vector< float > totalLumiByBXAvg_
 
float type1Frac
 
TGraphErrors * type1FracGraph
 
TH1F * type1FracHist
 
MonitorElementType1FracMon
 
TGraphErrors * type1resGraph
 
TH1F * type1resHist
 
MonitorElementType1ResMon
 
double type2_a_
 
double type2_b_
 
TGraphErrors * type2resGraph
 
TH1F * type2resHist
 
MonitorElementType2ResMon
 

Detailed Description

Definition at line 55 of file CorrPCCProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 137 of file CorrPCCProducer.cc.

References approxLumiBlockSize_, correctionScaleFactors_, correctionTemplate_, countLumi_, events_, edm::ParameterSet::getParameter(), histoFile, lumiInfoToken, makeCorrectionTemplate(), minimumNumberOfEvents, LumiConstants::numBX, pccSrc_, prodInst_, resetBlock(), totalLumiByBX_, totalLumiByBXAvg_, type1FracGraph, type1resGraph, type2_a_, type2_b_, and type2resGraph.

138 {
139  pccSrc_ = iConfig.getParameter<edm::ParameterSet>("CorrPCCProducerParameters").getParameter<std::string>("inLumiObLabel");
140  prodInst_ = iConfig.getParameter<edm::ParameterSet>("CorrPCCProducerParameters").getParameter<std::string>("ProdInst");
141  approxLumiBlockSize_=iConfig.getParameter<edm::ParameterSet>("CorrPCCProducerParameters").getParameter<int>("approxLumiBlockSize");
142  type2_a_ = iConfig.getParameter<edm::ParameterSet>("CorrPCCProducerParameters").getParameter<double>("type2_a");
143  type2_b_ = iConfig.getParameter<edm::ParameterSet>("CorrPCCProducerParameters").getParameter<double>("type2_b");
144  countLumi_=0;
146 
152 
153  resetBlock();
154 
156 
157  edm::InputTag inputPCCTag_(pccSrc_, prodInst_);
158 
159  lumiInfoToken=consumes<LumiInfo, edm::InLumi>(inputPCCTag_);
160 
161  histoFile = new TFile("CorrectionHisto.root","RECREATE");
162 
163  type1FracGraph= new TGraphErrors();
164  type1resGraph = new TGraphErrors();
165  type2resGraph = new TGraphErrors();
166  type1FracGraph->SetName("Type1Fraction");
167  type1resGraph->SetName("Type1Res");
168  type2resGraph->SetName("Type2Res");
169  type1FracGraph->GetYaxis()->SetTitle("Type 1 Fraction");
170  type1resGraph->GetYaxis()->SetTitle("Type 1 Residual");
171  type2resGraph->GetYaxis()->SetTitle("Type 2 Residual");
172  type1FracGraph->GetXaxis()->SetTitle("Unique LS ID");
173  type1resGraph->GetXaxis()->SetTitle("Unique LS ID");
174  type2resGraph->GetXaxis()->SetTitle("Unique LS ID");
175  type1FracGraph->SetMarkerStyle(8);
176  type1resGraph->SetMarkerStyle(8);
177  type2resGraph->SetMarkerStyle(8);
178 }
T getParameter(std::string const &) const
std::vector< float > events_
edm::EDGetTokenT< LumiInfo > lumiInfoToken
static const unsigned int numBX
Definition: LumiConstants.h:9
unsigned int countLumi_
std::string pccSrc_
unsigned int minimumNumberOfEvents
std::vector< float > totalLumiByBXAvg_
TGraphErrors * type1resGraph
std::string prodInst_
std::vector< float > correctionScaleFactors_
std::vector< float > correctionTemplate_
TGraphErrors * type2resGraph
std::vector< float > totalLumiByBX_
TGraphErrors * type1FracGraph
unsigned int approxLumiBlockSize_
void makeCorrectionTemplate()
CorrPCCProducer::~CorrPCCProducer ( )
override

Definition at line 181 of file CorrPCCProducer.cc.

181  {
182 }

Member Function Documentation

void CorrPCCProducer::beginLuminosityBlock ( edm::LuminosityBlock const &  lumiSeg,
const edm::EventSetup iSetup 
)
finalprivate

Definition at line 357 of file CorrPCCProducer.cc.

References countLumi_.

357  {
358  countLumi_++;
359 }
unsigned int countLumi_
void CorrPCCProducer::bookHistograms ( DQMStore::IBooker ibooker,
edm::Run const &  iRun,
edm::EventSetup const &  context 
)
overrideprivate

Definition at line 636 of file CorrPCCProducer.cc.

References DQMStore::IBooker::book1D(), maxLS, DQMStore::IBooker::setCurrentFolder(), Type1FracMon, Type1ResMon, and Type2ResMon.

636  {
637  ibooker.setCurrentFolder("AlCaReco/LumiPCC/") ;
638  Type1FracMon = ibooker.book1D("type1Fraction","Type1Fraction;Lumisection;Type 1 Fraction",maxLS,0,maxLS);
639  Type1ResMon = ibooker.book1D("type1Residual","Type1Residual;Lumisection;Type 1 Residual",maxLS,0,maxLS);
640  Type2ResMon = ibooker.book1D("type2Residual","Type2Residual;Lumisection;Type 2 Residual",maxLS,0,maxLS);
641 }
MonitorElement * Type1FracMon
MonitorElement * Type1ResMon
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
unsigned int maxLS
MonitorElement * Type2ResMon
void CorrPCCProducer::calculateCorrections ( std::vector< float >  uncorrected,
std::vector< float > &  correctionScaleFactors_,
float &  overallCorrection_ 
)
private

Definition at line 297 of file CorrPCCProducer.cc.

References correctionTemplate_, estimateType1Frac(), evaluateCorrectionResiduals(), getMaximum(), mps_fire::i, SiStripPI::max, LumiConstants::numBX, electronIdCutBased_cfi::threshold, and type1Frac.

Referenced by endRunProduce().

297  {
298  type1Frac = 0;
299 
300  int nTrials=4;
301 
302  for(int trial=0;trial<nTrials;trial++){
303  estimateType1Frac(uncorrected, type1Frac);
304  edm::LogInfo("INFO") <<"type 1 fraction after iteration "<<trial<<" is "<<type1Frac;
305  }
306 
307  //correction should never be negative
308  type1Frac=std::max(0.0,(double)type1Frac);
309 
310  std::vector<float> corrected_tmp_;
311  for(size_t i=0; i<uncorrected.size(); i++){
312  corrected_tmp_.push_back(uncorrected.at(i));
313  }
314 
315 
316  //Apply all corrections
317  for(size_t i=0; i<LumiConstants::numBX-1; i++){
318  // type 1 - first (spillover from previous BXs real clusters)
319  float bin_i = corrected_tmp_.at(i);
320  corrected_tmp_.at(i+1)=corrected_tmp_.at(i+1)-type1Frac*bin_i;
321 
322  // type 2 - after (comes from real activation)
323  bin_i = corrected_tmp_.at(i);
324  for(size_t j=i+1; j<i+LumiConstants::numBX-1; j++){
325  if(j<LumiConstants::numBX){
326  corrected_tmp_.at(j)=corrected_tmp_.at(j)-bin_i*correctionTemplate_.at(j-i);
327  }else{
328  corrected_tmp_.at(j-LumiConstants::numBX) = corrected_tmp_.at(j-LumiConstants::numBX)-bin_i*correctionTemplate_.at(j-i);
329  }
330  }
331  }
332 
333  evaluateCorrectionResiduals(corrected_tmp_);
334 
335  float integral_uncorr_clusters=0;
336  float integral_corr_clusters = 0;
337 
338  //Calculate Per-BX correction factor and overall correction factor
339  float lumiMax = getMaximum(corrected_tmp_);
340  float threshold = lumiMax*0.2;
341  for (size_t ibx=0; ibx<corrected_tmp_.size(); ibx++){
342  if(corrected_tmp_.at(ibx)>threshold){
343  integral_uncorr_clusters+=uncorrected.at(ibx);
344  integral_corr_clusters+=corrected_tmp_.at(ibx);
345  }
346  if(corrected_tmp_.at(ibx)!=0.0&&uncorrected.at(ibx)!=0.0){
347  correctionScaleFactors_.at(ibx) = corrected_tmp_.at(ibx)/uncorrected.at(ibx);
348  }else{
349  correctionScaleFactors_.at(ibx) = 0.0;
350  }
351  }
352 
353  overallCorrection_ = integral_corr_clusters/integral_uncorr_clusters;
354 }
static const unsigned int numBX
Definition: LumiConstants.h:9
void evaluateCorrectionResiduals(std::vector< float >)
std::vector< float > correctionScaleFactors_
std::vector< float > correctionTemplate_
float getMaximum(std::vector< float >)
void estimateType1Frac(std::vector< float >, float &)
void CorrPCCProducer::endJob ( void  )
finalprivate

Definition at line 643 of file CorrPCCProducer.cc.

References DEFINE_FWK_MODULE, histoFile, type1FracGraph, type1resGraph, and type2resGraph.

Referenced by o2olib.O2ORunMgr::executeJob().

643  {
644  histoFile->cd();
645  type1FracGraph->Write();
646  type1resGraph->Write();
647  type2resGraph->Write();
648  histoFile->Write();
649  histoFile->Close();
650  delete type1FracGraph;
651  delete type1resGraph;
652  delete type2resGraph;
653 }
TGraphErrors * type1resGraph
TGraphErrors * type2resGraph
TGraphErrors * type1FracGraph
void CorrPCCProducer::endLuminosityBlock ( edm::LuminosityBlock const &  lumiSeg,
const edm::EventSetup iSetup 
)
finalprivate

Definition at line 363 of file CorrPCCProducer.cc.

References errOnLumiByBX_, events_, edm::LuminosityBlock::getByToken(), LumiInfo::getErrorLumiAllBX(), LumiInfo::getInstLumiAllBX(), lumiInfoMapPerLS, lumiInfoToken, edm::LuminosityBlockBase::luminosityBlock(), lumiSections, minimumNumberOfEvents, LumiConstants::numBX, edm::Handle< T >::product(), thisLS, and totalLumiByBX_.

363  {
364 
365  thisLS = lumiSeg.luminosityBlock();
366 
367  edm::Handle<LumiInfo> PCCHandle;
368  lumiSeg.getByToken(lumiInfoToken,PCCHandle);
369 
370  const LumiInfo& inLumiOb = *(PCCHandle.product());
371 
372  errOnLumiByBX_= inLumiOb.getErrorLumiAllBX();
373 
374  unsigned int totalEvents=0;
375  for(unsigned int bx=0;bx<LumiConstants::numBX;bx++){
376  totalEvents+=errOnLumiByBX_[bx];
377  }
378 
379  if(totalEvents<minimumNumberOfEvents){
380  edm::LogInfo("INFO") <<"number of events in this LS is too few "<<totalEvents;
381  //return;
382  }
383  else{
384 
385  edm::LogInfo("INFO") <<"Skipping Lumisection "<<thisLS;
386  }
387 
389  totalLumiByBX_=inLumiOb.getInstLumiAllBX();
390  events_=inLumiOb.getErrorLumiAllBX();
391  lumiInfoMapPerLS[thisLS]->setInstLumiAllBX(totalLumiByBX_);
392  lumiInfoMapPerLS[thisLS]->setErrorLumiAllBX(events_);
393  lumiSections.push_back(thisLS);
394 }
std::vector< float > events_
edm::EDGetTokenT< LumiInfo > lumiInfoToken
static const unsigned int numBX
Definition: LumiConstants.h:9
const std::vector< float > & getErrorLumiAllBX() const
Definition: LumiInfo.h:104
unsigned int minimumNumberOfEvents
const std::vector< float > & getInstLumiAllBX() const
Definition: LumiInfo.h:100
std::vector< unsigned int > lumiSections
T const * product() const
Definition: Handle.h:81
std::vector< float > totalLumiByBX_
std::vector< float > errOnLumiByBX_
unsigned int thisLS
std::map< unsigned int, LumiInfo * > lumiInfoMapPerLS
void CorrPCCProducer::endRun ( edm::Run const &  runSeg,
const edm::EventSetup iSetup 
)
finalprivate

Definition at line 397 of file CorrPCCProducer.cc.

397  {
398 }
void CorrPCCProducer::endRunProduce ( edm::Run runSeg,
const edm::EventSetup iSetup 
)
finalprivate

Definition at line 401 of file CorrPCCProducer.cc.

References approxLumiBlockSize_, calculateCorrections(), correctionScaleFactors_, corrlumiAvg_h, gather_cfg::cout, errOnLumiByBX_, events_, plotBeamSpotDB::first, objects.autophobj::float, histoFile, mps_fire::i, iBlock, edm::RunBase::id(), edm::Service< T >::isAvailable(), lumiAvg_h, lumiInfoCounter, lumiInfoMap, lumiInfoMapIterator, lumiInfoMapPerLS, lumiSections, maxLS, mean_type1_residual, mean_type1_residual_unc, mean_type2_residual, mean_type2_residual_unc, LumiConstants::numBX, overallCorrection_, pccCorrections, poolDbService, rawlumiBX_, resetBlock(), edm::RunID::run(), edm::RunBase::run(), scaleFactorAvg_h, MonitorElement::setBinContent(), MonitorElement::setBinError(), LumiCorrections::setCorrectionsBX(), LumiCorrections::setOverallCorrection(), LumiCorrections::setType1Fraction(), LumiCorrections::setType1Residual(), LumiCorrections::setType2Residual(), thisLS, totalLumiByBX_, totalLumiByBXAvg_, type1Frac, type1FracGraph, type1FracHist, Type1FracMon, type1resGraph, type1resHist, Type1ResMon, type2resGraph, type2resHist, Type2ResMon, and cond::service::PoolDBOutputService::writeOne().

401  {
402  if(lumiSections.empty()){
403  return;
404  }
405 
406  std::sort (lumiSections.begin(), lumiSections.end());
407 
408  edm::LogInfo("INFO") <<"Number of Lumisections "<<lumiSections.size()<<" in run "<<runSeg.run() ;
409 
410  //Determining integer number of blocks
411  float nBlocks_f = float(lumiSections.size())/approxLumiBlockSize_;
412  unsigned int nBlocks=1;
413  if(nBlocks_f>1){
414  if(nBlocks_f - lumiSections.size()/approxLumiBlockSize_ < 0.5){
415  nBlocks=lumiSections.size()/approxLumiBlockSize_;
416  } else {
417  nBlocks=lumiSections.size()/approxLumiBlockSize_+1;
418  }
419  }
420 
421  float nLSPerBlock = float(lumiSections.size())/nBlocks;
422 
423  std::vector<std::pair<unsigned int, unsigned int>> lsKeys;
424  lsKeys.clear();
425 
426  //Constructing nBlocks IOVs
427  for(unsigned iKey=0; iKey<nBlocks; iKey++){
428  lsKeys.push_back(std::make_pair(lumiSections[(unsigned int)(iKey*nLSPerBlock)], lumiSections[(unsigned int)((iKey+1)*nLSPerBlock)-1]));
429  }
430 
431  lsKeys[0].first=1;
432 
433  for(unsigned int lumiSection=0; lumiSection<lumiSections.size(); lumiSection++){
434  thisLS=lumiSections[lumiSection];
435 
436  std::pair<unsigned int,unsigned int> lsKey;
437 
438  bool foundKey=false;
439 
440  for(unsigned iKey=0; iKey<nBlocks; iKey++){
441  if( (thisLS >= lsKeys[iKey].first) && (thisLS<= lsKeys[iKey].second) ){
442  lsKey=lsKeys[iKey];
443  foundKey=true;
444  break;
445  }
446  }
447 
448  if(!foundKey){
449  edm::LogInfo("WARNING")<<"Didn't find key "<<thisLS;
450  continue;
451  }
452 
453  if(lumiInfoMap.count( lsKey ) == 0 ) {
454  lumiInfoMap[lsKey] = new LumiInfo();
455  }
456 
457  //Sum all lumi in IOV of lsKey
458  totalLumiByBX_=lumiInfoMap[lsKey]->getInstLumiAllBX();
459  events_ =lumiInfoMap[lsKey]->getErrorLumiAllBX();
460 
461  rawlumiBX_ =lumiInfoMapPerLS[thisLS]->getInstLumiAllBX();
462  errOnLumiByBX_=lumiInfoMapPerLS[thisLS]->getErrorLumiAllBX();
463 
464  for(unsigned int bx=0;bx<LumiConstants::numBX;bx++){
465  totalLumiByBX_[bx]+=rawlumiBX_[bx];
466  events_[bx]+=errOnLumiByBX_[bx];
467  }
468  lumiInfoMap[lsKey]->setInstLumiAllBX(totalLumiByBX_);
469  lumiInfoMap[lsKey]->setErrorLumiAllBX(events_);
470  lumiInfoCounter[lsKey]++;
471  }
472 
473 
474  cond::Time_t thisIOV = 1;
475 
476  char *histname1 = new char[100];
477  char *histname2 = new char[100];
478  char *histname3 = new char[100];
479  char *histTitle1 = new char[100];
480  char *histTitle2 = new char[100];
481  char *histTitle3 = new char[100];
482  sprintf(histTitle1,"Type1Fraction_%d",runSeg.run());
483  sprintf(histTitle2,"Type1Res_%d",runSeg.run());
484  sprintf(histTitle3,"Type2Res_%d",runSeg.run());
485  type1FracHist = new TH1F(histTitle1,histTitle1,1000,-0.5,0.5);
486  type1resHist = new TH1F(histTitle2,histTitle2,4000,-0.2,0.2);
487  type2resHist = new TH1F(histTitle3,histTitle3,4000,-0.2,0.2);
488  delete[] histTitle1;
489  delete[] histTitle2;
490  delete[] histTitle3;
491 
493 
494  totalLumiByBX_=lumiInfoMapIterator->second->getInstLumiAllBX();
495  events_=lumiInfoMapIterator->second->getErrorLumiAllBX();
496 
497  if(events_.empty()){
498  continue;
499  }
500 
502  thisIOV = (cond::Time_t)(lu.value());
503 
504  sprintf(histname1, "CorrectedLumiAvg_%d_%d_%d_%d",runSeg.run(),iBlock,lumiInfoMapIterator->first.first,lumiInfoMapIterator->first.second);
505  sprintf(histname2, "ScaleFactorsAvg_%d_%d_%d_%d",runSeg.run(),iBlock,lumiInfoMapIterator->first.first,lumiInfoMapIterator->first.second);
506  sprintf(histname3, "RawLumiAvg_%d_%d_%d_%d",runSeg.run(),iBlock,lumiInfoMapIterator->first.first,lumiInfoMapIterator->first.second);
507 
508  corrlumiAvg_h = new TH1F(histname1,"",LumiConstants::numBX,1,LumiConstants::numBX);
509  scaleFactorAvg_h= new TH1F(histname2,"",LumiConstants::numBX,1,LumiConstants::numBX);
510  lumiAvg_h = new TH1F(histname3,"",LumiConstants::numBX,1,LumiConstants::numBX);
511 
512 
513  //Averaging by the number of events
514  for(unsigned int i=0;i<LumiConstants::numBX;i++){
515  if(events_.at(i)!=0){
517  }else{
518  totalLumiByBXAvg_[i]=0.0;
519  }
520  }
521 
523 
524  for(unsigned int bx=0;bx<LumiConstants::numBX;bx++){
525  corrlumiAvg_h->SetBinContent(bx,totalLumiByBXAvg_[bx]*correctionScaleFactors_[bx]);
526  if(events_.at(bx)!=0){
527  corrlumiAvg_h->SetBinError(bx,totalLumiByBXAvg_[bx]*correctionScaleFactors_[bx]/TMath::Sqrt(events_.at(bx)));
528  }else{
529  corrlumiAvg_h->SetBinError(bx,0.0);
530  }
531 
532  scaleFactorAvg_h->SetBinContent(bx,correctionScaleFactors_[bx]);
533  lumiAvg_h->SetBinContent(bx,totalLumiByBXAvg_[bx]);
534  }
535 
536  //Writing the corrections to SQL lite file for db
543 
544 
545  if( poolDbService.isAvailable() ){
546  poolDbService->writeOne<LumiCorrections>(pccCorrections,thisIOV,"LumiCorrectionsRcd");
547  }
548  else{
549  throw std::runtime_error("PoolDBService required.");
550  }
551 
552  delete pccCorrections;
553 
554  histoFile->cd();
555  corrlumiAvg_h->Write();
556  scaleFactorAvg_h->Write();
557  lumiAvg_h->Write();
558 
559  delete corrlumiAvg_h;
560  delete scaleFactorAvg_h;
561  delete lumiAvg_h;
562 
563  type1FracHist->Fill(type1Frac);
566 
567  for(unsigned int ils=lumiInfoMapIterator->first.first;ils<lumiInfoMapIterator->first.second+1;ils++){
568  if(ils>maxLS){
569  std::cout<<"ils out of maxLS range!!"<<std::endl;
570  break;
571  }
578  }
579 
580 
581  type1FracGraph->SetPoint(iBlock,thisIOV+approxLumiBlockSize_/2.0,type1Frac);
587 
588  edm::LogInfo("INFO") <<"iBlock type1Frac mean_type1_residual mean_type2_residual mean_type1_residual_unc mean_type2_residual_unc "<<iBlock<<" "<<type1Frac<<" "<<mean_type1_residual<<" "<<mean_type2_residual<<" "<<mean_type1_residual_unc<<" "<<mean_type2_residual_unc;
589 
590  type1Frac=0.0;
594  mean_type2_residual_unc=0;
595 
596  iBlock++;
597 
598  resetBlock();
599  }
600  histoFile->cd();
601  type1FracHist->Write();
602  type1resHist->Write();
603  type2resHist->Write();
604 
605  delete type1FracHist;
606  delete type1resHist;
607  delete type2resHist;
608 
609  delete[] histname1;
610  delete[] histname2;
611  delete[] histname3;
612 
614  delete lumiInfoMapIterator->second;
615  }
616  for(unsigned int lumiSection=0; lumiSection<lumiSections.size(); lumiSection++){
617  thisLS=lumiSections[lumiSection];
618  delete lumiInfoMapPerLS[thisLS];
619  }
620  lumiInfoMap.clear();
621  lumiInfoMapPerLS.clear();
622  lumiSections.clear();
623  lumiInfoCounter.clear();
624 }
std::vector< float > events_
void calculateCorrections(std::vector< float >, std::vector< float > &, float &)
MonitorElement * Type1FracMon
void setBinContent(int binx, double content)
set content of bin (1-D)
RunID const & id() const
Definition: RunBase.h:39
RunNumber_t run() const
Definition: RunBase.h:40
void setType1Fraction(float type1frac)
RunNumber_t run() const
Definition: RunID.h:39
std::map< std::pair< unsigned int, unsigned int >, LumiInfo * >::iterator lumiInfoMapIterator
void setOverallCorrection(float overallCorrection)
static const unsigned int numBX
Definition: LumiConstants.h:9
unsigned int iBlock
unsigned int LuminosityBlockNumber_t
MonitorElement * Type1ResMon
unsigned long long Time_t
Definition: Time.h:16
std::vector< float > totalLumiByBXAvg_
TGraphErrors * type1resGraph
std::map< std::pair< unsigned int, unsigned int >, LumiInfo * > lumiInfoMap
LumiCorrections * pccCorrections
bool isAvailable() const
Definition: Service.h:46
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
std::vector< float > correctionScaleFactors_
void setType2Residual(float type2res)
std::vector< unsigned int > lumiSections
TGraphErrors * type2resGraph
std::vector< float > rawlumiBX_
std::vector< float > totalLumiByBX_
edm::Service< cond::service::PoolDBOutputService > poolDbService
TGraphErrors * type1FracGraph
unsigned int approxLumiBlockSize_
unsigned int maxLS
void setType1Residual(float type1res)
std::map< std::pair< unsigned int, unsigned int >, unsigned int > lumiInfoCounter
std::vector< float > errOnLumiByBX_
MonitorElement * Type2ResMon
void setCorrectionsBX(std::vector< float > &correctBX)
unsigned int thisLS
std::map< unsigned int, LumiInfo * > lumiInfoMapPerLS
void CorrPCCProducer::estimateType1Frac ( std::vector< float >  uncorrPCCPerBX,
float &  type1Frac 
)
private

Definition at line 207 of file CorrPCCProducer.cc.

References correctionTemplate_, evaluateCorrectionResiduals(), mps_fire::i, gen::k, mean_type1_residual, and LumiConstants::numBX.

Referenced by calculateCorrections().

207  {
208  std::vector<float> corrected_tmp_;
209  for(size_t i=0; i<uncorrPCCPerBX.size(); i++){
210  corrected_tmp_.push_back(uncorrPCCPerBX.at(i));
211  }
212 
213 
214  //Apply initial type 1 correction
215  for(size_t k=0;k<LumiConstants::numBX-1; k++){
216  float bin_k = corrected_tmp_.at(k);
217  corrected_tmp_.at(k+1)=corrected_tmp_.at(k+1)-type1Frac*bin_k;
218  }
219 
220 
221  //Apply type 2 correction
222  for(size_t i=0; i<LumiConstants::numBX-1; i++){
223  for(size_t j=i+1; j<i+LumiConstants::numBX-1; j++){
224  float bin_i = corrected_tmp_.at(i);
225  if (j<LumiConstants::numBX){
226  corrected_tmp_.at(j)=corrected_tmp_.at(j)-bin_i*correctionTemplate_.at(j-i);
227  } else {
228  corrected_tmp_.at(j-LumiConstants::numBX) = corrected_tmp_.at(j-LumiConstants::numBX)-bin_i*correctionTemplate_.at(j-i);
229  }
230  }
231  }
232 
233  //Apply additional iteration for type 1 correction
234  evaluateCorrectionResiduals(corrected_tmp_);
236 }
static const unsigned int numBX
Definition: LumiConstants.h:9
void evaluateCorrectionResiduals(std::vector< float >)
std::vector< float > correctionTemplate_
int k[5][pyjets_maxn]
void CorrPCCProducer::evaluateCorrectionResiduals ( std::vector< float >  corrected_tmp_)
private

Definition at line 240 of file CorrPCCProducer.cc.

References getMaximum(), histoFile, mean_type1_residual, mean_type1_residual_unc, mean_type2_residual, mean_type2_residual_unc, nTrain, LumiConstants::numBX, and electronIdCutBased_cfi::threshold.

Referenced by calculateCorrections(), and estimateType1Frac().

240  {
241  float lumiMax = getMaximum(corrected_tmp_);
242  float threshold = lumiMax*0.2;
243 
244  mean_type1_residual = 0;
245  mean_type2_residual = 0;
246  nTrain = 0;
247  float lumi=0;
248  std::vector<float> afterGlow;
249  TH1F type1("type1","",1000,-0.5,0.5);
250  TH1F type2("type2","",1000,-0.5,0.5);
251  for(size_t ibx=2; ibx<LumiConstants::numBX-5; ibx++){
252  lumi = corrected_tmp_.at(ibx);
253  afterGlow.clear();
254  afterGlow.push_back(corrected_tmp_.at(ibx+1));
255  afterGlow.push_back(corrected_tmp_.at(ibx+2));
256 
257  //Where type 1 and type 2 residuals are computed
258  if(lumi>threshold && afterGlow[0]<threshold && afterGlow[1]<threshold){
259  for(int index=3; index<6; index++){
260  float thisAfterGlow=corrected_tmp_.at(ibx+index);
261  if(thisAfterGlow<threshold){
262  afterGlow.push_back(thisAfterGlow);
263  } else {
264  break;
265  }
266  }
267  float thisType1=0;
268  float thisType2=0;
269  if(afterGlow.size()>1){
270  int nAfter=0;
271  for(unsigned int index=1; index<afterGlow.size(); index++){
272  thisType2+=afterGlow[index];
273  type2.Fill(afterGlow[index]/lumi);
274  nAfter++;
275  }
276  thisType2/=nAfter;
277  }
278  thisType1=(afterGlow[0]-thisType2)/lumi;
279 
280  type1.Fill(thisType1);
281  nTrain+=1;
282  }
283  }
284 
285  mean_type1_residual=type1.GetMean();//Calculate the mean value of the type 1 residual
286  mean_type2_residual=type2.GetMean();//Calculate the mean value of the type 2 residual
287  mean_type1_residual_unc=type1.GetMeanError();
288  mean_type2_residual_unc=type2.GetMeanError();
289 
290  histoFile->cd();
291  type1.Write();
292  type2.Write();
293 }
unsigned int nTrain
static const unsigned int numBX
Definition: LumiConstants.h:9
float getMaximum(std::vector< float >)
float CorrPCCProducer::getMaximum ( std::vector< float >  lumi_vector)
private

Definition at line 194 of file CorrPCCProducer.cc.

References mps_fire::i.

Referenced by calculateCorrections(), and evaluateCorrectionResiduals().

194  {
195  float max_lumi=0;
196  for(size_t i=0; i<lumi_vector.size(); i++){
197  if(lumi_vector.at(i)>max_lumi) max_lumi = lumi_vector.at(i);
198  }
199  return max_lumi;
200 }
void CorrPCCProducer::makeCorrectionTemplate ( )
private

Definition at line 186 of file CorrPCCProducer.cc.

References correctionTemplate_, JetChargeProducer_cfi::exp, LumiConstants::numBX, type2_a_, and type2_b_.

Referenced by CorrPCCProducer().

186  {
187  for(unsigned int bx=1;bx<LumiConstants::numBX;bx++){
188  correctionTemplate_.at(bx)=type2_a_*exp(-(float(bx)-1)*type2_b_);
189  }
190 }
static const unsigned int numBX
Definition: LumiConstants.h:9
std::vector< float > correctionTemplate_
void CorrPCCProducer::resetBlock ( )
private

Definition at line 627 of file CorrPCCProducer.cc.

References correctionScaleFactors_, events_, LumiConstants::numBX, totalLumiByBX_, and totalLumiByBXAvg_.

Referenced by CorrPCCProducer(), and endRunProduce().

627  {
628  for(unsigned int bx=0;bx<LumiConstants::numBX;bx++){
629  totalLumiByBX_[bx]=0;
630  totalLumiByBXAvg_[bx]=0;
631  events_[bx]=0;
632  correctionScaleFactors_[bx]=1.0;
633  }
634 }
std::vector< float > events_
static const unsigned int numBX
Definition: LumiConstants.h:9
std::vector< float > totalLumiByBXAvg_
std::vector< float > correctionScaleFactors_
std::vector< float > totalLumiByBX_

Member Data Documentation

unsigned int CorrPCCProducer::approxLumiBlockSize_
private

Definition at line 124 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), and endRunProduce().

std::vector<float> CorrPCCProducer::correctionScaleFactors_
private

Definition at line 87 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), endRunProduce(), and resetBlock().

std::vector<float> CorrPCCProducer::correctionTemplate_
private
TH1F* CorrPCCProducer::corrlumiAvg_h
private

Definition at line 99 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

unsigned int CorrPCCProducer::countLumi_
private

Definition at line 123 of file CorrPCCProducer.cc.

Referenced by beginLuminosityBlock(), and CorrPCCProducer().

std::vector<float> CorrPCCProducer::errOnLumiByBX_
private

Definition at line 82 of file CorrPCCProducer.cc.

Referenced by endLuminosityBlock(), and endRunProduce().

std::vector<float> CorrPCCProducer::events_
private

Definition at line 85 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), endLuminosityBlock(), endRunProduce(), and resetBlock().

TFile* CorrPCCProducer::histoFile
private
TList* CorrPCCProducer::hlist
private

Definition at line 114 of file CorrPCCProducer.cc.

unsigned int CorrPCCProducer::iBlock =0
private

Definition at line 90 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

TH1F* CorrPCCProducer::lumiAvg_h
private

Definition at line 101 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

std::map<std::pair<unsigned int,unsigned int>, unsigned int> CorrPCCProducer::lumiInfoCounter
private

Definition at line 97 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

std::map<std::pair<unsigned int,unsigned int>, LumiInfo*> CorrPCCProducer::lumiInfoMap
private

Definition at line 96 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

std::map<std::pair<unsigned int,unsigned int>, LumiInfo*>::iterator CorrPCCProducer::lumiInfoMapIterator
private

Definition at line 95 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

std::map<unsigned int, LumiInfo*> CorrPCCProducer::lumiInfoMapPerLS
private

Definition at line 93 of file CorrPCCProducer.cc.

Referenced by endLuminosityBlock(), and endRunProduce().

edm::EDGetTokenT<LumiInfo> CorrPCCProducer::lumiInfoToken
private

Definition at line 77 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), and endLuminosityBlock().

std::vector<unsigned int> CorrPCCProducer::lumiSections
private

Definition at line 94 of file CorrPCCProducer.cc.

Referenced by endLuminosityBlock(), and endRunProduce().

unsigned int CorrPCCProducer::maxLS =3500
private

Definition at line 106 of file CorrPCCProducer.cc.

Referenced by bookHistograms(), and endRunProduce().

float CorrPCCProducer::mean_type1_residual
private
float CorrPCCProducer::mean_type1_residual_unc
private

Definition at line 120 of file CorrPCCProducer.cc.

Referenced by endRunProduce(), and evaluateCorrectionResiduals().

float CorrPCCProducer::mean_type2_residual
private

Definition at line 119 of file CorrPCCProducer.cc.

Referenced by endRunProduce(), and evaluateCorrectionResiduals().

float CorrPCCProducer::mean_type2_residual_unc
private

Definition at line 121 of file CorrPCCProducer.cc.

Referenced by endRunProduce(), and evaluateCorrectionResiduals().

unsigned int CorrPCCProducer::minimumNumberOfEvents
private

Definition at line 91 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), and endLuminosityBlock().

unsigned int CorrPCCProducer::nTrain
private

Definition at line 122 of file CorrPCCProducer.cc.

Referenced by evaluateCorrectionResiduals().

float CorrPCCProducer::overallCorrection_
private

Definition at line 88 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

LumiCorrections* CorrPCCProducer::pccCorrections
private

Definition at line 131 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

std::string CorrPCCProducer::pccSrc_
private

Definition at line 78 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer().

edm::Service<cond::service::PoolDBOutputService> CorrPCCProducer::poolDbService
private

Definition at line 133 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

std::string CorrPCCProducer::prodInst_
private

Definition at line 79 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer().

std::vector<float> CorrPCCProducer::rawlumiBX_
private

Definition at line 81 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

TH1F* CorrPCCProducer::scaleFactorAvg_h
private

Definition at line 100 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

unsigned int CorrPCCProducer::thisLS
private

Definition at line 125 of file CorrPCCProducer.cc.

Referenced by endLuminosityBlock(), and endRunProduce().

std::vector<float> CorrPCCProducer::totalLumiByBX_
private

Definition at line 83 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), endLuminosityBlock(), endRunProduce(), and resetBlock().

std::vector<float> CorrPCCProducer::totalLumiByBXAvg_
private

Definition at line 84 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), endRunProduce(), and resetBlock().

float CorrPCCProducer::type1Frac
private

Definition at line 117 of file CorrPCCProducer.cc.

Referenced by calculateCorrections(), and endRunProduce().

TGraphErrors* CorrPCCProducer::type1FracGraph
private

Definition at line 111 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), endJob(), and endRunProduce().

TH1F* CorrPCCProducer::type1FracHist
private

Definition at line 102 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

MonitorElement* CorrPCCProducer::Type1FracMon
private

Definition at line 107 of file CorrPCCProducer.cc.

Referenced by bookHistograms(), and endRunProduce().

TGraphErrors* CorrPCCProducer::type1resGraph
private

Definition at line 112 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), endJob(), and endRunProduce().

TH1F* CorrPCCProducer::type1resHist
private

Definition at line 103 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

MonitorElement* CorrPCCProducer::Type1ResMon
private

Definition at line 108 of file CorrPCCProducer.cc.

Referenced by bookHistograms(), and endRunProduce().

double CorrPCCProducer::type2_a_
private

Definition at line 127 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), and makeCorrectionTemplate().

double CorrPCCProducer::type2_b_
private

Definition at line 128 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), and makeCorrectionTemplate().

TGraphErrors* CorrPCCProducer::type2resGraph
private

Definition at line 113 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), endJob(), and endRunProduce().

TH1F* CorrPCCProducer::type2resHist
private

Definition at line 104 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

MonitorElement* CorrPCCProducer::Type2ResMon
private

Definition at line 109 of file CorrPCCProducer.cc.

Referenced by bookHistograms(), and endRunProduce().