177 {
178
180
181
182 double Rndm[16];
183
184
187
188 SG::ReadCondHandle<TileEMScale> emScale(
m_emScaleKey, ctx);
190
191 const TileBadChannels* badChannels = nullptr;
193 SG::ReadCondHandle<TileBadChannels> badChannelsHandle(
m_badChannelsKey, ctx);
194 ATH_CHECK( badChannelsHandle.isValid() );
195 badChannels = *badChannelsHandle;
196 }
197
198
199
200
201
202
203
206
208
209 ATH_CHECK( ttl1Container.record(std::make_unique<TileTTL1Container>()) );
211
212 std::unique_ptr<TileTTL1Container> mbtsTTL1Container;
214 mbtsTTL1Container = std::make_unique<TileTTL1Container>();
215 }
216
219
220
221
222
223
224 Identifier ttId[16];
225 std::vector<double> ttAmp[16];
226 std::vector<double> MBTSAmp;
227 bool ttHit[16];
228 bool MBTSHit;
229 int nTT;
230 int nHit;
231 int nIgnore;
232 int nTTTot = 0;
233 int nHitTot = 0;
234 int nIgnoreTot = 0;
235 double ttAmpTot = 0;
236 double ttAmpTotIg = 0.;
237 int minieta, maxieta, posneg;
238
239 for (int ieta = 0; ieta < 16; ++ieta)
242
243
245
246
247
248 std::vector<float> ttL1samples;
249 std::vector<float> MBTSsamples;
253
254 std::vector<double> ttl1Shape(
m_nSamples, 0.);
256
257
258
259
260 for (const TileHitCollection* hitCollection : *hitContainer) {
261
262
263 HWIdentifier drawer_id =
m_tileHWID->drawer_id(hitCollection->identify());
267
268
271 << " drawer " << drawer
272 << " is connected");
273 } else {
274 continue;
275 }
276
277
278
279 switch (ros) {
281 posneg = +1;
282 minieta = 0;
283 maxieta = 8;
284 break;
286 posneg = -1;
287 minieta = 0;
288 maxieta = 8;
289 break;
291 posneg = +1;
292 minieta = 9;
294 break;
296 posneg = -1;
297 minieta = 9;
299 break;
300 default:
301 posneg = minieta = maxieta = 0;
302 break;
303 }
304
305
306 for (int ieta = 0; ieta < 16; ++ieta) {
308 ttAmp[ieta][js] = 0.0;
309 }
311 MBTSAmp[js] = 0.0;
312
313 MBTSHit = false;
314 memset(ttHit, 0, sizeof(ttHit));
315 nTT = nIgnore = nHit = 0;
316
317
318
319
320 for (const TileHit* tile_hit : *hitCollection) {
321
322
323 Identifier pmt_id = tile_hit->pmt_ID();
324
325 HWIdentifier pmt_HWid = tile_hit->pmt_HWID();
326
328
329
330 double hit_calib = samplingFraction->getSamplingFraction(drawerIdx, channel);
331 hit_calib = std::round(hit_calib * 1000) / 1000;
332
333
334 double qfactor = hit_calib / emScale->calibrateChannel(drawerIdx, channel
338
339
340 bool is_good = true;
344
345
346 if (
status.isNoGainL1()) {
347 is_good = false;
348 qfactor = 0.0;
349 }
350
351
352 if (
status.isHalfGainL1()) {
353 is_good = false;
354 qfactor *= 0.5;
355 }
356
357 }
358
359
361
362 if (mbtsTTL1Container) {
363
364
365
367 hitSamples[js] = 0.0;
368
369 int n_hits = tile_hit->size();
370 for (int ihit = 0; ihit < n_hits; ++ihit) {
371
372
373 double t_hit = -(tile_hit->time(ihit));
375
376 double e_hit = tile_hit->energy(ihit);
378 hitSamples[
js] += e_hit * ttl1MBTSShape[
js];
379 }
380 }
381
382 if (MBTSHit) {
384 MBTSAmp[js] += qfactor * hitSamples[js];
385
386 } else {
387 MBTSHit = true;
389 MBTSAmp[js] = qfactor * hitSamples[js];
390 }
391
392 if (
msgLvl(MSG::VERBOSE)) {
393
394
399
400 msg(MSG::VERBOSE) <<
"New MBTS Hit:"
408 <<
", chan is good=" << is_good <<
endmsg;
409 }
410 }
411 continue;
412 }
413
414
415 Identifier tt_id = tile_hit->tt_ID();
416
417
418 int ieta =
m_TT_ID->eta(tt_id);
419 int iphi =
m_TT_ID->phi(tt_id);
422
423
424
426 hitSamples[js] = 0.0;
427 int n_hits = tile_hit->size();
428 for (int ihit = 0; ihit < n_hits; ++ihit) {
429
430
431 double t_hit = -(tile_hit->time(ihit));
433
434 double e_hit = tile_hit->energy(ihit);
436 hitSamples[
js] += e_hit * ttl1Shape[
js];
437 }
438 }
439
440
441 if (ttHit[ieta]) {
443 ttAmp[ieta][js] += qfactor * hitSamples[js];
444
445
446 } else {
447 ttId[ieta] = tt_id;
448 ttHit[ieta] = true;
450 ttAmp[ieta][js] = qfactor * hitSamples[js];
451
452 if (ieta >= minieta && ieta <= maxieta)
453 ++nTT;
454 }
455 ++nHit;
456 if (ieta < minieta || ieta > maxieta || !is_good)
457 ++nIgnore;
458
459
460 if (ieta >= minieta && ieta <= maxieta && is_good) {
461 ttAmpTot += hitSamples[
m_iTrig] * hit_calib;
462 } else {
463 ttAmpTotIg += hitSamples[
m_iTrig] * hit_calib;
464 }
465
466 if (
msgLvl(MSG::VERBOSE)) {
467
468
470 int tower =
m_tileID->tower(pmt_id);
474
475 msg(MSG::VERBOSE) <<
"New Hit:"
480 << ", tower=" << tower
483 <<
", e0=" << hitSamples[
m_iTrig] * hit_calib
484 << ", ie=" << ieta
485 << ", ip=" << iphi
486 << ", chan is good= " << is_good;
487
488 if (ieta >= minieta && ieta <= maxieta)
490 else
491 msg(MSG::VERBOSE) <<
" Outside limits" <<
endmsg;
492 }
493
494 }
495
496 nTTTot += nTT;
497 nHitTot += nHit;
498 nIgnoreTot += nIgnore;
499
501 << " ROS=" << ros
502 << ", drawer=" << drawer
503 << "; posneg=" << posneg
504 << ", minieta=" << minieta
505 << ", maxieta=" << maxieta
506 << "; nTT=" << nTT
507 << ", nHit=" << nHit
508 << ", nIgnore=" << nIgnore );
509
510
511
512
513
514
515
516
517
518
519 if (mbtsTTL1Container) {
520 Identifier MBTS_id =
m_cabling->drawer2MBTS_id(drawer_id);
523 if (Good) {
524 double ttL1NoiseSigma =
m_tileInfo->MBTSL1NoiseSigma(MBTS_id);
525 double ttL1Thresh =
m_tileInfo->MBTSL1Thresh(MBTS_id);
526 double ttL1Ped =
m_tileInfo->MBTSL1Ped(MBTS_id);
527 double ttL1Calib =
m_tileInfo->MBTSL1Calib(MBTS_id);
528 double ttL1Max =
m_tileInfo->MBTSL1Max(MBTS_id);
529
533 MBTSAmp[jsamp] *= ttL1Calib;
534 MBTSsamples[jsamp] = MBTSAmp[jsamp] + ttL1Ped;
536 MBTSsamples[jsamp] += ttL1NoiseSigma * Rndm[jsamp];
537
538
539
540 if (MBTSsamples[jsamp] > ttL1Max)
541 MBTSsamples[jsamp] = ttL1Max;
542
543 }
544
546 if (MBTSsamples[
m_MBTSiTrig] - ttL1Ped < ttL1Thresh)
547 Good = false;
548
549 if (Good) {
550 std::unique_ptr<TileTTL1> mbtsTTL1 = std::make_unique<TileTTL1>(MBTS_id, MBTSsamples);
551 mbtsTTL1Container->push_back(mbtsTTL1.release());
554 }
555 }
556 }
557 }
558
559 for (int ieta = minieta; ieta <= maxieta; ++ieta) {
562 if (Good) {
563 if (!ttHit[ieta])
564 ttId[ieta] =
m_TT_ID->tower_id(posneg, 1, 0, ieta, drawer);
565
566
567
568
570 double ttL1NoiseSigma =
m_tileInfo->TTL1CosmicsNoiseSigma(ttId[ieta]);
571 double ttL1Thresh =
m_tileInfo->TTL1CosmicsThresh(ttId[ieta]);
572 double ttL1Ped =
m_tileInfo->TTL1CosmicsPed(ttId[ieta]);
573 double ttL1Calib =
m_tileInfo->TTL1CosmicsCalib(ttId[ieta]);
574
575 double peakAmp = 0.0;
576 int peakSamp = 0;
577 for (
int jsamp = 0; jsamp <
m_nSamples; ++jsamp) {
578 ttAmp[ieta][jsamp] *= ttL1Calib;
579 ttAmp[ieta][jsamp] += ttL1Ped;
580 if (ttAmp[ieta][jsamp] > peakAmp) {
581 peakAmp = ttAmp[ieta][jsamp];
582 peakSamp = jsamp;
583 }
584 }
585
587 peakAmp += ttL1NoiseSigma * RandGaussQ::shoot(rngWrapper->
getEngine(ctx));
588 ttL1samples[0] = peakAmp;
590 if (ttL1samples[0] - ttL1Ped < ttL1Thresh)
591 Good = false;
592 }
593 if (
msgLvl(MSG::DEBUG) && Good) {
594 msg(MSG::DEBUG) <<
" TTL1: "
596 << ", ieta=" << ieta
597 << ", iphi=" << iphi
598 << ", hitTrue=" << ttHit[ieta]
599 << ", Good=" << Good
600 << ", peak Amp=" << ttAmp[ieta][peakSamp]
601 <<
", with noise=" << ttL1samples[0] <<
endmsg;
602 }
603
604
605 } else {
606 double ttL1NoiseSigma =
m_tileInfo->TTL1NoiseSigma(ttId[ieta]);
607 double ttL1Thresh =
m_tileInfo->TTL1Thresh(ttId[ieta]);
608 double ttL1Ped =
m_tileInfo->TTL1Ped(ttId[ieta]);
609 double ttL1Calib =
m_tileInfo->TTL1Calib(ttId[ieta]);
610 double ttL1Max =
m_tileInfo->TTL1Max(ttId[ieta]);
611
614 for (
int jsamp = 0; jsamp <
m_nSamples; ++jsamp) {
615 ttAmp[ieta][jsamp] *= ttL1Calib;
616 ttL1samples[jsamp] = ttAmp[ieta][jsamp] + ttL1Ped;
618 ttL1samples[jsamp] += ttL1NoiseSigma * Rndm[jsamp];
619
620
621
622 if (ttL1samples[jsamp] > ttL1Max)
623 ttL1samples[jsamp] = ttL1Max;
624
625 }
626
628 if (ttL1samples[
m_iTrig] - ttL1Ped < ttL1Thresh)
629 Good = false;
630 }
631 if (
msgLvl(MSG::DEBUG) && Good) {
632 msg(MSG::DEBUG) <<
" TTL1: "
634 << ", ieta=" << ieta
635 << ", iphi=" << iphi
636 << ", hitTrue=" << ttHit[ieta]
637 << ", Good=" << Good
638 <<
", amp0=" << ttAmp[ieta][
m_iTrig]
640 }
641 }
642 }
643
644
645 if (Good) {
646 std::unique_ptr<TileTTL1> ttl1 = std::make_unique<TileTTL1>(ttId[ieta], ttL1samples);
647 ttl1Container->push_back(ttl1.release());
648 }
649 }
650 }
651
652
654 ATH_MSG_DEBUG(
"Sorting container of size " << ttl1Container->size() );
655 TileLogicalOrdering<TileTTL1>
order;
656 ttl1Container->sort(order);
657 }
658
659 if (mbtsTTL1Container) {
661 ATH_CHECK( mbtsContainer.record(std::move(mbtsTTL1Container)));
662
664 }
665
666
668 msg(MSG::DEBUG) <<
"TileHitToTTL1 execution completed." <<
endmsg;
669 msg(MSG::DEBUG) <<
" nTTTot=" << nTTTot
670 << " nHitTot=" << nHitTot
671 << " nIgnoreTot=" << nIgnoreTot
672 << " ttAmpTot=" << ttAmpTot
673 << " ttAmpTotIg=" << ttAmpTotIg
674 <<
" =>eneTot=" << ttAmpTot + ttAmpTotIg <<
endmsg;
675 }
676
677 return StatusCode::SUCCESS;
678}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
bool msgLvl(const MSG::Level lvl) const
bool is_valid() const
Check if id is in a valid state.
const TileBchStatus & getAdcStatus(const HWIdentifier adc_id) const
Return Tile ADC status.
static unsigned int getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.
Gaudi::Property< bool > m_maskBadChannels
ServiceHandle< IAthRNGSvc > m_rndmSvc
Random number generator engine to use.
SG::ReadHandleKey< TileHitContainer > m_hitContainerKey
bool m_tileThresh
If true => apply threshold on the conversion to TileTTL1.
const TileID * m_tileID
Pointer to TileID helper.
SG::WriteHandleKey< TileTTL1Container > m_mbtsTTL1ContainerKey
bool m_tileNoise
If true => generate noise for the TileTTL1 creation.
const TileCablingService * m_cabling
Pointer to the TileCablingService instance.
int m_MBTSiTrig
index of the triggering time slice for MBTS TTL1
const TileInfo * m_tileInfo
Pointer to TileInfo.
SG::ReadCondHandleKey< TileEMScale > m_emScaleKey
Name of TileEMScale in condition store.
SG::WriteHandleKey< TileTTL1Container > m_ttl1ContainerKey
const TileTBID * m_tileTBID
Pointer to TileID helper.
SG::ReadCondHandleKey< TileBadChannels > m_badChannelsKey
Name of TileBadChannels in condition store.
int m_MBTSnSamples
number of time slices for each chan for MBTS TTL1
Gaudi::Property< std::string > m_randomStreamName
Random Stream Name.
const CaloLVL1_ID * m_TT_ID
Pointer to TT Identifier.
int m_lastTower
total number of towers in TileCal
int m_iTrig
index of the triggering time slice
int m_nSamples
number of time slices for each channel
const TileHWID * m_tileHWID
Pointer to TileHWID helper.
bool m_cosmicsType
if true => use dediated cosmcis TTL1
SG::ReadCondHandleKey< TileSamplingFraction > m_samplingFractionKey
Name of TileSamplingFraction in condition store.