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 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 ()
 
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::map< Time_t, std::shared_ptr< EcalPedestals > > Container
 
typedef std::unique_ptr< EcalPedestalsRef
 
typedef PopConSourceHandler< EcalPedestalsself
 
typedef cond::Time_t Time_t
 
typedef EcalPedestals value_type
 
- Protected Member Functions inherited from popcon::PopConSourceHandler< EcalPedestals >
cond::persistency::SessiondbSession () const
 
- Protected Attributes inherited from popcon::PopConSourceHandler< EcalPedestals >
Container m_iovs
 
std::vector< std::pair< EcalPedestals *, Time_t > > m_to_transfer
 
std::string m_userTextLog
 

Detailed Description

Definition at line 50 of file EcalPedestalsHandler.h.

Constructor & Destructor Documentation

◆ EcalPedestalsHandler()

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

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 << "/"
34  << "/" << m_location << "/" << m_gentag;
35 }
Log< level::Info, false > LogInfo

◆ ~EcalPedestalsHandler()

popcon::EcalPedestalsHandler::~EcalPedestalsHandler ( )
override

Definition at line 37 of file EcalPedestalsHandler.cc.

37 {}

Member Function Documentation

◆ checkPedestal()

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

Definition at line 61 of file EcalPedestalsHandler.cc.

References B2GTnPMonitor_cfi::item, and mps_fire::result.

61  {
62  // true means all is standard and OK
63  bool result = true;
64  if (item->rms_x12 > 3 || item->rms_x12 <= 0)
65  result = false;
66  if (item->rms_x6 > 2 || item->rms_x6 <= 0)
67  result = false;
68  if (item->rms_x1 > 1 || item->rms_x1 <= 0)
69  result = false;
70  if (item->mean_x12 > 300 || item->mean_x12 <= 100)
71  result = false;
72  if (item->mean_x1 > 300 || item->mean_x1 <= 100)
73  result = false;
74  if (item->mean_x6 > 300 || item->mean_x6 <= 100)
75  result = false;
76  return result;
77 }

◆ getNewObjects()

void popcon::EcalPedestalsHandler::getNewObjects ( )
overridevirtual

Implements popcon::PopConSourceHandler< EcalPedestals >.

Definition at line 39 of file EcalPedestalsHandler.cc.

References beamvalidation::exit().

39  {
40  edm::LogInfo("------- Ecal - > getNewObjects\n");
41  if (m_locationsource == "P5") {
43  } else if (m_locationsource == "H2") {
45  } else if (m_locationsource == "File") {
47  } else if (m_locationsource == "MC") {
49  } else if (m_locationsource == "2017") {
51  } else if (m_locationsource == "Tree") {
53  } else if (m_locationsource == "Timestamp") {
55  } else {
56  edm::LogInfo(" unknown location ") << m_locationsource << " give up ";
57  exit(-1);
58  }
59 }
Log< level::Info, false > LogInfo
def exit(msg="")

◆ getNewObjectsH2()

void popcon::EcalPedestalsHandler::getNewObjectsH2 ( )

Definition at line 468 of file EcalPedestalsHandler.cc.

References gather_cfg::cout, test_db_connect::econn, EcalCondObjectContainer< T >::endcap(), Exception, EcalLogicID::getID2(), MonPedestalsDat::getPedMeanG1(), MonPedestalsDat::getPedMeanG12(), MonPedestalsDat::getPedMeanG6(), MonPedestalsDat::getPedRMSG1(), MonPedestalsDat::getPedRMSG12(), MonPedestalsDat::getPedRMSG6(), MonRunList::getRuns(), EEDetId::hashedIndex(), EcalCondObjectContainer< T >::insert(), B2GTnPMonitor_cfi::item, test_db_connect::my_locdef, test_db_connect::my_rundef, AlCaHLTBitMon_ParallelJobs::p, DetId::rawId(), MonRunTag::setGeneralTag(), RunTag::setGeneralTag(), RunTag::setLocationDef(), MonVersionDef::setMonitoringVersion(), MonRunList::setMonRunTag(), MonRunTag::setMonVersionDef(), MonRunList::setRunTag(), RunTag::setRunTypeDef(), dumpRecoGeometry_cfg::tagInfo, and EEDetId::validDetId().

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

◆ getNewObjectsP5()

void popcon::EcalPedestalsHandler::getNewObjectsP5 ( )

Definition at line 81 of file EcalPedestalsHandler.cc.

References EcalCondObjectContainer< T >::barrel(), gather_cfg::cout, test_db_connect::econn, EcalCondObjectContainer< T >::endcap(), EBDetId::ETAPHIMODE, 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(), l1tTowerCalibrationProducer_cfi::iEta, EcalCondObjectContainer< T >::insert(), B2GTnPMonitor_cfi::item, EEDetId::IX_MAX, EEDetId::IX_MIN, EEDetId::IY_MAX, EEDetId::IY_MIN, EBDetId::MAX_IETA, EBDetId::MAX_IPHI, SiStripPI::min, EBDetId::MIN_IPHI, test_db_connect::my_locdef, test_db_connect::my_rundef, AlCaHLTBitMon_ParallelJobs::p, DetId::rawId(), RunTag::setGeneralTag(), MonRunTag::setGeneralTag(), RunTag::setLocationDef(), MonVersionDef::setMonitoringVersion(), MonRunList::setMonRunTag(), MonRunTag::setMonVersionDef(), MonRunList::setRunTag(), RunTag::setRunTypeDef(), EBDetId::SMCRYSTALMODE, contentValuesCheck::ss, dumpRecoGeometry_cfg::tagInfo, EBDetId::validDetId(), EEDetId::validDetId(), and x.

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

◆ id()

std::string popcon::EcalPedestalsHandler::id ( ) const
inlineoverridevirtual

Implements popcon::PopConSourceHandler< EcalPedestals >.

Definition at line 63 of file EcalPedestalsHandler.h.

References m_name.

63 { return m_name; }

◆ readPedestal2017()

void popcon::EcalPedestalsHandler::readPedestal2017 ( )

Definition at line 1050 of file EcalPedestalsHandler.cc.

References EcalCondObjectContainer< T >::barrel(), debug, EcalCondObjectContainer< T >::endcap(), EBDetId::ETAPHIMODE, beamvalidation::exit(), EBDetId::hashedIndex(), EEDetId::hashedIndex(), l1tTowerCalibrationProducer_cfi::iEta, EcalCondObjectContainer< T >::insert(), B2GTnPMonitor_cfi::item, EEDetId::IX_MAX, EEDetId::IX_MIN, EEDetId::IY_MAX, EEDetId::IY_MIN, kEBChannels, kEEChannels, EBDetId::MAX_IETA, EBDetId::MAX_IPHI, EBDetId::MIN_IPHI, DetId::rawId(), EBDetId::validDetId(), and EEDetId::validDetId().

