Belle II Software  release-05-01-25
ARICHDatabaseImporter.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Manca Mrvar, Thomas Kuhr, Leonid Burmistrov *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <arich/calibration/ARICHDatabaseImporter.h>
12 #include <arich/calibration/ARICHDatabaseTools.h>
13 #include <arich/dbobjects/ARICHAerogelMap.h>
14 #include <arich/dbobjects/ARICHAerogelInfo.h>
15 #include <arich/dbobjects/ARICHAerogelRayleighScatteringFit.h>
16 #include <arich/dbobjects/ARICHAsicInfo.h>
17 #include <arich/dbobjects/ARICHHapdQA.h>
18 #include <arich/dbobjects/ARICHFebTest.h>
19 #include <arich/dbobjects/ARICHHapdChipInfo.h>
20 #include <arich/dbobjects/ARICHHapdInfo.h>
21 #include <arich/dbobjects/ARICHHapdQE.h>
22 #include <arich/dbobjects/ARICHMagnetTest.h>
23 #include <arich/dbobjects/ARICHModuleTest.h>
24 #include <arich/dbobjects/ARICHSensorModuleInfo.h>
25 #include <arich/dbobjects/ARICHSensorModuleMap.h>
26 #include <arich/dbobjects/ARICHBiasCablesMapping.h>
27 #include <arich/dbobjects/ARICHBiasChannelsMapping.h>
28 #include <arich/dbobjects/ARICHBiasVoltages.h>
29 #include <arich/dbobjects/ARICHBiasCrateCableMapping.h>
30 #include <arich/dbobjects/ARICHHvCablesMapping.h>
31 #include <arich/dbobjects/ARICHHvChannelsMapping.h>
32 #include <arich/dbobjects/ARICHHvCrateCableMapping.h>
33 // database classes used by simulation/reconstruction software
34 #include <arich/dbobjects/ARICHChannelMask.h>
35 #include <arich/dbobjects/ARICHChannelMapping.h>
36 #include <arich/dbobjects/ARICHModulesInfo.h>
37 #include <arich/dbobjects/ARICHMergerMapping.h>
38 #include <arich/dbobjects/ARICHCopperMapping.h>
39 #include <arich/dbobjects/ARICHSimulationPar.h>
40 #include <arich/dbobjects/ARICHReconstructionPar.h>
41 #include <arich/dbobjects/ARICHGeometryConfig.h>
42 #include <arich/dbobjects/ARICHAeroTilesInfo.h>
43 #include <arich/dbobjects/ARICHGlobalAlignment.h>
44 #include <arich/dbobjects/ARICHMirrorAlignment.h>
45 #include <arich/dbobjects/ARICHPositionElement.h>
46 #include <arich/dbobjects/ARICHAeroTilesAlignment.h>
47 #include <arich/dbobjects/ARICHGeoMergerCooling.h>
48 
49 // channel histogram
50 #include <arich/utility/ARICHChannelHist.h>
51 #include <arich/utility/ARICHAerogelHist.h>
52 
53 #include <framework/gearbox/GearDir.h>
54 #include <framework/gearbox/Unit.h>
55 #include <framework/logging/Logger.h>
56 #include <framework/database/EventDependency.h>
57 
58 #include <framework/database/IntervalOfValidity.h>
59 #include <framework/database/Database.h>
60 #include <framework/database/DBArray.h>
61 #include <framework/database/DBObjPtr.h>
62 #include <framework/database/DBImportObjPtr.h>
63 
64 #include <TH1.h>
65 #include <TH2.h>
66 #include <TH3.h>
67 #include <TGraph.h>
68 #include <TGraph2D.h>
69 #include <TFile.h>
70 #include <TKey.h>
71 #include <TString.h>
72 #include <string>
73 #include <vector>
74 #include <map>
75 #include <fstream>
76 #include <iostream>
77 #include <TClonesArray.h>
78 #include <TTree.h>
79 #include <tuple>
80 #include <iomanip>
81 
82 using namespace std;
83 using namespace Belle2;
84 
85 ARICHDatabaseImporter::ARICHDatabaseImporter(const vector<string>& inputFilesHapdQA, const vector<string>& inputFilesAsicRoot,
86  const vector<string>& inputFilesAsicTxt, const vector<string>& inputFilesHapdQE, const vector<string>& inputFilesFebTest)
87 {
88  m_inputFilesHapdQA.reserve(inputFilesHapdQA.size());
89  m_inputFilesAsicRoot.reserve(inputFilesAsicRoot.size());
90  m_inputFilesAsicTxt.reserve(inputFilesAsicTxt.size());
91  m_inputFilesHapdQE.reserve(inputFilesHapdQE.size());
92  m_inputFilesFebTest.reserve(inputFilesFebTest.size());
93  for (unsigned int i = 0; i < inputFilesHapdQA.size(); i++) { m_inputFilesHapdQA.push_back(inputFilesHapdQA[i]); }
94  for (unsigned int i = 0; i < inputFilesAsicRoot.size(); i++) { m_inputFilesAsicRoot.push_back(inputFilesAsicRoot[i]); }
95  for (unsigned int i = 0; i < inputFilesAsicTxt.size(); i++) { m_inputFilesAsicTxt.push_back(inputFilesAsicTxt[i]); }
96  for (unsigned int i = 0; i < inputFilesHapdQE.size(); i++) { m_inputFilesHapdQE.push_back(inputFilesHapdQE[i]); }
97  for (unsigned int i = 0; i < inputFilesFebTest.size(); i++) { m_inputFilesFebTest.push_back(inputFilesFebTest[i]); }
98  m_iov = IntervalOfValidity(0, 0, -1, -1);
99 }
100 
101 ARICHDatabaseImporter::ARICHDatabaseImporter(int experiment, int run)
102 {
104  meta->setRun(run); meta->setExperiment(experiment);
105  B2INFO("Experiment " << experiment << ", run " << run);
106  m_iov = IntervalOfValidity(0, 0, -1, -1);
107 }
108 
109 void ARICHDatabaseImporter::SetIOV(int experimentLow, int runLow, int experimentHigh , int runHigh)
110 {
111  m_iov = IntervalOfValidity(experimentLow, runLow, experimentHigh, runHigh);
112 }
113 
114 
115 void ARICHDatabaseImporter::setExperimentAndRun(int experiment, int run)
116 {
118  meta->setRun(run); meta->setExperiment(experiment);
119  B2INFO("Experiment " << experiment << ", run " << run);
120 }
121 
122 // classses for simulation/reconstruction software
123 void ARICHDatabaseImporter::importModulesInfo()
124 {
125 
126  // geometry configuration
128 
129  // QE 2D maps from DB
130  DBArray<ARICHHapdQE> QEMaps("ARICHHapdQE");
131 
132  ARICHModulesInfo modInfo;
133 
134  // channel mapping used in QA tests (QE measurements, etc.)
135  ARICHChannelMapping QAChMap;
136 
137  // read mapping from xml file
138  GearDir content = GearDir("/Detector/DetectorComponent[@name='ARICH']/Content/ChannelMapping");
139  istringstream chstream;
140  int x, y, asic;
141  chstream.str(content.getString("QAChannelMapping"));
142  while (chstream >> x >> y >> asic) {
143  QAChMap.mapXY2Asic(x, y, asic);
144  }
145 
146  // get list of installed modules from xml
147  GearDir installedModules = GearDir("/Detector/DetectorComponent[@name='ARICH']/Content/InstalledModules");
148  B2INFO("Installed modules\n");
149 
150  std::vector<std::string> installed;
151 
152  for (const GearDir& module : installedModules.getNodes("Module")) {
153  std::string hapdID = module.getString("@hapdID");
154 
155  unsigned sector = module.getInt("Sector");
156  unsigned ring = module.getInt("Ring");
157  unsigned azimuth = module.getInt("Azimuth");
158  bool isActive = (bool)module.getInt("isActive");
159  B2INFO(" " << hapdID << ": S " << sector << " R " << ring << " Z " << azimuth << ", isActive: " << isActive << '\n');
160 
161  if (std::find(installed.begin(), installed.end(), hapdID) != installed.end()) {
162  B2WARNING("ARICHDatabaseImporter::importModulesInfo: hapd " << hapdID << " installed multiple times!");
163  } else installed.push_back(hapdID);
164 
165  unsigned moduleID = geoConfig->getDetectorPlane().getSlotIDFromSRF(sector, ring, azimuth);
166 
167  // get and set QE map
168  std::vector<float> qs;
169  qs.assign(144, 0);
170  bool init = false;
171  for (const auto& QEMap : QEMaps) {
172  if (hapdID == QEMap.getHapdSerialNumber()) {
173  TH2F* qe2d = QEMap.getQuantumEfficiency2D();
174  for (int k = 1; k < 13; k++) {
175  for (int l = 1; l < 13; l++) {
176  int asicCh = QAChMap.getAsicFromXY(k - 1, l - 1);
177  qs[asicCh] = qe2d->GetBinContent(k, l);
178  }
179  }
180  init = true;
181  B2INFO(" Channels QE map found and set.\n");
182  }
183  }
184 
185  if (!init) {
186  for (int k = 0; k < 144; k++) {
187  qs[k] = 27.0;
188  }
189  B2WARNING("ARICHDatabaseImporter::importModulesInfo: QE map for hapd " << hapdID << " not found! Setting 27% QE for all channels!");
190  }
191 
192  modInfo.addModule(moduleID, qs, isActive);
193 
194  }
195 
197  importObj.construct(modInfo);
198  importObj.import(m_iov);
199 
200 }
201 
202 void ARICHDatabaseImporter::importGlobalAlignment()
203 {
204 
205  GearDir content = GearDir("/Detector/DetectorComponent[@name='ARICH']/Content");
206  GearDir alignPars(content, "GlobalAlignment");
207  ARICHGlobalAlignment arichAlign;
208  ARICHPositionElement alignel(alignPars.getLength("x"), alignPars.getLength("y"), alignPars.getLength("z"),
209  alignPars.getAngle("alpha"), alignPars.getAngle("beta"), alignPars.getAngle("gamma"));
210  arichAlign.setAlignmentElement(alignel);
211 
213  importObj.construct(arichAlign);
214  importObj.import(m_iov);
215 }
216 
217 
218 void ARICHDatabaseImporter::importMirrorAlignment()
219 {
220 
221  GearDir content = GearDir("/Detector/DetectorComponent[@name='ARICH']/Content");
222  GearDir alignPars(content, "MirrorAlignment");
223 
225 
226  ARICHMirrorAlignment mirrAlign;
227 
228  for (auto plate : alignPars.getNodes("Plate")) {
229  int id = plate.getInt("@id");
230  double r = plate.getLength("r");
231  double phi = plate.getAngle("phi");
232  double z = plate.getLength("z");
233  double alpha = plate.getLength("alpha");
234  double beta = plate.getLength("beta");
235  double gamma = plate.getLength("gamma");
236  double origPhi = geoConfig->getMirrors().getPoint(id).Phi();
237  ARICHPositionElement alignEl(r * cos(origPhi + phi), r * sin(origPhi + phi), z, alpha, beta, gamma);
238  mirrAlign.setAlignmentElement(id, alignEl);
239  alignEl.print();
240  }
241 
243  importObj.construct(mirrAlign);
244  importObj.import(m_iov);
245 
246 }
247 
248 void ARICHDatabaseImporter::importAeroTilesAlignment()
249 {
250 
251  GearDir content = GearDir("/Detector/DetectorComponent[@name='ARICH']/Content");
252  GearDir alignPars(content, "AeroTilesAlignment");
253 
254  ARICHAeroTilesAlignment tileAlign;
255 
256  for (auto tile : alignPars.getNodes("Slot")) {
257  int id = tile.getInt("@id");
258  double r = tile.getLength("r");
259  double phi = tile.getAngle("phi");
260  double z = tile.getLength("z");
261  double alpha = tile.getLength("alpha");
262  double beta = tile.getLength("beta");
263  double gamma = tile.getLength("gamma");
264  ARICHPositionElement alignEl(r * cos(phi), r * sin(phi), z, alpha, beta, gamma);
265  tileAlign.setAlignmentElement(id, alignEl);
266  alignEl.print();
267  }
268 
270  importObj.construct(tileAlign);
271  importObj.import(m_iov);
272 
273 }
274 
275 
276 void ARICHDatabaseImporter::importChannelMask()
277 {
278 
280 
281  // module test results from DB (we take list of dead channels from here)
282  DBArray<ARICHModuleTest> moduleTest("ARICHModuleTestHV");
283 
284  ARICHChannelMask chanMask;
285 
286  // loop over installed modules (from xml file)
287  GearDir content = GearDir("/Detector/DetectorComponent[@name='ARICH']/Content/InstalledModules");
288  B2INFO("Installed modules\n");
289  for (const GearDir& module : content.getNodes("Module")) {
290  std::string hapdID = module.getString("@hapdID");
291  unsigned sector = module.getInt("Sector");
292  unsigned ring = module.getInt("Ring");
293  unsigned azimuth = module.getInt("Azimuth");
294  bool isActive = (bool)module.getInt("isActive");
295  B2INFO(" " << hapdID << ": S " << sector << " R " << ring << " Z " << azimuth << ", isActive: " << isActive << '\n');
296  unsigned moduleID = geoConfig->getDetectorPlane().getSlotIDFromSRF(sector, ring, azimuth);
297 
298  // get and set channel mask (mask dead channels)
299  bool init = false;
300  for (const auto& test : moduleTest) {
301  if (hapdID == test.getHapdSN()) {
302 
303  // loop over list of dead channels
304  for (int i = 0; i < test.getDeadChsSize(); i++) {
305  unsigned asicCh = test.getDeadCh(i);
306  if (asicCh > 143)B2ERROR("ARICHDatabaseImporter::importLWClasses: Asic channel for HAPD " << hapdID << " is out of range!");
307  chanMask.setActiveCh(moduleID, asicCh, false);
308  }
309  init = true;
310  B2INFO(" List of dead channels (from module test) found and set.\n");
311  }
312  }
313 
314  if (!init) {
315  B2WARNING("ARICHDatabaseImporter::importLWClasses: List of dead channels for hapd " << hapdID <<
316  " not found! All channels set to active.");
317  continue;
318  }
319  }
320 
322  importObj.construct(chanMask);
323  importObj.import(m_iov);
324 
325 }
326 
327 void ARICHDatabaseImporter::importMergerCoolingGeo()
328 {
329 
330  ARICHGeoMergerCooling cooling;
331  GearDir mergerCoolingParams = GearDir("/Detector/DetectorComponent[@name='ARICH']/Content/mergerCoolingBodiesv2");
332 
333  cooling.setMergerCoolingBodiesMaterialName(mergerCoolingParams.getString("material"));
334  //std::cout<<"Merger cooling material -> "<<mergerCoolingParams.getString("material")<<std::endl;
335  for (auto mergerCoolingNode : mergerCoolingParams.getNodes("BodiesDatFileName/Body")) {
336  //std::cout<<"@positionID = "<<mergerCoolingNode.getInt("@positionID")<<std::endl;
337  tessellatedSolidStr mergerTessellation = readTessellatedSolidVerticesFromDATfile(mergerCoolingNode.getString());
338  cooling.addMergerCoolingBodiesInfo(mergerTessellation);
339  }
340  cooling.setMergerCoolingPositionID(mergerCoolingParams.getArray("mergerCoolingPositionID"));
342 
344  importObj.construct(cooling);
345  importObj.import(m_iov);
346  B2INFO("--> Mergers cooling bodies geometry imported.");
347 
348 }
349 
350 
351 tessellatedSolidStr ARICHDatabaseImporter::readTessellatedSolidVerticesFromDATfile(const std::string& inDATfile)
352 {
353 
354  tessellatedSolidStr solidStr;
355  std::string mot;
356  std::ifstream infile(inDATfile.c_str(), std::ifstream::in);
357 
358  if (infile.is_open()) {
359  double val = 0.0;
360  while (infile >> mot) {
361  if (mot == "BodyPositionID")
362  infile >> solidStr.tessellatedSolidID;
363  else
364  assert(0);
365  infile >> mot;
366  if (mot == "nCells")
367  infile >> solidStr.nCells;
368  else
369  assert(0);
370  infile >> mot;
371  if (mot == "nApexPerCell")
372  infile >> solidStr.nApexPerCell;
373  else
374  assert(0);
375 
376  TString apexNamesStr[3][3] = { { "Apex_1_x", "Apex_1_y", "Apex_1_z" },
377  { "Apex_2_x", "Apex_2_y", "Apex_2_z" },
378  { "Apex_3_x", "Apex_3_y", "Apex_3_z" }
379  };
380  for (unsigned int i = 0; i < 3; i++) {
381  infile >> mot;
382  if (mot != apexNamesStr[0][i])
383  assert(0);
384  std::vector<double> valv;
385  for (unsigned int j = 0; j < solidStr.nCells; j++) {
386  infile >> val;
387  valv.push_back(val);
388  }
389  solidStr.posV1.push_back(valv);
390  }
391  //Apex_2_x, Apex_2_y, Apex_2_z
392  for (unsigned int i = 0; i < 3; i++) {
393  infile >> mot;
394  if (mot != apexNamesStr[1][i])
395  assert(0);
396  std::vector<double> valv;
397  for (unsigned int j = 0; j < solidStr.nCells; j++) {
398  infile >> val;
399  valv.push_back(val);
400  }
401  solidStr.posV2.push_back(valv);
402  }
403  //Apex_3_x, Apex_3_y, Apex_3_z
404  for (unsigned int i = 0; i < 3; i++) {
405  infile >> mot;
406  if (mot != apexNamesStr[2][i])
407  assert(0);
408  std::vector<double> valv;
409  for (unsigned int j = 0; j < solidStr.nCells; j++) {
410  infile >> val;
411  valv.push_back(val);
412  }
413  solidStr.posV3.push_back(valv);
414  }
415  }
416  infile.close();
417  } else {
418  B2WARNING("Unable to open file : " << inDATfile << " with cooling bodies geometry.");
419  }
420  return solidStr;
421 }
422 
423 void ARICHDatabaseImporter::importChannelMask(TH1* h)
424 {
425  if (h == NULL) {
426  B2ERROR("--> NULL Histogram");
427  return;
428  }
429 
430  ARICHChannelMask mask;
431  int inactive = 0;
432  int numChannels = h->GetNbinsX();
433  const int NumberOfChannelsPerHapd = 144;
434  const int NumberOfHapds = 420;
435 
436  if (numChannels != NumberOfHapds * NumberOfChannelsPerHapd) {
437  B2ERROR("There should be " << NumberOfHapds * NumberOfChannelsPerHapd << " in the histogram!");
438  return;
439  }
440 
441  for (int bin = 1; bin <= numChannels; ++bin) {
442  int moduleID = (bin - 1) / NumberOfChannelsPerHapd + 1;
443  int channelID = (bin - 1) % NumberOfChannelsPerHapd;
444  bool value = (h->GetBinContent(bin) > 0);
445  if (!value) inactive++;
446  //B2INFO("--> moduleID " << moduleID << " channelID " << channelID << " ACTIVE:" << inactive);
447 
448  mask.setActiveCh(moduleID, channelID, value);
449  }
450 
452  importObj.construct(mask);
453  importObj.import(m_iov);
454  B2INFO("--> Channel Mask imported. Number of disabled channels=" << inactive << " Number of all channels=" << numChannels);
455 }
456 
457 
458 
459 void ARICHDatabaseImporter::importReconstructionParams()
460 {
461  ARICHReconstructionPar recPar;
462  recPar.initializeDefault();
463 
465  importObj.construct(recPar);
466  importObj.import(m_iov);
467 
468 }
469 
470 void ARICHDatabaseImporter::importSimulationParams()
471 {
472 
473  ARICHSimulationPar simPar;
474 
475  GearDir content = GearDir("/Detector/DetectorComponent[@name='ARICH']/Content/SimulationParameters");
476 
477  double qeScale = content.getDouble("qeScale");
478  double winAbs = content.getDouble("windowAbsorbtion");
479  double crossTalk = content.getDouble("chipNegativeCrosstalk");
480  double colEff = content.getDouble("colEff");
481 
482  GearDir qeParams(content, "QE");
483  float lambdaFirst = qeParams.getLength("LambdaFirst") / Unit::nm;
484  float lambdaStep = qeParams.getLength("LambdaStep") / Unit::nm;
485  double peakQE = qeParams.getDouble("peakQE");
486 
487  std::vector<float> qes;
488  for (const auto& qeff : qeParams.getNodes("Qeffi")) {
489  qes.push_back(qeff.getDouble("qe"));
490  }
491 
492  simPar.setQECurve(lambdaFirst, lambdaStep, qes);
493  simPar.setCollectionEff(colEff);
494  simPar.setChipNegativeCrosstalk(crossTalk);
495  simPar.setWindowAbsorbtion(winAbs);
496  simPar.setQEScaling(qeScale);
497  simPar.setPeakQE(peakQE);
498 
499  simPar.print();
500 
502  importObj.construct(simPar);
503  importObj.import(m_iov);
504 
505 }
506 
507 void ARICHDatabaseImporter::importChannelMapping()
508 {
509  GearDir content = GearDir("/Detector/DetectorComponent[@name='ARICH']/Content");
510  ARICHChannelMapping chMap;
511 
512  istringstream chstream;
513  int x, y, asic;
514  chstream.str(content.getString("ChannelMapping/SoftChannelMapping"));
515 
516  B2INFO("Importing channel x,y to asic channel map\n");
517  B2INFO(" x y asic\n");
518  while (chstream >> x >> y >> asic) {
519  chMap.mapXY2Asic(x, y, asic);
520  B2INFO(" " << setw(2) << x << " " << setw(2) << y << " " << setw(3) << asic << '\n');
521  }
522 
524  importObjMap.construct(chMap);
525  importObjMap.import(m_iov);
526 
527 }
528 
529 void ARICHDatabaseImporter::importFEMappings()
530 {
531 
532  GearDir content = GearDir("/Detector/DetectorComponent[@name='ARICH']/Content");
533 
535 
536  ARICHMergerMapping mergerMap;
537  ARICHCopperMapping copperMap;
538  GearDir mapping(content, "FrontEndMapping");
539 
540  for (const GearDir& merger : mapping.getNodes("Merger")) {
541  unsigned mergerID = (unsigned) merger.getInt("@id");
542  unsigned mergerSN = (unsigned) merger.getInt("@sn");
543  B2INFO('\n' << "Mapping of modules to merger no. " << mergerID << ", SN = " << mergerSN << '\n');
544  for (const GearDir& module : merger.getNodes("Modules/Module")) {
545  unsigned sector = module.getInt("Sector");
546  unsigned ring = module.getInt("Ring");
547  unsigned azimuth = module.getInt("Azimuth");
548  std::cout << "ring = " << ring << '\n';
549  unsigned moduleID = geoConfig->getDetectorPlane().getSlotIDFromSRF(sector, ring, azimuth);
550  std::cout << "moduleID = " << moduleID << '\n';
551  unsigned slot = (unsigned) module.getInt("@FEBSlot");
552  mergerMap.addMapping(moduleID, mergerID, slot, mergerSN);
553  std::cout << '\n' << " FEB slot: " << slot << ", module position: S" << sector << " R" << ring << " Z" << azimuth <<
554  ", module ID: " << moduleID << '\n';
555  std::cout << " crosscheck: mergerMap.getMergerID(" << moduleID << ") = " << mergerMap.getMergerID(
556  moduleID) << ", mergerMap.getFEBSlot(" << moduleID << ") = " << mergerMap.getFEBSlot(moduleID) << ", mergerMap.getModuleID(" <<
557  mergerID << "," << slot << ") = " << mergerMap.getModuleID(mergerID, slot) << '\n';
558 
559  }
560  std::cout << '\n';
561 
562  unsigned copperID = (unsigned) merger.getInt("COPPERid");
563  string finesseSlot = merger.getString("FinesseSlot");
564  int finesse = 0;
565  if (finesseSlot == "A") {finesse = 0;}
566  else if (finesseSlot == "B") {finesse = 1;}
567  else if (finesseSlot == "C") {finesse = 2;}
568  else if (finesseSlot == "D") {finesse = 3;}
569  else {
570  B2ERROR(merger.getPath() << "/FinesseSlot " << finesseSlot <<
571  " ***invalid slot (valid are A, B, C, D)");
572  continue;
573  }
574  copperMap.addMapping(mergerID, copperID, finesse);
575  std::cout << "Merger " << mergerID << " connected to copper " << copperID << ", finesse " << finesse << '\n';
576 
577  }
578 
579  DBImportObjPtr<ARICHMergerMapping> importObjMerger;
580  importObjMerger.construct(mergerMap);
581  importObjMerger.import(m_iov);
582 
583  DBImportObjPtr<ARICHCopperMapping> importObjCopper;
584  importObjCopper.construct(copperMap);
585  importObjCopper.import(m_iov);
586 
587 }
588 
589 void ARICHDatabaseImporter::importGeometryConfig()
590 {
591 
592  GearDir content = GearDir("/Detector/DetectorComponent[@name='ARICH']/Content");
593  ARICHGeometryConfig arichGeometryConfig(content);
594 
596  importObj.construct(arichGeometryConfig);
597  importObj.import(m_iov);
598 
599 }
600 
601 void ARICHDatabaseImporter::importCosmicTestGeometry()
602 {
603  GearDir content = GearDir("/Detector/DetectorComponent[@name='ARICH']/Content");
604  GearDir cosmic(content, "CosmicTest");
606 
608  geoImport.construct(*geoConfig);
609 
610  ARICHGeometryConfig& geo = (ARICHGeometryConfig&)geoImport;
611 
612  GearDir masterDir(cosmic, "MasterVolume");
613  ARICHGeoMasterVolume master = geo.getMasterVolume();
614  master.setPlacement(masterDir.getLength("Position/x"), masterDir.getLength("Position/y"), masterDir.getLength("Position/z"),
615  masterDir.getAngle("Rotation/x"), masterDir.getAngle("Rotation/y"), masterDir.getAngle("Rotation/z"));
616  master.setVolume(master.getInnerRadius(), master.getOuterRadius(), 100., master.getMaterial());
617  geo.setMasterVolume(master);
618 
619 
620  GearDir aerogel(cosmic, "Aerogel");
621  std::vector<double> par = {aerogel.getLength("xSize"), aerogel.getLength("ySize"), aerogel.getLength("xPosition"), aerogel.getLength("yPosition"), aerogel.getAngle("zRotation")};
623  plane.setSimple(par);
624  geo.setAerogelPlane(plane);
625 
626  GearDir scints(cosmic, "Scintilators");
627  double size[3] = {scints.getLength("xSize"), scints.getLength("ySize"), scints.getLength("zSize")};
628  std::string scintMat = scints.getString("Material");
629 
630  ARICHGeoSupport support = geo.getSupportStructure();
631  support.clearBoxes();
632  for (const GearDir& scint : scints.getNodes("Scintilator")) {
633  std::string name = scint.getString("@name");
634  double position[3] = {scint.getLength("Position/x"), scint.getLength("Position/y"), scint.getLength("Position/z")};
635  double rotation[3] = {scint.getAngle("Rotation/x"), scint.getAngle("Rotation/y"), scint.getAngle("Rotation/z")};
636  support.addBox(name, scintMat, size, position, rotation);
637  }
638 
639  geo.setSupportStructure(support);
640 
641  IntervalOfValidity iov(0, 0, -1, -1); // IOV (0,0,-1,-1) is valid for all runs and experiments
642  geoImport.import(iov);
643 
644 }
645 
646 void ARICHDatabaseImporter::importAeroTilesInfo()
647 {
648  ARICHAeroTilesInfo tilesInfo;
649 
650  DBArray<ARICHAerogelMap> elements("ARICHAerogelMap");
651  elements.getEntries();
652  DBArray<ARICHAerogelInfo> elementsInfo("ARICHAerogelInfo");
653  elementsInfo.getEntries();
654 
655  for (int slot = 1; slot < 125; slot++) {
656  int ring = ARICHDatabaseImporter::getAeroTileRing(slot);
657  int column = ARICHDatabaseImporter::getAeroTileColumn(slot);
658  std::string aeroID = "";
659  float refractiveIndex = 0.;
660  float transmissionLength = 0.;
661  float thickness = 0.;
662  for (int layer = 0; layer < 2; layer++) {
663  for (const auto& element : elements) {
664  if (element.getAerogelLayer(layer) == 1 && element.getAerogelRingID() == ring
665  && element.getAerogelColumnID() == column) aeroID = element.getAerogelSN();
666  }
667  for (const auto& elementInfo : elementsInfo) {
668  if (elementInfo.getAerogelSN() == aeroID) {
669  refractiveIndex = elementInfo.getAerogelRefractiveIndex();
670  transmissionLength = elementInfo.getAerogelTransmissionLength();
671  thickness = elementInfo.getAerogelThickness();
672  }
673  }
674 
675  B2INFO("adding mapping... slot " << slot
676  << ", layer " << layer
677  << ", refIn " << refractiveIndex
678  << ", transLen " << transmissionLength
679  << ", thick " << thickness << '\n');
680  tilesInfo.addMapping(slot, layer, refractiveIndex, transmissionLength, thickness);
681 
682  }
683  }
684 
686  importObj.construct(tilesInfo);
687  importObj.import(m_iov);
688 }
689 
690 int ARICHDatabaseImporter::getAeroTileRing(int slot)
691 {
692  int ring = 0;
693  if (slot < 23) ring = 1;
694  else if (slot > 22 && slot < 51) ring = 2;
695  else if (slot > 50 && slot < 85) ring = 3;
696  else ring = 4;
697 
698  return ring;
699 }
700 
701 int ARICHDatabaseImporter::getAeroTileColumn(int slot)
702 {
703  int column = 0;
704  if (slot < 23) column = slot;
705  else if (slot > 22 && slot < 51) column = slot - 22;
706  else if (slot > 50 && slot < 85) column = slot - 50;
707  else column = slot - 84;
708 
709  return column;
710 }
711 
712 
713 void ARICHDatabaseImporter::printAeroTileInfo()
714 {
716  tilesInfo->print();
717 }
718 
719 void ARICHDatabaseImporter::printGlobalAlignment()
720 {
722  align->print();
723 }
724 
725 void ARICHDatabaseImporter::printMirrorAlignment()
726 {
728  align->print();
729 }
730 
731 void ARICHDatabaseImporter::printAeroTilesAlignment()
732 {
734  align->print();
735 }
736 
737 // classes for DAQ
738 
739 void ARICHDatabaseImporter::importBiasMappings()
740 {
741 
742  GearDir content = GearDir("/DetectorCables[@name='ARICH']/Content");
743 
745 
746  ARICHBiasCablesMapping biasMap;
747  GearDir mapping(content, "biasCableMapping");
748 
749  for (const GearDir& module : mapping.getNodes("cableMap")) {
750  unsigned cableID = (unsigned) module.getInt("cableID");
751  unsigned innerID = module.getInt("innerID");
752  unsigned ring = module.getInt("ring");
753  unsigned azimuth = module.getInt("azimuth");
754  for (unsigned sector = 1; sector < 7; sector++) {
755  unsigned moduleID = geoConfig->getDetectorPlane().getSlotIDFromSRF(sector, ring, azimuth);
756  biasMap.addMapping(moduleID, sector, cableID, innerID);
757  }
758  }
759 
760  ARICHBiasChannelsMapping channelsMap;
761  GearDir mappingCH(content, "biasChannelMapping");
762 
763  for (const GearDir& module : mappingCH.getNodes("channelMap")) {
764  int crate = module.getInt("crate");
765  int slot = module.getInt("slot");
766  int channelID = module.getInt("channelID");
767  int pinID = module.getInt("pinID");
768  int connectionID = module.getInt("connectionID");
769  int innerID = module.getInt("innerID");
770  std::string type = module.getString("type");
771  channelsMap.addMapping(crate, slot, channelID, pinID, connectionID, innerID, type);
772  }
773 
775  GearDir mappingCrate(content, "biasCrateToCable");
776 
777  for (const GearDir& module : mappingCrate.getNodes("connection")) {
778  int connectionID = module.getInt("connectionID");
779  int sector = module.getInt("sector");
780  int cable = module.getInt("cable");
781  std::vector<int> sectorCable{sector, cable};
782 
783  crateMap.addMapping(connectionID, sectorCable);
784  }
785 
787  importObjBias.construct(biasMap);
788  importObjBias.import(m_iov);
789 
791  importObjBiasCH.construct(channelsMap);
792  importObjBiasCH.import(m_iov);
793 
795  importObjBiasCrate.construct(crateMap);
796  importObjBiasCrate.import(m_iov);
797 }
798 
799 void ARICHDatabaseImporter::importHvMappings()
800 {
801 
802  GearDir content = GearDir("/DetectorCables[@name='ARICH']/Content");
803 
805 
806  ARICHHvCablesMapping hvMap;
807  GearDir mapping(content, "hvCableToModuleMapping");
808 
809  for (const GearDir& module : mapping.getNodes("cableMap")) {
810  unsigned cableID = (unsigned) module.getInt("cableID");
811  unsigned innerID = module.getInt("innerID");
812  unsigned ring = module.getInt("ring");
813  unsigned azimuth = module.getInt("azimuth");
814  for (unsigned sector = 1; sector < 7; sector++) {
815  unsigned moduleID = geoConfig->getDetectorPlane().getSlotIDFromSRF(sector, ring, azimuth);
816  hvMap.addMapping(moduleID, sector, cableID, innerID);
817  }
818  }
819 
820  ARICHHvChannelsMapping channelsMap;
821  GearDir mappingCH(content, "hvChannelMapping");
822 
823  for (const GearDir& module : mappingCH.getNodes("channelMap")) {
824  int crate = module.getInt("crate");
825  int slot = module.getInt("slot");
826  int channelID = module.getInt("channelID");
827  int connectionID = module.getInt("connectionID");
828  int pinID = module.getInt("pinID");
829  channelsMap.addMapping(crate, slot, channelID, connectionID, pinID);
830  }
831 
832  ARICHHvCrateCableMapping crateMap;
833  GearDir mappingCrate(content, "hvCrateToCable");
834 
835  for (const GearDir& module : mappingCrate.getNodes("connection")) {
836  int connectionID = module.getInt("connectionID");
837  int sector = module.getInt("sector");
838  int cable = module.getInt("cable");
839  std::vector<int> sectorCable{sector, cable};
840 
841  crateMap.addMapping(connectionID, sectorCable);
842  }
843 
845  importObjHv.construct(hvMap);
846  importObjHv.import(m_iov);
847 
849  importObjHvCH.construct(channelsMap);
850  importObjHvCH.import(m_iov);
851 
853  importObjHvCrate.construct(crateMap);
854  importObjHvCrate.import(m_iov);
855 }
856 
857 
858 
859 void ARICHDatabaseImporter::importNominalBiasVoltages()
860 {
861 
862  GearDir content = GearDir("/DetectorCables[@name='ARICH']/Content");
863 
865 
866  ARICHBiasVoltages biasVolt;
867  GearDir biasVoltages(content, "biasVoltages");
868 
869  for (const GearDir& module : biasVoltages.getNodes("hapd")) {
870  std::string hapdID = module.getString("@id");
871  int biasA = module.getInt("biasA");
872  int biasB = module.getInt("biasB");
873  int biasC = module.getInt("biasC");
874  int biasD = module.getInt("biasD");
875  int guard = module.getInt("guard");
876  std::vector<int> voltages{biasA, biasB, biasC, biasD, guard};
877  biasVolt.addVoltages(hapdID, voltages);
878  }
879 
880  DBImportObjPtr<ARICHBiasVoltages> importObjBiasVolt;
881  importObjBiasVolt.construct(biasVolt);
882  importObjBiasVolt.import(m_iov);
883 }
884 
885 
886 void ARICHDatabaseImporter::printBiasMappings()
887 {
889  biasMap->print();
891  channelsMap->print();
893  crateMap->print();
894 }
895 
896 void ARICHDatabaseImporter::printHvMappings()
897 {
899  hvMap->print();
901  crateMap->print();
902 }
903 
904 void ARICHDatabaseImporter::dumpHvMappings()
905 {
907 
908  ARICHChannelHist* hist = new ARICHChannelHist("hvMapping", "module - HV cable mapping", 1);
909  for (int hapdID = 1; hapdID < 421; hapdID++) {
910  int val = hvMap->getCableID(hapdID) * 100 + hvMap->getInnerID(hapdID);
911  hist->setBinContent(hapdID, val);
912  }
913  hist->SetOption("TEXT");
914  hist->SaveAs("HVMapping.root");
915 }
916 
917 void ARICHDatabaseImporter::printNominalBiasVoltages()
918 {
920  biasVolt->print();
921 }
922 
923 void ARICHDatabaseImporter::printNominalBiasVoltageForChannel(std::vector<int> channel)
924 {
929  DBArray<ARICHSensorModuleInfo> elements("ARICHSensorModuleInfo");
930  elements.getEntries();
931 
932  int connectionID = std::get<0>(channelsMap->getInnerConnection(channel));
933  int innerCable = std::get<1>(channelsMap->getInnerConnection(channel));
934  std::string biasType = std::get<2>(channelsMap->getInnerConnection(channel));
935 
936  int sector = crateMap->getSector(connectionID);
937  int outerCable = crateMap->getCable(connectionID);
938 
939  int moduleID = (int) biasMap->getModuleID(sector, outerCable, innerCable);
940  std::string hapdID = "";
941  for (const auto& element : elements) {
942  if (element.getSensorModuleID() == moduleID) hapdID = element.getHAPDserial();
943  }
944 
945  std::vector<int> voltages = biasVolt->getBiasVoltages(hapdID);
946  int appliedVoltage = 0;
947 // std::string appliedVoltage = "zero";
948  if (biasType == "bias-a") appliedVoltage = voltages[0];
949  if (biasType == "bias-b") appliedVoltage = voltages[1];
950  if (biasType == "bias-c") appliedVoltage = voltages[2];
951  if (biasType == "bias-d") appliedVoltage = voltages[3];
952  if (biasType == "guard") appliedVoltage = voltages[4];
953 
954 
955  B2INFO("Crate " << channel[0] << ", slot " << channel[1] << ", slot channel " << channel[2] << " belongs to hapd " << hapdID <<
956  " (module ID = " << moduleID << ") in sector " << sector << ".\n Corresponding cable is " << sector << "-" << outerCable <<
957  ".\n Cable type is " << biasType << " with applied voltage " << appliedVoltage << " V.");
958 // B2INFO(channel[0] << "," << channel[1] << "," << channel[2] << "," << moduleID << "," << sector << "," << outerCable << "," << biasType << "," << appliedVoltage);
959 }
960 
961 void ARICHDatabaseImporter::printHapdPositionFromCrateSlot(int crate, int slot, int channelID)
962 {
967 
968  DBArray<ARICHSensorModuleMap> elements("ARICHSensorModuleMap");
969  elements.getEntries();
970 
971  std::vector<int> channel{crate, slot, channelID};
972  int connectionID = std::get<0>(channelsMap->getInnerConnection(channel));
973  int innerCableNum = std::get<1>(channelsMap->getInnerConnection(channel));
974  std::string biasType = channelsMap->getType(channel);
975 
976  int sector = crateMap->getSector(connectionID);
977  int outerCable = crateMap->getCable(connectionID);
978 
979  int moduleID = (int)biasMap->getModuleID(sector, outerCable, innerCableNum);
980 
981  unsigned mergerID = mrgMap->getMergerID((unsigned)moduleID);
982  unsigned mergerSN = mrgMap->getMergerSN((unsigned)mergerID);
983  unsigned febSlot = mrgMap->getFEBSlot((unsigned)moduleID);
984  int febSlotDaq = ARICHDatabaseImporter::getFebDaqSlot(febSlot);
985 
986  for (const auto& element : elements) {
987  if (element.getSensorGlobalID() == moduleID) B2INFO("HAPD for crate " << crate + 1 << ", slot " << slot << ", inner cable " <<
988  innerCableNum << " has ID number " << moduleID << ". Bias cable number is " << sector << "-" << outerCable <<
989  ".\n Position is: RING " << element.getSensorModuleRingID() << " COLUMN " << element.getSensorModuleColumnID() <<
990  ". \n Bias type for channel " << channelID << " is " << biasType << ".\n It belongs to merger " << mergerID << " (SN " <<
991  mergerSN << ") and has DAQ feb slot " << febSlotDaq);
992  }
993 
994 }
995 
996 int ARICHDatabaseImporter::getFebDaqSlot(unsigned febSlot)
997 {
998  std::map<unsigned, int> febSlots;
999  febSlots.insert(std::pair<unsigned, int>(6, 0));
1000  febSlots.insert(std::pair<unsigned, int>(5, 1));
1001  febSlots.insert(std::pair<unsigned, int>(4, 2));
1002  febSlots.insert(std::pair<unsigned, int>(1, 3));
1003  febSlots.insert(std::pair<unsigned, int>(2, 4));
1004  febSlots.insert(std::pair<unsigned, int>(3, 5));
1005 
1006  int febDaqSlot = febSlots.find(febSlot)->second;
1007 
1008  return febDaqSlot;
1009 }
1010 
1011 void ARICHDatabaseImporter::printSimulationPar()
1012 {
1014  simPar->print();
1015 }
1016 
1017 void ARICHDatabaseImporter::printGeometryConfig()
1018 {
1020  geoConfig->print();
1021 
1022 }
1023 
1024 void ARICHDatabaseImporter::printChannelMapping()
1025 {
1027  chMap->print();
1028 }
1029 
1030 void ARICHDatabaseImporter::printMergerMapping()
1031 {
1033  mrgMap->print();
1034 }
1035 
1036 void ARICHDatabaseImporter::printCopperMapping()
1037 {
1039  copMap->print();
1040 }
1041 
1042 void ARICHDatabaseImporter::printModulesInfo()
1043 {
1045  modinfo->print();
1046 }
1047 
1048 void ARICHDatabaseImporter::printReconstructionPar()
1049 {
1051  recPar->print();
1052 }
1053 
1054 
1055 void ARICHDatabaseImporter::printChannelMask(bool makeHist)
1056 {
1057 
1059  chMask->print();
1060 
1061  if (makeHist) {
1062  ARICHChannelHist* hist = new ARICHChannelHist("channelMask", "Map of active channels");
1063  for (int hapdID = 1; hapdID < 421; hapdID++) {
1064  for (int ichn = 0; ichn < 144; ichn++) {
1065  if (chMask->isActive(hapdID, ichn)) hist->setBinContent(hapdID, ichn, 1.0);
1066  }
1067  }
1068  hist->SaveAs("channelMask.root");
1069  }
1070 }
1071 
1072 void ARICHDatabaseImporter::dumpMergerMapping(bool sn)
1073 {
1075  ARICHChannelHist* hist = new ARICHChannelHist("mergerNum", "module - merger mapping", 1);
1076  for (int hapdID = 1; hapdID < 421; hapdID++) {
1077  int val = mgrMap->getMergerID(hapdID);
1078  if (sn) val = mgrMap->getMergerSN(val);
1079  hist->setBinContent(hapdID, val);
1080  }
1081  hist->SetOption("TEXT");
1082  hist->SaveAs("MergerMapping.root");
1083 
1084 }
1085 
1086 void ARICHDatabaseImporter::printFEMappings()
1087 {
1088 
1092 
1093  GearDir content = GearDir("/Detector/DetectorComponent[@name='ARICH']/Content/InstalledModules");
1094 
1095  cout << "{ \"hapdmap\": [" << endl;
1096  for (unsigned hapdID = 1; hapdID < 421; hapdID++) {
1097  std::string hapdsn;
1098  for (const GearDir& module : content.getNodes("Module")) {
1099  hapdsn = module.getString("@hapdID");
1100  unsigned sector = module.getInt("Sector");
1101  unsigned ring = module.getInt("Ring");
1102  unsigned azimuth = module.getInt("Azimuth");
1103  unsigned moduleID = geoConfig->getDetectorPlane().getSlotIDFromSRF(sector, ring, azimuth);
1104  if (moduleID == hapdID) break;
1105  }
1106 
1107  int val = mgrMap->getMergerID(hapdID);
1108  cout << "{\n" << "\"ID\": \"" << hapdID << "\"," << endl;
1109  cout << "\"sn\": \"" << hapdsn << "\"," << endl;
1110  cout << "\"mrg\": \"" << val << "\"," << endl;
1111  cout << "\"mrgSN\": \"" << mgrMap->getMergerSN(val) << "\"," << endl;
1112  cout << "\"feb\": \"" << mgrMap->getFEBSlot(hapdID) - 1 << "\"," << endl;
1113  cout << "\"cpr\": \"" << cprMap->getCopperID(val) << "\"," << endl;
1114  cout << "\"hslb\": \"" << cprMap->getFinesse(val) << "\"" << endl;
1115  if (hapdID < 420) cout << "}," << endl;
1116  else cout << "}" << endl;
1117  }
1118  cout << "]}" << endl;
1119 
1120 
1121 }
1122 
1123 void ARICHDatabaseImporter::dumpModuleNumbering()
1124 {
1125 
1126  ARICHChannelHist* hist = new ARICHChannelHist("moduleNum", "HAPD module slot numbering", 1);
1127  for (int hapdID = 1; hapdID < 421; hapdID++) {
1128  hist->setBinContent(hapdID, hapdID);
1129  }
1130  hist->SetOption("TEXT");
1131  hist->SaveAs("ModuleNumbering.root");
1132 
1133 }
1134 
1135 void ARICHDatabaseImporter::dumpQEMap(bool simple)
1136 {
1140 
1141  if (simple) {
1142  TGraph2D* gr = new TGraph2D();
1143  int point = 0;
1144  for (int i = 1; i < 421; i++) {
1145  if (modInfo->isInstalled(i)) {
1146  for (int j = 0; j < 144; j++) {
1147  int xCh, yCh;
1148  chMap->getXYFromAsic(j, xCh, yCh);
1149  TVector2 chPos = geoConfig->getChannelPosition(i, xCh, yCh);
1150  gr->SetPoint(point, chPos.X(), chPos.Y(), modInfo->getChannelQE(i, j));
1151  point++;
1152  }
1153  }
1154  }
1155  gr->SaveAs("QEMap.root");
1156  } else {
1157  ARICHChannelHist* hist = new ARICHChannelHist("hapdQE", "hapd QE map");
1158  for (int hapdID = 1; hapdID < 421; hapdID++) {
1159  if (!modInfo->isInstalled(hapdID)) continue;
1160  for (int chID = 0; chID < 144; chID++) {
1161  hist->setBinContent(hapdID, chID, modInfo->getChannelQE(hapdID, chID));
1162  }
1163  }
1164  hist->SaveAs("QEMap.root");
1165  }
1166 }
1167 
1168 void ARICHDatabaseImporter::dumpAerogelOpticalProperties(std::string outRootFileName)
1169 {
1170 
1171  ARICHAerogelHist* h2_aerogel_up_n = new ARICHAerogelHist("h2_aerogel_up_n", "aerogel up n");
1172  ARICHAerogelHist* h2_aerogel_up_transmL = new ARICHAerogelHist("h2_aerogel_up_transmL", "aerogel up transmL");
1173  ARICHAerogelHist* h2_aerogel_up_thick = new ARICHAerogelHist("h2_aerogel_up_thick", "aerogel up thick");
1174  ARICHAerogelHist* h2_aerogel_down_n = new ARICHAerogelHist("h2_aerogel_down_n", "aerogel down n");
1175  ARICHAerogelHist* h2_aerogel_down_transmL = new ARICHAerogelHist("h2_aerogel_down_transmL", "aerogel down transmL");
1176  ARICHAerogelHist* h2_aerogel_down_thick = new ARICHAerogelHist("h2_aerogel_down_thick", "aerogel down thick");
1177 
1178  std::string condDBname = "ARICHdata";
1179 
1180  if (condDBname == "ARICHdata") {
1181 
1182  //
1183  DBArray<ARICHAerogelMap> elementsM("ARICHAerogelMap");
1184  elementsM.getEntries();
1185  DBArray<ARICHAerogelInfo> elementsI("ARICHAerogelInfo");
1186  elementsI.getEntries();
1187 
1188  //
1189  for (const auto& elementM : elementsM) {
1190  if (elementM.getAerogelLayer(0) == 1) {
1191  for (const auto& elementI : elementsI) {
1192  if (elementI.getAerogelSN() == elementM.getAerogelSN()) {
1193  //down
1194  h2_aerogel_down_n->SetBinContent(h2_aerogel_down_n->GetBinIDFromRingColumn(elementM.getAerogelRingID(),
1195  elementM.getAerogelColumnID()), elementI.getAerogelRefractiveIndex());
1196  h2_aerogel_down_transmL->SetBinContent(h2_aerogel_down_transmL->GetBinIDFromRingColumn(elementM.getAerogelRingID(),
1197  elementM.getAerogelColumnID()), elementI.getAerogelTransmissionLength());
1198  h2_aerogel_down_thick->SetBinContent(h2_aerogel_down_thick->GetBinIDFromRingColumn(elementM.getAerogelRingID(),
1199  elementM.getAerogelColumnID()), elementI.getAerogelThickness());
1200  }// if (elementI.getAerogelSN() == elementM.getAerogelSN()){
1201  }// for (const auto& elementI : elementsI) {
1202  }
1203  if (elementM.getAerogelLayer(1) == 1) {
1204  for (const auto& elementI : elementsI) {
1205  if (elementI.getAerogelSN() == elementM.getAerogelSN()) {
1206  //up
1207  h2_aerogel_up_n->SetBinContent(h2_aerogel_up_n->GetBinIDFromRingColumn(elementM.getAerogelRingID(), elementM.getAerogelColumnID()),
1208  elementI.getAerogelRefractiveIndex());
1209  h2_aerogel_up_transmL->SetBinContent(h2_aerogel_up_transmL->GetBinIDFromRingColumn(elementM.getAerogelRingID(),
1210  elementM.getAerogelColumnID()), elementI.getAerogelTransmissionLength());
1211  h2_aerogel_up_thick->SetBinContent(h2_aerogel_up_thick->GetBinIDFromRingColumn(elementM.getAerogelRingID(),
1212  elementM.getAerogelColumnID()), elementI.getAerogelThickness());
1213  }// if (elementI.getAerogelSN() == elementM.getAerogelSN()){
1214  }// for (const auto& elementI : elementsI) {
1215  }
1216  }// for (const auto& elementM : elementsM) {
1217 
1218  }// if (condDBname = "ARICHdata") {
1219  //else { // if (condDBname = "ARICHdata") {
1220  //To be added later when the information about aerogel optical properties
1221  //would be available not only in ARICHdata
1222  //}
1223 
1224  TFile* rootFile = new TFile(outRootFileName.c_str(), "RECREATE", " Histograms", 1);
1225  rootFile->cd();
1226  if (rootFile->IsZombie()) {
1227  B2ERROR(" ERROR ---> file : " << outRootFileName.c_str() << " is zombi");
1228  }
1229  h2_aerogel_up_n->Write();
1230  h2_aerogel_up_transmL->Write();
1231  h2_aerogel_up_thick->Write();
1232  h2_aerogel_down_n->Write();
1233  h2_aerogel_down_transmL->Write();
1234  h2_aerogel_down_thick->Write();
1235  rootFile->Close();
1236 }
1237 
1238 //class for ARICH aerogel Rayleigh scattering fit parameters
1239 void ARICHDatabaseImporter::importAeroRayleighScatteringFit(std::string commentSingleWord)
1240 {
1241  GearDir content = GearDir("/aerogelFit");
1242 
1243  //cout<<" ARICHDatabaseImporter::importAeroRayleighScatteringFit "<<endl;
1244 
1245  // define data array
1246  TClonesArray agelFitConstants("Belle2::ARICHAerogelRayleighScatteringFit");
1247  int agel = 0;
1248  string serial;
1249  float version = (float) content.getDouble("version");
1250 
1251  // loop over xml files and extract the data
1252  for (const auto& aerogel : content.getNodes("aerogeltile")) {
1253  //cout<<agel<<" serial : "<<<<endl;
1254  serial = aerogel.getString("serial");
1255  vector<float> vPar;
1256  vPar.push_back((float)aerogel.getDouble("p0"));
1257  vPar.push_back((float)aerogel.getDouble("p1"));
1258  vPar.push_back((float)aerogel.getDouble("p2"));
1259  vPar.push_back((float)aerogel.getDouble("p3"));
1260  vPar.push_back((float)aerogel.getDouble("p4"));
1261  vPar.push_back((float)aerogel.getDouble("p5"));
1262  vPar.push_back((float)aerogel.getDouble("p6"));
1263  ARICHAerogelRayleighScatteringFit* aeroRayScatFit = new ARICHAerogelRayleighScatteringFit(version, serial, commentSingleWord, vPar);
1264  //if(agel == 0)
1265  // aeroRayScatFit->printContent(true);
1266  //else
1267  // aeroRayScatFit->printContent();
1268  agelFitConstants[agel] = aeroRayScatFit;
1269  agel++;
1270  }
1271 
1272  // store under default name:
1273  // Database::Instance().storeData(&agelConstants, iov);
1274  // store under user defined name:
1275  TString coreName = "ARICHAerogelRayleighScatteringFit";
1276  TString coreNameSuffix = commentSingleWord;
1277  if (coreNameSuffix != "")
1278  coreName += coreNameSuffix;
1279  Database::Instance().storeData(coreName.Data(), &agelFitConstants, m_iov);
1280 
1281 }
1282 
1283 // classes for quality assessment and test data
1284 void ARICHDatabaseImporter::importAerogelInfo(TString coreNameSuffix)
1285 {
1286  GearDir content = GearDir("/ArichData/AllData/AerogelData/Content");
1287 
1288  // define data array
1289  TClonesArray agelConstants("Belle2::ARICHAerogelInfo");
1290  int agel = 0;
1291 
1292  // loop over xml files and extract the data
1293  for (const auto& aerogel : content.getNodes("aerogel")) {
1294  float version = (float) aerogel.getDouble("version");
1295  string serial = aerogel.getString("serial");
1296  string id = aerogel.getString("id");
1297  float index = (float) aerogel.getDouble("index");
1298  float trlen = ((float) aerogel.getDouble("translength")) * Unit::mm;
1299  float thickness = ((float) aerogel.getDouble("thick")) * Unit::mm;
1300  vector<int> lambdas;
1301  vector<float> transmittances;
1302  for (const auto& transmittance : aerogel.getNodes("transmittance/transpoint")) {
1303  int lambda = transmittance.getInt("@lambda");
1304  float val = (float) transmittance.getDouble(".");
1305  lambdas.push_back(lambda);
1306  transmittances.push_back(val);
1307  }
1308 
1309  // save data as an element of the array
1310  new(agelConstants[agel]) ARICHAerogelInfo(version, serial, id, index, trlen, thickness, lambdas, transmittances);
1311  agel++;
1312  }
1313 
1314  // define interval of validity
1315 
1316  // store under default name:
1317  // Database::Instance().storeData(&agelConstants, iov);
1318  // store under user defined name:
1319  TString coreName = "ARICHAerogelInfo";
1320  if (coreNameSuffix != "")
1321  coreName += coreNameSuffix;
1322  Database::Instance().storeData(coreName.Data(), &agelConstants, m_iov);
1323 }
1324 
1325 void ARICHDatabaseImporter::exportAerogelInfo(int verboseLevel)
1326 {
1327 
1328  // Definition:
1329  // This function extracts data from the database for chosen event.
1330 
1331  /*
1332  // Extract data from payload with bounded validity
1333 
1334  // Define event, run and experiment numbers
1335  EventMetaData event = EventMetaData(1200,4,0); // (event, run, exp)
1336 
1337  // Extract object and IOV from database
1338  std::pair<TObject*, IntervalOfValidity> podatki = Database::Instance().getData(event, "dbstore", "ARICHAerogelInfo");
1339 
1340  // print interval of validity
1341  // IntervalOfValidity iov = std::get<1>(podatki);
1342  // B2INFO("iov = " << iov);
1343 
1344  // Convert between different class types and extract TClonesArray
1345  // for chosen event
1346  TObject* data;
1347  data = std::get<0>(podatki);
1348  TClonesArray* elements = static_cast<TClonesArray*>(data);
1349 
1350  // Get entries from TClonesArray and print aerogel info
1351  (*elements).GetEntries();
1352  for (int i = 0; i < elements->GetSize(); i++) {
1353  ARICHAerogelInfo* myelement = static_cast<ARICHAerogelInfo*>(elements->At(i));
1354  B2INFO("Version = " << myelement->getAerogelVersion() << ", SN = " << myelement->getAerogelSN() << ", n = " << myelement->getAerogelRefractiveIndex() << ", trl = " << myelement->getAerogelTransmissionLength() << ", thickness = " << myelement->getAerogelThickness());
1355  }
1356  */
1357 
1358 
1359 
1360  // Extract data from payload with unbounded validity
1361  DBArray<ARICHAerogelInfo> elements("ARICHAerogelInfo");
1362  elements.getEntries();
1363 
1364  // Print aerogel info
1365  for (const auto& element : elements) {
1366  B2INFO("Version = " << element.getAerogelVersion() << ", serial = " << element.getAerogelSN() <<
1367  ", id = " << element.getAerogelID() << ", n = " << element.getAerogelRefractiveIndex() << ", transmLength = " <<
1368  element.getAerogelTransmissionLength() << ", thickness = " << element.getAerogelThickness());
1369  if (verboseLevel > 0) {
1370  unsigned int ii = 0;
1371  int lllambda = 200;
1372  while (lllambda > 0) {
1373  lllambda = element.getAerogelTransmittanceLambda(ii);
1374  if (lllambda < 0)
1375  break;
1376  float llval = element.getAerogelTransmittance(ii);
1377  B2INFO(" Lambda = " << lllambda << " Transmittance = " << llval);
1378  ii++;
1379  }// while(lllambda > 0){
1380  }// if(verboseLevel>0){
1381  }// for (const auto& element : elements) {
1382 
1383 }
1384 
1385 
1386 void ARICHDatabaseImporter::importAerogelMap()
1387 {
1388  GearDir content = GearDir("/ArichData/AllData/aerogelposition");
1389 
1390  // define data array
1391  TClonesArray agelMap("Belle2::ARICHAerogelMap");
1392  int agel = 0;
1393 
1394  for (int layer = 0; layer < 2; layer++) {
1395  // loop over xml files and extract the data
1396  for (const auto& aerogel : content.getNodes("position")) {
1397  string agelserial = "";
1398  int ring = aerogel.getInt("ring");
1399  int phi = aerogel.getInt("phi");
1400  if (layer == 1) agelserial = aerogel.getString("upaerogelserial");
1401  if (layer == 0) agelserial = aerogel.getString("downaerogelserial");
1402 
1403  // save data as an element of the array
1404  new(agelMap[agel]) ARICHAerogelMap();
1405  auto* agelConst = static_cast<ARICHAerogelMap*>(agelMap[agel]);
1406  agelConst->setAerogelSN(agelserial);
1407  agelConst->setAerogelRingID(ring);
1408  agelConst->setAerogelColumnID(phi);
1409  agelConst->setAerogelLayer(layer, 1);
1410 
1411  agel++;
1412  }
1413  }
1414 
1415  // store under user defined name:
1416  Database::Instance().storeData("ARICHAerogelMap", &agelMap, m_iov);
1417 }
1418 
1419 
1420 
1421 void ARICHDatabaseImporter::exportAerogelMap()
1422 {
1423 
1424  DBArray<ARICHAerogelMap> elements("ARICHAerogelMap");
1425  elements.getEntries();
1426 
1427  // Print aerogel info
1428  for (const auto& element : elements) {
1429  string layer;
1430  if (element.getAerogelLayer(0) == 1) layer = "down";
1431  if (element.getAerogelLayer(1) == 1) layer = "up";
1432  B2INFO("ID = " << element.getAerogelSN() << ", ring = " << element.getAerogelRingID() <<
1433  ", column = " << element.getAerogelColumnID() << ", layer: " << layer);
1434  }
1435 }
1436 
1437 
1438 void ARICHDatabaseImporter::importAerogelInfoEventDep()
1439 {
1440  GearDir content = GearDir("/ArichData/AllData/AerogelData/Content");
1441 
1442  // define data arrays
1443  TClonesArray agelConstantsA("Belle2::ARICHAerogelInfo");
1444  TClonesArray agelConstantsB("Belle2::ARICHAerogelInfo");
1445  TClonesArray agelConstantsC("Belle2::ARICHAerogelInfo");
1446 
1447 
1448  for (int someint = 0; someint < 3; someint++) {
1449  int agel = 0;
1450  // loop over xml files and extract the data
1451  for (const auto& aerogel : content.getNodes("aerogel")) {
1452  // different version is made up - only used to check performance
1453  // of intrarun dependat function
1454  float version = 0;
1455  if (someint == 0) version = (float) aerogel.getDouble("version");
1456  if (someint == 1) version = 4.0;
1457  if (someint == 2) version = 5.0;
1458 
1459  string serial = aerogel.getString("serial");
1460  string id = aerogel.getString("id");
1461  float index = (float) aerogel.getDouble("index");
1462  float trlen = ((float) aerogel.getDouble("translength")) * Unit::mm;
1463  float thickness = ((float) aerogel.getDouble("thick")) * Unit::mm;
1464  vector<int> lambdas;
1465  vector<float> transmittances;
1466  for (const auto& transmittance : aerogel.getNodes("transmittance/transpoint")) {
1467  int lambda = transmittance.getInt("@lambda");
1468  float val = (float) transmittance.getDouble(".");
1469  lambdas.push_back(lambda);
1470  transmittances.push_back(val);
1471  }
1472 
1473  // save data as an element of the array
1474  if (someint == 0) new(agelConstantsA[agel]) ARICHAerogelInfo(version, serial, id, index, trlen, thickness, lambdas,
1475  transmittances);
1476  if (someint == 1) new(agelConstantsB[agel]) ARICHAerogelInfo(version, serial, id, index, trlen, thickness, lambdas,
1477  transmittances);
1478  if (someint == 2) new(agelConstantsC[agel]) ARICHAerogelInfo(version, serial, id, index, trlen, thickness, lambdas,
1479  transmittances);
1480  agel++;
1481  }
1482  }
1483 
1484  // convert pointers to ARICHAerogelInfo into pointers to TObject
1485  TObject* agelObj[3];
1486  agelObj[0] = static_cast<TObject*>(&agelConstantsA);
1487  agelObj[1] = static_cast<TObject*>(&agelConstantsB);
1488  agelObj[2] = static_cast<TObject*>(&agelConstantsC);
1489 
1490  // add objects with different validity
1491  EventDependency intraRun(agelObj[0]);
1492  intraRun.add(500, agelObj[1]); // valid from event number 500
1493  intraRun.add(1000, agelObj[2]); // valid from event number 1000
1494 
1495  // store under user defined name
1496  Database::Instance().storeData("ARICHAerogelInfoEventDep", &intraRun, m_iov);
1497 
1498 }
1499 
1500 void ARICHDatabaseImporter::exportAerogelInfoEventDep()
1501 {
1502  // Definition:
1503  // This function extracts intrarun dependant data from the database.
1504  // It converts between different class types to get the saved
1505  // TClonesArray for chosen event, run and experiment.
1506 
1507 
1508  // Define event, run and experiment numbers
1509  EventMetaData event = EventMetaData(1200, 4, 0); // (event, run, exp)
1510 
1511  // Extract object and IOV from database
1512  std::pair<TObject*, IntervalOfValidity> podatki = Database::Instance().getData(event, "ARICHAerogelInfoEventDep");
1513 
1514  // print interval of validity
1515 // IntervalOfValidity iov = std::get<1>(podatki);
1516 // B2INFO("iov = " << iov);
1517 
1518  // Convert between different class types and extract TClonesArray
1519  // for chosen event
1520  TObject* data = std::get<0>(podatki);
1521  EventDependency* data2 = static_cast<EventDependency*>(data);
1522  TObject* myobject = data2->getObject(event);
1523  TClonesArray* elements = static_cast<TClonesArray*>(myobject);
1524 
1525  // Get entries from TClonesArray and print aerogel info
1526  (*elements).GetEntries();
1527  for (int i = 0; i < elements->GetSize(); i++) {
1528  ARICHAerogelInfo* myelement = (ARICHAerogelInfo*)elements->At(i);
1529  B2INFO("Version = " << myelement->getAerogelVersion() << ", SN = " << myelement->getAerogelSN() << ", n = " <<
1530  myelement->getAerogelRefractiveIndex() << ", trl = " << myelement->getAerogelTransmissionLength() << ", thickness = " <<
1531  myelement->getAerogelThickness());
1532  }
1533 
1534  /*
1535 
1536  // Extract data from the last added payload
1537  DBArray<ARICHAerogelInfo> elements("ARICHAerogelInfo");
1538  elements.getEntries();
1539 
1540  // Print aerogel info
1541 
1542  for (const auto& element : elements) {
1543  B2INFO("Version = " << element.getAerogelVersion() << ", serial = " << element.getAerogelSN() <<
1544  ", id = " << element.getAerogelID() << ", n = " << element.getAerogelRefractiveIndex() << ", transmLength = " <<
1545  element.getAerogelTransmissionLength() << ", thickness = " << element.getAerogelThickness())
1546  }
1547 
1548  */
1549 }
1550 
1551 
1552 void ARICHDatabaseImporter::importHapdQA()
1553 {
1554  // define data array
1555  TClonesArray hapdQAConstants("Belle2::ARICHHapdQA");
1556  int hapd = 0;
1557 
1558  // loop over root riles
1559  for (const string& inputFile : m_inputFilesHapdQA) {
1560  TFile* f = TFile::Open(inputFile.c_str(), "READ");
1561 
1562  int size = inputFile.length();
1563  string hapdSerial = inputFile.substr(size - 16, 6);
1564 
1565  vector<TGraph*> leakCurrent;
1566  TH2F* hitData2D = 0;
1567  vector<TGraph*> noise;
1568  vector<TH1S*> hitCount;
1569  TTimeStamp arrivalDate;
1570  int arrival;
1571  TTree* tree = 0;
1572 
1573  // extract data
1574  TIter next(f->GetListOfKeys());
1575  TKey* key;
1576  while ((key = (TKey*)next())) {
1577 
1578  string strime = key->GetName();
1579 
1580  if (strime.compare(0, 8, "gcurrent") == 0) {
1581  TGraph* graphcurrent = (TGraph*)f->Get(strime.c_str());
1582  leakCurrent.push_back(graphcurrent);
1583  }
1584 
1585  else if (strime.compare(0, 7, "h2dscan") == 0) {
1586  hitData2D = (TH2F*)f->Get(strime.c_str());
1587  hitData2D->SetDirectory(0);
1588  }
1589 
1590  else if (strime.compare(0, 9, "gnoise_ch") == 0) {
1591  TGraph* graphnoise = (TGraph*)f->Get(strime.c_str());
1592  noise.push_back(graphnoise);
1593  }
1594 
1595  else if (strime.compare(0, 7, "hchscan") == 0) {
1596  TH1F* hhist3 = (TH1F*)f->Get(strime.c_str());
1597  hhist3->SetDirectory(0);
1598 
1599  // conversion TH1F -> TH1S
1600 
1601  const char* hhist3_ime = hhist3->GetName();
1602  const char* hhist3_naslov = hhist3->GetTitle();
1603  int hhist3_nbins = hhist3->GetSize();
1604  TH1S* hhist3short = new TH1S(hhist3_ime, hhist3_naslov, hhist3_nbins - 2, 0, 1);
1605  for (int bin = 0; bin < hhist3_nbins; bin++) {
1606  hhist3short->SetBinContent(bin, hhist3->GetBinContent(bin));
1607  }
1608  hhist3short->SetDirectory(0);
1609  hitCount.push_back(hhist3short);
1610  }
1611 
1612  else if (strime.compare(0, 4, "tree") == 0) {
1613  tree = (TTree*)f->Get(strime.c_str());
1614  tree->SetBranchAddress("arrival", &arrival);
1615  tree->GetEntry(0);
1616  arrivalDate = TTimeStamp(arrival, 0);
1617  }
1618 
1619  else { B2INFO("Key name does not match any of the following: gcurrent, 2dscan, gnoise, hchscan, tree_ts! - serial number: " << hapdSerial << "; key name = " << strime.c_str()); }
1620  }
1621 
1622  // save data as an element of the array
1623  new(hapdQAConstants[hapd]) ARICHHapdQA(hapdSerial, arrivalDate, leakCurrent, hitData2D, noise, hitCount);
1624  hapd++;
1625  }
1626 
1627  // define IOV and store data to the DB
1628  Database::Instance().storeData("ARICHHapdQA", &hapdQAConstants, m_iov);
1629 }
1630 
1631 
1632 void ARICHDatabaseImporter::exportHapdQA()
1633 {
1634  DBArray<ARICHHapdQA> elements("ARICHHapdQA");
1635  elements.getEntries();
1636 
1637  // Print serial numbers of HAPDs
1638  for (const auto& element : elements) {
1639  B2INFO("Serial number = " << element.getHapdSerialNumber() << "; arrival date = " << element.getHapdArrivalDate());
1640  }
1641 }
1642 
1643 void ARICHDatabaseImporter::importAsicInfo()
1644 {
1645  GearDir content = GearDir("/ArichData/AllData/asicList");
1646  // define data array
1647  TClonesArray asicConstants("Belle2::ARICHAsicInfo");
1648  int asic = 0;
1649 
1650  for (const auto& asiclist : content.getNodes("asicinfo")) {
1651  string asicSerial = asiclist.getString("serial");
1652  string comment = asiclist.getString("comment");
1653  string numCH = asiclist.getString("num");
1654 
1655  // get time of measurement
1656  TTimeStamp timeFinishGain = ARICHDatabaseImporter::getAsicDate(asicSerial, "gain");
1657  TTimeStamp timeFinishOffset = ARICHDatabaseImporter::getAsicDate(asicSerial, "offset");
1658 
1659  // get lists of bad channels
1660  vector<int> nosignalCHs = ARICHDatabaseImporter::channelsList(asiclist.getString("nosignal"));
1661  vector<int> badconnCHs = ARICHDatabaseImporter::channelsList(asiclist.getString("badconn"));
1662  vector<int> badoffsetCHs = ARICHDatabaseImporter::channelsList(asiclist.getString("badoffset"));
1663  vector<int> badlinCHs = ARICHDatabaseImporter::channelsList(asiclist.getString("badlin"));
1664 
1665  int num = 0;
1666  if (numCH.find("many") != string::npos) {num = 5000; }
1667  else if (numCH.find("all") != string::npos) {num = 10000; }
1668  else {num = atoi(numCH.c_str()); }
1669 
1670 
1671  // save data as an element of the array
1672  new(asicConstants[asic]) ARICHAsicInfo();
1673  auto* asicConst = static_cast<ARICHAsicInfo*>(asicConstants[asic]);
1674 
1675  asicConst->setAsicID(asicSerial);
1676  asicConst->setTimeFinishGain(timeFinishGain);
1677  asicConst->setTimeFinishOffset(timeFinishOffset);
1678  asicConst->setDeadChannels(nosignalCHs);
1679  asicConst->setBadConnChannels(badconnCHs);
1680  asicConst->setBadOffsetChannels(badoffsetCHs);
1681  asicConst->setBadLinChannels(badlinCHs);
1682  asicConst->setNumOfProblematicChannels(num);
1683  asicConst->setComment(comment);
1684 
1685  asic++;
1686  }
1687 
1688  Database::Instance().storeData("ARICHAsicInfo", &asicConstants, m_iov);
1689 }
1690 
1691 void ARICHDatabaseImporter::importAsicInfoRoot()
1692 {
1693  TFile f1("asicInfoHistograms.root", "recreate");
1694  TH3F* gain0 = 0;
1695  TH3F* gain1 = 0;
1696  TH3F* gain2 = 0;
1697  TH3F* gain3 = 0;
1698  TH3F* offsetF = 0;
1699  TH3F* offsetR = 0;
1700  string asicSerial = "";
1701 
1702  // define tree
1703  TTree* tree = new TTree("asicInfo", "asic info data");
1704 
1705  tree->Branch("asicSerial", (void*)asicSerial.c_str(), "string/C", 1024);
1706  tree->Branch("gain0", "TH3F", &gain0);
1707  tree->Branch("gain1", "TH3F", &gain1);
1708  tree->Branch("gain2", "TH3F", &gain2);
1709  tree->Branch("gain3", "TH3F", &gain3);
1710  tree->Branch("offsetF", "TH3F", &offsetF);
1711  tree->Branch("offsetR", "TH3F", &offsetR);
1712 
1713  // loop over root files
1714  for (const string& inputFile : m_inputFilesAsicRoot) {
1715 
1716  string inputFileNew = (string) inputFile;
1717  string asicName = inputFileNew.substr(inputFileNew.find("/asicData") + 17);
1718  size_t findRoot = asicName.find(".root");
1719  if (findRoot != string::npos) {
1720  // extract the data from files
1721  TFile* f = TFile::Open(inputFile.c_str(), "READ", "", 0);
1722  TIter next(f->GetListOfKeys());
1723  TKey* key;
1724 
1725  // fill vectors with histograms with different gain and offset settings
1726  while ((key = (TKey*)next())) {
1727  string strname = key->GetName();
1728  if (strname.find("_g0") != string::npos) gain0 = (TH3F*)f->Get(strname.c_str());
1729  else if (strname.find("_g1") != string::npos) gain1 = (TH3F*)f->Get(strname.c_str());
1730  else if (strname.find("_g2") != string::npos) gain2 = (TH3F*)f->Get(strname.c_str());
1731  else if (strname.find("_g3") != string::npos) gain3 = (TH3F*)f->Get(strname.c_str());
1732  else if (strname.find("_f") != string::npos) offsetF = (TH3F*)f->Get(strname.c_str());
1733  else if (strname.find("_c") != string::npos) offsetR = (TH3F*)f->Get(strname.c_str());
1734  else B2INFO("Key name does not match any of the following: gain, offset!");
1735  }
1736 
1737  tree->Fill();
1738  f->Close();
1739  }
1740  }
1741 
1742  f1.cd();
1743  tree->Write();
1744  f1.Close();
1745 
1746 // define IOV and store data to the DB
1747  Database::Instance().addPayload("ARICHAsicInfoRoot", "asicInfoHistograms.root", m_iov);
1748 }
1749 
1750 TTimeStamp ARICHDatabaseImporter::getAsicDate(const std::string& asicSerial, const std::string& type)
1751 {
1752  TTimeStamp timeFinish;
1753  string line;
1754  size_t findText = 100;
1755 
1756  // extract measurement date for serial number
1757  for (const string& inputFile : m_inputFilesAsicTxt) {
1758  string inputFileNew = (string) inputFile;
1759  if (type == "gain") { findText = inputFileNew.find("dateGain.txt"); }
1760  else if (type == "offset") { findText = inputFileNew.find("dateOffset.txt"); }
1761  else {B2INFO("Check type of measurement!"); }
1762  if (findText != string::npos) {
1763  std::ifstream ifs(inputFile);
1764  if (ifs.is_open()) {
1765  while (ifs.good()) {
1766  std::getline(ifs, line);
1767  string asicSerial2 = asicSerial + ":";
1768  size_t findSerial = line.find(asicSerial2);
1769  if (findSerial != string::npos) {timeFinish = ARICHDatabaseImporter::timedate(line);}
1770  }
1771  }
1772  ifs.clear();
1773  ifs.close();
1774  }
1775  }
1776  return timeFinish;
1777 }
1778 
1779 TTimeStamp ARICHDatabaseImporter::timedate(std::string enddate)
1780 {
1781  // convert string into TTimeStamp
1782  string dateEnd = enddate.substr(enddate.find(":") + 2);
1783  string yearStr = dateEnd.substr(0, 4);
1784  string monthStr = dateEnd.substr(4, 2);
1785  string dayStr = dateEnd.substr(6, 2);
1786  string hourStr = dateEnd.substr(8, 2);
1787  string minStr = dateEnd.substr(10, 2);
1788  int year = atoi(yearStr.c_str());
1789  int month = atoi(monthStr.c_str());
1790  int day = atoi(dayStr.c_str());
1791  int hour = atoi(hourStr.c_str());
1792  int min = atoi(minStr.c_str());
1793  TTimeStamp datum = TTimeStamp(year, month, day, hour, min, 0, 0, kTRUE, -9 * 60 * 60);
1794  return datum;
1795 }
1796 
1797 vector<int> ARICHDatabaseImporter::channelsList(std::string badCH)
1798 {
1799 
1800  vector<int> CHs;
1801 
1802  if ((badCH.find("many") != string::npos) || (badCH.find("all") != string::npos)) CHs.emplace_back(-1);
1803  else ARICHTools::StringToVector::convert<int>(badCH, ',');
1804 
1805  return CHs;
1806 }
1807 
1808 
1809 void ARICHDatabaseImporter::exportAsicInfo()
1810 {
1811 
1812  DBArray<ARICHAsicInfo> elements("ARICHAsicInfo");
1813  elements.getEntries();
1814 
1815  // Print serial numbers of ASICs
1816  for (const auto& element : elements) {
1817  B2INFO("asic SN: " << element.getAsicID());
1818  }
1819 }
1820 
1821 
1822 void ARICHDatabaseImporter::importFebTest()
1823 {
1824 
1825  // define data array
1826  TClonesArray febConstants("Belle2::ARICHFebTest");
1827 
1828  int feb = 0;
1829 
1830  GearDir content = GearDir("/ArichData/AllData/arich");
1831  GearDir content1 = GearDir("/ArichData/AllData/dnamap");
1832  GearDir content2 = GearDir("/ArichData/AllData/FEBData/Content");
1833 
1834  for (const auto& runserial : content.getNodes("run")) {
1835  int serial = runserial.getInt("sn");
1836  // save data as an element of the array
1837  new(febConstants[feb]) ARICHFebTest();
1838  auto* febConst = static_cast<ARICHFebTest*>(febConstants[feb]);
1839  febConst->setFebSerial(serial);
1840 
1841  string runLV = runserial.getString("lv");
1842  string runHV = runserial.getString("hv");
1843  string runSCAN = runserial.getString("scan");
1844  string comment = runserial.getString("comment");
1845 
1846  febConst->setRunLV(runLV);
1847  febConst->setRunHV(runHV);
1848  febConst->setRunSlowC(runSCAN);
1849  febConst->setComment(comment);
1850 
1851  int l = 0;
1852  string dna;
1853 
1854  for (const auto& febmap : content1.getNodes("febps")) {
1855  string somedna = febmap.getString("@dna");
1856  int sn = febmap.getInt("sn");
1857  if ((l == 0) && (sn == serial)) {
1858  dna = somedna;
1859  febConst->setFebDna(dna);
1860  //febConst->setDeadChannels(ARICHDatabaseImporter::getDeadChFEB(dna));
1861  l++;
1862  }
1863  }
1864 
1865  // slow control data
1866  if (!runSCAN.empty()) {
1867  int scanRun;
1868  if (stoi(runSCAN.c_str()) < 23) {scanRun = stoi(runSCAN.c_str());}
1869  else {scanRun = stoi(runSCAN.c_str()) - 77;}
1870  for (const auto& testFEB : content2.getNodes("febtest[" + std::to_string(scanRun) + "]")) {
1871  string timeSlowC = testFEB.getString("time");
1872  int i = 0;
1873  int positionOld = 0;
1874 
1875  for (const auto& testFEBslowctest : testFEB.getNodes("slowc")) {
1876  int position = testFEBslowctest.getInt("id");
1877  if (position == positionOld) {i++; }
1878  else {i = 1; }
1879  if (i == 10) {
1880  string dnaNew = testFEBslowctest.getString("dna");
1881  if (dnaNew == dna) {
1882  float tmon0 = (float) testFEBslowctest.getDouble("TMON0");
1883  float tmon1 = (float) testFEBslowctest.getDouble("TMON1");
1884  float vdd = (float) testFEBslowctest.getDouble("VDD");
1885  float v2p = (float) testFEBslowctest.getDouble("V2P");
1886  float v2n = (float) testFEBslowctest.getDouble("V2N");
1887  float vss = (float) testFEBslowctest.getDouble("VSS");
1888  float vth1 = (float) testFEBslowctest.getDouble("VTH1");
1889  float vth2 = (float) testFEBslowctest.getDouble("VTH2");
1890  float vcc12 = (float) testFEBslowctest.getDouble("VCC12");
1891  float vcc15 = (float) testFEBslowctest.getDouble("VCC15");
1892  float vcc25 = (float) testFEBslowctest.getDouble("VCC25");
1893  float v38p = (float) testFEBslowctest.getDouble("V38P");
1894 
1895  febConst->setTemperature0(tmon0);
1896  febConst->setTemperature1(tmon1);
1897  febConst->setVdd(vdd);
1898  febConst->setV2p(v2p);
1899  febConst->setV2n(v2n);
1900  febConst->setVss(vss);
1901  febConst->setVth1(vth1);
1902  febConst->setVth2(vth2);
1903  febConst->setVcc12(vcc12);
1904  febConst->setVcc15(vcc15);
1905  febConst->setVcc25(vcc25);
1906  febConst->setV38p(v38p);
1907  febConst->setTimeSlowC(ARICHDatabaseImporter::timedate2(timeSlowC));
1908 
1909  }
1910  }
1911  positionOld = position;
1912  }
1913  }
1914 
1915  // slopes (from offset settings measurements)
1916  pair<vector<float>, vector<float>> slopes = ARICHDatabaseImporter::getSlopes(serial, runSCAN);
1917 
1918  febConst->setSlopesFine(slopes.first); // std::vector<float>
1919  febConst->setSlopesRough(slopes.second); // std::vector<float>
1920 
1921  // set FWHM values&sigmas)
1922  vector<pair<float, float>> fwhm = ARICHDatabaseImporter::getFwhm(serial, runSCAN);
1923  febConst->setFWHM(fwhm);
1924  }
1925 
1926 
1927  // high voltage test data
1928  if (!runHV.empty()) {
1929  int hvRun;
1930  if (stoi(runHV.c_str()) < 43) {hvRun = stoi(runHV.c_str());}
1931  else {hvRun = stoi(runHV.c_str()) - 57;}
1932  tuple<string, float> HVtest = ARICHDatabaseImporter::getFebHVtestData(serial, hvRun);
1933  febConst->setTimeHV(ARICHDatabaseImporter::timedate2(get<0>(HVtest)));
1934  febConst->setCurrentV99p(get<1>(HVtest));
1935  }
1936 
1937 
1938  // low voltage test data
1939  if (!runLV.empty()) {
1940  int lvRun;
1941  if (stoi(runLV.c_str()) < 43) {lvRun = stoi(runLV.c_str());}
1942  else {lvRun = stoi(runLV.c_str()) - 57;}
1943  tuple<string, float, float, float> LVtest = ARICHDatabaseImporter::getFebLVtestData(serial, lvRun);
1944  febConst->setTimeLV(ARICHDatabaseImporter::timedate2(get<0>(LVtest)));
1945  febConst->setCurrentV20p(get<1>(LVtest));
1946  febConst->setCurrentV21n(get<2>(LVtest));
1947  febConst->setCurrentV38p(get<3>(LVtest));
1948  }
1949 
1950  feb++;
1951 
1952  }
1953 
1954 // define IOV and store data to the DB
1955  Database::Instance().storeData("ARICHFebTest", &febConstants, m_iov);
1956 }
1957 
1958 
1959 
1960 void ARICHDatabaseImporter::importFebTestRoot()
1961 {
1962  TFile f("febTestHistograms.root", "recreate");
1963  TH3F* offsetRough = 0;
1964  TH3F* offsetFine = 0;
1965  TH2F* testPulse = 0;
1966  int serial;
1967 
1968  // define tree
1969  TTree* tree = new TTree("febTest", "feb test data");
1970 
1971  tree->Branch("serial", &serial, "sn/I");
1972  tree->Branch("offsetRough", "TH3F", &offsetRough);
1973  tree->Branch("offsetFine", "TH3F", &offsetFine);
1974  tree->Branch("testPulse", "TH2F", &testPulse);
1975 
1976  int febposition = -1;
1977 
1978  GearDir content = GearDir("/ArichData/AllData/arich");
1979  GearDir content1 = GearDir("/ArichData/AllData/dnamap");
1980  GearDir content2 = GearDir("/ArichData/AllData/FEBData/Content");
1981 
1982  for (const auto& runserial : content.getNodes("run")) {
1983  serial = runserial.getInt("sn");
1984  string runSCAN = runserial.getString("scan");
1985  int l = 0;
1986  string dna;
1987 
1988  for (const auto& febmap : content1.getNodes("febps")) {
1989  string somedna = febmap.getString("@dna");
1990  int sn = febmap.getInt("sn");
1991  if ((l == 0) && (sn == serial)) {
1992  dna = somedna;
1993  l++;
1994  }
1995  }
1996  // slow control data
1997  if (!runSCAN.empty()) {
1998  int scanRun;
1999  if (stoi(runSCAN.c_str()) < 23) {scanRun = stoi(runSCAN.c_str());}
2000  else {scanRun = stoi(runSCAN.c_str()) - 77;}
2001  for (const auto& testFEB : content2.getNodes("febtest[" + std::to_string(scanRun) + "]")) {
2002  int i = 0;
2003  int positionOld = 0;
2004 
2005  for (const auto& testFEBslowctest : testFEB.getNodes("slowc")) {
2006  int position = testFEBslowctest.getInt("id");
2007  if (position == positionOld) {i++; }
2008  else {i = 1; }
2009  if (i == 10) {
2010  string dnaNew = testFEBslowctest.getString("dna");
2011  if (dnaNew == dna) febposition = position;
2012  }
2013  positionOld = position;
2014  }
2015  }
2016  vector<TH3F*> histograms = getFebTestHistograms(dna, runSCAN, febposition);
2017  offsetRough = histograms[0];
2018  offsetFine = histograms[1];
2019 
2020  testPulse = ARICHDatabaseImporter::getFebTestPulse(dna, runSCAN, febposition); // TH2F*
2021 
2022  testPulse->SetDirectory(0);
2023  offsetRough->SetDirectory(0);
2024  offsetFine->SetDirectory(0);
2025 
2026  tree->Fill();
2027 
2028  delete testPulse;
2029  delete offsetRough;
2030  delete offsetFine;
2031  }
2032  }
2033 
2034  f.cd();
2035  tree->Write();
2036  f.Close();
2037 
2038 
2039 // define IOV and store data to the DB
2040  Database::Instance().addPayload("ARICHFebTestRoot", "febTestHistograms.root", m_iov);
2041 
2042 }
2043 
2044 std::tuple<std::string, float, float, float> ARICHDatabaseImporter::getFebLVtestData(int serial, int lvRun)
2045 {
2046  GearDir content2LV = GearDir("/ArichData/AllData/FEBDataLV/Content");
2047  std::tuple<std::string, float, float, float> LVtest;
2048  float currentV20p = 0.0, currentV21n = 0.0, currentV38p = 0.0;
2049 
2050  for (const auto& testFEBlv : content2LV.getNodes("febtest[" + std::to_string(lvRun) + "]")) {
2051  string timeLV = testFEBlv.getString("time");
2052  for (const auto& testFEBlv_sn : testFEBlv.getNodes("lvtest/feb[sn='" + to_string(serial) + "']/febps/n[@id='14']")) {
2053  for (const auto& testFEBlv_pw : testFEBlv_sn.getNodes("pw18")) {
2054  if (testFEBlv_pw.getInt("@id") == 0) { currentV20p = (float) testFEBlv_pw.getDouble("I"); }
2055  if (testFEBlv_pw.getInt("@id") == 1) { currentV21n = (float) testFEBlv_pw.getDouble("I"); }
2056  if (testFEBlv_pw.getInt("@id") == 2) { currentV38p = (float) testFEBlv_pw.getDouble("I"); }
2057  LVtest = make_tuple(timeLV, currentV20p, currentV21n, currentV38p);
2058  }
2059  }
2060  }
2061  return LVtest;
2062 }
2063 
2064 
2065 std::tuple<std::string, float> ARICHDatabaseImporter::getFebHVtestData(int serial, int hvRun)
2066 {
2067  GearDir content2HV = GearDir("/ArichData/AllData/FEBDataHV/Content");
2068  std::tuple<std::string, float> HVtest;
2069  for (const auto& testFEBhv : content2HV.getNodes("febtest[" + std::to_string(hvRun) + "]")) {
2070  string timeHV = testFEBhv.getString("time");
2071  for (const auto& testFEBhv_sn : testFEBhv.getNodes("hvtest/feb[sn='" + to_string(serial) + "']/febhv/n[@id='9']")) {
2072  float currentV99p = (float) testFEBhv_sn.getDouble("n1470/I");
2073  HVtest = std::make_tuple(timeHV, currentV99p);
2074  }
2075  }
2076  return HVtest;
2077 }
2078 
2079 std::vector<int> ARICHDatabaseImporter::getDeadChFEB(const std::string& dna)
2080 {
2081  vector<int> listCHs;
2082  string line;
2083  ifstream fileFEB("febTest/FEBdeadChannels.txt");
2084  if (fileFEB.is_open()) {
2085  while (getline(fileFEB, line)) {
2086  string ch2 = line.substr(line.find(",") + 1);
2087  string dna2 = line.erase(line.find(",") - 1);
2088  if (dna2 == dna) { listCHs.push_back(atoi(ch2.c_str())); }
2089  }
2090  } else { B2INFO("No file FEBdeadChannels.txt"); }
2091  fileFEB.close();
2092 
2093  return listCHs;
2094 }
2095 
2096 TTimeStamp ARICHDatabaseImporter::timedate2(std::string time)
2097 {
2098  // convert string into TTimeStamp
2099  string dateMeas = time.substr(4);
2100  string yearStr = dateMeas.substr(16, 4);
2101  string monthStr = dateMeas.substr(0, 3);
2102  string dayStr = dateMeas.substr(4, 2);
2103  string hourStr = dateMeas.substr(7, 2);
2104  string minStr = dateMeas.substr(10, 2);
2105  string secStr = dateMeas.substr(13, 2);
2106 
2107  int year = atoi(yearStr.c_str());
2108  int day = atoi(dayStr.c_str());
2109  int hour = atoi(hourStr.c_str());
2110  int min = atoi(minStr.c_str());
2111  int sec = atoi(secStr.c_str());
2112  map<string, int> months {
2113  { "Jan", 1 }, { "Feb", 2 }, { "Mar", 3 }, { "Apr", 4 }, { "May", 5 }, { "Jun", 6 }, { "Jul", 7 }, { "Aug", 8 }, { "Sep", 9 }, { "Oct", 10 }, { "Nov", 11 }, { "Dec", 12 }
2114  };
2115  int month = months.find(monthStr)->second;
2116 
2117  TTimeStamp datum = TTimeStamp(year, month, day, hour, min, sec, 0, kTRUE, 0);
2118  return datum;
2119 }
2120 
2121 std::pair<std::vector<float>, std::vector<float>> ARICHDatabaseImporter::getSlopes(int serialNum, const std::string& run)
2122 {
2123  GearDir contentData = GearDir("/ArichData/AllData/SlopesFebTest/Content");
2124  pair<vector<float>, vector<float>> slopesFebTest;
2125  vector<float> slopesCoarse, slopesFine;
2126 
2127  for (const auto& contentSlopes : contentData.getNodes("febtest")) {
2128  if ((contentSlopes.getInt("@id") == serialNum) && (contentSlopes.getString("@run") == run)) {
2129  for (int i = 0; i < 144; i++) {
2130  for (const auto& contSlopes : contentSlopes.getNodes("slope/ch[@id='" + to_string(i) + "']")) {
2131  float slopeCoarse = ((float) contSlopes.getDouble("coarse")) * 2.5 / 1024; // slope in V/step
2132  float slopeFine = ((float) contSlopes.getDouble("fine")) * 2.5 / 1024; // slope in V/step
2133  slopesCoarse.push_back(slopeCoarse);
2134  slopesFine.push_back(slopeFine);
2135  }
2136  }
2137  }
2138  slopesFebTest = std::make_pair(slopesFine, slopesCoarse);
2139  }
2140  return slopesFebTest;
2141 }
2142 
2143 std::vector<std::pair<float, float>> ARICHDatabaseImporter::getFwhm(int serialNum, const std::string& run)
2144 {
2145  GearDir contentData = GearDir("/ArichData/AllData/SlopesFebTest/Content");
2146  vector<pair<float, float>> fwhm;
2147 
2148  for (const auto& contentSlopes : contentData.getNodes("febtest")) {
2149  if ((contentSlopes.getInt("@id") == serialNum) && (contentSlopes.getString("@run") == run)) {
2150  for (const auto& contSlopes : contentSlopes.getNodes("data/ch")) {
2151  float fwhmVal = (float) contSlopes.getDouble("fwhm");
2152  float fwhmSig = (float) contSlopes.getDouble("sigma");
2153  pair<float, float> fwhmPair = std::make_pair(fwhmVal, fwhmSig);
2154  fwhm.push_back(fwhmPair);
2155  }
2156  }
2157  }
2158  return fwhm;
2159 }
2160 
2161 std::vector<TH3F*> ARICHDatabaseImporter::getFebTestHistograms(const std::string& dna, const std::string& run, int febposition)
2162 {
2163  vector<TH3F*> histogrami;
2164 
2165  for (const string& inputFile : m_inputFilesFebTest) {
2166 
2167  if (inputFile.find(run) != string::npos) {
2168  TFile* f = TFile::Open(inputFile.c_str(), "READ");
2169  int iMIN = 0, iMAX = 0, delta, stepsNum = 16, i = 0, point2 = 24;
2170  string option;
2171  float stepsMax = 15.5;
2172 
2173  // check how many steps were measured
2174  TIter next(f->GetListOfKeys());
2175  TKey* key;
2176  while ((key = (TKey*)next())) {
2177  string strime = key->GetName();
2178  if (strime.compare(0, 5, "h2d_0") == 0) i++;
2179  }
2180 
2181  // fill histogram for coarse/fine settings
2182  for (int k = 0; k < 2; k++) {
2183  if (i < 32) {
2184  stepsNum = 15;
2185  stepsMax = 14.5;
2186  point2 = 23;
2187  if (k == 0) { option = "coarse"; iMIN = 2; iMAX = 16; delta = 2;}
2188  if (k == 1) { option = "fine"; iMIN = 17; iMAX = 31; delta = 17; }
2189  } else {
2190  if (k == 0) { option = "coarse"; iMIN = 2; iMAX = 17; delta = 2; }
2191  if (k == 1) { option = "fine"; iMIN = 18; iMAX = 33; delta = 18; }
2192  }
2193 
2194  TH3F* histogram = new TH3F((option + " " + dna).c_str(), (option + " " + dna).c_str(), 144, -0.5, 143.5, 250, 299, 799, stepsNum,
2195  -0.5, stepsMax);
2196 
2197  for (int j = iMIN; j < iMAX + 1; j++) {
2198  TH2F* hist2d = (TH2F*)f->Get(("h2d_0;" + std::to_string(j)).c_str());
2199  hist2d->SetDirectory(0);
2200 
2201  int binZ;
2202  if ((j - delta) < 8) {binZ = 8 - (j - delta);}
2203  if ((j - delta) > 7) {binZ = point2 - (j - delta);}
2204  // conversion TH2F -> TH3F
2205  for (int binX = 144 * febposition + 1; binX < 144 * (febposition + 1) + 1; binX++) {
2206  for (int binY = 1; binY < 251; binY++) {
2207  histogram->SetBinContent(binX - 144 * febposition, binY, binZ, hist2d->GetBinContent(binX, binY));
2208  }
2209  }
2210  }
2211  histogram->SetDirectory(0);
2212  histogrami.push_back(histogram);
2213  for (int kanal = 1; kanal < 145; kanal ++) {
2214  for (int offset = 1; offset < stepsNum + 1; offset++) {
2215  TH1D* h1 = histogram->ProjectionY("A", kanal, kanal, offset, offset);
2216  h1->SetName((dna + " kanal: " + to_string(kanal) + ", offset: " + to_string(offset)).c_str());
2217  }
2218  }
2219  }
2220  f->Close();
2221  }
2222  }
2223 
2224  return histogrami;
2225 }
2226 
2227 TH2F* ARICHDatabaseImporter::getFebTestPulse(const std::string& dna, const std::string& run, int febposition)
2228 {
2229  TH2F* testPulse = new TH2F(("test pulse " + dna).c_str(), ("test pulse " + dna).c_str(), 144, -0.5, 143.5, 250, 299, 799);
2230 
2231  for (const string& inputFile : m_inputFilesFebTest) {
2232  if (inputFile.find(run) != string::npos) {
2233  TFile* f = TFile::Open(inputFile.c_str(), "READ");
2234  TH2F* pulseTest = (TH2F*)f->Get("h2d_0;1");
2235  pulseTest->SetDirectory(0);
2236  for (int binX = 144 * febposition + 1; binX < 144 * (febposition + 1) + 1; binX++) {
2237  for (int binY = 1; binY < 251; binY++) {
2238  testPulse->SetBinContent(binX - 144 * febposition, binY, pulseTest->GetBinContent(binX, binY));
2239  }
2240  }
2241  f->Close();
2242  }
2243  }
2244  return testPulse;
2245 }
2246 
2247 
2248 
2249 void ARICHDatabaseImporter::exportFebTest()
2250 {
2251 
2252  DBArray<ARICHFebTest> elements("ARICHFebTest");
2253  elements.getEntries();
2254 
2255  // Print serial numbers of FEBs
2256  for (const auto& element : elements) {
2257  B2INFO("Serial = " << element.getFebSerial() << "; dna = " << element.getFebDna() << "; slope R (ch143) = " <<
2258  element.getSlopeRough(143) << "; slope F (ch143) = " << element.getSlopeFine(143) << "; comment = " << element.getComment());
2259  }
2260 
2261 }
2262 
2263 void ARICHDatabaseImporter::importHapdChipInfo()
2264 {
2265  int chip_i = 0;
2266  GearDir content = GearDir("/ArichData/AllData/hapdData/Content");
2267 
2268  // define data array
2269  TClonesArray chipConstants("Belle2::ARICHHapdChipInfo");
2270 
2271  // extract chip info, such as bias voltage, lists of dead and bad channels etc.
2272  for (const auto& hapdInfo : content.getNodes("hapd")) {
2273  // extract information about HAPD
2274  string sn = hapdInfo.getString("serial");
2275 
2276  // define objects for chip info
2277  string chip[4];
2278  int channel_label_aval[4], bias[4], gain[4];
2279  TGraph** bombardmentGain, **avalancheGain;
2280  bombardmentGain = new TGraph *[4];
2281  avalancheGain = new TGraph *[4];
2282  TH2F** bias2DV, **bias2DI;
2283  bias2DV = new TH2F *[4];
2284  bias2DI = new TH2F *[4];
2285  vector<int> badlist[4], cutlist[4];
2286  vector<TGraph*> bombCurrents[4], avalCurrents[4];
2287  int chip_ABCD = 0;
2288 
2289  // extract information for each chip
2290  for (const auto& chipInfo : hapdInfo.getNodes("chipinfo")) {
2291  chip[chip_ABCD] = chipInfo.getString("chip");
2292  bias[chip_ABCD] = chipInfo.getInt("bias");
2293  string badL = chipInfo.getString("deadlist");
2294  string cutL = chipInfo.getString("cutlist");
2295  if (badL.find("ch") != string::npos) { string badLsub = badL.substr(3); badlist[chip_ABCD] = ARICHDatabaseImporter::channelsListHapd(badLsub.c_str(), chip[chip_ABCD]); }
2296  if (cutL.find("ch") != string::npos) { string cutLsub = cutL.substr(3); cutlist[chip_ABCD] = ARICHDatabaseImporter::channelsListHapd(cutLsub.c_str(), chip[chip_ABCD]); }
2297  string gain_str = chipInfo.getString("gain");
2298  gain[chip_ABCD] = atoi(gain_str.c_str());
2299  chip_ABCD++;
2300  }
2301 
2302  // prepare TGraphs for bombardment gain and current
2303  const int n3 = 30;
2304  int i3 = 0;
2305  //int channel_label_bomb;
2306  float hv_bomb[n3], gain_bomb[n3], current1_bomb[n3], current2_bomb[n3], current3_bomb[n3];
2307  chip_ABCD = 0;
2308  for (const auto& BG : hapdInfo.getNodes("bombardmentgain/ch")) {
2309  string value = BG.getString("value");
2310  string chip_label = value.erase(1);
2311  for (const auto& BG2 : BG.getNodes("point")) {
2312  hv_bomb[i3] = (float) BG2.getDouble("hv");
2313  gain_bomb[i3] = (float) BG2.getDouble("gain");
2314  current1_bomb[i3] = (float) BG2.getDouble("current1");
2315  current2_bomb[i3] = (float) BG2.getDouble("current2");
2316  current3_bomb[i3] = (float) BG2.getDouble("current3");
2317  i3++;
2318  }
2319 
2320  bombardmentGain[chip_ABCD] = ARICHDatabaseImporter::getGraphGainCurrent("Bombardment", "gain", chip_label, i3, hv_bomb, gain_bomb);
2321  TGraph* bombardmentCurrent1 = ARICHDatabaseImporter::getGraphGainCurrent("Bombardment", "current1", chip_label, i3, hv_bomb,
2322  current1_bomb);
2323  TGraph* bombardmentCurrent2 = ARICHDatabaseImporter::getGraphGainCurrent("Bombardment", "current2", chip_label, i3, hv_bomb,
2324  current2_bomb);
2325  TGraph* bombardmentCurrent3 = ARICHDatabaseImporter::getGraphGainCurrent("Bombardment", "current3", chip_label, i3, hv_bomb,
2326  current3_bomb);
2327  bombCurrents[chip_ABCD].push_back(bombardmentCurrent1);
2328  bombCurrents[chip_ABCD].push_back(bombardmentCurrent2);
2329  bombCurrents[chip_ABCD].push_back(bombardmentCurrent3);
2330  chip_ABCD++;
2331  i3 = 0;
2332  }
2333 
2334  // prepare TGraphs for avalanche gain and current
2335  const int n4 = 30;
2336  int i4 = 0;
2337  float hv_aval[n4], gain_aval[n4], current1_aval[n4], current2_aval[n4], current3_aval[n4];
2338  chip_ABCD = 0;
2339  for (const auto& BG : hapdInfo.getNodes("avalanchegain/ch")) {
2340  string value = BG.getString("value");
2341  string value_1 = value;
2342  string chip_label = value.erase(1);
2343  string value_2 = value_1.substr(2);
2344  channel_label_aval[chip_ABCD] = atoi(value_2.c_str());
2345  for (const auto& BG2 : BG.getNodes("point")) {
2346  hv_aval[i4] = (float) BG2.getDouble("biasv");
2347  gain_aval[i4] = (float) BG2.getDouble("gain");
2348  current1_aval[i4] = (float) BG2.getDouble("current1");
2349  current2_aval[i4] = (float) BG2.getDouble("current2");
2350  current3_aval[i4] = (float) BG2.getDouble("current3");
2351  i4++;
2352  }
2353 
2354  avalancheGain[chip_ABCD] = ARICHDatabaseImporter::getGraphGainCurrent("Avalanche", "gain", chip_label, i4, hv_aval, gain_aval);
2355  TGraph* avalancheCurrent1 = ARICHDatabaseImporter::getGraphGainCurrent("Avalanche", "current1", chip_label, i4, hv_aval,
2356  current1_aval);
2357  TGraph* avalancheCurrent2 = ARICHDatabaseImporter::getGraphGainCurrent("Avalanche", "current2", chip_label, i4, hv_aval,
2358  current2_aval);
2359  TGraph* avalancheCurrent3 = ARICHDatabaseImporter::getGraphGainCurrent("Avalanche", "current3", chip_label, i4, hv_aval,
2360  current3_aval);
2361  avalCurrents[chip_ABCD].push_back(avalancheCurrent1);
2362  avalCurrents[chip_ABCD].push_back(avalancheCurrent2);
2363  avalCurrents[chip_ABCD].push_back(avalancheCurrent3);
2364 
2365  chip_ABCD++;
2366  i4 = 0;
2367  }
2368 
2369 
2370  chip_ABCD = 0;
2371  // prepare 2D histograms for bias voltage and current
2372  const int n5 = 150;
2373  int i5 = 0, chipnum[n5];
2374  float biasv[n5], biasi[n5];
2375  for (const auto& HI : hapdInfo.getNodes("bias2d/biasvalue")) {
2376  string chip_2d = HI.getString("@chip");
2377  chipnum[i5] = HI.getInt("@ch");
2378  biasv[i5] = (float) HI.getDouble("biasv");
2379  biasi[i5] = (float) HI.getDouble("biasi");
2380  if (chipnum[i5] == 36) {
2381  bias2DV[chip_ABCD] = ARICHDatabaseImporter::getBiasGraph(chip_2d, "voltage", chipnum, biasv);
2382  bias2DI[chip_ABCD] = ARICHDatabaseImporter::getBiasGraph(chip_2d, "current", chipnum, biasi);
2383  i5 = -1;
2384  chip_ABCD++;
2385  }
2386  i5++;
2387  }
2388 
2389  // prepare ARICHHapdChipInfo class for each chip
2390  for (unsigned int l = 0; l < 4; l++) {
2391  new(chipConstants[4 * chip_i + l]) ARICHHapdChipInfo();
2392  auto* chipConst = static_cast<ARICHHapdChipInfo*>(chipConstants[4 * chip_i + l]);
2393 
2394  chipConst->setHapdSerial(sn);
2395  chipConst->setChipLabel(chip[l]);
2396  chipConst->setBiasVoltage(bias[l]);
2397  chipConst->setGain(gain[l]);
2398  chipConst->setBadChannel(badlist[l]);
2399  chipConst->setCutChannel(cutlist[l]);
2400  chipConst->setBombardmentGain(bombardmentGain[l]);
2401  chipConst->setBombardmentCurrent(bombCurrents[l]);
2402  chipConst->setAvalancheGain(avalancheGain[l]);
2403  chipConst->setAvalancheCurrent(avalCurrents[l]);
2404  chipConst->setChannelNumber(channel_label_aval[l]);
2405  chipConst->setBiasVoltage2D(bias2DV[l]);
2406  chipConst->setBiasCurrent2D(bias2DI[l]);
2407  }
2408 
2409  chip_i++;
2410 
2411  delete[] bombardmentGain;
2412  delete[] avalancheGain;
2413  delete[] bias2DV;
2414  delete[] bias2DI;
2415  }
2416 
2417  // define IOV and store data to the DB
2418  Database::Instance().storeData("ARICHHapdChipInfo", &chipConstants, m_iov);
2419 }
2420 
2421 void ARICHDatabaseImporter::exportHapdChipInfo()
2422 {
2423  DBArray<ARICHHapdChipInfo> elements("ARICHHapdChipInfo");
2424  elements.getEntries();
2425 
2426  for (const auto& element : elements) {
2427  B2INFO("Serial = " << element.getHapdSerial() << ", chip = " << element.getChipLabel() << ", bias= " << element.getBiasVoltage());
2428  }
2429 }
2430 
2431 
2432 
2433 void ARICHDatabaseImporter::importHapdInfo()
2434 {
2435  int hapd_i = 0;
2436  GearDir content = GearDir("/ArichData/AllData/hapdData/Content");
2437 
2438  // define data array
2439  TClonesArray hapdConstants("Belle2::ARICHHapdInfo");
2440 
2441  // extract chip info, such as bias voltage, lists of dead and bad channels etc.
2442  for (const auto& hapdInfo : content.getNodes("hapd")) {
2443  // define element of TClonesArray
2444  new(hapdConstants[hapd_i]) ARICHHapdInfo();
2445  auto* hapdConst = static_cast<ARICHHapdInfo*>(hapdConstants[hapd_i]);
2446 
2447  // extract information about HAPD
2448  string serial = hapdInfo.getString("serial");
2449  float qe400 = (float) hapdInfo.getDouble("qe400");
2450  float hv = 1000 * (float) hapdInfo.getDouble("hv");
2451  float current = (float) hapdInfo.getDouble("current");
2452  string gb = hapdInfo.getString("guardbias");
2453  int guardbias = atoi(gb.c_str());
2454 
2455  // prepare TGraph of quantum efficiency as function of lambda
2456  const int n1 = 70;
2457  float lambda[n1], qepoint[n1];
2458  int i1 = 0;
2459  for (const auto& QE : hapdInfo.getNodes("qe/qepoint")) {
2460  lambda[i1] = (float) QE.getInt("@lambda");
2461  qepoint[i1] = (float) QE.getDouble(".");
2462  i1++;
2463  }
2464  TGraph* qe = new TGraph(i1, lambda, qepoint);
2465  qe->SetName("qe");
2466  qe->SetTitle("qe");
2467  qe->GetXaxis()->SetTitle("lambda");
2468  qe->GetYaxis()->SetTitle("qe");
2469 
2470  // prepare TGraph of pulse height distribution
2471  const int n2 = 4100;
2472  int channel_adc[n2], pulse_adc[n2];
2473  int i2 = 0;
2474  for (const auto& ADC : hapdInfo.getNodes("adc/value")) {
2475  channel_adc[i2] = ADC.getInt("@ch");
2476  string str = ADC.getString(".");
2477  pulse_adc[i2] = atoi(str.c_str());
2478  i2++;
2479  }
2480  TGraph* adc = new TGraph(i2, channel_adc, pulse_adc);
2481  adc->SetName("adc");
2482  adc->SetTitle("Pulse Height Distribution");
2483  adc->GetXaxis()->SetTitle("channel");
2484  adc->GetYaxis()->SetTitle("pulse height");
2485 
2486  // save HAPD data to the element of TClonesArray
2487  hapdConst->setSerialNumber(serial);
2488  hapdConst->setQuantumEfficiency400(qe400);
2489  hapdConst->setHighVoltage(hv);
2490  hapdConst->setGuardBias(guardbias);
2491  hapdConst->setCurrent(current);
2492  hapdConst->setQuantumEfficiency(qe);
2493  hapdConst->setPulseHeightDistribution(adc);
2494 
2495  // export ARICHHapdChipInfo class for each chip from DB and
2496  // add it as an element of ARICHHapdInfo class
2497  DBArray<ARICHHapdChipInfo> elementsChip("ARICHHapdChipInfo");
2498  elementsChip.getEntries();
2499  for (const auto& element : elementsChip) {
2500  if (element.getHapdSerial() == serial) {
2501  ARICHHapdChipInfo& elementValue = const_cast<ARICHHapdChipInfo&>(element);
2502  if (element.getChipLabel() == "A") hapdConst->setHapdChipInfo(0, &elementValue);
2503  if (element.getChipLabel() == "B") hapdConst->setHapdChipInfo(1, &elementValue);
2504  if (element.getChipLabel() == "C") hapdConst->setHapdChipInfo(2, &elementValue);
2505  if (element.getChipLabel() == "D") hapdConst->setHapdChipInfo(3, &elementValue);
2506  }
2507  }
2508 
2509  hapd_i++;
2510  }
2511 
2512  // define IOV and store data to the DB
2513  Database::Instance().storeData("ARICHHapdInfo", &hapdConstants, m_iov);
2514 }
2515 
2516 
2517 // get list of bad channels on HAPD
2518 std::vector<int> ARICHDatabaseImporter::channelsListHapd(std::string chlist, std::string chipDelay)
2519 {
2520  B2INFO("channel list = " << chlist << ", chip = " << chipDelay);
2521  string chlistDig = ARICHTools::remove_chars_if_not(chlist, "0123456789,~");
2522 
2523  vector<int> CHs = ARICHTools::getDeadCutList(*chipDelay.c_str(), ARICHTools::StringToVector::parse<int>(chlistDig, ','));
2524 
2525  B2INFO("All channels: ");
2526  printContainer(CHs);
2527  return CHs;
2528 }
2529 
2530 // prepare TGraph for bombardment/avalanche gain/current
2531 TGraph* ARICHDatabaseImporter::getGraphGainCurrent(const std::string& bomb_aval, const std::string& g_i,
2532  const std::string& chip_label, int i, float* HV,
2533  float* gain_current)
2534 {
2535  TGraph* hapd_graph = new TGraph(i, HV, gain_current);
2536  string title = bomb_aval + " " + g_i + ", chip " + chip_label;
2537  hapd_graph->SetTitle(title.c_str());
2538  hapd_graph->GetXaxis()->SetTitle("high voltage");
2539  hapd_graph->GetYaxis()->SetTitle(g_i.c_str());
2540  return hapd_graph;
2541 }
2542 
2543 // use correct mapping of channels on HAPD
2544 int ARICHDatabaseImporter::getChannelPosition(const std::string& XY, const std::string& chip_2d, int chipnum)
2545 {
2546  int x = 100, y = 100;
2547  if (chip_2d == "A") {
2548  y = 12;
2549  x = 0 + chipnum;
2550  while (x > 6) {
2551  x = x - 6;
2552  y = y - 1;
2553  }
2554  } else if (chip_2d == "B") {
2555  x = 12;
2556  y = 13 - chipnum;
2557  while (y < 7) {
2558  y = y + 6;
2559  x = x - 1;
2560  }
2561  } else if (chip_2d == "C") {
2562  y = 1;
2563  x = 13 - chipnum;
2564  while (x < 7) {
2565  x = x + 6;
2566  y = y + 1;
2567  }
2568  } else if (chip_2d == "D") {
2569  x = 1;
2570  y = 0 + chipnum;
2571  while (y > 6) {
2572  y = y - 6;
2573  x = x + 1;
2574  }
2575  }
2576 
2577  if (XY == "x") { return x;}
2578  else if (XY == "y") { return y;}
2579  else {return 100;}
2580 }
2581 
2582 // prepare 2D histogram for bias voltage/current
2583 TH2F* ARICHDatabaseImporter::getBiasGraph(const std::string& chip_2d, const std::string& voltage_current, int* chipnum,
2584  float* bias_v_i)
2585 {
2586  string name = "bias " + voltage_current + ", chip " + chip_2d;
2587  TH2F* bias2d = new TH2F("bias2d", name.c_str(), 6, 0, 6, 6, 0, 6);
2588  for (int XYname = 0; XYname < 6; XYname++) {
2589  bias2d->GetXaxis()->SetBinLabel(XYname + 1, to_string(XYname).c_str());
2590  bias2d->GetYaxis()->SetBinLabel(XYname + 1, to_string(6 * XYname).c_str());
2591  }
2592  for (int XY = 0; XY < 36; XY++) {
2593  int x = 1;
2594  int y = 0 + chipnum[XY];
2595  while (y > 6) {
2596  y = y - 6;
2597  x = x + 1;
2598  }
2599  bias2d->SetBinContent(x, y, bias_v_i[XY]);
2600  }
2601  bias2d->SetDirectory(0);
2602  return bias2d;
2603 }
2604 
2605 void ARICHDatabaseImporter::exportHapdInfo()
2606 {
2607 
2608  DBArray<ARICHHapdInfo> elements("ARICHHapdInfo");
2609  elements.getEntries();
2610 
2611  for (const auto& element : elements) {
2612  B2INFO("Serial = " << element.getSerialNumber() << "; HV = " << element.getHighVoltage() << "; qe400 = " <<
2613  element.getQuantumEfficiency400());
2614  for (int n = 0; n < 4; n++) {
2615  ARICHHapdChipInfo* newelement = element.getHapdChipInfo(n);
2616  B2INFO("biasV(chip" << n << ") = " << newelement->getBiasVoltage());
2617  }
2618  /* TGraph* adc = element.getPulseHeightDistribution();
2619  TFile file("histogrami.root", "update");
2620  adc->Write();
2621  file.Close();
2622  */
2623  }
2624 }
2625 
2626 
2627 void ARICHDatabaseImporter::importHapdQE()
2628 {
2629  // define data array
2630  TClonesArray hapdQEConstants("Belle2::ARICHHapdQE");
2631  int hapd = 0;
2632 
2633  // loop over root riles
2634  for (const string& inputFile : m_inputFilesHapdQE) {
2635 
2636  TFile* f = TFile::Open(inputFile.c_str(), "READ");
2637 
2638  int size = inputFile.length();
2639  string hapdSerial = inputFile.substr(size - 11, 6);
2640  TH2F* qe2D = 0;
2641 
2642  // extract data
2643  TIter next(f->GetListOfKeys());
2644  TKey* key;
2645  while ((key = (TKey*)next())) {
2646 
2647  string strime = key->GetName();
2648 
2649  if (strime.compare(0, 11, "hqe2d_pixel") == 0) {
2650  qe2D = (TH2F*)f->Get(strime.c_str());
2651  qe2D->SetTitle("quantum efficiency");
2652  qe2D->SetName("QE");
2653  qe2D->SetDirectory(0);
2654  }
2655 
2656  else { B2INFO("Key name does not match 'hqe2d_pixel'!"); }
2657  }
2658 
2659  // save data as an element of the array
2660  new(hapdQEConstants[hapd]) ARICHHapdQE(hapdSerial, qe2D);
2661  hapd++;
2662  f->Close();
2663  }
2664 
2665  // define IOV and store data to the DB
2666  Database::Instance().storeData("ARICHHapdQE", &hapdQEConstants, m_iov);
2667 }
2668 
2669 
2670 void ARICHDatabaseImporter::exportHapdQE()
2671 {
2672  DBArray<ARICHHapdQE> elements("ARICHHapdQE");
2673  elements.getEntries();
2674  gROOT->SetBatch(kTRUE);
2675 
2676  // Example that prints serial numbers of HAPDs and saves QE 2D histograms to root file
2677  for (const auto& element : elements) {
2678  B2INFO(" SN = " << element.getHapdSerialNumber());
2679  TH2F* qe2d = element.getQuantumEfficiency2D();
2680  TFile file("QEhists.root", "update");
2681  qe2d->Write();
2682  file.Close();
2683  }
2684 
2685 }
2686 
2687 void ARICHDatabaseImporter::printBiasVoltagesForHapdChip(const std::string& serialNumber)
2688 {
2689  // example that shows how to extract and use data
2690  // it calculates bias voltage at gain = 40 for each chip
2691 
2692  DBArray<ARICHHapdChipInfo> elements("ARICHHapdChipInfo");
2693  elements.getEntries();
2694 
2695  for (const auto& element : elements) {
2696  if (element.getHapdSerial() == serialNumber) {
2697  TGraph* avalgain = element.getAvalancheGain();
2698 
2699  // use linear interpolation to get bias voltage at gain = 40
2700  /*
2701  // 1) you can do it by hand
2702 
2703  double A, B, C, D;
2704  for(int j = 0; j < 100; j++) {
2705  avalgain->GetPoint(j, A, B);
2706  if(B>40) {
2707  avalgain->GetPoint(j-1, A, B);
2708  avalgain->GetPoint(j, C, D);
2709  float k = (B-D)/(A-C);
2710  float n = B - k*A;
2711  float xgain = (40 - n)/k;
2712  B2INFO("serial#-chip = " << element.getHapdSerial() << "-" << element.getChipLabel() << "; " << "V(gain=40) = " << (int)(xgain+0.5));
2713  j = 100;
2714  }
2715  }
2716  */
2717 
2718  // 2) use "Eval" function
2719  // - avalgain graph is gain(voltage)
2720  // - function "Eval" can be used to interpolate around chosen x
2721  // - convert graph gain(voltage) to voltage(gain) to interpolate around gain = 40
2722  TGraph* gainnew = new TGraph(avalgain->GetN());
2723  double xpoint, ypoint;
2724  for (int j = 0; j < avalgain->GetN(); j++) {
2725  avalgain->GetPoint(j, xpoint, ypoint);
2726  gainnew->SetPoint(j, ypoint, xpoint);
2727  }
2728  B2INFO("serial#-chip = " << element.getHapdSerial() << "-" << element.getChipLabel() << "; " << "V(gain=40) = " << (int)(
2729  gainnew->Eval(40) + 0.5));
2730  }
2731  }
2732 }
2733 
2734 void ARICHDatabaseImporter::printMyParams(const std::string& aeroSerialNumber)
2735 {
2736  map<string, float> aerogelParams = ARICHDatabaseImporter::getAerogelParams(aeroSerialNumber);
2737 
2738  B2INFO("SN = " << aeroSerialNumber << "; n = " << aerogelParams.find("refractiveIndex")->second << "; transLen = " <<
2739  aerogelParams.find("transmissionLength")->second << "; thickness = " << aerogelParams.find("thickness")->second);
2740 }
2741 
2742 
2743 std::map<std::string, float> ARICHDatabaseImporter::getAerogelParams(const std::string& aeroSerialNumber)
2744 {
2745  // Description:
2746  // This function loops over aerogel tiles and returns refractive index,
2747  // thickness and transmission length of aerogel for serial number
2748 
2749  std::map<std::string, float> aerogelParams;
2750  DBArray<ARICHAerogelInfo> elements("ARICHAerogelInfo");
2751  elements.getEntries();
2752  for (const auto& element : elements) {
2753  if ((element.getAerogelSN()) == aeroSerialNumber) {
2754  aerogelParams = {
2755  { "refractiveIndex", element.getAerogelRefractiveIndex() },
2756  { "transmissionLength", element.getAerogelTransmissionLength() },
2757  { "thickness", element.getAerogelThickness() }
2758  };
2759  }
2760  }
2761  return aerogelParams;
2762 }
2763 
2764 void ARICHDatabaseImporter::importFEBoardInfo()
2765 {
2766 
2767  GearDir content = GearDir("/ArichData/AllData/febasicmapping");
2768 
2769  // define data array
2770  TClonesArray febConstants("Belle2::ARICHFEBoardInfo");
2771  int feb = 0;
2772 
2773  // loop over xml files and extract the data
2774  for (const auto& febinfo : content.getNodes("febasic")) {
2775  int febSN = (float) febinfo.getInt("sn");
2776  string asic1 = febinfo.getString("asic1");
2777  string asic2 = febinfo.getString("asic2");
2778  string asic3 = febinfo.getString("asic3");
2779  string asic4 = febinfo.getString("asic4");
2780  string delivery = febinfo.getString("delivered");
2781  string sentKEK = febinfo.getString("sentKEK");
2782 
2783  if (delivery.size() != 10) cout << "feb sn " << febSN << " check delivery time!" << endl;
2784 
2785  string year = delivery.substr(6, 4);
2786  delivery = febinfo.getString("delivered");
2787  string month = delivery.substr(3, 2);
2788  delivery = febinfo.getString("delivered");
2789  string day = delivery.substr(0, 2);
2790 
2791  int deliveryINT = atoi((year + month + day + "u").c_str());
2792  TTimeStamp deliverytime(deliveryINT, 0u, 0u);
2793 
2794  string location = "";
2795  if (!sentKEK.empty()) location = "KEK";
2796 
2797  // save data as an element of the array
2798  new(febConstants[feb]) ARICHFEBoardInfo();
2799  auto* febConst = static_cast<ARICHFEBoardInfo*>(febConstants[feb]);
2800  febConst->setFEBoardSerial(febSN);
2801  febConst->setAsicPosition(0, asic1);
2802  febConst->setAsicPosition(1, asic2);
2803  febConst->setAsicPosition(2, asic3);
2804  febConst->setAsicPosition(3, asic4);
2805  febConst->setTimeStamp(deliverytime);
2806  febConst->setFEBoardLocation(location);
2807 
2808  DBArray<ARICHAsicInfo> elementsAsic("ARICHAsicInfo");
2809  elementsAsic.getEntries();
2810  for (const auto& element : elementsAsic) {
2811  if (element.getAsicID() == asic1) {
2812  ARICHAsicInfo& elementValue = const_cast<ARICHAsicInfo&>(element);
2813  febConst->setAsicInfo(0, &elementValue);
2814  }
2815  if (element.getAsicID() == asic2) {
2816  ARICHAsicInfo& elementValue = const_cast<ARICHAsicInfo&>(element);
2817  febConst->setAsicInfo(1, &elementValue);
2818  }
2819  if (element.getAsicID() == asic3) {
2820  ARICHAsicInfo& elementValue = const_cast<ARICHAsicInfo&>(element);
2821  febConst->setAsicInfo(2, &elementValue);
2822  }
2823  if (element.getAsicID() == asic4) {
2824  ARICHAsicInfo& elementValue = const_cast<ARICHAsicInfo&>(element);
2825  febConst->setAsicInfo(3, &elementValue);
2826  }
2827  }
2828 
2829  feb++;
2830  }
2831 
2832  // store under user defined name:
2833  Database::Instance().storeData("ARICHFEBoardInfo", &febConstants, m_iov);
2834 }
2835 
2836 void ARICHDatabaseImporter::exportFEBoardInfo()
2837 {
2838  DBArray<ARICHFEBoardInfo> elements("ARICHFEBoardInfo");
2839  elements.getEntries();
2840 
2841  for (const auto& element : elements) {
2842  B2INFO("Feb sn = " << element.getFEBoardSerial());
2843  for (int i = 0; i < 4; i++) {
2844  B2INFO("ASIC " << i << " = " << element.getAsicPosition(i));
2845  }
2846  }
2847 }
2848 
2849 
2850 void ARICHDatabaseImporter::importModuleTest(const std::string& mypath, const std::string& HVtest)
2851 {
2852 
2853 
2854  std::string path;
2855  if (HVtest == "no") path = "/ArichData/AllData/moduletest";
2856  else if (HVtest == "yes") path = "/ArichData/AllData/moduletestHV";
2857  else B2INFO("Check HVB test parameter!");
2858 
2859  GearDir content = GearDir(path);
2860 
2861  // define data array
2862  TClonesArray moduleConstants("Belle2::ARICHModuleTest");
2863  int module = 0;
2864 
2865  // loop over xml files and extract the data
2866  for (const auto& moduletest : content.getNodes("module")) {
2867  int febSN = (float) moduletest.getInt("febserial");
2868  string hapdSN = moduletest.getString("hapdserial");
2869  int hvbSN = -1;
2870  if (HVtest == "yes") hvbSN = (float) moduletest.getInt("hvbserial");
2871  int run = moduletest.getInt("run");
2872  int runposition = moduletest.getInt("runposition");
2873  int isok = moduletest.getInt("isok");
2874  bool isOK = false;
2875  if (isok == 1) isOK = true;
2876  string comment = moduletest.getString("comment");
2877 
2878  vector<int> deadChannels;
2879 
2880  if (HVtest == "no") {
2881  auto ids = ARICHTools::StringToVector::convert<ARICHTools::ModuleID_t>(moduletest.getString("dead"), ',');
2882  deadChannels.reserve(ids.size());
2883  for (const auto& rID : ids)
2884  deadChannels.emplace_back(rID.getNumbering());
2885  }
2886 
2887 
2888 
2889  if (HVtest == "yes") {
2890  deadChannels = ARICHTools::StringToVector::convert<int>(moduletest.getString("dead"), ',');
2891  }
2892 
2893  B2INFO("Dead channels: ");
2894  printContainer(deadChannels);
2895  // define histograms
2896  TGraph* guardBias_th = 0;
2897  TGraph* chipVdiff_th[4] = {0};
2898  TGraph* chipLeak_th[4] = {0};
2899  TGraph* HV_th = 0;
2900 
2901  TGraph* guardBias_2Dx = 0;
2902  TGraph* chipVdiff_2Dx[4] = {0};
2903  TGraph* chipLeak_2Dx[4] = {0};
2904  TGraph* HV_2Dx = 0;
2905 
2906  TGraph* guardBias_2Dy = 0;
2907  TGraph* chipVdiff_2Dy[4] = {0};
2908  TGraph* chipLeak_2Dy[4] = {0};
2909  TGraph* HV_2Dy = 0;
2910 
2911  TH1F* gain = 0;
2912  TH2D* charge = 0;
2913  TH2D* th = 0;
2914  TH2D* scanX = 0;
2915  TH2D* scanY = 0;
2916 
2917  string runStr = "";
2918  if (run < 10) runStr = "000" + to_string(run);
2919  if ((run > 9) && (run < 100)) runStr = "00" + to_string(run);
2920  if (run > 99) runStr = "0" + to_string(run);
2921  TFile* f = TFile::Open((mypath + runStr + "/" + runStr + "_" + hapdSN + "_out.root").c_str(), "READ");
2922 
2923  // extract data
2924  TIter next(f->GetListOfKeys());
2925  TKey* key;
2926  while ((key = (TKey*)next())) {
2927 
2928  string strime = key->GetName();
2929 
2930  if (strime.find("Guard") != string::npos) {
2931  if (strime.find("_T_0") != string::npos) {
2932  guardBias_th = (TGraph*)f->Get(strime.c_str());
2933  }
2934  if (strime.find("_T_1") != string::npos) {
2935  guardBias_2Dx = (TGraph*)f->Get(strime.c_str());
2936  }
2937  if (strime.find("_T_2") != string::npos) {
2938  guardBias_2Dy = (TGraph*)f->Get(strime.c_str());
2939  }
2940  }
2941 
2942  if (strime.find("BiasDifference") != string::npos) {
2943  for (int i = 0; i < 4; i++) {
2944  if (strime.find(("CHIP_" + to_string(i) + "_T_0").c_str()) != string::npos) {
2945  chipVdiff_th[i] = (TGraph*)f->Get(strime.c_str());
2946  }
2947  if (strime.find(("CHIP_" + to_string(i) + "_T_1").c_str()) != string::npos) {
2948  chipVdiff_2Dx[i] = (TGraph*)f->Get(strime.c_str());
2949  }
2950  if (strime.find(("CHIP_" + to_string(i) + "_T_2").c_str()) != string::npos) {
2951  chipVdiff_2Dy[i] = (TGraph*)f->Get(strime.c_str());
2952  }
2953  }
2954  }
2955 
2956  if (strime.find("LeakageCurrent") != string::npos) {
2957  for (int i = 0; i < 4; i++) {
2958  if (strime.find(("CHIP_" + to_string(i) + "_T_0").c_str()) != string::npos) {
2959  chipLeak_th[i] = (TGraph*)f->Get(strime.c_str());
2960  }
2961  if (strime.find(("CHIP_" + to_string(i) + "_T_1").c_str()) != string::npos) {
2962  chipLeak_2Dx[i] = (TGraph*)f->Get(strime.c_str());
2963  }
2964  if (strime.find(("CHIP_" + to_string(i) + "_T_2").c_str()) != string::npos) {
2965  chipLeak_2Dy[i] = (TGraph*)f->Get(strime.c_str());
2966  }
2967  }
2968  }
2969 
2970  if (strime.find("HV") != string::npos) {
2971  if (strime.find("_T_0") != string::npos) {
2972  HV_th = (TGraph*)f->Get(strime.c_str());
2973  }
2974  if (strime.find("_T_1") != string::npos) {
2975  HV_2Dx = (TGraph*)f->Get(strime.c_str());
2976  }
2977  if (strime.find("_T_2") != string::npos) {
2978  HV_2Dy = (TGraph*)f->Get(strime.c_str());
2979  }
2980  }
2981 
2982  if (strime.find("Gain_1D") != string::npos) {
2983  gain = (TH1F*)f->Get(strime.c_str());
2984  gain->SetDirectory(0);
2985  }
2986 
2987  if (strime.find("Charge_2D") != string::npos) {
2988  charge = (TH2D*)f->Get(strime.c_str());
2989  charge->SetDirectory(0);
2990  }
2991 
2992  if (strime.find("Threshold_2D") != string::npos) {
2993  th = (TH2D*)f->Get(strime.c_str());
2994  th->SetDirectory(0);
2995  }
2996 
2997  if (strime.find("Scan_2D_X") != string::npos) {
2998  scanX = (TH2D*)f->Get(strime.c_str());
2999  scanX->SetDirectory(0);
3000  }
3001 
3002  if (strime.find("Scan_2D_Y") != string::npos) {
3003  scanY = (TH2D*)f->Get(strime.c_str());
3004  scanY->SetDirectory(0);
3005  }
3006  }
3007 
3008  // save data as an element of the array
3009  new(moduleConstants[module]) ARICHModuleTest();
3010  auto* moduleConst = static_cast<ARICHModuleTest*>(moduleConstants[module]);
3011  moduleConst->setFebSN(febSN);
3012  moduleConst->setHapdSN(hapdSN);
3013  moduleConst->setRun(run);
3014  moduleConst->setRunPosition(runposition);
3015  moduleConst->setOK(isOK);
3016  moduleConst->setDeadChs(deadChannels);
3017  moduleConst->setComment(comment);
3018  moduleConst->setGuardBiasTH(guardBias_th);
3019  moduleConst->setHighVoltageTH(HV_th);
3020  moduleConst->setGuardBias2Dx(guardBias_2Dx);
3021  moduleConst->setHighVoltage2Dx(HV_2Dx);
3022  moduleConst->setGuardBias2Dy(guardBias_2Dy);
3023  moduleConst->setHighVoltage2Dy(HV_2Dy);
3024  moduleConst->setGain(gain);
3025  moduleConst->setChargeScan(charge);
3026  moduleConst->setTresholdScan(th);
3027  moduleConst->setLaserScanX(scanX);
3028  moduleConst->setLaserScanY(scanY);
3029 
3030  for (int i = 0; i < 4; i++) {
3031  moduleConst->setChipVdiffTH(i, chipVdiff_th[i]);
3032  moduleConst->setChipLeakTH(i, chipLeak_th[i]);
3033  moduleConst->setChipVdiff2Dx(i, chipVdiff_2Dx[i]);
3034  moduleConst->setChipLeak2Dx(i, chipLeak_2Dx[i]);
3035  moduleConst->setChipVdiff2Dy(i, chipVdiff_2Dy[i]);
3036  moduleConst->setChipLeak2Dy(i, chipLeak_2Dy[i]);
3037  }
3038  if (HVtest == "yes") moduleConst->setHvbSN(hvbSN);
3039 
3040  module++;
3041  B2INFO("module no " << module - 1 << " saved to DB. HAPD SN = " << hapdSN << ", FEB SN = " << febSN);
3042  f->Close();
3043  }
3044 
3045  // store under user defined name:
3046  if (HVtest == "no") Database::Instance().storeData("ARICHModuleTest", &moduleConstants, m_iov);
3047  if (HVtest == "yes") Database::Instance().storeData("ARICHModuleTestHV", &moduleConstants, m_iov);
3048 }
3049 
3050 void ARICHDatabaseImporter::exportModuleTest(const std::string& HVtest)
3051 {
3052 
3053  if (HVtest == "no") {
3054  DBArray<ARICHModuleTest> elements("ARICHModuleTest");
3055  elements.getEntries();
3056  for (const auto& element : elements) {
3057  B2INFO("Feb sn = " << element.getFebSN() << ", hapd sn = " << element.getHapdSN() << ", run = " << element.getRun() <<
3058  ", run position = " << element.getRunPosition() << ", module is ok = " << element.getOK() << ", comment = " <<
3059  element.getComment());
3060  for (int i = 0; i < element.getDeadChsSize(); i++) {
3061  B2INFO("dead channel = " << element.getDeadCh(i) << " (hapd mapping)");
3062  }
3063  }
3064  }
3065 
3066  if (HVtest == "yes") {
3067  DBArray<ARICHModuleTest> elements("ARICHModuleTestHV");
3068  elements.getEntries();
3069  for (const auto& element : elements) {
3070  B2INFO("Feb sn = " << element.getFebSN() << ", hapd sn = " << element.getHapdSN() << ", hvb sn = " << element.getHvbSN() <<
3071  ", run = " << element.getRun() << ", run position = " << element.getRunPosition() << ", module is ok = " << element.getOK() <<
3072  ", comment = " << element.getComment());
3073  for (int i = 0; i < element.getDeadChsSize(); i++) {
3074  B2INFO("dead channel = " << element.getDeadCh(i) << " (asic mapping)");
3075  }
3076  }
3077  }
3078 }
3079 
3080 void ARICHDatabaseImporter::importSensorModuleInfo()
3081 {
3082  GearDir content = GearDir("/ArichData/AllData/moduleposition");
3083 
3084  // define data array
3085  TClonesArray moduleInfoConstants("Belle2::ARICHSensorModuleInfo");
3086 
3087  int module = 0;
3088 
3089  // loop over xml files and extract the data
3090  for (const auto& sensor : content.getNodes("position")) {
3091  int febSerial = sensor.getInt("febserial");
3092  string hapdSerial = sensor.getString("hapdserial");
3093  int id = sensor.getInt("moduleID");
3094  int hvSerial = sensor.getInt("HVserial");
3095 
3096  // save data as an element of the array
3097  new(moduleInfoConstants[module]) ARICHSensorModuleInfo();
3098  auto* moduleInfoConst = static_cast<ARICHSensorModuleInfo*>(moduleInfoConstants[module]);
3099  moduleInfoConst->setSensorModuleID(id);
3100  moduleInfoConst->setFEBserial(febSerial);
3101  moduleInfoConst->setHAPDserial(hapdSerial);
3102  moduleInfoConst->setHVboardID(hvSerial);
3103 
3104  DBArray<ARICHHapdInfo> elementsHapd("ARICHHapdInfo");
3105  elementsHapd.getEntries();
3106  for (const auto& element : elementsHapd) {
3107  if (element.getSerialNumber() == hapdSerial) {
3108  ARICHHapdInfo& elementValue = const_cast<ARICHHapdInfo&>(element);
3109  moduleInfoConst->setHapdID(&elementValue);
3110  }
3111  }
3112 
3113  DBArray<ARICHFEBoardInfo> elementsFeb("ARICHFEBoardInfo");
3114  elementsFeb.getEntries();
3115  for (const auto& element : elementsFeb) {
3116  if (element.getFEBoardSerial() == febSerial) {
3117  ARICHFEBoardInfo& elementValue = const_cast<ARICHFEBoardInfo&>(element);
3118  moduleInfoConst->setFEBoardID(&elementValue);
3119  }
3120  }
3121 
3122  DBArray<ARICHModuleTest> elementsModule("ARICHModuleTestHV");
3123  elementsModule.getEntries();
3124  for (const auto& element : elementsModule) {
3125  if (element.getFebSN() == febSerial) {
3126  ARICHModuleTest& elementValue = const_cast<ARICHModuleTest&>(element);
3127  moduleInfoConst->setModuleTest(&elementValue);
3128  }
3129  }
3130 
3131  module++;
3132  }
3133 
3134  // store under default name:
3135  Database::Instance().storeData("ARICHSensorModuleInfo", &moduleInfoConstants, m_iov);
3136 }
3137 
3138 
3139 void ARICHDatabaseImporter::importSensorModuleMap()
3140 {
3141 
3142  GearDir content = GearDir("/ArichData/AllData/moduleposition");
3143 
3144  // define data array
3145  TClonesArray moduleMapConstants("Belle2::ARICHSensorModuleMap");
3146 
3147  int module = 0;
3148 
3149  // loop over xml files and extract the data
3150  for (const auto& sensor : content.getNodes("position")) {
3151  int sextant = sensor.getInt("sector");
3152  int ring = sensor.getInt("ring");
3153  int column = sensor.getInt("column");
3154  int id = sensor.getInt("moduleID");
3155 
3156  // save data as an element of the array
3157  new(moduleMapConstants[module]) ARICHSensorModuleMap();
3158  auto* moduleMapConst = static_cast<ARICHSensorModuleMap*>(moduleMapConstants[module]);
3159  moduleMapConst->setSensorModuleSextantID(sextant);
3160  moduleMapConst->setSensorModuleRingID(ring);
3161  moduleMapConst->setSensorModuleColumnID(column);
3162  moduleMapConst->setSensorGlobalID(id);
3163 
3164  DBArray<ARICHSensorModuleInfo> elementsModule("ARICHSensorModuleInfo");
3165  elementsModule.getEntries();
3166  for (const auto& element : elementsModule) {
3167  if (element.getSensorModuleID() == id) {
3168  ARICHSensorModuleInfo& elementValue = const_cast<ARICHSensorModuleInfo&>(element);
3169  moduleMapConst->setSensorModuleId(&elementValue);
3170  }
3171  }
3172 
3173  module++;
3174  }
3175 
3176  // store under default name:
3177  Database::Instance().storeData("ARICHSensorModuleMap", &moduleMapConstants, m_iov);
3178 }
3179 
3180 void ARICHDatabaseImporter::exportSensorModuleMap()
3181 {
3182  DBArray<ARICHSensorModuleMap> elements("ARICHSensorModuleMap");
3183  elements.getEntries();
3184 
3185  for (const auto& element : elements) {
3186  B2INFO("Sextant = " << element.getSensorModuleSextantID() << ", ring = " << element.getSensorModuleRingID() << ", column = " <<
3187  element.getSensorModuleColumnID());
3188  ARICHSensorModuleInfo* newelement = element.getSensorModuleId();
3189  B2INFO("module ID = " << newelement->getSensorModuleID() << ", feb = " << newelement->getFEBserial() << ", hapd = " <<
3190  newelement->getHAPDserial());
3191  ARICHHapdInfo* newerelement = newelement->getHapdID();
3192  B2INFO("Hapd Serial = " << newerelement->getSerialNumber() << "; HV = " << newerelement->getHighVoltage() << "; qe400 = " <<
3193  newerelement->getQuantumEfficiency400());
3194  for (int i = 0; i < 4; i++) {
3195  ARICHHapdChipInfo* newestelement = newerelement->getHapdChipInfo(i);
3196  B2INFO("Hapd Serial = " << newestelement->getHapdSerial() << "; chip = " << newestelement->getChipLabel() << "; gain = " <<
3197  newestelement->getGain());
3198  }
3199  }
3200 }
3201 
3202 void ARICHDatabaseImporter::exportSensorModuleMapInfo(int number)
3203 {
3204  DBArray<ARICHSensorModuleMap> elements("ARICHSensorModuleMap");
3205  elements.getEntries();
3206 
3207  for (const auto& element : elements) {
3208  ARICHSensorModuleInfo* newelement = element.getSensorModuleId();
3209  if (!(newelement->getSensorModuleID() == number)) continue;
3210  B2INFO("Sextant = " << element.getSensorModuleSextantID() << ", ring = " << element.getSensorModuleRingID() << ", column = " <<
3211  element.getSensorModuleColumnID());
3212  B2INFO("module ID = " << newelement->getSensorModuleID() << ", feb = " << newelement->getFEBserial() << ", hapd = " <<
3213  newelement->getHAPDserial());
3214  ARICHHapdInfo* newerelement = newelement->getHapdID();
3215  B2INFO("Hapd Serial = " << newerelement->getSerialNumber() << "; HV = " << newerelement->getHighVoltage() << "; qe400 = " <<
3216  newerelement->getQuantumEfficiency400());
3217  for (int i = 0; i < 4; i++) {
3218  ARICHHapdChipInfo* newestelement = newerelement->getHapdChipInfo(i);
3219  B2INFO("Hapd Serial = " << newestelement->getHapdSerial() << "; chip = " << newestelement->getChipLabel() << "; gain = " <<
3220  newestelement->getGain());
3221  }
3222  }
3223 }
3224 
3225 void ARICHDatabaseImporter::importMagnetTest()
3226 {
3227  GearDir content = GearDir("/ArichData/AllData/magnetTest");
3228 
3229  // define data array
3230  TClonesArray magnetConstants("Belle2::ARICHMagnetTest");
3231  int num = 0;
3232  string sn;
3233 
3234  // loop over xml files and extract the data
3235  for (const auto& module : content.getNodes("module")) {
3236  // save data as an element of the array
3237  new(magnetConstants[num]) ARICHMagnetTest();
3238  auto* magnetConst = static_cast<ARICHMagnetTest*>(magnetConstants[num]);
3239 
3240  int snint = module.getInt("hapdID");
3241  if (snint < 5000) sn = "KA";
3242  else sn = "ZJ";
3243  char hapdID[6];
3244  sprintf(hapdID, "%s%04d", sn.c_str(), snint);
3245  magnetConst->setSerialNumber(hapdID);
3246 
3247  vector<float> deadtimes;
3248  for (const auto& time : module.getNodes("deadtime/measurement")) {
3249  if (time.getString(".") != "-") {
3250  float deadtime = (float) time.getDouble(".");
3251  deadtimes.push_back(deadtime);
3252  }
3253  }
3254  magnetConst->setDeadTime(deadtimes);
3255 
3256  if (module.getString("lowerA") != "-") magnetConst->setDeadTimeLowerA((float) module.getDouble("lowerA"));
3257  if (module.getString("lowerB") != "-") magnetConst->setDeadTimeLowerB((float) module.getDouble("lowerB"));
3258  if (module.getString("lowerC") != "-") magnetConst->setDeadTimeLowerC((float) module.getDouble("lowerC"));
3259  if (module.getString("lowerD") != "-") magnetConst->setDeadTimeLowerD((float) module.getDouble("lowerD"));
3260 
3261  bool getter_reactivation = module.getBool("getter");
3262  string comment = module.getString("comment");
3263  magnetConst->setGetter(getter_reactivation);
3264  magnetConst->setComment(comment);
3265 
3266  num++;
3267  }
3268 
3269  // store under default name:
3270  Database::Instance().storeData("ARICHMagnetTest", &magnetConstants, m_iov);
3271 }
3272 
3273 void ARICHDatabaseImporter::exportMagnetTest()
3274 {
3275 
3276  DBArray<ARICHMagnetTest> elements("ARICHMagnetTest");
3277  elements.getEntries();
3278 
3279  for (const auto& element : elements) {
3280  string getter = "no";
3281  if (element.getGetter() == 1) getter = "yes";
3282  B2INFO("SN = " << element.getSerialNumber() << "; after getter reactivation? " << getter);
3283  for (int i = 0; i < element.getDeadTimeSize();
3284  i++) B2INFO("dead time = " << element.getDeadTime(i) << " (" << (i + 1) << ". measurement)");
3285  if (element.getDeadTimeLowerA() > 0.) B2INFO("lower voltage on chip A = " << element.getDeadTimeLowerA());
3286  if (element.getDeadTimeLowerB() > 0.) B2INFO("lower voltage on chip B = " << element.getDeadTimeLowerB());
3287  if (element.getDeadTimeLowerC() > 0.) B2INFO("lower voltage on chip C = " << element.getDeadTimeLowerC());
3288  if (element.getDeadTimeLowerD() > 0.) B2INFO("lower voltage on chip D = " << element.getDeadTimeLowerD());
3289  B2INFO("comment = " << element.getComment());
3290  }
3291 }
3292 
3293 void ARICHDatabaseImporter::exportAll()
3294 {
3295  ARICHDatabaseImporter::exportAerogelInfo();
3296  ARICHDatabaseImporter::exportHapdQE();
3297  ARICHDatabaseImporter::exportModuleTest("no");
3298  ARICHDatabaseImporter::exportModuleTest("yes");
3299  ARICHDatabaseImporter::exportFEBoardInfo();
3300  ARICHDatabaseImporter::exportFebTest();
3301  ARICHDatabaseImporter::exportSensorModuleMap();
3302 }
Belle2::IntervalOfValidity
A class that describes the interval of experiments/runs for which an object in the database is valid.
Definition: IntervalOfValidity.h:35
Belle2::ARICHAeroTilesInfo
The Class for ARICH aerogel tiles properties for even reconstruction.
Definition: ARICHAeroTilesInfo.h:33
Belle2::ARICHChannelMask
The Class for ARICH HAPD channel mask.
Definition: ARICHChannelMask.h:35
Belle2::ARICHHapdChipInfo::getBiasVoltage
int getBiasVoltage() const
Return Chip Bias Voltage.
Definition: ARICHHapdChipInfo.h:82
Belle2::ARICHAerogelInfo::getAerogelVersion
float getAerogelVersion() const
Return Aerogel Version.
Definition: ARICHAerogelInfo.h:63
Belle2::ARICHPositionElement
Position element for ARICH.
Definition: ARICHPositionElement.h:36
Belle2::ARICHGeometryConfig
The Class for ARICH Geometry Parameters.
Definition: ARICHGeometryConfig.h:42
Belle2::tessellatedSolidStr
Structure which holds apexes of the tessellation volumes.
Definition: tessellatedSolidStr.h:36
Belle2::ARICHGeoMasterVolume::getMaterial
const std::string & getMaterial() const
Get material of ARICH master volume.
Definition: ARICHGeoMasterVolume.h:148
Belle2::ARICHGlobalAlignment::setAlignmentElement
void setAlignmentElement(const ARICHPositionElement &align)
Sets alignment parameters (element)
Definition: ARICHGlobalAlignment.h:93
Belle2::ARICHPositionElement::print
void print(const std::string &title="Parmeters of position element") const override
Print the content of the class.
Definition: ARICHPositionElement.h:196
Belle2::ARICHHapdChipInfo
Contains manufacturer data of one of the 4 photo sensors chips.
Definition: ARICHHapdChipInfo.h:35
Belle2::ARICHHapdChipInfo::setHapdSerial
void setHapdSerial(const std::string &serial)
Set Hapd Serial number.
Definition: ARICHHapdChipInfo.h:66
Belle2::hapd
TH1F * hapd[6]
histogram of hits for each hapd
Definition: arichBtestModule.cc:86
Belle2::ARICHGeoMasterVolume::getOuterRadius
double getOuterRadius() const
Get ARICH master volume outer radius.
Definition: ARICHGeoMasterVolume.h:136
Belle2::ARICHSensorModuleInfo::getHapdID
ARICHHapdInfo * getHapdID() const
Get HAPD Identifier.
Definition: ARICHSensorModuleInfo.h:105
Belle2::ARICHGlobalAlignment
Geometry parameters of ARICH Master volume (envelope)
Definition: ARICHGlobalAlignment.h:39
Belle2::ARICHChannelHist
ARICH histogram with HAPD plane 3 options for bin segmentation are available type 0 - one bin per HAP...
Definition: ARICHChannelHist.h:37
Belle2::ARICHMagnetTest
Contains fractions of dead times measured in a magnet.
Definition: ARICHMagnetTest.h:31
Belle2::ARICHGeometryConfig::setSupportStructure
void setSupportStructure(const ARICHGeoSupport &supportStructure)
Set support structure geometry configuration.
Definition: ARICHGeometryConfig.h:201
Belle2::gearbox::Interface::getAngle
double getAngle(const std::string &path="") const noexcept(false)
Get the parameter path as a double converted to the standard angle unit.
Definition: Interface.h:301
Belle2::ARICHMirrorAlignment
Mirror alignment parameters for ARICH.
Definition: ARICHMirrorAlignment.h:33
Belle2::ARICHGeoSupport::clearBoxes
void clearBoxes()
Clear container of boxes.
Definition: ARICHGeoSupport.h:280
Belle2::ARICHBiasVoltages
The Class for ARICH bias voltages at gain 40.
Definition: ARICHBiasVoltages.h:34
Belle2::ARICHReconstructionPar
The Class for ARICH reconstruction parameters.
Definition: ARICHReconstructionPar.h:34
Belle2::ARICHReconstructionPar::initializeDefault
void initializeDefault()
initializes "default" values of parameters
Definition: ARICHReconstructionPar.cc:20
Belle2::DBArray
Class for accessing arrays of objects in the database.
Definition: DBArray.h:36
Belle2::EventDependency::add
void add(unsigned int event, TObject *object)
Add an object to the intra run dependency.
Definition: EventDependency.cc:16
Belle2::ARICHAerogelInfo::getAerogelThickness
float getAerogelThickness() const
Return Aerogel Thickness.
Definition: ARICHAerogelInfo.h:114
Belle2::ARICHHapdChipInfo::getHapdSerial
std::string getHapdSerial() const
Return Hapd Serial number.
Definition: ARICHHapdChipInfo.h:61
Belle2::ARICHHvChannelsMapping
The Class for ARICH mapping of bias power supply channels to modules.
Definition: ARICHHvChannelsMapping.h:28
Belle2::ARICHFEBoardInfo::setFEBoardSerial
void setFEBoardSerial(int serial)
Set Front End Board Identifier.
Definition: ARICHFEBoardInfo.h:70
Belle2::ARICHBiasChannelsMapping::addMapping
void addMapping(int crate, int slot, int channelID, int pinID, int connectionID, int innerID, const std::string &type)
Add new entry to the mapping table.
Definition: ARICHBiasChannelsMapping.cc:77
Belle2::ARICHAerogelInfo::getAerogelRefractiveIndex
float getAerogelRefractiveIndex() const
Return Refractive Index of Aerogel.
Definition: ARICHAerogelInfo.h:94
Belle2::ARICHChannelMask::setActiveCh
void setActiveCh(unsigned modId, unsigned chNo, bool active)
Set active/non-active channel.
Definition: ARICHChannelMask.cc:24
Belle2::ARICHBiasCablesMapping
The Class for ARICH mapping of bias cables to modules.
Definition: ARICHBiasCablesMapping.h:30
Belle2::DBImportObjPtr::construct
void construct(Args &&... params)
Construct an object of type T in this DBImportObjPtr using the provided constructor arguments.
Definition: DBImportObjPtr.h:57
Belle2::ARICHSensorModuleInfo::getHAPDserial
std::string getHAPDserial() const
Get HAPD serial number.
Definition: ARICHSensorModuleInfo.h:95
Belle2::DBImportBase::import
bool import(const IntervalOfValidity &iov)
Import the object to database.
Definition: DBImportBase.cc:38
Belle2::ARICHMirrorAlignment::setAlignmentElement
void setAlignmentElement(int id, const ARICHPositionElement &pars)
Sets Alignment parameters (element) for mirror plate.
Definition: ARICHMirrorAlignment.h:50
Belle2::ARICHGeometryConfig::setAerogelPlane
void setAerogelPlane(const ARICHGeoAerogelPlane &aerogelPlane)
Set geometry configuration of aerogel plane.
Definition: ARICHGeometryConfig.h:165
Belle2::ARICHModuleTest
The Class for ARICH Aerogel Parameters.
Definition: ARICHModuleTest.h:40
Belle2::ARICHMergerMapping::getFEBSlot
unsigned getFEBSlot(unsigned moduleID) const
Get FEB slot to which module is connected.
Definition: ARICHMergerMapping.cc:40
Belle2::ARICHHapdQE
Contains manufacturer data of the photo sensor - HAPD.
Definition: ARICHHapdQE.h:32
Belle2::ARICHMergerMapping::getModuleID
unsigned getModuleID(unsigned mergerID, unsigned febSlot) const
Get ID of module connected to merger at FEB slot.
Definition: ARICHMergerMapping.cc:26
Belle2::ARICHSimulationPar::setPeakQE
void setPeakQE(double peak)
Set peak QE value (for HAPD with maximal QE, at later stage HAPD dependent scaling is done)
Definition: ARICHSimulationPar.h:116
Belle2::DBArray::getEntries
int getEntries() const
Get the number of objects in the array.
Definition: DBArray.h:52
Belle2::ARICHBiasCrateCableMapping
The Class for ARICH bias voltages at gain 40.
Definition: ARICHBiasCrateCableMapping.h:34
Belle2::ARICHAerogelRayleighScatteringFit
The Class for ARICH aerogel Rayleigh scattering fit parameters.
Definition: ARICHAerogelRayleighScatteringFit.h:36
Belle2::ARICHGeometryConfig::getAerogelPlane
const ARICHGeoAerogelPlane & getAerogelPlane() const
Get geometry configuration of aerogel plane.
Definition: ARICHGeometryConfig.h:98
Belle2::DBObjPtr
Class for accessing objects in the database.
Definition: DBObjPtr.h:31
Belle2::gearbox::Interface::getDouble
double getDouble(const std::string &path="") const noexcept(false)
Get the parameter path as a double.
Definition: Interface.cc:51
Belle2::EventDependency
Class for handling changing conditions as a function of event number.
Definition: EventDependency.h:32
Belle2::ARICHModulesInfo
The Class for information on HAPD modules installed in ARICH.
Definition: ARICHModulesInfo.h:35
Belle2::ARICHAerogelMap::setAerogelSN
void setAerogelSN(const std::string &agelid)
Set Aerogel serial number.
Definition: ARICHAerogelMap.h:72
Belle2::ARICHFEBoardInfo
Front End Electronics Boards.
Definition: ARICHFEBoardInfo.h:34
Belle2::ARICHSensorModuleMap::setSensorModuleSextantID
void setSensorModuleSextantID(int sextant)
Set SensorModule Sextant Identifier.
Definition: ARICHSensorModuleMap.h:75
Belle2::ARICHChannelMapping
The Class for ARICH HAPD channel mapping.
Definition: ARICHChannelMapping.h:30
Belle2::ARICHModulesInfo::addModule
void addModule(unsigned modId, std::vector< float > &qeList, bool active)
Add installed module.
Definition: ARICHModulesInfo.cc:44
Belle2::ARICHHapdQA
Contains manufacturer data of the photo sensor - HAPD.
Definition: ARICHHapdQA.h:36
Belle2::ARICHGeoMergerCooling::addMergerCoolingBodiesInfo
void addMergerCoolingBodiesInfo(tessellatedSolidStr mergerCoolingBodiesStr)
Set vector of structures which holds apexes of the tessellation volumes for (merger cooling bodyes).
Definition: ARICHGeoMergerCooling.h:61
Belle2::ARICHChannelMapping::mapXY2Asic
void mapXY2Asic(unsigned xChn, unsigned yChn, unsigned asicChn)
Add entry to channel map.
Definition: ARICHChannelMapping.cc:46
Belle2::ARICHGeoSupport::addBox
void addBox(const std::string &name, const std::string &material, double size[3], double position[3], double rotation[3])
Add box volume.
Definition: ARICHGeoSupport.h:239
Belle2::ARICHAeroTilesAlignment
Alignment parameters for aerogel tiles.
Definition: ARICHAeroTilesAlignment.h:33
Belle2::ARICHSensorModuleInfo
Sensor Module Information.
Definition: ARICHSensorModuleInfo.h:35
Belle2::ARICHSimulationPar
The Class for ARICH simulation parameters.
Definition: ARICHSimulationPar.h:34
Belle2::ARICHGeoMergerCooling::checkMergerCoolingSystemDataConsistency
void checkMergerCoolingSystemDataConsistency() const
Check data consistency of the cooling system (v2) positions In case of failure print the BASF2 ERROR ...
Definition: ARICHGeoMergerCooling.cc:49
Belle2::ARICHGeoMasterVolume::setPlacement
void setPlacement(double x, double y, double z, double rx, double ry, double rz)
Sets positioning of ARICH master volume in global Belle II coordinate system.
Definition: ARICHGeoMasterVolume.cc:39
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ARICHSensorModuleInfo::getSensorModuleID
int getSensorModuleID() const
Get Sensor Module Identifier.
Definition: ARICHSensorModuleInfo.h:65
Belle2::ARICHBiasCablesMapping::addMapping
void addMapping(int moduleID, int sectorID, int cableID, int innerID)
Add mapping entry.
Definition: ARICHBiasCablesMapping.cc:58
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::IntraRunDependency::getObject
TObject * getObject(const EventMetaData &event) const
Get the conditions object that is valid for the given event.
Definition: IntraRunDependency.h:57
Belle2::ARICHGeoMasterVolume::setVolume
void setVolume(double innerR, double outerR, double length, const std::string &material)
Sets parameters of ARICH master volume.
Definition: ARICHGeoMasterVolume.h:89
Belle2::ARICHFebTest::setFebSerial
void setFebSerial(int serial)
Set FEB serial number.
Definition: ARICHFebTest.h:76
Belle2::ARICHGeoMasterVolume::getInnerRadius
double getInnerRadius() const
Get ARICH master volume inner radius.
Definition: ARICHGeoMasterVolume.h:130
Belle2::ARICHGeoMergerCooling::setMergerCoolingBodiesMaterialName
void setMergerCoolingBodiesMaterialName(const std::string &materialName)
Set material name of merger cooling bodies.
Definition: ARICHGeoMergerCooling.h:55
Belle2::ARICHAerogelMap
Map of the Aerogel placement.
Definition: ARICHAerogelMap.h:32
Belle2::ARICHAerogelHist::GetBinIDFromRingColumn
Int_t GetBinIDFromRingColumn(Int_t ring, Int_t column)
Function which return histogram bin id from ring and column id's.
Definition: ARICHAerogelHist.cc:85
Belle2::GearDir
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:41
Belle2::ARICHFebTest
The Class for ARICH Aerogel Parameters.
Definition: ARICHFebTest.h:41
Belle2::ARICHHvCrateCableMapping::addMapping
void addMapping(int connectionID, std::vector< int > sectorCable)
Add new entry to the mapping table.
Definition: ARICHHvCrateCableMapping.cc:45
Belle2::ARICHSimulationPar::setQEScaling
void setQEScaling(double qescale)
Set QE scaling factor for photons internally reflected in HAPD window.
Definition: ARICHSimulationPar.h:92
Belle2::DBImportObjPtr
Class for importing a single object to the database.
Definition: DBImportObjPtr.h:33
Belle2::ARICHSensorModuleMap
Mapping of the Sensor Board Connections to the detector.
Definition: ARICHSensorModuleMap.h:35
Belle2::ARICHChannelMapping::getAsicFromXY
int getAsicFromXY(unsigned xChn, unsigned yChn) const
Get asic channel number from HAPD channel X,Y numbers.
Definition: ARICHChannelMapping.cc:39
Belle2::ARICHSimulationPar::setChipNegativeCrosstalk
void setChipNegativeCrosstalk(double cross)
Set factor to suppress p.e.
Definition: ARICHSimulationPar.h:104
Belle2::ARICHGeometryConfig::getMasterVolume
const ARICHGeoMasterVolume & getMasterVolume() const
Get ARICH master volume geometry configuration.
Definition: ARICHGeometryConfig.h:110
Belle2::ARICHHapdInfo::getQuantumEfficiency400
float getQuantumEfficiency400() const
Return quantum efficiency at 400 nm.
Definition: ARICHHapdInfo.h:83
Belle2::ARICHHapdInfo::getSerialNumber
std::string getSerialNumber() const
Return HAPD Serial Number.
Definition: ARICHHapdInfo.h:71
Belle2::ARICHSimulationPar::setWindowAbsorbtion
void setWindowAbsorbtion(double abs)
Set absorbtion probability for photons internally reflected in HAPD window.
Definition: ARICHSimulationPar.h:98
Belle2::ARICHGeometryConfig::setMasterVolume
void setMasterVolume(const ARICHGeoMasterVolume &masterVolume)
Set master volume geometry configuration.
Definition: ARICHGeometryConfig.h:192
Belle2::ARICHHapdChipInfo::getGain
int getGain() const
Return Chip Gain at Operational Voltage.
Definition: ARICHHapdChipInfo.h:94
Belle2::ARICHGeoMasterVolume
Geometry parameters of ARICH Master volume (envelope)
Definition: ARICHGeoMasterVolume.h:38
Belle2::ARICHBiasCrateCableMapping::addMapping
void addMapping(int connectionID, std::vector< int > sectorCable)
Add new entry to the mapping table.
Definition: ARICHBiasCrateCableMapping.cc:47
Belle2::ARICHSimulationPar::print
void print() const
print class content
Definition: ARICHSimulationPar.cc:41
Belle2::ARICHSimulationPar::setQECurve
void setQECurve(float lambdaFirst, float lambdaStep, const std::vector< float > &qe)
Set QE curve.
Definition: ARICHSimulationPar.cc:34
Belle2::ARICHHapdInfo::getHapdChipInfo
ARICHHapdChipInfo * getHapdChipInfo(unsigned int i) const
Return HapdChipInfo of the chip i.
Definition: ARICHHapdInfo.cc:17
Belle2::ARICHAerogelInfo::getAerogelSN
std::string getAerogelSN() const
Return Aerogel Serial number.
Definition: ARICHAerogelInfo.h:73
Belle2::ARICHGeoMergerCooling::setMergerCoolingPositionID
void setMergerCoolingPositionID(const std::vector< double > &mergerCoolingPositionID)
Set vector of merger cooling body shape id (positionID) for each merger PCB.
Definition: ARICHGeoMergerCooling.h:67
Belle2::ARICHSimulationPar::setCollectionEff
void setCollectionEff(double colEff)
Set HAPD collection efficiency.
Definition: ARICHSimulationPar.h:110
Belle2::ARICHHvCablesMapping
The Class for ARICH mapping of bias cables to modules.
Definition: ARICHHvCablesMapping.h:30
Belle2::gearbox::Interface::getLength
double getLength(const std::string &path="") const noexcept(false)
Get the parameter path as a double converted to the standard length unit.
Definition: Interface.h:261
Belle2::GearDir::getString
virtual std::string getString(const std::string &path="") const noexcept(false) override
Get the parameter path as a string.
Definition: GearDir.h:79
Belle2::ARICHModuleTest::setFebSN
void setFebSN(int serial)
Set FEB serial number.
Definition: ARICHModuleTest.h:71
Belle2::ARICHHvChannelsMapping::addMapping
void addMapping(int crate, int slot, int channelID, int connectionID, int pinID)
Add new entry to the mapping table.
Definition: ARICHHvChannelsMapping.cc:60
Belle2::ARICHMergerMapping::getMergerID
unsigned getMergerID(unsigned moduleID) const
Get ID of merger to which module is connected.
Definition: ARICHMergerMapping.cc:33
Belle2::gearbox::Interface::getArray
std::vector< double > getArray(const std::string &path) const noexcept(false)
Get the parameter path as a list of double values converted to the standard unit.
Definition: Interface.cc:133
Belle2::EventMetaData
Store event, run, and experiment numbers.
Definition: EventMetaData.h:43
Belle2::ARICHAerogelInfo::getAerogelTransmissionLength
float getAerogelTransmissionLength() const
Return Transmission Length at 400 nm.
Definition: ARICHAerogelInfo.h:104
Belle2::ARICHHvCablesMapping::addMapping
void addMapping(int moduleID, int sectorID, int cableID, int innerID)
Add mapping entry.
Definition: ARICHHvCablesMapping.cc:58
Belle2::ARICHBiasVoltages::addVoltages
void addVoltages(const std::string &hapdID, std::vector< int > biasVoltages)
Add new entry to the mapping table.
Definition: ARICHBiasVoltages.cc:33
Belle2::ARICHMergerMapping::addMapping
void addMapping(unsigned moduleID, unsigned mergerID, unsigned febSlot, unsigned mergerSN)
Add mapping entry.
Definition: ARICHMergerMapping.cc:61
Belle2::ARICHHapdInfo
Contains manufacturer data of the photo sensor - HAPD.
Definition: ARICHHapdInfo.h:33
Belle2::ARICHSensorModuleInfo::setSensorModuleID
void setSensorModuleID(int id)
Set Sensor Module Identifier.
Definition: ARICHSensorModuleInfo.h:70
Belle2::ARICHGeoAerogelPlane
Geometry parameters of HAPD.
Definition: ARICHGeoAerogelPlane.h:37
Belle2::ARICHAerogelInfo
The Class for ARICH Aerogel Parameters.
Definition: ARICHAerogelInfo.h:37
Belle2::ARICHGeoMergerCooling
Geometry parameters of Merger Cooling System - version2 (v2).
Definition: ARICHGeoMergerCooling.h:41
Belle2::ARICHGeometryConfig::getSupportStructure
const ARICHGeoSupport & getSupportStructure() const
Get ARICH support structure geometry configuration.
Definition: ARICHGeometryConfig.h:116
Belle2::ARICHAsicInfo
Tested ASIC chips.
Definition: ARICHAsicInfo.h:35
Belle2::ARICHAeroTilesAlignment::setAlignmentElement
void setAlignmentElement(int id, const ARICHPositionElement &pars)
Sets Alignment parameters (element) for aerogel tile.
Definition: ARICHAeroTilesAlignment.h:47
Belle2::ARICHBiasChannelsMapping
The Class for ARICH mapping of bias power supply channels to modules.
Definition: ARICHBiasChannelsMapping.h:28
Belle2::ARICHHapdChipInfo::getChipLabel
std::string getChipLabel() const
Return Chip label.
Definition: ARICHHapdChipInfo.h:71
Belle2::ARICHAeroTilesInfo::addMapping
void addMapping(int slot, int layer, float refractiveIndex, float transmissionLength, float thickness)
Add mapping entry.
Definition: ARICHAeroTilesInfo.cc:57
Belle2::gearbox::Interface::getNodes
std::vector< GearDir > getNodes(const std::string &path="") const
Get vector of GearDirs which point to all the nodes the given path evaluates to.
Definition: Interface.cc:31
Belle2::ARICHAsicInfo::setAsicID
void setAsicID(const std::string &id)
Set Asic Identifier.
Definition: ARICHAsicInfo.h:66
Belle2::ARICHHvCrateCableMapping
The Class for ARICH bias voltages at gain 40.
Definition: ARICHHvCrateCableMapping.h:34
Belle2::ARICHSensorModuleInfo::getFEBserial
int getFEBserial() const
Get FEB serial number.
Definition: ARICHSensorModuleInfo.h:75
Belle2::ARICHHapdInfo::getHighVoltage
float getHighVoltage() const
Return operational High Voltage.
Definition: ARICHHapdInfo.h:95
Belle2::ARICHAerogelHist
Base class for geometry parameters.
Definition: ARICHAerogelHist.h:38
XY
Point.
Definition: TRGCDCHoughMapping.cc:17
Belle2::ARICHCopperMapping::addMapping
void addMapping(unsigned mergerID, unsigned copperID, unsigned finesse)
Add new entry to the mapping table.
Definition: ARICHCopperMapping.cc:40
Belle2::ARICHGeoSupport
Geometry parameters of ARICH support structures and neutron shield.
Definition: ARICHGeoSupport.h:35
Belle2::ARICHCopperMapping
The Class for ARICH mapping of merger to copper boards.
Definition: ARICHCopperMapping.h:30
Belle2::ARICHMergerMapping
The Class for ARICH mapping of modules to merger boards.
Definition: ARICHMergerMapping.h:31