CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Private Attributes
popcon::EcalPedestalsHandler Class Reference

#include <EcalPedestalsHandler.h>

Inheritance diagram for popcon::EcalPedestalsHandler:
popcon::PopConSourceHandler< EcalPedestals >

Public Member Functions

bool checkPedestal (EcalPedestals::Item *item)
 
 EcalPedestalsHandler (edm::ParameterSet const &)
 
void getNewObjects () override
 
void getNewObjectsH2 ()
 
void getNewObjectsP5 ()
 
std::string id () const override
 
void readPedestal2017 ()
 
void readPedestalFile ()
 
void readPedestalMC ()
 
void readPedestalTimestamp ()
 
void readPedestalTree ()
 
 ~EcalPedestalsHandler () override
 
- Public Member Functions inherited from popcon::PopConSourceHandler< EcalPedestals >
void convertFromOld ()
 
SummarydummySummary (typename OldContainer::value_type const &) const
 
void initialize (const cond::persistency::Session &dbSession, cond::TagInfo_t const &tagInfo, cond::LogDBEntry_t const &logDBEntry)
 
Ref lastPayload () const
 
cond::LogDBEntry_t const & logDBEntry () const
 
std::pair< Container const *, std::string const > operator() (const cond::persistency::Session &session, cond::TagInfo_t const &tagInfo, cond::LogDBEntry_t const &logDBEntry) const
 
 PopConSourceHandler ()
 
Container const & returnData ()
 
void sort ()
 
cond::TagInfo_t const & tagInfo () const
 
std::string const & userTextLog () const
 
virtual ~PopConSourceHandler ()
 

Public Attributes

EcalCondDBInterfaceeconn
 

Private Attributes

bool m_corrected
 
std::string m_filename
 
unsigned int m_firstRun
 
std::string m_gentag
 
unsigned int m_lastRun
 
std::string m_location
 
std::string m_locationsource
 
std::string m_name
 
std::string m_pass
 
std::string m_runtag
 
int m_runtype
 
std::string m_sid
 
std::string m_user
 
const EcalPedestalsmypedestals
 

Additional Inherited Members

- Public Types inherited from popcon::PopConSourceHandler< EcalPedestals >
typedef std::vector< Triplet > Container
 
typedef std::vector< std::pair< EcalPedestals *, cond::Time_t > > OldContainer
 
typedef PopConSourceHandler< EcalPedestalsself
 
typedef cond::Summary Summary
 
typedef cond::Time_t Time_t
 
typedef EcalPedestals value_type
 
- Protected Member Functions inherited from popcon::PopConSourceHandler< EcalPedestals >
int add (value_type *payload, Summary *summary, Time_t time)
 
cond::persistency::SessiondbSession () const
 
- Protected Attributes inherited from popcon::PopConSourceHandler< EcalPedestals >
OldContainer m_to_transfer
 
std::string m_userTextLog
 

Detailed Description

Definition at line 53 of file EcalPedestalsHandler.h.

Constructor & Destructor Documentation

popcon::EcalPedestalsHandler::EcalPedestalsHandler ( edm::ParameterSet const &  )

Definition at line 17 of file EcalPedestalsHandler.cc.

References edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), m_corrected, m_filename, m_firstRun, m_gentag, m_lastRun, m_location, m_locationsource, m_pass, m_runtag, m_runtype, m_sid, m_user, and AlCaHLTBitMon_QueryRunRegistry::string.

18  : m_name(ps.getUntrackedParameter<std::string>("name","EcalPedestalsHandler")) {
19  edm::LogInfo("EcalPedestals Source handler constructor\n");
20  m_firstRun=static_cast<unsigned int>(atoi( ps.getParameter<std::string>("firstRun").c_str()));
21  m_lastRun=static_cast<unsigned int>(atoi( ps.getParameter<std::string>("lastRun").c_str()));
22  m_sid= ps.getParameter<std::string>("OnlineDBSID");
23  m_user= ps.getParameter<std::string>("OnlineDBUser");
24  m_pass= ps.getParameter<std::string>("OnlineDBPassword");
25  m_locationsource= ps.getParameter<std::string>("LocationSource");
26  m_location=ps.getParameter<std::string>("Location");
27  m_gentag=ps.getParameter<std::string>("GenTag");
28  m_runtag=ps.getParameter<std::string>("RunTag");
29  m_filename = ps.getUntrackedParameter<std::string>("filename","EcalPedestals.txt");
30  m_runtype = ps.getUntrackedParameter<int>("RunType",1);
31  m_corrected = ps.getUntrackedParameter<bool>("corrected",false);
32 
33  edm::LogInfo("EcalPedestalsHandler")<<m_sid<<"/"<<"/"<<m_location<<"/"<<m_gentag;
34 
35 }
popcon::EcalPedestalsHandler::~EcalPedestalsHandler ( )
override

Definition at line 37 of file EcalPedestalsHandler.cc.

37 {}

Member Function Documentation

bool popcon::EcalPedestalsHandler::checkPedestal ( EcalPedestals::Item item)

Definition at line 69 of file EcalPedestalsHandler.cc.

References EcalPedestal::mean_x1, EcalPedestal::mean_x12, EcalPedestal::mean_x6, mps_fire::result, EcalPedestal::rms_x1, EcalPedestal::rms_x12, and EcalPedestal::rms_x6.

Referenced by getNewObjectsP5().

69  {
70  // true means all is standard and OK
71  bool result=true;
72  if(item->rms_x12 >3 || item->rms_x12<=0) result=false;
73  if(item->rms_x6 >2 || item->rms_x6<=0) result=false;
74  if(item->rms_x1 >1 || item->rms_x1<=0) result=false;
75  if(item->mean_x12>300 || item->mean_x12<=100) result=false;
76  if(item->mean_x1>300 || item->mean_x1<=100) result=false;
77  if(item->mean_x6>300 || item->mean_x6<=100) result=false;
78  return result;
79 }
void popcon::EcalPedestalsHandler::getNewObjects ( )
overridevirtual

Implements popcon::PopConSourceHandler< EcalPedestals >.

Definition at line 40 of file EcalPedestalsHandler.cc.

References cmsRelvalreport::exit, getNewObjectsH2(), getNewObjectsP5(), m_locationsource, readPedestal2017(), readPedestalFile(), readPedestalMC(), readPedestalTimestamp(), and readPedestalTree().

40  {
41  edm::LogInfo("------- Ecal - > getNewObjects\n");
42  if(m_locationsource=="P5") {
44  } else if(m_locationsource=="H2") {
46  }
47  else if(m_locationsource=="File") {
49  }
50  else if(m_locationsource=="MC") {
52  }
53  else if(m_locationsource=="2017") {
55  }
56  else if(m_locationsource=="Tree") {
58  }
59  else if(m_locationsource=="Timestamp") {
61  }
62  else {
63  edm::LogInfo(" unknown location ") << m_locationsource << " give up ";
64  exit(-1);
65  }
66 }
void popcon::EcalPedestalsHandler::getNewObjectsH2 ( )

Definition at line 458 of file EcalPedestalsHandler.cc.

References gather_cfg::cout, econn, EcalCondObjectContainer< T >::endcap(), Exception, EcalCondDBInterface::fetchDataSet(), EcalCondDBInterface::fetchMonRunList(), EcalLogicID::getID2(), MonPedestalsDat::getPedMeanG1(), MonPedestalsDat::getPedMeanG12(), MonPedestalsDat::getPedMeanG6(), MonPedestalsDat::getPedRMSG1(), MonPedestalsDat::getPedRMSG12(), MonPedestalsDat::getPedRMSG6(), MonRunList::getRuns(), EEDetId::hashedIndex(), EcalCondObjectContainer< T >::insert(), cond::TagInfo_t::lastInterval, popcon::PopConSourceHandler< EcalPedestals >::lastPayload(), m_lastRun, m_pass, m_sid, popcon::PopConSourceHandler< EcalPedestals >::m_to_transfer, m_user, EcalPedestal::mean_x1, EcalPedestal::mean_x12, EcalPedestal::mean_x6, AlCaHLTBitMon_ParallelJobs::p, DetId::rawId(), EcalPedestal::rms_x1, EcalPedestal::rms_x12, EcalPedestal::rms_x6, RunTag::setGeneralTag(), MonRunTag::setGeneralTag(), LocationDef::setLocation(), RunTag::setLocationDef(), MonVersionDef::setMonitoringVersion(), MonRunList::setMonRunTag(), MonRunTag::setMonVersionDef(), MonRunList::setRunTag(), RunTypeDef::setRunType(), RunTag::setRunTypeDef(), popcon::PopConSourceHandler< EcalPedestals >::tagInfo(), and EEDetId::validDetId().

Referenced by getNewObjects().

458  {
459  unsigned int max_since=0;
460  max_since=static_cast<unsigned int>(tagInfo().lastInterval.first);
461  edm::LogInfo("max_since : ") << max_since;
462  Ref ped_db = lastPayload();
463 
464  edm::LogInfo("retrieved last payload ");
465 
466 
467  // we copy the last valid record to a temporary object peds
468  EcalPedestals* peds = new EcalPedestals();
469 
470  // get from offline DB the last valid pedestal set ped_db
471  // edm::ESHandle<EcalPedestals> pedestals;
472  // esetup.get<EcalPedestalsRcd>().get(pedestals);
473 
474 
475  // only positive endcap side and
476  // x from 86 to 95
477  // y from 46 to 55
478  int ixmin=86; int ixmax=95;
479  int iymin=46; int iymax=55;
480  for(int iX=ixmin; iX<=ixmax ;++iX) {
481  for(int iY=iymin; iY<=iymax; ++iY) {
482 
483  if (EEDetId::validDetId(iX,iY,1)) {
484  EEDetId eedetidpos(iX,iY,1);
485  unsigned int hiee = eedetidpos.hashedIndex();
486  EcalPedestals::Item aped= ped_db->endcap(hiee);
487 
488  // here I copy the last valid value in the peds object
489  EcalPedestals::Item item;
490  item.mean_x1 = aped.mean_x1;
491  item.rms_x1 = aped.rms_x1;
492  item.mean_x6 = aped.mean_x6;
493  item.rms_x6 = aped.rms_x6;
494  item.mean_x12 = aped.mean_x12;
495  item.rms_x12 = aped.rms_x12;
496  peds->insert(std::make_pair(eedetidpos.rawId(),item));
497  if(iX==ixmin && iY==iymin) std::cout<<"ped12 " << item.mean_x12<< std::endl;
498 
499  }
500  }
501  }
502 
503 
504  edm::LogInfo("We just retrieved the last valid record from DB ");
505 
506 
507  // here we retrieve all the runs after the last from online DB
508 
509  edm::LogInfo("Retrieving run list from ONLINE DB ... ");
510 
511  edm::LogInfo("Making connection...") << std::flush;
513  edm::LogInfo("Done.");
514 
515  if (!econn)
516  {
517  edm::LogInfo(" connection parameters ") <<m_sid;
518  throw cms::Exception("OMDS not available");
519  }
520 
521  // these are the online conditions DB classes
522  RunList my_runlist ;
523  RunTag my_runtag;
524  LocationDef my_locdef;
525  RunTypeDef my_rundef;
526 
527  my_locdef.setLocation("H2_07");
528  my_rundef.setRunType("PEDESTAL");
529  my_runtag.setLocationDef(my_locdef);
530  my_runtag.setRunTypeDef(my_rundef);
531  my_runtag.setGeneralTag("LOCAL");
532 
533 
534  // here we retrieve the Monitoring run records
535 
536  MonVersionDef monverdef;
537  monverdef.setMonitoringVersion("test01");
538 
539  MonRunTag mon_tag;
540  mon_tag.setGeneralTag("CMSSW");
541  mon_tag.setMonVersionDef(monverdef);
542  MonRunList mon_list;
543  mon_list.setMonRunTag(mon_tag);
544  mon_list.setRunTag(my_runtag);
545  // mon_list=econn->fetchMonRunList(my_runtag, mon_tag);
546  unsigned int min_run=max_since+1; // we have to add 1 to the last transferred one
547 
548  unsigned int max_run=m_lastRun;
549  mon_list=econn->fetchMonRunList(my_runtag, mon_tag,min_run,max_run );
550 
551  std::vector<MonRunIOV> mon_run_vec= mon_list.getRuns();
552  size_t mon_runs=mon_run_vec.size();
553  edm::LogInfo("number of Mon runs is : ") << mon_runs;
554 
555  if(mon_runs>0){
556 
557  for(size_t kr=0; kr<mon_runs; kr++){
558 
559  unsigned int irun=static_cast<unsigned int>(mon_run_vec[kr].getRunIOV().getRunNumber());
560 
561  edm::LogInfo("here is first sub run : ") << mon_run_vec[kr].getSubRunNumber();
562  edm::LogInfo("here is the run number: ") << mon_run_vec[kr].getRunIOV().getRunNumber();
563 
564  edm::LogInfo(" retrieve the data for a given run");
565 
566  if (mon_run_vec[kr].getSubRunNumber() <=1){
567 
568 
569  // retrieve the data for a given run
570  RunIOV runiov_prime = mon_run_vec[kr].getRunIOV();
571 
572  // retrieve the pedestals from OMDS for this run
573  std::map<EcalLogicID, MonPedestalsDat> dataset_mon;
574  econn->fetchDataSet(&dataset_mon, &mon_run_vec[kr]);
575  std::cout <<"OMDS record for run "<<irun <<" is made of "<< dataset_mon.size() << std::endl;
576  typedef std::map<EcalLogicID, MonPedestalsDat>::const_iterator CImon;
577  EcalLogicID ecid_xt;
578  MonPedestalsDat rd_ped;
579 
580  //int iEta=0;
581  //int iPhi=0;
582  int ix=0;
583  int iy=0;
584 
585  for (CImon p = dataset_mon.begin(); p != dataset_mon.end(); p++) {
586  ecid_xt = p->first;
587  rd_ped = p->second;
588  //int sm_num=ecid_xt.getID1();
589  int xt_num=ecid_xt.getID2(); // careful here !!! we number the channels from 1 to 1700
590 
591  //iEta=(xt_num/20)+1;
592  //iPhi=20-(xt_num-(iEta-1)*20);
593 
594  ix=95-(xt_num-1)/20;
595  iy=46+(xt_num-1)%20;
596 
597 
598  EcalPedestals::Item item;
599  item.mean_x1 =rd_ped.getPedMeanG1() ;
600  item.rms_x1 =rd_ped.getPedRMSG1();
601  item.mean_x6 =rd_ped.getPedMeanG6();
602  item.rms_x6 =rd_ped.getPedRMSG6() ;
603  item.mean_x12 =rd_ped.getPedMeanG12();
604  item.rms_x12 =rd_ped.getPedRMSG12();
605 
606  EEDetId eedetidpos(ix,iy,1);
607  // EBDetId ebdetid(iEta,iPhi);
608 
609  // here we change in the peds object only the values that are available in the online DB
610  // otherwise we keep the old value
611 
612  peds->insert(std::make_pair(eedetidpos.rawId(),item));
613  if(ix==ixmin && iy==iymin) std::cout<<"ped12 " << item.mean_x12<< std::endl;
614  }
615 
616  edm::LogInfo("Generating popcon record for run ") << irun << "..." << std::flush;
617 
618 
619  // now I copy peds in pedtemp and I ship pedtemp to popcon
620  // if I use always the same peds I always overwrite
621  // so I really have to create new objects for each new run
622  // popcon deletes everything for me
623 
624  EcalPedestals* pedtemp = new EcalPedestals();
625 
626 
627  for(int iX=ixmin; iX<=ixmax ;++iX) {
628  for(int iY=iymin; iY<=iymax; ++iY) {
629 
630  if (EEDetId::validDetId(iX,iY,1))
631  {
632  EEDetId eedetidpos(iX,iY,1);
633  unsigned int hiee = eedetidpos.hashedIndex();
634  EcalPedestals::Item aped = peds->endcap(hiee);
635 
636  EcalPedestals::Item item;
637  item.mean_x1 = aped.mean_x1;
638  item.rms_x1 = aped.rms_x1;
639  item.mean_x6 = aped.mean_x6;
640  item.rms_x6 = aped.rms_x6;
641  item.mean_x12 = aped.mean_x12;
642  item.rms_x12 = aped.rms_x12;
643  // here I copy the last valid value in the pedtemp object
644  pedtemp->insert(std::make_pair(eedetidpos.rawId(),item));
645  if(iX==ixmin && iY==iymin) std::cout<<"ped12 " << item.mean_x12<< std::endl;
646  }
647  }
648  }
649 
650 
651 
652  Time_t snc= (Time_t) irun ;
653 
654  m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedtemp,snc));
655 
656  edm::LogInfo("Ecal - > end of getNewObjectsH2 -----------\n");
657 
658  }
659  }
660  }
661  delete econn;
662  delete peds; // this is the only one that popcon does not delete
663 }
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:70
Definition: RunTag.h:13
float getPedRMSG1() const
MonRunList fetchMonRunList(const RunTag &tag, const MonRunTag &monruntag) noexcept(false)
void setGeneralTag(std::string tag)
Definition: MonRunTag.cc:33
void fetchDataSet(std::map< EcalLogicID, DATT > *fillMap, IOVT *iov) noexcept(false)
void setRunTag(const RunTag &tag)
Definition: MonRunList.cc:23
int getID2() const
Definition: EcalLogicID.cc:51
cond::ValidityInterval lastInterval
Definition: Types.h:76
float getPedMeanG12() const
float getPedRMSG12() const
void setMonVersionDef(const MonVersionDef &ver)
Definition: MonRunTag.cc:49
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:53
void insert(std::pair< uint32_t, Item > const &a)
std::vector< MonRunIOV > getRuns()
Definition: MonRunList.cc:46
EcalPedestalsMap EcalPedestals
Definition: EcalPedestals.h:53
void setRunType(std::string runtype)
Definition: RunTypeDef.cc:33
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
void setMonRunTag(const MonRunTag &tag)
Definition: MonRunList.cc:29
float getPedMeanG1() const
void setMonitoringVersion(std::string ver)
float getPedMeanG6() const
void setLocation(std::string loc)
Definition: LocationDef.cc:33
void setGeneralTag(std::string tag)
Definition: RunTag.cc:36
const Item & endcap(size_t hashedIndex) const
Definition: RunIOV.h:13
float getPedRMSG6() const
void popcon::EcalPedestalsHandler::getNewObjectsP5 ( )

