16#include "CLHEP/Random/RandomEngine.h"
17#include "CLHEP/Random/RandFlat.h"
18#include "CLHEP/Random/RandGaussZiggurat.h"
19#include "CLHEP/Random/RandPoissonQ.h"
23#include "Identifier/Identifier.h"
34#include "CLHEP/Vector/LorentzVector.h"
39#include "GaudiKernel/ITHistSvc.h"
51 const std::string& name,
52 const IInterface* parent) :
71 declareProperty(
"SimHitCollection",
m_SimHitCollectionName,
"Name of the input ALFA Sim Hit Collection of simulated hits");
72 declareProperty(
"SimODHitCollection",
m_SimODHitCollectionName,
"Name of the input ALFA Sim OD Hit Collection of simulated hits");
74 declareProperty(
"ALFA_DigitCollection",
m_key_DigitCollection,
"Name of the Collection to hold the output from the ALFA main detector digitization");
75 declareProperty(
"ALFA_ODDigitCollection",
m_key_ODDigitCollection,
"Name of the Collection to hold the output from the ALFA OD digitization");
85 declareProperty(
"mean",
m_mean);
109 return StatusCode::SUCCESS;
124 TimedALFAHitCollList tHitCollList;
125 TimedALFAODHitCollList tODHitCollList;
130 ATH_MSG_FATAL (
"Could not fill TimedALFAHitCollList" );
return StatusCode::FAILURE;
139 ATH_MSG_FATAL (
"Could not fill TimedALFAODHitCollList" );
return StatusCode::FAILURE;
141 else {
ATH_MSG_DEBUG (
"Retrieved TimedALFAODHitCollList" ); }
148 TimedALFAHitCollList::iterator iHitColl (tHitCollList.begin());
149 TimedALFAHitCollList::iterator eHitColl (tHitCollList.end());
151 while (iHitColl != eHitColl) {
155 tALFAhit.
insert(iHitColl->first, tmpColl);
157 ATH_MSG_DEBUG (
" ALFA_HitCollection found with " << tmpColl->
size() <<
" hits " << iHitColl->first );
164 TimedALFAODHitCollList::iterator iODHitColl (tODHitCollList.begin());
165 TimedALFAODHitCollList::iterator eODHitColl (tODHitCollList.end());
167 while (iODHitColl != eODHitColl) {
171 tALFAODhit.
insert(iODHitColl->first, tmpColl);
173 ATH_MSG_DEBUG (
" ALFA_ODHitCollection found with " << tmpColl->
size() <<
" hits " << iODHitColl->first );
182 ATH_MSG_FATAL (
" ALFA_PileUpTool::processAllSubEvents(): Could not record the empty ALFA digit container in StoreGate " );
return StatusCode::FAILURE;
184 else {
ATH_MSG_DEBUG (
" ALFA_PileUpTool::processAllSubEvents(): ALFA Digit container is recorded in StoreGate " ); }
189 ATH_MSG_FATAL (
" ALFA_PileUpTool::processAllSubEvents(): Could not record the empty ALFA OD digit container in StoreGate " );
return StatusCode::FAILURE;
191 else {
ATH_MSG_DEBUG (
" ALFA_PileUpTool::processAllSubEvents(): ALFA OD Digit container is recorded in StoreGate " ); }
201 CLHEP::HepRandomEngine* rngEngine = rngWrapper->
getEngine(ctx);
203 if (
sc.isFailure()) {
205 return StatusCode::SUCCESS;
212 if (
sc.isFailure()) {
214 return StatusCode::SUCCESS;
217 return StatusCode::SUCCESS;
225 ATH_MSG_DEBUG (
"ALFA_PileUpTool::prepareEvent() called for " << nInputEvents <<
" input events" );
229 if (
sc.isFailure()) {
ATH_MSG_FATAL (
" ALFA_PileUpTool::prepareEvent(): Could not record the empty digit container in StoreGate " );
return sc; }
230 else {
ATH_MSG_DEBUG (
" ALFA_PileUpTool::prepareEvent(): Digit container is recorded in StoreGate " ); }
234 if (
sc.isFailure()) {
ATH_MSG_FATAL (
" ALFA_PileUpTool::prepareEvent(): Could not record the empty digit OD container in StoreGate " );
return sc; }
235 else {
ATH_MSG_DEBUG (
" ALFA_PileUpTool::prepareEvent(): Digit OD container is recorded in StoreGate " ); }
240 return StatusCode::SUCCESS;
247 ATH_MSG_DEBUG (
"ALFA_PileUpTool::processBunchXing() " << bunchXing );
249 for (; iEvt!=eSubEvents; ++iEvt) {
253 <<
" bunch crossing : " << bunchXing
254 <<
" time offset : " << iEvt->time()
255 <<
" event number : " << iEvt->ptr()->eventNumber()
256 <<
" run number : " << iEvt->ptr()->runNumber()
264 ATH_MSG_ERROR (
"SubEvent ALFA_HitCollection not found in StoreGate " << seStore.name() );
266 return StatusCode::FAILURE;
269 ATH_MSG_DEBUG (
"SubEvent, ALFA_HitCollection found with " << tmpHitColl->
size() <<
" hits");
280 ATH_MSG_ERROR (
"SubEvent ALFA_ODHitCollection not found in StoreGate " << seStore.name() );
282 return StatusCode::FAILURE;
285 ATH_MSG_DEBUG (
"ALFA_ODHitCollection found with " << tmpODHitColl->
size() <<
" hits" );
293 return StatusCode::SUCCESS;
307 CLHEP::HepRandomEngine* rngEngine = rngWrapper->
getEngine(ctx);
309 if (
sc.isFailure()) {
311 return StatusCode::SUCCESS;
318 if (
sc.isFailure()) {
320 return StatusCode::SUCCESS;
323 return StatusCode::SUCCESS;
361 for (
int l = 0; l < 8; l++ )
363 for (
int i = 0; i < 20; i++ )
365 for (
int j = 0; j < 64; j++ )
377 int fiber, plate,
sign, station;
384 station = (*it)->GetStationNumber();
385 plate = (*it)->GetPlateNumber();
386 fiber = (*it)->GetFiberNumber();
387 sign = (*it)->GetSignFiber();
389 ATH_MSG_DEBUG (
"station=" << station <<
", plate= "<< plate <<
", fiber=" << fiber <<
", sign=" <<
sign <<
", dep energy=" << ((*it)->GetEnergyDeposit()));
391 m_E_fib[station-1][2*(plate-1)+(1-
sign)/2][fiber-1] += ((*it)->GetEnergyDeposit());
405 for (
int l = 0; l < 8; l++ )
407 for (
int i = 0; i < 20; i++ )
409 for (
int j = 0; j < 64; j++ )
422 int fiber, plate,
sign, station;
427 for (; it != itend; ++it) {
429 station = it->GetStationNumber();
430 plate = it->GetPlateNumber();
431 fiber = it->GetFiberNumber();
432 sign = it->GetSignFiber();
434 ATH_MSG_DEBUG (
"station=" << station <<
", plate= "<< plate <<
", fiber=" << fiber <<
", sign=" <<
sign <<
", dep energy=" << it->GetEnergyDeposit());
436 m_E_fib[station-1][2*(plate-1)+(1-
sign)/2][fiber-1] += it->GetEnergyDeposit();
450 for (
int l = 0; l < 8; l++ ){
451 for (
int i = 0; i < 2; i++ ){
452 for (
int j = 0; j < 3; j++ ){
453 for (
int k = 0; k < 30; k++ ){
464 int fiber, plate,
sign, side, station;
472 station = (*it)->GetStationNumber();
473 side = (*it)->GetODSide();
474 plate = (*it)->GetPlateNumber();
475 fiber = (*it)->GetFiberNumber();
476 sign = (*it)->GetSignFiber();
479 ATH_MSG_DEBUG (
"station=" << station <<
", side=" << side <<
", plate= "<< plate <<
", fiber=" << fiber <<
", sign=" <<
sign <<
", dep energy=" << ((*it)->GetEnergyDeposit()));
481 if (
sign==0)
m_E_ODfib[station-1][side-1][plate-1][fiber+15] += ((*it)->GetEnergyDeposit());
482 else m_E_ODfib[station-1][side-1][plate-1][fiber] += ((*it)->GetEnergyDeposit());
496 for (
int l = 0; l < 8; l++ ){
497 for (
int i = 0; i < 2; i++ ){
498 for (
int j = 0; j < 3; j++ ){
499 for (
int k = 0; k < 30; k++ ){
510 int fiber, plate,
sign, side, station;
516 for (; it != itend; ++it) {
519 station = it->GetStationNumber();
520 side = it->GetODSide();
521 plate = it->GetPlateNumber();
522 fiber = it->GetFiberNumber();
523 sign = it->GetSignFiber();
526 ATH_MSG_DEBUG (
"station=" << station <<
", side=" << side <<
", plate= "<< plate <<
", fiber=" << fiber <<
", sign=" <<
sign <<
", dep energy=" << it->GetEnergyDeposit());
528 if (
sign==0)
m_E_ODfib[station-1][side-1][plate-1][fiber+15] += it->GetEnergyDeposit();
529 else m_E_ODfib[station-1][side-1][plate-1][fiber] += it->GetEnergyDeposit();
539 ATH_MSG_DEBUG(
" ALFA_PileUpTool::fill_MD_DigitCollection()");
544 double amplitude = 0.;
548 for (
int l = 0; l < 8; l++ )
550 for (
int i = 0; i < 20; i++ )
552 for (
int j = 0; j < 64; j++ )
565 amplitude = CLHEP::RandGaussZiggurat::shoot(rndEngine, N_photo, sqrt(
pow(
m_sigma0,2)+N_photo*
pow(
m_sigma1,2)));
573 ATH_MSG_DEBUG(
" ALFA_Digitization::fillDigitCollection, amplitude " << amplitude);
574 ATH_MSG_DEBUG(
" station = " << l <<
", plate= " << i <<
", fiber=" << j );
585 for (
int l = 0; l < 8; l++ )
587 for (
int i = 0; i < 20; i++ )
589 for (
int j = 0; j < 64; j++ )
593 for (
int f = j+1; f < 64; f++)
595 rand_fib = CLHEP::RandFlat::shoot(rndEngine,0.,1.);
606 for (
int f = j-1; f > -1; f--)
608 rand_fib = CLHEP::RandFlat::shoot(rndEngine,0.,1.);
622 return StatusCode::SUCCESS;
635 double amplitude = 0.;
637 for (
int l = 0; l < 8; l++ )
639 for (
int i = 0; i < 2; i++ )
641 for (
int j = 0; j < 3; j++ )
643 for (
int k = 0; k < 30; k++)
649 double noise_1 = sigma * CLHEP::RandGaussZiggurat::shoot (rndEngine,
m_mean,
m_stdDev);
660 ATH_MSG_DEBUG(
" ALFA_Digitization::fill_OD_DigitCollection, amplitude " << amplitude);
661 ATH_MSG_DEBUG(
" station = " << l <<
", side = " << i <<
", plate = " << j <<
", fiber = " << k);
672 return StatusCode::SUCCESS;
678 std::ifstream fXTalk;
679 for (
unsigned int j=0; j<8; j++){
681 const std::string fname =
"ALFA_Digitization/Xtalk_station" + std::to_string(j+1) +
".txt";
686 if(filePath.length() == 0)
688 ATH_MSG_FATAL(
" XTalk file " << fname<<
" not found in Datapath");
689 throw std::runtime_error(
"FATAL: mapping MD maroc-mapmt not found in Datapath.");
694 ATH_MSG_DEBUG(
"the XTALK file \"" << fname <<
"\" found in Datapath");
698 fXTalk.open(filePath.c_str());
700 if (fXTalk.is_open())
702 for (
unsigned int i=0;i<127;i++)
714 return StatusCode::FAILURE;
717 return StatusCode::SUCCESS;
AtlasHitsVector< ALFA_Hit >::const_iterator ALFA_HitConstIter
AtlasHitsVector< ALFA_Hit > ALFA_HitCollection
AtlasHitsVector< ALFA_ODHit > ALFA_ODHitCollection
AtlasHitsVector< ALFA_ODHit >::const_iterator ALFA_ODHitConstIter
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
std::string PathResolverFindDataFile(const std::string &logical_file_name)
constexpr int pow(int base, int exp) noexcept
A wrapper class for event-slot-local random engines.
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.
CONT::const_iterator const_iterator
const_iterator begin() const
const_iterator end() const
The Athena Transient Store API.
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
bool nextDetectorElement(const_iterator &b, const_iterator &e)
sets an iterator range with the hits of current detector element returns a bool when done
TimedVector::const_iterator const_iterator
void insert(const PileUpTimeEventIndex &timeEventIndex, const AtlasHitsVector< HIT > *inputCollection)
std::list< value_t > type
type of the collection of timed data object