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