Definition at line 83 of file EcalPedestalsHandler.cc.

References EcalCondObjectContainer< T >::barrel(), checkPedestal(), gather_cfg::cout, econn, EcalCondObjectContainer< T >::endcap(), EBDetId::ETAPHIMODE, EcalCondDBInterface::fetchDataSet(), EcalCondDBInterface::fetchMonRunList(), EcalLogicID::getID1(), EcalLogicID::getID2(), EcalLogicID::getID3(), EcalLogicID::getName(), MonPedestalsDat::getPedMeanG1(), MonPedestalsDat::getPedMeanG12(), MonPedestalsDat::getPedMeanG6(), MonPedestalsDat::getPedRMSG1(), MonPedestalsDat::getPedRMSG12(), MonPedestalsDat::getPedRMSG6(), MonRunList::getRuns(), EBDetId::hashedIndex(), EEDetId::hashedIndex(), EcalCondObjectContainer< T >::insert(), EEDetId::IX_MAX, EEDetId::IX_MIN, EEDetId::IY_MAX, EEDetId::IY_MIN, cond::TagInfo_t::lastInterval, popcon::PopConSourceHandler< EcalPedestals >::lastPayload(), m_firstRun, m_gentag, m_lastRun, m_location, m_pass, m_runtag, m_sid, popcon::PopConSourceHandler< EcalPedestals >::m_to_transfer, m_user, popcon::PopConSourceHandler< EcalPedestals >::m_userTextLog, EBDetId::MAX_IETA, EBDetId::MAX_IPHI, EcalPedestal::mean_x1, EcalPedestal::mean_x12, EcalPedestal::mean_x6, min(), EBDetId::MIN_IPHI, AlCaHLTBitMon_ParallelJobs::p, DetId::rawId(), EcalPedestal::rms_x1, EcalPedestal::rms_x12, EcalPedestal::rms_x6, RunTag::setGeneralTag(), MonRunTag::setGeneralTag(), LocationDef::setLocation(), RunTag::setLocationDef(), MonVersionDef::setMonitoringVersion(), MonRunList::setMonRunTag(), MonRunTag::setMonVersionDef(), MonRunList::setRunTag(), RunTypeDef::setRunType(), RunTag::setRunTypeDef(), EBDetId::SMCRYSTALMODE, popcon::PopConSourceHandler< EcalPedestals >::tagInfo(), EBDetId::validDetId(), EEDetId::validDetId(), and x.

Referenced by getNewObjects().