1050  {
1051  bool debug = false;
1052  edm::LogInfo(" reading local Pedestal run (2017 way)! ") << m_filename;
1053 
1054  // First we copy the last valid record to a temporary object peds
1055  Ref ped_db = lastPayload();
1056  EcalPedestals* peds = new EcalPedestals();
1057  edm::LogInfo("retrieved last payload ");
1058 
1059  for (int iEta = -EBDetId::MAX_IETA; iEta <= EBDetId::MAX_IETA; ++iEta) {
1060  if (iEta == 0)
1061  continue;
1062  for (int iPhi = EBDetId::MIN_IPHI; iPhi <= EBDetId::MAX_IPHI; ++iPhi) {
1063  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
1064  if (EBDetId::validDetId(iEta, iPhi)) {
1065  EBDetId ebdetid(iEta, iPhi, EBDetId::ETAPHIMODE);
1066  EcalPedestals::const_iterator it = ped_db->find(ebdetid.rawId());
1067  EcalPedestals::Item aped = (*it);
1068  // here I copy the last valid value in the peds object
1070  item.mean_x1 = aped.mean_x1;
1071  item.rms_x1 = aped.rms_x1;
1072  item.mean_x6 = aped.mean_x6;
1073  item.rms_x6 = aped.rms_x6;
1074  item.mean_x12 = aped.mean_x12;
1075  item.rms_x12 = aped.rms_x12;
1076  peds->insert(std::make_pair(ebdetid.rawId(), item));
1077  }
1078  }
1079  }
1080  for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
1081  for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
1082  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
1083  if (EEDetId::validDetId(iX, iY, 1)) {
1084  EEDetId eedetidpos(iX, iY, 1);
1085  EcalPedestals::const_iterator it = ped_db->find(eedetidpos.rawId());
1086  EcalPedestals::Item aped = (*it);
1087  // here I copy the last valid value in the peds object
1089  item.mean_x1 = aped.mean_x1;
1090  item.rms_x1 = aped.rms_x1;
1091  item.mean_x6 = aped.mean_x6;
1092  item.rms_x6 = aped.rms_x6;
1093  item.mean_x12 = aped.mean_x12;
1094  item.rms_x12 = aped.rms_x12;
1095  peds->insert(std::make_pair(eedetidpos.rawId(), item));
1096  }
1097  if (EEDetId::validDetId(iX, iY, -1)) {
1098  EEDetId eedetidneg(iX, iY, -1);
1099  EcalPedestals::const_iterator it = ped_db->find(eedetidneg.rawId());
1100  EcalPedestals::Item aped = (*it);
1101  // here I copy the last valid value in the peds object
1103  item.mean_x1 = aped.mean_x1;
1104  item.rms_x1 = aped.rms_x1;
1105  item.mean_x6 = aped.mean_x6;
1106  item.rms_x6 = aped.rms_x6;
1107  item.mean_x12 = aped.mean_x12;
1108  item.rms_x12 = aped.rms_x12;
1109  peds->insert(std::make_pair(eedetidneg.rawId(), item));
1110  }
1111  }
1112  }
1113 
1114  edm::LogInfo(" reading the input file ") << m_filename;
1115  std::ifstream fInput;
1116  fInput.open(m_filename);
1117  if (!fInput.is_open()) {
1118  edm::LogInfo("ERROR : cannot open file ") << m_filename;
1119  exit(1);
1120  }
1121  // string pos, dummyLine;
1122  int hashedId;
1123  float EBmean12[kEBChannels], EBrms12[kEBChannels], EBmean6[kEBChannels], EBrms6[kEBChannels], EBmean1[kEBChannels],
1124  EBrms1[kEBChannels];
1125  //***************** barrel
1126  // getline(fInput, dummyLine); // skip first line
1127  for (int iChannel = 0; iChannel < kEBChannels; iChannel++) {
1128  fInput >> hashedId >> EBmean12[iChannel] >> EBrms12[iChannel] >> EBmean6[iChannel] >> EBrms6[iChannel] >>
1129  EBmean1[iChannel] >> EBrms1[iChannel];
1130  if (hashedId != iChannel + 1) {
1131  edm::LogInfo("File ") << m_filename << " strange hash " << hashedId << " while iChannel " << iChannel;
1132  exit(-1);
1133  }
1134  }
1135 
1136  // ***************** now EE *****************
1137  float EEmean12[kEEChannels], EErms12[kEEChannels], EEmean6[kEEChannels], EErms6[kEEChannels], EEmean1[kEEChannels],
1138  EErms1[kEEChannels];
1139  for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
1140  fInput >> hashedId >> EEmean12[iChannel] >> EErms12[iChannel] >> EEmean6[iChannel] >> EErms6[iChannel] >>
1141  EEmean1[iChannel] >> EErms1[iChannel];
1142  if (hashedId != iChannel + kEBChannels + 1) {
1143  edm::LogInfo("File ") << m_filename << " strange hash " << hashedId << " while iChannel " << iChannel;
1144  exit(-1);
1145  }
1146  }
1147  fInput.close();
1148 
1149  EcalPedestals* ped = new EcalPedestals();
1150  // barrel
1151  for (int iEta = -EBDetId::MAX_IETA; iEta <= EBDetId::MAX_IETA; ++iEta) {
1152  if (iEta == 0)
1153  continue;
1154  for (int iPhi = EBDetId::MIN_IPHI; iPhi <= EBDetId::MAX_IPHI; ++iPhi) {
1155  if (EBDetId::validDetId(iEta, iPhi)) {
1156  EBDetId ebdetid(iEta, iPhi);
1157  unsigned int hieb = ebdetid.hashedIndex();
1159  EcalPedestals::Item previous_ped = peds->barrel(hieb);
1160  if (debug & (EBmean12[hieb] == -999. || EBrms12[hieb] == -999. || EBmean6[hieb] == -999. ||
1161  EBrms6[hieb] == -999. || EBmean1[hieb] == -999. || EBrms1[hieb] == -999.))
1162  edm::LogInfo(" bad EB channel eta ")
1163  << iEta << " phi " << iPhi << " " << EBmean12[hieb] << " " << EBrms12[hieb] << " " << EBmean6[hieb] << " "
1164  << EBrms6[hieb] << " " << EBmean1[hieb] << " " << EBrms1[hieb];
1165  if (EBmean1[hieb] != -999.)
1166  item.mean_x1 = EBmean1[hieb];
1167  else
1168  item.mean_x1 = previous_ped.mean_x1;
1169  if (EBrms1[hieb] != -999.)
1170  item.rms_x1 = EBrms1[hieb];
1171  else
1172  item.rms_x1 = previous_ped.rms_x1;
1173  if (EBmean6[hieb] != -999.)
1174  item.mean_x6 = EBmean6[hieb];
1175  else
1176  item.mean_x6 = previous_ped.mean_x6;
1177  if (EBrms6[hieb] != -999.)
1178  item.rms_x6 = EBrms6[hieb];
1179  else
1180  item.rms_x6 = previous_ped.rms_x6;
1181  if (EBmean12[hieb] != -999.)
1182  item.mean_x12 = EBmean12[hieb];
1183  else
1184  item.mean_x12 = previous_ped.mean_x12;
1185  if (EBrms12[hieb] != -999.)
1186  item.rms_x12 = EBrms12[hieb];
1187  else
1188  item.rms_x12 = previous_ped.rms_x12;
1189  ped->insert(std::make_pair(ebdetid.rawId(), item));
1190  } // valid EBId
1191  } // loop over phi
1192  } // loop over eta
1193  // endcaps
1194  // std::ofstream fout;
1195  // fout.open("Pedestal.check");
1196  for (int iz = -1; iz < 2; iz = iz + 2) { // z : -1 and +1
1197  for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
1198  for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
1199  if (EEDetId::validDetId(iX, iY, iz)) {
1200  EEDetId eedetid(iX, iY, iz);
1201  unsigned int hiee = eedetid.hashedIndex();
1202  // fout << hiee << " mean 12 " << EEmean12[hiee] << std::endl;
1204  EcalPedestals::Item previous_ped = peds->endcap(hiee);
1205  if (debug & (EEmean12[hiee] == -999. || EErms12[hiee] == -999. || EEmean6[hiee] == -999. ||
1206  EErms6[hiee] == -999. || EEmean1[hiee] == -999. || EErms1[hiee] == -999.))
1207  edm::LogInfo(" bad EE channel x ")
1208  << iX << " y " << iY << " z" << iz << " " << EEmean12[hiee] << " " << EErms12[hiee] << " "
1209  << EEmean6[hiee] << " " << EErms6[hiee] << " " << EEmean1[hiee] << " " << EErms1[hiee];
1210  if (EEmean1[hiee] != -999.)
1211  item.mean_x1 = EEmean1[hiee];
1212  else
1213  item.mean_x1 = previous_ped.mean_x1;
1214  if (EErms1[hiee] != -999.)
1215  item.rms_x1 = EErms1[hiee];
1216  else
1217  item.rms_x1 = previous_ped.rms_x1;
1218  if (EEmean6[hiee] != -999.)
1219  item.mean_x6 = EEmean6[hiee];
1220  else
1221  item.mean_x6 = previous_ped.mean_x6;
1222  if (EErms6[hiee] != -999.)
1223  item.rms_x6 = EErms6[hiee];
1224  else
1225  item.rms_x6 = previous_ped.rms_x6;
1226  if (EEmean12[hiee] != -999.)
1227  item.mean_x12 = EEmean12[hiee];
1228  else
1229  item.mean_x12 = previous_ped.mean_x12;
1230  if (EErms12[hiee] != -999.)
1231  item.rms_x12 = EErms12[hiee];
1232  else
1233  item.rms_x12 = previous_ped.rms_x12;
1234  ped->insert(std::make_pair(eedetid.rawId(), item));
1235  } // val EEId
1236  } // loop over y
1237  } // loop over x
1238  } // loop over z
1239  // fout.close();
1240 
1241  unsigned int irun = m_firstRun;
1242  Time_t snc = (Time_t)irun;
1243  m_to_transfer.push_back(std::make_pair((EcalPedestals*)ped, snc));
1244 
1245  edm::LogInfo("Ecal - > end of readPedestal2017 -----------\n");
1246 }
const Int_t kEBChannels
static const int MIN_IPHI
Definition: EBDetId.h:135
const Item & barrel(size_t hashedIndex) const
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 Item & endcap(size_t hashedIndex) const
std::vector< std::pair< EcalPedestals *, Time_t > > m_to_transfer
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
Log< level::Info, false > LogInfo
EcalPedestalsMap EcalPedestals
Definition: EcalPedestals.h:50
#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
def exit(msg="")

