//_HADES_CLASS_DESCRIPTION ///////////////////////////////////////////////////////////// // // HStsCalGeomPar // // Container class for Sts calibration parameters // ///////////////////////////////////////////////////////////// #include "hstscalgeompar.h" #include "hades.h" #include "hdetpario.h" #include "hpario.h" #include "hspectrometer.h" #include "hstsdetector.h" #include "stsdef.h" #include #include #include const Int_t DATA_NUM = 3; ClassImp(HStsCalGeomPar) ClassImp(HStsCalGeomParMod) ClassImp(HStsCalGeomParSec) ClassImp(HStsCalGeomParCell) const float default_time_offset_as_disabled = 0.0f; void HStsCalGeomParCellKind::clear() { readoutPos = default_time_offset_as_disabled; strawLength = default_time_offset_as_disabled; propTime = default_time_offset_as_disabled; } void HStsCalGeomParCellKind::fill(Float_t rp, Float_t sl, Float_t pt) { readoutPos = rp; strawLength = sl; propTime = pt; } void HStsCalGeomParCellKind::fill(Float_t *data) { readoutPos = data[0]; strawLength = data[1]; propTime = data[2]; } void HStsCalGeomParCellKind::fill(HStsCalGeomParCellKind &r) { *this = r; } HStsCalGeomParCell::HStsCalGeomParCell(Int_t n) { // constructor creates an array of pointers of type HStsCalGeomParCellKind array = new TObjArray(n); for (Int_t i = 0; i < n; i++) { array->AddAt(new HStsCalGeomParCellKind(), i); } } HStsCalGeomParCell::~HStsCalGeomParCell() { // destructor array->Delete(); delete array; } HStsCalGeomParSec::HStsCalGeomParSec(Int_t n) { // constructor creates an array of pointers of type HStsCalGeomParCellKind array = new TObjArray(n); for (Int_t i = 0; i < n; i++) { array->AddAt(new HStsCalGeomParCell(STS_MAX_UDCONF), i); } } HStsCalGeomParSec::~HStsCalGeomParSec() { // destructor array->Delete(); delete array; } HStsCalGeomParMod::HStsCalGeomParMod(Int_t n) { // constructor creates an array of pointers of type HStsCalGeomParCellKind array = new TObjArray(n); for (Int_t i = 0; i < n; i++) { array->AddAt(new HStsCalGeomParSec(STS_MAX_CELLS), i); } } HStsCalGeomParMod::~HStsCalGeomParMod() { // destructor array->Delete(); delete array; } HStsCalGeomPar::HStsCalGeomPar(const Char_t *name, const Char_t *title, const Char_t *context) : HParSet(name, title, context) { // constructor creates an array of pointers of type HStsCalGeomParSec strcpy(detName, "Sts"); HStsDetector *det = (HStsDetector *)(gHades->getSetup()->getDetector("Sts")); array = new TObjArray(STS_MAX_MODULES); for (Int_t i = 0; i < STS_MAX_MODULES; i++) { if (det->getModule(i, 0) > 0) { array->AddAt(new HStsCalGeomParMod(STS_MAX_LAYERS), i); } else { array->AddAt(new HStsCalGeomParMod(0), i); } } } HStsCalGeomPar::~HStsCalGeomPar() { // destructor if (array) { array->Delete(); delete array; } } Bool_t HStsCalGeomPar::init(HParIo *inp, Int_t *set) { // intitializes the container from an input HDetParIo *input = inp->getDetParIo("HStsParIo"); if (input) return (input->init(this, set)); return kFALSE; } Int_t HStsCalGeomPar::write(HParIo *output) { // writes the container to an output HDetParIo *out = output->getDetParIo("HStsParIo"); if (out) return out->write(this); return -1; } void HStsCalGeomPar::clear() { // clears the container for (Int_t i = 0; i < getSize(); i++) { HStsCalGeomParMod &mod = (*this)[i]; for (Int_t j = 0; j < mod.getSize(); j++) { HStsCalGeomParSec &sec = mod[j]; for (Int_t k = 0; k < sec.getSize(); k++) { HStsCalGeomParCell &cell = sec[k]; for (Int_t l = 0; l < cell.getSize(); l++) cell[l].clear(); } } } status = kFALSE; resetInputVersions(); } void HStsCalGeomPar::printParams() { // prints the calibration parameters TString header; putAsciiHeader(header); printf("%s", header.Data()); Float_t data[DATA_NUM]; for (Int_t i = 0; i < getSize(); i++) { HStsCalGeomParMod &mod = (*this)[i]; for (Int_t j = 0; j < mod.getSize(); j++) { HStsCalGeomParSec §or = mod[j]; for (Int_t k = 0; k < sector.getSize(); k++) { HStsCalGeomParCell &cell = sector[k]; for (Int_t l = 0; l < cell.getSize(); l++) { HStsCalGeomParCellKind &kind = cell[l]; kind.getData(data); if (data[0] == default_time_offset_as_disabled) continue; printf("%4i %4i %4i %4i %10.5f %10.5f %10.5f\n", i, j, k, l, data[0], data[1], data[2]); } } } } } void HStsCalGeomPar::readline(const Char_t *buf, Int_t *set) { // decodes one line read from ASCII file I/O Int_t mod, sector, cell, kind; Float_t data[DATA_NUM] = {0.F}; Int_t n = sscanf(buf, "%i%i%i%i%f%f%f", &mod, §or, &cell, &kind, &data[0], &data[1], &data[2]); if (n < DATA_NUM + 4) { Error("readline", "Not enough values in line %s\n", buf); } else if (n > DATA_NUM + 4) { Error("readline", "Too many values in line %s\n", buf); } else { if (sector < 0 || sector > 3) return; if (!set[sector]) return; if (cell < 0) { Error("readline", "STS strip %d not defined\n", cell); return; } if (kind < 1 || kind > 3) { Error("readline", "STS strip %d kind %d not defined\n", cell, kind); return; } (*this)[mod][sector][cell][kind].fill(data); set[sector] = 999; } } void HStsCalGeomPar::putAsciiHeader(TString &header) { // puts the ascii header to the string used in HStsParAsciiFileIo header = "# Calibration parameters for the Sts\n" "# Format:\n" "# mod layer straw ud readoutPos strawLength propTime\n" "# 0-1 0-3 0-223 1-3 mm mm ns/mm\n"; } void HStsCalGeomPar::write(std::fstream &fout) { Text_t buf[255]; Float_t data[DATA_NUM]; for (Int_t i = 0; i < getSize(); i++) { HStsCalGeomParMod &mod = (*this)[i]; for (Int_t j = 0; j < mod.getSize(); j++) { HStsCalGeomParSec §or = mod[j]; for (Int_t k = 0; k < sector.getSize(); k++) { HStsCalGeomParCell &cell = sector[k]; for (Int_t l = 0; l < cell.getSize(); l++) { HStsCalGeomParCellKind &kind = cell[l]; kind.getData(data); if (data[0] == default_time_offset_as_disabled) continue; sprintf(buf, "%4i %4i %4i %4i %10.5f %10.5f %10.5f", i, j, k, l, data[0], data[1], data[2]); fout << buf <