83  {
84  std::ostringstream ss;
85  ss<<"ECAL ";
86 
87  unsigned int max_since=0;
88  max_since=static_cast<unsigned int>(tagInfo().lastInterval.first);
89  edm::LogInfo("max_since : ") << max_since;
90  Ref ped_db = lastPayload();
91 
92  // we copy the last valid record to a temporary object peds
93  EcalPedestals* peds = new EcalPedestals();
94  edm::LogInfo("retrieved last payload ");
95 
96  for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
97  if(iEta==0) continue;
98  for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
99  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
100  if (EBDetId::validDetId(iEta,iPhi)) {
101  EBDetId ebdetid(iEta,iPhi,EBDetId::ETAPHIMODE);
102  EcalPedestals::const_iterator it =ped_db->find(ebdetid.rawId());
103  EcalPedestals::Item aped = (*it);
104 
105  // here I copy the last valid value in the peds object
106  EcalPedestals::Item item;
107  item.mean_x1 = aped.mean_x1;
108  item.rms_x1 = aped.rms_x1;
109  item.mean_x6 = aped.mean_x6;
110  item.rms_x6 = aped.rms_x6;
111  item.mean_x12 = aped.mean_x12;
112  item.rms_x12 = aped.rms_x12;
113 
114  peds->insert(std::make_pair(ebdetid.rawId(),item));
115  }
116  }
117  }
118 
119  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
120  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
121  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
122  if (EEDetId::validDetId(iX,iY,1)) {
123  EEDetId eedetidpos(iX,iY,1);
124 
125  EcalPedestals::const_iterator it =ped_db->find(eedetidpos.rawId());
126  EcalPedestals::Item aped = (*it);
127 
128  // unsigned int hiee = eedetidpos.hashedIndex();
129  // EcalPedestals::Item aped= ped_db->endcap(hiee);
130 
131  // here I copy the last valid value in the peds object
132  EcalPedestals::Item item;
133  item.mean_x1 = aped.mean_x1;
134  item.rms_x1 = aped.rms_x1;
135  item.mean_x6 = aped.mean_x6;
136  item.rms_x6 = aped.rms_x6;
137  item.mean_x12 = aped.mean_x12;
138  item.rms_x12 = aped.rms_x12;
139  peds->insert(std::make_pair(eedetidpos.rawId(),item));
140  }
141  if(EEDetId::validDetId(iX,iY,-1)) {
142  EEDetId eedetidneg(iX,iY,-1);
143 
144  EcalPedestals::const_iterator it =ped_db->find(eedetidneg.rawId());
145  EcalPedestals::Item aped = (*it);
146  // unsigned int hiee = eedetidneg.hashedIndex();
147  // EcalPedestals::Item aped= ped_db->endcap(hiee);
148 
149  // here I copy the last valid value in the peds object
150  EcalPedestals::Item item;
151  item.mean_x1 = aped.mean_x1;
152  item.rms_x1 = aped.rms_x1;
153  item.mean_x6 = aped.mean_x6;
154  item.rms_x6 = aped.rms_x6;
155  item.mean_x12 = aped.mean_x12;
156  item.rms_x12 = aped.rms_x12;
157  peds->insert(std::make_pair(eedetidneg.rawId(),item));
158  }
159  }
160  }
161 
162  // here we retrieve all the runs after the last from online DB
163 
164  edm::LogInfo("Retrieving run list from ONLINE DB ... ");
166  edm::LogInfo("Connection done");
167 
168  // these are the online conditions DB classes
169  RunList my_runlist ;
170  RunTag my_runtag;
171  LocationDef my_locdef;
172  RunTypeDef my_rundef;
173 
174  my_locdef.setLocation(m_location);
175  // my_rundef.setRunType("PEDESTAL"); // 2017
176  my_rundef.setRunType(m_runtag);
177  my_runtag.setLocationDef(my_locdef);
178  my_runtag.setRunTypeDef(my_rundef);
179  my_runtag.setGeneralTag(m_gentag);
180 
181  // here we retrieve the Monitoring run records
182 
183  MonVersionDef monverdef;
184  monverdef.setMonitoringVersion("test01");
185 
186  MonRunTag mon_tag;
187  // mon_tag.setGeneralTag("CMSSW");
188  mon_tag.setGeneralTag("CMSSW-offline-private");
189  mon_tag.setMonVersionDef(monverdef);
190  MonRunList mon_list;
191  mon_list.setMonRunTag(mon_tag);
192  mon_list.setRunTag(my_runtag);
193  // mon_list=econn->fetchMonRunList(my_runtag, mon_tag);
194  unsigned int min_run=0;
195  if(m_firstRun<max_since) {
196  min_run=max_since+1; // we have to add 1 to the last transferred one
197  } else {
198  min_run=m_firstRun;
199  }
200 
201  unsigned int max_run=m_lastRun;
202  mon_list=econn->fetchMonRunList(my_runtag, mon_tag,min_run,max_run );
203 
204  std::vector<MonRunIOV> mon_run_vec= mon_list.getRuns();
205  int mon_runs = mon_run_vec.size();
206  edm::LogInfo("number of Mon runs is : ")<< mon_runs;
207 
208  if(mon_runs > 0) {
209  int krmax = std::min(mon_runs, 30);
210  for(int kr = 0; kr < krmax; kr++){
211  edm::LogInfo("-kr------: ")<<kr;
212 
213  unsigned int irun=static_cast<unsigned int>(mon_run_vec[kr].getRunIOV().getRunNumber());
214  edm::LogInfo("retrieve the data for run number: ")<< mon_run_vec[kr].getRunIOV().getRunNumber();
215  if (mon_run_vec[kr].getSubRunNumber() <=1){
216 
217  // retrieve the data for a given run
218  RunIOV runiov_prime = mon_run_vec[kr].getRunIOV();
219  // retrieve the pedestals from OMDS for this run
220  std::map<EcalLogicID, MonPedestalsDat> dataset_mon;
221  econn->fetchDataSet(&dataset_mon, &mon_run_vec[kr]);
222  edm::LogInfo("OMDS record for run ")<<irun <<" is made of "<< dataset_mon.size();
223  int nEB = 0, nEE = 0, nEBbad = 0, nEEbad =0;
224  typedef std::map<EcalLogicID, MonPedestalsDat>::const_iterator CImon;
225  EcalLogicID ecid_xt;
226  MonPedestalsDat rd_ped;
227 
228  // this to validate ...
229  int nbad=0;
230  for (CImon p = dataset_mon.begin(); p != dataset_mon.end(); p++) {
231  ecid_xt = p->first;
232  rd_ped = p->second;
233  int sm_num=ecid_xt.getID1();
234  int xt_num=ecid_xt.getID2();
235  int yt_num=ecid_xt.getID3();
236 
237  EcalPedestals::Item item;
238  item.mean_x1 =rd_ped.getPedMeanG1() ;
239  item.rms_x1 =rd_ped.getPedRMSG1();
240  item.mean_x6 =rd_ped.getPedMeanG6();
241  item.rms_x6 =rd_ped.getPedRMSG6() ;
242  item.mean_x12 =rd_ped.getPedMeanG12();
243  item.rms_x12 =rd_ped.getPedRMSG12();
244  /*
245  if(irun != 280216 && irun != 280218 && irun != 280259 && irun != 280261 && irun != 280392 && irun != 280394
246  && irun != 280762 && irun != 280765 && irun != 280936 && irun != 280939 && irun != 281756 && irun != 281757) {
247  */
248  if(ecid_xt.getName()=="EB_crystal_number") {
249  nEB++;
250  if(!checkPedestal(&item) ) nEBbad++;
251  }
252  else {
253  nEE++;
254  if(!checkPedestal(&item) ) nEEbad++;
255  }
256 
257  // here we check and count how many bad channels we have
258 
259  if(!checkPedestal(&item) ){
260  nbad++;
261  if(nbad < 10) std::cout <<"BAD LIST: channel " << sm_num << "/" << xt_num << "/"<< yt_num
262  << "ped/rms "<<item.mean_x12<< "/"<< item.rms_x12 << std::endl;
263  }
264  /*
265  }
266  else { // only gain 12 in these runs
267  if(ecid_xt.getName()=="EB_crystal_number") {
268  nEB++;
269  if(item.mean_x12 <= 100 || item.mean_x12 > 300 || item.rms_x12 > 3 || item.rms_x12 <= 0) {
270  nbad++;
271  nEBbad++;
272  }
273  }
274  else {
275  nEE++;
276  if(item.mean_x12 <= 100 || item.mean_x12 > 300 || item.rms_x12 > 3 || item.rms_x12 <= 0) {
277  nbad++;
278  nEEbad++;
279  }
280  }
281  } // only gain 12 in these runs
282  */
283  } // loop over all channels
284 
285  // ok or bad?
286  // a bad run is for more than 5% bad channels
287 
288  // if(nbad<(dataset_mon.size()*0.1)){
289  if(nbad<(dataset_mon.size()*0.05) && (nEB > 10200 || nEE > 2460)) {
290 
291  for (CImon p = dataset_mon.begin(); p != dataset_mon.end(); p++) {
292  ecid_xt = p->first;
293  rd_ped = p->second;
294  int sm_num=ecid_xt.getID1();
295  int xt_num=ecid_xt.getID2();
296  int yt_num=ecid_xt.getID3();
297 
298  EcalPedestals::Item item;
299  item.mean_x1 =rd_ped.getPedMeanG1() ;
300  item.rms_x1 =rd_ped.getPedRMSG1();
301  item.mean_x6 =rd_ped.getPedMeanG6();
302  item.rms_x6 =rd_ped.getPedRMSG6() ;
303  item.mean_x12 =rd_ped.getPedMeanG12();
304  item.rms_x12 =rd_ped.getPedRMSG12();
305 
306  if(ecid_xt.getName()=="EB_crystal_number") {
307  // Barrel channel
308  EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);
309 
310  // individual objects check
311  if(item.mean_x1==-1 || item.rms_x1 ==-1 || item.mean_x6==-1 ||
312  item.rms_x6==-1 || item.mean_x12==-1 || item.rms_x12==-1 ||
313  item.mean_x1==0 || item.rms_x1 ==0 || item.mean_x6==0 ||
314  item.rms_x6==0 || item.mean_x12==0 || item.rms_x12==0 ) {
315  // if one is bad we
316  // retrieve the old valid value
317  unsigned int hieb = ebdetid.hashedIndex();
318  EcalPedestals::Item previous_ped= peds->barrel(hieb);
319  if(item.mean_x1==-1 || item.mean_x1==0) item.mean_x1 =previous_ped.mean_x1;
320  if(item.rms_x1==-1 || item.rms_x1==0) item.rms_x1 =previous_ped.rms_x1;
321  if(item.mean_x6==-1 || item.mean_x6==0) item.mean_x6 =previous_ped.mean_x6;
322  if(item.rms_x6==-1 || item.rms_x6==0) item.rms_x6 =previous_ped.rms_x6;
323  if(item.mean_x12==-1 || item.mean_x12==0)item.mean_x12=previous_ped.mean_x12;
324  if(item.rms_x12==-1 || item.rms_x12==0) item.rms_x12 =previous_ped.rms_x12;
325  }
326 
327  // here we change in the peds object only the channels that are available in the online DB
328  // otherwise we keep the previous value
329  peds->insert(std::make_pair(ebdetid.rawId(),item));
330  } else {
331  // Endcap channel
332  // in this case xt_num is x
333  // yt_num is y and sm_num is the side +/- 1
334  if(EEDetId::validDetId(xt_num,yt_num,sm_num)){
335  EEDetId eedetid(xt_num,yt_num,sm_num);
336 
337  // individual objects check
338  if(item.mean_x1==-1 || item.rms_x1 ==-1 || item.mean_x6==-1 ||
339  item.rms_x6==-1 || item.mean_x12==-1 || item.rms_x12==-1 ||
340  item.mean_x1==0 || item.rms_x1 ==0 || item.mean_x6==0 ||
341  item.rms_x6==0 || item.mean_x12==0 || item.rms_x12==0 ) {
342  // if one is bad we
343  // retrieve the old valid value
344  unsigned int hiee = eedetid.hashedIndex();
345  EcalPedestals::Item previous_ped= peds->endcap(hiee);
346  if(item.mean_x1==-1 || item.mean_x1==0) item.mean_x1 =previous_ped.mean_x1;
347  if(item.rms_x1==-1 || item.rms_x1==0) item.rms_x1 =previous_ped.rms_x1;
348  if(item.mean_x6==-1 || item.mean_x6==0) item.mean_x6 =previous_ped.mean_x6;
349  if(item.rms_x6==-1 || item.rms_x6==0) item.rms_x6 =previous_ped.rms_x6;
350  if(item.mean_x12==-1 || item.mean_x12==0)item.mean_x12=previous_ped.mean_x12;
351  if(item.rms_x12==-1 || item.rms_x12==0) item.rms_x12 =previous_ped.rms_x12;
352  }
353  // here we change in the peds object only the channels that are available in the online DB
354  // otherwise we keep the previous value
355  peds->insert(std::make_pair(eedetid.rawId(),item));
356  }
357  }
358  }
359 
360  edm::LogInfo("Generating popcon record for run ") << irun << "..." << std::flush;
361  // now I copy peds in pedtemp and I ship pedtemp to popcon
362  // if I use always the same peds I always overwrite
363  // so I really have to create new objects for each new run
364  // popcon deletes everything for me
365 
366  EcalPedestals* pedtemp = new EcalPedestals();
367  for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
368  if(iEta==0) continue;
369  for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
370  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
371  if (EBDetId::validDetId(iEta,iPhi)) {
372  EBDetId ebdetid(iEta,iPhi);
373  unsigned int hiee = ebdetid.hashedIndex();
374  EcalPedestals::Item aped= peds->barrel(hiee);
375 
376  // here I copy the last valid value in the peds object
377  EcalPedestals::Item item;
378  item.mean_x1 = aped.mean_x1;
379  item.rms_x1 = aped.rms_x1;
380  item.mean_x6 = aped.mean_x6;
381  item.rms_x6 = aped.rms_x6;
382  item.mean_x12 = aped.mean_x12;
383  item.rms_x12 = aped.rms_x12;
384  // here I copy the last valid value in the pedtemp object
385  pedtemp->insert(std::make_pair(ebdetid.rawId(),item));
386  if((iEta==-1 || iEta==1) && iPhi==20){
387  float x=aped.mean_x12 ;
388  edm::LogInfo("channel:") <<iEta<<"/"<<iPhi<< "/" << hiee << " ped mean 12="<< x;
389  }
390  }
391  }
392  }
393  // endcaps
394  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
395  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
396  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
397  if (EEDetId::validDetId(iX,iY,1)) {
398  EEDetId eedetid(iX,iY,1);
399  unsigned int hiee = eedetid.hashedIndex();
400  EcalPedestals::Item aped= peds->endcap(hiee);
401  // here I copy the last valid value in the peds object
402  EcalPedestals::Item item;
403  item.mean_x1 = aped.mean_x1;
404  item.rms_x1 = aped.rms_x1;
405  item.mean_x6 = aped.mean_x6;
406  item.rms_x6 = aped.rms_x6;
407  item.mean_x12 = aped.mean_x12;
408  item.rms_x12 = aped.rms_x12;
409  // here I copy the last valid value in the pedtemp object
410  pedtemp->insert(std::make_pair(eedetid.rawId(),item));
411  }
412  if (EEDetId::validDetId(iX,iY,-1)) {
413  EEDetId eedetid(iX,iY,-1);
414  unsigned int hiee = eedetid.hashedIndex();
415  EcalPedestals::Item aped= peds->endcap(hiee);
416  // here I copy the last valid value in the peds object
417  EcalPedestals::Item item;
418  item.mean_x1 = aped.mean_x1;
419  item.rms_x1 = aped.rms_x1;
420  item.mean_x6 = aped.mean_x6;
421  item.rms_x6 = aped.rms_x6;
422  item.mean_x12 = aped.mean_x12;
423  item.rms_x12 = aped.rms_x12;
424  // here I copy the last valid value in the pedtemp object
425  pedtemp->insert(std::make_pair(eedetid.rawId(),item));
426  }
427  }
428  }
429 
430  Time_t snc= (Time_t) irun ;
431  m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedtemp,snc));
432 
433  ss << "Run=" << irun << "_WAS_GOOD_"<<std::endl;
434  m_userTextLog = ss.str()+";";
435  } // good run : write in DB
436  else {
437  edm::LogInfo("Run ") << irun << " was BAD !!!! not sent to the DB";
438  if(nbad >= (dataset_mon.size()*0.05))
439  edm::LogInfo(" number of bad channels = ") << nbad;
440  if(nEB <= 10200)
441  edm::LogInfo(" number of EB channels = ") << nEB;
442  if(nEE <= 2440)
443  edm::LogInfo(" number of EE channels = ") << nEE;
444  ss << "Run=" << irun << "_WAS_BAD_"<<std::endl;
445  m_userTextLog = ss.str()+";";
446  } // bad run : do not write in DB
447  } // SubRunNumber
448  } // loop over runs
449 
450  delete econn;
451  delete peds; // this is the only one that popcon does not delete
452  } // runs to analyze ?
453  edm::LogInfo("Ecal - > end of getNewObjects -----------\n");
454 }
bool checkPedestal(EcalPedestals::Item *item)
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:70
static const int MIN_IPHI
Definition: EBDetId.h:135
Definition: RunTag.h:13
float getPedRMSG1() const
MonRunList fetchMonRunList(const RunTag &tag, const MonRunTag &monruntag) noexcept(false)
void setGeneralTag(std::string tag)
Definition: MonRunTag.cc:33
void fetchDataSet(std::map< EcalLogicID, DATT > *fillMap, IOVT *iov) noexcept(false)
static const int IX_MIN
Definition: EEDetId.h:290
static const int IY_MIN
Definition: EEDetId.h:294
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:118
void setRunTag(const RunTag &tag)
Definition: MonRunList.cc:23
int getID2() const
Definition: EcalLogicID.cc:51
cond::ValidityInterval lastInterval
Definition: Types.h:76
std::string getName() const
Definition: EcalLogicID.cc:36
float getPedMeanG12() const
float getPedRMSG12() const
int getID1() const
Definition: EcalLogicID.cc:46
T min(T a, T b)
Definition: MathUtil.h:58
void setMonVersionDef(const MonVersionDef &ver)
Definition: MonRunTag.cc:49
static const int ETAPHIMODE
Definition: EBDetId.h:158
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:53
void insert(std::pair< uint32_t, Item > const &a)
static const int IX_MAX
Definition: EEDetId.h:298
std::vector< MonRunIOV > getRuns()
Definition: MonRunList.cc:46
EcalPedestalsMap EcalPedestals
Definition: EcalPedestals.h:53
static const int MAX_IPHI
Definition: EBDetId.h:137
void setRunType(std::string runtype)
Definition: RunTypeDef.cc:33
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
std::vector< Item >::const_iterator const_iterator
static const int MAX_IETA
Definition: EBDetId.h:136
void setMonRunTag(const MonRunTag &tag)
Definition: MonRunList.cc:29
float getPedMeanG1() const
void setMonitoringVersion(std::string ver)
float getPedMeanG6() const
void setLocation(std::string loc)
Definition: LocationDef.cc:33
static const int IY_MAX
Definition: EEDetId.h:302
const Item & barrel(size_t hashedIndex) const
int getID3() const
Definition: EcalLogicID.cc:56
void setGeneralTag(std::string tag)
Definition: RunTag.cc:36
static const int SMCRYSTALMODE
Definition: EBDetId.h:159
const Item & endcap(size_t hashedIndex) const
Definition: RunIOV.h:13
float getPedRMSG6() const
std::string popcon::EcalPedestalsHandler::id ( ) const
inlineoverridevirtual
void popcon::EcalPedestalsHandler::readPedestal2017 ( )

Definition at line 1036 of file EcalPedestalsHandler.cc.

References EcalCondObjectContainer< T >::barrel(), debug, EcalCondObjectContainer< T >::endcap(), EBDetId::ETAPHIMODE, cmsRelvalreport::exit, EBDetId::hashedIndex(), EEDetId::hashedIndex(), EcalCondObjectContainer< T >::insert(), EEDetId::IX_MAX, EEDetId::IX_MIN, EEDetId::IY_MAX, EEDetId::IY_MIN, kEBChannels, kEEChannels, popcon::PopConSourceHandler< EcalPedestals >::lastPayload(), m_filename, m_firstRun, popcon::PopConSourceHandler< EcalPedestals >::m_to_transfer, EBDetId::MAX_IETA, EBDetId::MAX_IPHI, EcalPedestal::mean_x1, EcalPedestal::mean_x12, EcalPedestal::mean_x6, EBDetId::MIN_IPHI, DetId::rawId(), EcalPedestal::rms_x1, EcalPedestal::rms_x12, EcalPedestal::rms_x6, EBDetId::validDetId(), and EEDetId::validDetId().

Referenced by getNewObjects().