◆ readPedestalFile()

void popcon::EcalPedestalsHandler::readPedestalFile ( )

Definition at line 661 of file EcalPedestalsHandler.cc.

References beamvalidation::exit(), EBDetId::hashedIndex(), EEDetId::hashedIndex(), l1tTowerCalibrationProducer_cfi::iEta, EcalCondObjectContainer< T >::insert(), B2GTnPMonitor_cfi::item, EEDetId::IX_MAX, EEDetId::IX_MIN, EEDetId::IY_MAX, EEDetId::IY_MIN, kEBChannels, kEEChannels, EBDetId::MAX_IETA, EBDetId::MAX_IPHI, EBDetId::MIN_IPHI, DetId::rawId(), EBDetId::validDetId(), and EEDetId::validDetId().

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

◆ readPedestalMC()

void popcon::EcalPedestalsHandler::readPedestalMC ( )

Definition at line 749 of file EcalPedestalsHandler.cc.

References funct::abs(), beamvalidation::exit(), groupFilesInBlocks::fout, PedestalClient_cfi::gain, gainValues, EBDetId::hashedIndex(), EEDetId::hashedIndex(), mps_fire::i, EBDetId::ieta(), l1tTowerCalibrationProducer_cfi::iEta, LEDCalibrationChannels::ieta, EcalCondObjectContainer< T >::insert(), B2GTnPMonitor_cfi::item, EEDetId::IX_MAX, EEDetId::IX_MIN, EEDetId::IY_MAX, EEDetId::IY_MIN, kEBChannels, kEEChannels, kGains, EBDetId::MAX_IETA, EBDetId::MAX_IPHI, EBDetId::MIN_IPHI, diffTwoXMLs::r1, DetId::rawId(), relativeConstraints::ring, SiStripPI::rms, mathSSE::sqrt(), AlCaHLTBitMon_QueryRunRegistry::string, EBDetId::unhashIndex(), EBDetId::validDetId(), EEDetId::validDetId(), and x.

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

◆ readPedestalTimestamp()

void popcon::EcalPedestalsHandler::readPedestalTimestamp ( )

Definition at line 1682 of file EcalPedestalsHandler.cc.

References funct::abs(), officialStyle::chan, debug, mps_splice::entry, beamvalidation::exit(), groupFilesInBlocks::fout, mps_fire::i, l1ctLayer2EG_cff::id, createfilelist::int, B2GTnPMonitor_cfi::item, kChannels, kEBChannels, kEEChannels, BXlumiParameters_cfi::lumi, Nbpedxml, createIOVlist::nevents, EcalCondDBWriter_cfi::pedestal, diffTwoXMLs::r1, DetId::rawId(), writedatasetfile::run, AlCaHLTBitMon_QueryRunRegistry::string, protons_cff::time, EBDetId::unhashIndex(), and EEDetId::unhashIndex().

