CMS 3D CMS Logo

EcalPulseSymmCovariancesHandler.cc
Go to the documentation of this file.
2 
3 #include <iostream>
4 #include <fstream>
5 
7  : m_name(ps.getUntrackedParameter<std::string>("name", "EcalPulseSymmCovariancesHandler")) {
8  std::cout << "EcalPulseSymmCovariance Source handler constructor\n" << std::endl;
9  m_firstRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("firstRun").c_str()));
10  m_filename = ps.getParameter<std::string>("inputFileName");
11  m_EBPulseShapeCovariance = ps.getParameter<std::vector<double> >("EBPulseShapeCovariance");
12  m_EEPulseShapeCovariance = ps.getParameter<std::vector<double> >("EEPulseShapeCovariance");
13 }
14 
16 
18  // true means all is standard and OK
19  bool result = true;
21  for (int k = 0; k < N; ++k) {
22  if (fabs(item->covval[k]) > 1)
23  result = false;
24  }
25  return result;
26 }
27 
29  bool isbarrel) {
30  for (int k = 0; k < std::pow(EcalPulseShape::TEMPLATESAMPLES, 2); ++k) {
33  if (j >= i) {
34  int linK = j + (EcalPulseShape::TEMPLATESAMPLES - 1) * i;
35  item->covval[linK] = isbarrel ? m_EBPulseShapeCovariance[k] : m_EEPulseShapeCovariance[k];
36  }
37  }
38 }
39 
41  std::cout << "------- Ecal - > getNewObjects\n";
42 
43  // create the object pukse shapes
45 
46  // read the templates from a text file
47  std::ifstream inputfile;
48  inputfile.open(m_filename.c_str());
50  unsigned int rawId;
51  int isbarrel;
53 
54  // keep track of bad crystals
55  int nEBbad(0), nEEbad(0);
56  int nEBgood(0), nEEgood(0);
57  std::vector<EBDetId> ebgood;
58  std::vector<EEDetId> eegood;
59 
60  // fill with the measured shapes only for data
61  if (m_firstRun > 1) {
62  while (std::getline(inputfile, line)) {
63  std::istringstream linereader(line);
64  linereader >> isbarrel >> rawId;
65  // std::cout << "Inserting template for crystal with rawId = " << rawId << " (isbarrel = " << isbarrel << ") " << std::endl;
66  for (int k = 0; k < std::pow(EcalPulseShape::TEMPLATESAMPLES, 2); ++k) {
69  linereader >> covvals[i][j];
70  }
71 
72  if (!linereader) {
73  std::cout << "Wrong format of the text file. Exit." << std::endl;
74  return;
75  }
77  for (int i = 0; i < EcalPulseShape::TEMPLATESAMPLES; ++i)
78  for (int j = 0; j < EcalPulseShape::TEMPLATESAMPLES; ++j) {
79  item.val(i, j) = covvals[i][j];
80  }
81 
82  if (isbarrel) {
83  EBDetId ebdetid(rawId);
84  if (!checkPulseSymmCovariance(&item))
85  nEBbad++;
86  else {
87  nEBgood++;
88  ebgood.push_back(ebdetid);
89  pulsecovs->insert(std::make_pair(ebdetid.rawId(), item));
90  }
91  } else {
92  EEDetId eedetid(rawId);
93  if (!checkPulseSymmCovariance(&item))
94  nEEbad++;
95  else {
96  nEEgood++;
97  eegood.push_back(eedetid);
98  pulsecovs->insert(std::make_pair(eedetid.rawId(), item));
99  }
100  }
101  }
102  }
103 
104  // now fill the bad crystals and simulation with the simulation values (from TB)
105  std::cout << "Filled the DB with the good measured ECAL templates. Now filling the others with the TB values"
106  << std::endl;
107  for (int iEta = -EBDetId::MAX_IETA; iEta <= EBDetId::MAX_IETA; ++iEta) {
108  if (iEta == 0)
109  continue;
110  for (int iPhi = EBDetId::MIN_IPHI; iPhi <= EBDetId::MAX_IPHI; ++iPhi) {
111  if (EBDetId::validDetId(iEta, iPhi)) {
112  EBDetId ebdetid(iEta, iPhi, EBDetId::ETAPHIMODE);
113 
114  std::vector<EBDetId>::iterator it = find(ebgood.begin(), ebgood.end(), ebdetid);
115  if (it == ebgood.end()) {
117  fillSimPulseSymmCovariance(&item, true);
118  pulsecovs->insert(std::make_pair(ebdetid.rawId(), item));
119  }
120  }
121  }
122  }
123 
124  for (int iZ = -1; iZ < 2; iZ += 2) {
125  for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
126  for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
127  if (EEDetId::validDetId(iX, iY, iZ)) {
128  EEDetId eedetid(iX, iY, iZ);
129 
130  std::vector<EEDetId>::iterator it = find(eegood.begin(), eegood.end(), eedetid);
131  if (it == eegood.end()) {
133  fillSimPulseSymmCovariance(&item, false);
134  pulsecovs->insert(std::make_pair(eedetid.rawId(), item));
135  }
136  }
137  }
138  }
139  }
140 
141  std::cout << "Inserted the pulse covariances into the new item object" << std::endl;
142 
143  unsigned int irun = m_firstRun;
144  Time_t snc = (Time_t)irun;
145 
146  m_to_transfer.push_back(std::make_pair((EcalPulseSymmCovariances*)pulsecovs, snc));
147 
148  std::cout << "Ecal - > end of getNewObjects -----------" << std::endl;
149  std::cout << "N. bad shapes for EB = " << nEBbad << std::endl;
150  std::cout << "N. bad shapes for EE = " << nEEbad << std::endl;
151  std::cout << "Written the object" << std::endl;
152 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
static const int MIN_IPHI
Definition: EBDetId.h:135
static const int TEMPLATESAMPLES
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
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
EcalPulseSymmCovariancesMap EcalPulseSymmCovariances
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
#define N
Definition: blowfish.cc:9
static const int MAX_IPHI
Definition: EBDetId.h:137
void fillSimPulseSymmCovariance(EcalPulseSymmCovariances::Item *item, bool isbarrel)
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
cond::Time_t Time_t
Definition: Time.h:18
bool checkPulseSymmCovariance(EcalPulseSymmCovariances::Item *item)
static const int IY_MAX
Definition: EEDetId.h:302
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29