17#include "CLHEP/Random/RandGaussZiggurat.h"
30#include "CLHEP/Random/RandomEngine.h"
32#include <CLHEP/Random/Randomize.h>
37using CLHEP::RandGaussZiggurat;
52 ATH_MSG_FATAL(
"Adding noise to hard-scatter Hits is not supported for Data Overlay! Fix your configuration. Bailing out.");
53 return StatusCode::FAILURE;
56 ATH_MSG_FATAL(
"MC overlay. Need to switch back on noise only to emulate extra noise for cells with different gains! Fix your configuration. Bailing out.");
57 return StatusCode::FAILURE;
60 ATH_MSG_FATAL(
"If RndmEvtOverlay==True then PileUp must also be True. Fix your configuration. Bailing out.");
61 return StatusCode::FAILURE;
64 ATH_MSG_FATAL(
"If PileUp==False then OnlyUserContainerName must also be False. Fix your configuration. Bailing out.");
65 return StatusCode::FAILURE;
71 ATH_MSG_INFO(
" pileup and/or noise added by overlaying digits of random events");
90 ATH_MSG_INFO(
" Electronic noise will be added in each cell ");
104 ATH_MSG_INFO(
" Cross-talk in EM barrel will be taken into account : ");
143 StatusCode
sc = detStore()->retrieve(caloIdMgr);
144 if (
sc.isFailure()) {
145 ATH_MSG_ERROR(
" Unable to retrieve CaloIdManager from DetectoreStore");
146 return StatusCode::FAILURE;
153 if (
sc.isFailure()) {
154 ATH_MSG_ERROR(
" Unable to retrieve LArOnlineId from DetectoreStore");
155 return StatusCode::FAILURE;
171 return StatusCode::SUCCESS;
179 m_data.m_energySum.clear();
180 m_data.m_energySum_DigiHSTruth.clear();
182 m_data.m_hitmap_DigiHSTruth=
nullptr;
187 auto* cabling=*cablingHdl;
190 return StatusCode::FAILURE;
196 ATH_CHECK(hitmap.record(std::move(hitMapPtr)));
197 m_data.m_hitmap=hitmap.ptr();
198 ATH_MSG_DEBUG(
" Number of created cells in Map " << hitmap->GetNbCells());
205 ATH_CHECK(hitmap_DigiHSTruth.record(std::move(hitMapPtr)));
206 m_data.m_hitmap_DigiHSTruth=hitmap_DigiHSTruth.ptr();
213 m_data.m_trigtime = cosTimeHdl->time();
229 if ( evtStore()->retrieve(mcCollptr).isFailure() ) {
230 ATH_MSG_WARNING (
"LArHitEMap:cannot retrieve McEventCollection (keyless)");
239 return StatusCode::SUCCESS;
248 float tbunch = (float)(bunchXing);
249 const EventContext& ctx = Gaudi::Hive::currentContext();
251 m_data.m_weights = *weightHdl;
254 while (iEvt != eSubEvents) {
263 return StatusCode::FAILURE;
271 for (
const LArDigit* digit : *rndm_digit_container) {
272 if (
m_data.m_hitmap->AddDigit(digit))
275 ATH_MSG_INFO(
" Number of digits stored for RndmEvt Overlay " << ndigit);
285 return StatusCode::FAILURE;
289 return StatusCode::SUCCESS;
306 return StatusCode::FAILURE;
317 ATH_MSG_DEBUG(
" Number of created cells in Map " << hitmap->GetNbCells());
327 if (!
m_useMBTime)
data.m_energySum_DigiHSTruth.assign(hitmap_DigiHSTruth->GetNbCells(),0.);
328 data.m_hitmap_DigiHSTruth=hitmap_DigiHSTruth.
ptr();
336 data.m_trigtime = cosTimeHdl->time();
353 data.m_hitmap->BuildWindows(mcCollptr,
357 data.m_hitmap_DigiHSTruth->BuildWindows(mcCollptr,
374 for (
auto & inputHits : hitVectorHandles) {
375 if (!inputHits.isValid()) {
377 return StatusCode::FAILURE;
380 double SubEvtTimOffset(0.0);
381 double timeCurrBunch=-9999999.;
382 for (
const LArHit* hit : *inputHits) {
383 float energy = (float) (hit->energy());
386 else time = (float) (SubEvtTimOffset+ hit->time() -
data.m_trigtime);
389 if (std::fabs(SubEvtTimOffset-timeCurrBunch)>1.) {
390 if (timeCurrBunch>-9999.) {
393 return(StatusCode::FAILURE);
396 timeCurrBunch = SubEvtTimOffset;
399 if (this->
AddHit(cellId,energy,time,isSignal,
data).isFailure())
return StatusCode::FAILURE;
408 return StatusCode::FAILURE;
418 double timeCurrBunch=-9999999.;
422 TimedHitContList hitContList;
426 if (!(
m_mergeSvc->retrieveSubEvtsData(containerName
427 ,hitContList).isSuccess()) && hitContList.empty()) {
429 return StatusCode::FAILURE;
433 TimedHitContList::iterator iFirstCont(hitContList.begin());
434 TimedHitContList::iterator iEndCont(hitContList.end());
436 iEndCont = iFirstCont ;
437 ATH_MSG_DEBUG(
" random event overlay mode : only time 0 read ");
440 double SubEvtTimOffset;
441 while (iFirstCont != iEndCont) {
444 bool isSignal = ( iFirstCont == hitContList.begin());
446 SubEvtTimOffset = time_evt->
time();
450 for (
const LArHit* hit : firstCont) {
451 float energy = (float) (hit->energy());
454 else time = (float) (SubEvtTimOffset+ hit->time() -
data.m_trigtime);
458 if (std::fabs(SubEvtTimOffset-timeCurrBunch)>1.) {
459 if (timeCurrBunch>-9999.) {
462 return(StatusCode::FAILURE);
465 timeCurrBunch = SubEvtTimOffset;
468 if (this->
AddHit(cellId,energy,time,isSignal,
data).isFailure())
return StatusCode::FAILURE;
477 TimedHitContList hitContList;
481 if (!(
m_mergeSvc->retrieveSubEvtsData(containerName
482 ,hitContList).isSuccess()) && hitContList.empty()) {
484 return StatusCode::FAILURE;
488 TimedHitContList::iterator iFirstCont(hitContList.begin());
489 TimedHitContList::iterator iEndCont(hitContList.end());
491 iEndCont = iFirstCont ;
492 ATH_MSG_DEBUG(
"random event overlay mode : only time 0 read ");
495 double SubEvtTimOffset;
496 while (iFirstCont != iEndCont) {
497 bool isSignal = ( iFirstCont == hitContList.begin());
501 SubEvtTimOffset = time_evt->
time();
506 float energy = (float)( hit.energy());
509 else time = (float) (SubEvtTimOffset+ hit.time() -
data.m_trigtime);
513 if (std::fabs(SubEvtTimOffset-timeCurrBunch)>1.) {
514 if (timeCurrBunch>-9999.) {
517 return(StatusCode::FAILURE);
520 timeCurrBunch = SubEvtTimOffset;
523 if (this->
AddHit(cellId,energy,time,isSignal,
data).isFailure())
return StatusCode::FAILURE;
533 return(StatusCode::FAILURE);
545 if (!digitCollection.
isValid()) {
546 ATH_MSG_ERROR(
"Could not get LArDigitContainer container " << digitCollection.
name() <<
" from store " << digitCollection.
store());
547 return StatusCode::FAILURE;
550 ATH_MSG_DEBUG(
"LArDigitContainer found with " << digitCollection->size() <<
" digits");
553 for (
const LArDigit* digit : *digitCollection) {
554 if (hitmap->AddDigit(digit)) ndigit++;
556 ATH_MSG_DEBUG(
" Number of digits stored for RndmEvt Overlay " << ndigit);
566 TimedDigitContList digitContList;
568 digitContList).isSuccess()) || digitContList.empty())
570 ATH_MSG_ERROR(
"Cannot retrieve LArDigitContainer for random event overlay or empty Container");
572 return StatusCode::FAILURE ;
574 TimedDigitContList::iterator iTzeroDigitCont(digitContList.begin()) ;
575 double SubEvtTimOffset;
578 SubEvtTimOffset = time_evt->
time();
582 for (
const LArDigit* digit : rndm_digit_container) {
583 if (hitmap->AddDigit(digit)) ndigit++;
585 ATH_MSG_INFO(
" Number of digits stored for RndmEvt Overlay " << ndigit);
591 return StatusCode::SUCCESS;
601 for (
auto & hit_container : hitVectorHandles) {
602 if (hit_container.isValid()) {
606 float energy = (float) hit.energy();
609 else time = (float) (hit.time() -
data.m_trigtime);
610 time = time + bunchTime;
611 if (this->
AddHit(cellId,energy,time,isSignal,
data).isFailure())
return StatusCode::FAILURE;
616 ATH_MSG_WARNING(
" LAr HitFloat container not found for signal event key " << hit_container.key());
623 for (
auto & hit_container : hitVectorHandles) {
624 if (hit_container.isValid()) {
625 for (
const LArHit* hit : *hit_container)
628 float energy = (float) hit->energy();
631 else time = (float) (hit->time() -
data.m_trigtime);
632 time = time + bunchTime;
633 if (this->
AddHit(cellId,energy,time,isSignal,
data).isFailure())
return StatusCode::FAILURE;
638 ATH_MSG_WARNING(
" LAr Hit container not found for signal event key " << hit_container.key());
644 return StatusCode::SUCCESS;
656 ATH_MSG_DEBUG(
" fillMapFromHit: asking for: " << containerName);
662 if (!(
m_mergeSvc->retrieveSingleSubEvtData(containerName, hit_container, bunchTime,
664 ATH_MSG_ERROR(
" LAr Hit container not found for event key " << containerName);
665 return StatusCode::FAILURE;
671 float energy = (float) hit.energy();
674 else time = (float) (hit.time() -
data.m_trigtime);
675 time = time + bunchTime;
677 if (this->
AddHit(cellId,energy,time,isSignal,
data).isFailure())
return StatusCode::FAILURE;
684 if (!(
m_mergeSvc->retrieveSingleSubEvtData(containerName, hit_container, bunchTime,
686 ATH_MSG_ERROR(
" LAr Hit container not found for event key " << containerName);
687 return StatusCode::FAILURE;
691 for(hititer=hit_container->
begin();
692 hititer != hit_container->
end();++hititer)
695 float energy = (float) (*hititer)->energy();
698 else time = (float) ((*hititer)->time() -
data.m_trigtime);
699 time = time + bunchTime;
701 if (this->
AddHit(cellId,energy,time,isSignal,
data).isFailure())
return StatusCode::FAILURE;
706 return StatusCode::SUCCESS;
715 if (std::fabs(energy)>1e+9) {
717 return StatusCode::SUCCESS;
721 ATH_MSG_DEBUG(
" Found hit Id= "<<
m_larem_id->show_to_string(cellId)<<
" energy= " << energy <<
"(MeV) time= " << time <<
"(ns)");
729 std::vector<IdentifierHash> neighbourList;
730 std::vector<float> energyList;
735 neighbourList,energyList, *
data.m_weights);
737 for (
unsigned int icell=0;icell<neighbourList.size();icell++)
743 ATH_MSG_ERROR(
"subCalo value is invalid in LArPileUpTool::AddHit");
744 return StatusCode::FAILURE;
747 float e = energyList[icell];
750 if ( !
data.m_hitmap->AddEnergy(
index,e,time) )
752 ATH_MSG_ERROR(
" Cell " <<
m_larem_id->show_to_string(cellId) <<
" could not add the energy= " << energy <<
" (GeV)");
753 return(StatusCode::FAILURE);
756 if(!
data.m_hitmap_DigiHSTruth->AddEnergy(
index,e,time) ) {
757 ATH_MSG_ERROR(
" Cell " <<
m_larem_id->show_to_string(cellId) <<
" could not add the energy= " << energy <<
" (GeV)");
758 return(StatusCode::FAILURE);
768 if ( !
data.m_hitmap->AddEnergy(idHash,energy,time) )
770 ATH_MSG_ERROR(
" Cell " <<
m_larem_id->show_to_string(cellId) <<
" could not add the energy= " << energy <<
" (GeV)");
771 return(StatusCode::FAILURE);
774 if(!
data.m_hitmap_DigiHSTruth->AddEnergy(idHash,energy,time) ) {
775 ATH_MSG_ERROR(
" Cell " <<
m_larem_id->show_to_string(cellId) <<
" could not add the energy= " << energy <<
" (GeV)");
776 return(StatusCode::FAILURE);
782 if (idHash<
data.m_energySum.size())
data.m_energySum[idHash] += energy;
785 return StatusCode::SUCCESS;
793 std::vector<IdentifierHash>& neighbourList,
794 std::vector<float>& energyList,
797 neighbourList.clear();
800 neighbourList.reserve(8);
801 energyList.reserve(8);
804 int ibec = abs(
m_larem_id->barrel_ec(cellId));
810 std::vector<IdentifierHash> tmpList;
815 if ((ibec==1 && sampling == 1 && region == 0)
816 || (ibec==2 && sampling ==1) )
823 if ( (ibec==1 &&
eta !=447) || (ibec==2 && (
eta!=3 || region !=5)) )
831 if (tmpList.size() == 1) {
834 neighbourList.push_back(tmpList[0]);
835 energyList.push_back(e);
838 if (( (ibec==1 &&
eta !=446)
840 std::vector<IdentifierHash> tmpList2;
843 if (tmpList2.size()==1) {
846 neighbourList.push_back(tmpList2[0]);
847 energyList.push_back(e);
856 if ( (ibec==1 &&
eta >1) || (ibec==2 && (
eta !=0 || region !=0)) )
863 if (tmpList.size() == 1) {
866 neighbourList.push_back(tmpList[0]);
867 energyList.push_back(e);
870 if (( (ibec==1 &&
eta !=2)
872 std::vector<IdentifierHash> tmpList2;
875 if (tmpList2.size()==1) {
878 neighbourList.push_back(tmpList2[0]);
879 energyList.push_back(e);
891 if ((ibec==1 && sampling==1 && region==0)
892 || (ibec==2 && sampling==1) )
897 if (ibec==1) fcr = fcr*2.;
899 if (region==0) fcr=fcr/4.;
900 if (region==1) fcr=fcr/4.;
901 if (region==2) fcr=fcr*2.;
902 if (region==3) fcr=fcr*1.5;
904 if (region==5) fcr=fcr/4.;
911 for (
unsigned int ii=0;ii<tmpList.size();ii++) {
913 neighbourList.push_back(tmpList[ii]);
914 energyList.push_back(e);
920 if ((ibec==1 && sampling==2 && region==0)
921 || (ibec==2 && sampling==2) )
927 for (
unsigned int ii=0;ii<tmpList.size();ii++) {
930 neighbourList.push_back(tmpList[ii]);
937 energyList.push_back(e);
946 if ((ibec==1 && sampling==2 && region==0 ) ||
947 (ibec==2 && sampling==2 && region==1)) {
963 if ( (ibec==1 &&
eta<55) || (ibec==2 &&
eta <42) ) {
967 if (tmpList.size() == 1) {
970 neighbourList.push_back(tmpList[0]);
971 energyList.push_back(e);
976 if ( (ibec==1 &&
eta>0) || (ibec==2 &&
eta >0) ) {
980 if (tmpList.size() == 1) {
983 neighbourList.push_back(tmpList[0]);
984 energyList.push_back(e);
992 if ( (ibec==1 && sampling ==2 && region == 0 )
993 || (ibec==2 && sampling ==2 && region ==1 &&
eta > 2)
994 || (ibec==3 && sampling ==1) )
1000 }
else if(ibec==3) {
1007 if (tmpList.size() == 1) {
1010 neighbourList.push_back(tmpList[0]);
1011 energyList.push_back(e);
1017 if ( (ibec==1 && sampling == 3 && region == 0 )
1018 ||(ibec==2 && sampling ==3)
1019 ||(ibec==3 && sampling ==2) )
1025 }
else if(ibec==2) {
1028 }
else if(ibec==3) {
1035 if ((ibec==1 || ibec==2) && tmpList.size() == 2) {
1039 neighbourList.push_back(tmpList[0]);
1040 neighbourList.push_back(tmpList[1]);
1041 energyList.push_back(e);
1042 energyList.push_back(e);
1044 if (ibec==1 && tmpList.size()==1) {
1047 neighbourList.push_back(tmpList[0]);
1048 energyList.push_back(e);
1050 if (ibec==3 && tmpList.size() ==1) {
1053 neighbourList.push_back(tmpList[0]);
1054 energyList.push_back(e);
1060 neighbourList.push_back(hashId);
1061 energyList.push_back(er);
1073 for (
unsigned int i=0;i<
data.m_energySum.size();i++) {
1074 float e =
data.m_energySum[i];
1076 if (!
data.m_hitmap->AddEnergy(i,e,bunchTime))
return false;
1078 data.m_energySum[i]=0.;
1081 for (
unsigned int i=0;i<
data.m_energySum_DigiHSTruth.size();i++) {
1082 float e =
data.m_energySum_DigiHSTruth[i];
1084 if (!
data.m_hitmap_DigiHSTruth->AddEnergy(i,e,bunchTime))
return false;
1086 data.m_energySum_DigiHSTruth[i]=0.;
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
char data[hepevt_bytes_allocation_ATLAS]
interface to a tool that returns the time offset of the current trigger.
A wrapper class for event-slot-local random engines.
SeedingOptionType
Options for seeding option=0 is setSeed as in MC20 option=1 is setSeedLegacy as in MC16 option=2 is s...
void setSeedLegacy(const std::string &algName, size_t slot, uint64_t ev, uint64_t run, uint64_t offset, SeedingOptionType seeding, EventContext::ContextEvt_t evt=EventContext::INVALID_CONTEXT_EVT)
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.
boost::transform_iterator< make_const, typename CONT::const_iterator > const_iterator
const_iterator end() const
const_iterator begin() const
This class provides the client interface for accessing the detector description information common to...
This class initializes the Calo (LAr and Tile) offline identifiers.
const LArHEC_ID * getHEC_ID(void) const
const LArFCAL_ID * getFCAL_ID(void) const
const LArEM_ID * getEM_ID(void) const
DataModel_detail::const_iterator< DataVector > const_iterator
This is a "hash" representation of an Identifier.
Container class for LArDigit.
Liquid Argon digit base class.
Container for LArHitFloat.
Class to store hit energy and time in LAr cell from G4 simulation.
Class to store hit energy and time in LAr cell from G4 simulation.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
const_pointer_type cptr()
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
std::string store() const
Return the name of the store holding the object we are proxying.
const std::string & name() const
Return the StoreGate ID for the referenced object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
@ Signal
The signal event.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
std::list< value_t > type
type of the collection of timed data object
a struct encapsulating the identifier of a pile-up event
time_type time() const
bunch xing time in ns