1682  {
1683  bool debug = false;
1684  edm::LogInfo(" reading the root file ") << m_filename;
1685  TFile* hfile = new TFile(m_filename.c_str());
1686 
1687  TTree* treeChan = (TTree*)hfile->Get("PedChan");
1688  int iChannel = 0, ix = 0, iy = 0, iz = 0;
1689  treeChan->SetBranchAddress("Channels", &iChannel);
1690  treeChan->SetBranchAddress("x", &ix);
1691  treeChan->SetBranchAddress("y", &iy);
1692  treeChan->SetBranchAddress("z", &iz);
1693  int neventsChan = (int)treeChan->GetEntries();
1694  edm::LogInfo("PedChan nb entries ") << neventsChan;
1695  int ringEB[kEBChannels], sideEB[kEBChannels], ixEE[kEEChannels], iyEE[kEEChannels], izEE[kEEChannels];
1696  for (int entry = 0; entry < neventsChan; entry++) {
1697  treeChan->GetEntry(entry);
1698  if (entry < kEBChannels) {
1699  ringEB[iChannel] = (abs(ix) - 1) / 5; // -85...-1, 1...85 give 0...16
1700  sideEB[iChannel] = 1;
1701  if (ix < 0)
1702  sideEB[iChannel] = 0;
1703  if (debug && entry % 10000 == 0)
1704  edm::LogInfo(" EB channel ") << iChannel << " eta " << ix << " phi " << iy << " side " << sideEB[iChannel]
1705  << " ring " << ringEB[iChannel];
1706  } else {
1707  ixEE[iChannel] = ix;
1708  iyEE[iChannel] = iy;
1709  izEE[iChannel] = iz;
1710  if (debug && entry % 1000 == 0)
1711  edm::LogInfo(" EE channel ") << iChannel << " x " << ixEE[iChannel] << " y " << iyEE[iChannel] << " z "
1712  << izEE[iChannel];
1713  }
1714  }
1715  // 2016: 26
1716  Int_t pedxml[Nbpedxml] = {271948,
1717  273634,
1718  273931,
1719  274705,
1720  275403,
1721  276108,
1722  276510,
1723  277169,
1724  278123,
1725  278183,
1726  278246,
1727  278389,
1728  278499,
1729  278693,
1730  278858,
1731  278888,
1732  278931,
1733  279728,
1734  280129,
1735  280263,
1736  280941,
1737  281753,
1738  282631,
1739  282833,
1740  283199,
1741  283766,
1742  // 2017 : 25
1743  286535,
1744  293513,
1745  293632,
1746  293732,
1747  295507,
1748  295672,
1749  296391,
1750  296917,
1751  297388,
1752  298481,
1753  299279,
1754  299710,
1755  300186,
1756  300581,
1757  301191,
1758  302006,
1759  302293,
1760  302605,
1761  303436,
1762  303848,
1763  304211,
1764  304680,
1765  305117,
1766  305848,
1767  306176,
1768  // 2018 : 30
1769  313760,
1770  315434,
1771  315831,
1772  316299,
1773  316694,
1774  316963,
1775  317399,
1776  317669,
1777  318249,
1778  318747,
1779  319111,
1780  319365,
1781  319700,
1782  320098,
1783  320515,
1784  320905,
1785  321184,
1786  321480,
1787  321855,
1788  322151,
1789  322653,
1790  323261,
1791  323802,
1792  324250,
1793  324632,
1794  325909,
1795  326038,
1796  326652,
1797  326979,
1798  327271};
1799 
1800  Int_t run16Index = 0;
1801 
1802  Int_t fed[kChannels], chan[kChannels], id, run, run_type, seq_id, las_id, fill_num, run_num_infill, run_time,
1803  run_time_stablebeam, nxt, time[54];
1804  Float_t ped[kChannels], pedrms[kChannels], lumi, bfield;
1805  TTree* tree = (TTree*)hfile->Get("T");
1806  tree->Print();
1807  tree->SetBranchAddress("id", &id);
1808  tree->SetBranchAddress("run", &run);
1809  tree->SetBranchAddress("run_type", &run_type);
1810  tree->SetBranchAddress("seq_id", &seq_id);
1811  tree->SetBranchAddress("las_id", &las_id);
1812  tree->SetBranchAddress("fill_num", &fill_num);
1813  tree->SetBranchAddress("run_num_infill", &run_num_infill);
1814  tree->SetBranchAddress("run_time", &run_time);
1815  tree->SetBranchAddress("run_time_stablebeam", &run_time_stablebeam);
1816  tree->SetBranchAddress("lumi", &lumi);
1817  tree->SetBranchAddress("bfield", &bfield);
1818  tree->SetBranchAddress("nxt", &nxt); // nb of filled Crystals
1819  tree->SetBranchAddress("time", time);
1820  tree->SetBranchAddress("fed", fed);
1821  tree->SetBranchAddress("chan", chan);
1822  tree->SetBranchAddress("ped", ped);
1823  tree->SetBranchAddress("pedrms", pedrms);
1824  int nevents = (int)tree->GetEntries();
1825  edm::LogInfo(" nb entries ") << nevents;
1826  std::ofstream fout;
1827  fout.open("copyTimestampPedestals.txt");
1828  if (!fout.is_open()) {
1829  edm::LogInfo("ERROR : cannot open file copyTimestampPedestals.txt");
1830  exit(1);
1831  }
1832  Double_t EAmean1[kChannels], EArms1[kChannels], EAmean6[kChannels], EArms6[kChannels], EAmean12[kChannels],
1833  EArms12[kChannels];
1834  for (int ich = 0; ich < kChannels; ich++) {
1835  EAmean12[ich] = 200.;
1836  EArms12[ich] = 0.;
1837  }
1838  tree->GetEntry(0);
1839  fout << " first run " << run << " fill " << fill_num << " B field " << bfield << " run type " << run_type
1840  << " seq_id " << seq_id << " las_id " << las_id << " run_num_infill " << run_num_infill << " lumi " << lumi
1841  << " nb of Crystals " << nxt << std::endl;
1842  if (debug) {
1843  for (int ich = 0; ich < kChannels; ich++) {
1844  if (ped[ich] != 0.) {
1845  if (ich < kEBChannels)
1846  fout << " channel " << ich << " FED " << fed[ich] << " chan " << chan[ich] << " pedestal " << ped[ich]
1847  << " RMS " << pedrms[ich] << std::endl;
1848  else // EE
1849  fout << " channel " << ich << " EE channel " << ich - kEBChannels << " FED " << fed[ich] << " chan "
1850  << chan[ich] << " pedestal " << ped[ich] << " RMS " << pedrms[ich] << std::endl;
1851  }
1852  }
1853  } // debug
1854 
1855  int runold = -1, fillold = -1, firsttimeFEDold = -1;
1856  int firsttimeFED = -1, firstFillSequence = 0;
1857  bool firstSeqBeforeStable = false;
1858  int transfer = 0;
1859  int first_run_kept = (int)m_firstRun; // m_firstRun is unsigned!
1860  int last_run_kept = (int)m_lastRun; // m_lastRun is unsigned!
1861  for (int entry = 0; entry < nevents; entry++) {
1862  tree->GetEntry(entry);
1863  if (nxt != kChannels) {
1864  // fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1865  fout << " entry " << entry << " run " << run << " sequence " << seq_id // run_time always 0!
1866  << " *********** Number of channels " << nxt;
1867  // if(seq_id == 0) { corrected Sep 15 2017
1868  fout << " rejected" << std::endl;
1869  continue;
1870  // }
1871  // else fout << std::endl;
1872  }
1873  if (run_type != 1) {
1874  fout << " entry " << entry << " run " << run << " sequence " << seq_id
1875  << " *********** run_type ( 1 coll, 2 cosm, 3 circ, 4 test ) = " << run_type << std::endl;
1876  continue;
1877  }
1878  if (las_id != 447) { //447 = blue laser
1879  fout << " entry " << entry << " run " << run << " sequence " << seq_id
1880  << " *********** laser wave length = " << las_id << std::endl;
1881  continue;
1882  }
1883  // if(las_id != 527) { //527 = green laser
1884  // fout << " entry " << entry << " run " << run << " sequence " << seq_id
1885  // << " *********** laser wave length = " << las_id << std::endl;
1886  // continue;
1887  // }
1888  if (bfield < 3.79) {
1889  fout << " entry " << entry << " run " << run << " sequence " << seq_id << " *********** bfield = " << bfield
1890  << std::endl;
1891  // continue; keep these runs
1892  }
1893  fout << " entry " << entry << " run " << run;
1894  if (run_type == 1)
1895  fout << " fill " << fill_num;
1896  fout << " sequence " << seq_id;
1897  if (run_type == 1) {
1898  fout << " stable " << run_time_stablebeam;
1899  if (run_time_stablebeam < first_run_kept) {
1900  fout << " before first wanted " << m_firstRun << std::endl;
1901  continue;
1902  }
1903  }
1904  firsttimeFED = time[0];
1905  for (int ifed = 0; ifed < 54; ifed++) {
1906  if (time[ifed] > firsttimeFEDold && time[ifed] < firsttimeFED)
1907  firsttimeFED = time[ifed]; // take the first AFTER the previous sequence one!...
1908  }
1909  if (firsttimeFED < first_run_kept) {
1910  fout << " time " << firsttimeFED << " before first wanted " << m_firstRun << std::endl;
1911  continue;
1912  }
1913  if (firsttimeFED > last_run_kept) {
1914  fout << " entry " << entry << " time " << firsttimeFED << " after last wanted " << m_lastRun << std::endl;
1915  break;
1916  }
1917  fout << " time " << firsttimeFED << std::endl;
1918  if (firsttimeFED <= firsttimeFEDold) {
1919  edm::LogInfo(" Problem finding the IOV : old one ") << firsttimeFEDold << " new one " << firsttimeFED;
1920  for (int ifed = 0; ifed < 54; ifed++)
1921  edm::LogInfo("Time ") << time[ifed] << " ignore this entry ";
1922  continue;
1923  }
1924  firsttimeFEDold = firsttimeFED;
1925 
1926  // if(run != runold) firstSeqBeforeStable = false;
1927  if (fill_num != fillold) {
1928  firstSeqBeforeStable = false;
1929  firstFillSequence = 0;
1930  } else
1931  firstFillSequence++;
1932  if (run_type == 1) {
1933  if (run_time_stablebeam > 0) {
1934  if (firsttimeFED < run_time_stablebeam) {
1935  fout << " data taken before stable beam, skip it" << std::endl;
1936  firstSeqBeforeStable = true;
1937  runold = run;
1938  fillold = fill_num;
1939  continue;
1940  }
1941  } else // problem with run_time_stablebeam
1942  fout << " *** entry " << entry << " run_time_stablebeam " << run_time_stablebeam << std::endl;
1943  if (firstSeqBeforeStable) { // this is the first fully filled entry after stable beam
1944  firstSeqBeforeStable = false;
1945  firsttimeFED = run_time_stablebeam;
1946  fout << " first full sequence after stable; change the IOV " << firsttimeFED << std::endl;
1947  }
1948  if (firstFillSequence == 0) { // first sequence in this fill
1949  if (firsttimeFED > run_time_stablebeam) {
1950  fout << " first full sequence " << firsttimeFED << " after stable " << run_time_stablebeam
1951  << "; change the IOV " << std::endl;
1952  firsttimeFED = run_time_stablebeam;
1953  }
1954  }
1955  } // only collision runs
1956 
1957  for (int ich = 0; ich < kChannels; ich++) {
1958  if (ped[ich] < 300 && ped[ich] > 100) {
1959  EAmean12[ich] = ped[ich];
1960  EArms12[ich] = pedrms[ich];
1961  }
1962  }
1963  // get gain 1 and 6 results
1964  bool foundNew = false;
1965  if (run != runold) {
1966  for (int i = run16Index; i < Nbpedxml; i++) {
1967  if (run > pedxml[i]) {
1968  fout << " found a new gain 1, 6 file " << pedxml[i] << " at index " << i << std::endl;
1969  run16Index++;
1970  foundNew = true;
1971  // if(runold < pedxml[i + 1]) break; why runold??
1972  if (run < pedxml[i + 1])
1973  break;
1974  }
1975  }
1976  if (foundNew) {
1977  int Indexxml = run16Index - 1;
1978  fout << " opening Pedestals_" << pedxml[Indexxml] << ".xml at index " << Indexxml << std::endl;
1979  std::ifstream fxml;
1980  fxml.open(Form("Pedestals_%i.xml", pedxml[Indexxml]));
1981  if (!fxml.is_open()) {
1982  edm::LogInfo("ERROR : cannot open file Pedestals_") << pedxml[Indexxml] << ".xml";
1983  exit(1);
1984  }
1985  std::string dummyLine, mean12, rms12, bid;
1986  for (int i = 0; i < 9; i++)
1987  std::getline(fxml, dummyLine); // skip first lines
1988  // Barrel
1989  for (int iEBChannel = 0; iEBChannel < kEBChannels; iEBChannel++) {
1990  fxml >> mean12 >> rms12 >> bid;
1991  std::string stt = bid.substr(9, 15);
1992  std::istringstream m6(stt);
1993  m6 >> EAmean6[iEBChannel];
1994  fxml >> bid;
1995  stt = bid.substr(8, 15);
1996  std::istringstream r6(stt);
1997  r6 >> EArms6[iEBChannel];
1998  fxml >> bid;
1999  stt = bid.substr(9, 15);
2000  std::istringstream m1(stt);
2001  m1 >> EAmean1[iEBChannel];
2002  fxml >> bid;
2003  stt = bid.substr(8, 15);
2004  std::istringstream r1(stt);
2005  r1 >> EArms1[iEBChannel];
2006  if (debug && iEBChannel % 10000 == 0)
2007  fout << " EB channel " << iEBChannel << " " << mean12 << " " << rms12 << " " << EAmean6[iEBChannel] << " "
2008  << EArms6[iEBChannel] << " " << EAmean1[iEBChannel] << " " << EArms1[iEBChannel] << std::endl;
2009  for (int i = 0; i < 3; i++)
2010  std::getline(fxml, dummyLine); // skip lines
2011  }
2012  for (int i = 0; i < 6; i++)
2013  std::getline(fxml, dummyLine); // skip lines
2014  for (int iEEChannel = 0; iEEChannel < kEEChannels; iEEChannel++) {
2015  int ich = iEEChannel + kEBChannels;
2016  fxml >> mean12 >> rms12 >> bid;
2017  std::string stt = bid.substr(9, 15);
2018  std::istringstream m6(stt);
2019  m6 >> EAmean6[ich];
2020  fxml >> bid;
2021  stt = bid.substr(8, 15);
2022  std::istringstream r6(stt);
2023  r6 >> EArms6[ich];
2024  fxml >> bid;
2025  stt = bid.substr(9, 15);
2026  std::istringstream m1(stt);
2027  m1 >> EAmean1[ich];
2028  fxml >> bid;
2029  stt = bid.substr(8, 15);
2030  std::istringstream r1(stt);
2031  r1 >> EArms1[ich];
2032  if (debug && iEEChannel % 1000 == 0)
2033  fout << " EE channel " << iEEChannel << " " << mean12 << " " << rms12 << " " << EAmean6[ich] << " "
2034  << EArms6[ich] << " " << EAmean1[ich] << " " << EArms1[ich] << std::endl;
2035  for (int i = 0; i < 3; i++)
2036  std::getline(fxml, dummyLine); // skip lines
2037  }
2038  fxml.close();
2039  } // found a new gain 1 6 file
2040  } // check gain 1 and 6 results only for new runs
2041 
2044  for (int ich = 0; ich < kChannels; ich++) {
2045  if (debug && ich % 10000 == 0)
2046  fout << " channel " << ich << " ped " << EAmean12[ich] << " RMS " << EArms12[ich] << std::endl;
2047  //
2048  item.mean_x1 = EAmean1[ich];
2049  item.rms_x1 = EArms1[ich];
2050  item.mean_x6 = EAmean6[ich];
2051  item.rms_x6 = EArms6[ich];
2052  item.mean_x12 = EAmean12[ich];
2053  item.rms_x12 = EArms12[ich];
2054  if (ich < kEBChannels) {
2055  // EBDetId ebdetid(fed, chan, EBDetId::SMCRYSTALMODE);
2056  EBDetId ebdetid = EBDetId::unhashIndex(ich);
2057  pedestal->insert(std::make_pair(ebdetid.rawId(), item));
2058  } else {
2059  // EEDetId eedetid(iX, iY, iz);
2060  int iChannel = ich - kEBChannels;
2061  EEDetId eedetid = EEDetId::unhashIndex(iChannel);
2062  pedestal->insert(std::make_pair(eedetid.rawId(), item));
2063  }
2064  } // end loop over all channels
2065  uint64_t iov = (uint64_t)firsttimeFED << 32;
2066  Time_t snc = (Time_t)iov;
2067  transfer++;
2068  fout << " entry " << entry << " transfer " << transfer << " iov " << iov << std::endl;
2069  m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedestal, snc)); // time based IOV
2070  fout << " m_to_transfer " << firsttimeFED << std::endl;
2071  runold = run;
2072  fillold = fill_num;
2073  } // end loop over all entries
2074 
2075  edm::LogInfo("Ecal - > end of readPedestalTimestamp -----------\n");
2076 }
const Int_t kEBChannels
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:65
std::vector< std::pair< EcalPedestals *, Time_t > > m_to_transfer
const Int_t kEEChannels
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Log< level::Info, false > LogInfo
EcalPedestalsMap EcalPedestals
Definition: EcalPedestals.h:50
#define debug
Definition: HDRShower.cc:19
unsigned long long uint64_t
Definition: Time.h:13
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
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
std::string id() const override
Definition: tree.py:1
def exit(msg="")
const Int_t kChannels

