CbmRoot
Loading...
Searching...
No Matches
CbmStsParSetModule.cxx
Go to the documentation of this file.
1/* Copyright (C) 2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer] */
4
10
11#include "CbmStsParModule.h" // for CbmStsParModule
12
13#include <Logger.h> // for LOG, Logger
14
15#include <cassert> // for assert
16#include <fstream> // for reading parameters from ASCII file
17#include <sstream> // for operator<<, basic_ostream, stringstream
18#include <string> // for char_traits
19
20
22
23 // ----- Constructor ----------------------------------------------------
24 CbmStsParSetModule::CbmStsParSetModule(const char* name, const char* title, const char* context)
25 : FairParGenericSet(name, title, context)
26{
27}
28// --------------------------------------------------------------------------
29
30
31// ----- Destructor -----------------------------------------------------
33// --------------------------------------------------------------------------
34
35
36// ----- Reset ----------------------------------------------------------
38{
39 fUseGlobal = kFALSE;
40 fParams.clear();
41 status = kFALSE;
42 resetInputVersions();
43}
44// --------------------------------------------------------------------------
45
46
47// ----- Randomly deactivate channels -----------------------------------
49{
50 if (fraction <= 0.) return 0;
51 UInt_t nDeactivated = 0;
52 for (auto& entry : fParams) {
53 nDeactivated += entry.second.DeactivateRandomChannels(fraction);
54 }
55 return nDeactivated;
56}
57// --------------------------------------------------------------------------
58
59
60// ----- Read parameters from ASCII file --------------------------------
62{
63 LOG(fatal) << GetName() << ": ASCII input is not defined!";
64 return kFALSE;
65}
66// --------------------------------------------------------------------------
67
68// ----- Read parameters from ASCII file --------------------------------
70{
71 std::ifstream input(file_name);
72 if (!input.is_open()) {
73 LOG(error) << Form("[STS Charge Calibration] Error opening file: %s", file_name.c_str());
74 ;
75 return kFALSE;
76 }
77
78 LOG(info) << Form("[STS Charge Calibration] Loading configuration from file: %s", file_name.c_str());
79
80 int32_t address, side, asic_idx, nb_channels, nb_adc;
81 double dyn_range, threshold, time_res, dead_time, noise, znr;
82
83 // Default ASIC values
84 std::unique_ptr<CbmStsParAsic> default_asic =
85 std::make_unique<CbmStsParAsic>(128, 31, 75000., 3000., 5., 800., 1000., 3.9789e-3);
86
87 // Default module configuration
88 std::unique_ptr<CbmStsParModule> default_module = std::make_unique<CbmStsParModule>(2048, 128);
89 default_module->SetAllAsics(*default_asic);
90
91 std::string line;
92 while (std::getline(input, line)) {
93
94 // Skip commented lines
95 if (line[0] == '#') {
96 continue;
97 }
98 std::istringstream str_stream(line);
99 str_stream >> std::hex >> address >> std::dec >> side >> asic_idx >> nb_channels >> nb_adc >> dyn_range >> threshold
100 >> time_res >> dead_time >> noise >> znr;
101
102 if (address == -1) {
103 LOG(info) << "[STS Charge Calibration] Using same configuration for all modules";
104 SetGlobalPar(*default_module);
105 break;
106 }
107
108 // Initialize map entry with default configuration
109 if (!fParams.count(address)) {
110 fParams[address] = *default_module;
111 }
112
113 // Custom ASIC loaded from file
114 std::unique_ptr<CbmStsParAsic> custom_asic =
115 std::make_unique<CbmStsParAsic>(nb_channels, nb_adc, dyn_range, threshold, time_res, dead_time, noise, znr);
116
117 if (asic_idx == -1) { // Same configuration for all ASIC in the given side
118 if (side == -1) { // Same configuration for both sides
119 LOG(info) << Form("[STS Charge Calibration] Using same configuration for all ASICs in module 0x%x", address);
120 fParams[address].SetAllAsics(*custom_asic);
121 }
122 else {
123 // Configure ASIC all for given side
124 LOG(info) << Form("[STS Charge Calibration] Using same configuration for all ASICs in module 0x%x, side %u",
125 address, side);
126 for (int idx = 0; idx < 8; idx++) {
127 fParams[address].SetAsic(idx + 8 * side, *custom_asic);
128 }
129 }
130 }
131 else {
132 if (side == -1) {
133 fParams[address].SetAsic(asic_idx, *custom_asic);
134 fParams[address].SetAsic(asic_idx + 8, *custom_asic);
135 }
136 else {
137 fParams[address].SetAsic(asic_idx + 8 * side, *custom_asic);
138 }
139 }
140 }
141
142
143 return kTRUE;
144}
145// --------------------------------------------------------------------------
146
147// ----- Get condition parameters of a module ---------------------------
149{
150 if (fUseGlobal) return fGlobalParams;
151 assert(fParams.count(address));
152 return fParams[address];
153}
154// --------------------------------------------------------------------------
155
156
157// ----- Write parameters from ASCII file -------------------------------
158void CbmStsParSetModule::putParams(FairParamList*) { LOG(fatal) << GetName() << ": ASCII output is not defined!"; }
159// --------------------------------------------------------------------------
160
161
162// ----- Set module parameters ------------------------------------------
163void CbmStsParSetModule::SetParModule(UInt_t address, const CbmStsParModule& par)
164{
165 if (fParams.count(address)) LOG(fatal) << GetName() << ": Replacing parameters for sensor address " << address;
166 fParams[address] = par;
167}
168// --------------------------------------------------------------------------
169
170
171// ----- Info to string ------------------------------------------------
173{
174 std::stringstream ss;
175 if (fUseGlobal) ss << "(Global) " << fGlobalParams.ToString();
176 else {
177 if (fParams.empty()) ss << "Empty";
178 else
179 ss << "Parameters for " << fParams.size() << " sensors";
180 }
181 return ss.str();
182}
183// -------------------------------------------------------------------------
ClassImp(CbmStsParSetModule) CbmStsParSetModule
bool Bool_t
Parameters for one STS module.
Parameters container for CbmStsParModule.
virtual void putParams(FairParamList *parList)
virtual Bool_t getParams(FairParamList *parList)
Reading parameters from ASCII. Abstract in base class.
void SetGlobalPar(const CbmStsParModule &params)
Set global parameters (for all modules)
CbmStsParModule fGlobalParams
Global parameters, used for all modules.
std::map< UInt_t, CbmStsParModule > fParams
Map of parameters. Key is module address.
Bool_t fUseGlobal
Flag for using global parameters.
CbmStsParSetModule(const char *name="CbmParSetModule", const char *title="STS parameters", const char *context="Default")
Constructor.
const CbmStsParModule & GetParModule(UInt_t address)
Get condition parameters of a sensor.
Bool_t LoadParASCII(std::string file_name)
Reading parameters from ASCII.
virtual void clear()
Reset all parameters.
void SetParModule(UInt_t address, const CbmStsParModule &par)
Set the parameters for a module.
UInt_t DeactivateRandomChannels(Double_t fraction)
Randomly deactivate a fraction of the channels.
std::string ToString() const
Info to string.
virtual ~CbmStsParSetModule()
Destructor.