ATLAS Offline Software
TubeDataFromFile.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <TString.h> // for Form
8 #include <math.h>
9 #include <stdio.h>
10 
11 #include <sstream>
12 #include <string>
13 
15 
16 namespace MuonCalib {
17 
18  std::ostream& TubeDataFromFile::write(std::ostream& os) const {
19  if (m_regions != m_tubeData.size()) {
20  MsgStream log(Athena::getMessageSvc(), "MdtTubeFitContainer");
21  log << MSG::WARNING << "TubeDataFromFile::write: <inconsistent count>" << endmsg;
22  }
23 
24  os << "v0.0 " << m_regions << " ";
25  unsigned int counter{0};
26  for (const MdtTubeFitContainer* container : m_tubeData) {
27  if (!container) continue;
28  const unsigned int nml = container->numMultilayers();
29  const unsigned int nl = container->numLayers();
30  const unsigned int nt = container->numTubes();
31  const std::string datatype = container->name();
32  const std::string implementation = container->implementation();
33  const int stnEta = container->idHelperSvc()->stationEta(container->identify());
34  const int stnPhi = container->idHelperSvc()->stationPhi(container->identify());
35  const std::string stnName = container->idHelperSvc()->stationNameString(container->identify());
36  os << datatype << " " << implementation << " " << counter << " " << container->size() << std::endl;
37  ++counter;
38  const MdtIdHelper& id_helper{container->idHelperSvc()->mdtIdHelper()};
39  for (unsigned int km = 1; km <= nml; ++km) {
40  for (unsigned int kl = 1; kl <= nl; ++kl) {
41  for (unsigned int kt = 1; kt <= nt; ++kt) {
42  const Identifier chId{id_helper.channelID(container->identify(),km ,kl ,kt)};
43  const MdtTubeFitContainer::SingleTubeCalib* stc = container->getCalib(chId);
44  const MdtTubeFitContainer::SingleTubeFit* stf = container->getFit(chId);
45  double t0 = 999.;
46  if (stc) {
47  t0 = stc->t0;
48  if (std::isnan(t0) != 0) t0 = -99999.;
49  }
50  constexpr int technology = 0;
51  os << " " << stnName << " " << stnPhi << " " << stnEta
52  << " " << technology << " " << km << " " << kl << " " << kt;
53  if (stc) {
54  os << " " << t0 << " " << stc->adcCal << " " << stc->statusCode;
55  } else{
56  os << " " << 0 << " " << 0 << " " << 0;
57 
58  }
59  if (stf)
60  os << " " << stf->statistics << " " << stf->chi2Tdc << " " << stf->cov[4] // stf->t0Err
61  << " " << stf->par[5] // stf->tMax
62  << " " << stf->cov[5] // stf->tMaxErr
63  << " " << stf->par[0] // stf->noise
64  << " " << stf->cov[0] // stf->noiseErr
65  << " " << stf->par[6] // stf->slope
66  << " " << stf->cov[6]; // stf->slopeErr;
67  else {
68  os << " " << -1 << " " << 0 << " " << 0 << " " << 0 << " "
69  << 0 << " " << 0 << " " << 0 << " " << 0 << " "
70  << 0;
71  }
72  os << std::endl;
73  }
74  }
75  }
76  }
77  return os;
78  }
79 
80 
81  std::ostream& TubeDataFromFile::write_forDB(std::ostream& ftube, int mdt_head, int lowrun, int uprun) const {
83  // write out ascii files for Calibration DB //
85  if (m_regions != m_tubeData.size()) {
86  MsgStream log(Athena::getMessageSvc(), "MdtTubeFitContainer");
87  log << MSG::WARNING << "TubeDataFromFile::write_forDB: <inconsistent count>" << endmsg;
88  }
89 
90  for (const MdtTubeFitContainer* container : m_tubeData) {
91  if (!container) continue;
92  const unsigned int nml = container->numMultilayers();
93  const unsigned int nl = container->numLayers();
94  const unsigned int nt = container->numTubes();
95  const std::string datatype = container->name();
96  const std::string implementation = container->implementation();
97  const int stnEta = container->idHelperSvc()->stationEta(container->identify());
98  const int stnPhi = container->idHelperSvc()->stationPhi(container->identify());
99  const std::string stnName = container->idHelperSvc()->stationNameString(container->identify());
100 
101  const MdtIdHelper& id_helper{container->idHelperSvc()->mdtIdHelper()};
102  for (unsigned int km = 1; km <= nml; ++km) {
103  for (unsigned int kl = 1; kl <= nl; ++kl) {
104  for (unsigned int kt = 1; kt <= nt; ++kt) {
105  const Identifier chId{id_helper.channelID(container->identify(),km ,kl ,kt)};
106  const MdtTubeFitContainer::SingleTubeCalib* stc = container->getCalib(chId);
107  const MdtTubeFitContainer::SingleTubeFit* stf = container->getFit(chId);
108  constexpr int technology = 0;
109 
110  MuonFixedId fixId{};
111  int sc{0}, stat{-1};
112  double t0{0.}, adcm{0.}, chi2tdc{0.}, t0err{0.},
113  tmax{0.}, tmaxerr{0.}, noise{0.}, noiseerr{0.},
114  slope{0.}, sloperr{0.};
115  int tube_id{0}, runflag{0}, validflag{0};
116 
117  if (!fixId.setTechnology(technology) ||
118  !fixId.setStationName(fixId.stationStringToFixedStationNumber(stnName)) ||
119  !fixId.setStationEta(stnEta) ||
120  !fixId.setStationPhi(stnPhi) ||
121  !fixId.setMdtTube(kt) ||
122  !fixId.setMdtTubeLayer(kl) ||
123  !fixId.setMdtMultilayer(km)) {
124  std::stringstream except{};
125  except<<__FILE__<<":"<<__LINE__<<"nTubeDataFromFile::write_forDB() - Setting identifier failed!";
126  throw std::runtime_error(except.str());
127  }
128  tube_id = fixId.getIdInt();
129 
130  if (stc) {
131  t0 = stc->t0;
132  adcm = stc->adcCal;
133  sc = stc->statusCode;
134  }
135  if (stf) {
136  stat = stf->statistics;
137  chi2tdc = stf->chi2Tdc;
138  t0err = stf->cov[4];
139  tmax = stf->par[5];
140  tmaxerr = stf->cov[5];
141  noise = stf->par[0];
142  noiseerr = stf->cov[0];
143  slope = stf->par[6];
144  sloperr = stf->cov[6];
145  }
146 
147  if (std::isnan(t0) != 0) t0 = -99999.;
148 
149  ftube<<mdt_head<<","<<tube_id<<","<<fixId.mdtChamberId().getIdInt()<<","
150  <<","<<lowrun<<","<<uprun<<","<<runflag<<","<<sc
151  <<validflag<<","<<stat<<",";
152 
153  for (int ii = -2; ii < 35; ii++) {
154  if (ii == -2) {
155  ftube<<chi2tdc<<",";
156  } else if (ii == 0) {
157  ftube<<noise<<",";
158  } else if (ii == 4) {
159  ftube<<t0<<",";
160  } else if (ii == 5) {
161  ftube<<tmax<<",";
162  } else if (ii == 6) {
163  ftube<<slope<<",";
164  } else if (ii == 10) {
165  ftube<<t0err<<",";
166  } else if (ii == 11) {
167  ftube<<tmaxerr<<",";
168  } else if (ii == 12) {
169  ftube<<noiseerr<<",";
170  } else if (ii == 13) {
171  ftube<<sloperr<<",";
172  } else if (ii == 14) {
173  ftube<<adcm<<",";
174  } else {
175  ftube<<0.0<<",";
176  }
177  }
178  ftube<<"0,0,algoflag,tubegrpgr"<<std::endl;
179  }
180  }
181  }
182  }
183  return ftube;
184  }
185 
186 } // namespace MuonCalib
187 
188 std::ostream& operator<<(std::ostream& os, const MuonCalib::TubeDataFromFile& data) { return data.write(os); }
MuonCalib::MdtTubeCalibContainer::SingleTubeCalib::t0
float t0
< relative t0 in chamber (ns)
Definition: MdtTubeCalibContainer.h:20
MuonCalib::MdtTubeFitContainer::SingleTubeFit::chi2Tdc
float chi2Tdc
Definition: MdtTubeFitContainer.h:26
MuonCalib::TubeDataFromFile::m_regions
unsigned int m_regions
total number of regions
Definition: TubeDataFromFile.h:77
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
MuonCalib::MdtTubeFitContainer::SingleTubeFit::par
std::array< float, 8 > par
Definition: MdtTubeFitContainer.h:29
MuonCalib::MdtTubeFitContainer::SingleTubeFit
Definition: MdtTubeFitContainer.h:18
MuonCalib::TubeDataFromFile
Definition: TubeDataFromFile.h:24
ALFA_EventTPCnv_Dict::t0
std::vector< ALFA_RawData_p1 > t0
Definition: ALFA_EventTPCnvDict.h:42
ParticleJetParams::kt
@ kt
Definition: ParticleJetParamDefs.h:43
MuonCalib::MdtTubeFitContainer::SingleTubeFit::statistics
int statistics
< number of hits used for the fit
Definition: MdtTubeFitContainer.h:20
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
MuonCalib::MdtTubeCalibContainer::SingleTubeCalib::statusCode
unsigned int statusCode
Definition: MdtTubeCalibContainer.h:26
operator<<
std::ostream & operator<<(std::ostream &os, const MuonCalib::TubeDataFromFile &data)
Definition: TubeDataFromFile.cxx:188
MuonCalib::TubeDataFromFile::write
std::ostream & write(std::ostream &os) const
Definition: TubeDataFromFile.cxx:18
keylayer_zslicemap.kl
kl
Definition: keylayer_zslicemap.py:109
calibdata.tube_id
tube_id
Definition: calibdata.py:30
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
calibdata.uprun
uprun
Definition: calibdata.py:34
MdtIdHelper
Definition: MdtIdHelper.h:61
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
MuonCalib::TubeDataFromFile::write_forDB
std::ostream & write_forDB(std::ostream &ftube, int mdt_head, int lowrun, int uprun) const
Definition: TubeDataFromFile.cxx:81
TubeDataFromFile.h
MuonCalib::MdtTubeFitContainer::SingleTubeFit::cov
std::array< float, 36 > cov
Definition: MdtTubeFitContainer.h:30
beamspotman.stat
stat
Definition: beamspotman.py:266
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
MuonCalib::MdtTubeCalibContainer::SingleTubeCalib::adcCal
float adcCal
quality flag for the SingleTubeCalib constants: 0 all ok, 1 no hits found, 2 too few hits,...
Definition: MdtTubeCalibContainer.h:24
MuonCalib::MuonFixedId
Definition: MuonFixedId.h:50
DeleteObject.h
MuonCalib::TubeDataFromFile::m_tubeData
TubeData m_tubeData
data
Definition: TubeDataFromFile.h:80
calibdata.lowrun
lowrun
Definition: calibdata.py:33
MuonCalib::MdtTubeFitContainer
Holds single-tube full calibration information of one chamber.
Definition: MdtTubeFitContainer.h:16
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
calibdata.implementation
implementation
Definition: calibdata.py:43
MuonCalib::MdtTubeCalibContainer::SingleTubeCalib
Definition: MdtTubeCalibContainer.h:18
beamspotnt.nt
def nt
Definition: bin/beamspotnt.py:1063
test_pyathena.counter
counter
Definition: test_pyathena.py:15
python.SystemOfUnits.km
int km
Definition: SystemOfUnits.py:95
WriteCellNoiseToCool.noise
noise
Definition: WriteCellNoiseToCool.py:380