1036  {
1037  bool debug = false;
1038  edm::LogInfo(" reading local Pedestal run (2017 way)! ") << m_filename;
1039 
1040  // First we copy the last valid record to a temporary object peds
1041  Ref ped_db = lastPayload();
1042  EcalPedestals* peds = new EcalPedestals();
1043  edm::LogInfo("retrieved last payload ");
1044 
1045  for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
1046  if(iEta==0) continue;
1047  for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
1048  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
1049  if (EBDetId::validDetId(iEta,iPhi)) {
1050  EBDetId ebdetid(iEta,iPhi,EBDetId::ETAPHIMODE);
1051  EcalPedestals::const_iterator it = ped_db->find(ebdetid.rawId());
1052  EcalPedestals::Item aped = (*it);
1053  // here I copy the last valid value in the peds object
1054  EcalPedestals::Item item;
1055  item.mean_x1 = aped.mean_x1;
1056  item.rms_x1 = aped.rms_x1;
1057  item.mean_x6 = aped.mean_x6;
1058  item.rms_x6 = aped.rms_x6;
1059  item.mean_x12 = aped.mean_x12;
1060  item.rms_x12 = aped.rms_x12;
1061  peds->insert(std::make_pair(ebdetid.rawId(),item));
1062  }
1063  }
1064  }
1065  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
1066  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
1067  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
1068  if (EEDetId::validDetId(iX,iY,1)) {
1069  EEDetId eedetidpos(iX,iY,1);
1070  EcalPedestals::const_iterator it = ped_db->find(eedetidpos.rawId());
1071  EcalPedestals::Item aped = (*it);
1072  // here I copy the last valid value in the peds object
1073  EcalPedestals::Item item;
1074  item.mean_x1 = aped.mean_x1;
1075  item.rms_x1 = aped.rms_x1;
1076  item.mean_x6 = aped.mean_x6;
1077  item.rms_x6 = aped.rms_x6;
1078  item.mean_x12 = aped.mean_x12;
1079  item.rms_x12 = aped.rms_x12;
1080  peds->insert(std::make_pair(eedetidpos.rawId(),item));
1081  }
1082  if(EEDetId::validDetId(iX,iY,-1)) {
1083  EEDetId eedetidneg(iX,iY,-1);
1084  EcalPedestals::const_iterator it = ped_db->find(eedetidneg.rawId());
1085  EcalPedestals::Item aped = (*it);
1086  // here I copy the last valid value in the peds object
1087  EcalPedestals::Item item;
1088  item.mean_x1 = aped.mean_x1;
1089  item.rms_x1 = aped.rms_x1;
1090  item.mean_x6 = aped.mean_x6;
1091  item.rms_x6 = aped.rms_x6;
1092  item.mean_x12 = aped.mean_x12;
1093  item.rms_x12 = aped.rms_x12;
1094  peds->insert(std::make_pair(eedetidneg.rawId(),item));
1095  }
1096  }
1097  }
1098 
1099  edm::LogInfo(" reading the input file ") << m_filename;
1100  std::ifstream fInput;
1101  fInput.open(m_filename);
1102  if(!fInput.is_open()) {
1103  edm::LogInfo("ERROR : cannot open file ") << m_filename;
1104  exit (1);
1105  }
1106  // string pos, dummyLine;
1107  int hashedId;
1108  float EBmean12[kEBChannels], EBrms12[kEBChannels], EBmean6[kEBChannels], EBrms6[kEBChannels], EBmean1[kEBChannels], EBrms1[kEBChannels];
1109  //***************** barrel
1110  // getline(fInput, dummyLine); // skip first line
1111  for (int iChannel = 0; iChannel < kEBChannels; iChannel++) {
1112  fInput >> hashedId >> EBmean12[iChannel] >> EBrms12[iChannel] >> EBmean6[iChannel] >> EBrms6[iChannel]
1113  >> EBmean1[iChannel] >> EBrms1[iChannel];
1114  if(hashedId != iChannel + 1) {
1115  edm::LogInfo("File ") << m_filename << " strange hash " << hashedId << " while iChannel " << iChannel;
1116  exit(-1);
1117  }
1118  }
1119 
1120  // ***************** now EE *****************
1121  float EEmean12[kEEChannels], EErms12[kEEChannels], EEmean6[kEEChannels], EErms6[kEEChannels], EEmean1[kEEChannels], EErms1[kEEChannels];
1122  for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
1123  fInput >> hashedId >> EEmean12[iChannel] >> EErms12[iChannel] >> EEmean6[iChannel] >> EErms6[iChannel]
1124  >> EEmean1[iChannel] >> EErms1[iChannel];
1125  if(hashedId != iChannel + kEBChannels + 1) {
1126  edm::LogInfo("File ") << m_filename << " strange hash " << hashedId << " while iChannel " << iChannel;
1127  exit(-1);
1128  }
1129  }
1130  fInput.close();
1131 
1132  EcalPedestals* ped = new EcalPedestals();
1133  // barrel
1134  for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
1135  if(iEta==0) continue;
1136  for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
1137  if (EBDetId::validDetId(iEta,iPhi)) {
1138  EBDetId ebdetid(iEta,iPhi);
1139  unsigned int hieb = ebdetid.hashedIndex();
1140  EcalPedestals::Item item;
1141  EcalPedestals::Item previous_ped = peds->barrel(hieb);
1142  if(debug & (EBmean12[hieb] == -999. || EBrms12[hieb] == -999. || EBmean6[hieb] == -999. || EBrms6[hieb] == -999. ||
1143  EBmean1[hieb] == -999. || EBrms1[hieb] == -999.))
1144  edm::LogInfo(" bad EB channel eta ") << iEta << " phi " << iPhi << " " << EBmean12[hieb] << " " << EBrms12[hieb]
1145  << " " << EBmean6[hieb] << " " << EBrms6[hieb] << " " << EBmean1[hieb] << " " << EBrms1[hieb];
1146  if(EBmean1[hieb] != -999.) item.mean_x1 = EBmean1[hieb];
1147  else item.mean_x1 = previous_ped.mean_x1;
1148  if(EBrms1[hieb] != -999.) item.rms_x1 = EBrms1[hieb];
1149  else item.rms_x1 = previous_ped.rms_x1;
1150  if(EBmean6[hieb] != -999.) item.mean_x6 = EBmean6[hieb];
1151  else item.mean_x6 = previous_ped.mean_x6;
1152  if(EBrms6[hieb] != -999.) item.rms_x6 = EBrms6[hieb];
1153  else item.rms_x6 = previous_ped.rms_x6;
1154  if(EBmean12[hieb] != -999.) item.mean_x12 = EBmean12[hieb];
1155  else item.mean_x12 = previous_ped.mean_x12;
1156  if(EBrms12[hieb] != -999.) item.rms_x12 = EBrms12[hieb];
1157  else item.rms_x12 = previous_ped.rms_x12;
1158  ped->insert(std::make_pair(ebdetid.rawId(),item));
1159  } // valid EBId
1160  } // loop over phi
1161  } // loop over eta
1162  // endcaps
1163  // std::ofstream fout;
1164  // fout.open("Pedestal.check");
1165  for(int iz = -1; iz < 2; iz = iz + 2) { // z : -1 and +1
1166  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
1167  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
1168  if (EEDetId::validDetId(iX, iY, iz)) {
1169  EEDetId eedetid(iX, iY, iz);
1170  unsigned int hiee = eedetid.hashedIndex();
1171  // fout << hiee << " mean 12 " << EEmean12[hiee] << std::endl;
1172  EcalPedestals::Item item;
1173  EcalPedestals::Item previous_ped= peds->endcap(hiee);
1174  if(debug & (EEmean12[hiee] == -999. || EErms12[hiee] == -999. || EEmean6[hiee] == -999. || EErms6[hiee] == -999. ||
1175  EEmean1[hiee] == -999. || EErms1[hiee] == -999.))
1176  edm::LogInfo(" bad EE channel x ") << iX << " y " << iY << " z" << iz << " " << EEmean12[hiee] << " " << EErms12[hiee]
1177  << " " <<EEmean6[hiee] << " " << EErms6[hiee] << " " << EEmean1[hiee] << " " << EErms1[hiee];
1178  if(EEmean1[hiee] != -999.) item.mean_x1 = EEmean1[hiee];
1179  else item.mean_x1 = previous_ped.mean_x1;
1180  if(EErms1[hiee] != -999.) item.rms_x1 = EErms1[hiee];
1181  else item.rms_x1 = previous_ped.rms_x1;
1182  if(EEmean6[hiee] != -999.) item.mean_x6 = EEmean6[hiee];
1183  else item.mean_x6 = previous_ped.mean_x6;
1184  if(EErms6[hiee] != -999.) item.rms_x6 = EErms6[hiee];
1185  else item.rms_x6 = previous_ped.rms_x6;
1186  if(EEmean12[hiee] != -999.) item.mean_x12 = EEmean12[hiee];
1187  else item.mean_x12 = previous_ped.mean_x12;
1188  if(EErms12[hiee] != -999.) item.rms_x12 = EErms12[hiee];
1189  else item.rms_x12 = previous_ped.rms_x12;
1190  ped->insert(std::make_pair(eedetid.rawId(),item));
1191  } // val EEId
1192  } // loop over y
1193  } // loop over x
1194  } // loop over z
1195  // fout.close();
1196 
1197  unsigned int irun = m_firstRun;
1198  Time_t snc= (Time_t) irun ;
1199  m_to_transfer.push_back(std::make_pair((EcalPedestals*)ped,snc));
1200 
1201  edm::LogInfo("Ecal - > end of readPedestal2017 -----------\n");
1202 }
const Int_t kEBChannels
static const int MIN_IPHI
Definition: EBDetId.h:135
static const int IX_MIN
Definition: EEDetId.h:290
static const int IY_MIN
Definition: EEDetId.h:294
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:118
const Int_t kEEChannels
static const int ETAPHIMODE
Definition: EBDetId.h:158
void insert(std::pair< uint32_t, Item > const &a)
static const int IX_MAX
Definition: EEDetId.h:298
EcalPedestalsMap EcalPedestals
Definition: EcalPedestals.h:53
#define debug
Definition: HDRShower.cc:19
static const int MAX_IPHI
Definition: EBDetId.h:137
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
std::vector< Item >::const_iterator const_iterator
static const int MAX_IETA
Definition: EBDetId.h:136
static const int IY_MAX
Definition: EEDetId.h:302
const Item & barrel(size_t hashedIndex) const
const Item & endcap(size_t hashedIndex) const
void popcon::EcalPedestalsHandler::readPedestalFile ( )

Definition at line 666 of file EcalPedestalsHandler.cc.

References cmsRelvalreport::exit, EBDetId::hashedIndex(), EEDetId::hashedIndex(), EcalCondObjectContainer< T >::insert(), EEDetId::IX_MAX, EEDetId::IX_MIN, EEDetId::IY_MAX, EEDetId::IY_MIN, kEBChannels, kEEChannels, m_filename, m_firstRun, popcon::PopConSourceHandler< EcalPedestals >::m_to_transfer, EBDetId::MAX_IETA, EBDetId::MAX_IPHI, EcalPedestal::mean_x1, EcalPedestal::mean_x12, EcalPedestal::mean_x6, EBDetId::MIN_IPHI, DetId::rawId(), EcalPedestal::rms_x1, EcalPedestal::rms_x12, EcalPedestal::rms_x6, EBDetId::validDetId(), and EEDetId::validDetId().

Referenced by getNewObjects().

666  {
667  edm::LogInfo(" reading the input file ") << m_filename;
668  std::ifstream fInput;
669  fInput.open(m_filename);
670  if(!fInput.is_open()) {
671  edm::LogInfo("ERROR : cannot open file ") << m_filename;
672  exit (1);
673  }
674  // string pos, dummyLine;
675  int hashedId;
676  float EBmean12[kEBChannels], EBrms12[kEBChannels], EBmean6[kEBChannels], EBrms6[kEBChannels], EBmean1[kEBChannels], EBrms1[kEBChannels];
677  //***************** barrel
678  // getline(fInput, dummyLine); // skip first line
679  for (int iChannel = 0; iChannel < kEBChannels; iChannel++) {
680  fInput >> hashedId >> EBmean12[iChannel] >> EBrms12[iChannel] >> EBmean6[iChannel] >> EBrms6[iChannel]
681  >> EBmean1[iChannel] >> EBrms1[iChannel];
682  if(hashedId != iChannel + 1) {
683  edm::LogInfo("File") << m_filename << " strange hash " << hashedId << " while iChannel " << iChannel;
684  exit(-1);
685  }
686  }
687 
688  // ***************** now EE *****************
689  float EEmean12[kEEChannels], EErms12[kEEChannels], EEmean6[kEEChannels], EErms6[kEEChannels], EEmean1[kEEChannels], EErms1[kEEChannels];
690  for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
691  fInput >> hashedId >> EEmean12[iChannel] >> EErms12[iChannel] >> EEmean6[iChannel] >> EErms6[iChannel]
692  >> EEmean1[iChannel] >> EErms1[iChannel];
693  if(hashedId != iChannel + kEBChannels + 1) {
694  edm::LogInfo("File") << m_filename << " strange hash " << hashedId << " while iChannel " << iChannel;
695  exit(-1);
696  }
697  }
698  fInput.close();
699 
700  EcalPedestals* ped = new EcalPedestals();
701  // barrel
702  for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
703  if(iEta==0) continue;
704  for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
705  if (EBDetId::validDetId(iEta,iPhi)) {
706  EBDetId ebdetid(iEta,iPhi);
707  unsigned int hieb = ebdetid.hashedIndex();
708  EcalPedestals::Item item;
709  item.mean_x1 = EBmean1[hieb];
710  item.rms_x1 = EBrms1[hieb];
711  item.mean_x6 = EBmean6[hieb];
712  item.rms_x6 = EBrms6[hieb];
713  item.mean_x12 = EBmean12[hieb];
714  item.rms_x12 = EBrms12[hieb];
715  ped->insert(std::make_pair(ebdetid.rawId(),item));
716  } // valid EBId
717  } // loop over phi
718  } // loop over eta
719  // endcaps
720  // std::ofstream fout;
721  // fout.open("Pedestal.check");
722  for(int iz = -1; iz < 2; iz = iz + 2) { // z : -1 and +1
723  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
724  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
725  if (EEDetId::validDetId(iX, iY, iz)) {
726  EEDetId eedetid(iX, iY, iz);
727  unsigned int hiee = eedetid.hashedIndex();
728  // fout << hiee << " mean 12 " << EEmean12[hiee] << std::endl;
729  EcalPedestals::Item item;
730  item.mean_x1 = EEmean1[hiee];
731  item.rms_x1 = EErms1[hiee];
732  item.mean_x6 = EEmean6[hiee];
733  item.rms_x6 = EErms6[hiee];
734  item.mean_x12 = EEmean12[hiee];
735  item.rms_x12 = EErms12[hiee];
736  ped->insert(std::make_pair(eedetid.rawId(),item));
737  } // val EEId
738  } // loop over y
739  } // loop over x
740  } // loop over z
741  // fout.close();
742 
743  unsigned int irun = m_firstRun;
744  Time_t snc= (Time_t) irun ;
745  m_to_transfer.push_back(std::make_pair((EcalPedestals*)ped,snc));
746 
747  edm::LogInfo("Ecal - > end of readPedestalFile -----------\n");
748 }
const Int_t kEBChannels
static const int MIN_IPHI
Definition: EBDetId.h:135
static const int IX_MIN
Definition: EEDetId.h:290
static const int IY_MIN
Definition: EEDetId.h:294
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:118
const Int_t kEEChannels
void insert(std::pair< uint32_t, Item > const &a)
static const int IX_MAX
Definition: EEDetId.h:298
EcalPedestalsMap EcalPedestals
Definition: EcalPedestals.h:53
static const int MAX_IPHI
Definition: EBDetId.h:137
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
static const int MAX_IETA
Definition: EBDetId.h:136
static const int IY_MAX
Definition: EEDetId.h:302
void popcon::EcalPedestalsHandler::readPedestalMC ( )

