CMS 3D CMS Logo

EcalPedestalsHandler.cc
Go to the documentation of this file.
2 
5 
6 #include <cstring>
7 #include<iostream>
8 #include <fstream>
9 
10 #include "TFile.h"
11 #include "TTree.h"
12 
13 const Int_t kChannels = 75848, kEBChannels = 61200, kEEChannels = 14648;
14 const Int_t Nbpedxml = 25; // Number of Gain1 Gain6 files in 2017
15 
17  : m_name(ps.getUntrackedParameter<std::string>("name","EcalPedestalsHandler")) {
18 
19  std::cout << "EcalPedestals Source handler constructor\n" << std::endl;
20  m_firstRun=static_cast<unsigned int>(atoi( ps.getParameter<std::string>("firstRun").c_str()));
21  m_lastRun=static_cast<unsigned int>(atoi( ps.getParameter<std::string>("lastRun").c_str()));
22  m_sid= ps.getParameter<std::string>("OnlineDBSID");
23  m_user= ps.getParameter<std::string>("OnlineDBUser");
24  m_pass= ps.getParameter<std::string>("OnlineDBPassword");
25  m_locationsource= ps.getParameter<std::string>("LocationSource");
26  m_location=ps.getParameter<std::string>("Location");
27  m_gentag=ps.getParameter<std::string>("GenTag");
28  m_runtag=ps.getParameter<std::string>("RunTag");
29  m_filename = ps.getUntrackedParameter<std::string>("filename","EcalPedestals.txt");
30  m_runtype = ps.getUntrackedParameter<int>("RunType",1);
31 
32  std::cout << m_sid<<"/"<<m_user<<"/"<<m_pass<<"/"<<m_location<<"/"<<m_gentag << std::endl;
33 
34 }
35 
37 
38 
40  std::cout << "------- Ecal - > getNewObjects\n";
41  if(m_locationsource=="H2") {
43  } else if(m_locationsource=="P5") {
45  }
46  else if(m_locationsource=="File") {
48  }
49  else if(m_locationsource=="Tree") {
51  }
52  else if(m_locationsource=="Timestamp") {
54  }
55  else if(m_locationsource=="2017") {
57  }
58  else {
59  std::cout << " unknown location " << m_locationsource << " give up " << std::endl;
60  exit(-1);
61  }
62 }
63 
64 
66  // true means all is standard and OK
67  bool result=true;
68  if(item->rms_x12 >3 || item->rms_x12<=0) result=false;
69  if(item->rms_x6 >2 || item->rms_x6<=0) result=false;
70  if(item->rms_x1 >1 || item->rms_x1<=0) result=false;
71  if(item->mean_x12>300 || item->mean_x12<=100) result=false;
72  if(item->mean_x1>300 || item->mean_x1<=100) result=false;
73  if(item->mean_x6>300 || item->mean_x6<=100) result=false;
74  return result;
75 }
76 
78  std::ostringstream ss;
79  ss<<"ECAL ";
80 
81  unsigned int max_since=0;
82  max_since=static_cast<unsigned int>(tagInfo().lastInterval.first);
83  std::cout << "max_since : " << max_since << std::endl;
84  Ref ped_db = lastPayload();
85 
86  // we copy the last valid record to a temporary object peds
87  EcalPedestals* peds = new EcalPedestals();
88  std::cout << "retrieved last payload " << std::endl;
89 
90  for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
91  if(iEta==0) continue;
92  for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
93  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
94  if (EBDetId::validDetId(iEta,iPhi)) {
95  EBDetId ebdetid(iEta,iPhi,EBDetId::ETAPHIMODE);
96  EcalPedestals::const_iterator it =ped_db->find(ebdetid.rawId());
97  EcalPedestals::Item aped = (*it);
98 
99  // here I copy the last valid value in the peds object
100  EcalPedestals::Item item;
101  item.mean_x1 = aped.mean_x1;
102  item.rms_x1 = aped.rms_x1;
103  item.mean_x6 = aped.mean_x6;
104  item.rms_x6 = aped.rms_x6;
105  item.mean_x12 = aped.mean_x12;
106  item.rms_x12 = aped.rms_x12;
107 
108  peds->insert(std::make_pair(ebdetid.rawId(),item));
109  }
110  }
111  }
112 
113  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
114  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
115  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
116  if (EEDetId::validDetId(iX,iY,1)) {
117  EEDetId eedetidpos(iX,iY,1);
118 
119  EcalPedestals::const_iterator it =ped_db->find(eedetidpos.rawId());
120  EcalPedestals::Item aped = (*it);
121 
122  // unsigned int hiee = eedetidpos.hashedIndex();
123  // EcalPedestals::Item aped= ped_db->endcap(hiee);
124 
125  // here I copy the last valid value in the peds object
126  EcalPedestals::Item item;
127  item.mean_x1 = aped.mean_x1;
128  item.rms_x1 = aped.rms_x1;
129  item.mean_x6 = aped.mean_x6;
130  item.rms_x6 = aped.rms_x6;
131  item.mean_x12 = aped.mean_x12;
132  item.rms_x12 = aped.rms_x12;
133  peds->insert(std::make_pair(eedetidpos.rawId(),item));
134  }
135  if(EEDetId::validDetId(iX,iY,-1)) {
136  EEDetId eedetidneg(iX,iY,-1);
137 
138  EcalPedestals::const_iterator it =ped_db->find(eedetidneg.rawId());
139  EcalPedestals::Item aped = (*it);
140  // unsigned int hiee = eedetidneg.hashedIndex();
141  // EcalPedestals::Item aped= ped_db->endcap(hiee);
142 
143  // here I copy the last valid value in the peds object
144  EcalPedestals::Item item;
145  item.mean_x1 = aped.mean_x1;
146  item.rms_x1 = aped.rms_x1;
147  item.mean_x6 = aped.mean_x6;
148  item.rms_x6 = aped.rms_x6;
149  item.mean_x12 = aped.mean_x12;
150  item.rms_x12 = aped.rms_x12;
151  peds->insert(std::make_pair(eedetidneg.rawId(),item));
152  }
153  }
154  }
155 
156  // here we retrieve all the runs after the last from online DB
157 
158  std::cout << "Retrieving run list from ONLINE DB ... " << std::endl;
160  std::cout << "Connection done" << std::endl;
161 
162  // these are the online conditions DB classes
163  RunList my_runlist ;
164  RunTag my_runtag;
165  LocationDef my_locdef;
166  RunTypeDef my_rundef;
167 
168  my_locdef.setLocation(m_location);
169  // my_rundef.setRunType("PEDESTAL"); // 2017
170  my_rundef.setRunType(m_runtag);
171  my_runtag.setLocationDef(my_locdef);
172  my_runtag.setRunTypeDef(my_rundef);
173  my_runtag.setGeneralTag(m_gentag);
174 
175  // here we retrieve the Monitoring run records
176 
177  MonVersionDef monverdef;
178  monverdef.setMonitoringVersion("test01");
179 
180  MonRunTag mon_tag;
181  // mon_tag.setGeneralTag("CMSSW");
182  mon_tag.setGeneralTag("CMSSW-offline-private");
183  mon_tag.setMonVersionDef(monverdef);
184  MonRunList mon_list;
185  mon_list.setMonRunTag(mon_tag);
186  mon_list.setRunTag(my_runtag);
187  // mon_list=econn->fetchMonRunList(my_runtag, mon_tag);
188  unsigned int min_run=0;
189  if(m_firstRun<max_since) {
190  min_run=max_since+1; // we have to add 1 to the last transferred one
191  } else {
192  min_run=m_firstRun;
193  }
194 
195  unsigned int max_run=m_lastRun;
196  mon_list=econn->fetchMonRunList(my_runtag, mon_tag,min_run,max_run );
197 
198  std::vector<MonRunIOV> mon_run_vec= mon_list.getRuns();
199  int mon_runs = mon_run_vec.size();
200  std::cout <<"number of Mon runs is : "<< mon_runs<< std::endl;
201 
202  if(mon_runs > 0) {
203  int krmax = std::min(mon_runs, 30);
204  for(int kr = 0; kr < krmax; kr++){
205  std::cout << "-kr------: "<<kr<<std::endl;
206 
207  unsigned int irun=static_cast<unsigned int>(mon_run_vec[kr].getRunIOV().getRunNumber());
208  std::cout << "retrieve the data for run number: "<< mon_run_vec[kr].getRunIOV().getRunNumber() << std::endl;
209  if (mon_run_vec[kr].getSubRunNumber() <=1){
210 
211  // retrieve the data for a given run
212  RunIOV runiov_prime = mon_run_vec[kr].getRunIOV();
213  // retrieve the pedestals from OMDS for this run
214  std::map<EcalLogicID, MonPedestalsDat> dataset_mon;
215  econn->fetchDataSet(&dataset_mon, &mon_run_vec[kr]);
216  std::cout <<"OMDS record for run "<<irun <<" is made of "<< dataset_mon.size() << std::endl;
217  int nEB = 0, nEE = 0, nEBbad = 0, nEEbad =0;
218  typedef std::map<EcalLogicID, MonPedestalsDat>::const_iterator CImon;
219  EcalLogicID ecid_xt;
220  MonPedestalsDat rd_ped;
221 
222  // this to validate ...
223  int nbad=0;
224  for (CImon p = dataset_mon.begin(); p != dataset_mon.end(); p++) {
225  ecid_xt = p->first;
226  rd_ped = p->second;
227  int sm_num=ecid_xt.getID1();
228  int xt_num=ecid_xt.getID2();
229  int yt_num=ecid_xt.getID3();
230 
231  EcalPedestals::Item item;
232  item.mean_x1 =rd_ped.getPedMeanG1() ;
233  item.rms_x1 =rd_ped.getPedRMSG1();
234  item.mean_x6 =rd_ped.getPedMeanG6();
235  item.rms_x6 =rd_ped.getPedRMSG6() ;
236  item.mean_x12 =rd_ped.getPedMeanG12();
237  item.rms_x12 =rd_ped.getPedRMSG12();
238  /*
239  if(irun != 280216 && irun != 280218 && irun != 280259 && irun != 280261 && irun != 280392 && irun != 280394
240  && irun != 280762 && irun != 280765 && irun != 280936 && irun != 280939 && irun != 281756 && irun != 281757) {
241  */
242  if(ecid_xt.getName()=="EB_crystal_number") {
243  nEB++;
244  if(!checkPedestal(&item) ) nEBbad++;
245  }
246  else {
247  nEE++;
248  if(!checkPedestal(&item) ) nEEbad++;
249  }
250 
251  // here we check and count how many bad channels we have
252 
253  if(!checkPedestal(&item) ){
254  nbad++;
255  if(nbad < 10) std::cout <<"BAD LIST: channel " << sm_num << "/" << xt_num << "/"<< yt_num
256  << "ped/rms "<<item.mean_x12<< "/"<< item.rms_x12 << std::endl;
257  }
258  /*
259  }
260  else { // only gain 12 in these runs
261  if(ecid_xt.getName()=="EB_crystal_number") {
262  nEB++;
263  if(item.mean_x12 <= 100 || item.mean_x12 > 300 || item.rms_x12 > 3 || item.rms_x12 <= 0) {
264  nbad++;
265  nEBbad++;
266  }
267  }
268  else {
269  nEE++;
270  if(item.mean_x12 <= 100 || item.mean_x12 > 300 || item.rms_x12 > 3 || item.rms_x12 <= 0) {
271  nbad++;
272  nEEbad++;
273  }
274  }
275  } // only gain 12 in these runs
276  */
277  } // loop over all channels
278 
279  // ok or bad?
280  // a bad run is for more than 5% bad channels
281 
282  // if(nbad<(dataset_mon.size()*0.1)){
283  if(nbad<(dataset_mon.size()*0.05) && (nEB > 10200 || nEE > 2460)) {
284 
285  for (CImon p = dataset_mon.begin(); p != dataset_mon.end(); p++) {
286  ecid_xt = p->first;
287  rd_ped = p->second;
288  int sm_num=ecid_xt.getID1();
289  int xt_num=ecid_xt.getID2();
290  int yt_num=ecid_xt.getID3();
291 
292  EcalPedestals::Item item;
293  item.mean_x1 =rd_ped.getPedMeanG1() ;
294  item.rms_x1 =rd_ped.getPedRMSG1();
295  item.mean_x6 =rd_ped.getPedMeanG6();
296  item.rms_x6 =rd_ped.getPedRMSG6() ;
297  item.mean_x12 =rd_ped.getPedMeanG12();
298  item.rms_x12 =rd_ped.getPedRMSG12();
299 
300  if(ecid_xt.getName()=="EB_crystal_number") {
301  // Barrel channel
302  EBDetId ebdetid(sm_num,xt_num,EBDetId::SMCRYSTALMODE);
303 
304  // individual objects check
305  if(item.mean_x1==-1 || item.rms_x1 ==-1 || item.mean_x6==-1 ||
306  item.rms_x6==-1 || item.mean_x12==-1 || item.rms_x12==-1 ||
307  item.mean_x1==0 || item.rms_x1 ==0 || item.mean_x6==0 ||
308  item.rms_x6==0 || item.mean_x12==0 || item.rms_x12==0 ) {
309  // if one is bad we
310  // retrieve the old valid value
311  unsigned int hieb = ebdetid.hashedIndex();
312  EcalPedestals::Item previous_ped= peds->barrel(hieb);
313  if(item.mean_x1==-1 || item.mean_x1==0) item.mean_x1 =previous_ped.mean_x1;
314  if(item.rms_x1==-1 || item.rms_x1==0) item.rms_x1 =previous_ped.rms_x1;
315  if(item.mean_x6==-1 || item.mean_x6==0) item.mean_x6 =previous_ped.mean_x6;
316  if(item.rms_x6==-1 || item.rms_x6==0) item.rms_x6 =previous_ped.rms_x6;
317  if(item.mean_x12==-1 || item.mean_x12==0)item.mean_x12=previous_ped.mean_x12;
318  if(item.rms_x12==-1 || item.rms_x12==0) item.rms_x12 =previous_ped.rms_x12;
319  }
320 
321  // here we change in the peds object only the channels that are available in the online DB
322  // otherwise we keep the previous value
323  peds->insert(std::make_pair(ebdetid.rawId(),item));
324  } else {
325  // Endcap channel
326  // in this case xt_num is x
327  // yt_num is y and sm_num is the side +/- 1
328  if(EEDetId::validDetId(xt_num,yt_num,sm_num)){
329  EEDetId eedetid(xt_num,yt_num,sm_num);
330 
331  // individual objects check
332  if(item.mean_x1==-1 || item.rms_x1 ==-1 || item.mean_x6==-1 ||
333  item.rms_x6==-1 || item.mean_x12==-1 || item.rms_x12==-1 ||
334  item.mean_x1==0 || item.rms_x1 ==0 || item.mean_x6==0 ||
335  item.rms_x6==0 || item.mean_x12==0 || item.rms_x12==0 ) {
336  // if one is bad we
337  // retrieve the old valid value
338  unsigned int hiee = eedetid.hashedIndex();
339  EcalPedestals::Item previous_ped= peds->endcap(hiee);
340  if(item.mean_x1==-1 || item.mean_x1==0) item.mean_x1 =previous_ped.mean_x1;
341  if(item.rms_x1==-1 || item.rms_x1==0) item.rms_x1 =previous_ped.rms_x1;
342  if(item.mean_x6==-1 || item.mean_x6==0) item.mean_x6 =previous_ped.mean_x6;
343  if(item.rms_x6==-1 || item.rms_x6==0) item.rms_x6 =previous_ped.rms_x6;
344  if(item.mean_x12==-1 || item.mean_x12==0)item.mean_x12=previous_ped.mean_x12;
345  if(item.rms_x12==-1 || item.rms_x12==0) item.rms_x12 =previous_ped.rms_x12;
346  }
347  // here we change in the peds object only the channels that are available in the online DB
348  // otherwise we keep the previous value
349  peds->insert(std::make_pair(eedetid.rawId(),item));
350  }
351  }
352  }
353 
354  std::cout << "Generating popcon record for run " << irun << "..." << std::flush;
355  // now I copy peds in pedtemp and I ship pedtemp to popcon
356  // if I use always the same peds I always overwrite
357  // so I really have to create new objects for each new run
358  // popcon deletes everything for me
359 
360  EcalPedestals* pedtemp = new EcalPedestals();
361  for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
362  if(iEta==0) continue;
363  for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
364  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
365  if (EBDetId::validDetId(iEta,iPhi)) {
366  EBDetId ebdetid(iEta,iPhi);
367  unsigned int hiee = ebdetid.hashedIndex();
368  EcalPedestals::Item aped= peds->barrel(hiee);
369 
370  // here I copy the last valid value in the peds object
371  EcalPedestals::Item item;
372  item.mean_x1 = aped.mean_x1;
373  item.rms_x1 = aped.rms_x1;
374  item.mean_x6 = aped.mean_x6;
375  item.rms_x6 = aped.rms_x6;
376  item.mean_x12 = aped.mean_x12;
377  item.rms_x12 = aped.rms_x12;
378  // here I copy the last valid value in the pedtemp object
379  pedtemp->insert(std::make_pair(ebdetid.rawId(),item));
380  if((iEta==-1 || iEta==1) && iPhi==20){
381  float x=aped.mean_x12 ;
382  std::cout<< "channel:" <<iEta<<"/"<<iPhi<< "/" << hiee << " ped mean 12="<< x << std::endl;
383  }
384  }
385  }
386  }
387  // endcaps
388  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
389  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
390  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
391  if (EEDetId::validDetId(iX,iY,1)) {
392  EEDetId eedetid(iX,iY,1);
393  unsigned int hiee = eedetid.hashedIndex();
394  EcalPedestals::Item aped= peds->endcap(hiee);
395  // here I copy the last valid value in the peds object
396  EcalPedestals::Item item;
397  item.mean_x1 = aped.mean_x1;
398  item.rms_x1 = aped.rms_x1;
399  item.mean_x6 = aped.mean_x6;
400  item.rms_x6 = aped.rms_x6;
401  item.mean_x12 = aped.mean_x12;
402  item.rms_x12 = aped.rms_x12;
403  // here I copy the last valid value in the pedtemp object
404  pedtemp->insert(std::make_pair(eedetid.rawId(),item));
405  }
406  if (EEDetId::validDetId(iX,iY,-1)) {
407  EEDetId eedetid(iX,iY,-1);
408  unsigned int hiee = eedetid.hashedIndex();
409  EcalPedestals::Item aped= peds->endcap(hiee);
410  // here I copy the last valid value in the peds object
411  EcalPedestals::Item item;
412  item.mean_x1 = aped.mean_x1;
413  item.rms_x1 = aped.rms_x1;
414  item.mean_x6 = aped.mean_x6;
415  item.rms_x6 = aped.rms_x6;
416  item.mean_x12 = aped.mean_x12;
417  item.rms_x12 = aped.rms_x12;
418  // here I copy the last valid value in the pedtemp object
419  pedtemp->insert(std::make_pair(eedetid.rawId(),item));
420  }
421  }
422  }
423 
424  Time_t snc= (Time_t) irun ;
425  m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedtemp,snc));
426 
427  ss << "Run=" << irun << "_WAS_GOOD_"<<std::endl;
428  m_userTextLog = ss.str()+";";
429  } // good run : write in DB
430  else {
431  std::cout << "Run " << irun << " was BAD !!!! not sent to the DB";
432  if(nbad >= (dataset_mon.size()*0.05))
433  std::cout << " number of bad channels = " << nbad;
434  if(nEB <= 10200)
435  std::cout << " number of EB channels = " << nEB;
436  if(nEE <= 2440)
437  std::cout << " number of EE channels = " << nEE;
438  std::cout << std::endl;
439  ss << "Run=" << irun << "_WAS_BAD_"<<std::endl;
440  m_userTextLog = ss.str()+";";
441  } // bad run : do not write in DB
442  } // SubRunNumber
443  } // loop over runs
444 
445  delete econn;
446  delete peds; // this is the only one that popcon does not delete
447  } // runs to analyze ?
448  std::cout << "Ecal - > end of getNewObjects -----------\n";
449 }
450 
451 
453  unsigned int max_since=0;
454  max_since=static_cast<unsigned int>(tagInfo().lastInterval.first);
455  std::cout << "max_since : " << max_since << std::endl;
456  Ref ped_db = lastPayload();
457 
458  std::cout << "retrieved last payload " << std::endl;
459 
460 
461  // we copy the last valid record to a temporary object peds
462  EcalPedestals* peds = new EcalPedestals();
463 
464  // get from offline DB the last valid pedestal set ped_db
465  // edm::ESHandle<EcalPedestals> pedestals;
466  // esetup.get<EcalPedestalsRcd>().get(pedestals);
467 
468 
469  // only positive endcap side and
470  // x from 86 to 95
471  // y from 46 to 55
472  int ixmin=86; int ixmax=95;
473  int iymin=46; int iymax=55;
474  for(int iX=ixmin; iX<=ixmax ;++iX) {
475  for(int iY=iymin; iY<=iymax; ++iY) {
476 
477  if (EEDetId::validDetId(iX,iY,1)) {
478  EEDetId eedetidpos(iX,iY,1);
479  unsigned int hiee = eedetidpos.hashedIndex();
480  EcalPedestals::Item aped= ped_db->endcap(hiee);
481 
482  // here I copy the last valid value in the peds object
483  EcalPedestals::Item item;
484  item.mean_x1 = aped.mean_x1;
485  item.rms_x1 = aped.rms_x1;
486  item.mean_x6 = aped.mean_x6;
487  item.rms_x6 = aped.rms_x6;
488  item.mean_x12 = aped.mean_x12;
489  item.rms_x12 = aped.rms_x12;
490  peds->insert(std::make_pair(eedetidpos.rawId(),item));
491  if(iX==ixmin && iY==iymin) std::cout<<"ped12 " << item.mean_x12<< std::endl;
492 
493  }
494  }
495  }
496 
497 
498  std::cout <<"WOW: we just retrieved the last valid record from DB "<< std::endl;
499 
500 
501  // here we retrieve all the runs after the last from online DB
502 
503  std::cout << "Retrieving run list from ONLINE DB ... " << std::endl;
504 
505  std::cout << "Making connection..." << std::flush;
507  std::cout << "Done." << std::endl;
508 
509  if (!econn)
510  {
511  std::cout << " connection parameters " <<m_sid <<"/"<<m_user<<"/"<<m_pass<<std::endl;
512  throw cms::Exception("OMDS not available");
513  }
514 
515  // these are the online conditions DB classes
516  RunList my_runlist ;
517  RunTag my_runtag;
518  LocationDef my_locdef;
519  RunTypeDef my_rundef;
520 
521  my_locdef.setLocation("H2_07");
522  my_rundef.setRunType("PEDESTAL");
523  my_runtag.setLocationDef(my_locdef);
524  my_runtag.setRunTypeDef(my_rundef);
525  my_runtag.setGeneralTag("LOCAL");
526 
527 
528  // here we retrieve the Monitoring run records
529 
530  MonVersionDef monverdef;
531  monverdef.setMonitoringVersion("test01");
532 
533  MonRunTag mon_tag;
534  mon_tag.setGeneralTag("CMSSW");
535  mon_tag.setMonVersionDef(monverdef);
536  MonRunList mon_list;
537  mon_list.setMonRunTag(mon_tag);
538  mon_list.setRunTag(my_runtag);
539  // mon_list=econn->fetchMonRunList(my_runtag, mon_tag);
540  unsigned int min_run=max_since+1; // we have to add 1 to the last transferred one
541 
542  unsigned int max_run=m_lastRun;
543  mon_list=econn->fetchMonRunList(my_runtag, mon_tag,min_run,max_run );
544 
545  std::vector<MonRunIOV> mon_run_vec= mon_list.getRuns();
546  size_t mon_runs=mon_run_vec.size();
547  std::cout <<"number of Mon runs is : "<< mon_runs<< std::endl;
548 
549  if(mon_runs>0){
550 
551  for(size_t kr=0; kr<mon_runs; kr++){
552 
553  unsigned int irun=static_cast<unsigned int>(mon_run_vec[kr].getRunIOV().getRunNumber());
554 
555  std::cout << "here is first sub run : "<< mon_run_vec[kr].getSubRunNumber() << std::endl;
556  std::cout << "here is the run number: "<< mon_run_vec[kr].getRunIOV().getRunNumber() << std::endl;
557 
558  std::cout <<" retrieve the data for a given run"<< std::endl;
559 
560  if (mon_run_vec[kr].getSubRunNumber() <=1){
561 
562 
563  // retrieve the data for a given run
564  RunIOV runiov_prime = mon_run_vec[kr].getRunIOV();
565 
566  // retrieve the pedestals from OMDS for this run
567  std::map<EcalLogicID, MonPedestalsDat> dataset_mon;
568  econn->fetchDataSet(&dataset_mon, &mon_run_vec[kr]);
569  std::cout <<"OMDS record for run "<<irun <<" is made of "<< dataset_mon.size() << std::endl;
570  typedef std::map<EcalLogicID, MonPedestalsDat>::const_iterator CImon;
571  EcalLogicID ecid_xt;
572  MonPedestalsDat rd_ped;
573 
574  //int iEta=0;
575  //int iPhi=0;
576  int ix=0;
577  int iy=0;
578 
579  for (CImon p = dataset_mon.begin(); p != dataset_mon.end(); p++) {
580  ecid_xt = p->first;
581  rd_ped = p->second;
582  //int sm_num=ecid_xt.getID1();
583  int xt_num=ecid_xt.getID2(); // careful here !!! we number the channels from 1 to 1700
584 
585  //iEta=(xt_num/20)+1;
586  //iPhi=20-(xt_num-(iEta-1)*20);
587 
588  ix=95-(xt_num-1)/20;
589  iy=46+(xt_num-1)%20;
590 
591 
592  EcalPedestals::Item item;
593  item.mean_x1 =rd_ped.getPedMeanG1() ;
594  item.rms_x1 =rd_ped.getPedRMSG1();
595  item.mean_x6 =rd_ped.getPedMeanG6();
596  item.rms_x6 =rd_ped.getPedRMSG6() ;
597  item.mean_x12 =rd_ped.getPedMeanG12();
598  item.rms_x12 =rd_ped.getPedRMSG12();
599 
600  EEDetId eedetidpos(ix,iy,1);
601  // EBDetId ebdetid(iEta,iPhi);
602 
603  // here we change in the peds object only the values that are available in the online DB
604  // otherwise we keep the old value
605 
606  peds->insert(std::make_pair(eedetidpos.rawId(),item));
607  if(ix==ixmin && iy==iymin) std::cout<<"ped12 " << item.mean_x12<< std::endl;
608  }
609 
610  std::cout << "Generating popcon record for run " << irun << "..." << std::flush;
611 
612 
613  // now I copy peds in pedtemp and I ship pedtemp to popcon
614  // if I use always the same peds I always overwrite
615  // so I really have to create new objects for each new run
616  // popcon deletes everything for me
617 
618  EcalPedestals* pedtemp = new EcalPedestals();
619 
620 
621  for(int iX=ixmin; iX<=ixmax ;++iX) {
622  for(int iY=iymin; iY<=iymax; ++iY) {
623 
624  if (EEDetId::validDetId(iX,iY,1))
625  {
626  EEDetId eedetidpos(iX,iY,1);
627  unsigned int hiee = eedetidpos.hashedIndex();
628  EcalPedestals::Item aped = peds->endcap(hiee);
629 
630  EcalPedestals::Item item;
631  item.mean_x1 = aped.mean_x1;
632  item.rms_x1 = aped.rms_x1;
633  item.mean_x6 = aped.mean_x6;
634  item.rms_x6 = aped.rms_x6;
635  item.mean_x12 = aped.mean_x12;
636  item.rms_x12 = aped.rms_x12;
637  // here I copy the last valid value in the pedtemp object
638  pedtemp->insert(std::make_pair(eedetidpos.rawId(),item));
639  if(iX==ixmin && iY==iymin) std::cout<<"ped12 " << item.mean_x12<< std::endl;
640  }
641  }
642  }
643 
644 
645 
646  Time_t snc= (Time_t) irun ;
647 
648  m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedtemp,snc));
649 
650  std::cout << "Ecal - > end of getNewObjectsH2 -----------\n";
651 
652  }
653  }
654  }
655  delete econn;
656  delete peds; // this is the only one that popcon does not delete
657 }
658 
660  std::cout << " reading the input file " << m_filename << std::endl;
661  std::ifstream fInput;
662  fInput.open(m_filename);
663  if(!fInput.is_open()) {
664  std::cout << "ERROR : cannot open file " << m_filename << std::endl;
665  exit (1);
666  }
667  // string pos, dummyLine;
668  int hashedId;
669  float EBmean12[kEBChannels], EBrms12[kEBChannels], EBmean6[kEBChannels], EBrms6[kEBChannels], EBmean1[kEBChannels], EBrms1[kEBChannels];
670  //***************** barrel
671  // getline(fInput, dummyLine); // skip first line
672  for (int iChannel = 0; iChannel < kEBChannels; iChannel++) {
673  fInput >> hashedId >> EBmean12[iChannel] >> EBrms12[iChannel] >> EBmean6[iChannel] >> EBrms6[iChannel]
674  >> EBmean1[iChannel] >> EBrms1[iChannel];
675  if(hashedId != iChannel + 1) {
676  std::cout << m_filename << " strange hash " << hashedId << " while iChannel " << iChannel << std::endl;
677  exit(-1);
678  }
679  }
680 
681  // ***************** now EE *****************
682  float EEmean12[kEEChannels], EErms12[kEEChannels], EEmean6[kEEChannels], EErms6[kEEChannels], EEmean1[kEEChannels], EErms1[kEEChannels];
683  for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
684  fInput >> hashedId >> EEmean12[iChannel] >> EErms12[iChannel] >> EEmean6[iChannel] >> EErms6[iChannel]
685  >> EEmean1[iChannel] >> EErms1[iChannel];
686  if(hashedId != iChannel + kEBChannels + 1) {
687  std::cout << m_filename << " strange hash " << hashedId << " while iChannel " << iChannel << std::endl;
688  exit(-1);
689  }
690  }
691  fInput.close();
692 
693  EcalPedestals* ped = new EcalPedestals();
694  // barrel
695  for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
696  if(iEta==0) continue;
697  for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
698  if (EBDetId::validDetId(iEta,iPhi)) {
699  EBDetId ebdetid(iEta,iPhi);
700  unsigned int hieb = ebdetid.hashedIndex();
701  EcalPedestals::Item item;
702  item.mean_x1 = EBmean1[hieb];
703  item.rms_x1 = EBrms1[hieb];
704  item.mean_x6 = EBmean6[hieb];
705  item.rms_x6 = EBrms6[hieb];
706  item.mean_x12 = EBmean12[hieb];
707  item.rms_x12 = EBrms12[hieb];
708  ped->insert(std::make_pair(ebdetid.rawId(),item));
709  } // valid EBId
710  } // loop over phi
711  } // loop over eta
712  // endcaps
713  // std::ofstream fout;
714  // fout.open("Pedestal.check");
715  for(int iz = -1; iz < 2; iz = iz + 2) { // z : -1 and +1
716  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
717  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
718  if (EEDetId::validDetId(iX, iY, iz)) {
719  EEDetId eedetid(iX, iY, iz);
720  unsigned int hiee = eedetid.hashedIndex();
721  // fout << hiee << " mean 12 " << EEmean12[hiee] << std::endl;
722  EcalPedestals::Item item;
723  item.mean_x1 = EEmean1[hiee];
724  item.rms_x1 = EErms1[hiee];
725  item.mean_x6 = EEmean6[hiee];
726  item.rms_x6 = EErms6[hiee];
727  item.mean_x12 = EEmean12[hiee];
728  item.rms_x12 = EErms12[hiee];
729  ped->insert(std::make_pair(eedetid.rawId(),item));
730  } // val EEId
731  } // loop over y
732  } // loop over x
733  } // loop over z
734  // fout.close();
735 
736  unsigned int irun = m_firstRun;
737  Time_t snc= (Time_t) irun ;
738  m_to_transfer.push_back(std::make_pair((EcalPedestals*)ped,snc));
739 
740  std::cout << "Ecal - > end of readPedestalFile -----------\n";
741 }
742 
744  bool debug = false;
745  std::cout << " reading local Pedestal run (2017 way)! " << m_filename << std::endl;
746 
747  // First we copy the last valid record to a temporary object peds
748  Ref ped_db = lastPayload();
749  EcalPedestals* peds = new EcalPedestals();
750  std::cout << "retrieved last payload " << std::endl;
751 
752  for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
753  if(iEta==0) continue;
754  for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
755  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
756  if (EBDetId::validDetId(iEta,iPhi)) {
757  EBDetId ebdetid(iEta,iPhi,EBDetId::ETAPHIMODE);
758  EcalPedestals::const_iterator it = ped_db->find(ebdetid.rawId());
759  EcalPedestals::Item aped = (*it);
760  // here I copy the last valid value in the peds object
761  EcalPedestals::Item item;
762  item.mean_x1 = aped.mean_x1;
763  item.rms_x1 = aped.rms_x1;
764  item.mean_x6 = aped.mean_x6;
765  item.rms_x6 = aped.rms_x6;
766  item.mean_x12 = aped.mean_x12;
767  item.rms_x12 = aped.rms_x12;
768  peds->insert(std::make_pair(ebdetid.rawId(),item));
769  }
770  }
771  }
772  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
773  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
774  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
775  if (EEDetId::validDetId(iX,iY,1)) {
776  EEDetId eedetidpos(iX,iY,1);
777  EcalPedestals::const_iterator it = ped_db->find(eedetidpos.rawId());
778  EcalPedestals::Item aped = (*it);
779  // here I copy the last valid value in the peds object
780  EcalPedestals::Item item;
781  item.mean_x1 = aped.mean_x1;
782  item.rms_x1 = aped.rms_x1;
783  item.mean_x6 = aped.mean_x6;
784  item.rms_x6 = aped.rms_x6;
785  item.mean_x12 = aped.mean_x12;
786  item.rms_x12 = aped.rms_x12;
787  peds->insert(std::make_pair(eedetidpos.rawId(),item));
788  }
789  if(EEDetId::validDetId(iX,iY,-1)) {
790  EEDetId eedetidneg(iX,iY,-1);
791  EcalPedestals::const_iterator it = ped_db->find(eedetidneg.rawId());
792  EcalPedestals::Item aped = (*it);
793  // here I copy the last valid value in the peds object
794  EcalPedestals::Item item;
795  item.mean_x1 = aped.mean_x1;
796  item.rms_x1 = aped.rms_x1;
797  item.mean_x6 = aped.mean_x6;
798  item.rms_x6 = aped.rms_x6;
799  item.mean_x12 = aped.mean_x12;
800  item.rms_x12 = aped.rms_x12;
801  peds->insert(std::make_pair(eedetidneg.rawId(),item));
802  }
803  }
804  }
805 
806  std::cout << " reading the input file " << m_filename << std::endl;
807  std::ifstream fInput;
808  fInput.open(m_filename);
809  if(!fInput.is_open()) {
810  std::cout << "ERROR : cannot open file " << m_filename << std::endl;
811  exit (1);
812  }
813  // string pos, dummyLine;
814  int hashedId;
815  float EBmean12[kEBChannels], EBrms12[kEBChannels], EBmean6[kEBChannels], EBrms6[kEBChannels], EBmean1[kEBChannels], EBrms1[kEBChannels];
816  //***************** barrel
817  // getline(fInput, dummyLine); // skip first line
818  for (int iChannel = 0; iChannel < kEBChannels; iChannel++) {
819  fInput >> hashedId >> EBmean12[iChannel] >> EBrms12[iChannel] >> EBmean6[iChannel] >> EBrms6[iChannel]
820  >> EBmean1[iChannel] >> EBrms1[iChannel];
821  if(hashedId != iChannel + 1) {
822  std::cout << m_filename << " strange hash " << hashedId << " while iChannel " << iChannel << std::endl;
823  exit(-1);
824  }
825  }
826 
827  // ***************** now EE *****************
828  float EEmean12[kEEChannels], EErms12[kEEChannels], EEmean6[kEEChannels], EErms6[kEEChannels], EEmean1[kEEChannels], EErms1[kEEChannels];
829  for (int iChannel = 0; iChannel < kEEChannels; iChannel++) {
830  fInput >> hashedId >> EEmean12[iChannel] >> EErms12[iChannel] >> EEmean6[iChannel] >> EErms6[iChannel]
831  >> EEmean1[iChannel] >> EErms1[iChannel];
832  if(hashedId != iChannel + kEBChannels + 1) {
833  std::cout << m_filename << " strange hash " << hashedId << " while iChannel " << iChannel << std::endl;
834  exit(-1);
835  }
836  }
837  fInput.close();
838 
839  EcalPedestals* ped = new EcalPedestals();
840  // barrel
841  for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
842  if(iEta==0) continue;
843  for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
844  if (EBDetId::validDetId(iEta,iPhi)) {
845  EBDetId ebdetid(iEta,iPhi);
846  unsigned int hieb = ebdetid.hashedIndex();
847  EcalPedestals::Item item;
848  EcalPedestals::Item previous_ped = peds->barrel(hieb);
849  if(debug & (EBmean12[hieb] == -999. || EBrms12[hieb] == -999. || EBmean6[hieb] == -999. || EBrms6[hieb] == -999. ||
850  EBmean1[hieb] == -999. || EBrms1[hieb] == -999.))
851  std::cout << " bad EB channel eta " << iEta << " phi " << iPhi << " " << EBmean12[hieb] << " " << EBrms12[hieb]
852  << " " << EBmean6[hieb] << " " << EBrms6[hieb] << " " << EBmean1[hieb] << " " << EBrms1[hieb] << std::endl;
853  if(EBmean1[hieb] != -999.) item.mean_x1 = EBmean1[hieb];
854  else item.mean_x1 = previous_ped.mean_x1;
855  if(EBrms1[hieb] != -999.) item.rms_x1 = EBrms1[hieb];
856  else item.rms_x1 = previous_ped.rms_x1;
857  if(EBmean6[hieb] != -999.) item.mean_x6 = EBmean6[hieb];
858  else item.mean_x6 = previous_ped.mean_x6;
859  if(EBrms6[hieb] != -999.) item.rms_x6 = EBrms6[hieb];
860  else item.rms_x6 = previous_ped.rms_x6;
861  if(EBmean12[hieb] != -999.) item.mean_x12 = EBmean12[hieb];
862  else item.mean_x12 = previous_ped.mean_x12;
863  if(EBrms12[hieb] != -999.) item.rms_x12 = EBrms12[hieb];
864  else item.rms_x12 = previous_ped.rms_x12;
865  ped->insert(std::make_pair(ebdetid.rawId(),item));
866  } // valid EBId
867  } // loop over phi
868  } // loop over eta
869  // endcaps
870  // std::ofstream fout;
871  // fout.open("Pedestal.check");
872  for(int iz = -1; iz < 2; iz = iz + 2) { // z : -1 and +1
873  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
874  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
875  if (EEDetId::validDetId(iX, iY, iz)) {
876  EEDetId eedetid(iX, iY, iz);
877  unsigned int hiee = eedetid.hashedIndex();
878  // fout << hiee << " mean 12 " << EEmean12[hiee] << std::endl;
879  EcalPedestals::Item item;
880  EcalPedestals::Item previous_ped= peds->endcap(hiee);
881  if(debug & (EEmean12[hiee] == -999. || EErms12[hiee] == -999. || EEmean6[hiee] == -999. || EErms6[hiee] == -999. ||
882  EEmean1[hiee] == -999. || EErms1[hiee] == -999.))
883  std::cout << " bad EE channel x " << iX << " y " << iY << " z" << iz << " " << EEmean12[hiee] << " " << EErms12[hiee]
884  << " " <<EEmean6[hiee] << " " << EErms6[hiee] << " " << EEmean1[hiee] << " " << EErms1[hiee] << std::endl;
885  if(EEmean1[hiee] != -999.) item.mean_x1 = EEmean1[hiee];
886  else item.mean_x1 = previous_ped.mean_x1;
887  if(EErms1[hiee] != -999.) item.rms_x1 = EErms1[hiee];
888  else item.rms_x1 = previous_ped.rms_x1;
889  if(EEmean6[hiee] != -999.) item.mean_x6 = EEmean6[hiee];
890  else item.mean_x6 = previous_ped.mean_x6;
891  if(EErms6[hiee] != -999.) item.rms_x6 = EErms6[hiee];
892  else item.rms_x6 = previous_ped.rms_x6;
893  if(EEmean12[hiee] != -999.) item.mean_x12 = EEmean12[hiee];
894  else item.mean_x12 = previous_ped.mean_x12;
895  if(EErms12[hiee] != -999.) item.rms_x12 = EErms12[hiee];
896  else item.rms_x12 = previous_ped.rms_x12;
897  ped->insert(std::make_pair(eedetid.rawId(),item));
898  } // val EEId
899  } // loop over y
900  } // loop over x
901  } // loop over z
902  // fout.close();
903 
904  unsigned int irun = m_firstRun;
905  Time_t snc= (Time_t) irun ;
906  m_to_transfer.push_back(std::make_pair((EcalPedestals*)ped,snc));
907 
908  std::cout << "Ecal - > end of readPedestalFile -----------\n";
909 }
910 
912  std::cout << " reading the root file " << m_filename << std::endl;
913  TFile * hfile = new TFile(m_filename.c_str());
914 
915  TTree *treeChan = (TTree*)hfile->Get("PedChan");
916  int iChannel = 0, ix = 0, iy = 0, iz = 0;
917  treeChan->SetBranchAddress("Channels", &iChannel);
918  treeChan->SetBranchAddress("x", &ix);
919  treeChan->SetBranchAddress("y", &iy);
920  treeChan->SetBranchAddress("z", &iz);
921  int neventsChan = (int)treeChan->GetEntries();
922  std::cout << "PedChan nb entries " << neventsChan << std::endl;
923  int ringEB[kEBChannels], sideEB[kEBChannels], ixEE[kEEChannels], iyEE[kEEChannels], izEE[kEEChannels];
924  for(int entry = 0; entry < neventsChan; entry++) {
925  treeChan->GetEntry(entry);
926  if(entry < kEBChannels) {
927  ringEB[iChannel] = (abs(ix) -1)/5; // -85...-1, 1...85 give 0...16
928  sideEB[iChannel] = 1;
929  if(ix < 0) sideEB[iChannel] = 0;
930  if(entry%10000 == 0) std::cout << " EB channel " << iChannel << " eta " << ix << " phi " << iy
931  << " side " << sideEB[iChannel] << " ring " << ringEB[iChannel] << std::endl;
932  }
933  else {
934  ixEE[iChannel] = ix;
935  iyEE[iChannel] = iy;
936  izEE[iChannel] = iz;
937  if(entry%1000 == 0) std::cout << " EE channel " << iChannel << " x " << ixEE[iChannel] << " y " << iyEE[iChannel] << " z " << izEE[iChannel] << std::endl;
938  }
939  }
940  /* 2016
941  int Nbpedxml = 26;
942  Int_t pedxml[Nbpedxml] = {271948, 273634, 273931, 274705, 275403, 276108, 276510, 277169, 278123, 278183,
943  278246, 278389, 278499, 278693, 278858, 278888, 278931, 279728, 280129, 280263,
944  280941, 281753, 282631, 282833, 283199, 283766};
945  */
946  Int_t pedxml[Nbpedxml] = {286535, 293513, 293632, 293732, 295507, 295672, 296391, 296917, 297388, 298481,
947  299279, 299710, 300186, 300581, 301191, 302006, 302293, 302605, 303436, 303848,
948  304211, 304680, 305117, 305848, 306176};
949  Int_t run16Index = 0;
950 
951  Int_t fed[kChannels], chan[kChannels], id, run, run_type, seq_id, las_id, fill_num, run_num_infill, run_time, run_time_stablebeam, nxt, time[54];
952  Float_t ped[kChannels], pedrms[kChannels], lumi, bfield;
953  TTree *tree = (TTree*)hfile->Get("T");
954  tree->Print();
955  tree->SetBranchAddress("id", &id);
956  tree->SetBranchAddress("run", &run);
957  tree->SetBranchAddress("run_type", &run_type);
958  tree->SetBranchAddress("seq_id", &seq_id);
959  tree->SetBranchAddress("las_id", &las_id);
960  tree->SetBranchAddress("fill_num", &fill_num);
961  tree->SetBranchAddress("run_num_infill", &run_num_infill);
962  tree->SetBranchAddress("run_time", &run_time);
963  tree->SetBranchAddress("run_time_stablebeam", &run_time_stablebeam);
964  tree->SetBranchAddress("lumi", &lumi);
965  tree->SetBranchAddress("bfield", &bfield);
966  tree->SetBranchAddress("nxt", &nxt); // nb of filled Crystals
967  tree->SetBranchAddress("time", time);
968  tree->SetBranchAddress("fed", fed);
969  tree->SetBranchAddress("chan", chan);
970  tree->SetBranchAddress("ped", ped);
971  tree->SetBranchAddress("pedrms", pedrms);
972  int nevents = (int)tree->GetEntries();
973  std::cout << " nb entries " << nevents << std::endl;
974  std::ofstream fout;
975  fout.open("copyTreePedestals.txt");
976  if(!fout.is_open()) {
977  std::cout << "ERROR : cannot open file copyTreePedestals.txt" << std::endl;
978  exit (1);
979  }
980  Double_t EAmean1[kChannels], EArms1[kChannels], EAmean6[kChannels], EArms6[kChannels], EAmean12[kChannels], EArms12[kChannels];
981  Int_t RunEntry = 0, EAentry[kChannels];
982  for(int ich = 0; ich < kChannels; ich++) {
983  EAmean12[ich] = 0;
984  EArms12[ich] = 0;
985  EAentry[ich] = 0;
986  }
987  tree->GetEntry(0);
988  fout << " first run " << run << " fill " << fill_num << " B field " << bfield << " run type " << run_type << " seq_id " << seq_id
989  << " las_id " << las_id << " run_num_infill " << run_num_infill << " lumi "<< lumi << " nb of Crystals " << nxt << std::endl;
990  for(int ich = 0; ich < kChannels; ich++) {
991  if(ped[ich] != 0.) {
992  if(ich < kEBChannels)
993  fout << " channel " << ich << " FED " << fed[ich] << " chan " << chan[ich] << " pedestal " << ped[ich] << " RMS " << pedrms[ich] << std::endl;
994  else // EE
995  fout << " channel " << ich << " EE channel " << ich - kEBChannels << " FED " << fed[ich] << " chan " << chan[ich]
996  << " pedestal " << ped[ich] << " RMS " << pedrms[ich] << std::endl;
997  }
998  }
999 
1000  int run_type_kept = m_runtype; // 1 collision 2 cosmics 3 circulating 4 test
1001  int first_run_kept = (int)m_firstRun; // m_firstRun is unsigned!
1002  int runold = run;
1003  int firsttimeFED = -1;
1004  // int timeold = -1;
1005  for(int entry = 0; entry < nevents; entry++) {
1006  tree->GetEntry(entry);
1007  if(run < first_run_kept) {
1008  fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1009  << " before first wanted " << m_firstRun << std::endl;
1010  runold = run;
1011  continue;
1012  }
1013  if(run_type != run_type_kept) {
1014  fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1015  << " run type " << run_type << std::endl;
1016  continue; // use only wanted type runs
1017  }
1018  if(nxt != kChannels) {
1019  fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1020  << " *********** Number of channels " << nxt << std::endl;
1021  continue;
1022  }
1023  if(bfield < 3.79) {
1024  fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1025  << " *********** bfield = " << bfield << std::endl;
1026  // continue; keep these runs
1027  }
1028  if(run_type_kept == 1) { // for collision runs, keep only sequences after stable beam
1029  int time_seq = 0;
1030  for(int ifed = 0; ifed < 54; ifed++) {
1031  if(time[ifed] < run_time_stablebeam) {
1032  if(time_seq == 0)
1033  fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1034  << " *********** sequence before stable beam at " << run_time_stablebeam << " FED " << ifed << " : " << time[ifed];
1035  else
1036  fout << " FED " << ifed << " : " << time[ifed];
1037  time_seq++;
1038  }
1039  }
1040  if(time_seq != 0) {
1041  fout << " total nb " << time_seq << std::endl;
1042  continue;
1043  }
1044  } // only collision runs
1045  // if(idtime != timeold) {
1046  // std::cout << " entry "<< entry << " run " << run << " time " << idtime << " run type " << run_type << std::endl;
1047  // timeold = idtime;
1048  // }
1049  if(run == runold) {
1050  RunEntry++;
1051  for(int ich = 0; ich < kChannels; ich++) {
1052  if(ped[ich] < 300 && ped[ich] > 100) {
1053  EAmean12[ich] += ped[ich];
1054  EArms12[ich] += pedrms[ich];
1055  EAentry[ich]++;
1056  }
1057  }
1058  }
1059  else {
1060  // new run. Write the previous one
1061  // std::cout << " entry "<< entry << " fill " << fill_num << " run " << runold << " nb of events " << RunEntry
1062  // << " time " << run_time << " " << run_time_stablebeam << " " << time[0] << " run type " << run_type << std::endl;
1063  if(RunEntry == 0 || (run_type_kept == 2 && RunEntry < 6)) fout << " skiped run " << runold << " not enough entries : " << RunEntry << std::endl;
1064  else {
1065  fout << " entry "<< entry -1 << " run " << runold << " nb of events " << RunEntry;
1066  firsttimeFED = time[0];
1067  for(int ifed = 0; ifed < 54; ifed++) {
1068  fout << " " << time[ifed];
1069  if(firsttimeFED < time[ifed]) firsttimeFED = time[ifed];
1070  }
1071  fout << std::endl;
1072 
1073  // get gain 1 and 6 results
1074  bool foundNew = false;
1075  for(int i = run16Index; i < Nbpedxml; i++) {
1076  if(runold > pedxml[i]) {
1077  fout << " found a new gain 1, 6 file " << pedxml[i] << " at index " << i << std::endl;
1078  run16Index++;
1079  foundNew = true;
1080  if(runold < pedxml[i + 1]) break;
1081  }
1082  }
1083  if(foundNew) {
1084  int Indexxml = run16Index -1;
1085  fout << " opening Pedestals_" << pedxml[Indexxml] << ".xml at index " << Indexxml << std::endl;
1086  std::ifstream fxml;
1087  fxml.open(Form("Pedestals_%i.xml",pedxml[Indexxml]));
1088  if(!fxml.is_open()) {
1089  std::cout << "ERROR : cannot open file Pedestals_" << pedxml[Indexxml] << ".xml" << std::endl;
1090  exit (1);
1091  }
1092  std::string dummyLine, mean12, rms12, bid;
1093  for(int i = 0; i < 9; i++) std::getline(fxml, dummyLine); // skip first lines
1094  // Barrel
1095  for (int iEBChannel = 0; iEBChannel < kEBChannels; iEBChannel++) {
1096  fxml >> mean12 >> rms12 >> bid;
1097  // std::string stt = bid.std::substr(10,15);
1098  // istringstream ii(stt);
1099  // ii >> EBmean12[iEBChannel];
1100  // fxml >> bid;
1101  // stt = bid.substr(9,15);
1102  // istringstream r12(stt);
1103  // r12 >> EBrms12[iEBChannel];
1104  // fxml >> bid;
1105  std::string stt = bid.substr(9,15);
1106  std::istringstream m6(stt);
1107  m6 >> EAmean6[iEBChannel];
1108  fxml >> bid;
1109  stt = bid.substr(8,15);
1110  std::istringstream r6(stt);
1111  r6 >> EArms6[iEBChannel];
1112  fxml >> bid;
1113  stt = bid.substr(9,15);
1114  std::istringstream m1(stt);
1115  m1 >> EAmean1[iEBChannel];
1116  fxml >> bid;
1117  stt = bid.substr(8,15);
1118  std::istringstream r1(stt);
1119  r1 >> EArms1[iEBChannel];
1120  if(iEBChannel%10000 == 0) fout << " EB channel " << iEBChannel << " " << mean12 << " " << rms12
1121  << " " << EAmean6[iEBChannel] << " " << EArms6[iEBChannel]
1122  << " " << EAmean1[iEBChannel] << " " << EArms1[iEBChannel] << std::endl;
1123  for(int i = 0; i < 3; i++) std::getline(fxml, dummyLine); // skip lines
1124  }
1125  for(int i = 0; i < 6; i++) std::getline(fxml, dummyLine); // skip lines
1126  for (int iEEChannel = 0; iEEChannel < kEEChannels; iEEChannel++) {
1127  int ich = iEEChannel + kEBChannels;
1128  fxml >> mean12 >> rms12 >> bid;
1129  std::string stt = bid.substr(9,15);
1130  std::istringstream m6(stt);
1131  m6 >> EAmean6[ich];
1132  fxml >> bid;
1133  stt = bid.substr(8,15);
1134  std::istringstream r6(stt);
1135  r6 >> EArms6[ich];
1136  fxml >> bid;
1137  stt = bid.substr(9,15);
1138  std::istringstream m1(stt);
1139  m1 >> EAmean1[ich];
1140  fxml >> bid;
1141  stt = bid.substr(8,15);
1142  std::istringstream r1(stt);
1143  r1 >> EArms1[ich];
1144  if(iEEChannel%1000 == 0) fout << " EE channel " << iEEChannel << " " << mean12 << " " << rms12
1145  << " " << EAmean6[ich] << " " << EArms6[ich]
1146  << " " << EAmean1[ich] << " " << EArms1[ich] << std::endl;
1147  for(int i = 0; i < 3; i++) std::getline(fxml, dummyLine); // skip lines
1148  }
1149 
1150  fxml.close();
1151  }
1152  // end gain 1 and 6 results
1153 
1155  EcalPedestals::Item item;
1156  for(int ich = 0; ich < kChannels; ich++) {
1157  if(EAentry[ich] != 0) {
1158  EAmean12[ich] /= EAentry[ich];
1159  EArms12[ich] /= EAentry[ich];
1160  }
1161  else {
1162  EAmean12[ich] = 200.;
1163  EArms12[ich] = 0.;
1164  }
1165  if(ich%10000 == 0) fout << " channel " << ich << " ped " << EAmean12[ich] << " RMS " << EArms12[ich] << std::endl;
1166  //
1167  item.mean_x1 = EAmean1[ich];
1168  item.rms_x1 = EArms1[ich];
1169  item.mean_x6 = EAmean6[ich];
1170  item.rms_x6 = EArms6[ich];
1171  item.mean_x12 = EAmean12[ich];
1172  item.rms_x12 = EArms12[ich];
1173  if(ich < kEBChannels) {
1174  // EBDetId ebdetid(fed, chan, EBDetId::SMCRYSTALMODE);
1175  EBDetId ebdetid = EBDetId::unhashIndex(ich);
1176  pedestal->insert(std::make_pair(ebdetid.rawId(),item));
1177  }
1178  else {
1179  // EEDetId eedetid(iX, iY, iz);
1180  int iChannel = ich - kEBChannels;
1181  EEDetId eedetid = EEDetId::unhashIndex(iChannel);
1182  pedestal->insert(std::make_pair(eedetid.rawId(),item));
1183  }
1184  } // end loop over all channels
1185  Time_t snc= (Time_t) runold;
1186  m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedestal, snc));
1187  } // skip too short cosmics runs
1188 
1189  runold = run;
1190  RunEntry = 1;
1191  for(int ich = 0; ich < kChannels; ich++) {
1192  if(ped[ich] < 300 && ped[ich] > 100) {
1193  EAmean12[ich] = ped[ich];
1194  EArms12[ich] = pedrms[ich];
1195  EAentry[ich] = 1;
1196  }
1197  else {
1198  EAmean12[ich] = 0;
1199  EArms12[ich] = 0;
1200  EAentry[ich] = 0;
1201  }
1202  }
1203  } // new run
1204  } // end loop over all entries
1205  // write also the last run
1206  fout << " last entry fill " << fill_num << " run " << runold << " nb of events " << RunEntry
1207  << " time " << run_time << " " << run_time_stablebeam << " " << time[0] << " run type " << run_type << std::endl;
1208  for(int ifed = 0; ifed < 54; ifed++)
1209  fout << " " << time[ifed];
1210  fout << std::endl;
1212  EcalPedestals::Item item;
1213  for(int ich = 0; ich < kChannels; ich++) {
1214  if(EAentry[ich] != 0) {
1215  EAmean12[ich] /= EAentry[ich];
1216  EArms12[ich] /= EAentry[ich];
1217  }
1218  else {
1219  EAmean12[ich] = 200.;
1220  EArms12[ich] = 0.;
1221  }
1222  if(ich%10000 == 0) fout << " channel " << ich << " ped " << EAmean12[ich] << " RMS " << EArms12[ich] << std::endl;
1223  // get gain 1 and 6 results
1224  // ...
1225  //
1226  item.mean_x1 = EAmean1[ich];
1227  item.rms_x1 = EArms1[ich];
1228  item.mean_x6 = EAmean6[ich];
1229  item.rms_x6 = EArms6[ich];
1230  item.mean_x12 = EAmean12[ich];
1231  item.rms_x12 = EArms12[ich];
1232  if(ich < kEBChannels) {
1233  // EBDetId ebdetid(fed, chan, EBDetId::SMCRYSTALMODE);
1234  EBDetId ebdetid = EBDetId::unhashIndex(ich);
1235  pedestal->insert(std::make_pair(ebdetid.rawId(),item));
1236  }
1237  else {
1238  // EEDetId eedetid(iX, iY, iz);
1239  int iChannel = ich - kEBChannels;
1240  EEDetId eedetid = EEDetId::unhashIndex(iChannel);
1241  pedestal->insert(std::make_pair(eedetid.rawId(),item));
1242  }
1243  } // end loop over all channels
1244  Time_t snc= (Time_t) runold;
1245  m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedestal,snc)); // run based IOV
1246  std::cout << "Ecal - > end of readPedestalTree -----------\n";
1247 }
1248 
1250  bool debug = false;
1251  std::cout << " reading the root file " << m_filename << std::endl;
1252  TFile * hfile = new TFile(m_filename.c_str());
1253 
1254  TTree *treeChan = (TTree*)hfile->Get("PedChan");
1255  int iChannel = 0, ix = 0, iy = 0, iz = 0;
1256  treeChan->SetBranchAddress("Channels", &iChannel);
1257  treeChan->SetBranchAddress("x", &ix);
1258  treeChan->SetBranchAddress("y", &iy);
1259  treeChan->SetBranchAddress("z", &iz);
1260  int neventsChan = (int)treeChan->GetEntries();
1261  std::cout << "PedChan nb entries " << neventsChan << std::endl;
1262  int ringEB[kEBChannels], sideEB[kEBChannels], ixEE[kEEChannels], iyEE[kEEChannels], izEE[kEEChannels];
1263  for(int entry = 0; entry < neventsChan; entry++) {
1264  treeChan->GetEntry(entry);
1265  if(entry < kEBChannels) {
1266  ringEB[iChannel] = (abs(ix) -1)/5; // -85...-1, 1...85 give 0...16
1267  sideEB[iChannel] = 1;
1268  if(ix < 0) sideEB[iChannel] = 0;
1269  if(debug && entry%10000 == 0) std::cout << " EB channel " << iChannel << " eta " << ix << " phi " << iy
1270  << " side " << sideEB[iChannel] << " ring " << ringEB[iChannel] << std::endl;
1271  }
1272  else {
1273  ixEE[iChannel] = ix;
1274  iyEE[iChannel] = iy;
1275  izEE[iChannel] = iz;
1276  if(debug && entry%1000 == 0) std::cout << " EE channel " << iChannel << " x " << ixEE[iChannel] << " y "
1277  << iyEE[iChannel] << " z " << izEE[iChannel] << std::endl;
1278  }
1279  }
1280  /* 2016
1281  int Nbpedxml = 26;
1282  Int_t pedxml[Nbpedxml] = {271948, 273634, 273931, 274705, 275403, 276108, 276510, 277169, 278123, 278183,
1283  278246, 278389, 278499, 278693, 278858, 278888, 278931, 279728, 280129, 280263,
1284  280941, 281753, 282631, 282833, 283199, 283766};
1285  */
1286  Int_t pedxml[Nbpedxml] = {286535, 293513, 293632, 293732, 295507, 295672, 296391, 296917, 297388, 298481,
1287  299279, 299710, 300186, 300581, 301191, 302006, 302293, 302605, 303436, 303848,
1288  304211, 304680, 305117, 305848, 306176};
1289  Int_t run16Index = 0;
1290 
1291  Int_t fed[kChannels], chan[kChannels], id, run, run_type, seq_id, las_id, fill_num, run_num_infill, run_time, run_time_stablebeam, nxt, time[54];
1292  Float_t ped[kChannels], pedrms[kChannels], lumi, bfield;
1293  TTree *tree = (TTree*)hfile->Get("T");
1294  tree->Print();
1295  tree->SetBranchAddress("id", &id);
1296  tree->SetBranchAddress("run", &run);
1297  tree->SetBranchAddress("run_type", &run_type);
1298  tree->SetBranchAddress("seq_id", &seq_id);
1299  tree->SetBranchAddress("las_id", &las_id);
1300  tree->SetBranchAddress("fill_num", &fill_num);
1301  tree->SetBranchAddress("run_num_infill", &run_num_infill);
1302  tree->SetBranchAddress("run_time", &run_time);
1303  tree->SetBranchAddress("run_time_stablebeam", &run_time_stablebeam);
1304  tree->SetBranchAddress("lumi", &lumi);
1305  tree->SetBranchAddress("bfield", &bfield);
1306  tree->SetBranchAddress("nxt", &nxt); // nb of filled Crystals
1307  tree->SetBranchAddress("time", time);
1308  tree->SetBranchAddress("fed", fed);
1309  tree->SetBranchAddress("chan", chan);
1310  tree->SetBranchAddress("ped", ped);
1311  tree->SetBranchAddress("pedrms", pedrms);
1312  int nevents = (int)tree->GetEntries();
1313  std::cout << " nb entries " << nevents << std::endl;
1314  std::ofstream fout;
1315  fout.open("copyTimestampPedestals.txt");
1316  if(!fout.is_open()) {
1317  std::cout << "ERROR : cannot open file copyTimestampPedestals.txt" << std::endl;
1318  exit (1);
1319  }
1320  Double_t EAmean1[kChannels], EArms1[kChannels], EAmean6[kChannels], EArms6[kChannels], EAmean12[kChannels], EArms12[kChannels];
1321  for(int ich = 0; ich < kChannels; ich++) {
1322  EAmean12[ich] = 200.;
1323  EArms12[ich] = 0.;
1324  }
1325  tree->GetEntry(0);
1326  fout << " first run " << run << " fill " << fill_num << " B field " << bfield << " run type " << run_type << " seq_id " << seq_id
1327  << " las_id " << las_id << " run_num_infill " << run_num_infill << " lumi "<< lumi << " nb of Crystals " << nxt << std::endl;
1328  if(debug) {
1329  for(int ich = 0; ich < kChannels; ich++) {
1330  if(ped[ich] != 0.) {
1331  if(ich < kEBChannels)
1332  fout << " channel " << ich << " FED " << fed[ich] << " chan " << chan[ich] << " pedestal " << ped[ich] << " RMS " << pedrms[ich] << std::endl;
1333  else // EE
1334  fout << " channel " << ich << " EE channel " << ich - kEBChannels << " FED " << fed[ich] << " chan " << chan[ich]
1335  << " pedestal " << ped[ich] << " RMS " << pedrms[ich] << std::endl;
1336  }
1337  }
1338  } // debug
1339 
1340  int runold = -1, fillold = -1, firsttimeFEDold = -1;
1341  int firsttimeFED = -1;
1342  bool firstSeqBeforeStable = false;
1343  int transfer = 0;
1344  int first_run_kept = (int)m_firstRun; // m_firstRun is unsigned!
1345  for(int entry = 0; entry < nevents; entry++) {
1346  tree->GetEntry(entry);
1347  if(nxt != kChannels) {
1348  // fout << " entry " << entry << " run " << run << " sequence " << seq_id << " run_time " << run_time
1349  fout << " entry " << entry << " run " << run << " sequence " << seq_id // run_time always 0!
1350  << " *********** Number of channels " << nxt;
1351  // if(seq_id == 0) { corrected Sep 15 2017
1352  fout << " rejected" << std::endl;
1353  continue;
1354  // }
1355  // else fout << std::endl;
1356  }
1357  if(las_id != 447) {
1358  fout << " entry " << entry << " run " << run << " sequence " << seq_id
1359  << " *********** laser wave length = " << las_id << std::endl;
1360  continue;
1361  }
1362  if(bfield < 3.79) {
1363  fout << " entry " << entry << " run " << run << " sequence " << seq_id
1364  << " *********** bfield = " << bfield << std::endl;
1365  // continue; keep these runs
1366  }
1367  fout << " entry "<< entry << " run " << run;
1368  if(run_type == 1) fout << " fill " << fill_num;
1369  fout << " sequence " << seq_id;
1370  if(run_type == 1) {
1371  fout << " stable " << run_time_stablebeam;
1372  if(run_time_stablebeam < first_run_kept) {
1373  fout << " before first wanted " << m_firstRun << std::endl;
1374  continue;
1375  }
1376  }
1377  firsttimeFED = time[0];
1378  for(int ifed = 0; ifed < 54; ifed++) {
1379  if(time[ifed] > firsttimeFEDold && firsttimeFED < time[ifed]) time[ifed] = firsttimeFED; // take the first AFTER the previous sequence one!...
1380  }
1381  if(firsttimeFED < first_run_kept) {
1382  fout << " time " << firsttimeFED << " before first wanted " << m_firstRun << std::endl;
1383  continue;
1384  }
1385  fout << " time " << firsttimeFED << std::endl;
1386  if(firsttimeFED <= firsttimeFEDold) {
1387  std::cout << " Problem finding the IOV : old one " << firsttimeFEDold << " new one " << firsttimeFED << std::endl;
1388  for(int ifed = 0; ifed < 54; ifed++)
1389  std::cout << " " << time[ifed];
1390  std::cout << std::endl << " ignore this entry " << std::endl;
1391  continue;
1392  }
1393  firsttimeFEDold = firsttimeFED;
1394 
1395  // if(run != runold) firstSeqBeforeStable = false;
1396  if(fill_num != fillold) firstSeqBeforeStable = false;
1397  if(run_type == 1) {
1398  if(run_time_stablebeam > 0) {
1399  if(firsttimeFED < run_time_stablebeam) {
1400  fout << " data taken before stable beam, skip it" << std::endl;
1401  firstSeqBeforeStable = true;
1402  runold = run;
1403  fillold = fill_num;
1404  continue;
1405  }
1406  }
1407  else // problem with run_time_stablebeam
1408  fout << " *** entry " << entry << " run_time_stablebeam " << run_time_stablebeam << std::endl;
1409  if(firstSeqBeforeStable) { // this is the first fully filled entry after stable beam
1410  firstSeqBeforeStable = false;
1411  firsttimeFED = run_time_stablebeam;
1412  fout << " first full sequence after stable; change the IOV " << firsttimeFED << std::endl;
1413  }
1414  } // only collision runs
1415 
1416  for(int ich = 0; ich < kChannels; ich++) {
1417  if(ped[ich] < 300 && ped[ich] > 100) {
1418  EAmean12[ich] = ped[ich];
1419  EArms12[ich] = pedrms[ich];
1420  }
1421  }
1422  // get gain 1 and 6 results
1423  bool foundNew = false;
1424  if(run != runold) {
1425  for(int i = run16Index; i < Nbpedxml; i++) {
1426  if(run > pedxml[i]) {
1427  fout << " found a new gain 1, 6 file " << pedxml[i] << " at index " << i << std::endl;
1428  run16Index++;
1429  foundNew = true;
1430  // if(runold < pedxml[i + 1]) break; why runold??
1431  if(run < pedxml[i + 1]) break;
1432  }
1433  }
1434  if(foundNew) {
1435  int Indexxml = run16Index -1;
1436  fout << " opening Pedestals_" << pedxml[Indexxml] << ".xml at index " << Indexxml << std::endl;
1437  std::ifstream fxml;
1438  fxml.open(Form("Pedestals_%i.xml",pedxml[Indexxml]));
1439  if(!fxml.is_open()) {
1440  std::cout << "ERROR : cannot open file Pedestals_" << pedxml[Indexxml] << ".xml" << std::endl;
1441  exit (1);
1442  }
1443  std::string dummyLine, mean12, rms12, bid;
1444  for(int i = 0; i < 9; i++) std::getline(fxml, dummyLine); // skip first lines
1445  // Barrel
1446  for (int iEBChannel = 0; iEBChannel < kEBChannels; iEBChannel++) {
1447  fxml >> mean12 >> rms12 >> bid;
1448  std::string stt = bid.substr(9,15);
1449  std::istringstream m6(stt);
1450  m6 >> EAmean6[iEBChannel];
1451  fxml >> bid;
1452  stt = bid.substr(8,15);
1453  std::istringstream r6(stt);
1454  r6 >> EArms6[iEBChannel];
1455  fxml >> bid;
1456  stt = bid.substr(9,15);
1457  std::istringstream m1(stt);
1458  m1 >> EAmean1[iEBChannel];
1459  fxml >> bid;
1460  stt = bid.substr(8,15);
1461  std::istringstream r1(stt);
1462  r1 >> EArms1[iEBChannel];
1463  if(debug && iEBChannel%10000 == 0) fout << " EB channel " << iEBChannel << " " << mean12 << " " << rms12
1464  << " " << EAmean6[iEBChannel] << " " << EArms6[iEBChannel]
1465  << " " << EAmean1[iEBChannel] << " " << EArms1[iEBChannel] << std::endl;
1466  for(int i = 0; i < 3; i++) std::getline(fxml, dummyLine); // skip lines
1467  }
1468  for(int i = 0; i < 6; i++) std::getline(fxml, dummyLine); // skip lines
1469  for (int iEEChannel = 0; iEEChannel < kEEChannels; iEEChannel++) {
1470  int ich = iEEChannel + kEBChannels;
1471  fxml >> mean12 >> rms12 >> bid;
1472  std::string stt = bid.substr(9,15);
1473  std::istringstream m6(stt);
1474  m6 >> EAmean6[ich];
1475  fxml >> bid;
1476  stt = bid.substr(8,15);
1477  std::istringstream r6(stt);
1478  r6 >> EArms6[ich];
1479  fxml >> bid;
1480  stt = bid.substr(9,15);
1481  std::istringstream m1(stt);
1482  m1 >> EAmean1[ich];
1483  fxml >> bid;
1484  stt = bid.substr(8,15);
1485  std::istringstream r1(stt);
1486  r1 >> EArms1[ich];
1487  if(debug && iEEChannel%1000 == 0)
1488  fout << " EE channel " << iEEChannel << " " << mean12 << " " << rms12
1489  << " " << EAmean6[ich] << " " << EArms6[ich]
1490  << " " << EAmean1[ich] << " " << EArms1[ich] << std::endl;
1491  for(int i = 0; i < 3; i++) std::getline(fxml, dummyLine); // skip lines
1492  }
1493  fxml.close();
1494  } // found a new gain 1 6 file
1495  } // check gain 1 and 6 results only for new runs
1496 
1498  EcalPedestals::Item item;
1499  for(int ich = 0; ich < kChannels; ich++) {
1500  if(debug && ich%10000 == 0) fout << " channel " << ich << " ped " << EAmean12[ich] << " RMS " << EArms12[ich] << std::endl;
1501  //
1502  item.mean_x1 = EAmean1[ich];
1503  item.rms_x1 = EArms1[ich];
1504  item.mean_x6 = EAmean6[ich];
1505  item.rms_x6 = EArms6[ich];
1506  item.mean_x12 = EAmean12[ich];
1507  item.rms_x12 = EArms12[ich];
1508  if(ich < kEBChannels) {
1509  // EBDetId ebdetid(fed, chan, EBDetId::SMCRYSTALMODE);
1510  EBDetId ebdetid = EBDetId::unhashIndex(ich);
1511  pedestal->insert(std::make_pair(ebdetid.rawId(),item));
1512  }
1513  else {
1514  // EEDetId eedetid(iX, iY, iz);
1515  int iChannel = ich - kEBChannels;
1516  EEDetId eedetid = EEDetId::unhashIndex(iChannel);
1517  pedestal->insert(std::make_pair(eedetid.rawId(),item));
1518  }
1519  } // end loop over all channels
1520  uint64_t iov = (uint64_t)firsttimeFED << 32;
1521  Time_t snc = (Time_t) iov;
1522  transfer++;
1523  fout << " entry " << entry << " transfer " << transfer << " iov " << iov << std::endl;
1524  m_to_transfer.push_back(std::make_pair((EcalPedestals*)pedestal, snc)); // time based IOV
1525  fout << " m_to_transfer " << firsttimeFED << std::endl;
1526  runold = run;
1527  fillold = fill_num;
1528  } // end loop over all entries
1529 
1530  std::cout << "Ecal - > end of readPedestalTimestamp -----------\n";
1531 }
bool checkPedestal(EcalPedestals::Item *item)
T getParameter(std::string const &) const
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:70
T getUntrackedParameter(std::string const &, T const &) const
const Int_t kEBChannels
int hashedIndex() const
get a compact index for arrays
Definition: EBDetId.h:86
static const int MIN_IPHI
Definition: EBDetId.h:142
std::string id() const override
Definition: RunTag.h:13
float getPedRMSG1() const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:47
EcalPedestalsHandler(edm::ParameterSet const &)
MonRunList fetchMonRunList(const RunTag &tag, const MonRunTag &monruntag) noexcept(false)
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:99
void setGeneralTag(std::string tag)
Definition: MonRunTag.cc:33
void fetchDataSet(std::map< EcalLogicID, DATT > *fillMap, IOVT *iov) noexcept(false)
static const int IX_MIN
Definition: EEDetId.h:294
static const int IY_MIN
Definition: EEDetId.h:298
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:124
void setRunTag(const RunTag &tag)
Definition: MonRunList.cc:23
int getID2() const
Definition: EcalLogicID.cc:51
cond::ValidityInterval lastInterval
Definition: Types.h:75
std::string getName() const
Definition: EcalLogicID.cc:36
float getPedMeanG12() const
float getPedRMSG12() const
const Int_t kEEChannels
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int getID1() const
Definition: EcalLogicID.cc:46
T min(T a, T b)
Definition: MathUtil.h:58
void setMonVersionDef(const MonVersionDef &ver)
Definition: MonRunTag.cc:49
static const int ETAPHIMODE
Definition: EBDetId.h:166
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:53
void insert(std::pair< uint32_t, Item > const &a)
static const int IX_MAX
Definition: EEDetId.h:302
std::vector< MonRunIOV > getRuns()
Definition: MonRunList.cc:46
EcalPedestalsMap EcalPedestals
Definition: EcalPedestals.h:53
#define debug
Definition: HDRShower.cc:19
int hashedIndex() const
Definition: EEDetId.h:182
static const int MAX_IPHI
Definition: EBDetId.h:144
unsigned long long uint64_t
Definition: Time.h:15
void setRunType(std::string runtype)
Definition: RunTypeDef.cc:33
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
std::vector< Item >::const_iterator const_iterator
static const int MAX_IETA
Definition: EBDetId.h:143
void setMonRunTag(const MonRunTag &tag)
Definition: MonRunList.cc:29
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
float getPedMeanG1() const
void setMonitoringVersion(std::string ver)
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:114
const Int_t Nbpedxml
float getPedMeanG6() const
void setLocation(std::string loc)
Definition: LocationDef.cc:33
static const int IY_MAX
Definition: EEDetId.h:306
const Item & barrel(size_t hashedIndex) const
Definition: tree.py:1
int getID3() const
Definition: EcalLogicID.cc:56
void setGeneralTag(std::string tag)
Definition: RunTag.cc:36
static const int SMCRYSTALMODE
Definition: EBDetId.h:167
const Item & endcap(size_t hashedIndex) const
Definition: RunIOV.h:13
float getPedRMSG6() const
const Int_t kChannels