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 return StatusCode::SUCCESS;
549 if (!digitCollection.
isValid()) {
550 ATH_MSG_ERROR(
"Could not get LArDigitContainer container " << digitCollection.
name() <<
" from store " << digitCollection.
store());
551 return StatusCode::FAILURE;
554 ATH_MSG_DEBUG(
"LArDigitContainer found with " << digitCollection->size() <<
" digits");
557 for (
const LArDigit* digit : *digitCollection) {
558 if (hitmap->AddDigit(digit)) ndigit++;
560 ATH_MSG_DEBUG(
" Number of digits stored for RndmEvt Overlay " << ndigit);
570 TimedDigitContList digitContList;
572 digitContList).isSuccess()) || digitContList.empty())
574 ATH_MSG_ERROR(
"Cannot retrieve LArDigitContainer for random event overlay or empty Container");
576 return StatusCode::FAILURE ;
578 TimedDigitContList::iterator iTzeroDigitCont(digitContList.begin()) ;
579 double SubEvtTimOffset;
582 SubEvtTimOffset = time_evt->
time();
586 for (
const LArDigit* digit : rndm_digit_container) {
587 if (hitmap->AddDigit(digit)) ndigit++;
589 ATH_MSG_INFO(
" Number of digits stored for RndmEvt Overlay " << ndigit);
595 return StatusCode::SUCCESS;
605 for (
auto & hit_container : hitVectorHandles) {
606 if (hit_container.isValid()) {
610 float energy = (float) hit.energy();
613 else time = (float) (hit.time() -
data.m_trigtime);
614 time = time + bunchTime;
615 if (this->
AddHit(cellId,energy,time,isSignal,
data).isFailure())
return StatusCode::FAILURE;
620 ATH_MSG_WARNING(
" LAr HitFloat container not found for signal event key " << hit_container.key());
627 for (
auto & hit_container : hitVectorHandles) {
628 if (hit_container.isValid()) {
629 for (
const LArHit* hit : *hit_container)
632 float energy = (float) hit->energy();
635 else time = (float) (hit->time() -
data.m_trigtime);
636 time = time + bunchTime;
637 if (this->
AddHit(cellId,energy,time,isSignal,
data).isFailure())
return StatusCode::FAILURE;
642 ATH_MSG_WARNING(
" LAr Hit container not found for signal event key " << hit_container.key());
648 return StatusCode::SUCCESS;
660 ATH_MSG_DEBUG(
" fillMapFromHit: asking for: " << containerName);
666 if (!(
m_mergeSvc->retrieveSingleSubEvtData(containerName, hit_container, bunchTime,
668 ATH_MSG_ERROR(
" LAr Hit container not found for event key " << containerName);
669 return StatusCode::FAILURE;
675 float energy = (float) hit.energy();
678 else time = (float) (hit.time() -
data.m_trigtime);
679 time = time + bunchTime;
681 if (this->
AddHit(cellId,energy,time,isSignal,
data).isFailure())
return StatusCode::FAILURE;
688 if (!(
m_mergeSvc->retrieveSingleSubEvtData(containerName, hit_container, bunchTime,
690 ATH_MSG_ERROR(
" LAr Hit container not found for event key " << containerName);
691 return StatusCode::FAILURE;
695 for(hititer=hit_container->
begin();
696 hititer != hit_container->
end();++hititer)
699 float energy = (float) (*hititer)->energy();
702 else time = (float) ((*hititer)->time() -
data.m_trigtime);
703 time = time + bunchTime;
705 if (this->
AddHit(cellId,energy,time,isSignal,
data).isFailure())
return StatusCode::FAILURE;
710 return StatusCode::SUCCESS;
719 if (std::fabs(energy)>1e+9) {
721 return StatusCode::SUCCESS;
725 ATH_MSG_DEBUG(
" Found hit Id= "<<
m_larem_id->show_to_string(cellId)<<
" energy= " << energy <<
"(MeV) time= " << time <<
"(ns)");
733 std::vector<IdentifierHash> neighbourList;
734 std::vector<float> energyList;
739 neighbourList,energyList, *
data.m_weights);
741 for (
unsigned int icell=0;icell<neighbourList.size();icell++)
747 ATH_MSG_ERROR(
"subCalo value is invalid in LArPileUpTool::AddHit");
748 return StatusCode::FAILURE;
751 float e = energyList[icell];
754 if ( !
data.m_hitmap->AddEnergy(
index,e,time) )
756 ATH_MSG_ERROR(
" Cell " <<
m_larem_id->show_to_string(cellId) <<
" could not add the energy= " << energy <<
" (GeV)");
757 return(StatusCode::FAILURE);
760 if(!
data.m_hitmap_DigiHSTruth->AddEnergy(
index,e,time) ) {
761 ATH_MSG_ERROR(
" Cell " <<
m_larem_id->show_to_string(cellId) <<
" could not add the energy= " << energy <<
" (GeV)");
762 return(StatusCode::FAILURE);
772 if ( !
data.m_hitmap->AddEnergy(idHash,energy,time) )
774 ATH_MSG_ERROR(
" Cell " <<
m_larem_id->show_to_string(cellId) <<
" could not add the energy= " << energy <<
" (GeV)");
775 return(StatusCode::FAILURE);
778 if(!
data.m_hitmap_DigiHSTruth->AddEnergy(idHash,energy,time) ) {
779 ATH_MSG_ERROR(
" Cell " <<
m_larem_id->show_to_string(cellId) <<
" could not add the energy= " << energy <<
" (GeV)");
780 return(StatusCode::FAILURE);
786 if (idHash<
data.m_energySum.size())
data.m_energySum[idHash] += energy;
789 return StatusCode::SUCCESS;
797 std::vector<IdentifierHash>& neighbourList,
798 std::vector<float>& energyList,
801 neighbourList.clear();
804 neighbourList.reserve(8);
805 energyList.reserve(8);
808 int ibec = abs(
m_larem_id->barrel_ec(cellId));
814 std::vector<IdentifierHash> tmpList;
819 if ((ibec==1 && sampling == 1 && region == 0)
820 || (ibec==2 && sampling ==1) )
827 if ( (ibec==1 &&
eta !=447) || (ibec==2 && (
eta!=3 || region !=5)) )
835 if (tmpList.size() == 1) {
838 neighbourList.push_back(tmpList[0]);
839 energyList.push_back(e);
842 if (( (ibec==1 &&
eta !=446)
844 std::vector<IdentifierHash> tmpList2;
847 if (tmpList2.size()==1) {
850 neighbourList.push_back(tmpList2[0]);
851 energyList.push_back(e);
860 if ( (ibec==1 &&
eta >1) || (ibec==2 && (
eta !=0 || region !=0)) )
867 if (tmpList.size() == 1) {
870 neighbourList.push_back(tmpList[0]);
871 energyList.push_back(e);
874 if (( (ibec==1 &&
eta !=2)
876 std::vector<IdentifierHash> tmpList2;
879 if (tmpList2.size()==1) {
882 neighbourList.push_back(tmpList2[0]);
883 energyList.push_back(e);
895 if ((ibec==1 && sampling==1 && region==0)
896 || (ibec==2 && sampling==1) )
901 if (ibec==1) fcr = fcr*2.;
903 if (region==0) fcr=fcr/4.;
904 if (region==1) fcr=fcr/4.;
905 if (region==2) fcr=fcr*2.;
906 if (region==3) fcr=fcr*1.5;
908 if (region==5) fcr=fcr/4.;
915 for (
unsigned int ii=0;ii<tmpList.size();ii++) {
917 neighbourList.push_back(tmpList[ii]);
918 energyList.push_back(e);
924 if ((ibec==1 && sampling==2 && region==0)
925 || (ibec==2 && sampling==2) )
931 for (
unsigned int ii=0;ii<tmpList.size();ii++) {
934 neighbourList.push_back(tmpList[ii]);
941 energyList.push_back(e);
950 if ((ibec==1 && sampling==2 && region==0 ) ||
951 (ibec==2 && sampling==2 && region==1)) {
967 if ( (ibec==1 &&
eta<55) || (ibec==2 &&
eta <42) ) {
971 if (tmpList.size() == 1) {
974 neighbourList.push_back(tmpList[0]);
975 energyList.push_back(e);
980 if ( (ibec==1 &&
eta>0) || (ibec==2 &&
eta >0) ) {
984 if (tmpList.size() == 1) {
987 neighbourList.push_back(tmpList[0]);
988 energyList.push_back(e);
996 if ( (ibec==1 && sampling ==2 && region == 0 )
997 || (ibec==2 && sampling ==2 && region ==1 &&
eta > 2)
998 || (ibec==3 && sampling ==1) )
1002 }
else if(ibec==2) {
1004 }
else if(ibec==3) {
1011 if (tmpList.size() == 1) {
1014 neighbourList.push_back(tmpList[0]);
1015 energyList.push_back(e);
1021 if ( (ibec==1 && sampling == 3 && region == 0 )
1022 ||(ibec==2 && sampling ==3)
1023 ||(ibec==3 && sampling ==2) )
1029 }
else if(ibec==2) {
1032 }
else if(ibec==3) {
1039 if ((ibec==1 || ibec==2) && tmpList.size() == 2) {
1043 neighbourList.push_back(tmpList[0]);
1044 neighbourList.push_back(tmpList[1]);
1045 energyList.push_back(e);
1046 energyList.push_back(e);
1048 if (ibec==1 && tmpList.size()==1) {
1051 neighbourList.push_back(tmpList[0]);
1052 energyList.push_back(e);
1054 if (ibec==3 && tmpList.size() ==1) {
1057 neighbourList.push_back(tmpList[0]);
1058 energyList.push_back(e);
1064 neighbourList.push_back(hashId);
1065 energyList.push_back(er);
1077 for (
unsigned int i=0;i<
data.m_energySum.size();i++) {
1078 float e =
data.m_energySum[i];
1080 if (!
data.m_hitmap->AddEnergy(i,e,bunchTime))
return false;
1082 data.m_energySum[i]=0.;
1085 for (
unsigned int i=0;i<
data.m_energySum_DigiHSTruth.size();i++) {
1086 float e =
data.m_energySum_DigiHSTruth[i];
1088 if (!
data.m_hitmap_DigiHSTruth->AddEnergy(i,e,bunchTime))
return false;
1090 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