@@ -80,7 +80,7 @@ class DigitTime
8080 std::vector<CommonMode>& commonModeOutput, const Sector& sector, TimeBin timeBin,
8181 SAMPAProcessing& sampaProcessing, std::vector<std::pair<MCCompLabel, int >>& labelCollector,
8282 PrevDigitInfoArray* prevTime = nullptr , Streamer* debugStream = nullptr ,
83- const CalPad* padParams[3 ] = nullptr , const CalDet<bool >* deadMap = nullptr );
83+ const CalPad* padParams[4 ] = nullptr , const CalDet<bool >* deadMap = nullptr );
8484
8585 private:
8686 std::array<float , GEMSTACKSPERSECTOR > mCommonMode ; // /< Common mode container - 4 GEM ROCs per sector
@@ -131,7 +131,7 @@ template <DigitzationMode MODE>
131131inline void DigitTime::fillOutputContainer (std::vector<Digit>& output, dataformats::MCTruthContainer<MCCompLabel>& mcTruth,
132132 std::vector<CommonMode>& commonModeOutput, const Sector& sector, TimeBin timeBin,
133133 SAMPAProcessing& sampaProcessing, std::vector<std::pair<MCCompLabel, int >>& labelCollector,
134- PrevDigitInfoArray* prevTime, Streamer* debugStream, const CalPad* padParams[3 ],
134+ PrevDigitInfoArray* prevTime, Streamer* debugStream, const CalPad* padParams[4 ],
135135 const CalDet<bool >* deadMap)
136136{
137137 const auto & mapper = Mapper::instance ();
@@ -153,23 +153,33 @@ inline void DigitTime::fillOutputContainer(std::vector<Digit>& output, dataforma
153153 mCommonMode [cru.gemStack ()] += digit.getChargePad () * eleParam.commonModeCoupling * cmKValue; // TODO: Add stack-by-stack variation?
154154 }
155155
156- // fill common mode output container
157- for (size_t i = 0 ; i < mCommonMode .size (); ++i) {
158- const float cm = getCommonMode (GEMstack (i));
159- if (cm > 0 .) {
160- commonModeOutput.push_back ({cm, timeBin, static_cast <unsigned char >(i)});
161- }
162- }
156+ // the common mode is induced on all pads of the GEM stack, but the baseline of a pad can at most drop to 0 ADC,
157+ // so the common mode seen by a pad saturates at its pedestal value
158+ const CalPad* pedestals = eleParam.doCommonModePerPadSaturation ? padParams[3 ] : nullptr ;
159+ std::array<double , GEMSTACKSPERSECTOR > commonModeSeen{}; // double: sum of ~3000 values per stack
163160
164161 for (size_t iPad = 0 ; iPad < mGlobalPads .size (); ++iPad) {
165162 auto & digit = mGlobalPads [iPad];
163+ const CRU cru = mapper.getCRU (sector, iPad);
164+ float commonMode = getCommonMode (cru);
165+ if (pedestals) {
166+ commonMode = std::min (commonMode, pedestals->getValue (sector.getSector (), iPad));
167+ commonModeSeen[cru.gemStack ()] += commonMode;
168+ }
166169 if (eleParam.doNoiseEmptyPads || (digit.getChargePad () > 0 .f )) {
167170 PrevDigitInfo prevDigit;
168171 if (prevTime) {
169172 prevDigit = (*prevTime)[iPad];
170173 }
171- const CRU cru = mapper.getCRU (sector, iPad);
172- digit.fillOutputContainer <MODE >(output, mcTruth, cru, timeBin, iPad, mLabels , sampaProcessing, labelCollector, getCommonMode (cru), prevDigit, debugStream, deadMap);
174+ digit.fillOutputContainer <MODE >(output, mcTruth, cru, timeBin, iPad, mLabels , sampaProcessing, labelCollector, commonMode, prevDigit, debugStream, deadMap);
175+ }
176+ }
177+
178+ // fill common mode output container, with saturation the average common mode seen by the pads of the GEM stack
179+ for (size_t i = 0 ; i < mCommonMode .size (); ++i) {
180+ const float cm = pedestals ? static_cast <float >(commonModeSeen[i] / mapper.getNumberOfPads (GEMstack (i))) : getCommonMode (GEMstack (i));
181+ if (cm > 0 .) {
182+ commonModeOutput.push_back ({cm, timeBin, static_cast <unsigned char >(i)});
173183 }
174184 }
175185}
0 commit comments