File indexing completed on 2025-10-16 08:23:43
0001 R__LOAD_LIBRARY(libmicromegas.so)
0002
0003 #include <micromegas/MicromegasCalibrationData.h>
0004
0005 #include <micromegas/MicromegasCalibrationData.h>
0006 #include <micromegas/MicromegasMapping.h>
0007
0008 #include <nlohmann/json.hpp>
0009
0010 void ConvertTpotCalibrationToJSon( int runnumber = 74871 )
0011 {
0012
0013 const auto inputfile = Form("TPOT_Pedestal-%08i-0000.root", runnumber );
0014 const auto outputfile = Form("TPOT_Pedestal-%08i-0000.json", runnumber );
0015
0016 std::cout << "EvaluateCalibration - inputfile: " << inputfile << std::endl;
0017 std::cout << "EvaluateCalibration - outputfile: " << outputfile << std::endl;
0018
0019 MicromegasCalibrationData m_calibration_data;
0020 m_calibration_data.read(inputfile);
0021
0022 const MicromegasMapping m_mapping;
0023
0024 static const int nsigma = 5;
0025 static const bool use_maximum = true;
0026
0027 nlohmann::json calib_list;
0028
0029
0030 for( const auto& fee_id:m_mapping.get_fee_id_list() )
0031 {
0032 double mean_pedestal = 0;
0033 double mean_rms = 0;
0034
0035 double max_pedestal = 0;
0036 double max_rms = 0;
0037
0038 int entries = 0;
0039
0040 for( int ich = 0; ich < MicromegasDefs::m_nchannels_fee; ++ich )
0041 {
0042 const auto pedestal = m_calibration_data.get_pedestal( fee_id, ich );
0043 const auto rms = m_calibration_data.get_rms( fee_id, ich );
0044
0045 if(!pedestal || pedestal<20) continue;
0046 if(!rms) continue;
0047
0048
0049 if( fee_id == 8 && ich > 128 ) continue;
0050
0051 max_pedestal = std::max<double>(max_pedestal,pedestal);
0052 max_rms = std::max<double>(max_rms,rms);
0053
0054 mean_pedestal += pedestal;
0055 mean_rms += rms;
0056 ++entries;
0057 }
0058
0059 mean_pedestal/=entries;
0060 mean_rms/=entries;
0061
0062 const double mean_threshold = mean_pedestal+nsigma*mean_rms;
0063 std::cout
0064 << "feid: " << fee_id
0065 << " pedestal: " << mean_pedestal
0066 << " rms: " << mean_rms
0067 << " threshold: " << mean_threshold
0068 << " value: " << int( 4.*mean_threshold )
0069 << std::endl;
0070
0071 const double max_threshold = max_pedestal+nsigma*max_rms;
0072 std::cout
0073 << "feid: " << fee_id
0074 << " pedestal: " << max_pedestal
0075 << " rms: " << max_rms
0076 << " threshold: " << max_threshold
0077 << " value: " << int( 4.*max_threshold )
0078 << std::endl;
0079
0080
0081 const int fee_id_new = (fee_id == 11) ? 21:fee_id;
0082 nlohmann::json calibration = {
0083 {"fee_id", fee_id_new },
0084 {"threshold", int(4*std::round( use_maximum ? max_threshold:mean_threshold ))}
0085 };
0086
0087 calib_list.emplace_back(calibration);
0088 }
0089
0090 std::ofstream out( outputfile );
0091 out << std::setw(2) << calib_list << std::endl;
0092 }