36 namespace po = boost::program_options;
38 TString dir = getenv(
"VMCWORKDIR");
39 TString path = dir +
"/input/";
43 std::vector<std::string> configuration;
46 po::options_description desc(
"Options");
47 desc.add_options()(
"VERSION.id", po::value<float>(&version),
48 "version identificator")(
"COMMENT.str", po::value<std::string>(&comment),
"comment")(
49 "CONFIGURATION.config", po::value<std::vector<std::string>>(&configuration)->multitoken(),
"configuration");
53 std::ifstream config_file((path + mappingFile).Data(), std::ifstream::in);
54 if (!config_file.is_open()) {
55 LOG(error) << Form(
"BmnNdetRaw2Digit : Loading Config from file: %s - file open error!", mappingFile.Data());
58 LOG(debug) << Form(
"BmnNdetRaw2Digit : Loading Config from file: %s", mappingFile.Data());
59 po::store(po::parse_config_file(config_file, desc), vm);
63 std::string board_serial;
65 int det_id, layer_id, row_id, column_id;
67 fuoChannelMap.clear();
68 for (
auto it : configuration) {
70 ss >> board_serial >> board_channel >> det_id >> layer_id >> row_id >> column_id;
71 LOGF(debug,
"config = %s %d %d %d %d %d", board_serial.c_str(), board_channel, 0, layer_id,
73 assert(board_channel < 16);
75 auto key = std::make_pair(std::stoul(board_serial,
nullptr, 16), board_channel);
83 namespace po = boost::program_options;
85 TString dir = getenv(
"VMCWORKDIR");
86 TString path = dir +
"/parameters/ndet/";
90 std::vector<std::string> harmonics;
91 std::vector<std::string> calibrations;
94 po::options_description desc(
"Options");
95 desc.add_options()(
"VERSION.id", po::value<float>(&version),
96 "version identificator")(
"COMMENT.str", po::value<std::string>(&comment),
"comment")(
98 "writing waveforms")(
"PARAMETERS.gateBegin", po::value<int>(&
fdigiPars.
gateBegin),
"digi parameters")(
100 "digi parameters")(
"PARAMETERS.threshold", po::value<float>(&
fdigiPars.
threshold),
"digi parameters")(
102 "digi parameters")(
"PARAMETERS.doInvert", po::value<bool>(&
fdigiPars.
doInvert),
"digi parameters")(
103 "PARAMETERS.applyINLcorr", po::value<bool>(&fApplyINL),
104 "digi parameters")(
"PARAMETERS.applyAmplCalib", po::value<bool>(&fApplyAmplCalib),
"digi parameters")(
105 "PARAMETERS.applyTimeCalib", po::value<bool>(&fApplyTimeCalib),
106 "digi parameters")(
"FITPARAMETERS.isfit", po::value<bool>(&
fdigiPars.
isfit),
"digi parameters")(
107 "FITPARAMETERS.harmonic", po::value<std::vector<std::string>>(&harmonics)->multitoken(),
"fit harmonics")(
108 "CALIBRATION.calib", po::value<std::vector<std::string>>(&calibrations)->multitoken(),
"calibrations");
111 po::variables_map vm;
112 std::ifstream calib_file((path + calibrationFile).Data(), std::ifstream::in);
113 if (!calib_file.is_open()) {
114 LOG(error) << Form(
"BmnNdetRaw2Digit : Loading Calibration from file: %s - file open error!",
115 calibrationFile.Data());
118 LOG(debug) << Form(
"BmnNdetRaw2Digit : Loading Calibration from file: %s", calibrationFile.Data());
119 po::store(po::parse_config_file(calib_file, desc), vm);
123 for (
auto str : harmonics) {
124 if (str.find(
',') != std::string::npos) {
126 std::string real_part_str, imaginary_part_str;
127 std::istringstream iss(str);
128 std::getline(iss, real_part_str,
',');
129 std::getline(iss, imaginary_part_str);
132 float real_part = std::stof(real_part_str);
133 float imaginary_part = std::stof(imaginary_part_str);
141 int det_id, layer_id, row_id, column_id;
147 float calibTimeShift;
149 fuoCalibSlewShiftMap.clear();
150 for (
auto it : calibrations) {
151 istringstream ss(it);
152 ss >> det_id >> layer_id >> row_id >> column_id >> calibration >> calibError >> calibSlewP1 >> calibSlewP2
153 >> calibSlewP3 >> calibTimeShift;
156 fuoCalibMap[address] = std::make_pair(calibration, calibError);
157 std::vector<float> time_calib_vect{calibSlewP1, calibSlewP2, calibSlewP3, calibTimeShift};
158 fuoCalibSlewShiftMap[address] = time_calib_vect;
164 auto maxElement = std::max_element(
166 [](
const std::complex<float>& a,
const std::complex<float>& b) { return std::abs(a) < std::abs(b); });
169 int maxElementLength = floor(5. / (-
log(real(*maxElement))));
174 fAZik =
new std::complex<float>*[model_order];
175 for (
int i = 0;
i < model_order;
i++) {
176 fAZik[
i] =
new std::complex<float>[model_order];
177 for (
int j = 0; j < model_order; j++)
193 TString dir = getenv(
"VMCWORKDIR");
194 TString path = dir +
"/parameters/ndet/INLcorrections/";
195 LOG(info) << Form(
"BmnNdetRaw2Digit : Loading INL corrections from directory: %s", path.Data());
197 boost::property_tree::ptree pt;
198 TString header =
"TQDC16VS_E";
199 TString postfix =
"inl_corr";
202 for (
auto& it : fuoChannelMap) {
203 auto boardSerial = (
unsigned int)it.first.first;
204 TString corrFileName = Form(
"%s%s-%04X-%04X.ini", path.Data(), header.Data(),
205 ((boardSerial & 0xffff0000) >> 16), (boardSerial & 0xffff));
206 boost::property_tree::ini_parser::read_ini(corrFileName.Data(), pt);
207 TString thisHeader = Form(
"%s-%08x-%s", header.Data(), boardSerial, postfix.Data());
209 auto correction_string = pt.get<std::string>(Form(
"%s.%d", thisHeader.Data(), chan_iter));
210 istringstream ss(correction_string);
213 std::vector<float> corrV;
214 while (std::getline(ss, token,
','))
215 corrV.push_back(stof(token));
216 assert(corrV.size() == 1024);
218 auto key = std::make_pair(boardSerial, chan_iter);
219 fINLcorrMap[key] = corrV;
267 unordered_map<UInt_t, Long64_t>* mapTS,
268 TClonesArray* Ndetdigit)
271 LOG(debug) <<
"BmnNdetRaw2Digit::fillEvent";
274 for (Int_t iTdc = 0; iTdc < tdc->GetEntriesFast(); iTdc++) {
278 if (!catch_address.has_value())
280 auto address = catch_address.value();
285 if (!catch_calib.has_value())
287 auto calib_pair = catch_calib.value();
289 UInt_t ttvxs_ndet = 0x0CD9B727;
290 unordered_map<UInt_t, Long64_t>::iterator itTS = mapTS->find(ttvxs_ndet);
291 if (itTS == mapTS->end()) {
294 double TimeShift = itTS->second;
296 time *= 0.024 / 1.024;
303 LOG(debug) <<
"BmnNdetRaw2Digit::Switch to adc digit" << endl;
304 for (
int iAdc = 0; iAdc < adc->GetEntriesFast(); iAdc++) {
315 LOG(debug) <<
"BmnNdetRaw2Digit::ProcessWfm Calibration" << endl;
316 if (fApplyAmplCalib ==
true) {
327 if (fApplyTimeCalib ==
true) {
330 - ((calib_slew_shift.at(0)) /
sqrt(ThisDigi.
GetSignal() + calib_slew_shift.at(1))
331 + calib_slew_shift.at(2))
332 - calib_slew_shift.at(3);
342 TClonesArray& ar_Ndet = *Ndetdigit;
343 new (ar_Ndet[Ndetdigit->GetEntriesFast()])
BmnNdetDigi(ThisDigi);