File indexing completed on 2021-05-25 06:38:09
0001 #include "CondTools/Ecal/interface/EcalPulseSymmCovariancesHandler.h"
0002
0003 #include <iostream>
0004 #include <fstream>
0005
0006 popcon::EcalPulseSymmCovariancesHandler::EcalPulseSymmCovariancesHandler(const edm::ParameterSet& ps)
0007 : m_name(ps.getUntrackedParameter<std::string>("name", "EcalPulseSymmCovariancesHandler")) {
0008 std::cout << "EcalPulseSymmCovariance Source handler constructor\n" << std::endl;
0009 m_firstRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("firstRun").c_str()));
0010 m_filename = ps.getParameter<std::string>("inputFileName");
0011 m_EBPulseShapeCovariance = ps.getParameter<std::vector<double> >("EBPulseShapeCovariance");
0012 m_EEPulseShapeCovariance = ps.getParameter<std::vector<double> >("EEPulseShapeCovariance");
0013 }
0014
0015 popcon::EcalPulseSymmCovariancesHandler::~EcalPulseSymmCovariancesHandler() {}
0016
0017 bool popcon::EcalPulseSymmCovariancesHandler::checkPulseSymmCovariance(EcalPulseSymmCovariances::Item* item) {
0018
0019 bool result = true;
0020 int N = EcalPulseShape::TEMPLATESAMPLES * (EcalPulseShape::TEMPLATESAMPLES + 1) / 2;
0021 for (int k = 0; k < N; ++k) {
0022 if (fabs(item->covval[k]) > 1)
0023 result = false;
0024 }
0025 return result;
0026 }
0027
0028 void popcon::EcalPulseSymmCovariancesHandler::fillSimPulseSymmCovariance(EcalPulseSymmCovariances::Item* item,
0029 bool isbarrel) {
0030 for (int k = 0; k < std::pow(EcalPulseShape::TEMPLATESAMPLES, 2); ++k) {
0031 int i = k / EcalPulseShape::TEMPLATESAMPLES;
0032 int j = k % EcalPulseShape::TEMPLATESAMPLES;
0033 if (j >= i) {
0034 int linK = j + (EcalPulseShape::TEMPLATESAMPLES - 1) * i;
0035 item->covval[linK] = isbarrel ? m_EBPulseShapeCovariance[k] : m_EEPulseShapeCovariance[k];
0036 }
0037 }
0038 }
0039
0040 void popcon::EcalPulseSymmCovariancesHandler::getNewObjects() {
0041 std::cout << "------- Ecal - > getNewObjects\n";
0042
0043
0044 EcalPulseSymmCovariances* pulsecovs = new EcalPulseSymmCovariances();
0045
0046
0047 std::ifstream inputfile;
0048 inputfile.open(m_filename.c_str());
0049 float covvals[EcalPulseShape::TEMPLATESAMPLES][EcalPulseShape::TEMPLATESAMPLES];
0050 unsigned int rawId;
0051 int isbarrel;
0052 std::string line;
0053
0054
0055 int nEBbad(0), nEEbad(0);
0056 int nEBgood(0), nEEgood(0);
0057 std::vector<EBDetId> ebgood;
0058 std::vector<EEDetId> eegood;
0059
0060
0061 if (m_firstRun > 1) {
0062 while (std::getline(inputfile, line)) {
0063 std::istringstream linereader(line);
0064 linereader >> isbarrel >> rawId;
0065
0066 for (int k = 0; k < std::pow(EcalPulseShape::TEMPLATESAMPLES, 2); ++k) {
0067 int i = k / EcalPulseShape::TEMPLATESAMPLES;
0068 int j = k % EcalPulseShape::TEMPLATESAMPLES;
0069 linereader >> covvals[i][j];
0070 }
0071
0072 if (!linereader) {
0073 std::cout << "Wrong format of the text file. Exit." << std::endl;
0074 return;
0075 }
0076 EcalPulseSymmCovariances::Item item;
0077 for (int i = 0; i < EcalPulseShape::TEMPLATESAMPLES; ++i)
0078 for (int j = 0; j < EcalPulseShape::TEMPLATESAMPLES; ++j) {
0079 item.val(i, j) = covvals[i][j];
0080 }
0081
0082 if (isbarrel) {
0083 EBDetId ebdetid(rawId);
0084 if (!checkPulseSymmCovariance(&item))
0085 nEBbad++;
0086 else {
0087 nEBgood++;
0088 ebgood.push_back(ebdetid);
0089 pulsecovs->insert(std::make_pair(ebdetid.rawId(), item));
0090 }
0091 } else {
0092 EEDetId eedetid(rawId);
0093 if (!checkPulseSymmCovariance(&item))
0094 nEEbad++;
0095 else {
0096 nEEgood++;
0097 eegood.push_back(eedetid);
0098 pulsecovs->insert(std::make_pair(eedetid.rawId(), item));
0099 }
0100 }
0101 }
0102 }
0103
0104
0105 std::cout << "Filled the DB with the good measured ECAL templates. Now filling the others with the TB values"
0106 << std::endl;
0107 for (int iEta = -EBDetId::MAX_IETA; iEta <= EBDetId::MAX_IETA; ++iEta) {
0108 if (iEta == 0)
0109 continue;
0110 for (int iPhi = EBDetId::MIN_IPHI; iPhi <= EBDetId::MAX_IPHI; ++iPhi) {
0111 if (EBDetId::validDetId(iEta, iPhi)) {
0112 EBDetId ebdetid(iEta, iPhi, EBDetId::ETAPHIMODE);
0113
0114 std::vector<EBDetId>::iterator it = find(ebgood.begin(), ebgood.end(), ebdetid);
0115 if (it == ebgood.end()) {
0116 EcalPulseSymmCovariances::Item item;
0117 fillSimPulseSymmCovariance(&item, true);
0118 pulsecovs->insert(std::make_pair(ebdetid.rawId(), item));
0119 }
0120 }
0121 }
0122 }
0123
0124 for (int iZ = -1; iZ < 2; iZ += 2) {
0125 for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
0126 for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
0127 if (EEDetId::validDetId(iX, iY, iZ)) {
0128 EEDetId eedetid(iX, iY, iZ);
0129
0130 std::vector<EEDetId>::iterator it = find(eegood.begin(), eegood.end(), eedetid);
0131 if (it == eegood.end()) {
0132 EcalPulseSymmCovariances::Item item;
0133 fillSimPulseSymmCovariance(&item, false);
0134 pulsecovs->insert(std::make_pair(eedetid.rawId(), item));
0135 }
0136 }
0137 }
0138 }
0139 }
0140
0141 std::cout << "Inserted the pulse covariances into the new item object" << std::endl;
0142
0143 unsigned int irun = m_firstRun;
0144 Time_t snc = (Time_t)irun;
0145
0146 m_to_transfer.push_back(std::make_pair((EcalPulseSymmCovariances*)pulsecovs, snc));
0147
0148 std::cout << "Ecal - > end of getNewObjects -----------" << std::endl;
0149 std::cout << "N. bad shapes for EB = " << nEBbad << std::endl;
0150 std::cout << "N. bad shapes for EE = " << nEEbad << std::endl;
0151 std::cout << "Written the object" << std::endl;
0152 }