CMS 3D CMS Logo

EcalPulseShapesHandler.cc
Go to the documentation of this file.
2 
3 #include <algorithm>
4 #include <iostream>
5 #include <fstream>
6 
8  : m_name(ps.getUntrackedParameter<std::string>("name", "EcalPulseShapesHandler")) {
9  std::cout << "EcalPulseShape Source handler constructor\n" << std::endl;
10  m_firstRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("firstRun").c_str()));
11  m_filename = ps.getParameter<std::string>("inputFileName");
12  m_EBPulseShapeTemplate = ps.getParameter<std::vector<double> >("EBPulseShapeTemplate");
13  m_EEPulseShapeTemplate = ps.getParameter<std::vector<double> >("EEPulseShapeTemplate");
14 }
15 
17 
19  // true means all is standard and OK
20  bool result = true;
21  for (int s = 0; s < EcalPulseShape::TEMPLATESAMPLES; ++s) {
22  if (item->pdfval[s] > 1 || item->pdfval[s] < 0)
23  result = false;
24  }
25  return result;
26 }
27 
29  for (int s = 0; s < EcalPulseShape::TEMPLATESAMPLES; ++s) {
30  item->pdfval[s] = isbarrel ? m_EBPulseShapeTemplate[s] : m_EEPulseShapeTemplate[s];
31  }
32 }
33 
35  std::cout << "------- Ecal - > getNewObjects\n";
36 
37  // create the object pukse shapes
38  EcalPulseShapes* pulseshapes = new EcalPulseShapes();
39 
40  // read the templates from a text file
41  std::ifstream inputfile;
42  inputfile.open(m_filename.c_str());
43  float templatevals[EcalPulseShape::TEMPLATESAMPLES];
44  unsigned int rawId;
45  int isbarrel;
47 
48  // keep track of bad crystals
49  int nEBbad(0), nEEbad(0);
50  int nEBgood(0), nEEgood(0);
51  std::vector<EBDetId> ebgood;
52  std::vector<EEDetId> eegood;
53 
54  // fill with the measured shapes only for data
55  if (m_firstRun > 1) {
56  while (std::getline(inputfile, line)) {
57  std::istringstream linereader(line);
58  linereader >> isbarrel >> rawId;
59  // std::cout << "Inserting template for crystal with rawId = " << rawId << " (isbarrel = " << isbarrel << ") " << std::endl;
60  for (int s = 0; s < EcalPulseShape::TEMPLATESAMPLES; ++s) {
61  linereader >> templatevals[s];
62  // std::cout << templatevals[s] << "\t";
63  }
64  // std::cout << std::endl;
65 
66  if (!linereader) {
67  std::cout << "Wrong format of the text file. Exit." << std::endl;
68  return;
69  }
71  for (int s = 0; s < EcalPulseShape::TEMPLATESAMPLES; ++s)
72  item.pdfval[s] = templatevals[s];
73 
74  if (isbarrel) {
75  EBDetId ebdetid(rawId);
76  if (!checkPulseShape(&item))
77  nEBbad++;
78  else {
79  nEBgood++;
80  ebgood.push_back(ebdetid);
81  pulseshapes->insert(std::make_pair(ebdetid.rawId(), item));
82  }
83  } else {
84  EEDetId eedetid(rawId);
85  if (!checkPulseShape(&item))
86  nEEbad++;
87  else {
88  nEEgood++;
89  eegood.push_back(eedetid);
90  pulseshapes->insert(std::make_pair(eedetid.rawId(), item));
91  }
92  }
93  }
94  }
95 
96  // now fill the bad crystals and simulation with the simulation values (from TB)
97  std::cout << "Filled the DB with the good measured ECAL templates. Now filling the others with the TB values"
98  << std::endl;
99  for (int iEta = -EBDetId::MAX_IETA; iEta <= EBDetId::MAX_IETA; ++iEta) {
100  if (iEta == 0)
101  continue;
102  for (int iPhi = EBDetId::MIN_IPHI; iPhi <= EBDetId::MAX_IPHI; ++iPhi) {
103  if (EBDetId::validDetId(iEta, iPhi)) {
104  EBDetId ebdetid(iEta, iPhi, EBDetId::ETAPHIMODE);
105 
106  std::vector<EBDetId>::iterator it = find(ebgood.begin(), ebgood.end(), ebdetid);
107  if (it == ebgood.end()) {
109  fillSimPulseShape(&item, true);
110  pulseshapes->insert(std::make_pair(ebdetid.rawId(), item));
111  }
112  }
113  }
114  }
115 
116  for (int iZ = -1; iZ < 2; iZ += 2) {
117  for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
118  for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
119  if (EEDetId::validDetId(iX, iY, iZ)) {
120  EEDetId eedetid(iX, iY, iZ);
121 
122  std::vector<EEDetId>::iterator it = find(eegood.begin(), eegood.end(), eedetid);
123  if (it == eegood.end()) {
125  fillSimPulseShape(&item, false);
126  pulseshapes->insert(std::make_pair(eedetid.rawId(), item));
127  }
128  }
129  }
130  }
131  }
132 
133  std::cout << "Inserted the pulse shapes into the new item object" << std::endl;
134 
135  unsigned int irun = m_firstRun;
136  Time_t snc = (Time_t)irun;
137 
138  m_to_transfer.push_back(std::make_pair((EcalPulseShapes*)pulseshapes, snc));
139 
140  std::cout << "Ecal - > end of getNewObjects -----------" << std::endl;
141  std::cout << "N. bad shapes for EB = " << nEBbad << std::endl;
142  std::cout << "N. bad shapes for EE = " << nEEbad << std::endl;
143  std::cout << "Written the object" << std::endl;
144 }
popcon::EcalPulseShapesHandler::EcalPulseShapesHandler
EcalPulseShapesHandler(edm::ParameterSet const &)
Definition: EcalPulseShapesHandler.cc:7
cond::time::Time_t
cond::Time_t Time_t
Definition: Time.h:18
EBDetId
Definition: EBDetId.h:17
gather_cfg.cout
cout
Definition: gather_cfg.py:144
popcon::PopConSourceHandler< EcalPulseShapes >::Time_t
cond::Time_t Time_t
Definition: PopConSourceHandler.h:34
EEDetId::IX_MIN
static const int IX_MIN
Definition: EEDetId.h:290
EEDetId::IY_MIN
static const int IY_MIN
Definition: EEDetId.h:294
popcon::EcalPulseShapesHandler::m_firstRun
unsigned int m_firstRun
Definition: EcalPulseShapesHandler.h:52
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
EcalCondObjectContainer< EcalPulseShape >
popcon::EcalPulseShapesHandler::~EcalPulseShapesHandler
~EcalPulseShapesHandler() override
Definition: EcalPulseShapesHandler.cc:16
popcon::EcalPulseShapesHandler::m_filename
std::string m_filename
Definition: EcalPulseShapesHandler.h:56
alignCSCRings.s
s
Definition: alignCSCRings.py:92
popcon::EcalPulseShapesHandler::m_EBPulseShapeTemplate
std::vector< double > m_EBPulseShapeTemplate
Definition: EcalPulseShapesHandler.h:58
EBDetId::MAX_IPHI
static const int MAX_IPHI
Definition: EBDetId.h:137
EEDetId::IY_MAX
static const int IY_MAX
Definition: EEDetId.h:302
EEDetId
Definition: EEDetId.h:14
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EBDetId::ETAPHIMODE
static const int ETAPHIMODE
Definition: EBDetId.h:158
edm::ParameterSet
Definition: ParameterSet.h:36
EcalCondObjectContainer< EcalPulseShape >::Item
EcalPulseShape Item
Definition: EcalCondObjectContainer.h:15
popcon::EcalPulseShapesHandler::getNewObjects
void getNewObjects() override
Definition: EcalPulseShapesHandler.cc:34
EEDetId::IX_MAX
static const int IX_MAX
Definition: EEDetId.h:298
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
popcon::EcalPulseShapesHandler::checkPulseShape
bool checkPulseShape(EcalPulseShapes::Item *item)
Definition: EcalPulseShapesHandler.cc:18
popcon::EcalPulseShapesHandler::fillSimPulseShape
void fillSimPulseShape(EcalPulseShapes::Item *item, bool isbarrel)
Definition: EcalPulseShapesHandler.cc:28
EBDetId::validDetId
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:118
popcon::EcalPulseShapesHandler::m_EEPulseShapeTemplate
std::vector< double > m_EEPulseShapeTemplate
Definition: EcalPulseShapesHandler.h:58
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
EcalCondObjectContainer::insert
void insert(std::pair< uint32_t, Item > const &a)
Definition: EcalCondObjectContainer.h:38
EcalPulseShape::TEMPLATESAMPLES
static const int TEMPLATESAMPLES
Definition: EcalPulseShapes.h:10
EcalPulseShapes
EcalPulseShapesMap EcalPulseShapes
Definition: EcalPulseShapes.h:23
EEDetId::validDetId
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
L1TowerCalibrationProducer_cfi.iEta
iEta
Definition: L1TowerCalibrationProducer_cfi.py:60
mps_fire.result
result
Definition: mps_fire.py:303
EcalPulseShapesHandler.h
mps_splice.line
line
Definition: mps_splice.py:76
EBDetId::MAX_IETA
static const int MAX_IETA
Definition: EBDetId.h:136
EBDetId::MIN_IPHI
static const int MIN_IPHI
Definition: EBDetId.h:135