CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalLaser_weekly_Linearization_Check.cc
Go to the documentation of this file.
9 
10 #include<iostream>
11 #include<iomanip>
12 #include <sstream>
13 #include "TFile.h"
14 #include <string>
15 
17  : m_name(ps.getUntrackedParameter<std::string>("name","EcalLaser_weekly_Handler")) {
18  std::cout << "EcalLaser Source handler constructor\n" << std::endl;
19 }
20 
22  // do nothing
23 }
24 
26  std::cout << "------- Ecal -> getNewObjects\n";
27 
28  std::ifstream fin;
29  int conf, idEB, crysEB[61200];
30  uint32_t mult12EB[61200], mult6EB[61200], mult1EB[61200], shift12EB[61200], shift6EB[61200], shift1EB[61200];
31  int idEE, crysEE[14648];
32  uint32_t mult12EE[14648], mult6EE[14648], mult1EE[14648], shift12EE[14648], shift6EE[14648], shift1EE[14648];
33  int ansDB, ans;
34  std::string fDB = "";
35  std::cout << "Check from OMDS (1) or Orcon prod DB (2)? ";
36  std::cin >> ansDB;
37  if(ansDB == 1) {
38  std::cout << "Which LIN_DATA_CONF_ID? ";
39  std::cin >> ans;
40  fDB = Form("/afs/cern.ch/cms/ECAL/triggerTransp/LIN_DATA_CONF_ID_%i.dat",ans);
41  fin.open(fDB.c_str());
42  if(!fin) {
43  std::cout << "Error: file LIN_DATA_CONF_ID_"<< ans << ".dat could not be opened" << std::endl;
44  exit(1);
45  }
46  std::cout << "file LIN_DATA_CONF_ID_"<< ans << ".dat opened" << std::endl;
47  std::string c, log, m1, m2, m3, s1, s2, s3;
48  fin >> c >> log >> m1 >> m2 >> m3 >> s1 >> s2 >> s3;
49  // EB
50  for (int ich = 0; ich < 61200; ich++) {
51  fin >> conf >> idEB >> mult12EB[ich] >> mult6EB[ich] >> mult1EB[ich] >> shift12EB[ich] >> shift6EB[ich] >> shift1EB[ich];
52  int chinSM = idEB%10000;
53  int SM = (idEB/10000)%100;
54  if(SM < 1 || SM > 36 || chinSM < 1 || chinSM > 1700) std::cout << idEB << " EB channel " << chinSM << " SM " << SM << std::endl;
55  EBDetId EBId(SM, chinSM, EBDetId::SMCRYSTALMODE);
56  crysEB[ich] = EBId.hashedIndex();
57  }
58  // EE
59  for (int ich = 0; ich < 14648; ich++) {
60  fin >> conf >> idEE >> mult12EE[ich] >> mult6EE[ich] >> mult1EE[ich] >> shift12EE[ich] >> shift6EE[ich] >> shift1EE[ich];
61  int ix = (idEE/1000)%1000;
62  int iy = idEE%1000;
63  int iz = (idEE/1000000)%10;
64  int side = -1;
65  if(iz == 2) side = 1;
66  if(ix < 1 || ix > 100 || iy < 1 || iy > 100 || (iz != 0 && iz != 2))
67  std::cout << idEE << " ix " << ix << " iy " << iy << " iz " << iz << std::endl;
68  EEDetId EEId(ix, iy, side, EEDetId::XYMODE);
69  crysEE[ich] = EEId.hashedIndex();
70  }
71  fin.close();
72  } // end OMDS
73  else if(ansDB == 2) {
74  std::cout << "Which Linearization? ";
75  std::cin >> ans;
76  fDB = Form("./Linearization_%i.txt",ans);
77  fin.open(fDB.c_str());
78  if(!fin) {
79  std::cout << "Error: file " << fDB << " could not be opened" << std::endl;
80  exit(1);
81  }
82  std::cout << "prod DB file " << fDB << " opened" << std::endl;
83  // EB
84  for (int ich = 0; ich < 61200; ich++) {
85  fin >> idEB >> mult12EB[ich] >> mult6EB[ich] >> mult1EB[ich] >> shift12EB[ich] >> shift6EB[ich] >> shift1EB[ich];
86  EBDetId ebId = DetId(idEB);
87  crysEB[ich] = ebId.hashedIndex();
88  }
89  // EE
90  for (int ich = 0; ich < 14648; ich++) {
91  fin >> idEE >> mult12EE[ich] >> mult6EE[ich] >> mult1EE[ich] >> shift12EE[ich] >> shift6EE[ich] >> shift1EE[ich];
92  EEDetId eeId = DetId(idEE);
93  crysEE[ich] = eeId.hashedIndex();
94  }
95  fin.close();
96  } // end Orcon
97  else {
98  std::cout << ansDB << " is not a right answer. Sorry let us give up!" << std::endl;
99  exit(-1);
100  }
101 
102  // EcalTPGLinearizationConst *linC = new EcalTPGLinearizationConst;
103  int fileIOV;
104  std::cout << " Which input file IOV? ";
105  std::cin >> fileIOV;
106  std::ifstream fWeek;
107  std::ostringstream oss;
108  oss << fileIOV;
109  std::string fname = "/afs/cern.ch/cms/ECAL/triggerTransp/TPG_beamv6_trans_" + oss.str() + "_spikekill.txt";
110  fWeek.open(fname.c_str());
111  if(!fWeek.is_open()) {
112  std::cout << "ERROR : can't open file '" << fname << std::endl;
113  exit(-1);
114  }
115  std::cout << " file " << fname << " opened" << std::endl;
117  for(int i = 0; i < 85; i++) getline (fWeek, line);
118  char cryst[10];
119  uint32_t ped[kGains], mult[kGains], shift[kGains];
120  uint32_t id;
121  for (int iChannel = 0; iChannel < kEBChannels; iChannel++) {
122  getline (fWeek, line);
123  sscanf(line.c_str(), "%s %u", cryst, &id);
124  EBDetId ebId = DetId(id);
125  int crys = ebId.hashedIndex();
126  bool found = false;
127  int ich = -1;
128  for (int icc = 0; icc < 61200; icc++) {
129  if(crys == crysEB[icc]) {
130  found = true;
131  ich = icc;
132  break;
133  }
134  }
135  if(!found) std::cout << " ***** EB crystal not found in DB " << crys << std::endl;
136  for (int gain = 0; gain < kGains; gain++) {
137  getline (fWeek, line);
138  sscanf(line.c_str(), "%X %X %X", &ped[gain], &mult[gain], &shift[gain]);
139  }
140  if(mult[0] != mult12EB[ich])
141  std::cout << " mult12 file " << fDB << " " << mult12EB[ich] << " file " << fname << " " << mult[0] << "\n";
142  if(mult[1] != mult6EB[ich])
143  std::cout << " mult6 file " << fDB << " " << mult6EB[ich] << " file " << fname << " " << mult[1] << "\n";
144  if(mult[2] != mult1EB[ich])
145  std::cout << " mult1 file " << fDB << " " << mult1EB[ich] << " file " << fname << " " << mult[2] << "\n";
146  if(shift[0] != shift12EB[ich])
147  std::cout << " shift12 file " << fDB << " " << shift12EB[ich] << " file " << fname << " " << shift[0] << "\n";
148  if(shift[1] != shift6EB[ich])
149  std::cout << " shift6 file " << fDB << " " << shift6EB[ich] << " file " << fname << " " << shift[1] << "\n";
150  if(shift[2] != shift1EB[ich]) {
151  std::cout << " ***** EB crystal " << id << " hashed " << crys << std::endl;
152  std::cout << " shift1 file " << fDB << " " << shift1EB[ich] << " file " << fname << " " << shift[2] << "\n";
153  exit(-1);
154  }
155  } // end loop over EB channels
156  getline (fWeek, line); // comment before EE crystals
157  std::cout << " comment line " << line << std::endl;
158  int chm12 = 0, chm6 = 0, chm1 = 0, chs12 = 0, chs6 = 0, chs1 = 0;
159  for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
160  getline (fWeek, line);
161  sscanf(line.c_str(), "%s %u", cryst, &id);
162  EEDetId eeId = DetId(id);
163  int crys = eeId.hashedIndex();
164  bool found = false;
165  int ich = -1;
166  for (int icc = 0; icc < 14648; icc++) {
167  if(crys == crysEE[icc]) {
168  found = true;
169  ich = icc;
170  break;
171  }
172  }
173  if(!found) std::cout << " ***** EE crystal not found in DB " << crys << std::endl;
174  for (int gain =0; gain < kGains; gain++) {
175  getline (fWeek, line);
176  sscanf(line.c_str(), "%X %X %X", &ped[gain], &mult[gain], &shift[gain]);
177  // std::cout << " gain " << gain << " ped " << ped[gain] << " mult " << mult[gain] << " shift " << shift[gain]<< std::endl;
178  }
179  if(mult[0] != mult12EE[ich]) chm12++;
180  if(mult[1] != mult6EE[ich]) chm6++;
181  if(mult[2] != mult1EE[ich]) chm1++;
182  if(shift[0] != shift12EE[ich])chs12++;
183  if(shift[1] != shift6EE[ich]) chs6++;
184  if(shift[2] != shift1EE[ich]) chs1++;
185  } // end loop over EE channels
186  fWeek.close();
187  if(chm12 != 0 || chm6 != 0 || chm1 != 0 || chs12 != 0 || chs6 != 0 || chs1 != 0)
188  std::cout << " different files "<< fDB << " and TPG_beamv6_trans_" << fileIOV << "_spikekill.txt" << "\n"
189  << " mult12 " << chm12 << " mult6 " << chm6 << " mult1 " << chm1
190  << " shift12 " << chs12 << " shift6 " << chs6 << " shift1 " << chs1 << std::endl;
191  else std::cout << "identical files "<< fDB
192  << " and TPG_beamv6_trans_" << fileIOV << "_spikekill.txt" <<std:: endl;
193  std::cout << "Ecal -> end of getNewObjects -----------\n";
194 }
int i
Definition: DBlmapReader.cc:9
int hashedIndex() const
get a compact index for arrays
Definition: EBDetId.h:86
static const int XYMODE
Definition: EEDetId.h:339
tuple s2
Definition: indexGen.py:106
tuple conf
Definition: dbtoconf.py:185
Definition: DetId.h:18
int hashedIndex() const
Definition: EEDetId.h:182
string fname
main script
static unsigned int const shift
tuple cout
Definition: gather_cfg.py:121
static const int SMCRYSTALMODE
Definition: EBDetId.h:167
tuple log
Definition: cmsBatch.py:341