Definition at line 752 of file EcalPedestalsHandler.cc.

References funct::abs(), cmsRelvalreport::exit, groupFilesInBlocks::fout, muonCSCDigis_cfi::gain, gainValues, EBDetId::hashedIndex(), EEDetId::hashedIndex(), mps_fire::i, EBDetId::ieta(), EcalCondObjectContainer< T >::insert(), EEDetId::IX_MAX, EEDetId::IX_MIN, EEDetId::IY_MAX, EEDetId::IY_MIN, kEBChannels, kEEChannels, kGains, m_corrected, m_filename, m_firstRun, popcon::PopConSourceHandler< EcalPedestals >::m_to_transfer, EBDetId::MAX_IETA, EBDetId::MAX_IPHI, EcalPedestal::mean_x1, EcalPedestal::mean_x12, EcalPedestal::mean_x6, EBDetId::MIN_IPHI, diffTwoXMLs::r1, DetId::rawId(), relativeConstraints::ring, SiStripPI::rms, EcalPedestal::rms_x1, EcalPedestal::rms_x12, EcalPedestal::rms_x6, mathSSE::sqrt(), AlCaHLTBitMon_QueryRunRegistry::string, EBDetId::unhashIndex(), EBDetId::validDetId(), EEDetId::validDetId(), and x.

Referenced by getNewObjects().

752  {
753  edm::LogInfo(" reading the input file ") << m_filename;
754  std::ifstream fxml;
755  fxml.open(m_filename);
756  if(!fxml.is_open()) {
757  edm::LogInfo("ERROR : cannot open file ") << m_filename;
758  exit (1);
759  }
760  std::ofstream fout;
761  fout.open("Pedestal.check");
762  // int hashedId;
763  float EBmean12[kEBChannels], EBrms12[kEBChannels], EBmean6[kEBChannels], EBrms6[kEBChannels], EBmean1[kEBChannels], EBrms1[kEBChannels];
764  // int ringEB[kEBChannels], ringEE[kEEChannels];
765  double RingMean[28][2][3], RingRMS[28][2][3];
766  int NbVal[28][2][3];
767  for (int ring = 0; ring < 28; ring++) {
768  for (int side = 0; side < 2; side++) {
769  for (int igain = 0; igain < kGains; igain++) {
770  RingMean[ring][side][igain] = 0.;
771  RingRMS[ring][side][igain] = 0.;
772  NbVal[ring][side][igain] = 0;
773  }
774  }
775  }
776  std::string dummyLine, mean12, rms12, bid;
777  for(int i = 0; i < 9; i++) std::getline(fxml, dummyLine); // skip first lines
778  // Barrel
779  for (int iEBChannel = 0; iEBChannel < kEBChannels; iEBChannel++) {
780  EBDetId ebdetid = EBDetId::unhashIndex(iEBChannel);
781  int ieta = ebdetid.ieta();
782  int ring = (abs(ieta) - 1)/5;
783  if(ring < 0 || ring > 16) edm::LogInfo("EB channel ") << iEBChannel << " ring " << ring;
784  int izz = 0;
785  if(ieta > 0) izz = 1;
786  fxml >> bid;
787  std::string stt = bid.substr(10,15);
788  std::istringstream m12(stt);
789  m12 >> EBmean12[iEBChannel];
790  fxml >> bid;
791  stt = bid.substr(9,15);
792  std::istringstream r12(stt);
793  r12 >> EBrms12[iEBChannel];
794  if(EBrms12[iEBChannel] != 0. && EBrms12[iEBChannel] < 5.) {
795  RingMean[ring][izz][0] += EBrms12[iEBChannel];
796  RingRMS[ring][izz][0] += EBrms12[iEBChannel] * EBrms12[iEBChannel];
797  NbVal[ring][izz][0]++;
798  }
799  fxml >> bid;
800  stt = bid.substr(9,15);
801  std::istringstream m6(stt);
802  m6 >> EBmean6[iEBChannel];
803  fxml >> bid;
804  stt = bid.substr(8,15);
805  std::istringstream r6(stt);
806  r6 >> EBrms6[iEBChannel];
807  if(EBrms6[iEBChannel] != 0. && EBrms6[iEBChannel] < 5.) {
808  RingMean[ring][izz][1] += EBrms6[iEBChannel];
809  RingRMS[ring][izz][1] += EBrms6[iEBChannel] * EBrms6[iEBChannel];
810  NbVal[ring][izz][1]++;
811  }
812  fxml >> bid;
813  stt = bid.substr(9,15);
814  std::istringstream m1(stt);
815  m1 >> EBmean1[iEBChannel];
816  fxml >> bid;
817  stt = bid.substr(8,15);
818  std::istringstream r1(stt);
819  r1 >> EBrms1[iEBChannel];
820  if(EBrms1[iEBChannel] != 0. && EBrms1[iEBChannel] < 5.) {
821  RingMean[ring][izz][2] += EBrms1[iEBChannel];
822  RingRMS[ring][izz][2] += EBrms1[iEBChannel] * EBrms1[iEBChannel];
823  NbVal[ring][izz][2]++;
824  }
825  if(iEBChannel%10000 == 0) fout << " EB channel " << iEBChannel
826  << " " << EBmean12[iEBChannel] << " " << EBrms12[iEBChannel]
827  << " " << EBmean6[iEBChannel] << " " << EBrms6[iEBChannel]
828  << " " << EBmean1[iEBChannel] << " " << EBrms1[iEBChannel] << std::endl;
829  for(int i = 0; i < 3; i++) std::getline(fxml, dummyLine); // skip lines
830  }
831 
832  // ***************** now EE *****************
833  std::ifstream fCrystal;
834  fCrystal.open("Crystal");
835  if(!fCrystal.is_open()) {
836  edm::LogInfo("ERROR : cannot open file Crystal");
837  exit (1);
838  }
839  int ringEE[kEEChannels];
840  for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
841  fCrystal >> ringEE[iChannel];
842  int ring = abs(ringEE[iChannel]) - 1;
843  if(ring < 17 || ring > 27) {
844  edm::LogInfo(" EE channel ") << iChannel << " ring " << ringEE[iChannel];
845  exit(-1);
846  }
847  }
848  fCrystal.close();
849 
850  float EEmean12[kEEChannels], EErms12[kEEChannels], EEmean6[kEEChannels], EErms6[kEEChannels], EEmean1[kEEChannels], EErms1[kEEChannels];
851  for(int i = 0; i < 6; i++) std::getline(fxml, dummyLine); // skip lines
852  for (int iEEChannel = 0; iEEChannel < kEEChannels; iEEChannel++) {
853  // int ich = iEEChannel + kEBChannels;
854  fxml >> bid;
855  std::string stt = bid.substr(10,15);
856  std::istringstream m12(stt);
857  m12 >> EEmean12[iEEChannel];
858  int ring = abs(ringEE[iEEChannel]) - 1;
859  if(ring < 17 || ring > 27) edm::LogInfo("EE channel ") << iEEChannel << " ring " << ring;
860  int izz = 1;
861  if(iEEChannel < 7324) izz = 0;
862  fxml >> bid;
863  stt = bid.substr(9,15);
864  std::istringstream r12(stt);
865  r12 >> EErms12[iEEChannel];
866  if(EErms12[iEEChannel] != 0. && EErms12[iEEChannel] < 5.) {
867  RingMean[ring][izz][0] += EErms12[iEEChannel];
868  RingRMS[ring][izz][0] += EErms12[iEEChannel] * EErms12[iEEChannel];
869  NbVal[ring][izz][0]++;
870  }
871  fxml >> bid;
872  stt = bid.substr(9,15);
873  std::istringstream m6(stt);
874  m6 >> EEmean6[iEEChannel];
875  fxml >> bid;
876  stt = bid.substr(8,15);
877  std::istringstream r6(stt);
878  r6 >> EErms6[iEEChannel];
879  if(EErms6[iEEChannel] != 0. && EErms6[iEEChannel] < 5.) {
880  RingMean[ring][izz][1] += EErms6[iEEChannel];
881  RingRMS[ring][izz][1] += EErms6[iEEChannel] * EErms6[iEEChannel];
882  NbVal[ring][izz][1]++;
883  }
884  fxml >> bid;
885  stt = bid.substr(9,15);
886  std::istringstream m1(stt);
887  m1 >> EEmean1[iEEChannel];
888  fxml >> bid;
889  stt = bid.substr(8,15);
890  std::istringstream r1(stt);
891  r1 >> EErms1[iEEChannel];
892  if(EErms1[iEEChannel] != 0. && EErms1[iEEChannel] < 5.) {
893  RingMean[ring][izz][2] += EErms1[iEEChannel];
894  RingRMS[ring][izz][2] += EErms1[iEEChannel] * EErms1[iEEChannel];
895  NbVal[ring][izz][2]++;
896  }
897  if(iEEChannel%1000 == 0) fout << " EE channel " << iEEChannel
898  << " " << EEmean12[iEEChannel] << " " << EErms12[iEEChannel]
899  << " " << EEmean6[iEEChannel] << " " << EErms6[iEEChannel]
900  << " " << EEmean1[iEEChannel] << " " << EErms1[iEEChannel] << std::endl;
901  for(int i = 0; i < 3; i++) std::getline(fxml, dummyLine); // skip lines
902  }
903 
904  fxml.close();
905 
906  for (int gain = 0; gain < kGains; gain++) {
907  fout << "\n" << "**** Gain **** " << gainValues[gain] << "\n";
908  for (int ring = 0; ring < 28; ring++) {
909  for (int side = 0; side < 2; side++) {
910  if(NbVal[ring][side][gain] <= 0) {
911  edm::LogInfo(" No entry for ring ") << ring;
912  exit(-1);
913  }
914  RingMean[ring][side][gain] /= (double)NbVal[ring][side][gain];
915  double x = RingMean[ring][side][gain];
916  RingRMS[ring][side][gain] /= (double)NbVal[ring][side][gain];
917  double rms = sqrt(RingRMS[ring][side][gain] - x * x);
918  RingRMS[ring][side][gain] = rms;
919  fout << " ring " << ring + 1 << " mean " << x << " rms " << rms << " ";
920  } // loop over sides
921  fout << std::endl;
922  if(ring == 16) fout << "***** End caps ***** EE- EE+" << std::endl;
923  } // loop over rings
924  } // loop over gains
925 
926  // read also the ring value from Crystal file
927 
928  EcalPedestals* ped = new EcalPedestals();
929  // barrel
930  for(int iEta = -EBDetId::MAX_IETA; iEta <= EBDetId::MAX_IETA; ++iEta) {
931  if(iEta==0) continue;
932  for(int iPhi = EBDetId::MIN_IPHI; iPhi <= EBDetId::MAX_IPHI; ++iPhi) {
933  if (EBDetId::validDetId(iEta,iPhi)) {
934  EBDetId ebdetid(iEta,iPhi);
935  unsigned int hieb = ebdetid.hashedIndex();
936  EcalPedestals::Item item;
937  item.mean_x1 = 200.;
938  item.mean_x6 = 200.;
939  item.mean_x12 = 200.;
940  if(m_corrected) {
941  int ring = (abs(iEta) - 1)/5;
942  if(ring < 0 || ring > 16) edm::LogInfo("EB channel ") << hieb << " ring " << ring;
943  int side = 0;
944  if(iEta > 0) side = 1;
945  if(EBrms1[hieb] == 0 || EBrms1[hieb] > RingMean[ring][side][2] + 3 * RingRMS[ring][side][2]) {
946  fout << " EB channel " << hieb << " eta " << iEta << " phi " << iPhi << " ring " << ring + 1
947  << " gain 1 rms " << EBrms1[hieb] << " replaced by " << RingMean[ring][side][2] << std::endl;
948  item.rms_x1 = RingMean[ring][side][2];
949  }
950  else item.rms_x1 = EBrms1[hieb];
951  if(EBrms6[hieb] == 0 || EBrms6[hieb] > RingMean[ring][side][1] + 3 * RingRMS[ring][side][1]) {
952  fout << " EB channel " << hieb << " eta " << iEta << " phi " << iPhi << " ring " << ring + 1
953  << " gain 6 rms " << EBrms6[hieb] << " replaced by " << RingMean[ring][side][1] << std::endl;
954  item.rms_x6 = RingMean[ring][side][1];
955  }
956  else item.rms_x6 = EBrms6[hieb];
957  if(EBrms12[hieb] == 0 || EBrms12[hieb] > RingMean[ring][side][0] + 3 * RingRMS[ring][side][0]) {
958  fout << " EB channel " << hieb << " eta " << iEta << " phi " << iPhi << " ring " << ring + 1
959  << " gain 12 rms " << EBrms12[hieb] << " replaced by " << RingMean[ring][side][0] << std::endl;
960  item.rms_x12 = RingMean[ring][side][0];
961  }
962  else item.rms_x12 = EBrms12[hieb];
963  if(hieb > 4534 && hieb < 4540)
964  edm::LogInfo(" Channel ") << hieb << " ring " << ring
965  << " 12 " << EBrms12[hieb] << " mean " << RingMean[ring][side][0] << " rms " << RingRMS[ring][side][0]
966  << " 6 " << EBrms6[hieb] << " mean " << RingMean[ring][side][1] << " rms " << RingRMS[ring][side][1]
967  << " 1 " << EBrms1[hieb] << " mean " << RingMean[ring][side][2] << " rms " << RingRMS[ring][side][2];
968  } // if corrected
969  else {
970  item.rms_x1 = EBrms1[hieb];
971  item.rms_x6 = EBrms6[hieb];
972  item.rms_x12 = EBrms12[hieb];
973  }
974  if(item.rms_x1 > 4. || item.rms_x6 > 4. || item.rms_x12 > 4.)
975  edm::LogInfo(" Channel ") << hieb << " 12 " << item.rms_x12 << " 6 " << item.rms_x6 << " 1 " << item.rms_x1;
976  ped->insert(std::make_pair(ebdetid.rawId(),item));
977  } // valid EBId
978  } // loop over phi
979  } // loop over eta
980 
981  // endcaps
982  for(int iz = -1; iz < 2; iz = iz + 2) { // z : -1 and +1
983  for(int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
984  for(int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
985  if (EEDetId::validDetId(iX, iY, iz)) {
986  EEDetId eedetid(iX, iY, iz);
987  unsigned int hiee = eedetid.hashedIndex();
988  // fout << hiee << " mean 12 " << EEmean12[hiee] << std::endl;
989  EcalPedestals::Item item;
990  item.mean_x1 = 200.;
991  item.mean_x6 = 200.;
992  item.mean_x12 = 200.;
993  if(m_corrected) {
994  int ring = abs(ringEE[hiee]) - 1;
995  if(ring < 17 || ring > 27) edm::LogInfo("EE channel ") << hiee << " ring " << ring;
996  if(EErms1[hiee] == 0 || EErms1[hiee] > RingMean[ring][iz][2] + 3 * RingRMS[ring][iz][2]) {
997  fout << " EE channel " << hiee << " x " << iX << " y " << iY << " z " << iz << " ring " << ring + 1
998  << " gain 1 rms " << EErms1[hiee] << " replaced by " << RingMean[ring][iz][2] << std::endl;
999  item.rms_x1 = RingMean[ring][iz][2];
1000  }
1001  else item.rms_x1 = EErms1[hiee];
1002  if(EErms6[hiee] == 0 || EErms6[hiee] > RingMean[ring][iz][1] + 3 * RingRMS[ring][iz][1]) {
1003  fout << " EE channel " << hiee << " x " << iX << " y " << iY << " z " << iz << " ring " << ring + 1
1004  << " gain 6 rms " << EErms6[hiee] << " replaced by " << RingMean[ring][iz][1] << std::endl;
1005  item.rms_x6 = RingMean[ring][iz][1];
1006  }
1007  else item.rms_x6 = EErms6[hiee];
1008  if(EErms12[hiee] == 0 || EErms12[hiee] > RingMean[ring][iz][0] + 3 * RingRMS[ring][iz][0]) {
1009  fout << " EE channel " << hiee << " x " << iX << " y " << iY << " z " << iz << " ring " << ring + 1
1010  << " gain 12 rms " << EErms12[hiee] << " replaced by " << RingMean[ring][iz][0] << std::endl;
1011  item.rms_x12 = RingMean[ring][iz][0];
1012  }
1013  else item.rms_x12 = EErms12[hiee];
1014  } // if corrected
1015  else {
1016  item.rms_x1 = EErms1[hiee];
1017  item.rms_x6 = EErms6[hiee];
1018  item.rms_x12 = EErms12[hiee];
1019  }
1020  ped->insert(std::make_pair(eedetid.rawId(),item));
1021  } // val EEId
1022  } // loop over y
1023  } // loop over x
1024  } // loop over z
1025  fout.close();
1026 
1027  unsigned int irun = m_firstRun;
1028  Time_t snc= (Time_t) irun ;
1029  m_to_transfer.push_back(std::make_pair((EcalPedestals*)ped,snc));
1030 
1031  edm::LogInfo("Ecal - > end of readPedestalMC -----------\n");
1032 }
const Int_t kEBChannels
int hashedIndex() const
get a compact index for arrays
Definition: EBDetId.h:82
static const int MIN_IPHI
Definition: EBDetId.h:135
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
static const int IX_MIN
Definition: EEDetId.h:290
const Int_t gainValues[kGains]
static const int IY_MIN
Definition: EEDetId.h:294
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:118
T sqrt(T t)
Definition: SSEVec.h:18
const Int_t kEEChannels
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
void insert(std::pair< uint32_t, Item > const &a)
static const int IX_MAX
Definition: EEDetId.h:298
EcalPedestalsMap EcalPedestals
Definition: EcalPedestals.h:53
static const int MAX_IPHI
Definition: EBDetId.h:137
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
static const int MAX_IETA
Definition: EBDetId.h:136
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:110
static const int IY_MAX
Definition: EEDetId.h:302
const Int_t kGains
void popcon::EcalPedestalsHandler::readPedestalTimestamp ( )