◆ readPedestalTree()

void popcon::EcalPedestalsHandler::readPedestalTree ( )

Definition at line 1249 of file EcalPedestalsHandler.cc.

References funct::abs(), officialStyle::chan, mps_splice::entry, beamvalidation::exit(), groupFilesInBlocks::fout, mps_fire::i, l1ctLayer2EG_cff::id, createfilelist::int, B2GTnPMonitor_cfi::item, kChannels, kEBChannels, kEEChannels, BXlumiParameters_cfi::lumi, Nbpedxml, createIOVlist::nevents, EcalCondDBWriter_cfi::pedestal, diffTwoXMLs::r1, DetId::rawId(), writedatasetfile::run, AlCaHLTBitMon_QueryRunRegistry::string, protons_cff::time, EBDetId::unhashIndex(), and EEDetId::unhashIndex().

1249  {
1250  edm::LogInfo(" reading the root file ") << m_filename;
1251  TFile* hfile = new TFile(m_filename.c_str());
1252 
1253  TTree* treeChan = (TTree*)hfile->Get("PedChan");
1254  int iChannel = 0, ix = 0, iy = 0, iz = 0;
1255  treeChan->SetBranchAddress("Channels", &iChannel);
1256  treeChan->SetBranchAddress("x", &ix);
1257  treeChan->SetBranchAddress("y", &iy);
1258  treeChan->SetBranchAddress("z", &iz);
1259  int neventsChan = (int)treeChan->GetEntries();
1260  edm::LogInfo("PedChan nb entries ") << neventsChan;
1261  int ringEB[kEBChannels], sideEB[kEBChannels], ixEE[kEEChannels], iyEE[kEEChannels], izEE[kEEChannels];
1262  for (int entry = 0; entry < neventsChan; entry++) {
1263  treeChan->GetEntry(entry);
1264  if (entry < kEBChannels) {
1265  ringEB[iChannel] = (abs(ix) - 1) / 5; // -85...-1, 1...85 give 0...16
1266  sideEB[iChannel] = 1;
1267  if (ix < 0)
1268  sideEB[iChannel] = 0;
1269  if (entry % 10000 == 0)
1270  edm::LogInfo(" EB channel ") << iChannel << " eta " << ix << " phi " << iy << " side " << sideEB[iChannel]
1271  << " ring " << ringEB[iChannel];
1272  } else {
1273  ixEE[iChannel] = ix;
1274  iyEE[iChannel] = iy;
1275  izEE[iChannel] = iz;
1276  if (entry % 1000 == 0)
1277  edm::LogInfo(" EE channel ") << iChannel << " x " << ixEE[iChannel] << " y " << iyEE[iChannel] << " z "
1278  << izEE[iChannel];
1279  }
1280  }
1281  // 2016 : 26
1282  Int_t pedxml[Nbpedxml] = {271948,
1283  273634,
1284  273931,
1285  274705,
1286  275403,
1287  276108,
1288  276510,
1289  277169,
1290  278123,
1291  278183,
1292  278246,
1293  278389,
1294  278499,
1295  278693,
1296  278858,
1297  278888,
1298  278931,
1299  279728,
1300  280129,
1301  280263,
1302  280941,
1303  281753,
1304  282631,
1305  282833,
1306  283199,
1307  283766,
1308  // 2017 : 25
1309  286535,
1310  293513,
1311  293632,
1312  293732,
1313  295507,
1314  295672,
1315  296391,
1316  296917,
1317  297388,
1318  298481,
1319  299279,
1320  299710,
1321  300186,
1322  300581,
1323  301191,
1324  302006,
1325  302293,
1326  302605,
1327  303436,
1328  303848,
1329  304211,
1330  304680,
1331  305117,
1332  305848,
1333  306176,
1334  // 2018 : 30
1335  313760,
1336  315434,
1337  315831,
1338  316299,
1339  316694,
1340  316963,
1341  317399,
1342  317669,
1343  318249,
1344  318747,
1345  319111,
1346  319365,
1347  319700,
1348  320098,
1349  320515,
1350  320905,
1351  321184,
1352  321480,
1353  321855,
1354  322151,
1355  322653,
1356  323261,
1357  323802,
1358  324250,
1359  324632,
1360  325909,
1361  326038,
1362  326652,
1363  326979,
1364  327271};
1365 
1366  Int_t run16Index = 0;
1367 
1368  Int_t fed[kChannels], chan[kChannels], id, run, run_type, seq_id, las_id, fill_num, run_num_infill, run_time,
1369  run_time_stablebeam, nxt, time[54];
1370  Float_t ped[kChannels], pedrms[kChannels], lumi, bfield;
1371  TTree* tree = (TTree*)hfile->Get("T");
1372  tree->Print();
1373  tree->SetBranchAddress("id", &id);
1374  tree->SetBranchAddress("run", &run);
1375  tree->SetBranchAddress("run_type", &run_type);
1376  tree->SetBranchAddress("seq_id", &seq_id);
1377  tree->SetBranchAddress("las_id", &las_id);
1378  tree->SetBranchAddress("fill_num", &fill_num);
1379  tree->SetBranchAddress("run_num_infill", &run_num_infill);
1380  tree->SetBranchAddress("run_time", &run_time);
1381  tree->SetBranchAddress("run_time_stablebeam", &run_time_stablebeam);
1382  tree->SetBranchAddress("lumi", &lumi);
1383  tree->SetBranchAddress("bfield", &bfield);
1384  tree->SetBranchAddress("nxt", &nxt); // nb of filled Crystals
1385  tree->SetBranchAddress("time", time);
1386  tree->SetBranchAddress("fed", fed);
1387  tree->SetBranchAddress("chan", chan);
1388  tree->SetBranchAddress("ped", ped);
1389  tree->SetBranchAddress("pedrms", pedrms);
1390  int nevents = (int)tree->GetEntries();
1391  edm::LogInfo(" nb entries ") << nevents;
1392  std::ofstream fout;
1393  fout.open("copyTreePedestals.txt");
1394  if (!fout.is_open()) {
1395  edm::LogInfo("ERROR : cannot open file copyTreePedestals.txt");
1396  exit(1);
1397  }
1398  Double_t EAmean1[kChannels], EArms1[kChannels], EAmean6[kChannels], EArms6[kChannels], EAmean12[kChannels],
1399  EArms12[kChannels];
1400  Int_t RunEntry = 0, EAentry[kChannels];
1401  for (int ich = 0; ich < kChannels; ich++) {
1402  EAmean12[ich] = 0;
1403  EArms12[ich] = 0;
1404  EAentry[ich] = 0;
1405  }
1406  tree->GetEntry(0);
1407  fout << " first run " << run << " fill " << fill_num << " B field " << bfield << " run type " << run_type
1408  << " seq_id " << seq_id << " las_id " << las_id << " run_num_infill " << run_num_infill << " lumi " << lumi
1409  << " nb of Crystals " << nxt << std::endl;
1410  for (int ich = 0; ich < kChannels; ich++) {
1411  if (ped[ich] != 0.) {
1412  if (ich < kEBChannels)
1413  fout << " channel " << ich << " FED " << fed[ich] << " chan " << chan[ich] << " pedestal " << ped[ich]
1414  << " RMS " << pedrms[ich] << std::endl;
1415  else // EE
1416  fout << " channel " << ich << " EE channel " << ich - kEBChannels << " FED " << fed[ich] << " chan "
1417  << chan[ich] << " pedestal " << ped[ich] << " RMS " << pedrms[ich] << std::endl;
1418  }
1419  }
1420 
1421  int run_type_kept = m_runtype; // 1 collision 2 cosmics 3 circulating 4 test
1422  int first_run_kept = (int)m_firstRun; // m_firstRun is unsigned!
1423  int last_run_kept = (int)m_lastRun; // m_lastRun is unsigned!
1424  int runold = run;
1425  int firsttimeFED = -1;
1426  // int timeold = -1;
1427  for (int entry = 0; entry < nevents; entry++) {
1428  tree->GetEntry(entry);
1429  if (run < first_run_kept) {
1430  fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1431  << " before first wanted " << m_firstRun << std::endl;
1432  runold = run;
1433  continue;
1434  }
1435  if (run > last_run_kept) {
1436  fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1437  << " after last wanted " << m_lastRun << std::endl;
1438  runold = run;
1439  break;
1440  }
1441  if (run_type != run_type_kept) {
1442  fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time << " run type "
1443  << run_type << std::endl;
1444  continue; // use only wanted type runs
1445  }
1446  if (nxt != kChannels) {
1447  fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1448  << " *********** Number of channels " << nxt << std::endl;
1449  continue;
1450  }
1451  if (bfield < 3.79) {
1452  fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1453  << " *********** bfield = " << bfield << std::endl;
1454  // continue; keep these runs
1455  }
1456  if (run_type_kept == 1) { // for collision runs, keep only sequences after stable beam
1457  int time_seq = 0;
1458  for (int ifed = 0; ifed < 54; ifed++) {
1459  if (time[ifed] < run_time_stablebeam) {
1460  if (time_seq == 0)
1461  fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1462  << " *********** sequence before stable beam at " << run_time_stablebeam << " FED " << ifed << " : "
1463  << time[ifed];
1464  else
1465  fout << " FED " << ifed << " : " << time[ifed];
1466  time_seq++;
1467  }
1468  }
1469  if (time_seq != 0) {
1470  fout << " total nb " << time_seq << std::endl;
1471  continue;
1472  }
1473  } // only collision runs
1474  // if(idtime != timeold) {
1475  // edm::LogInfo(" entry ")<< entry << " run " << run << " time " << idtime << " run type " << run_type;
1476  // timeold = idtime;
1477  // }
1478  if (run == runold) {
1479  RunEntry++;
1480  for (int ich = 0; ich < kChannels; ich++) {
1481  if (ped[ich] < 300 && ped[ich] > 100) {
1482  EAmean12[ich] += ped[ich];
1483  EArms12[ich] += pedrms[ich];
1484  EAentry[ich]++;
1485  }
1486  }
1487  } else {
1488  // new run. Write the previous one
1489  // edm::LogInfo(" entry ")<< entry << " fill " << fill_num << " run " << runold << " nb of events " << RunEntry
1490  // << " time " << run_time << " " << run_time_stablebeam << " " << time[0] << " run type " << run_type;
1491  if (RunEntry == 0 || (run_type_kept == 2 && RunEntry < 6))
1492  fout << " skiped run " << runold << " not enough entries : " << RunEntry << std::endl;
1493  else {
1494  fout << " entry " << entry - 1 << " run " << runold << " nb of events " << RunEntry;
1495  firsttimeFED = time[0];
1496  for (int ifed = 0; ifed < 54; ifed++) {
1497  fout << " " << time[ifed];
1498  if (firsttimeFED < time[ifed])
1499  firsttimeFED = time[ifed];
1500  }
1501  fout << std::endl;
1502 
1503  // get gain 1 and 6 results
1504  bool foundNew = false;
1505  for (int i = run16Index; i < Nbpedxml; i++) {
1506  if (runold > pedxml[i]) {
1507  fout << " found a new gain 1, 6 file " << pedxml[i] << " at index " << i << std::endl;
1508  run16Index++;
1509  foundNew = true;
1510  if (runold < pedxml[i + 1])
1511  break;
1512  }
1513  }
1514  if (foundNew) {
1515  int Indexxml = run16Index - 1;
1516  fout << " opening Pedestals_" << pedxml[Indexxml] << ".xml at index " << Indexxml << std::endl;
1517  std::ifstream fxml;
1518  fxml.open(Form("Pedestals_%i.xml", pedxml[Indexxml]));
1519  if (!fxml.is_open()) {
1520  edm::LogInfo("ERROR : cannot open file Pedestals_") << pedxml[Indexxml] << ".xml";
1521  exit(1);
1522  }
1523  std::string dummyLine, mean12, rms12, bid;
1524  for (int i = 0; i < 9; i++)
1525  std::getline(fxml, dummyLine); // skip first lines
1526  // Barrel
1527  for (int iEBChannel = 0; iEBChannel < kEBChannels; iEBChannel++) {
1528  fxml >> mean12 >> rms12 >> bid;
1529  // std::string stt = bid.std::substr(10,15);
1530  // istringstream ii(stt);
1531  // ii >> EBmean12[iEBChannel];
1532  // fxml >> bid;
1533  // stt = bid.substr(9,15);
1534  // istringstream r12(stt);
1535  // r12 >> EBrms12[iEBChannel];
1536  // fxml >> bid;
1537  std::string stt = bid.substr(9, 15);
1538  std::istringstream m6(stt);
1539  m6 >> EAmean6[iEBChannel];
1540  fxml >> bid;
1541  stt = bid.substr(8, 15);
1542  std::istringstream r6(stt);
1543  r6 >> EArms6[iEBChannel];
1544  fxml >> bid;
1545  stt = bid.substr(9, 15);
1546  std::istringstream m1(stt);
1547  m1 >> EAmean1[iEBChannel];
1548  fxml >> bid;
1549  stt = bid.substr(8, 15);
1550  std::istringstream r1(stt);
1551  r1 >> EArms1[iEBChannel];
1552  if (iEBChannel % 10000 == 0)
1553  fout << " EB channel " << iEBChannel << " " << mean12 << " " << rms12 << " " << EAmean6[iEBChannel] << " "
1554  << EArms6[iEBChannel] << " " << EAmean1[iEBChannel] << " " << EArms1[iEBChannel] << std::endl;
1555  for (int i = 0; i < 3; i++)
1556  std::getline(fxml, dummyLine); // skip lines
1557  }
1558  for (int i = 0; i < 6; i++)
1559  std::getline(fxml, dummyLine); // skip lines
1560  for (int iEEChannel = 0; iEEChannel < kEEChannels; iEEChannel++) {
1561  int ich = iEEChannel + kEBChannels;
1562  fxml >> mean12 >> rms12 >> bid;
1563  std::string stt = bid.substr(9, 15);
1564  std::istringstream m6(stt);
1565  m6 >> EAmean6[ich];
1566  fxml >> bid;
1567  stt = bid.substr(8, 15);
1568  std::istringstream r6(stt);
1569  r6 >> EArms6[ich];
1570  fxml >> bid;
1571  stt = bid.substr(9, 15);
1572  std::istringstream m1(stt);
1573  m1 >> EAmean1[ich];
1574  fxml >> bid;
1575  stt = bid.substr(8, 15);
1576  std::istringstream r1(stt);
1577  r1 >> EArms1[ich];
1578  if (iEEChannel % 1000 == 0)
1579  fout << " EE channel " << iEEChannel << " " << mean12 << " " << rms12 << " " << EAmean6[ich] << " "
1580  << EArms6[ich] << " " << EAmean1[ich] << " " << EArms1[ich] << std::endl;
1581  for (int i = 0; i < 3; i++)
1582  std::getline(fxml, dummyLine); // skip lines
1583  }
1584 
1585  fxml.close();
1586  }
1587  // end gain 1 and 6 results
1588 
1591  for (int ich = 0; ich < kChannels; ich++) {
1592  if (EAentry[ich] != 0) {
1593  EAmean12[ich] /= EAentry[ich];
1594  EArms12[ich] /= EAentry[ich];
1595  } else {
1596  EAmean12[ich] = 200.;
1597  EArms12[ich] = 0.;
1598  }
1599  if (ich % 10000 == 0)
1600  fout << " channel " << ich << " ped " << EAmean12[ich] << " RMS " << EArms12[ich] << std::endl;
1601  //
1602  item.mean_x1 = EAmean1[ich];
1603  item.rms_x1 = EArms1[ich];
1604  item.mean_x6 = EAmean6[ich];
1605  item.rms_x6 = EArms6[ich];
1606  item.mean_x12 = EAmean12[ich];
1607  item.rms_x12 = EArms12[ich];
1608  if (ich < kEBChannels) {
1609  // EBDetId ebdetid(fed, chan, EBDetId::SMCRYSTALMODE);
1610  EBDetId ebdetid = EBDetId::unhashIndex(ich);
1611  pedestal->insert(std::make_pair(ebdetid.rawId(), item));
1612  } else {
1613  // EEDetId eedetid(iX, iY, iz);
1614  int iChannel = ich - kEBChannels;
1615  EEDetId eedetid = EEDetId::unhashIndex(iChannel);
1616  pedestal->insert(std::make_pair(eedetid.rawId(), item));
1617  }
1618  } // end loop over all channels
1619  Time_t snc = (Time_t)runold;
1620  m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedestal, snc));
1621  } // skip too short cosmics runs
1622 
1623  runold = run;
1624  RunEntry = 1;
1625  for (int ich = 0; ich < kChannels; ich++) {
1626  if (ped[ich] < 300 && ped[ich] > 100) {
1627  EAmean12[ich] = ped[ich];
1628  EArms12[ich] = pedrms[ich];
1629  EAentry[ich] = 1;
1630  } else {
1631  EAmean12[ich] = 0;
1632  EArms12[ich] = 0;
1633  EAentry[ich] = 0;
1634  }
1635  }
1636  } // new run
1637  } // end loop over all entries
1638  // write also the last run
1639  fout << " last entry fill " << fill_num << " run " << runold << " nb of events " << RunEntry << " time " << run_time
1640  << " " << run_time_stablebeam << " " << time[0] << " run type " << run_type << std::endl;
1641  for (int ifed = 0; ifed < 54; ifed++)
1642  fout << " " << time[ifed];
1643  fout << std::endl;
1646  for (int ich = 0; ich < kChannels; ich++) {
1647  if (EAentry[ich] != 0) {
1648  EAmean12[ich] /= EAentry[ich];
1649  EArms12[ich] /= EAentry[ich];
1650  } else {
1651  EAmean12[ich] = 200.;
1652  EArms12[ich] = 0.;
1653  }
1654  if (ich % 10000 == 0)
1655  fout << " channel " << ich << " ped " << EAmean12[ich] << " RMS " << EArms12[ich] << std::endl;
1656  // get gain 1 and 6 results
1657  // ...
1658  //
1659  item.mean_x1 = EAmean1[ich];
1660  item.rms_x1 = EArms1[ich];
1661  item.mean_x6 = EAmean6[ich];
1662  item.rms_x6 = EArms6[ich];
1663  item.mean_x12 = EAmean12[ich];
1664  item.rms_x12 = EArms12[ich];
1665  if (ich < kEBChannels) {
1666  // EBDetId ebdetid(fed, chan, EBDetId::SMCRYSTALMODE);
1667  EBDetId ebdetid = EBDetId::unhashIndex(ich);
1668  pedestal->insert(std::make_pair(ebdetid.rawId(), item));
1669  } else {
1670  // EEDetId eedetid(iX, iY, iz);
1671  int iChannel = ich - kEBChannels;
1672  EEDetId eedetid = EEDetId::unhashIndex(iChannel);
1673  pedestal->insert(std::make_pair(eedetid.rawId(), item));
1674  }
1675  } // end loop over all channels
1676  Time_t snc = (Time_t)runold;
1677  m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedestal, snc)); // run based IOV
1678  edm::LogInfo("Ecal - > end of readPedestalTree -----------\n");
1679 }
const Int_t kEBChannels
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:65
std::vector< std::pair< EcalPedestals *, Time_t > > m_to_transfer
const Int_t kEEChannels
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Log< level::Info, false > LogInfo
EcalPedestalsMap EcalPedestals
Definition: EcalPedestals.h:50
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
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
std::string id() const override
Definition: tree.py:1
def exit(msg="")
const Int_t kChannels

