59 unsigned int event_bcid = thisEvent->bcid();
65 ATH_CHECK(outputContainerHdl.
record(std::make_unique<LArRawSCContainer>()));
66 auto *outputContainer = outputContainerHdl.
ptr();
68 outputContainer->reserve(inputContainer->size());
70 dataItemsPool.
reserve(inputContainer->size());
75 if (!Peds)
return StatusCode::FAILURE;
79 if (!OFCs)
return StatusCode::FAILURE;
83 if (!Ramps)
return StatusCode::FAILURE;
87 if (!DAC2uAs)
return StatusCode::FAILURE;
91 if (!uA2MeVs)
return StatusCode::FAILURE;
95 if (!MphysOverMcals)
return StatusCode::FAILURE;
99 if (!HVScaleCorrs)
return StatusCode::FAILURE;
106 for (
const LArDigit* digit : *inputContainer) {
111 return StatusCode::FAILURE;
113 const std::vector<uint16_t>& bcids = digitSC->
BCId();
115 std::flush(std::cout);
116 const std::vector<short>& samples=digit->samples();
117 int gain=digit->gain();
122 float dac2ua=DAC2uAs->
DAC2UA(
id);
123 float ua2mev=uA2MeVs->
UA2MEV(
id);
129 ATH_MSG_ERROR(
"No valid pedestal for connected channel " <<
id.get_identifier32().get_compact() <<
" gain " << gain);
130 return StatusCode::FAILURE;
133 ATH_MSG_ERROR(
"No valid ofca for connected channel " <<
id.get_identifier32().get_compact() <<
" gain " << gain);
134 return StatusCode::FAILURE;
137 ATH_MSG_ERROR(
"No valid ofcb for connected channel " <<
id.get_identifier32().get_compact() <<
" gain " << gain);
138 return StatusCode::FAILURE;
141 ATH_MSG_ERROR(
"No valid ramp for connected channel " <<
id.get_identifier32().get_compact() <<
" gain " << gain);
142 return StatusCode::FAILURE;
145 ATH_MSG_ERROR(
"wrong ramp size for connected channel " <<
id.get_identifier32().get_compact() <<
" gain " << gain);
146 return StatusCode::FAILURE;
149 ATH_MSG_ERROR(
"No valid dac2ua for connected channel " <<
id.get_identifier32().get_compact());
150 return StatusCode::FAILURE;
153 ATH_MSG_ERROR(
"No valid ua2mev for connected channel " <<
id.get_identifier32().get_compact());
154 return StatusCode::FAILURE;
157 ATH_MSG_ERROR(
"No valid mphys for connected channel " <<
id.get_identifier32().get_compact() <<
" gain " << gain);
158 return StatusCode::FAILURE;
161 ATH_MSG_ERROR(
"No valid hvcorr for connected channel " <<
id.get_identifier32().get_compact());
162 return StatusCode::FAILURE;
166 std::vector<float> ofca_mev(ofca.size());
167 std::vector<float> ofcb_mev(ofca.size());
170 for (
unsigned int i = 0; i < ofca.size(); ++i) {
171 ofca_mev[i] = ofca[i] * ramp[1] * dac2ua * ua2mev / ELSB;
172 ofcb_mev[i] = ofcb[i] * ramp[1] * dac2ua * ua2mev / ELSB;
174 ofca_mev[i] /= mphys;
175 ofcb_mev[i] /= mphys;
178 ofca_mev[i] *= hvcorr;
179 ofcb_mev[i] *= hvcorr;
183 float suma=0;
for(
auto a:ofca)suma+=
a;
184 float sumb=0;
for(
auto b:ofcb)sumb+=b;
185 peda=ped-ramp[0]/ramp[1]*suma;
186 pedb=ped-ramp[0]/ramp[1]*sumb;
189 bool aoverflow=
false;
190 bool boverflow=
false;
191 bool pedoverflow=
false;
193 std::vector<int> ofca_int(ofca.size(),0);
194 std::vector<int> ofcb_int(ofca.size(),0);
198 const int pedHardpoint = 3;
199 const int firLSBdropped = 8;
200 const int satLSBdropped = 6;
201 const int paramBitSize = 18;
203 for (
unsigned int i = 0; i < ofca.size(); ++i) {
204 if (!
floatToInt(ofca_mev[i], ofca_int[i], firLSBdropped - pedHardpoint,
208 if (!
floatToInt(ofcb_mev[i], ofcb_int[i], satLSBdropped - pedHardpoint,
213 if(!
floatToInt(peda,peda_int,pedHardpoint,paramBitSize))pedoverflow=
true;
214 if(!
floatToInt(pedb,pedb_int,pedHardpoint,paramBitSize))pedoverflow=
true;
216 unsigned int nsamples = samples.size();
217 unsigned int firsamples=4;
219 for(
unsigned int is=0; is<nsamples; ++is){
220 if(bcids[is]==event_bcid) startSample=is;
222 int maxNenergies = 0;
224 ATH_MSG_WARNING(
"could not find correct BCID for recomputing the energies, event BCID="<<event_bcid<<
" first sample BCID " << (nsamples?bcids[0]:-1));
227 maxNenergies=nsamples-firsamples-startSample+1;
235 if((
int)nEnergies>maxNenergies){
236 ATH_MSG_WARNING(
"requested nEnergies > maxNenergies " <<
m_nEnergies <<
">" <<maxNenergies<<
". setting nEnegries to maxNenergies");
237 nEnergies=maxNenergies;
240 std::vector<unsigned short> newBCIDs(nEnergies,0);
241 std::vector<int> newEnergies(nEnergies,0);
242 std::vector<int> tauEnergies(nEnergies,0);
243 std::vector<bool> passSelections(nEnergies,
false);
244 std::vector<bool> satur(nEnergies,
false);
245 const unsigned int nMaxBitsEnergy=18;
246 const unsigned int nMaxBitsEnergyTau=22;
248 for(
unsigned int ss=0;
ss<nEnergies; ++
ss){
251 int64_t computedEtau=0;
252 unsigned short bcid = bcids[startSample+
ss];
254 for(
unsigned int is=0; is<firsamples; ++is){
255 int sample = samples[startSample +
ss + is];
257 sample *= std::pow(2, pedHardpoint);
258 computedE +=
static_cast<int64_t
>(sample - peda_int) * ofca_int[is];
259 computedEtau +=
static_cast<int64_t
>(sample - pedb_int) * ofcb_int[is];
261 computedE=computedE>>firLSBdropped;
262 computedEtau=computedEtau>>satLSBdropped;
264 if(std::abs(computedE)>std::pow(2,nMaxBitsEnergy-1)){
266 computedE = std::pow(2, nMaxBitsEnergy - 1) - 1;
270 if (std::abs(computedEtau) > std::pow(2, nMaxBitsEnergyTau - 1)) {
271 if (computedEtau >= 0)
272 computedEtau = std::pow(2, nMaxBitsEnergyTau - 1) - 1;
274 computedEtau = -std::pow(2, nMaxBitsEnergyTau - 1) + 1;
276 newEnergies[
ss] = computedE;
277 tauEnergies[
ss] = computedEtau;
278 bool passSelection =
false;
279 if (computedE < 0 && computedE > -80) {
280 if (computedEtau > 8 * computedE && computedEtau < -8 * computedE)
281 passSelection =
true;
282 }
else if (computedE < 800) {
283 if (computedEtau > -8 * computedE && computedEtau < 8 * computedE)
284 passSelection =
true;
285 }
else if (computedE >= 800) {
286 if (computedEtau > -8 * computedE && computedEtau < 16 * computedE)
287 passSelection =
true;
289 passSelections[
ss] = passSelection;
296 scraw->
setBCIds(std::move(newBCIDs));
305 outputContainer->push_back(scraw);
310 return StatusCode::SUCCESS;