Definition at line 1555 of file EcalPedestalsHandler.cc.

References funct::abs(), officialStyle::chan, debug, mps_splice::entry, cmsRelvalreport::exit, groupFilesInBlocks::fout, mps_fire::i, id(), EcalCondObjectContainer< T >::insert(), createfilelist::int, kChannels, kEBChannels, kEEChannels, csvLumiCalc::lumi, m_filename, m_firstRun, m_lastRun, popcon::PopConSourceHandler< EcalPedestals >::m_to_transfer, EcalPedestal::mean_x1, EcalPedestal::mean_x12, EcalPedestal::mean_x6, Nbpedxml, muonCSCDigis_cfi::pedestal, diffTwoXMLs::r1, DetId::rawId(), EcalPedestal::rms_x1, EcalPedestal::rms_x12, EcalPedestal::rms_x6, writedatasetfile::run, AlCaHLTBitMon_QueryRunRegistry::string, ntuplemaker::time, EBDetId::unhashIndex(), and EEDetId::unhashIndex().

Referenced by getNewObjects().

1555  {
1556  bool debug = false;
1557  edm::LogInfo(" reading the root file ")<< m_filename;
1558  TFile * hfile = new TFile(m_filename.c_str());
1559 
1560  TTree *treeChan = (TTree*)hfile->Get("PedChan");
1561  int iChannel = 0, ix = 0, iy = 0, iz = 0;
1562  treeChan->SetBranchAddress("Channels", &iChannel);
1563  treeChan->SetBranchAddress("x", &ix);
1564  treeChan->SetBranchAddress("y", &iy);
1565  treeChan->SetBranchAddress("z", &iz);
1566  int neventsChan = (int)treeChan->GetEntries();
1567  edm::LogInfo("PedChan nb entries ") << neventsChan;
1568  int ringEB[kEBChannels], sideEB[kEBChannels], ixEE[kEEChannels], iyEE[kEEChannels], izEE[kEEChannels];
1569  for(int entry = 0; entry < neventsChan; entry++) {
1570  treeChan->GetEntry(entry);
1571  if(entry < kEBChannels) {
1572  ringEB[iChannel] = (abs(ix) -1)/5; // -85...-1, 1...85 give 0...16
1573  sideEB[iChannel] = 1;
1574  if(ix < 0) sideEB[iChannel] = 0;
1575  if(debug && entry%10000 == 0) edm::LogInfo(" EB channel ") << iChannel << " eta " << ix << " phi " << iy
1576  << " side " << sideEB[iChannel] << " ring " << ringEB[iChannel];
1577  }
1578  else {
1579  ixEE[iChannel] = ix;
1580  iyEE[iChannel] = iy;
1581  izEE[iChannel] = iz;
1582  if(debug && entry%1000 == 0) edm::LogInfo(" EE channel ") << iChannel << " x " << ixEE[iChannel] << " y "
1583  << iyEE[iChannel] << " z " << izEE[iChannel];
1584  }
1585  }
1586  // 2016: 26
1587  Int_t pedxml[Nbpedxml] = {271948, 273634, 273931, 274705, 275403, 276108, 276510, 277169, 278123, 278183,
1588  278246, 278389, 278499, 278693, 278858, 278888, 278931, 279728, 280129, 280263,
1589  280941, 281753, 282631, 282833, 283199, 283766,
1590  // 2017 : 25
1591  286535, 293513, 293632, 293732, 295507, 295672, 296391, 296917, 297388, 298481,
1592  299279, 299710, 300186, 300581, 301191, 302006, 302293, 302605, 303436, 303848,
1593  304211, 304680, 305117, 305848, 306176,
1594  // 2018 : 30
1595  313760, 315434, 315831, 316299, 316694, 316963, 317399, 317669, 318249, 318747,
1596  319111, 319365, 319700, 320098, 320515, 320905, 321184, 321480, 321855, 322151,
1597  322653, 323261, 323802, 324250, 324632, 325909, 326038, 326652, 326979, 327271};
1598 
1599  Int_t run16Index = 0;
1600 
1601  Int_t fed[kChannels], chan[kChannels], id, run, run_type, seq_id, las_id, fill_num, run_num_infill, run_time, run_time_stablebeam, nxt, time[54];
1602  Float_t ped[kChannels], pedrms[kChannels], lumi, bfield;
1603  TTree *tree = (TTree*)hfile->Get("T");
1604  tree->Print();
1605  tree->SetBranchAddress("id", &id);
1606  tree->SetBranchAddress("run", &run);
1607  tree->SetBranchAddress("run_type", &run_type);
1608  tree->SetBranchAddress("seq_id", &seq_id);
1609  tree->SetBranchAddress("las_id", &las_id);
1610  tree->SetBranchAddress("fill_num", &fill_num);
1611  tree->SetBranchAddress("run_num_infill", &run_num_infill);
1612  tree->SetBranchAddress("run_time", &run_time);
1613  tree->SetBranchAddress("run_time_stablebeam", &run_time_stablebeam);
1614  tree->SetBranchAddress("lumi", &lumi);
1615  tree->SetBranchAddress("bfield", &bfield);
1616  tree->SetBranchAddress("nxt", &nxt); // nb of filled Crystals
1617  tree->SetBranchAddress("time", time);
1618  tree->SetBranchAddress("fed", fed);
1619  tree->SetBranchAddress("chan", chan);
1620  tree->SetBranchAddress("ped", ped);
1621  tree->SetBranchAddress("pedrms", pedrms);
1622  int nevents = (int)tree->GetEntries();
1623  edm::LogInfo(" nb entries ") << nevents;
1624  std::ofstream fout;
1625  fout.open("copyTimestampPedestals.txt");
1626  if(!fout.is_open()) {
1627  edm::LogInfo("ERROR : cannot open file copyTimestampPedestals.txt");
1628  exit (1);
1629  }
1630  Double_t EAmean1[kChannels], EArms1[kChannels], EAmean6[kChannels], EArms6[kChannels], EAmean12[kChannels], EArms12[kChannels];
1631  for(int ich = 0; ich < kChannels; ich++) {
1632  EAmean12[ich] = 200.;
1633  EArms12[ich] = 0.;
1634  }
1635  tree->GetEntry(0);
1636  fout << " first run " << run << " fill " << fill_num << " B field " << bfield << " run type " << run_type << " seq_id " << seq_id
1637  << " las_id " << las_id << " run_num_infill " << run_num_infill << " lumi "<< lumi << " nb of Crystals " << nxt << std::endl;
1638  if(debug) {
1639  for(int ich = 0; ich < kChannels; ich++) {
1640  if(ped[ich] != 0.) {
1641  if(ich < kEBChannels)
1642  fout << " channel " << ich << " FED " << fed[ich] << " chan " << chan[ich] << " pedestal " << ped[ich] << " RMS " << pedrms[ich] << std::endl;
1643  else // EE
1644  fout << " channel " << ich << " EE channel " << ich - kEBChannels << " FED " << fed[ich] << " chan " << chan[ich]
1645  << " pedestal " << ped[ich] << " RMS " << pedrms[ich] << std::endl;
1646  }
1647  }
1648  } // debug
1649 
1650  int runold = -1, fillold = -1, firsttimeFEDold = -1;
1651  int firsttimeFED = -1, firstFillSequence = 0;
1652  bool firstSeqBeforeStable = false;
1653  int transfer = 0;
1654  int first_run_kept = (int)m_firstRun; // m_firstRun is unsigned!
1655  int last_run_kept = (int)m_lastRun; // m_lastRun is unsigned!
1656  for(int entry = 0; entry < nevents; entry++) {
1657  tree->GetEntry(entry);
1658  if(nxt != kChannels) {
1659  // fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1660  fout << " entry " << entry << " run " << run << " sequence " << seq_id // run_time always 0!
1661  << " *********** Number of channels " << nxt;
1662  // if(seq_id == 0) { corrected Sep 15 2017
1663  fout << " rejected" << std::endl;
1664  continue;
1665  // }
1666  // else fout << std::endl;
1667  }
1668  if(run_type != 1) {
1669  fout << " entry " << entry << " run " << run << " sequence " << seq_id
1670  << " *********** run_type ( 1 coll, 2 cosm, 3 circ, 4 test ) = " << run_type << std::endl;
1671  continue;
1672  }
1673  if(las_id != 447) { //447 = blue laser
1674  fout << " entry " << entry << " run " << run << " sequence " << seq_id
1675  << " *********** laser wave length = " << las_id << std::endl;
1676  continue;
1677  }
1678  // if(las_id != 527) { //527 = green laser
1679  // fout << " entry " << entry << " run " << run << " sequence " << seq_id
1680  // << " *********** laser wave length = " << las_id << std::endl;
1681  // continue;
1682  // }
1683  if(bfield < 3.79) {
1684  fout << " entry " << entry << " run " << run << " sequence " << seq_id
1685  << " *********** bfield = " << bfield << std::endl;
1686  // continue; keep these runs
1687  }
1688  fout << " entry "<< entry << " run " << run;
1689  if(run_type == 1) fout << " fill " << fill_num;
1690  fout << " sequence " << seq_id;
1691  if(run_type == 1) {
1692  fout << " stable " << run_time_stablebeam;
1693  if(run_time_stablebeam < first_run_kept) {
1694  fout << " before first wanted " << m_firstRun << std::endl;
1695  continue;
1696  }
1697  }
1698  firsttimeFED = time[0];
1699  for(int ifed = 0; ifed < 54; ifed++) {
1700  if(time[ifed] > firsttimeFEDold && time[ifed] < firsttimeFED) firsttimeFED = time[ifed]; // take the first AFTER the previous sequence one!...
1701  }
1702  if(firsttimeFED < first_run_kept) {
1703  fout << " time " << firsttimeFED << " before first wanted " << m_firstRun << std::endl;
1704  continue;
1705  }
1706  if(firsttimeFED > last_run_kept) {
1707  fout << " entry " << entry << " time " << firsttimeFED << " after last wanted " << m_lastRun << std::endl;
1708  break;
1709  }
1710  fout << " time " << firsttimeFED << std::endl;
1711  if(firsttimeFED <= firsttimeFEDold) {
1712  edm::LogInfo(" Problem finding the IOV : old one ") << firsttimeFEDold << " new one " << firsttimeFED;
1713  for(int ifed = 0; ifed < 54; ifed++)
1714  edm::LogInfo("Time ") << time[ifed] << " ignore this entry ";
1715  continue;
1716  }
1717  firsttimeFEDold = firsttimeFED;
1718 
1719  // if(run != runold) firstSeqBeforeStable = false;
1720  if(fill_num != fillold) {
1721  firstSeqBeforeStable = false;
1722  firstFillSequence = 0;
1723  }
1724  else firstFillSequence++;
1725  if(run_type == 1) {
1726  if(run_time_stablebeam > 0) {
1727  if(firsttimeFED < run_time_stablebeam) {
1728  fout << " data taken before stable beam, skip it" << std::endl;
1729  firstSeqBeforeStable = true;
1730  runold = run;
1731  fillold = fill_num;
1732  continue;
1733  }
1734  }
1735  else // problem with run_time_stablebeam
1736  fout << " *** entry " << entry << " run_time_stablebeam " << run_time_stablebeam << std::endl;
1737  if(firstSeqBeforeStable) { // this is the first fully filled entry after stable beam
1738  firstSeqBeforeStable = false;
1739  firsttimeFED = run_time_stablebeam;
1740  fout << " first full sequence after stable; change the IOV " << firsttimeFED << std::endl;
1741  }
1742  if(firstFillSequence == 0) { // first sequence in this fill
1743  if(firsttimeFED > run_time_stablebeam) {
1744  fout << " first full sequence " << firsttimeFED << " after stable " << run_time_stablebeam << "; change the IOV " << std::endl;
1745  firsttimeFED = run_time_stablebeam;
1746  }
1747  }
1748  } // only collision runs
1749 
1750  for(int ich = 0; ich < kChannels; ich++) {
1751  if(ped[ich] < 300 && ped[ich] > 100) {
1752  EAmean12[ich] = ped[ich];
1753  EArms12[ich] = pedrms[ich];
1754  }
1755  }
1756  // get gain 1 and 6 results
1757  bool foundNew = false;
1758  if(run != runold) {
1759  for(int i = run16Index; i < Nbpedxml; i++) {
1760  if(run > pedxml[i]) {
1761  fout << " found a new gain 1, 6 file " << pedxml[i] << " at index " << i << std::endl;
1762  run16Index++;
1763  foundNew = true;
1764  // if(runold < pedxml[i + 1]) break; why runold??
1765  if(run < pedxml[i + 1]) break;
1766  }
1767  }
1768  if(foundNew) {
1769  int Indexxml = run16Index -1;
1770  fout << " opening Pedestals_" << pedxml[Indexxml] << ".xml at index " << Indexxml << std::endl;
1771  std::ifstream fxml;
1772  fxml.open(Form("Pedestals_%i.xml",pedxml[Indexxml]));
1773  if(!fxml.is_open()) {
1774  edm::LogInfo("ERROR : cannot open file Pedestals_") << pedxml[Indexxml] << ".xml";
1775  exit (1);
1776  }
1777  std::string dummyLine, mean12, rms12, bid;
1778  for(int i = 0; i < 9; i++) std::getline(fxml, dummyLine); // skip first lines
1779  // Barrel
1780  for (int iEBChannel = 0; iEBChannel < kEBChannels; iEBChannel++) {
1781  fxml >> mean12 >> rms12 >> bid;
1782  std::string stt = bid.substr(9,15);
1783  std::istringstream m6(stt);
1784  m6 >> EAmean6[iEBChannel];
1785  fxml >> bid;
1786  stt = bid.substr(8,15);
1787  std::istringstream r6(stt);
1788  r6 >> EArms6[iEBChannel];
1789  fxml >> bid;
1790  stt = bid.substr(9,15);
1791  std::istringstream m1(stt);
1792  m1 >> EAmean1[iEBChannel];
1793  fxml >> bid;
1794  stt = bid.substr(8,15);
1795  std::istringstream r1(stt);
1796  r1 >> EArms1[iEBChannel];
1797  if(debug && iEBChannel%10000 == 0) fout << " EB channel " << iEBChannel << " " << mean12 << " " << rms12
1798  << " " << EAmean6[iEBChannel] << " " << EArms6[iEBChannel]
1799  << " " << EAmean1[iEBChannel] << " " << EArms1[iEBChannel] << std::endl;
1800  for(int i = 0; i < 3; i++) std::getline(fxml, dummyLine); // skip lines
1801  }
1802  for(int i = 0; i < 6; i++) std::getline(fxml, dummyLine); // skip lines
1803  for (int iEEChannel = 0; iEEChannel < kEEChannels; iEEChannel++) {
1804  int ich = iEEChannel + kEBChannels;
1805  fxml >> mean12 >> rms12 >> bid;
1806  std::string stt = bid.substr(9,15);
1807  std::istringstream m6(stt);
1808  m6 >> EAmean6[ich];
1809  fxml >> bid;
1810  stt = bid.substr(8,15);
1811  std::istringstream r6(stt);
1812  r6 >> EArms6[ich];
1813  fxml >> bid;
1814  stt = bid.substr(9,15);
1815  std::istringstream m1(stt);
1816  m1 >> EAmean1[ich];
1817  fxml >> bid;
1818  stt = bid.substr(8,15);
1819  std::istringstream r1(stt);
1820  r1 >> EArms1[ich];
1821  if(debug && iEEChannel%1000 == 0)
1822  fout << " EE channel " << iEEChannel << " " << mean12 << " " << rms12
1823  << " " << EAmean6[ich] << " " << EArms6[ich]
1824  << " " << EAmean1[ich] << " " << EArms1[ich] << std::endl;
1825  for(int i = 0; i < 3; i++) std::getline(fxml, dummyLine); // skip lines
1826  }
1827  fxml.close();
1828  } // found a new gain 1 6 file
1829  } // check gain 1 and 6 results only for new runs
1830 
1832  EcalPedestals::Item item;
1833  for(int ich = 0; ich < kChannels; ich++) {
1834  if(debug && ich%10000 == 0) fout << " channel " << ich << " ped " << EAmean12[ich] << " RMS " << EArms12[ich] << std::endl;
1835  //
1836  item.mean_x1 = EAmean1[ich];
1837  item.rms_x1 = EArms1[ich];
1838  item.mean_x6 = EAmean6[ich];
1839  item.rms_x6 = EArms6[ich];
1840  item.mean_x12 = EAmean12[ich];
1841  item.rms_x12 = EArms12[ich];
1842  if(ich < kEBChannels) {
1843  // EBDetId ebdetid(fed, chan, EBDetId::SMCRYSTALMODE);
1844  EBDetId ebdetid = EBDetId::unhashIndex(ich);
1845  pedestal->insert(std::make_pair(ebdetid.rawId(),item));
1846  }
1847  else {
1848  // EEDetId eedetid(iX, iY, iz);
1849  int iChannel = ich - kEBChannels;
1850  EEDetId eedetid = EEDetId::unhashIndex(iChannel);
1851  pedestal->insert(std::make_pair(eedetid.rawId(),item));
1852  }
1853  } // end loop over all channels
1854  uint64_t iov = (uint64_t)firsttimeFED << 32;
1855  Time_t snc = (Time_t) iov;
1856  transfer++;
1857  fout << " entry " << entry << " transfer " << transfer << " iov " << iov << std::endl;
1858  m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedestal, snc)); // time based IOV
1859  fout << " m_to_transfer " << firsttimeFED << std::endl;
1860  runold = run;
1861  fillold = fill_num;
1862  } // end loop over all entries
1863 
1864  edm::LogInfo("Ecal - > end of readPedestalTimestamp -----------\n");
1865 }
const Int_t kEBChannels
std::string id() const override
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:65
const Int_t kEEChannels
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void insert(std::pair< uint32_t, Item > const &a)
EcalPedestalsMap EcalPedestals
Definition: EcalPedestals.h:53
#define debug
Definition: HDRShower.cc:19
unsigned long long uint64_t
Definition: Time.h:15
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:110
const Int_t Nbpedxml
Definition: tree.py:1
const Int_t kChannels
void popcon::EcalPedestalsHandler::readPedestalTree ( )

