File indexing completed on 2024-09-07 04:35:43
0001 #include "CondTools/Ecal/interface/EcalLaser_weekly_Linearization_Check.h"
0002 #include "OnlineDB/EcalCondDB/interface/EcalLogicID.h"
0003 #include "OnlineDB/EcalCondDB/interface/LMFSextuple.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
0005 #include "CondCore/CondDB/interface/Time.h"
0006 #include "DataFormats/Provenance/interface/Timestamp.h"
0007 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0008 #include "OnlineDB/EcalCondDB/interface/Tm.h"
0009
0010 #include <iostream>
0011 #include <iomanip>
0012 #include <sstream>
0013 #include "TFile.h"
0014 #include <string>
0015
0016 popcon::EcalLaser_weekly_Linearization_Check::EcalLaser_weekly_Linearization_Check(const edm::ParameterSet& ps)
0017 : m_name(ps.getUntrackedParameter<std::string>("name", "EcalLaser_weekly_Handler")) {
0018 std::cout << "EcalLaser Source handler constructor\n" << std::endl;
0019 }
0020
0021 popcon::EcalLaser_weekly_Linearization_Check::~EcalLaser_weekly_Linearization_Check() {
0022
0023 }
0024
0025 void popcon::EcalLaser_weekly_Linearization_Check::getNewObjects() {
0026 std::cout << "------- Ecal -> getNewObjects\n";
0027
0028 std::ifstream fin;
0029 int conf, idEB, crysEB[61200];
0030 uint32_t mult12EB[61200], mult6EB[61200], mult1EB[61200], shift12EB[61200], shift6EB[61200], shift1EB[61200];
0031 int idEE, crysEE[14648];
0032 uint32_t mult12EE[14648], mult6EE[14648], mult1EE[14648], shift12EE[14648], shift6EE[14648], shift1EE[14648];
0033 int ansDB, ans;
0034 std::string fDB = "";
0035 std::cout << "Check from OMDS (1) or Orcon prod DB (2)? ";
0036 std::cin >> ansDB;
0037 if (ansDB == 1) {
0038 std::cout << "Which LIN_DATA_CONF_ID? ";
0039 std::cin >> ans;
0040 fDB = Form("/afs/cern.ch/cms/ECAL/triggerTransp/LIN_DATA_CONF_ID_%i.dat", ans);
0041 fin.open(fDB.c_str());
0042 if (!fin) {
0043 std::cout << "Error: file LIN_DATA_CONF_ID_" << ans << ".dat could not be opened" << std::endl;
0044 exit(1);
0045 }
0046 std::cout << "file LIN_DATA_CONF_ID_" << ans << ".dat opened" << std::endl;
0047 std::string c, log, m1, m2, m3, s1, s2, s3;
0048 fin >> c >> log >> m1 >> m2 >> m3 >> s1 >> s2 >> s3;
0049
0050 for (int ich = 0; ich < 61200; ich++) {
0051 fin >> conf >> idEB >> mult12EB[ich] >> mult6EB[ich] >> mult1EB[ich] >> shift12EB[ich] >> shift6EB[ich] >>
0052 shift1EB[ich];
0053 int chinSM = idEB % 10000;
0054 int SM = (idEB / 10000) % 100;
0055 if (SM < 1 || SM > 36 || chinSM < 1 || chinSM > 1700)
0056 std::cout << idEB << " EB channel " << chinSM << " SM " << SM << std::endl;
0057 EBDetId EBId(SM, chinSM, EBDetId::SMCRYSTALMODE);
0058 crysEB[ich] = EBId.hashedIndex();
0059 }
0060
0061 for (int ich = 0; ich < 14648; ich++) {
0062 fin >> conf >> idEE >> mult12EE[ich] >> mult6EE[ich] >> mult1EE[ich] >> shift12EE[ich] >> shift6EE[ich] >>
0063 shift1EE[ich];
0064 int ix = (idEE / 1000) % 1000;
0065 int iy = idEE % 1000;
0066 int iz = (idEE / 1000000) % 10;
0067 int side = -1;
0068 if (iz == 2)
0069 side = 1;
0070 if (ix < 1 || ix > 100 || iy < 1 || iy > 100 || (iz != 0 && iz != 2))
0071 std::cout << idEE << " ix " << ix << " iy " << iy << " iz " << iz << std::endl;
0072 EEDetId EEId(ix, iy, side, EEDetId::XYMODE);
0073 crysEE[ich] = EEId.hashedIndex();
0074 }
0075 fin.close();
0076 }
0077 else if (ansDB == 2) {
0078 std::cout << "Which Linearization? ";
0079 std::cin >> ans;
0080 fDB = Form("./Linearization_%i.txt", ans);
0081 fin.open(fDB.c_str());
0082 if (!fin) {
0083 std::cout << "Error: file " << fDB << " could not be opened" << std::endl;
0084 exit(1);
0085 }
0086 std::cout << "prod DB file " << fDB << " opened" << std::endl;
0087
0088 for (int ich = 0; ich < 61200; ich++) {
0089 fin >> idEB >> mult12EB[ich] >> mult6EB[ich] >> mult1EB[ich] >> shift12EB[ich] >> shift6EB[ich] >> shift1EB[ich];
0090 EBDetId ebId = DetId(idEB);
0091 crysEB[ich] = ebId.hashedIndex();
0092 }
0093
0094 for (int ich = 0; ich < 14648; ich++) {
0095 fin >> idEE >> mult12EE[ich] >> mult6EE[ich] >> mult1EE[ich] >> shift12EE[ich] >> shift6EE[ich] >> shift1EE[ich];
0096 EEDetId eeId = DetId(idEE);
0097 crysEE[ich] = eeId.hashedIndex();
0098 }
0099 fin.close();
0100 }
0101 else {
0102 std::cout << ansDB << " is not a right answer. Sorry let us give up!" << std::endl;
0103 exit(-1);
0104 }
0105
0106
0107 int fileIOV;
0108 std::cout << " Which input file IOV? ";
0109 std::cin >> fileIOV;
0110 std::ifstream fWeek;
0111 std::ostringstream oss;
0112 oss << fileIOV;
0113 std::string fname = "/afs/cern.ch/cms/ECAL/triggerTransp/TPG_beamv6_trans_" + oss.str() + "_spikekill.txt";
0114 fWeek.open(fname.c_str());
0115 if (!fWeek.is_open()) {
0116 std::cout << "ERROR : can't open file '" << fname << std::endl;
0117 exit(-1);
0118 }
0119 std::cout << " file " << fname << " opened" << std::endl;
0120 std::string line;
0121 for (int i = 0; i < 85; i++)
0122 getline(fWeek, line);
0123 char cryst[10];
0124 uint32_t ped[kGains], mult[kGains], shift[kGains];
0125 uint32_t id;
0126 for (int iChannel = 0; iChannel < kEBChannels; iChannel++) {
0127 getline(fWeek, line);
0128 sscanf(line.c_str(), "%s %u", cryst, &id);
0129 EBDetId ebId = DetId(id);
0130 int crys = ebId.hashedIndex();
0131 bool found = false;
0132 int ich = -1;
0133 for (int icc = 0; icc < 61200; icc++) {
0134 if (crys == crysEB[icc]) {
0135 found = true;
0136 ich = icc;
0137 break;
0138 }
0139 }
0140 if (!found)
0141 std::cout << " ***** EB crystal not found in DB " << crys << std::endl;
0142 for (int gain = 0; gain < kGains; gain++) {
0143 getline(fWeek, line);
0144 sscanf(line.c_str(), "%X %X %X", &ped[gain], &mult[gain], &shift[gain]);
0145 }
0146 if (mult[0] != mult12EB[ich])
0147 std::cout << " mult12 file " << fDB << " " << mult12EB[ich] << " file " << fname << " " << mult[0] << "\n";
0148 if (mult[1] != mult6EB[ich])
0149 std::cout << " mult6 file " << fDB << " " << mult6EB[ich] << " file " << fname << " " << mult[1] << "\n";
0150 if (mult[2] != mult1EB[ich])
0151 std::cout << " mult1 file " << fDB << " " << mult1EB[ich] << " file " << fname << " " << mult[2] << "\n";
0152 if (shift[0] != shift12EB[ich])
0153 std::cout << " shift12 file " << fDB << " " << shift12EB[ich] << " file " << fname << " " << shift[0] << "\n";
0154 if (shift[1] != shift6EB[ich])
0155 std::cout << " shift6 file " << fDB << " " << shift6EB[ich] << " file " << fname << " " << shift[1] << "\n";
0156 if (shift[2] != shift1EB[ich]) {
0157 std::cout << " ***** EB crystal " << id << " hashed " << crys << std::endl;
0158 std::cout << " shift1 file " << fDB << " " << shift1EB[ich] << " file " << fname << " " << shift[2] << "\n";
0159 exit(-1);
0160 }
0161 }
0162 getline(fWeek, line);
0163 std::cout << " comment line " << line << std::endl;
0164 int chm12 = 0, chm6 = 0, chm1 = 0, chs12 = 0, chs6 = 0, chs1 = 0;
0165 for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
0166 getline(fWeek, line);
0167 sscanf(line.c_str(), "%s %u", cryst, &id);
0168 EEDetId eeId = DetId(id);
0169 int crys = eeId.hashedIndex();
0170 bool found = false;
0171 int ich = -1;
0172 for (int icc = 0; icc < 14648; icc++) {
0173 if (crys == crysEE[icc]) {
0174 found = true;
0175 ich = icc;
0176 break;
0177 }
0178 }
0179 if (!found)
0180 std::cout << " ***** EE crystal not found in DB " << crys << std::endl;
0181 for (int gain = 0; gain < kGains; gain++) {
0182 getline(fWeek, line);
0183 sscanf(line.c_str(), "%X %X %X", &ped[gain], &mult[gain], &shift[gain]);
0184
0185 }
0186 if (mult[0] != mult12EE[ich])
0187 chm12++;
0188 if (mult[1] != mult6EE[ich])
0189 chm6++;
0190 if (mult[2] != mult1EE[ich])
0191 chm1++;
0192 if (shift[0] != shift12EE[ich])
0193 chs12++;
0194 if (shift[1] != shift6EE[ich])
0195 chs6++;
0196 if (shift[2] != shift1EE[ich])
0197 chs1++;
0198 }
0199 fWeek.close();
0200 if (chm12 != 0 || chm6 != 0 || chm1 != 0 || chs12 != 0 || chs6 != 0 || chs1 != 0)
0201 std::cout << " different files " << fDB << " and TPG_beamv6_trans_" << fileIOV << "_spikekill.txt"
0202 << "\n"
0203 << " mult12 " << chm12 << " mult6 " << chm6 << " mult1 " << chm1 << " shift12 " << chs12 << " shift6 "
0204 << chs6 << " shift1 " << chs1 << std::endl;
0205 else
0206 std::cout << "identical files " << fDB << " and TPG_beamv6_trans_" << fileIOV << "_spikekill.txt" << std::endl;
0207 std::cout << "Ecal -> end of getNewObjects -----------\n";
0208 }