ATLAS Offline Software
SCTCalib.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
24 #include "SCT_CalibAlgs/SCTCalib.h"
26 
27 #include "SCT_CalibUtilities.h"
28 #include "XmlHeader.h"
29 #include "XmlStreamer.h"
30 
31 //InnerDetector
33 
34 //Gaudi
35 #include "GaudiKernel/IEventProcessor.h"
36 
37 //root
38 #include "TFile.h"
39 #include "TH1I.h"
40 #include "TH2D.h"
41 #include "TF1.h"
42 #include "TProfile.h"
43 #include "TProfile2D.h"
44 #include "Math/ProbFuncMathCore.h"
45 
46 #include <array>
47 #include <cmath>
48 
49 using namespace SCT_CalibAlgs;
50 
51 namespace {
52 enum Bec {ENDCAP_C = -2, BARREL = 0, ENDCAP_A = 2};
53 // String names for the detector parts
54 const std::string shortNames[] = {"EndCapC", "Barrel", "EndCapA"};
55 
56 bool areConsecutiveIntervals(const std::pair<int, int>& i1, const std::pair<int, int>& i2, const int withinLimits) {
57  return i1.second <= (i2.first + withinLimits);
58 }
59 const std::string xmlHeader{"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"};
60 const std::string linefeed{"\n"};
61 std::string
62 associateStylesheet(const std::string& stylesheetName) {
63  return std::string("<?xml-stylesheet type=\"text/xsl\" href=\"")+stylesheetName+"\"?>";
64 }
65 
66 template <class T>
67 std::string
68 xmlPartData(const Bec bec, const int layer, const int eta, const std::string& dataName, const T data) {
69  std::ostringstream os;
70  const std::string thisPart{shortNames[bec2Index(bec)]};
71  os << " <parts>" << std::endl
72  << " " << xmlValue("part", thisPart) << std::endl
73  << " " << xmlValue("layer", layer) << std::endl
74  << " ";
75  std::string barrelEtaXml{xmlValue("eta", "all")};
76  std::string endcapEtaXml{xmlValue("eta", eta)};
77  if (bec==BARREL) os << barrelEtaXml;
78  else os << endcapEtaXml;
79  os << std::endl
80  << " " << xmlValue(dataName, data) << std::endl
81  << " </parts>" << std::endl;
82  return os.str();
83 }
84 
85 template <class T>
86 std::string
87 xmlModuleData(const Bec bec, const int layer, const int side, const int phi, const int eta, const std::string& dataName, const T data, const std::string& serial, const std::string& listOfErrors) {
88  std::ostringstream os;
89  os << " <module>" << std::endl
90  << " " << xmlValue("SN", serial) << std::endl;
91 
92  if (bec==ENDCAP_C) os << " " << xmlValue("barrel_endcap", "-2") << std::endl;
93  else if (bec==BARREL) os << " " << xmlValue("barrel_endcap", "0") << std::endl;
94  else if (bec==ENDCAP_A) os << " " << xmlValue("barrel_endcap", "2") << std::endl;
95  os << " " << xmlValue("layer", layer) << std::endl
96  << " " << xmlValue("side", side) << std::endl
97  << " " << xmlValue("eta", eta) << std::endl
98  << " " << xmlValue("phi", phi) << std::endl
99  << " " << xmlValue(dataName, data) << std::endl;
100  os << listOfErrors;
101  os << " </module>" << std::endl;
102  return os.str();
103 }
104 
105 
106 }
107 
108 
110 // Constructor
112 SCTCalib::SCTCalib(const std::string& name, ISvcLocator* pSvcLocator) :
113  AthAlgorithm(name, pSvcLocator)
114 {
116 }
117 
118 
120 // Initialization
123 
124  ATH_MSG_INFO("----- in initialize() ----- ");
125  if (detStore()->retrieve(m_pSCTHelper, "SCT_ID").isFailure()) {
126  ATH_MSG_ERROR("Unable to retrieve SCTHelper");
127  return StatusCode::FAILURE;
128  }
129 
130  if (not retrievedService(m_pCalibWriteTool)) return StatusCode::FAILURE;
131  if (m_doHV) ATH_MSG_FATAL("Not yet properly implemented and tested!");
132 
133  ATH_CHECK(m_ConfigurationConditionsTool.retrieve(EnableTool {m_useConfiguration}));
134 
135  if (not m_useCalibration) {
136  ATH_MSG_DEBUG("ReadCalibDataTool was removed in initialization");
137  m_ReadCalibDataTool.disable();
138  } else {
139  if (m_ReadCalibDataTool.retrieve().isFailure()) return StatusCode::FAILURE;
140  }
141 
142  if (not m_useMajority) {
143  ATH_MSG_DEBUG("MajorityConditionsTool was removed in initialization");
144  } else {
145  if (m_MajorityConditionsTool.retrieve().isFailure()) return StatusCode::FAILURE;
146  }
147 
148  if (not retrievedService(m_calibHitmapTool)) return StatusCode::FAILURE;
149 
150  if (not retrievedService(m_calibModuleListTool)) return StatusCode::FAILURE;
151 
152  if (not retrievedService(m_calibEvtInfoTool)) return StatusCode::FAILURE;
153 
154  if (not m_useBSError) {
155  ATH_MSG_DEBUG("ByteStreamErrorsSvc was removed in initialization");
156  } else {
157  if (not retrievedService(m_calibBsErrTool)) return StatusCode::FAILURE;
158  }
159  if (not retrievedService(m_calibLbTool)) return StatusCode::FAILURE;
160 
161  ATH_CHECK(m_CablingTool.retrieve());
163 
164  //--- LB range
165  try {
166  m_LBRange = std::stoi(m_LBMax);
167  m_calibHitmapTool->setNumberOfLb(m_LBRange);
168  m_calibLbTool->setNumberOfLb(m_LBRange);
169  m_calibBsErrTool->setNumberOfLb(m_LBRange);
170  } catch (...) {
171  ATH_MSG_ERROR("Couldn't cast m_LBMax=\"" << m_LBMax << "\" to m_LBRange...");
172  m_LBRange = 0;
173  }
174 
175  m_calibHitmapTool->setLbToMerge(m_nLbsMerged);
176  m_calibLbTool->setLbToMerge(m_nLbsMerged);
177  m_calibBsErrTool->setLbToMerge(m_nLbsMerged);
178 
180 
181  if (m_readBS and m_readHIST) {
182  ATH_MSG_ERROR("Both BS and HIST are set to be read. Choose either of BS or HIST.");
183  return StatusCode::FAILURE;
184  }
185 
186  //--- Open BS
187  if (m_readBS) {
188  ATH_MSG_INFO("------------> Reading from ByteStream <-------------");
189  m_calibEvtInfoTool->setSource("BS");
190  }
191 
192  //--- Open HIST
193  if (m_readHIST) {
194  ATH_MSG_INFO("------------> Reading from HIST <-------------");
195  m_calibEvtInfoTool->setSource("HIST");
196  //--- List of HIST
197  std::string hist{""};
198  std::vector<std::string> histCollection{m_input_hist.value()};
199  ATH_MSG_INFO("The input histogram name is : " << m_input_hist);
200  if (not histCollection.empty()) {
201  hist=histCollection.back();
202  if (histCollection.size() > 1) ATH_MSG_WARNING("The Histogram collection contains more than one histogram; using the last one.");
203  } else {
204  ATH_MSG_ERROR("The input histogram collection property is empty");
205  return StatusCode::FAILURE;
206  }
207 
208  //in case of DeadStrip or DeadChip, change open from EOS to
209  //copy and open locally. Delete the file after processing
210  m_inputHist = TFile::Open(hist.c_str());
211 
212  ATH_MSG_INFO("opening HIST file : " << hist.c_str());
213 
214  if (m_inputHist) {
215  //--- Check run number
216  const std::string os{std::to_string(m_runNumber.value())};
217  ATH_MSG_INFO("Getting HIST directory : " << m_runNumber.value());
218  if (not m_inputHist->GetDirectory("/run_"+TString{os})) {
219  ATH_MSG_ERROR("RunNumber in HIST is inconsistent with jobO : " << os);
220  return StatusCode::FAILURE ;
221  }
222  ATH_MSG_INFO("Getting Number of events: " << m_calibEvtInfoTool->counter());
223  //--- Read number of events : Previously from entry of "tier0ESD" in "/GLOBAL/DQTDataFlow/events_lb"
224  std::string osHist{std::string{"/run_"} + std::to_string(m_runNumber.value())+"/SCT/GENERAL/Conf/NumberOfEventsVsLB"};
225  TH1F* hist_events{dynamic_cast<TH1F*>(m_inputHist->Get(osHist.c_str()))};
226  m_numberOfEventsHist = hist_events->GetEntries();
227  } else {
228  ATH_MSG_WARNING("can not open HIST : " << hist.c_str());
229  }
230 
231 
232  ATH_MSG_INFO("Initialization of TimeStamp/LB, taken from runInfo.txt");
233  //--- Initialization of TimeStamp/LB, taken from runInfo.txt
234  m_calibEvtInfoTool->setSource("HIST");
236  m_calibEvtInfoTool->setRunNumber(m_runNumber);
237  m_calibEvtInfoTool->setEventNumber(m_eventNumber);
238  }
239 
240  //--- Booking histograms for hitmaps
241  if (m_doHitMaps) m_calibHitmapTool->book();
242  //--- Booking histograms for BSErrors
243  if (m_doHitMaps and m_doBSErrors) m_calibBsErrTool->book();
244 
245  //--- Reading histograms for hitmaps
246  if ((not m_doHitMaps and not m_doHitMapsLB) and m_readHitMaps) {
247  ATH_MSG_INFO("Set CalibEventInfo for m_readHitMaps == true");
248  m_calibEvtInfoTool->setSource("HIST");
249  m_calibHitmapTool->read("./SCTHitMaps.root");
252  m_calibEvtInfoTool->setRunNumber(m_runNumber);
253  m_calibEvtInfoTool->setEventNumber(m_eventNumber);
254  if (m_doNoisyStrip) {
255  m_calibLbTool->read("./SCTLB.root");
256  }
257  if (m_doBSErrors) {
258  m_calibBsErrTool->read("./SCTBSErrors.root");
259  }
260  }
261  //--- Hit-vs-LB for LBs in noisy links/chips
262  if (m_doHitMapsLB) m_calibLbTool->book();
263 
264  //--- Check statistics for NoiseOccupancy
266  //--- Check statistics for RawOccupancy
268  //--- Check statistics for Efficiency
269  if (m_doEfficiency and notEnoughStatistics(m_efficiencyMinStat, m_numberOfEventsHist)) return StatusCode::FAILURE;
270  //--- Check statistics for BSError
271  if (m_doBSErrorDB and notEnoughStatistics(m_BSErrorDBMinStat, m_numberOfEventsHist)) return StatusCode::FAILURE;
272  //--- Check statistics for LorentzAngle
274  //
275 
276  ATH_MSG_INFO("----- end of initialize() ----- ");
277  return StatusCode::SUCCESS;
278 }
279 
280 
281 bool
282 SCTCalib::notEnoughStatistics(const int required, const int obtained, const std::string& histogramName) const {
283  if (obtained<required) {
284  ATH_MSG_ERROR("Number of events in " << histogramName << ": " << obtained << " is less than the required minimum number of events " << required);
285  return true;
286  }
287  return false;
288 }
289 
290 
292 // Execute - on event by event
295 
296  ATH_MSG_DEBUG("----- in execute() ----- ");
297 
298  const bool majorityIsGoodOrUnused{(m_useMajority and m_MajorityConditionsTool->isGood()) or !m_useMajority};
299  if (m_readBS) {
300  //--- TimeStamp/LB range analyzed
301  const EventContext& ctx = Gaudi::Hive::currentContext();
302  const int timeStamp{static_cast<int>(ctx.eventID().time_stamp())};
303  const int lumiBlock{static_cast<int>(ctx.eventID().lumi_block())};
304  int timeStampBeginOld;
305  int timeStampEndOld;
306  m_calibEvtInfoTool->getTimeStamps(timeStampBeginOld, timeStampEndOld);
307  m_calibEvtInfoTool->setTimeStamp(std::min(timeStamp, timeStampBeginOld), std::max(timeStamp, timeStampEndOld));
308  int lbBeginOld;
309  int lbEndOld;
310  m_calibEvtInfoTool->getLumiBlock(lbBeginOld, lbEndOld);
311  m_calibEvtInfoTool->setLumiBlock(std::min(lumiBlock, lbBeginOld), std::max(lumiBlock, lbEndOld));
312  m_calibEvtInfoTool->setLumiBlock(lumiBlock);
313  m_calibEvtInfoTool->setTimeStamp(timeStamp);
314  if (m_doHitMapsLB and majorityIsGoodOrUnused) {
315  m_calibLbTool->setLb(ctx.eventID().lumi_block());
316  }
317  }
318 
319  //--- Fill histograms for (1) Number of events and (2) Hitmaps
320  if (m_doHitMaps and majorityIsGoodOrUnused) m_calibHitmapTool->fill(m_readBS);
321 
322  //--- Fill histograms for (1) Number of events and (2) Hits as a function of LB
323  if (m_doHitMapsLB and majorityIsGoodOrUnused) {
324  m_calibLbTool->fill(m_readBS);
325  }
326 
327  //--- Fill histograms for (1) Number of events and (2) BSErrors
329 
330  //--- Increment event counter : to be ready for the next event loop
331  m_calibEvtInfoTool->incrementCounter();
332 
333  ATH_MSG_DEBUG("----- end of execute() ----- ");
334 
335  return StatusCode::SUCCESS;
336 }
337 
338 
342 StatusCode SCTCalib::stop ATLAS_NOT_THREAD_SAFE () { // Thread unsafe getNoisyStrip, getDeadStrip, getNoiseOccupancy, getRawOccupancy, getEfficiency, getBSErrors, getLorentzAngle methods are used.
343  ATH_MSG_INFO("----- in stop() ----- ");
344  //--- Number of events processed
345  m_numberOfEvents = (m_readHIST or (!m_doHitMaps and m_readHitMaps)) ? m_numberOfEventsHist : m_calibEvtInfoTool->counter();
346  m_calibEvtInfoTool->getTimeStamps(m_utcBegin, m_utcEnd);
347 
348  //--- IOV range defined by RunNumber and LB
349  unsigned int beginRun{static_cast<unsigned int>(m_runNumber.value())};
350  unsigned int endRun{static_cast<unsigned int>(m_runNumber.value())};
351  unsigned int beginLB{IOVTime::MINEVENT};
352  unsigned int endLB{IOVTime::MAXEVENT};
353  m_iovStart.setRunEvent(static_cast<unsigned long>(beginRun), static_cast<unsigned long>(beginLB));
354  m_iovStop.setRunEvent(static_cast<unsigned long>(endRun), static_cast<unsigned long>(endLB));
355 
356  //--- Find noisy strips from hitmaps
357  const bool doNoisyStripAnalysis{((!m_doHitMaps and m_readHitMaps) or !m_readHitMaps) and m_doNoisyStrip};
358  if (doNoisyStripAnalysis) {
359  if (getNoisyStrip().isFailure()) {
360  ATH_MSG_ERROR("Failed to run getNoisyStrip()");
361  return StatusCode::FAILURE;
362  }
363  }
364 
365  //--- Upload hv
366  if (m_doHV) {
367  m_gofile.open(m_badModulesFile.value().c_str(), std::ios::out);
368  if (not m_gofile) ATH_MSG_ERROR("Problem opening " << m_badModulesFile);
369  //
370  XmlHeader myXml{m_gofile};
371  XmlStreamer root{"modules", m_gofile};
372  SCT_ID::const_id_iterator waferItr{m_pSCTHelper->wafer_begin()};
373  SCT_ID::const_id_iterator waferItrE{m_pSCTHelper->wafer_end()};
374  const unsigned int onlyDummy{1};
375  std::pair<int, int> timeInterval{0, 0};
376  std::pair<int, int> lbRange{0, 0};
377  const int withinLimits{m_maxtbins};
378  //
379  for (; waferItr not_eq waferItrE; ++waferItr) {
380  const Identifier waferId{*waferItr};
381  IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
382  const std::vector<std::pair<int, int>>& tvec{m_summarytrips.at(waferHash.value())};
383  const std::vector<std::pair<int, int>>& tlbn{m_summarytripslb.at(waferHash.value())};
384  //tvec is a pair of times in general, although the very first one is a dummy
385  const unsigned int numberOfElements{static_cast<unsigned int>(tvec.size())};
386  if (numberOfElements > onlyDummy) {
387  //only care if something happened in this module
388  timeInterval=tvec.at(1);
389  lbRange=tlbn.at(1);
390  for (unsigned int itrip{2}; itrip != numberOfElements; ++itrip) { //skip 0 since that is just the dummy pair.
391  if (areConsecutiveIntervals(tvec[itrip], timeInterval, withinLimits)) {
392  timeInterval.second = tvec.at(itrip).second;
393  lbRange.second = tlbn.at(itrip).second;
394  } else {
395  //not consecutive, so first print out the old one
396  doHVPrintXML(timeInterval, lbRange, waferId);
397  timeInterval = tvec.at(itrip);
398  lbRange = tlbn.at(itrip);
399  }
400  } // end loop over times
401  doHVPrintXML(timeInterval, lbRange, waferId);
402  }
403  } // end loop over wafers
404  }
405 
406  //--- Find dead strips/chips from hitmaps
407  if ((m_doDeadStrip or m_doDeadChip) and getDeadStrip().isFailure()) {
408  ATH_MSG_ERROR("Failed to run getDeadStrip()");
409  return StatusCode::FAILURE;
410  }
411 
412  //--- Upload noise occupancy
413  if (m_doNoiseOccupancy and getNoiseOccupancy().isFailure()) {
414  ATH_MSG_ERROR("Failed to run getNoiseOccupancy()");
415  return StatusCode::FAILURE;
416  }
417 
418  //--- Upload raw occupancy
419  if (m_doRawOccupancy and getRawOccupancy().isFailure()) {
420  ATH_MSG_ERROR("Failed to run getRawOccupancy()");
421  return StatusCode::FAILURE;
422  }
423 
424  //--- Upload efficiency
425  if (m_doEfficiency and getEfficiency().isFailure()) {
426  ATH_MSG_ERROR("Failed to run getEfficiency()");
427  return StatusCode::FAILURE;
428  }
429 
430  //--- Upload ByteStream Errors
431  if (m_doBSErrorDB and getBSErrors().isFailure()) {
432  ATH_MSG_ERROR("Failed to run getBSErrors()");
433  return StatusCode::FAILURE;
434  }
435 
436  //--- Upload Lorentz Angle
437  if (m_doLorentzAngle and getLorentzAngle().isFailure()) {
438  ATH_MSG_ERROR("Failed to run getLorentzAngle()");
439  return StatusCode::FAILURE;
440  }
441 
442  //--- Close HIST
443  if (m_readHIST) m_inputHist->Close();
444 
445  return StatusCode::SUCCESS;
446 }
447 
448 
453  ATH_MSG_INFO("----- in finalize() ----- ");
454 
455  if (m_writeToCool) {
456  if (!m_pCalibWriteTool.release().isSuccess()) {
457  ATH_MSG_ERROR("Failed to release m_pCalibWriteTool");
458  return StatusCode::FAILURE;
459  }
460  }
461 
462  return StatusCode::SUCCESS;
463 }
464 
465 
470 void SCTCalib::doHVPrintXML(const std::pair<int, int>& timeInterval, const std::pair<int, int>& lbRange, Identifier waferId) {
471  const IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
472  const SCT_SerialNumber sn{m_CablingTool->getSerialNumberFromHash(waferHash)};
473 
474  XmlStreamer mod{"module", m_gofile};
475  {
476  XmlStreamer v{"value", "name", "SN", m_gofile};
477  m_gofile << sn.str();
478  }
479  {
480  XmlStreamer v{"value", "name", "BecLayerPhiEta", m_gofile};
481  m_gofile << formatPosition(waferId, m_pSCTHelper, ".", false);
482  }
483  {
484  XmlStreamer v{"value", "name", "StartTime", m_gofile};
485  m_gofile << timeInterval.first;
486  }
487  {
488  XmlStreamer v{"value", "name", "EndTime", m_gofile};
489  m_gofile << timeInterval.second;
490  }
491  {
492  XmlStreamer v{"value", "name", "StartLBN", m_gofile};
493  m_gofile << lbRange.first;
494  }
495  {
496  XmlStreamer v{"value", "name", "EndLBN", m_gofile};
497  m_gofile << lbRange.second;
498  }
499 }
500 
501 
506 StatusCode SCTCalib::getNoisyStrip ATLAS_NOT_THREAD_SAFE () { // Thread unsafe writeModuleListToCool method is used.
507  enum Categories {ALL, NEW, REF, N_CATEGORIES};
508 
509 
510  ATH_MSG_INFO("----- in getNoisyStrip() ----- ");
511 
512  //--- Number of LBs processed
513  m_numOfLBsProcessed = 0;
514  for (int iLB{0}; iLB != m_LBRange; ++iLB) {
515  if (m_calibLbTool and m_calibLbTool->getNumberOfEventsInBin(iLB + 1) > 0) ++m_numOfLBsProcessed;
516  }
517 
518  //--- Choice of threshold
519  //three module lists: all, new, ref
520  using ModuleList_t = std::map<Identifier, std::set<Identifier>>;
521  ModuleList_t moduleLists[N_CATEGORIES];
522  //Reading data from COOL
523  // original code switched on this :if (m_noisyUpdate)
524  ATH_MSG_DEBUG("in getNoisyStrips: before readModuleList");
525  if (m_calibModuleListTool->readModuleList(moduleLists[REF]).isFailure()) {
526  ATH_MSG_ERROR("Could not read moduleList");
527  return StatusCode::FAILURE;
528  }
529 
530  //two bad strip lists: all, new
531  using StripList_t = std::set<Identifier>;
532  StripList_t stripIdLists[2];
533 
534  //--- Loop over wafers
535  SCT_ID::const_id_iterator waferItr{m_pSCTHelper->wafer_begin()};
536  SCT_ID::const_id_iterator waferItrE{m_pSCTHelper->wafer_end()};
537  for (; waferItr not_eq waferItrE; ++waferItr) {
538  //--- Identifier/SN
539  Identifier waferId{*waferItr};
540  Identifier moduleId{m_pSCTHelper->module_id(waferId)};
541  //--- Initialization in *module*
542  if (m_pSCTHelper->side(waferId) == 0) {
543  stripIdLists[ALL].clear();
544  stripIdLists[NEW].clear();
545  }
546  std::pair<int, bool> noisy{getNumNoisyStrips(waferId)};
547  const int numNoisyStripsInWafer{noisy.first};
548  const bool isNoisyWafer{noisy.second};
549  if (numNoisyStripsInWafer!=0 || m_noisyWriteAllModules) {
550  if (m_noisyWaferFinder and isNoisyWafer) { //in noisy wafer
551 
552  if (not m_noisyWaferWrite) break;
553  if (m_noisyWaferAllStrips) { //write out all strips
554  if (addStripsToList(waferId, stripIdLists[ALL], false, false).isFailure() or addStripsToList(waferId, stripIdLists[NEW], false, true).isFailure()) {
555  ATH_MSG_ERROR("Could not add stripIds to the list");
556  return StatusCode::FAILURE;
557  }
558  break;
559  } else {
560  //only noisy strips in noisy wafer
561  if (addStripsToList(waferId, stripIdLists[ALL], true, false).isFailure() or addStripsToList(waferId, stripIdLists[NEW], true, true).isFailure()) {
562  ATH_MSG_ERROR("Could not add stripIds to the list");
563  return StatusCode::FAILURE;
564  }
565  }
566  } else { // not in noisy wafer
567  if (addStripsToList(waferId, stripIdLists[ALL], true, false).isFailure() or addStripsToList(waferId, stripIdLists[NEW], true, true).isFailure()) {
568  ATH_MSG_ERROR("Could not add stripIds to the list");
569  return StatusCode::FAILURE;
570  }
571  }
572  }//endif numnoisystrips!=0
573  //--- Create objects for a module
574  if (m_pSCTHelper->side(waferId) == 1) {
575  if (!stripIdLists[ALL].empty()) moduleLists[ALL].insert(std::map< Identifier, std::set<Identifier> >::value_type(moduleId, stripIdLists[ALL]));
576  if (!stripIdLists[NEW].empty()) moduleLists[NEW].insert(std::map< Identifier, std::set<Identifier> >::value_type(moduleId, stripIdLists[NEW]));
577  }
578  }//end loop over wafers
579 
580  //--- Local sqlite files here
581  ATH_MSG_DEBUG("------ Before writing into COOL ------");
582  if (m_writeToCool) {
583  if (writeModuleListToCool(moduleLists[ALL], moduleLists[NEW], moduleLists[REF]).isFailure()) {
584  ATH_MSG_ERROR("Could not write NoisyStrips into COOL");
585  return StatusCode::FAILURE;
586  }
587  }
588  //--- XML outputs
589  if (noisyStripsToXml(moduleLists[ALL], m_badStripsAllFile).isFailure()) {
590  ATH_MSG_ERROR("Could not write XML file");
591  return StatusCode::FAILURE;
592  }
593  if (noisyStripsToXml(moduleLists[NEW], m_badStripsNewFile).isFailure()) {
594  ATH_MSG_ERROR("Could not write XML file");
595  return StatusCode::FAILURE;
596  }
597  //if (noisyStripsToSummaryXml(moduleLists[ALL], moduleLists[NEW], moduleLists[REF], m_badStripsSummaryFile).isFailure()) {
598  if (noisyStripsToSummaryXml(moduleLists[ALL], moduleLists[REF], m_badStripsSummaryFile).isFailure()) {
599  ATH_MSG_ERROR("Could not write XML file");
600  return StatusCode::FAILURE;
601  }
602 
603  return StatusCode::SUCCESS;
604 }
605 
606 
607 //====================================================================================================
608 // SCTCalib :: getDeadStrip
609 //====================================================================================================
610 StatusCode SCTCalib::getDeadStrip ATLAS_NOT_THREAD_SAFE () { // Thread unsafe SCTCalibWriteTool::createListStrip, SCTCalibWriteTool::createListChip methods are used.
611  //Function to identify and print out the dead strips.
612  ATH_MSG_INFO("getDeadStrip() called");
613 
614  // Bad Mods
615  const std::set<Identifier>* badMods{m_ConfigurationConditionsTool->badModules()};
616  std::set<Identifier>::const_iterator ModItr{badMods->begin()};
617  std::set<Identifier>::const_iterator ModEnd{badMods->end()};
618  // Bad links
619  const std::map<IdentifierHash, std::pair<bool, bool> >* badLinks{m_ConfigurationConditionsTool->badLinks()};
620  std::map<IdentifierHash, std::pair<bool, bool> >::const_iterator linkItr{badLinks->begin()};
621  std::map<IdentifierHash, std::pair<bool, bool> >::const_iterator linkEnd{badLinks->end()};
622  // Bad chips
623  const std::map<Identifier, unsigned int>* badChips{m_ConfigurationConditionsTool->badChips()};
624  std::map<Identifier, unsigned int>::const_iterator chipItr{badChips->begin()};
625  std::map<Identifier, unsigned int>::const_iterator chipEnd{badChips->end()};
626  // Bad strips (w/o bad modules and chips)
627  std::set<Identifier> badStripsExclusive;
628  m_ConfigurationConditionsTool->badStrips(badStripsExclusive, true, true);
629  std::set<Identifier>::const_iterator stripEnd(badStripsExclusive.end());
630  //To get #(Enabled Modules)
631  int numEnabledModules_B[n_barrels] = {n_phiBinsB0*n_etaInBarrel, n_phiBinsB1*n_etaInBarrel, n_phiBinsB2*n_etaInBarrel, n_phiBinsB3*n_etaInBarrel};
632  int numEnabledModules_EC[n_disks][n_etaBinsEC] = {{0}, {0}};
633  for (int i{0}; i<n_disks; i++) {
634  for (int j{0}; j<n_etaBinsEC; j++) {
635  if (!((i==0 and j==2) or (i==6 and j==2) or (i==7 and j==2) or (i==8 and j==1) or (i==8 and j==2))) {
636  numEnabledModules_EC[i][j] = j==0 ? n_phiBinsECOuter*2 : n_phiBinsECMiddle*2;
637  }
638  }
639  }
640  for (; ModItr!=ModEnd; ++ModItr) {
641  Identifier moduleId{*ModItr};
642  if (m_pSCTHelper->barrel_ec(moduleId)==BARREL) numEnabledModules_B[m_pSCTHelper->layer_disk(moduleId)]--;
643  else numEnabledModules_EC[m_pSCTHelper->layer_disk(moduleId)][m_pSCTHelper->eta_module(moduleId)]--;
644  }
645  //calculate meanOccupancy of layer etc...
646  double meanOccupancy_Barrel[n_barrels] = {0};
647  double meanOccupancy_EC[n_disks][n_etaBinsEC] = {{0}, {0}};
648  SCT_ID::const_id_iterator waferItr{m_pSCTHelper->wafer_begin()};
649  SCT_ID::const_id_iterator waferItrE{m_pSCTHelper->wafer_end()};
650  for (; waferItr != waferItrE; ++waferItr) {
651  Identifier waferId{*waferItr};
652  IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
653  for (int j{0}; j<n_stripPerChip*n_chipPerSide; j++) {
654  double n_hits{m_calibHitmapTool->getBinForHistogramIndex(j+1, waferHash.value())};
655  if (n_hits/m_numberOfEvents<m_noisyThr4DeadFinding) {
656  if (m_pSCTHelper->barrel_ec(waferId)==BARREL) {
657  meanOccupancy_Barrel[m_pSCTHelper->layer_disk(waferId)]+=m_calibHitmapTool->getBinForHistogramIndex(j+1, waferHash.value());
658  } else {
659  meanOccupancy_EC[m_pSCTHelper->layer_disk(waferId)][m_pSCTHelper->eta_module(waferId)]+=m_calibHitmapTool->getBinForHistogramIndex(j+1, waferHash.value());
660  }
661  }
662  }
663  }
664 
665  for (int i{0}; i<n_barrels; i++) {
666  meanOccupancy_Barrel[i]/=static_cast<double>(m_numberOfEvents*nbins*2*numEnabledModules_B[i]);
667  ATH_MSG_INFO("Barrel : layer=" << i << ", meanOccupancy=" << meanOccupancy_Barrel[i] << ", nbins:" << nbins << ", #enabledModule=" << numEnabledModules_B[i]);
668  }
669 
670  for (int i{0}; i<n_disks; i++) {
671  for (int j{0}; j<n_etaBinsEC; j++) {
672  if (numEnabledModules_EC[i][j]!=0) {
673  meanOccupancy_EC[i][j]/=static_cast<double>(m_numberOfEvents*nbins*2*numEnabledModules_EC[i][j]);
674  ATH_MSG_INFO("EndCap : disk=" << i << ", eta=" << j << ", meanOccupancy=" << meanOccupancy_EC[i][j] << ", #enabledModule=" << numEnabledModules_EC[i][j]);
675  }
676  }
677  }
678  bool busyStream{meanOccupancy_Barrel[3]>m_busyThr4DeadFinding ? true : false};
679  unsigned int minStat{busyStream ? static_cast<unsigned int>(m_deadStripMinStatBusy) : static_cast<unsigned int>(m_deadStripMinStat)};
680  if (m_doDeadStrip and m_numberOfEvents<minStat) {
681  ATH_MSG_WARNING("required minimum statistics is " << minStat/1E3 << "k events for DeadStrip search with this stream");
682  m_doDeadStrip = true; // CS: do it anyway
683  }
684  if (m_doDeadChip and m_numberOfEvents<m_deadChipMinStat) {
685  ATH_MSG_WARNING("required minimum statistics is " << static_cast<unsigned int>(m_deadChipMinStat) << " events for DeadChip search");
686  m_doDeadChip = true; // CS: do it anyway
687  }
688  if (m_doDeadStrip==false and m_doDeadChip==false) {
689  ATH_MSG_ERROR("Number of events " << m_numberOfEvents << " is less than the required minimum number of events... exit getDeadStrip()");
690  return StatusCode::FAILURE;
691  }
692  //create XML files
693  if (m_doDeadStrip) {
694  if (openXML4DB(m_outDeadStrips, "DeadStrip", m_tagID4DeadStrips.value().c_str(), m_iovStart, m_iovStop).isFailure()) {
695  ATH_MSG_ERROR("Problem opening " << m_deadStripsFile);
696  return StatusCode::FAILURE;
697  }
698  }
699  if (m_doDeadChip) {
700  if (openXML4DB(m_outDeadChips, "DeadChip", m_tagID4DeadChips.value().c_str(), m_iovStart, m_iovStop).isFailure()) {
701  ATH_MSG_ERROR("Problem opening " << m_deadChipsFile);
702  return StatusCode::FAILURE;
703  }
704  }
705 
706  // Get SCT_DetectorElementCollection
707  SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> sctDetEle{m_SCTDetEleCollKey};
708  const InDetDD::SiDetectorElementCollection* elements{sctDetEle.retrieve()};
709  if (elements==nullptr) {
710  ATH_MSG_FATAL(m_SCTDetEleCollKey.fullKey() << " could not be retrieved");
711  return StatusCode::FAILURE;
712  }
713 
714  //Dead identification
715  bool hasDeadStrip{false};
716  bool hasDeadChip{false};
717  bool isNoHitLink{false};
718  bool isDead{false};
719  bool beforeIsDead{false};
720  int n_deadStrip{0};
721  int n_deadChip{0};
722  int n_deadLink{0};
723  int n_deadModule{0};
724  int n_checkedChip{0};
725  int beginDead{0};
726  int endDead{0};
727  std::string defectStrip;
728  std::string defectChip;
729  std::ostringstream summaryList;
730  defectStrip.erase();
731  defectChip.erase();
732  const double deadStripDefinition{ROOT::Math::gaussian_cdf_c(m_deadStripSignificance)};
733  const double deadChipDefinition{ROOT::Math::gaussian_cdf_c(m_deadChipSignificance)};
734 
735  //--- Loop over wafers
736  waferItr = m_pSCTHelper->wafer_begin();
737  for (; waferItr != waferItrE; ++waferItr) {
738  Identifier waferId{*waferItr};
739  Identifier moduleId{m_pSCTHelper->module_id(waferId)};
740  IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
741 
742  bool disabledChip[n_chipPerModule] = {false};
743  unsigned int disabledChipFlag=0;
744  double numHitsInStrip[n_stripPerChip*n_chipPerSide] = {0};
745  double numHitsInChip[n_chipPerSide] = {0};
746  double totalHitsInWafer{0};
747  int n_noisyStrip{0};
748  int n_noHitsStrip{0};
749  int n_disabledStrip{0};
750  int n_disabledInChip[n_chipPerSide] = {0};
751 
752  //initialize
753  int side{m_pSCTHelper->side(waferId)};
754  if (side==0) {
755  isDead=false;
756  beforeIsDead=false;
757  beginDead=0;
758  endDead=0;
759  defectStrip.erase();
760  defectChip.erase();
761  }
762 
763  //check if module/link is disabled or not
764  bool disabled{false};
765  if (badMods->find(moduleId)!=badMods->end()) disabled=true;
766  linkItr=badLinks->find(waferHash);
767  if (linkItr!=linkEnd) {
768  std::pair<bool, bool> status{(*linkItr).second};
769  if ((side==0 and status.first==true) or (side==1 and status.second==true)) disabled=true;
770  }
771 
772  //check BS Error
773  bool hasBSError{false};
774  if (m_calibBsErrTool->size(waferHash.value())>0) hasBSError=true;
775  if (disabled or hasBSError) { //goto WRITE_DB; //<-- who ever put this in should be shot; http://xkcd.com/292/
776  if (side==1) {
777  //write to DB & .xml.
778  if (defectChip==" 0-5 6-11 ") {
779  n_deadModule++;
780  } else if (defectChip==" 0-5 " or defectChip==" 6-11 ") {
781  n_deadLink++;
782  }
783 
784  if (!(defectStrip.empty()) or !(defectChip.empty())) {
785  if (addToSummaryStr(summaryList, waferId, "DEAD", defectStrip.c_str(), defectChip.c_str()).isFailure()) {
786  ATH_MSG_ERROR("Could not add dead strips to the summary");
787  return StatusCode::FAILURE;
788  }
789  }
790 
791  if (!(defectStrip.empty())) {
793  double threshold = m_deadStripSignificance;
794  if (!m_deadNotQuiet) threshold = m_quietThresholdStrip;
795  if (m_writeToCool) {
796  if (m_pCalibWriteTool->createListStrip(moduleId, m_pSCTHelper, 10000, "DEAD", threshold, defectStrip).isFailure()) {
797  ATH_MSG_ERROR("Could not create list");
798  return StatusCode::FAILURE;
799  }
800  }
801  if (addToXML4DB(m_outDeadStrips, waferId, "DEAD", threshold, defectStrip.c_str()).isFailure()) {
802  ATH_MSG_ERROR("Could not add dead strips to the summary");
803  return StatusCode::FAILURE;
804  }
805 
806  hasDeadStrip=true;
807  }
808 
809  if (!(defectChip.empty())) {
811  double threshold = m_deadChipSignificance;
812  if (!m_deadNotQuiet) threshold = m_quietThresholdChip;
813  if (m_writeToCool) {
814  if (m_pCalibWriteTool->createListChip(moduleId, m_pSCTHelper, 10000, "DEAD", threshold, defectChip).isFailure()) {
815  ATH_MSG_ERROR("Could not create list");
816  return StatusCode::FAILURE;
817  }
818  }
819 
820  if (addToXML4DB(m_outDeadChips, waferId, "DEAD", threshold, defectChip.c_str()).isFailure()) {
821  ATH_MSG_ERROR("Could not add dead chips to the summary");
822  return StatusCode::FAILURE;
823  }
824 
825  hasDeadChip=true;
826 
827  }
828  }
829  continue;
830  }
831  //retrieving info of chip status
832  chipItr=badChips->find(moduleId);
833  if (chipItr!=chipEnd) disabledChipFlag = (*chipItr).second;
834  for (unsigned int i{0}; i<n_chipPerModule; i++) {
835  disabledChip[i] = ((disabledChipFlag & (1 << i)) != 0);
836  }
837 
838  //retrieving #hits in each strip
839  for (int j=0; j<n_stripPerChip*n_chipPerSide; j++) {
840  const InDetDD::SiDetectorElement* pElement{elements->getDetectorElement(waferHash)};
841  bool swap{(pElement->swapPhiReadoutDirection()) ? true : false};
842  int chipNum{0};
843  if (side==0) chipNum = swap ? 5-j/n_stripPerChip : j/n_stripPerChip;
844  else chipNum = swap ? 11-j/n_stripPerChip : 6+j/n_stripPerChip;
845  int stripNum{swap ? 767-j : j};
846  Identifier stripId{m_pSCTHelper->strip_id(waferId, j)};
847 
848  numHitsInStrip[stripNum] = m_calibHitmapTool->getBinForHistogramIndex(j+1, waferHash.value());
849  bool misMatch{false};
850  double n_hitsInDisable{numHitsInStrip[stripNum]};
851  if (((disabledChipFlag & (1 << chipNum))!=0) or badStripsExclusive.find(stripId)!=stripEnd) {
852  if (numHitsInStrip[stripNum]!=0) misMatch = true;
853  numHitsInStrip[stripNum] = -99;
854  }
855  if (misMatch) {
856  ATH_MSG_WARNING("hits in disabled Strip : "
857  << "n_hits=" << n_hitsInDisable << ", "
858  << "bec=" << m_pSCTHelper->barrel_ec(stripId) << ", "
859  << "layer=" << m_pSCTHelper->layer_disk(stripId) << ", "
860  << "phi=" << m_pSCTHelper->phi_module(stripId) << ", "
861  << "eta=" << m_pSCTHelper->eta_module(stripId) << ", "
862  << "side=" << m_pSCTHelper->side(stripId) << ", "
863  << "strip=" << m_pSCTHelper->strip(stripId));
864  }
865 
866  if (numHitsInStrip[stripNum]==0) {
867  n_noHitsStrip++;
868  ATH_MSG_DEBUG("nohit strip : barrel_ec=" << m_pSCTHelper->barrel_ec(stripId)
869  << ", layer=" << m_pSCTHelper->layer_disk(stripId) << ", phi=" << m_pSCTHelper->phi_module(stripId)
870  << ", eta=" << m_pSCTHelper->eta_module(stripId) << ", side=" << m_pSCTHelper->side(stripId)
871  << ", strip=offline" << m_pSCTHelper->strip(stripId));
872  } else if (numHitsInStrip[stripNum]==-99) {
873  n_disabledStrip++;
874  n_disabledInChip[stripNum/n_stripPerChip]++;
875  ATH_MSG_DEBUG("disabled strip : barrel_ec=" << m_pSCTHelper->barrel_ec(stripId)
876  << ", layer=" << m_pSCTHelper->layer_disk(stripId) << ", phi=" << m_pSCTHelper->phi_module(stripId)
877  << ", eta=" << m_pSCTHelper->eta_module(stripId) << ", side=" << m_pSCTHelper->side(stripId)
878  << ", strip=offline" << m_pSCTHelper->strip(stripId));
879  } else if (numHitsInStrip[stripNum]/m_numberOfEvents>m_noisyThr4DeadFinding) {
880  n_noisyStrip++;
881  } else {
882  totalHitsInWafer+=numHitsInStrip[stripNum];
883  }
884 
885  } //end strip loop
886 
887  if (n_disabledStrip==768) {
888  if (side==1) {
889  if (defectChip==" 0-5 6-11 ") {
890  n_deadModule++;
891  } else if (defectChip==" 0-5 " or defectChip==" 6-11 ") {
892  n_deadLink++;
893  }
894  if (!(defectStrip.empty()) or !(defectChip.empty())) {
895  if (addToSummaryStr(summaryList, waferId, "DEAD", defectStrip.c_str(), defectChip.c_str()).isFailure()) {
896  ATH_MSG_ERROR("Could not add dead strips to the summary");
897  return StatusCode::FAILURE;
898  }
899  }
900 
901  if (!(defectStrip.empty())) {
902  if (m_writeToCool) {
903  if (m_pCalibWriteTool->createListStrip(moduleId, m_pSCTHelper, 10000, "DEAD", m_deadStripSignificance, defectStrip).isFailure()) {
904  ATH_MSG_ERROR("Could not create strip list");
905  return StatusCode::FAILURE;
906  }
907  }
908 
909  if (addToXML4DB(m_outDeadStrips, waferId, "DEAD", m_deadStripSignificance, defectStrip.c_str()).isFailure()) {
910  ATH_MSG_ERROR("Could not add xml strip list");
911  return StatusCode::FAILURE;
912  }
913  hasDeadStrip=true;
914 
915  }
916  if (!(defectChip.empty())) {
917  if (m_writeToCool) {
918  if (m_pCalibWriteTool->createListChip(moduleId, m_pSCTHelper, 10000, "DEAD", m_deadChipSignificance, defectChip).isFailure()) {
919  ATH_MSG_ERROR("Could not create strip list");
920  return StatusCode::FAILURE;
921  }
922  }
923 
924  if (addToXML4DB(m_outDeadChips, waferId, "DEAD", m_deadChipSignificance, defectChip.c_str()).isFailure()) {
925  ATH_MSG_ERROR("Could not add xml chip list");
926  return StatusCode::FAILURE;
927  }
928 
929  hasDeadChip=true;
930 
931  }
932  }
933  continue;
934 
935  }
936 
937  isNoHitLink=false;
938  if (n_noHitsStrip+n_disabledStrip==768) {
939  n_checkedChip+=n_chipPerSide;
940  isNoHitLink=true;
941 
942  double meanOccu{0.};
943  if (m_pSCTHelper->barrel_ec(waferId)==BARREL) meanOccu=meanOccupancy_Barrel[m_pSCTHelper->layer_disk(waferId)];
944  else meanOccu=meanOccupancy_EC[m_pSCTHelper->layer_disk(waferId)][m_pSCTHelper->eta_module(waferId)];
945  double sum_binomial{ROOT::Math::binomial_cdf(0, meanOccu, m_numberOfEvents*n_stripPerChip*n_chipPerSide)};
946 
947  if (sum_binomial<deadChipDefinition) {
948  ATH_MSG_INFO("DEADLINK : " << moduleId << ", side=" << side);
949  n_deadChip+=n_chipPerSide;
950 
951  //For DeadStrip
952  if (m_doDeadStrip) {
953  if (side==0) beginDead=0, endDead=767;
954  else beginDead=768, endDead=1535;
955  defectStrip = m_pCalibWriteTool->addDefect(defectStrip, beginDead, endDead);
956  }
957 
958  //For DeadChip
959  if (m_doDeadChip) {
960  if (side==0) beginDead=0, endDead=5;
961  else beginDead=6, endDead=11;
962  defectChip = m_pCalibWriteTool->addDefect(defectChip, beginDead, endDead);
963  }
964 
965  if (side==1) {
966  if (defectChip==" 0-5 6-11 ") {
967  n_deadModule++;
968  } else if (defectChip==" 0-5 " or defectChip==" 6-11 ") {
969  n_deadLink++;
970  }
971 
972  if (!(defectStrip.empty()) or !(defectChip.empty())) {
973  if (addToSummaryStr(summaryList, waferId, "DEAD", defectStrip.c_str(), defectChip.c_str()).isFailure()) {
974  ATH_MSG_ERROR("Could not add dead strips to the summary");
975  return StatusCode::FAILURE;
976  }
977  }
978  if (!(defectStrip.empty())) {
979  if (m_writeToCool) {
980  if (m_pCalibWriteTool->createListStrip(moduleId, m_pSCTHelper, 10000, "DEAD", m_deadStripSignificance, defectStrip).isFailure()) {
981  ATH_MSG_ERROR("Could not create strip list");
982  return StatusCode::FAILURE;
983  }
984  }
985 
986  if (addToXML4DB(m_outDeadStrips, waferId, "DEAD", m_deadStripSignificance, defectStrip.c_str()).isFailure()) {
987  ATH_MSG_ERROR("Could not add xml strip list");
988  return StatusCode::FAILURE;
989  }
990 
991  hasDeadStrip=true;
992 
993  }
994 
995  if (!(defectChip.empty())) {
996  if (m_writeToCool) {
997  if (m_pCalibWriteTool->createListChip(moduleId, m_pSCTHelper, 10000, "DEAD", m_deadChipSignificance, defectChip).isFailure()) {
998  ATH_MSG_ERROR("Could not create chip list");
999  return StatusCode::FAILURE;
1000  }
1001  }
1002 
1003  if (addToXML4DB(m_outDeadChips, waferId, "DEAD", m_deadChipSignificance, defectChip.c_str()).isFailure()) {
1004  ATH_MSG_ERROR("Could not add xml chip list");
1005  return StatusCode::FAILURE;
1006  }
1007 
1008  hasDeadChip=true;
1009 
1010  }
1011  }
1012  continue;
1013  }
1014  } //end DeadLink
1015 
1016  if (n_noHitsStrip>0 || !m_deadNotQuiet) {
1017  int n_deadChipInWafer{0};
1018 
1019  double n_effectiveEvents{0.};
1020  if (busyStream) n_effectiveEvents = m_numberOfEvents*(n_stripPerChip*n_chipPerSide-n_disabledStrip-n_noisyStrip-n_noHitsStrip);
1021  else n_effectiveEvents = m_numberOfEvents*(n_stripPerChip*n_chipPerSide-n_disabledStrip-n_noisyStrip);
1022 
1023  //First, check DeadChip
1024  double meanOccupancy{totalHitsInWafer/n_effectiveEvents};
1025  for (int j{0}; j<n_stripPerChip*n_chipPerSide; j++) {
1026  if (numHitsInStrip[j]>0) numHitsInChip[j/n_stripPerChip] += numHitsInStrip[j];
1027  }
1028 
1029  for (int j{0}; j<n_chipPerSide; j++) {
1030  isDead=false;
1031  int chipNum{side==0 ? j : j+6};
1032  if ( !disabledChip[chipNum] && (numHitsInChip[j]==0 || !m_deadNotQuiet) ) {
1033  if (!isNoHitLink) n_checkedChip++;
1034  double sum_binomial{ROOT::Math::binomial_cdf(0, meanOccupancy, m_numberOfEvents*(n_stripPerChip-n_disabledInChip[j]))};
1036  if ((m_deadNotQuiet && sum_binomial<deadChipDefinition) ||
1037  (!m_deadNotQuiet && numHitsInChip[j]/(m_numberOfEvents*(n_stripPerChip-n_disabledInChip[j])) < meanOccupancy*m_quietThresholdChip)) {
1038  ATH_MSG_INFO("DEADCHIP : " << moduleId << ", side=" << side << ", chip(online)=" << (side==0 ? j : j+n_chipPerSide));
1039  isDead=true;
1040  n_deadChip++;
1041  n_deadChipInWafer++;
1042  endDead = side==0 ? j : j+n_chipPerSide;
1043  if (!beforeIsDead) beginDead = side==0 ? j : j+n_chipPerSide;
1044  }
1045  }
1046 
1047  if (m_doDeadChip) {
1048  if ((beforeIsDead and !isDead) or (j==5 and isDead)) defectChip = m_pCalibWriteTool->addDefect(defectChip, beginDead, endDead);
1049  }
1050  beforeIsDead = isDead;
1051  } //end chip loop
1052 
1053  //Second, check DeadStrip
1054  if (m_doDeadStrip) {
1055  double meanOccExceptDeadChip{totalHitsInWafer/(n_effectiveEvents-n_stripPerChip*n_deadChipInWafer)};
1056  double numHitsInStripOnlineOrder[n_stripPerChip*n_chipPerSide] = {0};
1057  for (int j{0}; j<n_stripPerChip*n_chipPerSide; j++) {
1058  numHitsInStripOnlineOrder[j] = side==0 ? numHitsInStrip[j] : numHitsInStrip[n_stripPerChip*n_chipPerSide-j];
1059  isDead=false;
1060  if (numHitsInStripOnlineOrder[j]==0 || !m_deadNotQuiet) {
1061  double sum_binomial{ROOT::Math::binomial_cdf(0, meanOccExceptDeadChip, m_numberOfEvents)};
1063  if ((m_deadNotQuiet && sum_binomial<deadStripDefinition) ||
1064  (!m_deadNotQuiet && numHitsInStripOnlineOrder[j]/m_numberOfEvents < meanOccExceptDeadChip*m_quietThresholdStrip)) {
1065  ATH_MSG_INFO("DEADSTRIP : " << moduleId << ", side=" << side << ", strip(offline)=" << j);
1066  isDead=true;
1067  n_deadStrip++;
1068  endDead = side==0 ? j : j+n_stripPerChip*n_chipPerSide;
1069  if (!beforeIsDead) beginDead = side==0 ? j : j+n_stripPerChip*n_chipPerSide;
1070  }
1071  }
1072 
1073  if (m_doDeadStrip) {
1074  if ((beforeIsDead and !isDead) or (j==5 and isDead)) defectStrip = m_pCalibWriteTool->addDefect(defectStrip, beginDead, endDead);
1075  }
1076  beforeIsDead = isDead;
1077  }
1078  }
1079  } //if (n_noHitsStrip>0)
1080  } //Wafer Loop end
1081 
1082 
1083  //Close Files
1084  if (m_doDeadStrip) {
1085  ATH_MSG_INFO("total #DeadStrip : " << n_deadStrip);
1086  if (closeXML4DB(m_outDeadStrips).isFailure()) {
1087  ATH_MSG_ERROR("Problem closing " << m_deadStripsFile);
1088  return StatusCode::FAILURE;
1089  }
1090  }
1091  if (m_doDeadChip) {
1092  ATH_MSG_INFO("total #DeadChip : " << n_deadChip << ", #noHitChip : " << n_checkedChip);
1093  if (closeXML4DB(m_outDeadChips).isFailure()) {
1094  ATH_MSG_ERROR("Problem closing " << m_deadChipsFile);
1095  return StatusCode::FAILURE;
1096  }
1097  }
1098 
1099  //Making Summary File
1100  if (openXML4DeadSummary(m_outDeadSummary, "DEAD", n_deadModule, n_deadLink, n_deadChip, n_deadStrip).isFailure()) {
1101  ATH_MSG_ERROR("Problem opening " << m_deadSummaryFile);
1102  return StatusCode::FAILURE;
1103  }
1104  if (wrapUpXML4Summary(m_outDeadSummary, "DEAD", summaryList).isFailure()) {
1105  ATH_MSG_ERROR("Problem closing " << m_deadSummaryFile);
1106  return StatusCode::FAILURE;
1107  }
1108 
1109  if (m_writeToCool) {
1110  if (m_doDeadStrip and hasDeadStrip) {
1111  if (m_pCalibWriteTool->wrapUpDeadStrips().isFailure()) {
1112  ATH_MSG_ERROR("Could not get DeadStrips Info");
1113  return StatusCode::FAILURE;
1114  }
1115  }
1116  if (m_doDeadChip and hasDeadChip) {
1117  if (m_pCalibWriteTool->wrapUpDeadChips().isFailure()) {
1118  ATH_MSG_ERROR("Could not get DeadChips Info");
1119  return StatusCode::FAILURE;
1120  }
1121  }
1122  }
1123 
1124  ATH_MSG_INFO("END HERE");
1125  return StatusCode::SUCCESS;
1126 }
1127 
1128 
1133 StatusCode SCTCalib::getNoiseOccupancy ATLAS_NOT_THREAD_SAFE () // Thread unsafe SCTCalibWriteTool::createListNO method is used.
1134 {
1135  ATH_MSG_INFO("----- in getNoiseOccupancy() -----");
1136 
1137  //--- Initialization
1138  int n_phiBinsBarrel[n_barrels] = {n_phiBinsB0, n_phiBinsB1, n_phiBinsB2, n_phiBinsB3};
1139  int n_phiBinsEndcap[n_disks][n_etaBinsEC] = {{n_phiBinsECOuter, n_phiBinsECMiddle, 0},
1140  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1141  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1142  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1143  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1144  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1145  {n_phiBinsECOuter, n_phiBinsECMiddle, 0},
1146  {n_phiBinsECOuter, n_phiBinsECMiddle, 0},
1147  {n_phiBinsECOuter, 0, 0}
1148  };
1149 
1150  double meanNO_Barrel[n_barrels] = {0};
1151  double meanNO_ECA[n_disks][n_etaBinsEC] = {{0}, {0}};
1152  double meanNO_ECC[n_disks][n_etaBinsEC] = {{0}, {0}};
1153 
1154  //--- Directory in HIST
1155  std::string stem;
1156 
1157  //--- EndcapC
1158  stem = "/run_" + std::to_string(m_runNumber.value()) + "/SCT/SCTEC/Noise/";
1159  m_pnoiseoccupancymapHistoVectorECm.clear();
1160  for (int iDisk{0}; iDisk < n_disks ; ++iDisk) {
1161  for (int iSide{0}; iSide < 2; ++iSide) {
1162  std::ostringstream streamHist;
1163  streamHist << "hitoccupancymap";
1164  if (m_noiseOccupancyTriggerAware) streamHist << "trigger";
1165  streamHist << "ECm_" << iDisk << "_" << iSide;
1166  std::string histName{stem + streamHist.str()};
1167  TProfile2D* hist_tmp{dynamic_cast<TProfile2D*>(m_inputHist->Get(histName.c_str()))};
1168  m_pnoiseoccupancymapHistoVectorECm.push_back(hist_tmp);
1169  }
1170  }
1171  //--- Barrel
1172  stem = "/run_" + std::to_string(m_runNumber.value()) + "/SCT/SCTB/Noise/";
1173  m_pnoiseoccupancymapHistoVector.clear();
1174  for (int iLayer{0}; iLayer < n_barrels ; ++iLayer) {
1175  for (int iSide{0}; iSide < 2; ++iSide) {
1176  std::ostringstream streamHist;
1177  streamHist << "hitoccupancymap";
1178  if (m_noiseOccupancyTriggerAware) streamHist << "trigger";
1179  streamHist << "_" << iLayer << "_" << iSide;
1180  std::string histName{stem + streamHist.str()};
1181  TProfile2D* hist_tmp{dynamic_cast<TProfile2D*>(m_inputHist->Get(histName.c_str()))};
1182  m_pnoiseoccupancymapHistoVector.push_back(hist_tmp);
1183  }
1184  }
1185  //--- EndcapA
1186  stem = "/run_" + std::to_string(m_runNumber.value()) + "/SCT/SCTEA/Noise/";
1187  m_pnoiseoccupancymapHistoVectorECp.clear();
1188  for (int iDisk{0}; iDisk < n_disks ; ++iDisk) {
1189  for (int iSide{0}; iSide < 2; ++iSide) {
1190  std::ostringstream streamHist;
1191  streamHist << "hitoccupancymap";
1192  if (m_noiseOccupancyTriggerAware) streamHist << "trigger";
1193  streamHist << "ECp_" << iDisk << "_" << iSide;
1194  std::string histName{stem + streamHist.str()};
1195  TProfile2D* hist_tmp{dynamic_cast<TProfile2D*>(m_inputHist->Get(histName.c_str()))};
1196  m_pnoiseoccupancymapHistoVectorECp.push_back(hist_tmp);
1197  }
1198  }
1199 
1200  //--- XML file
1201  const char* outputNoiseOccupancyFileName{m_noiseOccupancyFile.value().c_str()};
1202  std::ofstream outFile{outputNoiseOccupancyFileName, std::ios::out};
1203  if (!outFile.good()) {
1204  ATH_MSG_ERROR("Unable to open NoiseOccupancyFile : " << outputNoiseOccupancyFileName);
1205  return StatusCode::FAILURE;
1206  }
1207 
1208  //--- Header for XML outputs
1209  std::ostringstream osHeader;
1210  osHeader << "<channels server=\"ATLAS_COOLPROD\" schema=\"ATLAS_COOLOFL_SCT\" dbname=\"MONP200\" folder=\"SCT/Derived/NoiseOccupancy\" "
1211  << "since=\"" << m_iovStart.re_time() << "\" "
1212  << "until=\"" << m_iovStop.re_time() << "\" "
1213  << "tag=\"" << m_tagID4NoiseOccupancy << "\" "
1214  << "version=\"" << "multi\">" << std::endl;
1215  outFile << osHeader.str();
1216 
1217  //--- EndcapC
1218  for (int iDisk{0}; iDisk < n_disks ; ++iDisk) {
1219  for (int iSide{0}; iSide < 2; ++iSide) {
1220  for (int iEta{0}; iEta < n_etaBinsEC; ++iEta) {
1221  for (int iPhi{0}; iPhi < n_phiBinsEndcap[iDisk][iEta]; ++iPhi) {
1222  Identifier waferId = m_pSCTHelper->wafer_id(ENDCAP_C, iDisk, iPhi, iEta, iSide);
1223  float occupancy{static_cast<float>(m_pnoiseoccupancymapHistoVectorECm[2*iDisk + iSide]->GetBinContent(iEta+1, iPhi+1))};
1224  occupancy /= static_cast<float>(ntimeBins);
1225  occupancy /= 1E5;
1226  //--- For calculating average Noise Occupancy
1227  meanNO_ECC[iDisk][iEta]+=occupancy;
1228  IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
1229  SCT_SerialNumber sn{m_CablingTool->getSerialNumberFromHash(waferHash)};
1230  outFile << xmlChannelNoiseOccDataString(waferId, occupancy, sn) << std::endl;
1231  //--- DB output
1232  if (m_writeToCool) {
1233  if (m_pCalibWriteTool->createListNO(waferId, m_pSCTHelper, 10000, occupancy).isFailure()) {
1234  ATH_MSG_ERROR("Unable to run createListNO");
1235  return StatusCode::FAILURE;
1236  }
1237  }
1238  }
1239  }
1240  }
1241  }
1242  //--- Barrel
1243  for (int iLayer{0}; iLayer < n_barrels; ++iLayer) {
1244  for (int iSide{0}; iSide < 2; ++iSide) {
1245  for (int iEta{0}; iEta < n_etaBins; ++iEta) {
1246  if (iEta-6 == 0) continue;
1247  for (int iPhi{0}; iPhi < n_phiBinsBarrel[iLayer]; ++iPhi) {
1248  Identifier waferId{m_pSCTHelper->wafer_id(BARREL, iLayer, iPhi, iEta-6, iSide)};
1249  float occupancy{static_cast<float>(m_pnoiseoccupancymapHistoVector[2*iLayer + iSide]->GetBinContent(iEta+1, iPhi+1))};
1250  occupancy /= static_cast<float>(ntimeBins);
1251  occupancy /= 1E5;
1252  //--- For calculating average Noise Occupancy
1253  meanNO_Barrel[iLayer]+=occupancy;
1254  IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
1255  SCT_SerialNumber sn{m_CablingTool->getSerialNumberFromHash(waferHash)};
1256  outFile << xmlChannelNoiseOccDataString(waferId, occupancy, sn) << std::endl;
1257  //--- DB output
1258  if (m_writeToCool) {
1259  if (m_pCalibWriteTool->createListNO(waferId, m_pSCTHelper, 10000, occupancy).isFailure()) {
1260  ATH_MSG_ERROR("Unable to run createListNO");
1261  return StatusCode::FAILURE;
1262  }
1263  }
1264  }
1265  }
1266  }
1267  }
1268  //--- EndcapA
1269  for (int iDisk{0}; iDisk < n_disks ; ++iDisk) {
1270  for (int iSide{0}; iSide < 2; ++iSide) {
1271  for (int iEta{0}; iEta < n_etaBinsEC; ++iEta) {
1272  for (int iPhi{0}; iPhi < n_phiBinsEndcap[iDisk][iEta]; ++iPhi) {
1273  Identifier waferId{m_pSCTHelper->wafer_id(ENDCAP_A, iDisk, iPhi, iEta, iSide)};
1274  float occupancy{static_cast<float>(m_pnoiseoccupancymapHistoVectorECp[2*iDisk + iSide]->GetBinContent(iEta+1, iPhi+1))};
1275  occupancy /= static_cast<float>(ntimeBins);
1276  occupancy /= 1E5;
1277  //--- For calculating average Noise Occupancy
1278  meanNO_ECA[iDisk][iEta]+=occupancy;
1279  IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
1280  SCT_SerialNumber sn{m_CablingTool->getSerialNumberFromHash(waferHash)};
1281  outFile << xmlChannelNoiseOccDataString(waferId, occupancy, sn) << std::endl;
1282  //--- DB output
1283  if (m_writeToCool) {
1284  if (m_pCalibWriteTool->createListNO(waferId, m_pSCTHelper, 10000, occupancy).isFailure()) {
1285  ATH_MSG_ERROR("Unable to run createListNO");
1286  return StatusCode::FAILURE;
1287  }
1288  }
1289  }
1290  }
1291  }
1292  }
1293 
1294  //--- Tail of XML outputs
1295  outFile << "</channels>" << std::endl;
1296 
1297  //--- Summary XML output
1298  std::ostringstream summaryList;
1299  for (int i{0}; i < n_disks; ++i) {
1300  for (int j{0}; j < n_etaBinsEC; ++j) {
1301  if (n_phiBinsEndcap[i][j] != 0) {
1302  meanNO_ECC[i][j] /= (n_phiBinsEndcap[i][j]*2);
1303  summaryList << xmlPartData(ENDCAP_C, i, j, "meanNO", meanNO_ECC[i][j]);
1304  }
1305  }
1306  }
1307  for (int i{0}; i < n_barrels; ++i) {
1308  meanNO_Barrel[i] /= (n_phiBinsBarrel[i]*n_etaInBarrel*2);
1309  summaryList << xmlPartData(BARREL, i, 0, "meanNO", meanNO_Barrel[i]);
1310  }
1311  for (int i{0}; i < n_disks; ++i) {
1312  for (int j{0}; j < n_etaBinsEC; ++j) {
1313  if (n_phiBinsEndcap[i][j] != 0) {
1314  meanNO_ECA[i][j] /= (n_phiBinsEndcap[i][j]*2);
1315  summaryList << xmlPartData(ENDCAP_A, i, j, "meanNO", meanNO_ECA[i][j]);
1316  }
1317  }
1318  }
1319 
1320  if (openXML4MonSummary(m_outNOSummary, "NoiseOccupancy").isFailure()) {
1321  ATH_MSG_ERROR("Problem in opening NoiseOccupancy file");
1322  return StatusCode::FAILURE;
1323  }
1324  if (wrapUpXML4Summary(m_outNOSummary, "NoiseOccupancy", summaryList).isFailure()) {
1325  ATH_MSG_ERROR("Problem in closing NoiseOccupancy file");
1326  return StatusCode::FAILURE;
1327  }
1328 
1329  //--- DB output
1330  if (m_writeToCool) {
1331  if (m_pCalibWriteTool->wrapUpNoiseOccupancy().isFailure()) {
1332  ATH_MSG_ERROR("Could not get NoiseOccupancy");
1333  return StatusCode::FAILURE;
1334  }
1335  }
1336 
1337  return StatusCode::SUCCESS;
1338 }
1339 
1340 
1345 StatusCode SCTCalib::getRawOccupancy ATLAS_NOT_THREAD_SAFE () // Thread unsafe SCTCalibWriteTool::createListRawOccu method is used.
1346 {
1347  ATH_MSG_INFO("----- in getRawOccupancy() -----");
1348 
1349  //--- Initialization
1350  int n_phiBinsBarrel[n_barrels] = {n_phiBinsB0, n_phiBinsB1, n_phiBinsB2, n_phiBinsB3};
1351  int n_phiBinsEndcap[n_disks][n_etaBinsEC] = {{n_phiBinsECOuter, n_phiBinsECMiddle, 0},
1352  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1353  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1354  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1355  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1356  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1357  {n_phiBinsECOuter, n_phiBinsECMiddle, 0},
1358  {n_phiBinsECOuter, n_phiBinsECMiddle, 0},
1359  {n_phiBinsECOuter, 0, 0}
1360  };
1361 
1362  double meanRO_Barrel[n_barrels] = {0};
1363  double meanRO_ECA[n_disks][n_etaBinsEC] = {{0}, {0}};
1364  double meanRO_ECC[n_disks][n_etaBinsEC] = {{0}, {0}};
1365 
1366 
1367  //--- Directory in HIST
1368  std::vector<std::pair<std::string, int>> EC_stems;
1369  EC_stems.clear();
1370  std::pair<std::string, int> stem_C("/run_" + std::to_string(m_runNumber.value()) + "/SCT/SCTEC/hits/", ENDCAP_C);
1371  std::pair<std::string, int> stem_A("/run_" + std::to_string(m_runNumber.value()) + "/SCT/SCTEA/hits/", ENDCAP_A);
1372  EC_stems.push_back(stem_C);
1373  EC_stems.push_back(stem_A);
1374  std::vector< std::pair<std::string, int> >::iterator stemItr{EC_stems.begin()};
1375 
1376  //--- Endcaps
1377  for (stemItr=EC_stems.begin(); stemItr!=EC_stems.end(); ++stemItr) {
1378  for (int iDisk{0}; iDisk<n_disks; ++iDisk) {
1379  for (int iSide{0}; iSide<2; ++iSide) {
1380  for (int iEta{0}; iEta<n_etaBinsEC; ++iEta) {
1381  for (int iPhi{0}; iPhi<n_phiBinsEndcap[iDisk][iEta]; ++iPhi) {
1382  Identifier waferId{m_pSCTHelper->wafer_id((*stemItr).second, iDisk, iPhi, iEta, iSide)};
1383  std::string detector_part;
1384  detector_part.erase();
1385  if (m_histBefore2010) {
1386  if ((*stemItr).second==ENDCAP_C) detector_part = "ECm_hitsmap";
1387  else detector_part = "ECp_hitsmap";
1388  } else {
1389  if ((*stemItr).second==ENDCAP_C) detector_part = "hitsmapECm";
1390  else detector_part = "hitsmapECp";
1391  }
1392  std::ostringstream streamHist;
1393  streamHist << detector_part << "_" << iDisk << "_" << iSide;
1394  std::string hitsmapname{stemItr->first + streamHist.str()};
1395  TH2F* hist_tmp{dynamic_cast<TH2F*>(m_inputHist->Get(hitsmapname.c_str()))};
1396  unsigned long long n_hits{static_cast<unsigned long long>(hist_tmp->GetBinContent(iEta+1, iPhi+1))};
1397  float raw_occu{0};
1398  if (m_numberOfEvents!=0) {
1399  raw_occu = static_cast<float>(n_hits)/(m_numberOfEvents*n_chipPerSide*n_stripPerChip);
1400  //--- For calculating average Raw Occupancy
1401  if (stemItr->second==ENDCAP_C) meanRO_ECC[iDisk][iEta] += static_cast<double>(raw_occu);
1402  else if (stemItr->second==ENDCAP_A) meanRO_ECA[iDisk][iEta] += static_cast<double>(raw_occu);
1403  }
1404  //--- DB writing
1405  if (m_writeToCool) {
1406  if (m_pCalibWriteTool->createListRawOccu(waferId, m_pSCTHelper, m_numberOfEvents, raw_occu).isFailure()) {
1407  ATH_MSG_ERROR("Unable to run createListRawOccu");
1408  return StatusCode::FAILURE;
1409  }
1410  }
1411  }
1412  }
1413  }
1414  }
1415  }
1416  //--- Barrel
1417  for (int iLayer{0}; iLayer<n_barrels; ++iLayer) {
1418  for (int iSide{0}; iSide<2; ++iSide) {
1419  for (int iEta{0}; iEta<n_etaBins; ++iEta) {
1420  if (iEta-6==0) continue;
1421  for (int iPhi{0}; iPhi<n_phiBinsBarrel[iLayer]; ++iPhi) {
1422  Identifier waferId{m_pSCTHelper->wafer_id(BARREL, iLayer, iPhi, iEta-6, iSide)};
1423  std::ostringstream streamHist;
1424  streamHist << iLayer << "_" << iSide;
1425  std::string hitsmapname{"/run_" + std::to_string(m_runNumber.value()) + "/SCT/SCTB/hits/hitsmap_" + streamHist.str()};
1426  TH2F* hist_tmp{dynamic_cast<TH2F*>(m_inputHist->Get(hitsmapname.c_str()))};
1427  unsigned long long n_hits{static_cast<unsigned long long>(hist_tmp->GetBinContent(iEta+1, iPhi+1))};
1428  float raw_occu{0};
1429  if (m_numberOfEvents!=0) {
1430  raw_occu = static_cast<float>(n_hits)/(m_numberOfEvents*n_chipPerSide*n_stripPerChip);
1431  //--- For calculating average Raw Occupancy
1432  meanRO_Barrel[iLayer] += static_cast<double>(raw_occu);
1433  }
1434  //--- DB writing
1435  if (m_writeToCool) {
1436  if (m_pCalibWriteTool->createListRawOccu(waferId, m_pSCTHelper, m_numberOfEvents, raw_occu).isFailure()) {
1437  ATH_MSG_ERROR("Unable to run createListRawOccu");
1438  return StatusCode::FAILURE;
1439  }
1440  }
1441  }
1442  }
1443  }
1444  }
1445  //--- Summary XML output
1446  std::ostringstream summaryList;
1447  for (int i{0}; i < n_disks; ++i) {
1448  for (int j{0}; j < n_etaBinsEC; ++j) {
1449  if (n_phiBinsEndcap[i][j] != 0) {
1450  meanRO_ECC[i][j] /= (n_phiBinsEndcap[i][j]*2);
1451  summaryList << xmlPartData(ENDCAP_C, i, j, "meanRO", meanRO_ECC[i][j]);
1452  }
1453  }
1454  }
1455  for (int i{0}; i < n_barrels; ++i) {
1456  meanRO_Barrel[i] /= (n_phiBinsBarrel[i]*n_etaInBarrel*2);
1457  summaryList << xmlPartData(BARREL, i, 0, "meanRO", meanRO_Barrel[i]);
1458  }
1459  for (int i{0}; i < n_disks; ++i) {
1460  for (int j{0}; j < n_etaBinsEC; ++j) {
1461  if (n_phiBinsEndcap[i][j] != 0) {
1462  meanRO_ECA[i][j] /= (n_phiBinsEndcap[i][j]*2);
1463  summaryList << xmlPartData(ENDCAP_A, i, j, "meanRO", meanRO_ECA[i][j]);
1464  }
1465  }
1466  }
1467 
1468  if (openXML4MonSummary(m_outROSummary, "RawOccupancy").isFailure()) {
1469  ATH_MSG_ERROR("Problem in opening RawOccupancy file");
1470  return StatusCode::FAILURE;
1471  }
1472  if (wrapUpXML4Summary(m_outROSummary, "RawOccupancy", summaryList).isFailure()) {
1473  ATH_MSG_ERROR("Problem in closing RawOccupancy file ");
1474  return StatusCode::FAILURE;
1475  }
1476 
1477  //--- DB output
1478  if (m_writeToCool) {
1479  if (m_pCalibWriteTool->wrapUpRawOccupancy().isFailure()) {
1480  ATH_MSG_ERROR("Could not get RawOccupancy");
1481  return StatusCode::FAILURE;
1482  }
1483  }
1484 
1485  return StatusCode::SUCCESS;
1486 }
1487 
1488 
1493 StatusCode SCTCalib::getEfficiency ATLAS_NOT_THREAD_SAFE () { // Thread unsafe SCTCalibWriteTool::createListEff method is used.
1494  ATH_MSG_INFO("----- in getEfficiency() -----");
1495 
1496  //--- Initialization
1497  int n_phiBinsBarrel[n_barrels] = {n_phiBinsB0, n_phiBinsB1, n_phiBinsB2, n_phiBinsB3};
1498  int n_phiBinsEndcap[n_disks][n_etaBinsEC] = {{n_phiBinsECOuter, n_phiBinsECMiddle, 0},
1499  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1500  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1501  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1502  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1503  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1504  {n_phiBinsECOuter, n_phiBinsECMiddle, 0},
1505  {n_phiBinsECOuter, n_phiBinsECMiddle, 0},
1506  {n_phiBinsECOuter, 0, 0}
1507  };
1508 
1509  double meanEff_Barrel[n_barrels] = {0};
1510  double meanEff_ECA[n_disks][n_etaBinsEC] = {{0}, {0}};
1511  double meanEff_ECC[n_disks][n_etaBinsEC] = {{0}, {0}};
1512 
1513  double meanEff_Barrel_bcid1[ n_barrels ] = { 0 };
1514  double meanEff_ECA_bcid1[ n_disks ][ n_etaBinsEC ] = { {0}, {0} };
1515  double meanEff_ECC_bcid1[ n_disks ][ n_etaBinsEC ] = { {0}, {0} };
1516 
1517  //--- Directory in HIST
1518  std::vector<std::pair<std::string, int>> EC_stems;
1519  EC_stems.clear();
1520  std::pair<std::string, int> stem_C{"/run_" + std::to_string(m_runNumber.value()) + "/SCT/SCTEC/eff/", ENDCAP_C};
1521  std::pair<std::string, int> stem_A{"/run_" + std::to_string(m_runNumber.value()) + "/SCT/SCTEA/eff/", ENDCAP_A};
1522  EC_stems.push_back(stem_C);
1523  EC_stems.push_back(stem_A);
1524  std::vector<std::pair<std::string, int>>::iterator stemItr{EC_stems.begin()};
1525 
1526  const char* outputEfficiencyFileName{m_efficiencyModuleFile.value().c_str()};
1527  std::ofstream outFile{outputEfficiencyFileName, std::ios::out};
1528  if (!outFile.good()) {
1529  ATH_MSG_ERROR("Unable to open EfficiencyFile : " << outputEfficiencyFileName);
1530  return StatusCode::FAILURE;
1531  }
1532 
1533  std::string xslName{"EfficiencyInfo.xsl"};
1534  outFile << xmlHeader << linefeed << associateStylesheet(xslName) << linefeed << "<run>" << std::endl;
1535  outFile << xmlValue("RunNumber", m_runNumber.value()) << linefeed
1536  << xmlValue("StartTime", m_utcBegin) << linefeed
1537  << xmlValue("EndTime", m_utcEnd) << linefeed
1538  << xmlValue("Duration", m_calibEvtInfoTool->duration()) << linefeed
1539  << xmlValue("LB", m_LBRange) << linefeed
1540  << xmlValue("Events", m_numberOfEvents) << linefeed
1541  << " <modules>" << std::endl;
1542 
1543  const char* outputEfficiencyFileNameChip{m_efficiencyChipFile.value().c_str()};
1544  std::ofstream outFileChip{outputEfficiencyFileNameChip, std::ios::out};
1545  if (!outFileChip.good()) {
1546  ATH_MSG_ERROR("Unable to open EfficiencyFile for chips : " << outputEfficiencyFileNameChip);
1547  return StatusCode::FAILURE;
1548  }
1549 
1550  if (m_efficiencyDoChips) {
1551  std::string xslNameChip{"EfficiencyChipInfo.xsl"};
1552  outFileChip << xmlHeader << linefeed << associateStylesheet(xslNameChip) << linefeed << "<run>" << std::endl;
1553  outFileChip << xmlValue("RunNumber", m_runNumber.value()) << linefeed
1554  << xmlValue("StartTime", m_utcBegin) << linefeed
1555  << xmlValue("EndTime", m_utcEnd) << linefeed
1556  << xmlValue("Duration", m_calibEvtInfoTool->duration()) << linefeed
1557  << xmlValue("LB", m_LBRange) << linefeed
1558  << xmlValue("Events", m_numberOfEvents) << linefeed
1559  << " <chips>" << std::endl;
1560  }
1561 
1562  //--- Endcaps
1563  for (stemItr=EC_stems.begin(); stemItr!=EC_stems.end(); ++stemItr) {
1564  for (int iDisk{0}; iDisk<n_disks; ++iDisk) {
1565  for (int iSide{0}; iSide<2; ++iSide) {
1566  for (int iEta{0}; iEta<n_etaBinsEC; ++iEta) {
1567  for (int iPhi{0}; iPhi<n_phiBinsEndcap[iDisk][iEta]; ++iPhi) {
1568  Identifier waferId = m_pSCTHelper->wafer_id((*stemItr).second, iDisk, iPhi, iEta, iSide);
1569  std::string detector_part;
1570  detector_part.erase();
1571  std::ostringstream streamProf;
1572  if ((*stemItr).second==ENDCAP_C) {
1573  detector_part = "m_eff";
1574  streamProf << detector_part << "_" << iDisk << "_" << iSide;
1575  } else {
1576  detector_part = "p_eff";
1577  streamProf << detector_part << "_" << iDisk << "_" << iSide;
1578  }
1579  std::string effmapname{stemItr->first + streamProf.str()};
1580  TProfile2D* prof_tmp{dynamic_cast<TProfile2D*>(m_inputHist->Get(effmapname.c_str()))};
1581  int global_bin{prof_tmp->GetBin(iEta+1, iPhi+1)};
1582  float eff{static_cast<float>(prof_tmp->GetBinContent(global_bin))};
1583  unsigned long long eff_entry{static_cast<unsigned long long>(prof_tmp->GetBinEntries(global_bin))};
1584 
1585  //--- For calculating average Efficiency
1586  if (stemItr->second==ENDCAP_C) meanEff_ECC[iDisk][iEta] += static_cast<double>(eff);
1587  else if (stemItr->second==ENDCAP_A) meanEff_ECA[iDisk][iEta] += static_cast<double>(eff);
1588 
1589  std::string effmapname_bcid1 = effmapname+"_bcid";
1590  TProfile2D* prof_tmp_bcid1 = (TProfile2D*) m_inputHist->Get( effmapname_bcid1.c_str() );
1591  int global_bin_bcid1 = prof_tmp_bcid1->GetBin( iEta+1, iPhi+1 );
1592  float eff_bcid1 = (float)prof_tmp_bcid1->GetBinContent( global_bin_bcid1 );
1593 
1594  //--- For calculating average Efficiency (BCID1)
1595  if( stemItr->second==ENDCAP_C ) meanEff_ECC_bcid1[iDisk][iEta]+=(double)eff_bcid1;
1596  else if( stemItr->second==ENDCAP_A ) meanEff_ECA_bcid1[iDisk][iEta]+=(double)eff_bcid1;
1597 
1598  //--- Write out Efficiency to XML file as -1 if it is 0 due to no entries in histogram (e.g. for disabled links)
1599  float effToXML = (eff_entry == 0 ? -1. : eff);
1600 
1601  //--- For Efficiency _not_ averaged over modules
1602  IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
1603  SCT_SerialNumber sn{m_CablingTool->getSerialNumberFromHash(waferHash)};
1604  outFile << xmlChannelEfficiencyDataString(waferId, effToXML, sn, iSide) << std::endl;
1605 
1606  //--- Loop over chips
1607  if (m_efficiencyDoChips) {
1608  for (int iChip{0}; iChip<n_chipPerSide; ++iChip) {
1609  std::string detector_part_chip;
1610  detector_part_chip.erase();
1611  std::ostringstream streamProfChip;
1612  if ((*stemItr).second==ENDCAP_C) {
1613  detector_part_chip = "m_eff";
1614  streamProfChip << detector_part_chip << "_" << "chip" << iChip<< "_" << iDisk << "_" << iSide;
1615  } else {
1616  detector_part_chip = "p_eff";
1617  streamProfChip << detector_part_chip << "_" << "chip" << iChip<< "_" << iDisk << "_" << iSide;
1618  }
1619  std::string effchipmapname{stemItr->first + "chip" + std::to_string(iChip) + "/" + streamProfChip.str()};
1620  TProfile2D* profChip_tmp{dynamic_cast<TProfile2D*>(m_inputHist->Get(effchipmapname.c_str()))};
1621  global_bin = profChip_tmp->GetBin(iEta+1, iPhi+1);
1622  float effChip{static_cast<float>(profChip_tmp->GetBinContent(global_bin))};
1623  unsigned long long effChip_entry{static_cast<unsigned long long>(profChip_tmp->GetBinEntries(global_bin))};
1624 
1625  //--- Write out Efficiency to XML file as -1 if it is 0 due to no entries in histogram (e.g. for disabled links)
1626  effToXML = (effChip_entry == 0 ? -1. : effChip);
1627 
1628  std::string effchipmapname_bcid1 = effchipmapname+"_bcid";
1629  TProfile2D* profChip_tmp_bcid1 = (TProfile2D*) m_inputHist->Get( effchipmapname_bcid1.c_str() );
1630  global_bin_bcid1 = profChip_tmp_bcid1->GetBin( iEta+1, iPhi+1 );
1631  eff_bcid1 = (float)profChip_tmp_bcid1->GetBinContent( global_bin_bcid1 );
1632  outFileChip << xmlChannelEfficiencyDataStringChip(waferId, effToXML, eff_bcid1, sn, iSide, iChip) << std::endl;
1633  }
1634  }
1635 
1636  //--- DB writing
1637  if (m_writeToCool) {
1638  if (m_pCalibWriteTool->createListEff(waferId, m_pSCTHelper, eff_entry, eff).isFailure()) {
1639  ATH_MSG_ERROR("Unable to run createListEff");
1640  return StatusCode::FAILURE;
1641  }
1642  }
1643  }
1644  }
1645  }
1646  }
1647  }
1648  //--- Barrel
1649  for (int iLayer{0}; iLayer<n_barrels; ++iLayer) {
1650  for (int iSide{0}; iSide<2; ++iSide) {
1651  for (int iEta{0}; iEta<n_etaBins; ++iEta) {
1652  if (iEta-6==0) continue;
1653  for (int iPhi{0}; iPhi<n_phiBinsBarrel[iLayer]; ++iPhi) {
1654  Identifier waferId{m_pSCTHelper->wafer_id(BARREL, iLayer, iPhi, iEta-6, iSide)};
1655  std::ostringstream streamProf;
1656  streamProf << iLayer << "_" << iSide;
1657 
1658  std::string effmapname{"/run_" + std::to_string(m_runNumber.value()) + "/SCT/SCTB/eff/eff_" + streamProf.str()};
1659  TProfile2D* prof_tmp{dynamic_cast<TProfile2D*>(m_inputHist->Get(effmapname.c_str()))};
1660  int global_bin{prof_tmp->GetBin(iEta+1, iPhi+1)};
1661  float eff{static_cast<float>(prof_tmp->GetBinContent(global_bin))};
1662  unsigned long long eff_entry{static_cast<unsigned long long>(prof_tmp->GetBinEntries(global_bin))};
1663 
1664  //--- For calculating average Efficiency
1665  meanEff_Barrel[iLayer] += static_cast<double>(eff);
1666 
1667  std::string effmapname_bcid1 = effmapname+"_bcid";
1668  TProfile2D* prof_tmp_bcid1 = (TProfile2D*) m_inputHist->Get( effmapname_bcid1.c_str() );
1669  int global_bin_bcid1 = prof_tmp_bcid1->GetBin( iEta+1, iPhi+1 );
1670  float eff_bcid1 = (float)prof_tmp_bcid1->GetBinContent( global_bin_bcid1 );
1671 
1672  //--- For calculating average Efficiency (BCID1)
1673  meanEff_Barrel_bcid1[iLayer]+=(double)eff_bcid1;
1674 
1675  //--- Write out Efficiency to XML file as -1 if it is 0 due to no entries in histogram (e.g. for disabled links)
1676  float effToXML = (eff_entry == 0 ? -1. : eff);
1677 
1678  //--- For Efficiency _not_ averaged over modules
1679  IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
1680  SCT_SerialNumber sn{m_CablingTool->getSerialNumberFromHash(waferHash)};
1681  outFile << xmlChannelEfficiencyDataString(waferId, effToXML, sn, iSide) << std::endl;
1682 
1683  //--- Loop over chips
1684  if (m_efficiencyDoChips) {
1685  for (int iChip{0}; iChip<n_chipPerSide; ++iChip) {
1686  std::ostringstream streamProfChip;
1687  streamProfChip << "chip" << iChip << "_" << iLayer << "_" << iSide;
1688 
1689  std::string effchipmapname{"/run_" + std::to_string(m_runNumber.value()) + "/SCT/SCTB/eff/chip" + std::to_string(iChip) + "/eff_" + streamProfChip.str()};
1690  TProfile2D* profChip_tmp{dynamic_cast<TProfile2D*>(m_inputHist->Get(effchipmapname.c_str()))};
1691  global_bin = profChip_tmp->GetBin(iEta+1, iPhi+1);
1692  float effChip{static_cast<float>(profChip_tmp->GetBinContent(global_bin))};
1693  unsigned long long effChip_entry{static_cast<unsigned long long>(profChip_tmp->GetBinEntries(global_bin))};
1694 
1695  //--- Write out Efficiency to XML file as -1 if it is 0 due to no entries in histogram (e.g. for disabled links)
1696  effToXML = (effChip_entry == 0 ? -1. : effChip);
1697 
1698  std::string effchipmapname_bcid1 = effchipmapname+"_bcid";
1699  TProfile2D* profChip_tmp_bcid1 = (TProfile2D*) m_inputHist->Get( effchipmapname_bcid1.c_str() );
1700  int global_bin_bcid1 = profChip_tmp_bcid1->GetBin( iEta+1, iPhi+1 );
1701  float eff_bcid1 = (float)profChip_tmp_bcid1->GetBinContent( global_bin_bcid1 );
1702 
1703  outFileChip << xmlChannelEfficiencyDataStringChip(waferId, effToXML, eff_bcid1, sn, iSide, iChip) << std::endl;
1704  }
1705  }
1706 
1707  //--- DB writing
1708  if (m_writeToCool) {
1709  if (m_pCalibWriteTool->createListEff(waferId, m_pSCTHelper, eff_entry, eff).isFailure()) {
1710  ATH_MSG_ERROR("Unable to run createListEff");
1711  return StatusCode::FAILURE;
1712  }
1713  }
1714  }
1715  }
1716  }
1717  }
1718 
1719  outFile << " </modules>" << std::endl;
1720  outFile << "</run>" << std::endl;
1721 
1722  if (m_efficiencyDoChips) {
1723  outFileChip << " </chips>" << std::endl;
1724  outFileChip << "</run>" << std::endl;
1725  }
1726 
1727  //--- Summary XML output
1728  std::ostringstream summaryList;
1729  for (int i{0}; i < n_disks; ++i) {
1730  for (int j{0}; j < n_etaBinsEC; ++j) {
1731  if (n_phiBinsEndcap[i][j] != 0) {
1732  meanEff_ECC[i][j] /= (n_phiBinsEndcap[i][j]*2);
1733  summaryList << xmlPartData(ENDCAP_C, i, j, "meanEff", meanEff_ECC[i][j]);
1734  meanEff_ECC_bcid1[i][j] /= (n_phiBinsEndcap[i][j]*2);
1735  summaryList<<xmlPartData(ENDCAP_C, i, j, "meanEff_bcid1",meanEff_ECC_bcid1[i][j]);
1736  }
1737  }
1738  }
1739  for (int i{0}; i < n_barrels; ++i) {
1740  meanEff_Barrel[i] /= (n_phiBinsBarrel[i]*n_etaInBarrel*2);
1741  summaryList << xmlPartData(BARREL, i, 0, "meanEff", meanEff_Barrel[i]);
1742  meanEff_Barrel_bcid1[i] /= (n_phiBinsBarrel[i]*n_etaInBarrel*2);
1743  summaryList<<xmlPartData(BARREL, i, 0, "meanEff_bcid1",meanEff_Barrel_bcid1[i]);
1744  }
1745  for (int i{0}; i < n_disks; ++i) {
1746  for (int j{0}; j < n_etaBinsEC; ++j) {
1747  if (n_phiBinsEndcap[i][j] != 0) {
1748  meanEff_ECA[i][j] /= (n_phiBinsEndcap[i][j]*2);
1749  summaryList << xmlPartData(ENDCAP_A, i, j, "meanEff", meanEff_ECA[i][j]);
1750  meanEff_ECA_bcid1[i][j] /= (n_phiBinsEndcap[i][j]*2);
1751  summaryList<<xmlPartData(ENDCAP_A, i, j, "meanEff_bcid1",meanEff_ECA_bcid1[i][j]);
1752  }
1753  }
1754  }
1755 
1756  if (openXML4MonSummary(m_outEffSummary, "Efficiency").isFailure()) {
1757  ATH_MSG_ERROR("Problem in opening Efficiency file");
1758  return StatusCode::FAILURE;
1759  }
1760 
1761  if (wrapUpXML4Summary(m_outEffSummary, "Efficiency", summaryList).isFailure()) {
1762  ATH_MSG_ERROR("Problem in closing Efficiency file ");
1763  return StatusCode::FAILURE;
1764  }
1765 
1766  //--- DB output
1767  if (m_writeToCool) {
1768  if (m_pCalibWriteTool->wrapUpEfficiency().isFailure()) {
1769  ATH_MSG_ERROR("Could not get Efficiency");
1770  return StatusCode::FAILURE;
1771  }
1772  }
1773 
1774  return StatusCode::SUCCESS;
1775 }
1776 
1777 
1782 StatusCode SCTCalib::getBSErrors ATLAS_NOT_THREAD_SAFE () { // Thread unsafe SCTCalibWriteTool::createListBSErr method is used.
1783  ATH_MSG_INFO("----- in getBSErrors() -----");
1784 
1785  //--- Initialization
1786  int n_phiBinsBarrel[n_barrels] = {n_phiBinsB0, n_phiBinsB1, n_phiBinsB2, n_phiBinsB3};
1787  int n_phiBinsEndcap[n_disks][n_etaBinsEC] = {{n_phiBinsECOuter, n_phiBinsECMiddle, 0},
1788  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1789  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1790  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1791  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1792  {n_phiBinsECOuter, n_phiBinsECMiddle, n_phiBinsECShort},
1793  {n_phiBinsECOuter, n_phiBinsECMiddle, 0},
1794  {n_phiBinsECOuter, n_phiBinsECMiddle, 0},
1795  {n_phiBinsECOuter, 0, 0}
1796  };
1797 
1798  unsigned long long nErrLink_Barrel[n_barrels] = {0};
1799  unsigned long long nErrLink_ECA[n_disks][n_etaBinsEC] = {{0}, {0}};
1800  unsigned long long nErrLink_ECC[n_disks][n_etaBinsEC] = {{0}, {0}};
1801 
1802  unsigned long long nErrLink_Barrel_module[n_barrels][2][n_etaBins][n_phiBinsB3] = {{{{0}}}};
1803  unsigned long long nErrLink_ECA_module[n_disks][2][n_etaBinsEC][n_phiBinsECOuter] = {{{{0}}}};
1804  unsigned long long nErrLink_ECC_module[n_disks][2][n_etaBinsEC][n_phiBinsECOuter] = {{{{0}}}};
1805 
1806  std::string nErrLink_Barrel_module_serial[n_barrels][2][n_etaBins][n_phiBinsB3];
1807  std::string nErrLink_ECA_module_serial[n_disks][2][n_etaBinsEC][n_phiBinsECOuter];
1808  std::string nErrLink_ECC_module_serial[n_disks][2][n_etaBinsEC][n_phiBinsECOuter];
1809 
1810  unsigned long long nErrs_Barrel_module[n_barrels][2][n_etaBins][n_phiBinsB3][15] = {{{{{0}}}}};
1811  unsigned long long nErrs_ECA_module[n_disks][2][n_etaBinsEC][n_phiBinsECOuter][15] = {{{{{0}}}}};
1812  unsigned long long nErrs_ECC_module[n_disks][2][n_etaBinsEC][n_phiBinsECOuter][15] = {{{{{0}}}}};
1813 
1814  //--- ErrorList
1815  using IntStringMap = std::map<int, std::string>;
1816  IntStringMap ErrMap_C, ErrMap;
1817  const int numberOfErrorTypes{12};
1818  std::array<std::string, numberOfErrorTypes> errorNames = {{
1819  "ByteStreamParseError","TimeOutError","BCIDError","LVL1IDError","PreambleError","FormatterError",
1820  "ABCDError","RawError","MaskedLink","RODClockError",
1821  "TruncatedROD","ROBFragmentError"
1822  }
1823  };
1824  //
1825  std::array<std::string, numberOfErrorTypes> errorNames_C = {{
1826  "ByteStreamParseError","TimeOutError","BCIDError","LVL1IDError","PreambleError","FormatterError",
1827  "ABCDError","RawError","MaskedLink","RODClockError",
1828  "TruncatedROD","ROBFragmentError"
1829  }
1830  };
1831  std::array<int, numberOfErrorTypes> errorValues = {{0, 1, 2, 3, 4, 5, 9, 10, 11, 12, 13, 14}};
1832  //should do compile time check to ensure the sizes are equal.
1833  ErrMap_C.clear();
1834  for (int indx{0}; indx!=numberOfErrorTypes; ++indx) {
1835  ErrMap_C.insert(std::make_pair(errorValues[indx], errorNames_C[indx]));
1836  }
1837  ErrMap.clear();
1838  for (int indx{0}; indx!=numberOfErrorTypes; ++indx) {
1839  ErrMap.insert(std::make_pair(errorValues[indx], errorNames[indx]));
1840  }
1841 
1842  //--- Directory in HIST
1843  const int N_ENDCAPS{2};
1844  std::array<std::string, N_ENDCAPS> detectorStems = {{"/run_" + std::to_string(m_runNumber.value()) + "/SCT/SCTEC/errors/", "/run_" + std::to_string(m_runNumber.value()) + "/SCT/SCTEA/errors/"}}; //barrel stem unused here
1845  std::array<IntStringMap::iterator, N_ENDCAPS> detectorIterators = {{ErrMap_C.begin(), ErrMap.begin()}};
1846  std::array<IntStringMap::iterator, N_ENDCAPS> detectorIteratorsE = {{ErrMap_C.end(), ErrMap.end()}};
1847  std::array<std::string, N_ENDCAPS> detectorParts = {{"EC", "EA"}};
1848  std::string defecttype{""};
1849  std::string n_defect{""};
1850  int n_errorLink{0};
1851  //--- Endcaps
1852  for (int stemIndex{0}; stemIndex!=N_ENDCAPS; ++stemIndex) {
1853  const int thisBec{(4 * stemIndex) - 2}; //map 0, 1 onto -2, 2
1854  const std::string detector_part{detectorParts[stemIndex]};
1855  for (int iDisk{0}; iDisk<n_disks; ++iDisk) {
1856  for (int iSide{0}; iSide<2; ++iSide) {
1857  for (int iEta{0}; iEta<n_etaBinsEC; ++iEta) {
1858  for (int iPhi{0}; iPhi<n_phiBinsEndcap[iDisk][iEta]; ++iPhi) {
1859  defecttype.erase();
1860  n_defect.erase();
1861  std::ostringstream osErrorList;
1862  std::ostringstream osProbList;
1863  Identifier waferId{m_pSCTHelper->wafer_id(thisBec, iDisk, iPhi, iEta, iSide)};
1864  IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
1865  SCT_SerialNumber sn{m_CablingTool->getSerialNumberFromHash(waferHash)};
1866 
1867  if (thisBec==ENDCAP_C) {
1868  nErrLink_ECC_module_serial[iDisk][iSide][iEta][iPhi]=sn.str();
1869  } else if (thisBec==ENDCAP_A) {
1870  nErrLink_ECA_module_serial[iDisk][iSide][iEta][iPhi]=sn.str();
1871  }
1872 
1873  IntStringMap::iterator errItr{detectorIterators[stemIndex]};
1874  IntStringMap::iterator errItrE{detectorIteratorsE[stemIndex]};
1875  for (int iType{0}; iType < n_BSErrorType; ++iType) {
1876  float errorProb{0.};
1877  unsigned long long n_errors{0};
1878  if (errItr!=errItrE and iType == errItr->first) {
1879  std::ostringstream streamHist;
1880  std::ostringstream streamHistAlt;
1881  streamHist << "SCT_NumberOf" << errItr->second << detector_part << "_" << iDisk << "_" << iSide;
1882  streamHistAlt << "SCT_" << errItr->second << detector_part << "_" << iDisk << "_" << iSide;
1883  std::string folder = errItr->second+std::string("/");
1884  //histogram might or might not be inside a folder with the same name
1885  std::string profname = detectorStems[stemIndex] + folder +streamHist.str();
1886  std::string profnameShort = detectorStems[stemIndex] + streamHist.str();
1887  std::string profnameAlt = detectorStems[stemIndex] + folder +streamHistAlt.str();
1888  std::string profnameAltShort = detectorStems[stemIndex] + streamHistAlt.str();
1889 
1890  TProfile2D* prof_tmp = (TProfile2D*) m_inputHist->Get( profname.c_str() );
1891  if(prof_tmp ==nullptr) {
1892  prof_tmp = (TProfile2D*) m_inputHist->Get( profnameShort.c_str() );
1893  }
1894  if(prof_tmp ==nullptr) {
1895  prof_tmp = (TProfile2D*) m_inputHist->Get( profnameAlt.c_str() );
1896  }
1897  if(prof_tmp ==nullptr) {
1898  prof_tmp = (TProfile2D*) m_inputHist->Get( profnameAltShort.c_str() );
1899  }
1900  if(prof_tmp ==nullptr) {
1901  msg( MSG::ERROR ) << "Unable to get profile for BSErrorsDB : " << profname << endmsg;
1902  return StatusCode::FAILURE;
1903  }
1904 
1905  n_errors = static_cast<unsigned long long>(prof_tmp->GetBinContent(iEta+1, iPhi+1));
1906  if (n_errors!=0) {
1907  defecttype = m_pCalibWriteTool->addNumber(defecttype, errItr->first);
1908  n_defect = m_pCalibWriteTool->addNumber(n_defect, n_errors);
1909  errorProb = static_cast<float>(n_errors) / static_cast<float>(m_numberOfEvents);
1910  nErrs_ECC_module[iDisk][iSide][iEta][iPhi][errItr->first] = n_errors;
1911  if (thisBec==ENDCAP_C) {
1912  nErrLink_ECC_module[iDisk][iSide][iEta][iPhi]+=n_errors;
1913  } else if (thisBec==ENDCAP_A) {
1914  nErrLink_ECA_module[iDisk][iSide][iEta][iPhi]+=n_errors;
1915  }
1916 
1917  }//end if (n_errors!=0)
1918  ++errItr;
1919  }//end if (iType == (*errItr).first)
1920  osErrorList << n_errors;
1921  osProbList << errorProb;
1922  if (iType != n_BSErrorType-1) {
1923  osErrorList << " ";
1924  osProbList << " ";
1925  }
1926  }//end ErrorType Loop
1927  //--- DB writing
1928  if (!(defecttype.empty()) || n_errorLink == 0) {
1929  n_errorLink++;
1930  if (thisBec==ENDCAP_C) {
1931  nErrLink_ECC[iDisk][iEta]++;
1932  } else if (thisBec==ENDCAP_A) {
1933  nErrLink_ECA[iDisk][iEta]++;
1934  }
1935  if (m_writeToCool) {
1936  if (m_pCalibWriteTool->createListBSErr(waferId, m_pSCTHelper, m_numberOfEvents, osErrorList.str(), osProbList.str()).isFailure()) {
1937  ATH_MSG_ERROR("Unable to run createListBSError");
1938  return StatusCode::FAILURE;
1939  }
1940  }
1941  }
1942  }// end of for iPhi
1943  }//implicit end of iEta
1944  }//implicit end of iside
1945  }//implicit end of iDisk
1946  }//end of stemIndex loop
1947  //--- Barrel
1948  for (int iLayer{0}; iLayer<n_barrels; ++iLayer) {
1949  for (int iSide{0}; iSide<2; ++iSide) {
1950  for (int iEta{0}; iEta<n_etaBins; ++iEta) {
1951  if (iEta-6==0) continue;
1952  for (int iPhi{0}; iPhi<n_phiBinsBarrel[iLayer]; ++iPhi) {
1953  defecttype.erase();
1954  n_defect.erase();
1955  std::ostringstream osErrorList;
1956  std::ostringstream osProbList;
1957  Identifier waferId{m_pSCTHelper->wafer_id(BARREL, iLayer, iPhi, iEta-6, iSide)};
1958  IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
1959  SCT_SerialNumber sn{m_CablingTool->getSerialNumberFromHash(waferHash)};
1960  nErrLink_Barrel_module_serial[iLayer][iSide][iEta][iPhi] = sn.str();
1961  IntStringMap::iterator errItr{ErrMap.begin()};
1962  IntStringMap::iterator errItrE{ErrMap.end()};
1963  for (int iType{0}; iType < n_BSErrorType; ++iType) {
1964  float errorProb{0.};
1965  unsigned long long n_errors{0};
1966  if (errItr!=errItrE and iType == errItr->first) {
1967  std::ostringstream streamHist;
1968  streamHist << "SCT_NumberOf" << errItr->second << "B" << "_" << iLayer << "_" << iSide;
1969  //histogram or might not be inside a folder with the same name
1970  std::string folder = errItr->second+std::string("/");
1971  std::string profname = "/run_" + std::to_string(m_runNumber.value()) + "/SCT/SCTB/errors/" + folder + streamHist.str();
1972  std::string profnameShort = "/run_" + std::to_string(m_runNumber.value()) + "/SCT/SCTB/errors/" + streamHist.str();
1973 
1974  TProfile2D* prof_tmp = (TProfile2D*) m_inputHist->Get( profname.c_str() );
1975  if(prof_tmp ==nullptr) {
1976  prof_tmp = (TProfile2D*) m_inputHist->Get( profnameShort.c_str() );
1977  }
1978  if(prof_tmp ==nullptr) {
1979  msg( MSG::ERROR ) << "Unable to get profile for BSErrorsDB : " << profname << endmsg;
1980  return StatusCode::FAILURE;
1981  }
1982  n_errors = static_cast<unsigned long long>(prof_tmp->GetBinContent(iEta+1, iPhi+1));
1983  if (n_errors!=0) {
1984  defecttype = m_pCalibWriteTool->addNumber(defecttype, errItr->first);
1985  n_defect = m_pCalibWriteTool->addNumber(n_defect, n_errors);
1986  errorProb = static_cast<float>(n_errors) / static_cast<float>(m_numberOfEvents);
1987  nErrs_Barrel_module[iLayer][iSide][iEta][iPhi][errItr->first] = n_errors;
1988  nErrLink_Barrel_module[iLayer][iSide][iEta][iPhi]+=n_errors;
1989 
1990  }//end if (n_errors!=0)
1991  ++errItr;
1992  }//end if (iType == (*errItr).first)
1993  osErrorList << n_errors;
1994  osProbList << errorProb;
1995  if (iType != n_BSErrorType-1) {
1996  osErrorList << " ";
1997  osProbList << " ";
1998  }
1999  } //end ErrorType Loop
2000  //--- DB writing
2001  if (!(defecttype.empty())) {
2002  n_errorLink++;
2003  nErrLink_Barrel[iLayer]++;
2004  if (m_writeToCool) {
2005  if (m_pCalibWriteTool->createListBSErr(waferId, m_pSCTHelper, m_numberOfEvents, osErrorList.str(), osProbList.str()).isFailure()) {
2006  ATH_MSG_ERROR("Unable to run createListBSError");
2007  return StatusCode::FAILURE;
2008  }
2009  }//end of if m_writeToCool
2010  } //end of if defecttype empty
2011  }//end of for iPhi
2012  }//endof for iEta, implicit end of for iSide and iLayer
2013  }
2014  }
2015 
2016  ATH_MSG_INFO("#Links which send BSError : " << n_errorLink);
2017 
2018  //--- Summary XML output
2019  std::ostringstream summaryList;
2020  for (int i{0}; i < n_disks; ++i) {
2021  for (int j{0}; j < n_etaBinsEC; ++j) {
2022  if (n_phiBinsEndcap[i][j] != 0) {
2023  summaryList << xmlPartData(ENDCAP_C, i, j, "nErrLink", nErrLink_ECC[i][j]);
2024  }
2025  }
2026  }
2027  for (int i{0}; i < n_barrels; ++i) {
2028  summaryList << xmlPartData(BARREL, i, 0, "nErrLink", nErrLink_Barrel[i]);
2029  }
2030 
2031  for (int i{0}; i < n_disks; ++i) {
2032  for (int j{0}; j < n_etaBinsEC; ++j) {
2033  if (n_phiBinsEndcap[i][j] != 0) {
2034  summaryList << xmlPartData(ENDCAP_A, i, j, "nErrLink", nErrLink_ECA[i][j]);
2035  }
2036  }
2037  }
2038 
2039  if (openXML4MonSummary(m_outBSErrSummary, "BSErrors").isFailure()) {
2040  ATH_MSG_ERROR("Problem in opening BSErrors file");
2041  return StatusCode::FAILURE;
2042  }
2043  if (wrapUpXML4Summary(m_outBSErrSummary, "BSErrors", summaryList).isFailure()) {
2044  ATH_MSG_ERROR("Problem in closing BSErrors file");
2045  return StatusCode::FAILURE;
2046  }
2047 
2048  //module XML output
2049  std::ostringstream moduleList;
2050  std::string serial;
2051  for (int i{0}; i < n_disks; ++i) {
2052  for (int j{0}; j < n_etaBinsEC; ++j) {
2053  if (n_phiBinsEndcap[i][j] != 0) {
2054  for (int k{0}; k < 2; k++) {
2055  for (int l{0}; l < n_phiBinsEndcap[i][j]; l++) {
2056  serial = nErrLink_ECC_module_serial[i][k][j][l];
2057 
2058  //fill ostringstream with number of error of each type for one particular module
2059  std::ostringstream errList;
2060  for (int errCount{0}; errCount < numberOfErrorTypes; errCount++) {
2061  int type{errorValues[errCount]}; //
2062  errList << " " << xmlValue(ErrMap[type], nErrs_ECC_module[i][k][j][l][type]) << std::endl;
2063  }
2064 
2065  moduleList << xmlModuleData(ENDCAP_C, i, k, j, l, "nErrors", nErrLink_ECC_module[i][k][j][l], serial, errList.str());
2066 
2067  }
2068  }
2069  }
2070  }
2071  }
2072 
2073 
2074  for (int i{0}; i < n_barrels; i++) {
2075  for (int j{0}; j < 2; j++) {
2076  for (int k{0}; k < n_etaBins; k++) {
2077  for (int l{0}; l < n_phiBinsBarrel[i] ; l++) {
2078  serial = nErrLink_Barrel_module_serial[i][j][k][l];
2079 
2080  std::ostringstream errList;
2081  for (int errCount{0}; errCount < numberOfErrorTypes; errCount++) {
2082  int type{errorValues[errCount]}; //
2083  errList << " " << xmlValue(ErrMap[type], nErrs_Barrel_module[i][j][k][l][type]) << std::endl;
2084  }
2085 
2086  moduleList << xmlModuleData(BARREL, i, j, k, l, "nErrors", nErrLink_Barrel_module[i][j][k][l], serial, errList.str());
2087  }
2088  }
2089  }
2090  }
2091 
2092  for (int i{0}; i < n_disks; ++i) {
2093  for (int j{0}; j < n_etaBinsEC; ++j) {
2094  if (n_phiBinsEndcap[i][j] != 0) {
2095  for (int k{0}; k < 2; k++) {
2096  for (int l{0}; l < n_phiBinsEndcap[i][j]; l++) {
2097  serial = nErrLink_ECA_module_serial[i][k][j][l];
2098 
2099  std::ostringstream errList;
2100  for (int errCount{0}; errCount < numberOfErrorTypes; errCount++) {
2101  int type{errorValues[errCount]}; //
2102  errList << " " << xmlValue(ErrMap[type], nErrs_ECA_module[i][k][j][l][type]) << std::endl;
2103  }
2104 
2105  moduleList << xmlModuleData(ENDCAP_A, i, k, j, l, "nErrors", nErrLink_ECA_module[i][k][j][l], serial, errList.str());
2106  }
2107  }
2108  }
2109  }
2110  }
2111 
2112  if (openXML4MonSummary(m_outBSErrModule, "BSErrorsModule").isFailure()) {
2113  ATH_MSG_ERROR("Problem in opening BSErrorsModule file");
2114  return StatusCode::FAILURE;
2115  }
2116  if (wrapUpXML4Summary(m_outBSErrModule, "BSErrors", moduleList).isFailure()) {
2117  ATH_MSG_ERROR("Problem in closing BSErrors file");
2118  return StatusCode::FAILURE;
2119  }
2120 
2121  //--- DB output
2122  if (m_writeToCool) {
2123  if (m_pCalibWriteTool->wrapUpBSErrors().isFailure()) {
2124  ATH_MSG_ERROR("Could not get ByteStream Errors");
2125  return StatusCode::FAILURE;
2126  }
2127  }
2128 
2129  return StatusCode::SUCCESS;
2130 }
2131 
2132 
2137 StatusCode SCTCalib::getLorentzAngle ATLAS_NOT_THREAD_SAFE () { // Thread unsafe SCTCalibWriteTool::createListLA method is used.
2138  ATH_MSG_INFO("----- in getLorentzAngle() -----");
2139 
2140  //--- Initialization
2141 
2142  float A_BarrelSide[n_barrels][2][2] = {{{0}, {0}}, {{0}, {0}}};
2143  float LA_BarrelSide[n_barrels][2][2] = {{{0}, {0}}, {{0}, {0}}};
2144  float B_BarrelSide[n_barrels][2][2] = {{{0}, {0}}, {{0}, {0}}};
2145  float Sigma_BarrelSide[n_barrels][2][2] = {{{0}, {0}}, {{0}, {0}}};
2146 
2147  float Err_A_BarrelSide[n_barrels][2][2] = {{{0}, {0}}, {{0}, {0}}};
2148  float Err_LA_BarrelSide[n_barrels][2][2] = {{{0}, {0}}, {{0}, {0}}};
2149  float Err_B_BarrelSide[n_barrels][2][2] = {{{0}, {0}}, {{0}, {0}}};
2150  float Err_Sigma_BarrelSide[n_barrels][2][2] = {{{0}, {0}}, {{0}, {0}}};
2151 
2152  float MCW_BarrelSide[n_barrels][2][2] = {{{0}, {0}}, {{0}, {0}}};
2153  float Err_MCW_BarrelSide[n_barrels][2][2] = {{{0}, {0}}, {{0}, {0}}};
2154  float Chisq_BarrelSide[n_barrels][2][2] = {{{0}, {0}}, {{0}, {0}}};
2155 
2156  std::string DBUploadFlag{"G"}; // fit status flag
2157  std::string module[2] = {"100", "111"};
2158  int moduleint[2] = {100, 111};
2159 
2160  int FitFlag[n_barrels][2][2] = {{{0}, {0}}, {{0}, {0}}}; // fit status flag
2161 
2162  TFile* fitFile;
2163 
2164 
2165  //--- Directory in HIST
2166  std::string stem;
2167 
2168  //--- Barrel
2169  stem = "/run_" + std::to_string(m_runNumber.value()) + "/SCT/GENERAL/lorentz/";
2170  m_h_phiVsNstripsSideHistoVector.clear();
2171  for (int iLayer{0}; iLayer < n_barrels ; ++iLayer) {
2172  for (int iSide{0}; iSide < 2; ++iSide) {
2173  for (int iModule{0}; iModule < 2; ++iModule) {
2174  std::ostringstream streamHist;
2175  streamHist << "h_phiVsNstrips_" << module[iModule] << "_" << iLayer << "Side" << iSide;
2176  std::string histName{stem + streamHist.str()};
2177  TProfile* hist_tmp{dynamic_cast<TProfile*>(m_inputHist->Get(histName.c_str()))};
2178  if (hist_tmp ==nullptr) {
2179  ATH_MSG_ERROR("Unable to get histogram for LorentzAngle : " << histName);
2180  return StatusCode::FAILURE;
2181  }
2182  m_h_phiVsNstripsSideHistoVector.push_back(hist_tmp);
2183  }
2184  }
2185  }
2186 
2187  //--- XML file
2188  const char* outputLorentzAngleFileName{m_LorentzAngleFile.value().c_str()};
2189  std::ofstream outFile{outputLorentzAngleFileName, std::ios::out};
2190  if (!outFile.good()) {
2191  ATH_MSG_ERROR("Unable to open LorentzAngleFile : " << outputLorentzAngleFileName);
2192  return StatusCode::FAILURE;
2193  }
2194 
2195  //--- Header for XML outputs
2196  std::ostringstream osHeader;
2197  osHeader << "<folder>" << std::endl;
2198  outFile << osHeader.str();
2199 
2200  fitFile = new TFile("FittingDebugFile.root", "RECREATE");
2201 
2202  //--- Barrel
2203  for (int iLayer{0}; iLayer < n_barrels; ++iLayer) {
2204  for (int iSide{0}; iSide < 2; ++iSide) {
2205  for (int iModule{0}; iModule < 2; ++iModule) {
2206  if (iLayer==1 and iModule==0) continue; // Layer 1 doesn't contain 100 modules
2207  ATH_MSG_INFO("LorentzAngle fit start : " << 4*iLayer + iSide +1 + iModule << " / 16");
2208  Int_t fitResult;
2209  Double_t par[4], err_par[4];
2210  TF1* LAfit{new TF1{"LAfit", LA_func, -9., 2., 4}};
2211  std::ostringstream streamFile;
2212  streamFile << "h_phiVsNstrips_" << module[iModule] << "_" << iLayer << "Side" << iSide;
2213 
2214  LAfit->SetParLimits(3, 0.1, 50.);
2215  LAfit->SetParNames("a", "LA", "b", "sigma");
2216  LAfit->SetParameters(1., -5., 1.13, 2.);
2217  fitResult = m_h_phiVsNstripsSideHistoVector[4*iLayer + 2*iSide +iModule]->Fit("LAfit", "E", "", -9., 2.);
2218  LAfit->GetParameters(par);
2219  err_par[0] = LAfit->GetParError(0);
2220  err_par[1] = LAfit->GetParError(1);
2221  err_par[2] = LAfit->GetParError(2);
2222  err_par[3] = LAfit->GetParError(3);
2223 
2224  //DEBUG MODE
2225  if (m_LorentzAngleDebugMode) {
2226  std::ostringstream streamFileTmp;
2227  streamFileTmp << "h_phiVsNstrips_" << module[iModule] << "_" << iLayer << "Side" << iSide << "_First_Fit";
2228  std::string dn{streamFile.str()};
2229  std::string tmp_hn{streamFileTmp.str()};
2230  const char* dir_name{dn.c_str()};
2231  const char* histo_name{tmp_hn.c_str()};
2232  fitFile->cd();
2233  fitFile->mkdir(dir_name); //Creating Directories
2234  fitFile->cd(dir_name);
2235  m_h_phiVsNstripsSideHistoVector[4*iLayer + 2*iSide +iModule]->SetName(histo_name);
2236  m_h_phiVsNstripsSideHistoVector[4*iLayer + 2*iSide +iModule]->Write();
2237  ATH_MSG_INFO("-------:Directory Name: " << dir_name << "--------");
2238  }
2239 
2240  if (fitResult != 0) {
2241  ATH_MSG_INFO("Try to use parabola Fit to determine initial value!");
2242  TF1* parafit{new TF1{"parafit", "[0]*(x-[1])*(x-[1])+[2]", -9., 2.}};
2243  ATH_MSG_INFO("LorentzAngle 2nd para fit start : " << 4*iLayer + iSide +1 + iModule << " / 16");
2244  parafit->SetParameters(par[0], par[1], LAfit->Eval(par[1], 0, 0, 0));
2245  m_h_phiVsNstripsSideHistoVector[4*iLayer + 2*iSide +iModule]->Fit("parafit", "R", "", -9., 2.);
2246  ATH_MSG_INFO("LorentzAngle 2nd pre fit start : " << 4*iLayer + iSide +1 + iModule << " / 16");
2247  par[1] = parafit->GetParameter(1);
2248  LAfit->SetParameters(par[0], par[1], par[2], par[3]);
2249  LAfit->SetParLimits(1, par[1], par[1]);
2250  m_h_phiVsNstripsSideHistoVector[4*iLayer + 2*iSide +iModule]->Fit("LAfit", "R", "", -9., 2.);
2251  LAfit->GetParameters(par);
2252  LAfit->SetParLimits(1, -90., 90.);
2253  LAfit->SetParameters(par[0], par[1], par[2], par[3]);
2254  ATH_MSG_INFO("LorentzAngle 2nd main fit start : " << 4*iLayer + iSide +1 + iModule << " / 16");
2255  fitResult = m_h_phiVsNstripsSideHistoVector[4*iLayer + 2*iSide +iModule]->Fit("LAfit", "E", "", -9., 2.);
2256  LAfit->GetParameters(par);
2257  if (m_LorentzAngleDebugMode) {
2258  std::ostringstream streamFileTmp;
2259  streamFileTmp << "h_phiVsNstrips_" << module[iModule] << "_" << iLayer << "Side" << iSide << "Second_Fit";
2260  std::string tmp_hn{streamFileTmp.str()};
2261  const char* histo_name{tmp_hn.c_str()};
2262  m_h_phiVsNstripsSideHistoVector[4*iLayer + 2*iSide +iModule]->SetName(histo_name);
2263  m_h_phiVsNstripsSideHistoVector[4*iLayer + 2*iSide +iModule]->Write();
2264  }
2265  }
2266 
2267  if (fitResult != 0) {
2268  ATH_MSG_INFO("Try to fix one parameter sigma=2.0 to determine other initial value!");
2269  ATH_MSG_INFO("LorentzAngle 3rd pre fit start : " << 4*iLayer + iSide +1+ iModule << " / 16");
2270  LAfit->SetParameters(par[0], par[1], par[2], 2.);
2271  LAfit->SetParLimits(3, 2., 2.);
2272  m_h_phiVsNstripsSideHistoVector[4*iLayer + 2*iSide +iModule]->Fit("LAfit", "R", "", -9., 2.);
2273  LAfit->GetParameters(par);
2274  LAfit->SetParLimits(3, 0., 50.);
2275  LAfit->SetParameters(par[0], par[1], par[2], par[3]);
2276  ATH_MSG_INFO("LorentzAngle 3rd main fit start : " << 4*iLayer + iSide +1 +iModule << " / 16");
2277  fitResult = m_h_phiVsNstripsSideHistoVector[4*iLayer + 2*iSide +iModule]->Fit("LAfit", "E", "", -9., 2.);
2278  LAfit->GetParameters(par);
2279  if (m_LorentzAngleDebugMode) {
2280  std::ostringstream streamFileTmp;
2281  streamFileTmp << "h_phiVsNstrips_" << module[iModule] << "_" << iLayer << "Side" << iSide << "Third_Fit";
2282  std::string tmp_hn{streamFileTmp.str()};
2283  const char* histo_name{tmp_hn.c_str()};
2284  m_h_phiVsNstripsSideHistoVector[4*iLayer + 2*iSide +iModule]->SetName(histo_name);
2285  m_h_phiVsNstripsSideHistoVector[4*iLayer + 2*iSide +iModule]->Write();
2286  }
2287  }
2288 
2289  if (fitResult == 0) {
2290  FitFlag[iLayer][iSide][iModule] = 1;
2291  } else {
2292  DBUploadFlag = "R";
2293  FitFlag[iLayer][iSide][iModule] = 0;
2294  ATH_MSG_WARNING("Fit Failed! Unable to get LorentzAngle");
2295  }
2296  double A{par[0]};
2297  double LA{par[1]}; // Lorentz Angle
2298  double B{par[2]};
2299  double sigma{par[3]};
2300  double err_A{err_par[0]};
2301  double err_LA{err_par[1]}; // Lorentz Angle
2302  double err_B{err_par[2]};
2303  double err_sigma{err_par[3]};
2304  float MCW{static_cast<float>(LAfit->Eval(LA, 0, 0, 0))}; //Min-cluster-width
2305  float err_MCW{static_cast<float>(LAfit->Eval(std::abs(err_par[1]), 0, 0, 0))}; //Min-cluster-width
2306 
2307  A_BarrelSide[iLayer][iSide][iModule] = A;
2308  LA_BarrelSide[iLayer][iSide][iModule] = LA;
2309  B_BarrelSide[iLayer][iSide][iModule] = B;
2310  Sigma_BarrelSide[iLayer][iSide][iModule] = sigma;
2311  Err_A_BarrelSide[iLayer][iSide][iModule] = err_A;
2312  Err_LA_BarrelSide[iLayer][iSide][iModule] = err_LA;
2313  Err_B_BarrelSide[iLayer][iSide][iModule] = err_B;
2314  Err_Sigma_BarrelSide[iLayer][iSide][iModule] = err_sigma;
2315  MCW_BarrelSide[iLayer][iSide][iModule] = MCW;
2316  Err_MCW_BarrelSide[iLayer][iSide][iModule] = err_MCW;
2317  Chisq_BarrelSide[iLayer][iSide][iModule] = LAfit->GetChisquare();
2318  }
2319  }
2320  }
2321 
2322  if (m_LorentzAngleDebugMode) {
2323  fitFile->Close();
2324  }
2325 
2326  for (int iLayer{0}; iLayer < n_barrels; ++iLayer) {
2327  for (int iSide{0}; iSide < 2; ++iSide) {
2328  for (int iModule{0}; iModule < 2; ++iModule) {
2329  Identifier waferId{m_pSCTHelper->wafer_id(BARREL, iLayer, 0, 0, iSide)};
2330  int ch{0};
2331  outFile << "<folderDefinition folder=\"SCT/Derived/LorentzAngleRun2_v2\" version=\"multi\">" << linefeed
2332  << " <folderDescription>" << linefeed
2333  << " <timeStamp>run-lumi</timeStamp>" << linefeed
2334  << " <addrHeader>" << linefeed
2335  << " <address_header service_type=\"71\" clid=\"1238547719\">" << linefeed
2336  << " </addrHeader>" << linefeed
2337  << " <typeName>CondAttrListCollection</typeName>" << linefeed
2338  << " </folderDescription>" << linefeed
2339  << " <payloadDescription>" << linefeed
2340  << " <payloadType name=\"moduleType\">" << moduleint[iModule] << "</payloadType>" << linefeed
2341  << " <payloadType name=\"lorentzAngle\">" << LA_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed
2342  << " <payloadType name=\"err_lorentzAngle\">" << Err_LA_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed
2343  << " <payloadType name=\"chisq\">" << Chisq_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed
2344  << " <payloadType name=\"fitParam_a\">" << A_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed
2345  << " <payloadType name=\"err_a\">" << Err_A_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed
2346  << " <payloadType name=\"fitParam_b\">" << B_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed
2347  << " <payloadType name=\"err_b\">" << Err_B_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed
2348  << " <payloadType name=\"fitParam_sigma\">" << Sigma_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed
2349  << " <payloadType name=\"err_sigma\">" << Err_Sigma_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed
2350  << " <payloadType name=\"minClusterWidth\">" << MCW_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed
2351  << " <payloadType name=\"err_minClusterWidth\">" << Err_MCW_BarrelSide[iLayer][iSide][iModule] << "</payloadType>" << linefeed
2352  << " </payloadDescription>" << linefeed
2353  << " <channel id=\"" << ch << "\" name=\"" << iLayer << "_" << iSide << " \" />" << linefeed
2354  << "</folderDefinition>" << std::endl;
2355 
2356  ch++;
2357 
2358  //--- DB output
2359  if (m_writeToCool) {
2360  if (m_pCalibWriteTool->createListLA(waferId, m_pSCTHelper, 10000, moduleint[iModule], LA_BarrelSide[iLayer][iSide][iModule], Err_LA_BarrelSide[iLayer][iSide][iModule], Chisq_BarrelSide[iLayer][iSide][iModule], A_BarrelSide[iLayer][iSide][iModule], Err_A_BarrelSide[iLayer][iSide][iModule], B_BarrelSide[iLayer][iSide][iModule], Err_B_BarrelSide[iLayer][iSide][iModule], Sigma_BarrelSide[iLayer][iSide][iModule], Err_Sigma_BarrelSide[iLayer][iSide][iModule], MCW_BarrelSide[iLayer][iSide][iModule], Err_MCW_BarrelSide[iLayer][iSide][iModule]).isFailure()) {
2361  ATH_MSG_ERROR("Unable to run createListLA");
2362  return StatusCode::FAILURE;
2363  }
2364  }
2365 
2366  }
2367  }
2368  }
2369 
2370  //--- Tail of XML outputs
2371  outFile << "</folder>" << std::endl;
2372 
2373  //--- Summary XML output
2374  std::ostringstream summaryList;
2375  for (int i{0}; i < n_barrels; ++i) {
2376  for (int iSide{0}; iSide < 2; ++iSide) {
2377  for (int iModule{0}; iModule < 2; ++iModule) {
2378  const std::string thisPart{shortNames[bec2Index(BARREL)]};
2379  summaryList << " <parts>" << linefeed
2380  << xmlValue("part", thisPart) << linefeed
2381  << xmlValue("layer", i) << linefeed
2382  << xmlValue("Side", iSide) << linefeed
2383  << xmlValue("Module", module[iModule]) << linefeed
2384  << xmlValue("lorentzAngle", LA_BarrelSide[i][iSide][iModule]) << linefeed
2385  << xmlValue("minClusterWidth", MCW_BarrelSide[i][iSide][iModule]) << linefeed
2386  << xmlValue("Fit", FitFlag[i][iSide][iModule]) << linefeed
2387  << " </parts>" << linefeed;
2388  }
2389  }
2390  }
2391 
2392  std::ofstream& file{m_outLASummary};
2393  using TwoStrings = std::pair<std::string, std::string>;
2394  using Names = std::map<std::string, TwoStrings>;
2395  Names nameAssociation;
2396  nameAssociation["LorentzAngle"]=TwoStrings(m_LorentzAngleSummaryFile, "LorentzAngleInfo.xsl");
2397  Names::iterator found{nameAssociation.find("LorentzAngle")};
2398  if (found!=nameAssociation.end()) {
2399  std::string filename{found->second.first};
2400  std::string xslName{found->second.second};
2401  file.open(filename.c_str(), std::ios::out);
2402  if (!file.good()) return StatusCode::FAILURE;
2403  file << xmlHeader << linefeed << associateStylesheet(xslName) << linefeed << "<run>" << std::endl;
2404  } else {
2405  ATH_MSG_ERROR(" argument \"type\" needs to be LorentzAngle.");
2406  return StatusCode::FAILURE;
2407  }
2408 
2409  file << xmlValue("RunNumber", m_runNumber.value()) << linefeed
2410  << xmlValue("StartTime", m_utcBegin) << linefeed
2411  << xmlValue("EndTime", m_utcEnd) << linefeed
2412  << xmlValue("Duration", m_calibEvtInfoTool->duration()) << linefeed
2413  << xmlValue("LB", m_LBRange) << linefeed
2414  << xmlValue("Events", m_numberOfEvents) << linefeed
2415  << xmlValue("Flag", DBUploadFlag) << linefeed
2416  << " <data>" << std::endl;
2417 
2418  if (wrapUpXML4Summary(m_outLASummary, "LorentzAngle", summaryList).isFailure()) {
2419  ATH_MSG_ERROR("Problem in closing LorentzAngle file");
2420  return StatusCode::FAILURE;
2421  }
2422 
2423  //--- DB output
2424  if (m_writeToCool) {
2425  if (m_pCalibWriteTool->wrapUpLorentzAngle().isFailure()) {
2426  ATH_MSG_ERROR("Could not get LorentzAngle");
2427  return StatusCode::FAILURE;
2428  }
2429  }
2430  return StatusCode::SUCCESS;
2431 }
2432 
2433 
2435 // Functions to handle XML File for COOL
2437 StatusCode SCTCalib::openXML4DB(std::ofstream& file, const char* type, const char* tag, IOVTime start, IOVTime end) const {
2438  if (!strcmp(type, "DeadStrip")) {
2439  file.open(m_deadStripsFile.value().c_str(), std::ios::out);
2440  if (!file.good()) return StatusCode::FAILURE;
2441  file << "<channels server=\"ATLAS_COOLPROD\" schema=\"ATLAS_COOLOFL_SCT\" dbname=\"MONP200\" folder=\"SCT/Derived/DeadStrips\" ";
2442  } else if (!strcmp(type, "DeadChip")) {
2443  file.open(m_deadChipsFile.value().c_str(), std::ios::out);
2444  if (!file.good()) return StatusCode::FAILURE;
2445  file << "<channels server=\"ATLAS_COOLPROD\" schema=\"ATLAS_COOLOFL_SCT\" dbname=\"MONP200\" folder=\"SCT/Derived/DeadChips\" ";
2446  } else {
2447  ATH_MSG_ERROR("in openXML4DB : argument \"type\" needs to be (DeadStrip, DeadChip).");
2448  return StatusCode::FAILURE;
2449  }
2450  file << "since=\"" << start.re_time() << "\" "
2451  << "until=\"" << end.re_time() << "\" "
2452  << "tag=\"" << tag << "\" "
2453  << "version=\"" << "multi\">" << linefeed;
2454  return StatusCode::SUCCESS;
2455 }
2456 
2457 
2458 StatusCode SCTCalib::closeXML4DB(std::ofstream& file) const {
2459  file << "</channels>" << std::endl;
2460  if (file.is_open()) {
2461  file.close();
2462  return StatusCode::SUCCESS;
2463  } else {
2464  return StatusCode::FAILURE;
2465  }
2466 }
2467 
2468 
2469 StatusCode SCTCalib::addToXML4DB(std::ofstream& file, const Identifier& waferId, const char* DefectType, float Threshold, const char* DefectList) const {
2470  std::string tmp{DefectList};
2471  int length{static_cast<int>(tmp.length())};
2472  std::string Defect4DB{tmp.substr(1, length-2)}; // Removing first&end spaces in DefectList
2473 
2474  file << xmlOpenChannel(m_pSCTHelper->module_id(waferId).get_identifier32().get_compact(), m_iovStart.re_time(), m_iovStop.re_time()) << linefeed
2475  << xmlValue("SampleSize", "10000") << linefeed
2476  << xmlValue("BarrelEndcap", m_pSCTHelper->barrel_ec(waferId)) << linefeed
2477  << xmlValue("Layer", m_pSCTHelper->layer_disk(waferId)) << linefeed
2478  << xmlValue("Eta", m_pSCTHelper->eta_module(waferId)) << linefeed
2479  << xmlValue("Phi", m_pSCTHelper->phi_module(waferId)) << linefeed
2480  << xmlValue("DefectType", DefectType) << linefeed
2481  << xmlValue("Threshold", Threshold) << linefeed
2482  << xmlValue("DefectList", Defect4DB) << linefeed
2483  << xmlCloseChannel() << std::endl;
2484 
2485  return StatusCode::SUCCESS;
2486 }
2487 
2488 
2490 // Functions to handle XML File for Summary
2492 StatusCode SCTCalib::openXML4DeadSummary(std::ofstream& file, const char* type, int n_Module, int n_Link, int n_Chip, int n_Strip) const {
2493  if (!strcmp(type, "DEAD")) {
2494  file.open(m_deadSummaryFile.value().c_str(), std::ios::out);
2495  if (!file.good()) return StatusCode::FAILURE;
2496  file << xmlHeader << linefeed << associateStylesheet("DeadInfo.xsl") << linefeed
2497  << "<run>" << linefeed;
2498  } else {
2499  ATH_MSG_ERROR("in openXML4DeadSummary : argument \"type\" needs to be \"DEAD\".");
2500  return StatusCode::FAILURE;
2501  }
2502 
2503  //--- Upload flag
2504  std::string strUploadFlag{"U"};
2505  bool isNonZero{false};
2506 
2508  if (n_Chip > 0) {
2509  isNonZero = true;
2510  strUploadFlag = "G";
2511  } else {
2512  strUploadFlag = "R";
2513  }
2514  }
2515 
2516  //--- Upload test result
2517  std::ostringstream osNonZero;
2518  osNonZero << "#chips or #strips is non-zero";
2519  std::ostringstream osFlagReason;
2520  if (!isNonZero) osFlagReason << "FAILED in " << osNonZero.str();
2521  std::string strFlagEnable{(m_deadChipUploadTest or m_deadStripUploadTest) ? "ENABLED" : "DISABLED"};
2522  std::ostringstream osCheckList;
2523  osCheckList << osNonZero.str();
2524 
2525  file << xmlValue("RunNumber", m_runNumber.value()) << linefeed
2526  << xmlValue("StartTime", m_utcBegin) << linefeed
2527  << xmlValue("EndTime", m_utcEnd) << linefeed
2528  << xmlValue("Duration", m_calibEvtInfoTool->duration()) << linefeed
2529  << xmlValue("LB", m_calibEvtInfoTool->numLumiBlocks()) << linefeed
2530  << xmlValue("Events", m_numberOfEvents) << linefeed
2531  << xmlValue("Modules", n_Module) << linefeed
2532  << xmlValue("Links", n_Link) << linefeed
2533  << xmlValue("Chips", n_Chip) << linefeed
2534  << xmlValue("Strips", n_Strip) << linefeed
2535  << xmlValue("Flag", strUploadFlag) << linefeed
2536  << xmlValue("FlagReason", osFlagReason.str()) << linefeed
2537  << xmlValue("FlagEnable", strFlagEnable) << linefeed
2538  << xmlValue("CheckList", osCheckList.str()) << linefeed
2539  << " <modules>" << std::endl;
2540 
2541  return StatusCode::SUCCESS;
2542 }
2543 
2544 
2545 StatusCode SCTCalib::openXML4MonSummary(std::ofstream& file, const char* type) const {
2546  using TwoStrings = std::pair<std::string, std::string>;
2547  using Names = std::map<std::string, TwoStrings>;
2548  Names nameAssociation;
2549  nameAssociation["NoiseOccupancy"] = TwoStrings(m_noiseOccupancySummaryFile, "NoiseOccupancyInfo.xsl");
2550  nameAssociation["RawOccupancy"] = TwoStrings(m_rawOccupancySummaryFile, "RawOccupancyInfo.xsl");
2551  nameAssociation["Efficiency"] = TwoStrings(m_efficiencySummaryFile, "EfficiencyInfo.xsl");
2552  nameAssociation["BSErrors"] = TwoStrings(m_BSErrorSummaryFile, "BSErrorInfo.xsl");
2553  nameAssociation["BSErrorsModule"] = TwoStrings(m_BSErrorModuleFile, "BSErrorInfo.xsl");
2554  Names::iterator found{nameAssociation.find(type)};
2555  if (found!=nameAssociation.end()) {
2556  std::string filename{found->second.first};
2557  std::string xslName{found->second.second};
2558  //
2559  file.open(filename.c_str(), std::ios::out);
2560  if (!file.good()) return StatusCode::FAILURE;
2561  file << xmlHeader << linefeed << associateStylesheet(xslName) << linefeed << "<run>" << std::endl;
2562  } else {
2563  ATH_MSG_ERROR("in openXML4MonSummary : argument \"type\" needs to be (NoiseOccupancy, RawOccupancy, Efficiency, BSErrors).");
2564  return StatusCode::FAILURE;
2565  }
2566  file << xmlValue("RunNumber", m_runNumber.value()) << linefeed
2567  << xmlValue("StartTime", m_utcBegin) << linefeed
2568  << xmlValue("EndTime", m_utcEnd) << linefeed
2569  << xmlValue("Duration", m_calibEvtInfoTool->duration()) << linefeed
2570  << xmlValue("LB", m_LBRange) << linefeed
2571  << xmlValue("Events", m_numberOfEvents) << linefeed
2572  << " <data>" << std::endl;
2573  return StatusCode::SUCCESS;
2574 }
2575 
2576 
2577 StatusCode SCTCalib::wrapUpXML4Summary(std::ofstream& file, const char* type, std::ostringstream& list) const {
2578  file << list.str();
2579  if (!strcmp(type, "DEAD")) {
2580  file << " </modules>" << std::endl;
2581  } else if (!strcmp(type, "NoiseOccupancy") or !strcmp(type, "RawOccupancy") or !strcmp(type, "Efficiency") or !strcmp(type, "BSErrors") or !strcmp(type, "LorentzAngle")) {
2582  file << " </data>" << std::endl;
2583  }
2584  file << "</run>" << std::endl;
2585 
2586  if (file.is_open()) {
2587  file.close();
2588  return StatusCode::SUCCESS;
2589  } else {
2590  return StatusCode::FAILURE;
2591  }
2592 }
2593 
2594 
2595 StatusCode SCTCalib::addToSummaryStr(std::ostringstream& list, const Identifier& waferId, const char* type, const char* stripId, const char* chipId) const {
2596  //--- Remove first&end spaces in DefectList
2597  const std::string tmpstrip{stripId};
2598  const std::string tmpchip{chipId};
2599  int len_strip{static_cast<int>(tmpstrip.length())};
2600  int len_chip{static_cast<int>(tmpchip.length())};
2601  std::string stripList{""};
2602  std::string chipList{""};
2603  if (len_strip > 0) {
2604  int stringLength = (len_strip-2 >0) ? len_strip-2 : len_strip;
2605  stripList = tmpstrip.substr(1, stringLength);
2606  }
2607  if (len_chip > 0) {
2608  int stringLength = (len_chip-2 >0) ? len_chip-2 : len_chip;
2609  chipList = tmpchip.substr(1, stringLength);
2610  }
2611  //--- Identifier/SN
2612  IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
2613  SCT_SerialNumber sn{m_CablingTool->getSerialNumberFromHash(waferHash)};
2614  //--- Preparing linkList
2615  std::string linkList{chipList2LinkList(stripList)};
2616  //--- Push to summary stream
2617  XmlStreamer m{"module", list};
2618  {
2619  XmlStreamer v{"value", "name", "SN", list};
2620  list << sn.str();
2621  }
2622  {
2623  XmlStreamer v{"value", "name", "BecLayerPhiEta", list};
2624  list << formatPosition(waferId, m_pSCTHelper, ".", false);
2625  }
2626  {
2627  XmlStreamer v{"value", "name", "LinkID", list};
2628  list << linkList;
2629  }
2630  {
2631  XmlStreamer v{"value", "name", "ChipID", list};
2632  list << stripList;
2633  }
2634  if (!strcmp(type, "DEAD")) {
2635  XmlStreamer v{"value", "name", "StripIDOnline", list};
2636  list << stripList;
2637  } else {
2638  ATH_MSG_ERROR("in addToSummaryStr : argument \"type\" needs to be \"DEAD\".");
2639  return StatusCode::FAILURE;
2640  }
2641 
2642  return StatusCode::SUCCESS;
2643 }
2644 
2645 
2646 std::string
2647 SCTCalib::xmlChannelNoiseOccDataString(const Identifier& waferId, const float occupancy, const SCT_SerialNumber& serial) const {
2648  std::ostringstream os;
2649  os << xmlOpenChannel(waferId.get_identifier32().get_compact(), m_iovStart.re_time(), m_iovStop.re_time()) << std::endl
2650  << " " << xmlValue("SN", serial.str()) << std::endl
2651  << " " << xmlValue("SampleSize", "10000") << std::endl
2652  << " " << xmlValue("barrel_endcap", m_pSCTHelper->barrel_ec(waferId)) << std::endl
2653  << " " << xmlValue("Layer", m_pSCTHelper->layer_disk(waferId)) << linefeed
2654  << " " << xmlValue("Eta", m_pSCTHelper->eta_module(waferId)) << std::endl
2655  << " " << xmlValue("Phi", m_pSCTHelper->phi_module(waferId)) << std::endl
2656  << " " << xmlValue("NoiseOccupancy", occupancy) << std::endl
2657  << " " << xmlCloseChannel();
2658  return os.str();
2659 }
2660 
2661 
2662 std::string
2663 SCTCalib::xmlChannelEfficiencyDataString(const Identifier& waferId, const float efficiency, const SCT_SerialNumber& serial, const int side) const {
2664  std::ostringstream os;
2665  os << " <module>" << std::endl
2666  << " " << xmlValue("SN", serial.str()) << std::endl
2667  << " " << xmlValue("SampleSize", "10000") << std::endl
2668  << " " << xmlValue("barrel_endcap", m_pSCTHelper->barrel_ec(waferId)) << std::endl
2669  << " " << xmlValue("Layer", m_pSCTHelper->layer_disk(waferId)) << linefeed
2670  << " " << xmlValue("Eta", m_pSCTHelper->eta_module(waferId)) << std::endl
2671  << " " << xmlValue("Phi", m_pSCTHelper->phi_module(waferId)) << std::endl
2672  << " " << xmlValue("Efficiency", efficiency) << std::endl
2673  << " " << xmlValue("Side", side )<<std::endl
2674  << " </module>";
2675  return os.str();
2676 }
2677 
2678 
2679 std::string
2680 SCTCalib::xmlChannelEfficiencyDataStringChip(const Identifier& waferId, const float efficiency, const float efficiency_bcid, const SCT_SerialNumber& serial, const int side, const int chip) const {
2681  std::ostringstream os;
2682  os << " <chip>" << std::endl
2683  << " " << xmlValue("SN", serial.str()) << std::endl
2684  << " " << xmlValue("SampleSize", "10000") << std::endl
2685  << " " << xmlValue("barrel_endcap", m_pSCTHelper->barrel_ec(waferId)) << std::endl
2686  << " " << xmlValue("Layer", m_pSCTHelper->layer_disk(waferId)) << linefeed
2687  << " " << xmlValue("Eta", m_pSCTHelper->eta_module(waferId)) << std::endl
2688  << " " << xmlValue("Phi", m_pSCTHelper->phi_module(waferId)) << std::endl
2689  << " " << xmlValue("Side", side )<<std::endl
2690  << " " << xmlValue("Chip", chip )<<std::endl
2691  << " " << xmlValue("Efficiency", efficiency) << std::endl
2692  << " " << xmlValue("Efficiency_bcid", efficiency_bcid) << std::endl
2693  << " </chip>";
2694  return os.str();
2695 }
2696 
2697 std::pair<int, bool>
2698 SCTCalib::getNumNoisyStrips(const Identifier& waferId) const {
2699  IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
2700  //--- Check if there are noisy strips in the wafer
2701  int numNoisyStripsInTheWafer{0};
2702  bool isNoisyWafer{false};
2704  for (int iStrip{0}; iStrip != nbins; ++iStrip) {
2705  if ( (float) m_calibHitmapTool->getBinForHistogramIndex(iStrip + 1, waferHash.value()) / m_numberOfEvents > noisyStripThr) ++numNoisyStripsInTheWafer;
2706  }
2707  //--- Define/counts noisy wafers using wafer occupancy and number of noisy strips
2708  double averageOccupancy{m_calibHitmapTool->size(waferHash.value())/static_cast<double>(nbins)/static_cast<double>(m_numberOfEvents)};
2709  const int subdetector{m_pSCTHelper->barrel_ec(waferId)};
2710  isNoisyWafer = (numNoisyStripsInTheWafer > m_noisyWaferFraction*nbins) and
2711  ((subdetector == ENDCAP_C and averageOccupancy > m_noisyWaferThrECC) or
2712  (subdetector == BARREL and averageOccupancy > m_noisyWaferThrBarrel) or
2713  (subdetector == ENDCAP_A and averageOccupancy > m_noisyWaferThrECA));
2714  if (isNoisyWafer) {
2715  ATH_MSG_INFO("Module: " << waferHash.value());
2716  ATH_MSG_INFO("Hits, Nevts, Occ: " << m_calibHitmapTool->size(waferHash.value()) << ", "
2717  << m_numberOfEvents << ", "
2718  << averageOccupancy);
2719  }
2720  return std::make_pair(numNoisyStripsInTheWafer, isNoisyWafer);
2721 }
2722 
2723 
2724 StatusCode
2725 SCTCalib::addStripsToList(Identifier& waferId, std::set<Identifier>& stripIdList, bool isNoisy, bool isNew) const {
2726  IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
2728  for (int iStrip{0}; iStrip != nbins; ++iStrip) {
2729  Identifier stripId{m_pSCTHelper->strip_id(waferId, iStrip)};
2730  if (!isNoisy) { //--- Add all strips
2731  stripIdList.insert(stripId);
2732  } else {
2733  const float stripOccupancy{ (float) m_calibHitmapTool->getBinForHistogramIndex(iStrip + 1, waferHash.value()) / m_numberOfEvents};
2734  if (stripOccupancy > noisyStripThr) {
2735  if (!isNew) { //--- All noisy strips
2736  stripIdList.insert(stripId);
2737  } else { //--- New noisy strips : compared with configuration and calibration
2738  const bool isGoodInConfiguration{m_useConfiguration ? m_ConfigurationConditionsTool->isGood(stripId, InDetConditions::SCT_STRIP) : true};
2739  const bool isGoodInCalibration{m_useCalibration ? m_ReadCalibDataTool->isGood(stripId, InDetConditions::SCT_STRIP) : true};
2741  if (isGoodInConfiguration and isGoodInCalibration) {
2742  stripIdList.insert(stripId);
2743  }
2744  }
2745  }
2746  }
2747  }
2748  }
2749  return StatusCode::SUCCESS;
2750 }
2751 
2752 
2753 StatusCode
2754 SCTCalib::writeModuleListToCool ATLAS_NOT_THREAD_SAFE // Thread unsafe SCTCalibWriteTool::createListStrip method is used.
2755 (const std::map<Identifier, std::set<Identifier>>& moduleListAll,
2756  const std::map<Identifier, std::set<Identifier>>& moduleListNew,
2757  const std::map<Identifier, std::set<Identifier>>& moduleListRef) {
2758  //--- Write out strips
2759  float noisyStripThr{m_noisyStripThrDef?(m_noisyStripThrOffline):(m_noisyStripThrOnline)};
2760  int nDefects{0};
2761  SCT_ID::const_id_iterator idItr{m_pSCTHelper->wafer_begin()};
2762  SCT_ID::const_id_iterator idItrE{m_pSCTHelper->wafer_end()};
2763  for (; idItr != idItrE; ++idItr) {
2764  if (m_pSCTHelper->side(*idItr) == 0) {
2765  Identifier moduleId{m_pSCTHelper->module_id(*idItr)};
2766  std::map<Identifier, std::set<Identifier>>::const_iterator moduleAllItr{moduleListAll.find(moduleId)};
2767  std::map<Identifier, std::set<Identifier>>::const_iterator moduleNewItr{moduleListNew.find(moduleId)};
2768  std::map<Identifier, std::set<Identifier>>::const_iterator moduleRefItr{moduleListRef.find(moduleId)};
2769  std::string defectStripsAll{moduleAllItr != moduleListAll.end() ? getStripList((*moduleAllItr).second) : ""};
2770  std::string defectStripsNew{moduleNewItr != moduleListNew.end() ? getStripList((*moduleNewItr).second) : ""};
2771  std::string defectStripsRef{moduleRefItr != moduleListRef.end() ? getStripList((*moduleRefItr).second) : ""};
2772  if (m_noisyUpdate) { //--- UPD1/UPD4
2773  if (defectStripsAll != defectStripsRef) {
2774  if (m_pCalibWriteTool->createCondObjects(moduleId, m_pSCTHelper, 10000, "NOISY", noisyStripThr, defectStripsAll).isFailure()) {
2775  ATH_MSG_ERROR("Could not create defect strip entry in the CalibWriteTool.");
2776  }
2777  nDefects++;
2778  };
2779  } else {
2780  if (m_noisyStripAll) { //--- ALL noisy strips
2781  if (!defectStripsAll.empty() || m_noisyWriteAllModules) {
2782  if (m_pCalibWriteTool->createCondObjects(moduleId, m_pSCTHelper, 10000, "NOISY", noisyStripThr, defectStripsAll).isFailure()) {
2783  ATH_MSG_ERROR("Could not create defect strip entry in the CalibWriteTool.");
2784  }
2785  }
2786  } else { //--- Only NEW noisy strips
2787  if (!defectStripsNew.empty()) {
2788  if (m_pCalibWriteTool->createCondObjects(moduleId, m_pSCTHelper, 10000, "NOISY", noisyStripThr, defectStripsNew).isFailure()) {
2789  ATH_MSG_ERROR("Could not create defect strip entry in the CalibWriteTool.");
2790  }
2791  }
2792  }
2793  }
2794  }
2795  }
2796  ATH_MSG_DEBUG("Number of modules for which conditions were created: " << nDefects << " !!!!");
2797  if (moduleListAll.empty() or ( nDefects==0 && m_noisyUpdate )) {
2798  ATH_MSG_INFO("Number of noisy strips was zero or the same list of noisy strips. No local DB was created.");
2799  } else {
2800  ATH_MSG_DEBUG("directly before call of wrapUpNoisyChannel");
2801  if (m_pCalibWriteTool->wrapUpNoisyChannel().isFailure()) {
2802  ATH_MSG_ERROR("Could not get NoisyStrips info");
2803  return StatusCode::FAILURE;
2804  }
2805  }
2806  ATH_MSG_DEBUG("before return");
2807  return StatusCode::SUCCESS;
2808 }
2809 
2810 
2811 std::set<Identifier>
2812 SCTCalib::getOverlapStripList( const std::set<Identifier>& stripAllIdList, const std::set<Identifier>& stripRefIdList ) const {
2813  std::set<Identifier> stripList;
2814  std::set<Identifier>::const_iterator stripAllItrLast = stripAllIdList.end();
2815  std::set<Identifier>::const_iterator stripRefItrLast = stripRefIdList.end();
2816 
2817  std::set<Identifier>::const_iterator stripAllItr = stripAllIdList.begin();
2818  for ( ; stripAllItr != stripAllItrLast; ++stripAllItr ) {
2819  std::set<Identifier>::const_iterator stripRefItr = stripRefIdList.begin();
2820  bool old = false;
2821  for ( ; stripRefItr != stripRefItrLast; ++stripRefItr ) {
2822  if (*stripAllItr == *stripRefItr) old = true;
2823  }
2824  if (!old) {
2825  stripList.insert(*stripAllItr);
2826  }
2827  }
2828  return stripList;
2829 }
2830 
2831 
2832 std::string
2833 SCTCalib::getStripList(const std::set<Identifier>& stripIdList) const {
2834  std::string strList;
2835  if (!stripIdList.empty()) {
2836  int firstStrip{-1};
2837  int groupSize{-1};
2838 
2839  std::set<Identifier>::const_iterator stripItrFirst{stripIdList.begin()};
2840  std::set<Identifier>::const_iterator stripItrLast{--stripIdList.end()};
2841 
2842  std::set<Identifier>::const_iterator stripItr{stripIdList.begin()};
2843  std::set<Identifier>::const_iterator stripItrE{stripIdList.end()};
2844  for (; stripItr != stripItrE; ++stripItr) {
2845  Identifier stripId{*stripItr};
2846  int stripNum{m_pSCTHelper->side(stripId)*nbins + m_pSCTHelper->strip(stripId)};
2847  if (stripItr == stripItrFirst) {
2848  firstStrip = stripNum;
2849  groupSize = 1;
2850  } else {
2851  if (stripNum == firstStrip + groupSize) {
2852  ++groupSize;
2853  } else {
2854  int stripBegin{firstStrip};
2855  int stripEnd{firstStrip + groupSize -1};
2856  strList = m_pCalibWriteTool->addDefect(strList, stripBegin, stripEnd);
2857  firstStrip = stripNum;
2858  groupSize = 1;
2859  }
2860  }
2861  if (stripItr == stripItrLast) {
2862  int stripBegin{firstStrip};
2863  int stripEnd{stripNum};
2864  strList = m_pCalibWriteTool->addDefect(strList, stripBegin, stripEnd);
2865  }
2866  }
2867  }
2868  return strList;
2869 }
2870 
2871 
2872 StatusCode
2873 SCTCalib::noisyStripsToXml(const std::map<Identifier, std::set<Identifier>>& moduleList, const std::string& badStripsFile) const {
2874  //--- Open
2875  const char* outputFileName{badStripsFile.c_str()};
2876  std::ofstream outFile{outputFileName, std::ios::out};
2877  if (!outFile.good()) {
2878  ATH_MSG_ERROR("Unable to open " << outputFileName);
2879  return(StatusCode::FAILURE);
2880  }
2882  //--- Create module list
2883  std::ostringstream osModuleList;
2884  //--- Loop over wafers
2887  for (; waferItr != waferItrE; ++waferItr) {
2888  Identifier waferId{*waferItr};
2889  Identifier moduleId{m_pSCTHelper->module_id(waferId)};
2890  if (m_pSCTHelper->side(waferId) != 0) continue;
2891  std::map< Identifier, std::set<Identifier> >::const_iterator moduleItr{moduleList.find(moduleId)};
2892  if (moduleItr != moduleList.end()) {
2893  std::string defectStrips{getStripList((*moduleItr).second)};
2894  osModuleList << " <channel id=\"" << m_pSCTHelper->module_id(waferId).get_compact() << "\" "
2895  << "since=\"" << m_iovStart.re_time() << "\" "
2896  << "until=\"" << m_iovStop.re_time() << "\">" << linefeed
2897  << " <value name=\"SampleSize\">" << "10000" << "</value>" << linefeed
2898  << " <value name=\"BarrelEndcap\">" << m_pSCTHelper->barrel_ec(waferId) << "</value>" << linefeed
2899  << " <value name=\"Layer\">" << m_pSCTHelper->layer_disk(waferId) << "</value>" << linefeed
2900  << " <value name=\"Eta\">" << m_pSCTHelper->eta_module(waferId) << "</value>" << linefeed
2901  << " <value name=\"Phi\">" << m_pSCTHelper->phi_module(waferId) << "</value>" << linefeed
2902  << " <value name=\"DefectType\">" << "NOISY" << "</value>" << linefeed
2903  << " <value name=\"Threshold\">" << noisyStripThr << "</value>" << linefeed
2904  << " <value name=\"DefectList\">" << normalizeList(defectStrips) << "</value>" << linefeed
2905  << " </channel>" << std::endl;
2906  }
2907  }
2908  //--- Write out the contents
2909  outFile << "<channels server=\"ATLAS_COOLPROD\" schema=\"ATLAS_COOLOFL_SCT\" dbname=\"CONDBR2\" folder=\"SCT/Derived/Monitoring\" "
2910  << "since=\"" << m_iovStart.re_time() << "\" "
2911  << "until=\"" << m_iovStop.re_time() << "\" "
2912  << "tag=\"" << m_tagID4NoisyStrips << "\" "
2913  << "version=\"" << "multi\">" << std::endl
2914  << osModuleList.str()
2915  << "</channels>" << std::endl;
2916 
2917  return StatusCode::SUCCESS;
2918 }
2919 
2920 
2921 StatusCode SCTCalib::noisyStripsToSummaryXml(const std::map<Identifier, std::set<Identifier>>& moduleListAll,
2922  const std::map<Identifier, std::set<Identifier>>& moduleListRef,
2923  const std::string& badStripsFile) const {
2924 
2925  ATH_MSG_DEBUG("noisyStripsToSummaryXml: start");
2926 
2927  //--- Open
2928  const char* outputFileName{badStripsFile.c_str()};
2929  std::ofstream outFile{outputFileName, std::ios::out};
2930  if (!outFile.good()) {
2931  ATH_MSG_ERROR("Unable to open " << outputFileName);
2932  return(StatusCode::FAILURE);
2933  }
2934 
2935  //--- Initialization
2936  int numLinksAll{0}, numChipsAll{0};
2937  int numModulesAll{0}, numModulesRef{0};
2938  int numStripsAll{0}, numStripsNew{0}, numStripsRef{0};
2939  int numModulesDiff{0};
2940 
2941  std::string defectLinks, defectChips;
2942  std::string defectStripsAll, defectStripsNew, defectStripsRef;
2943  std::ostringstream osModuleList, osChipList;
2944 
2945  //--- Create module list
2948  ATH_MSG_DEBUG("noisyStripsToSummaryXml: before wafer loop");
2949  for (; waferItr != waferItrE; ++waferItr) {
2950  //--- Identifier
2951  Identifier waferId{*waferItr};
2952  Identifier moduleId{m_pSCTHelper->module_id(waferId)};
2953  IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
2954  SCT_SerialNumber sn{m_CablingTool->getSerialNumberFromHash(waferHash)};
2955 
2956  //--- Initialization for a module
2957  if (m_pSCTHelper->side(waferId) == 0) {
2958  defectLinks.erase();
2959  defectChips.erase();
2960  defectStripsAll.erase();
2961  defectStripsNew.erase();
2962  defectStripsRef.erase();
2963  }
2964 
2965  //--- Noisy links
2966  bool isNoisyWafer{getNumNoisyStrips(waferId).second}; // true if this wafer is noisy
2967  if (isNoisyWafer) {
2968  int link{m_pSCTHelper->side(waferId)};
2969  defectLinks = m_pCalibWriteTool->addDefect(defectLinks, link, link);
2970  ++numLinksAll;
2971  }
2972 
2973  //--- Execute once in this module
2974  if (m_pSCTHelper->side(waferId) == 1) {
2975  ATH_MSG_DEBUG("noisyStripsToSummaryXml: ALL");
2976  //--- Noisy strips : All
2977  std::map< Identifier, std::set<Identifier> >::const_iterator moduleAllItr{moduleListAll.find(moduleId)};
2978  if (moduleAllItr != moduleListAll.end()) {
2979  defectStripsAll = getStripList((*moduleAllItr).second);
2980  ++numModulesAll;
2981  numStripsAll += (*moduleAllItr).second.size();
2982  }
2983 
2984  ATH_MSG_DEBUG("noisyStripsToSummaryXml: REF");
2985  //--- Noisy strips : Ref
2986  std::map< Identifier, std::set<Identifier> >::const_iterator moduleRefItr{moduleListRef.find(moduleId)};
2987  if (moduleRefItr != moduleListRef.end()) {
2988  defectStripsRef = getStripList(moduleRefItr->second);
2989  ++numModulesRef;
2990  numStripsRef += moduleRefItr->second.size();
2991  }
2992 
2993  ATH_MSG_DEBUG("noisyStripsToSummaryXml: NEW");
2994  //--- Noisy strips : New
2995  if ( moduleAllItr != moduleListAll.end() ) {
2996  if ( moduleRefItr != moduleListRef.end() ) {
2997  std::set<Identifier> listNEW = getOverlapStripList( (*moduleAllItr).second, (*moduleRefItr).second );
2998  defectStripsNew = getStripList( listNEW );
2999  numStripsNew += listNEW.size();
3000  } else {
3001 
3002  defectStripsNew = getStripList( (*moduleAllItr).second );
3003  }
3004  }
3005 
3006  ATH_MSG_DEBUG("noisyStripsToSummaryXml: stripIdList -> chipIdList");
3007  //--- Noisy chips : stripIdList -> chipIdList
3008  if (moduleAllItr != moduleListAll.end()) {
3009  std::set<int> chipIdList{getNoisyChips(moduleAllItr->second)};
3010  if (!chipIdList.empty()) {
3011  ++numChipsAll;
3012  std::set<int>::iterator chipItr{chipIdList.begin()};
3013  std::set<int>::iterator chipItrE{chipIdList.end()};
3014  for (; chipItr != chipItrE; ++chipItr) {
3015  int chipId{*chipItr};
3016  //--- To be written into module list
3017  defectChips = m_pCalibWriteTool->addDefect(defectChips, chipId, chipId);
3018  //--- LBs where this chip was noisy
3019  std::pair< std::string, float > defectLB{getNoisyLB(moduleId, chipId)};
3020  //--- Chip list written to XML
3021  osChipList << " <chip>" << linefeed
3022  << " <value name=\"SN\">" << sn.str() << "</value>" << linefeed
3023  << " <value name=\"BecLayerPhiEta\">" << m_pSCTHelper->barrel_ec(waferId) << "."
3024  << m_pSCTHelper->layer_disk(waferId) << "."
3025  << m_pSCTHelper->phi_module(waferId) << "."
3026  << m_pSCTHelper->eta_module(waferId) << "</value>" << linefeed
3027  << " <value name=\"ChipID\">" << chipId << "</value>" << linefeed
3028  << " <value name=\"LB\">" << normalizeList(defectLB.first) << "</value>" << linefeed
3029  << " <value name=\"LBFraction\">" << defectLB.second << "</value>" << linefeed
3030  << " </chip>" << std::endl;
3031  }
3032  }
3033  }
3034  ATH_MSG_DEBUG("noisyStripsToSummaryXml: Difference between All & Ref");
3035  //--- Difference between All & Ref
3036  if (defectStripsAll != defectStripsRef) ++numModulesDiff;
3037  //--- Module list written to XML
3038  if (!defectStripsAll.empty() or (m_noisyUpdate and defectStripsAll != defectStripsRef)) {
3039  osModuleList << " <module>" << linefeed
3040  << " <value name=\"SN\">" << sn.str() << "</value>" << linefeed
3041  << " <value name=\"BecLayerPhiEta\">" << m_pSCTHelper->barrel_ec(waferId) << "."
3042  << m_pSCTHelper->layer_disk(waferId) << "."
3043  << m_pSCTHelper->phi_module(waferId) << "."
3044  << m_pSCTHelper->eta_module(waferId) << "</value>" << linefeed
3045  << " <value name=\"LinkID\">" << normalizeList(defectLinks) << "</value>" << linefeed
3046  << " <value name=\"ChipID\">" << normalizeList(defectChips) << "</value>" << linefeed
3047  << " <value name=\"StripOfflineAll\">" << normalizeList(defectStripsAll) << "</value>" << linefeed
3048  << " <value name=\"StripOfflineNew\">" << normalizeList(defectStripsNew) << "</value>" << linefeed
3049  << " <value name=\"StripOfflineRef\">" << normalizeList(defectStripsRef) << "</value>" << linefeed
3050  << " </module>" << std::endl;
3051  }
3052  ATH_MSG_DEBUG("noisyStripsToSummaryXml: After Difference between All & Ref");
3053  }
3054  }//--- end loop : waferItr
3055 
3056  ATH_MSG_DEBUG("noisyStripsToSummaryXml: after waferItr");
3057 
3058  //--- Upload flag
3059  std::string strUploadFlag{"U"};
3060 
3061  bool isRunsInCool{false};
3062  bool isNoisyMinStat{false}, isNoisyModuleList{false}, isNoisyModuleDiff{false}, isNoisyStripDiff{false};
3063  if (m_noisyUploadTest) {
3064  isRunsInCool = ((m_noisyModuleAverageInDB != -1.) and (m_noisyStripLastRunInDB != -999));
3065  if (isRunsInCool) {
3066  isNoisyMinStat = m_numberOfEvents > m_noisyMinStat;
3067  isNoisyModuleList = numModulesAll < m_noisyModuleList;
3068  isNoisyModuleDiff = ((static_cast<float>(numModulesAll) - m_noisyModuleAverageInDB)/m_noisyModuleAverageInDB) < m_noisyModuleDiff;
3069  isNoisyStripDiff = ((static_cast<float>(numStripsAll) - m_noisyStripAverageInDB)/m_noisyStripAverageInDB) < m_noisyStripDiff;
3070  if (!isNoisyMinStat or !isNoisyModuleList) {
3071  strUploadFlag = "R";
3072  } else {
3073  if (!isNoisyModuleDiff or !isNoisyStripDiff) {
3074  strUploadFlag = "Y";
3075  } else {
3076  strUploadFlag = "G";
3077  }
3078  }
3079  }
3080  }
3081 
3082  ATH_MSG_DEBUG("noisyStripsToSummaryXml: after FlagChecking");
3083 
3084  //--- Upload test result to XML
3085  std::ostringstream osNoisyMinStat, osNoisyModuleList, osNoisyModuleDiff, osNoisyStripDiff;
3086  osNoisyMinStat << "#events more than " << m_noisyMinStat.value();
3087  osNoisyModuleList << "#(modules w/ at least 1 noisy strip) less than " << m_noisyModuleList.value();
3088  osNoisyModuleDiff << "Increase of #(modules w/ at least 1 noisy strip) from average of recent runs less than " << m_noisyModuleDiff*100 << "%";
3089  osNoisyStripDiff << "Increase of #(noisy strips) from average of recent runs less than " << m_noisyStripDiff*100 << "%";
3090 
3091  std::ostringstream osFlagReason;
3092  if (!isNoisyMinStat) osFlagReason << "FAILED in " << osNoisyMinStat.str() << "; ";
3093  if (!isNoisyModuleList) osFlagReason << "FAILED in " << osNoisyModuleList.str() << "; ";
3094  if (!isNoisyModuleDiff) osFlagReason << "FAILED in " << osNoisyModuleDiff.str() << "; ";
3095  if (!isNoisyStripDiff) osFlagReason << "FAILED in " << osNoisyStripDiff.str();
3096 
3097  std::string strFlagEnable = m_noisyUploadTest ? "ENABLED" : "DISABLED";
3098  std::string strRunsInCool = isRunsInCool ? "AVAILABLE" : "UNAVAILABLE";
3099 
3100  std::ostringstream osCheckList;
3101  osCheckList << osNoisyMinStat.str() << "; "
3102  << osNoisyModuleList.str() << "; "
3103  << osNoisyModuleDiff.str() << "; "
3104  << osNoisyStripDiff.str();
3105 
3106  //--- Write out the contents to XML file
3107  outFile << xmlHeader << linefeed
3108  << associateStylesheet("BadStrips.xsl") << linefeed
3109  << "<run>" << linefeed
3110  << " <value name=\"RunNumber\">" << m_runNumber.value() << "</value>" << linefeed
3111  << " <value name=\"StartTime\">" << m_utcBegin << "</value>" << linefeed
3112  << " <value name=\"EndTime\">" << m_utcEnd << "</value>" << linefeed
3113  << " <value name=\"Duration\">" << m_calibEvtInfoTool->duration() << "</value>" << linefeed
3114  << " <value name=\"LB\">" << m_numOfLBsProcessed << "</value>" << linefeed
3115  << " <value name=\"Events\">" << m_numberOfEvents << "</value>" << linefeed
3116  << " <value name=\"Modules\">" << numModulesAll << "</value>" << linefeed
3117  << " <value name=\"Links\">" << numLinksAll << "</value>" << linefeed
3118  << " <value name=\"Chips\">" << numChipsAll << "</value>" << linefeed
3119  << " <value name=\"StripsOfflineAll\">" << numStripsAll << "</value>" << linefeed
3120  << " <value name=\"StripsOfflineNew\">" << numStripsNew << "</value>" << linefeed
3121  << " <value name=\"ModulesRef\">" << numModulesRef << "</value>" << linefeed
3122  << " <value name=\"StripsOfflineRef\">" << numStripsRef << "</value>" << linefeed
3123  << " <value name=\"ModulesDiff\">" << numModulesDiff << "</value>" << linefeed
3124  << " <value name=\"Flag\">" << strUploadFlag << "</value>" << linefeed
3125  << " <value name=\"FlagReason\">" << osFlagReason.str() << "</value>" << linefeed
3126  << " <value name=\"FlagEnable\">" << strFlagEnable << "</value>" << linefeed
3127  << " <value name=\"ReadCool\">" << strRunsInCool << "</value>" << linefeed
3128  << " <value name=\"CheckList\">" << osCheckList.str() << "</value>" << linefeed
3129  << " <chips>" << linefeed
3130  << osChipList.str()
3131  << " </chips>" << linefeed
3132  << " <modules>" << linefeed
3133  << osModuleList.str()
3134  << " </modules>" << linefeed
3135  << "</run>" << std::endl;
3136 
3137  ATH_MSG_DEBUG("noisyStripsToSummaryXml: before return");
3138 
3139  return StatusCode::SUCCESS;
3140 }
3141 
3142 
3143 std::set<int>
3144 SCTCalib::getNoisyChips(const std::set<Identifier>& stripIdList) const {
3145  std::set<int> chipIdList;
3146  chipIdList.clear();
3147 
3148  // Get SCT_DetectorElementCollection
3150  const InDetDD::SiDetectorElementCollection* elements{sctDetEle.retrieve()};
3151  if (elements==nullptr) {
3152  ATH_MSG_FATAL(m_SCTDetEleCollKey.fullKey() << " could not be retrieved");
3153  return chipIdList;
3154  }
3155 
3156  //--- Minimum number of noisy strips for a noisy chip
3157  unsigned int noisyChipThr{static_cast<unsigned int>(m_noisyChipFraction*n_stripPerChip)};
3158  if (stripIdList.size() > noisyChipThr) {
3159  unsigned int numStripsPerChip[n_chipPerModule] = {0};
3160  //--- Loop over stripIdList
3161  std::set<Identifier>::const_iterator stripItr{stripIdList.begin()};
3162  std::set<Identifier>::const_iterator stripItrE{stripIdList.end()};
3163  for (; stripItr != stripItrE; ++stripItr) {
3164  Identifier stripId{*stripItr};
3165  int stripOffline{m_pSCTHelper->strip(stripId)};
3166  //--- Chip number : taken from SCT_ConfigurationConditionsTool::getChip
3167  IdentifierHash waferHash{m_pSCTHelper->wafer_hash(m_pSCTHelper->wafer_id(stripId))};
3168  const InDetDD::SiDetectorElement* pElement{elements->getDetectorElement(waferHash)};
3169  if (!pElement) {
3170  ATH_MSG_FATAL("Element pointer is nullptr");
3171  continue;
3172  }
3173  int stripOnline{(pElement->swapPhiReadoutDirection()) ? lastStrip - stripOffline : stripOffline};
3174  int chipId{m_pSCTHelper->side(stripId) == 0 ? stripOnline/n_stripPerChip : stripOnline/n_stripPerChip + n_chipPerSide};
3175  //--- Count number of noisy strips per chips
3176  ++numStripsPerChip[chipId];
3177  }
3178 
3179  //--- Insert noisy chips
3180  for (int iChip{0}; iChip != n_chipPerModule; ++iChip) {
3181  if (numStripsPerChip[iChip] > noisyChipThr) chipIdList.insert(iChip);
3182  }
3183  }
3184  return chipIdList;
3185 }
3186 
3187 
3188 std::pair< std::string, float >
3189 SCTCalib::getNoisyLB(const Identifier& moduleId, int& chipId) const {
3190  std::string defectLB{""}; //return value if invalid
3191  float defectLBFrac{0.0}; //return value if invalid
3193 
3194  //--- Identifier
3195  Identifier waferId{m_pSCTHelper->wafer_id(m_pSCTHelper->barrel_ec(moduleId),
3196  m_pSCTHelper->layer_disk(moduleId),
3197  m_pSCTHelper->phi_module(moduleId),
3198  m_pSCTHelper->eta_module(moduleId),
3199  chipId < n_chipPerSide ? 0 : 1)};
3200  IdentifierHash waferHash{m_pSCTHelper->wafer_hash(waferId)};
3201  //--- Histogram for this chip
3202  int chipPositionInSide{m_pSCTHelper->side(waferId) == 0 ? chipId : chipId - n_chipPerSide};
3203  int histIndex{static_cast<int>((waferHash.value())*n_chipPerSide + chipPositionInSide)};
3204 
3205  //--- Find LBs where this chip was noisy
3206  double chipOccupancyThr{noisyStripThr*n_stripPerChip*m_noisyChipFraction};
3207  std::set<int> LBList;
3208  LBList.clear();
3209  if (!m_calibLbTool) {
3210  ATH_MSG_ERROR("nullptr m_calibLbTool line " <<__LINE__);
3211  return std::make_pair(defectLB, defectLBFrac);
3212  }
3213 
3214  for (int iLB{0}; iLB != m_LBRange; ++iLB) {
3215  double numEventsInLB{static_cast<double>(m_calibLbTool->getNumberOfEventsInBin(iLB + 1))};
3216  if (numEventsInLB == 0) continue;
3217  double chipOccupancy{(float) m_calibLbTool->getBinForHistogramIndex(iLB + 1, histIndex) / numEventsInLB};
3218  if (chipOccupancy > chipOccupancyThr) LBList.insert(iLB);
3219  }
3220  //--- Transform LBList to string and calculate a fraction of noisy LBs
3221  if (LBList.size() != 0) {
3222  defectLB = getLBList(LBList);
3223  defectLBFrac = static_cast<float>(LBList.size()) / m_numOfLBsProcessed;
3224  }
3225 
3226  return std::make_pair(defectLB, defectLBFrac);
3227 }
3228 
3229 
3230 std::string SCTCalib::getLBList(const std::set<int>& LBList) const {
3231  std::string strList;
3232  strList.erase();
3233  if (!LBList.empty()) {
3234  int firstLB{-1};
3235  int LBSize{-1};
3236 
3237  std::set<int>::const_iterator LBItrFirst{LBList.begin()};
3238  std::set<int>::const_iterator LBItrLast{--LBList.end()};
3239 
3240  std::set<int>::const_iterator LBItr{LBList.begin()};
3241  std::set<int>::const_iterator LBItrE{LBList.end()};
3242  for (; LBItr != LBItrE; ++LBItr) {
3243  int iLB{*LBItr};
3244  if (LBItr == LBItrFirst) {
3245  firstLB = iLB;
3246  LBSize = 1;
3247  } else {
3248  if (iLB == firstLB + LBSize) {
3249  ++LBSize;
3250  } else {
3251  int LBBegin{firstLB};
3252  int LBEnd{firstLB + LBSize -1};
3253  strList = m_pCalibWriteTool->addDefect(strList, LBBegin, LBEnd);
3254  firstLB = iLB;
3255  LBSize = 1;
3256  }
3257  }
3258  if (LBItr == LBItrLast) {
3259  int LBBegin{firstLB};
3260  int LBEnd{iLB};
3261  strList = m_pCalibWriteTool->addDefect(strList, LBBegin, LBEnd);
3262  }
3263  }
3264  }
3265  return strList;
3266 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
histCollection
Definition: LArQuickHistMerge.cxx:56
SCT_CalibAlgs::chipList2LinkList
std::string chipList2LinkList(const std::string &chipList)
Definition: SCT_CalibUtilities.cxx:47
SCT_CalibAlgs::bec2Index
unsigned int bec2Index(const int bec)
Definition: SCT_CalibUtilities.cxx:60
SCT_CalibAlgs::n_barrels
@ n_barrels
Definition: SCT_CalibNumbers.h:15
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
SCTCalib::initialize
virtual StatusCode initialize() override
Definition: SCTCalib.cxx:122
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SCTCalib::m_efficiencyMinStat
UnsignedIntegerProperty m_efficiencyMinStat
Definition: SCTCalib.h:203
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
pdg_comparison.sigma
sigma
Definition: pdg_comparison.py:324
SCTCalib::n_chipPerSide
@ n_chipPerSide
Definition: SCTCalib.h:89
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
SCTCalib::m_iovStop
IOVTime m_iovStop
Definition: SCTCalib.h:244
max
#define max(a, b)
Definition: cfImp.cxx:41
SCTCalib::m_deadStripUploadTest
BooleanProperty m_deadStripUploadTest
Definition: SCTCalib.h:195
SCTCalib::m_doHitMapsLB
BooleanProperty m_doHitMapsLB
Definition: SCTCalib.h:146
SCTCalib::m_eventNumber
IntegerProperty m_eventNumber
Definition: SCTCalib.h:129
SCTCalib::m_readHitMaps
BooleanProperty m_readHitMaps
Definition: SCTCalib.h:148
AddEmptyComponent.histName
string histName
Definition: AddEmptyComponent.py:64
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
SCTCalib::m_pSCTHelper
const SCT_ID * m_pSCTHelper
Definition: SCTCalib.h:95
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
SCT_CalibAlgs::ntimeBins
@ ntimeBins
Definition: SCT_CalibNumbers.h:11
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SCTCalib::xmlChannelEfficiencyDataStringChip
std::string xmlChannelEfficiencyDataStringChip(const Identifier &waferId, const float efficiency, const float efficiency_bcid, const SCT_SerialNumber &serial, const int side, const int chip) const
Definition: SCTCalib.cxx:2680
SCTCalib::m_BSErrorDBMinStat
UnsignedIntegerProperty m_BSErrorDBMinStat
Definition: SCTCalib.h:205
SCT_LorentzAngleFunc.h
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
SCT_CalibAlgs::XmlHeader
Definition: XmlHeader.h:18
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
SCTCalib::m_calibHitmapTool
ToolHandle< ISCT_CalibHistoTool > m_calibHitmapTool
Definition: SCTCalib.h:103
SCTCalib::m_LorentzAngleMinStat
UnsignedIntegerProperty m_LorentzAngleMinStat
Definition: SCTCalib.h:206
SCTCalib::m_runStartTime
StringProperty m_runStartTime
Definition: SCTCalib.h:131
SCT_Monitoring::N_ENDCAPS
@ N_ENDCAPS
Definition: SCT_MonitoringNumbers.h:46
SCTCalib::m_nLbsMerged
IntegerProperty m_nLbsMerged
Definition: SCTCalib.h:147
plotmaker.hist
hist
Definition: plotmaker.py:148
SCT_CalibAlgs::XmlStreamer
Definition: XmlStreamer.h:18
SCTCalib::openXML4DeadSummary
StatusCode openXML4DeadSummary(std::ofstream &file, const char *type, int n_Module=0, int n_Link=0, int n_Chip=0, int n_Strip=0) const
Definition: SCTCalib.cxx:2492
SCTCalib::m_useBSError
BooleanProperty m_useBSError
Definition: SCTCalib.h:138
SCTCalib::noisyStripsToSummaryXml
StatusCode noisyStripsToSummaryXml(const std::map< Identifier, std::set< Identifier >> &moduleListAll, const std::map< Identifier, std::set< Identifier >> &moduleListRef, const std::string &badStripsFile) const
Definition: SCTCalib.cxx:2921
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
SCTCalib::m_doEfficiency
BooleanProperty m_doEfficiency
Definition: SCTCalib.h:156
TProfile2D
Definition: rootspy.cxx:531
SCTCalib::m_runEndTime
StringProperty m_runEndTime
Definition: SCTCalib.h:132
SCT_ID::wafer_begin
const_id_iterator wafer_begin(void) const
Iterators over full set of ids. Wafer iterator is sorted.
Definition: SCT_ID.cxx:648
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
LA_func
Double_t LA_func(Double_t *x, Double_t *par)
Definition: SCT_LorentzAngleFunc.h:11
SCTCalib::notEnoughStatistics
bool notEnoughStatistics(const int required, const int obtained, const std::string &histogramName="HIST") const
Definition: SCTCalib.cxx:282
SCTCalib::SCTCalib
SCTCalib(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SCTCalib.cxx:112
SCTCalib::m_noisyStripThrDef
BooleanProperty m_noisyStripThrDef
Definition: SCTCalib.h:173
SCTCalib::m_noisyWaferThrBarrel
FloatProperty m_noisyWaferThrBarrel
Definition: SCTCalib.h:179
SCT_ID::const_id_iterator
std::vector< Identifier >::const_iterator const_id_iterator
Definition: SCT_ID.h:73
SCTCalib::m_rawOccupancySummaryFile
StringProperty m_rawOccupancySummaryFile
Definition: SCTCalib.h:227
SCTCalib::m_BSErrorModuleFile
StringProperty m_BSErrorModuleFile
Definition: SCTCalib.h:232
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
SCT_CalibAlgs
Definition: IElementStreamer.cxx:13
ALL
@ ALL
Definition: sTGCenumeration.h:14
SCTCalib::n_chipPerModule
@ n_chipPerModule
Definition: SCTCalib.h:89
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
SCTCalib::m_efficiencySummaryFile
StringProperty m_efficiencySummaryFile
Definition: SCTCalib.h:228
SCTCalib::m_noisyStripLastRunInDB
IntegerProperty m_noisyStripLastRunInDB
Definition: SCTCalib.h:165
SCT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: SCT_ID.h:728
sendEI_SPB.root
root
Definition: sendEI_SPB.py:34
SCT_ID::phi_module
int phi_module(const Identifier &id) const
Definition: SCT_ID.h:740
histCollection::size
size_t size()
Definition: LArQuickHistMerge.cxx:62
python.TrigEgammaMonitorHelper.TH2F
def TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:45
SCTCalib::m_calibBsErrTool
ToolHandle< ISCT_CalibHistoTool > m_calibBsErrTool
Definition: SCTCalib.h:105
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
SCTCalib::m_BSErrorSummaryFile
StringProperty m_BSErrorSummaryFile
Definition: SCTCalib.h:231
SCTCalib::m_noisyModuleAverageInDB
FloatProperty m_noisyModuleAverageInDB
Definition: SCTCalib.h:164
SCT_ID::module_id
Identifier module_id(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
For a single crystal.
Definition: SCT_ID.h:416
SCTCalib::m_noisyModuleDiff
FloatProperty m_noisyModuleDiff
Definition: SCTCalib.h:168
SCTCalib::m_SCTDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_SCTDetEleCollKey
Definition: SCTCalib.h:96
DeMoAtlasDataLoss.lbRange
string lbRange
Definition: DeMoAtlasDataLoss.py:67
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
SCTCalib::xmlChannelEfficiencyDataString
std::string xmlChannelEfficiencyDataString(const Identifier &waferId, const float efficiency, const SCT_SerialNumber &serial, const int side) const
Definition: SCTCalib.cxx:2663
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
SCTCalib::m_doHV
BooleanProperty m_doHV
Definition: SCTCalib.h:151
SCTCalib::m_input_hist
StringArrayProperty m_input_hist
Definition: SCTCalib.h:140
SCTCalib::closeXML4DB
StatusCode closeXML4DB(std::ofstream &) const
Definition: SCTCalib.cxx:2458
TRT::Hit::side
@ side
Definition: HitInfo.h:83
dqt_zlumi_alleff_HIST.A
A
Definition: dqt_zlumi_alleff_HIST.py:110
SCTCalib::m_doRawOccupancy
BooleanProperty m_doRawOccupancy
Definition: SCTCalib.h:155
SCTCalib::m_numberOfEvents
unsigned long long m_numberOfEvents
Definition: SCTCalib.h:238
SCTCalib::m_LBRange
int m_LBRange
Definition: SCTCalib.h:242
SCT_ConditionsAlgorithms::xmlHeader
std::string xmlHeader(const std::string &version="1.0", const std::string &encoding="UTF-8")
Definition: SCT_SimpleHisto.h:64
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
SCTCalib::m_numberOfEventsHist
unsigned long long m_numberOfEventsHist
Definition: SCTCalib.h:239
SCTCalib::m_noisyStripAverageInDB
FloatProperty m_noisyStripAverageInDB
Definition: SCTCalib.h:166
python.PyAthena.module
module
Definition: PyAthena.py:134
SCTCalib::m_noisyModuleList
IntegerProperty m_noisyModuleList
Definition: SCTCalib.h:167
SCTCalib::addStripsToList
StatusCode addStripsToList(Identifier &waferId, std::set< Identifier > &stripIdList, bool isNoisy, bool isNew) const
Definition: SCTCalib.cxx:2725
ATLAS_NOT_THREAD_SAFE
StatusCode SCTCalib::stop ATLAS_NOT_THREAD_SAFE()
stop - process results accumulated in execute()
Definition: SCTCalib.cxx:342
efficiency
void efficiency(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
Definition: dependence.cxx:128
SCTCalib::m_useMajority
BooleanProperty m_useMajority
Definition: SCTCalib.h:137
SCT_SerialNumber::str
std::string str() const
Full serial number as a string
Definition: SCT_SerialNumber.cxx:56
SCTCalib::m_useConfiguration
BooleanProperty m_useConfiguration
Definition: SCTCalib.h:135
SCTCalib::m_deadSummaryFile
StringProperty m_deadSummaryFile
Definition: SCTCalib.h:223
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
maskDeadModules.mod
mod
Definition: maskDeadModules.py:36
SCTCalib::m_inputHist
TFile * m_inputHist
Definition: SCTCalib.h:247
SCTCalib::m_iovStart
IOVTime m_iovStart
Definition: SCTCalib.h:243
lumiFormat.i
int i
Definition: lumiFormat.py:92
python.TrigEgammaMonitorHelper.TProfile
def TProfile(*args, **kwargs)
Definition: TrigEgammaMonitorHelper.py:81
SCTCalib::m_useCalibration
BooleanProperty m_useCalibration
Definition: SCTCalib.h:136
SCT_CalibAlgs::xmlOpenChannel
std::string xmlOpenChannel(const long id, const T since, const T until)
Definition: SCT_CalibUtilities.h:36
SCTCalib::m_ConfigurationConditionsTool
ToolHandle< ISCT_ConfigurationConditionsTool > m_ConfigurationConditionsTool
Definition: SCTCalib.h:99
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
SCT_CalibAlgs::formatPosition
std::string formatPosition(const Identifier &waferId, const SCT_ID *helper, const std::string &delimiter, const bool includeSide)
Definition: SCT_CalibUtilities.cxx:36
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
SCT_CalibAlgs::xmlValue
std::string xmlValue(const std::string &name, const T value)
Definition: SCT_CalibUtilities.h:29
SCTCalib::m_readBS
BooleanProperty m_readBS
Definition: SCTCalib.h:142
python.getCurrentFolderTag.dn
dn
Definition: getCurrentFolderTag.py:64
SCTCalib::m_doBSErrorDB
BooleanProperty m_doBSErrorDB
Definition: SCTCalib.h:157
SCTCalib::m_utcEnd
std::string m_utcEnd
Definition: SCTCalib.h:241
SCTCalib::m_writeToCool
BooleanProperty m_writeToCool
Definition: SCTCalib.h:159
SCTCalib::m_doNoiseOccupancy
BooleanProperty m_doNoiseOccupancy
Definition: SCTCalib.h:154
file
TFile * file
Definition: tile_monitor.h:29
SCTCalib::m_runNumber
IntegerProperty m_runNumber
Definition: SCTCalib.h:128
SCTCalib::getLBList
std::string getLBList(const std::set< int > &LBList) const
Definition: SCTCalib.cxx:3230
SCTCalib::m_readHIST
bool m_readHIST
Definition: SCTCalib.h:248
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SCTCalib::openXML4DB
StatusCode openXML4DB(std::ofstream &, const char *, const char *, IOVTime, IOVTime) const
Definition: SCTCalib.cxx:2437
SCT_Monitoring::disabled
@ disabled
Definition: SCT_MonitoringNumbers.h:60
SCT_ID::wafer_hash
IdentifierHash wafer_hash(const Identifier &wafer_id) const
wafer hash from id - optimized
Definition: SCT_ID.h:492
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
SH::MetaObject::swap
void swap(MetaObject &a, MetaObject &b)
standard swap
SCTCalib::m_doDeadStrip
BooleanProperty m_doDeadStrip
Definition: SCTCalib.h:152
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
SCTCalib::m_calibModuleListTool
ToolHandle< ISCT_CalibModuleListTool > m_calibModuleListTool
Definition: SCTCalib.h:106
SCT_Monitoring::ENDCAP_A
@ ENDCAP_A
Definition: SCT_MonitoringNumbers.h:21
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
AthAlgorithm
Definition: AthAlgorithm.h:47
SCTCalib::m_ReadCalibDataTool
ToolHandle< ISCT_ReadCalibDataTool > m_ReadCalibDataTool
Definition: SCTCalib.h:100
SCTCalib::m_MajorityConditionsTool
ToolHandle< ISCT_DetectorLevelConditionsTool > m_MajorityConditionsTool
Definition: SCTCalib.h:101
perfmonmt-printer.required
required
Definition: perfmonmt-printer.py:184
min
#define min(a, b)
Definition: cfImp.cxx:40
SCTCalib::lastStrip
@ lastStrip
Definition: SCTCalib.h:77
DQPostProcessTest.outFile
outFile
Comment Out Those You do not wish to run.
Definition: DQPostProcessTest.py:37
IOVTime::MAXEVENT
static constexpr uint32_t MAXEVENT
Definition: IOVTime.h:51
SCTCalib::firstStrip
@ firstStrip
Definition: SCTCalib.h:77
SCTCalib::m_pCalibWriteTool
ToolHandle< SCTCalibWriteTool > m_pCalibWriteTool
Definition: SCTCalib.h:98
SCT_CalibAlgs::xmlCloseChannel
std::string xmlCloseChannel()
Definition: SCT_CalibUtilities.cxx:65
SCTCalib::m_calibLbTool
ToolHandle< ISCT_CalibHistoTool > m_calibLbTool
Definition: SCTCalib.h:104
SCTCalib::m_noisyWaferThrECA
FloatProperty m_noisyWaferThrECA
Definition: SCTCalib.h:180
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
SCTCalib::wrapUpXML4Summary
StatusCode wrapUpXML4Summary(std::ofstream &, const char *, std::ostringstream &) const
Definition: SCTCalib.cxx:2577
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
SCTCalib::getStripList
std::string getStripList(const std::set< Identifier > &stripIdList) const
Definition: SCTCalib.cxx:2833
SCT_CalibAlgs::normalizeList
std::string normalizeList(std::string s)
Definition: SCT_CalibUtilities.cxx:21
threshold
Definition: chainparser.cxx:74
SCTCalib::m_noiseOccupancySummaryFile
StringProperty m_noiseOccupancySummaryFile
Definition: SCTCalib.h:226
SCTCalib::getNoisyChips
std::set< int > getNoisyChips(const std::set< Identifier > &stripIdList) const
Definition: SCTCalib.cxx:3144
SCTCalib::m_doDeadChip
BooleanProperty m_doDeadChip
Definition: SCTCalib.h:153
SCT_ID::layer_disk
int layer_disk(const Identifier &id) const
Definition: SCT_ID.h:734
SCT_Monitoring::ENDCAP_C
@ ENDCAP_C
Definition: SCT_MonitoringNumbers.h:21
SCTCalib.h
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
dqt_zlumi_alleff_HIST.B
B
Definition: dqt_zlumi_alleff_HIST.py:110
TProfile2D::GetBinContent
double GetBinContent(int) const
Definition: rootspy.cxx:546
SCTCalib::m_doHitMaps
BooleanProperty m_doHitMaps
Definition: SCTCalib.h:145
IOVTime::MINEVENT
static constexpr uint32_t MINEVENT
Definition: IOVTime.h:50
SCTCalib::m_noisyChipFraction
FloatProperty m_noisyChipFraction
Definition: SCTCalib.h:183
SiDetectorElement.h
SCT_SerialNumber
Definition: SCT_SerialNumber.h:22
SCTCalib::getNoisyLB
std::pair< std::string, float > getNoisyLB(const Identifier &moduleId, int &chipId) const
Definition: SCTCalib.cxx:3189
SCTCalib::doHVPrintXML
void doHVPrintXML(const std::pair< int, int > &timeInterval, const std::pair< int, int > &lbRange, Identifier)
doHVPrintXML() Prints XML file for hv modules
Definition: SCTCalib.cxx:470
xAOD::timeStamp
setEventNumber timeStamp
Definition: EventInfo_v1.cxx:128
SCTCalib::getNumNoisyStrips
std::pair< int, bool > getNumNoisyStrips(const Identifier &waferId) const
Definition: SCTCalib.cxx:2698
SCTCalib::m_doBSErrors
BooleanProperty m_doBSErrors
Definition: SCTCalib.h:149
Trk::iPhi
@ iPhi
Definition: ParamDefs.h:53
SCTCalib::m_utcBegin
std::string m_utcBegin
Definition: SCTCalib.h:240
python.PyAthena.v
v
Definition: PyAthena.py:157
SCTCalib::m_gofile
std::ofstream m_gofile
Definition: SCTCalib.h:114
SCT_CalibAlgs::n_disks
@ n_disks
Definition: SCT_CalibNumbers.h:16
SCT_ConditionsData::Bec
Bec
Definition: SCT_ConditionsParameters.h:31
Threshold
Threshold
Definition: TRIGGERidentity.h:18
SCTCalib::addToSummaryStr
StatusCode addToSummaryStr(std::ostringstream &, const Identifier &, const char *, const char *, const char *) const
Definition: SCTCalib.cxx:2595
SCTCalib::m_noiseOccupancyMinStat
UnsignedIntegerProperty m_noiseOccupancyMinStat
Definition: SCTCalib.h:201
SCTCalib::m_noisyStripDiff
FloatProperty m_noisyStripDiff
Definition: SCTCalib.h:169
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
CSV_InDetExporter.old
old
Definition: CSV_InDetExporter.py:145
SCTCalib::finalize
virtual StatusCode finalize() override
Finalize - delete any memory allocation from the heap.
Definition: SCTCalib.cxx:452
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
SCT_ID::strip
int strip(const Identifier &id) const
Definition: SCT_ID.h:764
SCTCalib::m_noisyUpdate
BooleanProperty m_noisyUpdate
Definition: SCTCalib.h:161
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
SCTCalib::addToXML4DB
StatusCode addToXML4DB(std::ofstream &, const Identifier &, const char *, float, const char *) const
Definition: SCTCalib.cxx:2469
XmlHeader.h
SCT_ID::eta_module
int eta_module(const Identifier &id) const
Definition: SCT_ID.h:746
SCTCalib::m_rawOccupancyMinStat
UnsignedIntegerProperty m_rawOccupancyMinStat
Definition: SCTCalib.h:202
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
BARREL
@ BARREL
Definition: TRTRadiatorParameters.h:10
SCTCalib::m_deadChipsFile
StringProperty m_deadChipsFile
Definition: SCTCalib.h:222
SCTCalib::m_deadStripsFile
StringProperty m_deadStripsFile
Definition: SCTCalib.h:221
CaloCondBlobAlgs_fillNoiseFromASCII.folder
folder
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:56
SCTCalib::retrievedService
bool retrievedService(S &service) const
Definition: SCTCalib.h:284
SCT_ID::side
int side(const Identifier &id) const
Definition: SCT_ID.h:752
SCT_ID::wafer_end
const_id_iterator wafer_end(void) const
Definition: SCT_ID.cxx:652
SCTCalib::m_noisyStripThrOnline
FloatProperty m_noisyStripThrOnline
Definition: SCTCalib.h:175
dqt_zlumi_alleff_HIST.eff
int eff
Definition: dqt_zlumi_alleff_HIST.py:113
merge.status
status
Definition: merge.py:17
SCTCalib::n_stripPerChip
@ n_stripPerChip
Definition: SCTCalib.h:89
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
SCTCalib::m_noisyWaferFraction
FloatProperty m_noisyWaferFraction
Definition: SCTCalib.h:182
SCTCalib::m_tagID4NoisyStrips
StringProperty m_tagID4NoisyStrips
Definition: SCTCalib.h:210
SCT_ID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module, int side) const
For a single side of module.
Definition: SCT_ID.h:464
SCTCalib::m_numOfLBsProcessed
int m_numOfLBsProcessed
Definition: SCTCalib.h:237
InDetConditions::SCT_STRIP
@ SCT_STRIP
Definition: InDetHierarchy.h:14
SCTCalib::getOverlapStripList
std::set< Identifier > getOverlapStripList(const std::set< Identifier > &stripAllIdList, const std::set< Identifier > &stripRefIdList) const
Definition: SCTCalib.cxx:2812
xAOD::lumiBlock
setTeId lumiBlock
Definition: L2StandAloneMuon_v1.cxx:327
SCT_CalibAlgs::n_etaBins
@ n_etaBins
Definition: SCT_CalibNumbers.h:13
SCTCalib::m_deadChipUploadTest
BooleanProperty m_deadChipUploadTest
Definition: SCTCalib.h:194
value_type
Definition: EDM_MasterSearch.h:11
xAOD::iEta
setScale setgFexType iEta
Definition: gFexJetRoI_v1.cxx:74
SCTCalib::m_noisyStripThrOffline
FloatProperty m_noisyStripThrOffline
Definition: SCTCalib.h:174
XmlStreamer.h
SCT_CalibUtilities.h
SCTCalib::noisyStripsToXml
StatusCode noisyStripsToXml(const std::map< Identifier, std::set< Identifier > > &moduleList, const std::string &badStripsFile) const
Definition: SCTCalib.cxx:2873
AthenaPoolExample_Copy.outputFileName
string outputFileName
Definition: AthenaPoolExample_Copy.py:40
length
double length(const pvec &v)
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:26
SCTCalib::m_CablingTool
ToolHandle< ISCT_CablingTool > m_CablingTool
Definition: SCTCalib.h:102
SCTCalib::m_noisyUploadTest
BooleanProperty m_noisyUploadTest
Definition: SCTCalib.h:163
SCTCalib::m_noisyMinStat
UnsignedIntegerProperty m_noisyMinStat
Definition: SCTCalib.h:171
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
readCCLHist.float
float
Definition: readCCLHist.py:83
SCTCalib::openXML4MonSummary
StatusCode openXML4MonSummary(std::ofstream &, const char *) const
Definition: SCTCalib.cxx:2545
SCTCalib::m_LBMax
StringProperty m_LBMax
Definition: SCTCalib.h:133
SCTCalib::m_doNoisyStrip
BooleanProperty m_doNoisyStrip
Definition: SCTCalib.h:150
SCTCalib::m_doLorentzAngle
BooleanProperty m_doLorentzAngle
Definition: SCTCalib.h:158
WriteBchToCool.moduleList
moduleList
Definition: WriteBchToCool.py:72
fitman.k
k
Definition: fitman.py:528
SCTCalib::m_calibEvtInfoTool
ToolHandle< ISCT_CalibEvtInfo > m_calibEvtInfoTool
Definition: SCTCalib.h:107
SCTCalib::xmlChannelNoiseOccDataString
std::string xmlChannelNoiseOccDataString(const Identifier &waferId, const float occupancy, const SCT_SerialNumber &serial) const
Definition: SCTCalib.cxx:2647
SCTCalib::nbins
@ nbins
Definition: SCTCalib.h:77
SCT_ID::strip_id
Identifier strip_id(int barrel_ec, int layer_disk, int phi_module, int eta_module, int side, int strip) const
For an individual strip.
Definition: SCT_ID.h:535
SCTCalib::execute
virtual StatusCode execute() override
Definition: SCTCalib.cxx:294
SCTCalib::m_noisyWaferThrECC
FloatProperty m_noisyWaferThrECC
Definition: SCTCalib.h:181
SCT_CalibAlgs::n_etaBinsEC
@ n_etaBinsEC
Definition: SCT_CalibNumbers.h:17