Definition at line 1205 of file EcalPedestalsHandler.cc.

References funct::abs(), officialStyle::chan, mps_splice::entry, cmsRelvalreport::exit, groupFilesInBlocks::fout, mps_fire::i, id(), EcalCondObjectContainer< T >::insert(), createfilelist::int, kChannels, kEBChannels, kEEChannels, csvLumiCalc::lumi, m_filename, m_firstRun, m_lastRun, m_runtype, popcon::PopConSourceHandler< EcalPedestals >::m_to_transfer, EcalPedestal::mean_x1, EcalPedestal::mean_x12, EcalPedestal::mean_x6, Nbpedxml, muonCSCDigis_cfi::pedestal, diffTwoXMLs::r1, DetId::rawId(), EcalPedestal::rms_x1, EcalPedestal::rms_x12, EcalPedestal::rms_x6, writedatasetfile::run, AlCaHLTBitMon_QueryRunRegistry::string, ntuplemaker::time, EBDetId::unhashIndex(), and EEDetId::unhashIndex().

Referenced by getNewObjects().

1205  {
1206  edm::LogInfo(" reading the root file ") << m_filename;
1207  TFile * hfile = new TFile(m_filename.c_str());
1208 
1209  TTree *treeChan = (TTree*)hfile->Get("PedChan");
1210  int iChannel = 0, ix = 0, iy = 0, iz = 0;
1211  treeChan->SetBranchAddress("Channels", &iChannel);
1212  treeChan->SetBranchAddress("x", &ix);
1213  treeChan->SetBranchAddress("y", &iy);
1214  treeChan->SetBranchAddress("z", &iz);
1215  int neventsChan = (int)treeChan->GetEntries();
1216  edm::LogInfo("PedChan nb entries ") << neventsChan;
1217  int ringEB[kEBChannels], sideEB[kEBChannels], ixEE[kEEChannels], iyEE[kEEChannels], izEE[kEEChannels];
1218  for(int entry = 0; entry < neventsChan; entry++) {
1219  treeChan->GetEntry(entry);
1220  if(entry < kEBChannels) {
1221  ringEB[iChannel] = (abs(ix) -1)/5; // -85...-1, 1...85 give 0...16
1222  sideEB[iChannel] = 1;
1223  if(ix < 0) sideEB[iChannel] = 0;
1224  if(entry%10000 == 0) edm::LogInfo(" EB channel ") << iChannel << " eta " << ix << " phi " << iy
1225  << " side " << sideEB[iChannel] << " ring " << ringEB[iChannel];
1226  }
1227  else {
1228  ixEE[iChannel] = ix;
1229  iyEE[iChannel] = iy;
1230  izEE[iChannel] = iz;
1231  if(entry%1000 == 0) edm::LogInfo(" EE channel ") << iChannel << " x " << ixEE[iChannel] << " y " << iyEE[iChannel] << " z " << izEE[iChannel];
1232  }
1233  }
1234  // 2016 : 26
1235  Int_t pedxml[Nbpedxml] = {271948, 273634, 273931, 274705, 275403, 276108, 276510, 277169, 278123, 278183,
1236  278246, 278389, 278499, 278693, 278858, 278888, 278931, 279728, 280129, 280263,
1237  280941, 281753, 282631, 282833, 283199, 283766,
1238  // 2017 : 25
1239  286535, 293513, 293632, 293732, 295507, 295672, 296391, 296917, 297388, 298481,
1240  299279, 299710, 300186, 300581, 301191, 302006, 302293, 302605, 303436, 303848,
1241  304211, 304680, 305117, 305848, 306176,
1242  // 2018 : 30
1243  313760, 315434, 315831, 316299, 316694, 316963, 317399, 317669, 318249, 318747,
1244  319111, 319365, 319700, 320098, 320515, 320905, 321184, 321480, 321855, 322151,
1245  322653, 323261, 323802, 324250, 324632, 325909, 326038, 326652, 326979, 327271};
1246 
1247  Int_t run16Index = 0;
1248 
1249  Int_t fed[kChannels], chan[kChannels], id, run, run_type, seq_id, las_id, fill_num, run_num_infill, run_time, run_time_stablebeam, nxt, time[54];
1250  Float_t ped[kChannels], pedrms[kChannels], lumi, bfield;
1251  TTree *tree = (TTree*)hfile->Get("T");
1252  tree->Print();
1253  tree->SetBranchAddress("id", &id);
1254  tree->SetBranchAddress("run", &run);
1255  tree->SetBranchAddress("run_type", &run_type);
1256  tree->SetBranchAddress("seq_id", &seq_id);
1257  tree->SetBranchAddress("las_id", &las_id);
1258  tree->SetBranchAddress("fill_num", &fill_num);
1259  tree->SetBranchAddress("run_num_infill", &run_num_infill);
1260  tree->SetBranchAddress("run_time", &run_time);
1261  tree->SetBranchAddress("run_time_stablebeam", &run_time_stablebeam);
1262  tree->SetBranchAddress("lumi", &lumi);
1263  tree->SetBranchAddress("bfield", &bfield);
1264  tree->SetBranchAddress("nxt", &nxt); // nb of filled Crystals
1265  tree->SetBranchAddress("time", time);
1266  tree->SetBranchAddress("fed", fed);
1267  tree->SetBranchAddress("chan", chan);
1268  tree->SetBranchAddress("ped", ped);
1269  tree->SetBranchAddress("pedrms", pedrms);
1270  int nevents = (int)tree->GetEntries();
1271  edm::LogInfo(" nb entries ") << nevents;
1272  std::ofstream fout;
1273  fout.open("copyTreePedestals.txt");
1274  if(!fout.is_open()) {
1275  edm::LogInfo("ERROR : cannot open file copyTreePedestals.txt");
1276  exit (1);
1277  }
1278  Double_t EAmean1[kChannels], EArms1[kChannels], EAmean6[kChannels], EArms6[kChannels], EAmean12[kChannels], EArms12[kChannels];
1279  Int_t RunEntry = 0, EAentry[kChannels];
1280  for(int ich = 0; ich < kChannels; ich++) {
1281  EAmean12[ich] = 0;
1282  EArms12[ich] = 0;
1283  EAentry[ich] = 0;
1284  }
1285  tree->GetEntry(0);
1286  fout << " first run " << run << " fill " << fill_num << " B field " << bfield << " run type " << run_type << " seq_id " << seq_id
1287  << " las_id " << las_id << " run_num_infill " << run_num_infill << " lumi "<< lumi << " nb of Crystals " << nxt << std::endl;
1288  for(int ich = 0; ich < kChannels; ich++) {
1289  if(ped[ich] != 0.) {
1290  if(ich < kEBChannels)
1291  fout << " channel " << ich << " FED " << fed[ich] << " chan " << chan[ich] << " pedestal " << ped[ich] << " RMS " << pedrms[ich] << std::endl;
1292  else // EE
1293  fout << " channel " << ich << " EE channel " << ich - kEBChannels << " FED " << fed[ich] << " chan " << chan[ich]
1294  << " pedestal " << ped[ich] << " RMS " << pedrms[ich] << std::endl;
1295  }
1296  }
1297 
1298  int run_type_kept = m_runtype; // 1 collision 2 cosmics 3 circulating 4 test
1299  int first_run_kept = (int)m_firstRun; // m_firstRun is unsigned!
1300  int last_run_kept = (int)m_lastRun; // m_lastRun is unsigned!
1301  int runold = run;
1302  int firsttimeFED = -1;
1303  // int timeold = -1;
1304  for(int entry = 0; entry < nevents; entry++) {
1305  tree->GetEntry(entry);
1306  if(run < first_run_kept) {
1307  fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1308  << " before first wanted " << m_firstRun << std::endl;
1309  runold = run;
1310  continue;
1311  }
1312  if(run > last_run_kept) {
1313  fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1314  << " after last wanted " << m_lastRun << std::endl;
1315  runold = run;
1316  break;
1317  }
1318  if(run_type != run_type_kept) {
1319  fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1320  << " run type " << run_type << std::endl;
1321  continue; // use only wanted type runs
1322  }
1323  if(nxt != kChannels) {
1324  fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1325  << " *********** Number of channels " << nxt << std::endl;
1326  continue;
1327  }
1328  if(bfield < 3.79) {
1329  fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1330  << " *********** bfield = " << bfield << std::endl;
1331  // continue; keep these runs
1332  }
1333  if(run_type_kept == 1) { // for collision runs, keep only sequences after stable beam
1334  int time_seq = 0;
1335  for(int ifed = 0; ifed < 54; ifed++) {
1336  if(time[ifed] < run_time_stablebeam) {
1337  if(time_seq == 0)
1338  fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1339  << " *********** sequence before stable beam at " << run_time_stablebeam << " FED " << ifed << " : " << time[ifed];
1340  else
1341  fout << " FED " << ifed << " : " << time[ifed];
1342  time_seq++;
1343  }
1344  }
1345  if(time_seq != 0) {
1346  fout << " total nb " << time_seq << std::endl;
1347  continue;
1348  }
1349  } // only collision runs
1350  // if(idtime != timeold) {
1351  // edm::LogInfo(" entry ")<< entry << " run " << run << " time " << idtime << " run type " << run_type;
1352  // timeold = idtime;
1353  // }
1354  if(run == runold) {
1355  RunEntry++;
1356  for(int ich = 0; ich < kChannels; ich++) {
1357  if(ped[ich] < 300 && ped[ich] > 100) {
1358  EAmean12[ich] += ped[ich];
1359  EArms12[ich] += pedrms[ich];
1360  EAentry[ich]++;
1361  }
1362  }
1363  }
1364  else {
1365  // new run. Write the previous one
1366  // edm::LogInfo(" entry ")<< entry << " fill " << fill_num << " run " << runold << " nb of events " << RunEntry
1367  // << " time " << run_time << " " << run_time_stablebeam << " " << time[0] << " run type " << run_type;
1368  if(RunEntry == 0 || (run_type_kept == 2 && RunEntry < 6)) fout << " skiped run " << runold << " not enough entries : " << RunEntry << std::endl;
1369  else {
1370  fout << " entry "<< entry -1 << " run " << runold << " nb of events " << RunEntry;
1371  firsttimeFED = time[0];
1372  for(int ifed = 0; ifed < 54; ifed++) {
1373  fout << " " << time[ifed];
1374  if(firsttimeFED < time[ifed]) firsttimeFED = time[ifed];
1375  }
1376  fout << std::endl;
1377 
1378  // get gain 1 and 6 results
1379  bool foundNew = false;
1380  for(int i = run16Index; i < Nbpedxml; i++) {
1381  if(runold > pedxml[i]) {
1382  fout << " found a new gain 1, 6 file " << pedxml[i] << " at index " << i << std::endl;
1383  run16Index++;
1384  foundNew = true;
1385  if(runold < pedxml[i + 1]) break;
1386  }
1387  }
1388  if(foundNew) {
1389  int Indexxml = run16Index -1;
1390  fout << " opening Pedestals_" << pedxml[Indexxml] << ".xml at index " << Indexxml << std::endl;
1391  std::ifstream fxml;
1392  fxml.open(Form("Pedestals_%i.xml",pedxml[Indexxml]));
1393  if(!fxml.is_open()) {
1394  edm::LogInfo("ERROR : cannot open file Pedestals_") << pedxml[Indexxml] << ".xml";
1395  exit (1);
1396  }
1397  std::string dummyLine, mean12, rms12, bid;
1398  for(int i = 0; i < 9; i++) std::getline(fxml, dummyLine); // skip first lines
1399  // Barrel
1400  for (int iEBChannel = 0; iEBChannel < kEBChannels; iEBChannel++) {
1401  fxml >> mean12 >> rms12 >> bid;
1402  // std::string stt = bid.std::substr(10,15);
1403  // istringstream ii(stt);
1404  // ii >> EBmean12[iEBChannel];
1405  // fxml >> bid;
1406  // stt = bid.substr(9,15);
1407  // istringstream r12(stt);
1408  // r12 >> EBrms12[iEBChannel];
1409  // fxml >> bid;
1410  std::string stt = bid.substr(9,15);
1411  std::istringstream m6(stt);
1412  m6 >> EAmean6[iEBChannel];
1413  fxml >> bid;
1414  stt = bid.substr(8,15);
1415  std::istringstream r6(stt);
1416  r6 >> EArms6[iEBChannel];
1417  fxml >> bid;
1418  stt = bid.substr(9,15);
1419  std::istringstream m1(stt);
1420  m1 >> EAmean1[iEBChannel];
1421  fxml >> bid;
1422  stt = bid.substr(8,15);
1423  std::istringstream r1(stt);
1424  r1 >> EArms1[iEBChannel];
1425  if(iEBChannel%10000 == 0) fout << " EB channel " << iEBChannel << " " << mean12 << " " << rms12
1426  << " " << EAmean6[iEBChannel] << " " << EArms6[iEBChannel]
1427  << " " << EAmean1[iEBChannel] << " " << EArms1[iEBChannel] << std::endl;
1428  for(int i = 0; i < 3; i++) std::getline(fxml, dummyLine); // skip lines
1429  }
1430  for(int i = 0; i < 6; i++) std::getline(fxml, dummyLine); // skip lines
1431  for (int iEEChannel = 0; iEEChannel < kEEChannels; iEEChannel++) {
1432  int ich = iEEChannel + kEBChannels;
1433  fxml >> mean12 >> rms12 >> bid;
1434  std::string stt = bid.substr(9,15);
1435  std::istringstream m6(stt);
1436  m6 >> EAmean6[ich];
1437  fxml >> bid;
1438  stt = bid.substr(8,15);
1439  std::istringstream r6(stt);
1440  r6 >> EArms6[ich];
1441  fxml >> bid;
1442  stt = bid.substr(9,15);
1443  std::istringstream m1(stt);
1444  m1 >> EAmean1[ich];
1445  fxml >> bid;
1446  stt = bid.substr(8,15);
1447  std::istringstream r1(stt);
1448  r1 >> EArms1[ich];
1449  if(iEEChannel%1000 == 0) fout << " EE channel " << iEEChannel << " " << mean12 << " " << rms12
1450  << " " << EAmean6[ich] << " " << EArms6[ich]
1451  << " " << EAmean1[ich] << " " << EArms1[ich] << std::endl;
1452  for(int i = 0; i < 3; i++) std::getline(fxml, dummyLine); // skip lines
1453  }
1454 
1455  fxml.close();
1456  }
1457  // end gain 1 and 6 results
1458 
1460  EcalPedestals::Item item;
1461  for(int ich = 0; ich < kChannels; ich++) {
1462  if(EAentry[ich] != 0) {
1463  EAmean12[ich] /= EAentry[ich];
1464  EArms12[ich] /= EAentry[ich];
1465  }
1466  else {
1467  EAmean12[ich] = 200.;
1468  EArms12[ich] = 0.;
1469  }
1470  if(ich%10000 == 0) fout << " channel " << ich << " ped " << EAmean12[ich] << " RMS " << EArms12[ich] << std::endl;
1471  //
1472  item.mean_x1 = EAmean1[ich];
1473  item.rms_x1 = EArms1[ich];
1474  item.mean_x6 = EAmean6[ich];
1475  item.rms_x6 = EArms6[ich];
1476  item.mean_x12 = EAmean12[ich];
1477  item.rms_x12 = EArms12[ich];
1478  if(ich < kEBChannels) {
1479  // EBDetId ebdetid(fed, chan, EBDetId::SMCRYSTALMODE);
1480  EBDetId ebdetid = EBDetId::unhashIndex(ich);
1481  pedestal->insert(std::make_pair(ebdetid.rawId(),item));
1482  }
1483  else {
1484  // EEDetId eedetid(iX, iY, iz);
1485  int iChannel = ich - kEBChannels;
1486  EEDetId eedetid = EEDetId::unhashIndex(iChannel);
1487  pedestal->insert(std::make_pair(eedetid.rawId(),item));
1488  }
1489  } // end loop over all channels
1490  Time_t snc= (Time_t) runold;
1491  m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedestal, snc));
1492  } // skip too short cosmics runs
1493 
1494  runold = run;
1495  RunEntry = 1;
1496  for(int ich = 0; ich < kChannels; ich++) {
1497  if(ped[ich] < 300 && ped[ich] > 100) {
1498  EAmean12[ich] = ped[ich];
1499  EArms12[ich] = pedrms[ich];
1500  EAentry[ich] = 1;
1501  }
1502  else {
1503  EAmean12[ich] = 0;
1504  EArms12[ich] = 0;
1505  EAentry[ich] = 0;
1506  }
1507  }
1508  } // new run
1509  } // end loop over all entries
1510  // write also the last run
1511  fout << " last entry fill " << fill_num << " run " << runold << " nb of events " << RunEntry
1512  << " time " << run_time << " " << run_time_stablebeam << " " << time[0] << " run type " << run_type << std::endl;
1513  for(int ifed = 0; ifed < 54; ifed++)
1514  fout << " " << time[ifed];
1515  fout << std::endl;
1516  EcalPedestals* pedestal = new EcalPedestals();
1517  EcalPedestals::Item item;
1518  for(int ich = 0; ich < kChannels; ich++) {
1519  if(EAentry[ich] != 0) {
1520  EAmean12[ich] /= EAentry[ich];
1521  EArms12[ich] /= EAentry[ich];
1522  }
1523  else {
1524  EAmean12[ich] = 200.;
1525  EArms12[ich] = 0.;
1526  }
1527  if(ich%10000 == 0) fout << " channel " << ich << " ped " << EAmean12[ich] << " RMS " << EArms12[ich] << std::endl;
1528  // get gain 1 and 6 results
1529  // ...
1530  //
1531  item.mean_x1 = EAmean1[ich];
1532  item.rms_x1 = EArms1[ich];
1533  item.mean_x6 = EAmean6[ich];
1534  item.rms_x6 = EArms6[ich];
1535  item.mean_x12 = EAmean12[ich];
1536  item.rms_x12 = EArms12[ich];
1537  if(ich < kEBChannels) {
1538  // EBDetId ebdetid(fed, chan, EBDetId::SMCRYSTALMODE);
1539  EBDetId ebdetid = EBDetId::unhashIndex(ich);
1540  pedestal->insert(std::make_pair(ebdetid.rawId(),item));
1541  }
1542  else {
1543  // EEDetId eedetid(iX, iY, iz);
1544  int iChannel = ich - kEBChannels;
1545  EEDetId eedetid = EEDetId::unhashIndex(iChannel);
1546  pedestal->insert(std::make_pair(eedetid.rawId(),item));
1547  }
1548  } // end loop over all channels
1549  Time_t snc= (Time_t) runold;
1550  m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedestal,snc)); // run based IOV
1551  edm::LogInfo("Ecal - > end of readPedestalTree -----------\n");
1552 }
const Int_t kEBChannels
std::string id() const override
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:65
const Int_t kEEChannels
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void insert(std::pair< uint32_t, Item > const &a)
EcalPedestalsMap EcalPedestals
Definition: EcalPedestals.h:53
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:110
const Int_t Nbpedxml
Definition: tree.py:1
const Int_t kChannels

