39 static constexpr int sampaMapping[10] = {0, 0, 1, 1, 2, 3, 3, 4, 4, 2};
40 static constexpr int channelOffset[10] = {0, 16, 0, 16, 0, 0, 16, 0, 16, 16};
41 const int regionIter = cruID % 2;
43 const int istreamm = ((hwChannel % 10) / 2);
44 const int partitionStream = istreamm + regionIter * 5;
45 const int sampaOnFEC = sampaMapping[partitionStream];
46 const int channel = (hwChannel % 2) + 2 * (hwChannel / 10);
47 const int channelOnSAMPA = channel + channelOffset[partitionStream];
49 return {sampaOnFEC, channelOnSAMPA};
57 const int sampaMapping[10] = {0, 0, 1, 1, 2, 3, 3, 4, 4, 2};
58 const int channelOffset[10] = {0, 16, 0, 16, 0, 0, 16, 0, 16, 16};
59 const int regionIter = cruID % 2;
61 for (std::size_t ichannel = 0; ichannel < 80; ++ichannel) {
62 const int istreamm = ((ichannel % 10) / 2);
63 const int partitionStream = istreamm + regionIter * 5;
64 const int sampaOnFEC = sampaMapping[partitionStream];
65 const int channel = (ichannel % 2) + 2 * (ichannel / 10);
66 const int channelOnSAMPA = channel + channelOffset[partitionStream];
69 printf(
"%4zu %4d %4d : %4zu %s\n", outch, sampaOnFEC, channelOnSAMPA, ichannel, (outch != ichannel) ?
"============" :
"");
81 std::unique_ptr<TFile> tFile1(TFile::Open(file1.data()));
82 std::unique_ptr<TFile> tFile2(TFile::Open(file2.data()));
85 tFile1->GetObject(objName.data(), calPad1);
86 tFile2->GetObject(objName.data(), calPad2);
88 for (
size_t iroc = 0; iroc < calPad1->getData().
size(); ++iroc) {
89 const auto& calArray1 = calPad1->getCalArray(iroc);
90 const auto& calArray2 = calPad2->getCalArray(iroc);
92 if (!(std::abs(calArray1.getSum() + calArray2.getSum()) > 0)) {
96 for (
size_t ipad = 0; ipad < calArray1.getData().
size(); ++ipad) {
97 const auto val1 = calArray1.getValue(ipad);
98 const auto val2 = calArray2.getValue(ipad);
100 if (std::abs(val2 - val1) >= 0.25) {
101 printf(
"%2zu %5zu : %.5f - %.5f = %.2f\n", iroc, ipad, val2, val1, val2 - val1);
107std::unordered_map<std::string, CalPad>
cru_calib_helpers::preparePedestalFiles(
const CalPad& pedestals,
const CalPad& noise, std::vector<float> sigmaNoiseROCType, std::vector<float> minADCROCType,
float pedestalOffset,
bool onlyFilled,
bool maskBad,
float noisyChannelThreshold,
float sigmaNoiseNoisyChannels,
float badChannelThreshold,
bool fixedSize)
111 auto expandVector = [](std::vector<float>&
vec,
const std::string
name) {
112 if (
vec.size() == 1) {
114 std::fill_n(&
vec[1], 3,
vec[0]);
115 }
else if (
vec.size() == 2) {
117 std::fill_n(&
vec[2], 2,
vec[1]);
118 }
else if (
vec.size() != 4) {
119 LOGP(fatal,
"{} definition must be either one value for all ROC types, or {{IROC, OROC}}, or {{IROC, OROC1, OROC2, OROC3}}",
name);
121 LOGP(info,
"Using {} = {{{}}}",
name, utils::elementsToString(
vec));
124 expandVector(sigmaNoiseROCType,
"sigmaNoiseROCType");
125 expandVector(minADCROCType,
"minADCROCType");
127 std::unordered_map<std::string, CalPad> pedestalsThreshold;
128 pedestalsThreshold[
"Pedestals"] =
CalPad(
"Pedestals");
129 pedestalsThreshold[
"ThresholdMap"] =
CalPad(
"ThresholdMap");
130 pedestalsThreshold[
"PedestalsPhys"] =
CalPad(
"Pedestals");
131 pedestalsThreshold[
"ThresholdMapPhys"] =
CalPad(
"ThresholdMap");
133 auto& pedestalsCRU = pedestalsThreshold[
"Pedestals"];
134 auto& thresholdCRU = pedestalsThreshold[
"ThresholdMap"];
137 for (
size_t iroc = 0; iroc < pedestals.
getData().
size(); ++iroc) {
140 const auto& rocPedestal = pedestals.
getCalArray(iroc);
143 const int padOffset =
roc.isOROC() ? mapper.getPadsInIROC() : 0;
144 const auto& traceLengths =
roc.isIROC() ? mapper.getTraceLengthsIROC() : mapper.getTraceLengthsOROC();
147 if (!(std::abs(rocPedestal.getSum() + rocNoise.getSum()) > 0)) {
152 for (
size_t ipad = 0; ipad < rocPedestal.getData().
size(); ++ipad) {
153 const int globalPad = ipad + padOffset;
154 const FECInfo& fecInfo = mapper.fecInfo(globalPad);
155 const CRU cru = mapper.getCRU(
roc.getSector(), globalPad);
156 const uint32_t region = cru.
region();
157 const int cruID = cru.
number();
164 const int fecOffset = (nFECs + 1) / 2;
168 const int rocType =
roc.isIROC() ? 0 : cru.
partition() - 1;
169 const float sigmaNoise = sigmaNoiseROCType[rocType];
170 const float minADC = minADCROCType[rocType];
172 const auto traceLength = traceLengths[ipad];
174 float pedestal = rocPedestal.getValue(ipad);
175 if ((pedestal > 0) && (pedestalOffset > pedestal)) {
176 LOGP(warning,
"ROC: {:2}, pad: {:3} -- pedestal offset {:.2f} larger than the pedestal value {:.2f}. Pedestal and noise will be set to 0", iroc, ipad, pedestalOffset, pedestal);
178 pedestal -= pedestalOffset;
181 float noise = std::abs(rocNoise.getValue(ipad));
182 float noiseCorr = noise - (0.847601 + 0.031514 * traceLength);
183 if ((pedestal <= 0) || (pedestal > 150) || (noise <= 0) || (noise > 50)) {
184 LOGP(info,
"Bad pedestal or noise value in ROC {:2}, CRU {:3}, fec in CRU: {:2}, SAMPA: {}, channel: {:2}, pedestal: {:.4f}, noise {:.4f}", iroc, cruID, fecInPartition, sampa, sampaChannel, pedestal, noise);
188 LOGP(info,
", they will be masked using pedestal value {:.0f} and noise {:.0f}", pedestal, noise);
190 LOGP(info,
", setting both to 0");
195 float threshold = (noise > 0) ? std::max(sigmaNoise * noise, minADC) : 0;
196 threshold = std::min(threshold, 1023.f);
197 float thresholdHighNoise = (noiseCorr > noisyChannelThreshold) ? std::max(sigmaNoiseNoisyChannels * noise, minADC) : threshold;
198 thresholdHighNoise = std::min(thresholdHighNoise, 1023.f);
200 float pedestalHighNoise = pedestal;
201 if (noiseCorr > badChannelThreshold) {
202 pedestalHighNoise = 1023;
203 thresholdHighNoise = 1023;
206 const int hwChannel =
getHWChannel(sampa, sampaChannel, region % 2);
220 pedestalsThreshold[
"Pedestals"].getCalArray(iroc).setValue(ipad, pedestal);
221 pedestalsThreshold[
"ThresholdMap"].getCalArray(iroc).setValue(ipad, threshold);
222 pedestalsThreshold[
"PedestalsPhys"].getCalArray(iroc).setValue(ipad, pedestalHighNoise);
223 pedestalsThreshold[
"ThresholdMapPhys"].getCalArray(iroc).setValue(ipad, thresholdHighNoise);
231 return pedestalsThreshold;
std::unordered_map< std::string, CalPad > preparePedestalFiles(const CalPad &pedestals, const CalPad &noise, std::vector< float > sigmaNoiseROCType={3, 3, 3, 3}, std::vector< float > minADCROCType={2, 2, 2, 2}, float pedestalOffset=0, bool onlyFilled=false, bool maskBad=true, float noisyChannelThreshold=1.5, float sigmaNoiseNoisyChannels=4, float badChannelThreshold=6, bool fixedSize=false)