Member Data Documentation

◆ econn

EcalCondDBInterface* popcon::EcalPedestalsHandler::econn

Definition at line 64 of file EcalPedestalsHandler.h.

◆ m_corrected

bool popcon::EcalPedestalsHandler::m_corrected
private

Definition at line 82 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler().

◆ m_filename

std::string popcon::EcalPedestalsHandler::m_filename
private

Definition at line 80 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler().

◆ m_firstRun

unsigned int popcon::EcalPedestalsHandler::m_firstRun
private

Definition at line 69 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler().

◆ m_gentag

std::string popcon::EcalPedestalsHandler::m_gentag
private

Definition at line 73 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler().

◆ m_lastRun

unsigned int popcon::EcalPedestalsHandler::m_lastRun
private

Definition at line 70 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler().

◆ m_location

std::string popcon::EcalPedestalsHandler::m_location
private

Definition at line 72 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler().

◆ m_locationsource

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

Definition at line 78 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler().

◆ m_name

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

Definition at line 79 of file EcalPedestalsHandler.h.

Referenced by id().

◆ m_pass

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

Definition at line 77 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler().

◆ m_runtag

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

Definition at line 74 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler().

◆ m_runtype

int popcon::EcalPedestalsHandler::m_runtype
private

Definition at line 81 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler().

◆ m_sid

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

Definition at line 75 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler().

◆ m_user

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

Definition at line 76 of file EcalPedestalsHandler.h.

Referenced by EcalPedestalsHandler().

◆ mypedestals

const EcalPedestals* popcon::EcalPedestalsHandler::mypedestals
private

Definition at line 67 of file EcalPedestalsHandler.h.