Member Data Documentation

EcalCondDBInterface* popcon::EcalPedestalsHandler::econn

Definition at line 68 of file EcalPedestalsHandler.h.

Referenced by getNewObjectsH2(), and getNewObjectsP5().

bool popcon::EcalPedestalsHandler::m_corrected
private

Definition at line 86 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler(), and readPedestalMC().

std::string popcon::EcalPedestalsHandler::m_filename
private
unsigned int popcon::EcalPedestalsHandler::m_firstRun
private
std::string popcon::EcalPedestalsHandler::m_gentag
private

Definition at line 77 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler(), and getNewObjectsP5().

unsigned int popcon::EcalPedestalsHandler::m_lastRun
private
std::string popcon::EcalPedestalsHandler::m_location
private

Definition at line 76 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler(), and getNewObjectsP5().

std::string popcon::EcalPedestalsHandler::m_locationsource
private

Definition at line 82 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler(), and getNewObjects().

std::string popcon::EcalPedestalsHandler::m_name
private

Definition at line 83 of file EcalPedestalsHandler.h.

std::string popcon::EcalPedestalsHandler::m_pass
private

Definition at line 81 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler(), getNewObjectsH2(), and getNewObjectsP5().

std::string popcon::EcalPedestalsHandler::m_runtag
private

Definition at line 78 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler(), and getNewObjectsP5().

int popcon::EcalPedestalsHandler::m_runtype
private

Definition at line 85 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler(), and readPedestalTree().

std::string popcon::EcalPedestalsHandler::m_sid
private

Definition at line 79 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler(), getNewObjectsH2(), and getNewObjectsP5().

std::string popcon::EcalPedestalsHandler::m_user
private

Definition at line 80 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler(), getNewObjectsH2(), and getNewObjectsP5().

const EcalPedestals* popcon::EcalPedestalsHandler::mypedestals
private

Definition at line 71 of file EcalPedestalsHandler.h.